Bug #31696 | < col1 and > col2 optimization | ||
---|---|---|---|
Submitted: | 18 Oct 2007 17:16 | Modified: | 19 Oct 2007 9:16 |
Reporter: | Matthew Lord | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server: Optimizer | Severity: | S4 (Feature request) |
Version: | all | OS: | Any |
Assigned to: | CPU Architecture: | Any | |
Tags: | Optimizer |
[18 Oct 2007 17:16]
Matthew Lord
[19 Oct 2007 9:16]
Sergey Petrunya
Matt, This rewrite will not make any query faster (did you actually try it?). The rewrite that was provided for the customer was different from what you write here: 1. the inner query had "ORDER BY col1 ... LIMIT 1", which makes a *big* difference for the possible execution time. 2. the rewrite with LIMIT 1 is only valid when we have a specific assumption about the meaning of table data: we assume that values of col1 and col2 that columns col1 and col2 are bounds of a range, and that different rows in the table "own" different ranges, i.e. any point falls into at most *one* range (that's why we could add LIMIT 1). MySQL server does not know anything about the meaning of the data (there is no way to express such constraints in SQL), and therefore cannot perform the mentioned rewrite.