Bug #36064 | FR: MySQL can use eq_ref in more cases | ||
---|---|---|---|
Submitted: | 14 Apr 2008 16:41 | Modified: | 15 Apr 2008 3:58 |
Reporter: | Baron Schwartz (Basic Quality Contributor) | Email Updates: | |
Status: | Verified | Impact on me: | |
Category: | MySQL Server: Optimizer | Severity: | S4 (Feature request) |
Version: | OS: | Any | |
Assigned to: | CPU Architecture: | Any | |
Tags: | qc |
[14 Apr 2008 16:41]
Baron Schwartz
[14 Apr 2008 22:27]
Sergei Golubchik
It's not a bug. First, notice that the optimizer prefers a faster execution plan, manual tweaking (with FORCE INDEX) makes it slower. Then, eq_ref is only used (in col=val) when optimizer knows that for every value of val, there could be only one value in col, that is only one row could be found (no more than one, to be precise). This only works when a unique index on (col) is used. You force the server to use the index (col, anothercol), this index cannot guarantee that all values of col are unique, and the server cannot use eq_ref anymore. Of course, technically, it could've noticed that besides this, forced, index there's another index that, though unused in the query, guarantees uniqueness of all values of col. But the fact that optimizer doesn't do it is not a bug, at most it could be considered a feature request ("take into account information about existing unique indexes even if they cannot be used in the query")
[14 Apr 2008 23:07]
Baron Schwartz
Right, this is definitely a feature request. Sorry, I should have said that in the report.