risinglightdb / risinglight

An educational OLAP database system.
Apache License 2.0
1.59k stars 211 forks source link

optimizer: filter scan rule #834

Open crwen opened 6 months ago

crwen commented 6 months ago

https://github.com/risinglightdb/risinglight/blob/0e4a8469e74d6e8a468b58e82df9ac0d0311b5e3/src/planner/rules/range.rs#L88-L100

Here's my understanding: When there are predicates on primary key, we should push them down to the storage layer. Is that right?

But it seems not to work when I execute statements like select pk from t where pk > 1. And the filter passed to scan function is always None. It looks like these:

> explain select a from t2 where a > 17;
Filter { cond: > { lhs: a, rhs: 17 }, cost: 68.4, rows: 20 }
└── Scan { table: t2, list: [ a ], filter: null, cost: 40, rows: 40 }

Maybe the true in "(scan ?table ?columns true)" should be replaced to null? Because it seems to work if I change it.

> explain select a from t2 where a > 17;
Scan { table: t2, list: [ a ], filter: > { lhs: a, rhs: 17 }, cost: 40, rows: 40 }
skyzh commented 6 months ago

maybe related: https://github.com/risinglightdb/risinglight/pull/795? But it's a known issue and if you want to fix that, please submit a pull request, thanks!

crwen commented 6 months ago

It seems like that the filter is true by default, instead of null. So the solution may be like this in #795?

https://github.com/risinglightdb/risinglight/blob/cd03496eb2c0cb1fab7e43fa5738d42c091013fd/src/binder/table.rs#L60-L70