![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
A new query was running slowly, so I ran it through "explain" and discovered that it was using Index6. I added a new index, Index7 that I thought would be a better fit. After re-running explain, it's now opting for Index1. I don't understand how adding a new index could cause the system to choose a different pre-existing index. Any thoughts? |
#3
| |||
| |||
|
|
Blake <blake (AT) custom-fitz-software (DOT) com> wrote: A new query was running slowly, so I ran it through "explain" and discovered that it was using Index6. I added a new index, Index7 that I thought would be a better fit. After re-running explain, it's now opting for Index1. I don't understand how adding a new index could cause the system to choose a different pre-existing index. Any thoughts? Adding another index will also update statistics for existing indexes. (this is what ANALYZE TABLE does). Optimizer decision depends on existing indexes *and* statistical information for such indexes. If you receive a bad (and seemingly inappropriate) result from EXPLAIN you should always run ANALYZE TABLE first. Ideally you should run ANALYZE TABLE regularly (for tables that are constantly modified) or after changing significant part of a table. XL |
#4
| |||
| |||
|
|
On Tue, 5 Oct 2010 07:47:41 +0200, Axel Schwenke axel.schwenke (AT) gmx (DOT) de> wrote: Blake <blake (AT) custom-fitz-software (DOT) com> wrote: A new query was running slowly, so I ran it through "explain" and discovered that it was using Index6. I added a new index, Index7 that I thought would be a better fit. After re-running explain, it's now opting for Index1. I don't understand how adding a new index could cause the system to choose a different pre-existing index. Any thoughts? Adding another index will also update statistics for existing indexes. (this is what ANALYZE TABLE does). Optimizer decision depends on existing indexes *and* statistical information for such indexes. If you receive a bad (and seemingly inappropriate) result from EXPLAIN you should always run ANALYZE TABLE first. Ideally you should run ANALYZE TABLE regularly (for tables that are constantly modified) or after changing significant part of a table. Thanks, that fixed the problem. I was always under the impression that index stats were updated on INSERT / DELETE / UPDATE queries, and this was what caused those queries to take longer when using multiple indices - didn't even know ANALYZE TABLE existsed. |
![]() |
| Thread Tools | |
| Display Modes | |
| |