chai
chai copied to clipboard
Use ranges when dealing with suitable comparison operators
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}])"
}