shamim8888 / asterixdb

Automatically exported from code.google.com/p/asterixdb
0 stars 0 forks source link

Optimizer fails to use index when operation is performed on value #853

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
AQL:
drop dataverse emergencyTest if exists;
create dataverse emergencyTest;
use dataverse emergencyTest;

create type CHPReport as {
    "rid":uuid,
    "number":int64
}

create dataset CHPReports(CHPReport)
primary key rid autogenerated;

create index reportTimes on CHPReports(number);

///This query uses the index:
for $result in dataset CHPReports
where $result.number = 6 + 5
return $result;

 ///This query doesn't:
for $result in dataset CHPReports
where $result.number + 5  = 6 
return $result;

The + 5 operation should be able to be implicitly moved to the right side (and 
thereby use the index for both).

Original issue reported on code.google.com by sjaco...@ucr.edu on 18 Feb 2015 at 8:34

GoogleCodeExporter commented 9 years ago
We're at least in acceptable company - I was curious and just tested MySQL, 
and...
SELECT * FROM Sailors WHERE rating + 2 = 10 does a table scan, while
SELECT * FROM Sailors WHERE rating = 8 uses an index on rating, and 
SELECT * FROM Sailors WHERE rating = 6 + 2 uses the rating index too.
(So both do simple constant folding but don't do deeper algebraic rewriting.)
:-)

Original comment by dtab...@gmail.com on 19 Feb 2015 at 5:23

GoogleCodeExporter commented 9 years ago
PS - The good news is that users can be alerted to this and write queries 
accordingly.

Original comment by dtab...@gmail.com on 19 Feb 2015 at 5:24