Re: Range Access for Multiple-Part Indexes
Posted by:
Rick James
Date: December 31, 2009 08:11PM
What indexes do you have?
To assist in analyzing slow SELECTs, please provide
* SHOW CREATE TABLE tbl\G -- engine, indexes
* SHOW TABLE STATUS LIKE 'tbl'\G -- sizes
* EXPLAIN SELECT ...\G -- clues of inefficiencies
* SHOW VARIABLES LIKE '%buffer%'; -- cache size
and surround them with [ code ] and [ / code ]
BETWEEN may have tricked it into using a different index. Or maybe there should be an index beginning with year.
Are you taking an average of an average? That is usually mathematically wrong! Please justify it or switch to SUM and COUNT, then taking SUM(SUM)/SUM(COUNT).
How fast does it run as a single query instead of using a subquery?
Suggest you build and maintain summary tables, probably indexed by (year, month, x, y) and having sum(value) and count(*).
The PRIMARY KEY is useful only for fetching by x (the first field), since it is multivalued (IN).
There is no index on the subquery, so there is no optimization there.
It is usually inefficient to split dates into separate fields. Recommend you switch from the two columns year and month to a single field computed as, for example, 12*year+month.
Subject
Views
Written By
Posted
4304
December 30, 2009 03:52PM
Re: Range Access for Multiple-Part Indexes
2308
December 31, 2009 08:11PM
2514
January 01, 2010 03:52PM
2394
January 01, 2010 04:37PM
2193
January 01, 2010 05:23PM
2195
January 01, 2010 09:23PM
2464
January 02, 2010 12:54AM
2259
January 02, 2010 09:41PM
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.