Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

frontend: merge is_const and fold_const (eval) #15768

Open
BugenZhao opened this issue Mar 19, 2024 · 5 comments
Open

frontend: merge is_const and fold_const (eval) #15768

BugenZhao opened this issue Mar 19, 2024 · 5 comments
Labels
component/func-expr Support a SQL function or operator component/optimizer Query optimization. no-issue-activity type/refactor

Comments

@BugenZhao
Copy link
Member

BugenZhao commented Mar 19, 2024

I think the main issue is that the code logic for determining if an ExprImpl can be constant-folded differs from the actual evaluation process for folding it.

So I'm considering if it's possible to merge is_const and fold_const into a single step, that is:

  • Provide another implementation of build_from_prost that rejects any other expressions except for Literal and FunctionCall.

  • Call that to build the expression. If there's an error, we say that the expression cannot be folded.

  • Call eval_row on the built expression, which will utilize short-circuiting.

Originally posted by @BugenZhao in #15758 (review)

cc @xxchan @st1page @xiangjinwu for discussion

@BugenZhao BugenZhao changed the title frontend: combine is_const and fold_const frontend: merge is_const and fold_const Mar 19, 2024
@github-actions github-actions bot added this to the release-1.8 milestone Mar 19, 2024
@BugenZhao BugenZhao added type/refactor component/optimizer Query optimization. component/func-expr Support a SQL function or operator labels Mar 19, 2024
@BugenZhao
Copy link
Member Author

  • that rejects any other expressions except for Literal and FunctionCall.

This even seems unnecessary. What about always building the expressions and evaluating it on an empty row, then treat any returned error as "not able to do constant-folding"? The point is that we don't have to care about InputRefs in the expression tree as long as it's short-circuited, like:

select true or (k / 0)::boolean from (values (1)) t(k);

@BugenZhao BugenZhao changed the title frontend: merge is_const and fold_const frontend: merge is_const and fold_const (eval) Mar 19, 2024
@BugenZhao
Copy link
Member Author

A draft demonstrating the idea: #15777

@xzhseh
Copy link
Contributor

xzhseh commented Mar 19, 2024

This even seems unnecessary.

I believe this will increase building cost especially when the expression takes a relatively long time to build, narrowing down the types of expressions to build at the beginning (e.g., only from Literal or FunctionCall) sounds a good idea.

@BugenZhao
Copy link
Member Author

increase building cost especially when the expression takes a relatively long time to build

Does it sound like this, but have we verified it (for example, through flamegraph)? I'm unsure if this overhead is non-negligible.

Copy link
Contributor

This issue has been open for 60 days with no activity. Could you please update the status? Feel free to continue discussion or close as not planned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/func-expr Support a SQL function or operator component/optimizer Query optimization. no-issue-activity type/refactor
Projects
None yet
Development

No branches or pull requests

2 participants