MySQL Forums
Forum List  »  Optimizer & Parser

Optimizer ignores number of records
Posted by: Lite Wait
Date: September 15, 2006 06:28AM

The query:
EXPLAIN SELECT
`dw_item`.`dwin_item_description` 'Item',
Sum(`dw_sls_item_dtl`.`dwsi_net_sales`) 'Sales'
FROM
dw_sls_item_dtl
INNER JOIN dw_item ON `dw_sls_item_dtl`.`dwsi_store` = `dw_item`.`dwin_store` AND `dw_sls_item_dtl`.`dwsi_item` = `dw_item`.`dwin_item_number`
INNER JOIN dw_vendor ON `dw_sls_item_dtl`.`dwsi_store` = `dw_vendor`.`dwvm_store` AND `dw_sls_item_dtl`.`dwsi_vendor` = `dw_vendor`.`dwvm_vendor_code`
WHERE
`dw_vendor`.`dwvm_vendor_name` = "IMAX CORPORATION"
GROUP BY
`dw_item`.`dwin_item_description`

(returns)
+----+-------------+-----------------+--------+---------------------------------
-----+---------+---------+------------------------------------------------------
----------------+---------+---------------------------------+
| id | select_type | table | type | possible_keys
| key | key_len | ref
| rows | Extra |
+----+-------------+-----------------+--------+---------------------------------
-----+---------+---------+------------------------------------------------------
----------------+---------+---------------------------------+
| 1 | SIMPLE | dw_sls_item_dtl | ALL | Idw_sls_item_dtl3,Idw_sls_item_dtl10 | NULL | NULL | NULL
| 2871033 | Using temporary; Using filesort |
| 1 | SIMPLE | dw_item | eq_ref | PRIMARY
| PRIMARY | 15 | EAGLEDW.dw_sls_item_dtl.dwsi_item,EAGLEDW.dw_sls_item_dtl.dwsi_store | 2 | |
| 1 | SIMPLE | dw_vendor | eq_ref | PRIMARY
| PRIMARY | 6 | EAGLEDW.dw_sls_item_dtl.dwsi_vendor,EAGLEDW.dw_item.dwin_store | 1 | Using where |
+----+-------------+-----------------+--------+---------------------------------
-----+---------+---------+------------------------------------------------------
----------------+---------+---------------------------------+

there are indexes in the dw_sls_item_dtl table for all keys being used in the inner joins. It seems since the where clause isn't using an indexed field, the optimizer doesn't even consider the number of records likely to be returned by each table. (of course) if I index the vendor_name teh query runs fast, but I can't index every field in that table (since they can select any column) and the optimizer _should_ be considering the number of records in the table (heck even lowly Informix-SE does that). Any ideas? Thanks.

Options: ReplyQuote


Subject
Views
Written By
Posted
Optimizer ignores number of records
2803
September 15, 2006 06:28AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.