chai icon indicating copy to clipboard operation
chai copied to clipboard

Use ranges when dealing with suitable comparison operators

Open asdine opened this issue 2 years ago • 0 comments

Given the following table:

CREATE TABLE foo (a INT PRIMARY KEY);
genji> explain select * from foo where a > 10 AND a < 100;
{
  "plan": "table.Scan(\"foo\", [{\"min\": [10], \"exclusive\": true}]) | docs.Filter(a < 100)"
}

genji> explain select * from foo where a > 10 AND a < 120 OR a > 4 AND a < 100;
{
  "plan": "seqScan(foo) | filter(a > 10 AND a < 120 OR a > 4 AND a < 100)"
}

This should use ranges instead:

genji> explain select * from foo where a > 10 AND a < 100;
{
  "plan": "table.Scan(\"foo\", [{\"min\": [10], \"max\": [100], \"exclusive\": true}])"
}

genji> explain select * from foo where a > 10 AND a <100 OR a > 400 AND a < 1000;
{
   "plan": "table.Scan(\"foo\", [{\"min\": [4], \"max\": [120], \"exclusive\": true}, {\"min\": [400], \"max\": [1000], \"exclusive\": true}])"
}

genji> explain select * from foo where a > 10 AND a < 120 OR a > 4 AND a < 100;
{
   "plan": "table.Scan(\"foo\", [{\"min\": [4], \"max\": [120], \"exclusive\": true}])"
}

asdine avatar Jul 02 '22 14:07 asdine