Query with GROUP BY not using Index
The following query is taking 3.8 seconds to run:
SELECT wafer_name FROM epi_iv GROUP BY wafer_name ORDER BY date DESC;
EXPLAIN SELECT wafer_name FROM epi_iv GROUP BY wafer_name ORDER BY date DESC\G
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: epi_iv
type: ALL
possible_keys: NULL
key: NULL
key_len: NULL
ref: NULL
rows: 496613
Extra: Using temporary; Using filesort
SHOW CREATE TABLE's output is really long, but the relevant parts are:
`wafer_name` varchar(256) collate utf8_unicode_ci NOT NULL,
`date` datetime NOT NULL,
PRIMARY KEY (`iv_id`),
KEY `wafer_id` (`wafer_id`),
KEY `wafer_name` (`wafer_name`(255)),
KEY `wafer_name_date` (`wafer_name`(255),`date`)
) ENGINE=InnoDB AUTO_INCREMENT=514387 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
If I simplify the query by removing the ORDER BY, it still takes 3 seconds:
SELECT wafer_name FROM epi_iv GROUP BY wafer_name;
I know this query can run in ~.05 seconds when it uses the index because it does so on another table with about the same number of rows and the same composite index.
The cardinality of the wafer_name_date composite index is:
3463 for wafer_name and 126435 for the date.
Any ideas?
thanks
Subject
Views
Written By
Posted
Query with GROUP BY not using Index
3070
August 14, 2012 01:06PM
1544
August 15, 2012 02:46AM
1417
August 16, 2012 10:30AM
1708
August 17, 2012 02:58AM
1419
August 18, 2012 10:30PM
1383
August 24, 2012 12:41PM
1456
August 28, 2012 03:11AM
1521
August 28, 2012 06:21PM
1883
August 29, 2012 01:28AM
1339
August 29, 2012 10:36AM
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.