Oracle 5.0 Reference Manual page 671

Table of Contents

Advertisement

tt.ProjectReference, tt.EstimatedShipDate,
tt.ActualShipDate, tt.ClientID,
tt.ServiceCodes, tt.RepetitiveID,
tt.CurrentProcess, tt.CurrentDPPerson,
tt.RecordVolume, tt.DPPrinted, et.COUNTRY,
et_1.COUNTRY, do.CUSTNAME
FROM tt, et, et AS et_1, do
WHERE tt.SubmitTime IS NULL
AND tt.ActualPC = et.EMPLOYID
AND tt.AssignedPC = et_1.EMPLOYID
AND tt.ClientID = do.CUSTNMBR;
For this example, make the following assumptions:
• The columns being compared have been declared as follows.
Table
Column
tt
ActualPC
tt
AssignedPC
tt
ClientID
et
EMPLOYID
do
CUSTNMBR
• The tables have the following indexes.
Table
tt
tt
tt
et
do
• The
values are not evenly distributed.
tt.ActualPC
Initially, before any optimizations have been performed, the
information:
table type possible_keys key
et
ALL
PRIMARY
do
ALL
PRIMARY
et_1
ALL
PRIMARY
tt
ALL
AssignedPC,
ClientID,
ActualPC
Range checked for each record (index map: 0x23)
Because
is
for each table, this output indicates that MySQL is generating a Cartesian
type
ALL
product of all the tables; that is, every combination of rows. This takes quite a long time, because the
product of the number of rows in each table must be examined. For the case at hand, this product is 74
× 2135 × 74 × 3872 = 45,268,558,720 rows. If the tables were bigger, you can only imagine how long it
would take.
One problem here is that MySQL can use indexes on columns more efficiently if they are declared
as the same type and size. In this context,
declared as the same size.
so there is a length mismatch.
To fix this disparity between column lengths, use
characters to 15 characters:
Output Format
EXPLAIN
Index
ActualPC
AssignedPC
ClientID
(primary key)
EMPLOYID
(primary key)
CUSTNMBR
key_len ref
NULL NULL
NULL 74
NULL NULL
NULL 2135
NULL NULL
NULL 74
NULL NULL
NULL 3872
VARCHAR
is declared as
tt.ActualPC
651
Data Type
CHAR(10)
CHAR(10)
CHAR(10)
CHAR(15)
CHAR(15)
EXPLAIN
rows
Extra
and
are considered the same if they are
CHAR
and
CHAR(10)
to lengthen
ALTER TABLE
statement produces the following
is CHAR(15),
et.EMPLOYID
from 10
ActualPC

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents