Bug #9693 | bug in trying to join a value on a range (using indexes) | ||
---|---|---|---|
Submitted: | 6 Apr 2005 19:29 | Modified: | 20 Jun 2005 5:38 |
Reporter: | mysql prutser | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server: Optimizer | Severity: | S3 (Non-critical) |
Version: | 3.23.41, 4.0.24, 4.1 | OS: | Linux (linux) |
Assigned to: | Sergey Petrunya | CPU Architecture: | Any |
[6 Apr 2005 19:29]
mysql prutser
[20 Jun 2005 5:36]
Sergey Petrunya
The behavior you`ve described is expected, and is in line with documentation at http://dev.mysql.com/doc/mysql/en/range-optimization.html http://dev.mysql.com/doc/mysql/en/explain.html The difference between queries (2) and (3) is caused by different clauses on table data_main. For query (2) the clause is dm.id=1. data_main.id is a primary key, the optimizer figures out it can consider all dm.* column values to be constants, and the second part of the WHERE condition (dm.range >= p.range_from AND dm.range <= p.range_till) can be used to perform 'range' access to table postcodes. For query (3) dm.id can have 2 values, so dm.range is not constant, and 'range' access cannot be performed. What does EXPLAIN show in "Extra" field for table postcodes? If it is "range checked for each record", that means MySQL will use (dm.range >= p.range_from AND dm.range <= p.range_till) to limit number rows it read from postcodes table and it is already as good as it can be. If not, you might try rewriting query (3) as a two-way UNION (one part with "dm.id=1" and another with "dm.id=2")
[20 Jun 2005 5:38]
Sergey Petrunya
Setting to "Not a bug" as the described behavior is expected for current versions of MySQL.