-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
Follow on to #9506
The idea is to support arbitrary expressions that can be consolidated to a constant in the LIMIT clause. For example
❯ select * from (values (1)) LIMIT 10*100;
Error during planning: Unsupported operator for LIMIT clauseThis query should be able to run (and return the single value)
❯ select * from (values (1)) LIMIT 10+100;
+---------+
| column1 |
+---------+
| 1 |
+---------+#9790 adds support for basic +/- but the general purpose solution that would handle any expr that can be consolidated to a constant would be better
As suggested by @jonahgao this might look like change the Limit logical plan to support arbitrary expressions?
pub struct Limit {
pub skip: Expr,
pub fetch: Option<Expr>,
pub input: Arc<LogicalPlan>,
}The SimplifyExpressions rule can automatically optimize them into constants. Some optimization rules such as PushDownLimit only run when the limit expression is a constant. We may need to add a cast for the limit expression when planning, only checking if it is a constant of type u64.
When creating the LimitExec physical plan, convert the limit expression into PhysicalExpr and evaluate it.
Originally posted by @jonahgao in #9790 (comment)