Skip to content

Conversation

@chenzl25
Copy link
Contributor

I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.

What's changed and what's your intention?

  • Previously, select * from t where id in ($1) will be converted into select * from t where id in() or id = $1 which is unfriendly to the const folding and it looks like a bug as well.

Checklist

  • I have written necessary rustdoc comments.
  • I have added necessary unit tests and integration tests.
  • I have added test labels as necessary.
  • I have added fuzzing tests or opened an issue to track them.
  • My PR contains breaking changes.
  • My PR changes performance-critical code, so I will run (micro) benchmarks and present the results.
  • I have checked the Release Timeline and Currently Supported Versions to determine which release branches I need to cherry-pick this PR into.

Documentation

  • My PR needs documentation updates.
Release note

@chenzl25 chenzl25 requested a review from yuhao-su October 27, 2025 07:19
@github-actions github-actions bot added the type/fix Type: Bug fix. Only for pull requests. label Oct 27, 2025
@chenzl25 chenzl25 requested a review from xiangjinwu October 27, 2025 07:20
Copy link
Contributor

@xiangjinwu xiangjinwu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is unfriendly to the const folding and it looks like a bug as well

Could you elaborate on this?

  • I agree it is redundant and better removed.
  • But is there any correctness issue that we overlooked? If yes how can we reproduce it?
  • The two fixes in this PR seems unrelated, one about non-const IN and another about $1 in ConstEvalRewriter. In which case is the latter code path reachable?

FunctionCall::new(
ExprType::Or,
vec![
ret.unwrap(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: if-let or let-else to avoid this unwrap()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In which case is the latter code path reachable?

We can simply run explain select $1 to reproduce it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding 2 test cases here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can simply run explain select $1 to reproduce it.

I see; so it is indeed unrelated to IN and just blocks the usage of explain when parameter is not provided. select $1 without explain is still rejected (via captured panic) at a later stage: Parameter should not be serialized to ExprNode

Copy link
Contributor

@xiangjinwu xiangjinwu Oct 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree it is redundant and better removed.

With the redundant part removed, a single equality condition can be pushed down for index selection. I guess this is the real fix (for performance), right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, but we shouldn't panic. And explain is useful to debug this prepared statement.

Copy link
Contributor Author

@chenzl25 chenzl25 Oct 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the redundant part removed, a single equality condition can be pushed down for index selection. I guess this is the real fix (for performance), right?

Yes. BTW, an in expression without any arguments seems an invalid expression.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. Just trying to understand how each part of the PR contribute to fix for panic and performance.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

an in expression without any arguments seems an invalid expression

It is syntactically invalid, but semantically well defined - just testing against an empty set, like IN (subquery) where the subquery returns zero rows. Or did you find any problem in this definition or our existing implementation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed.It is syntactically invalid, but semantically well defined .

@chenzl25 chenzl25 requested a review from xiangjinwu October 28, 2025 08:03
@xiangjinwu xiangjinwu changed the title fix(binder): fix in expr with parameters fix(binder): fix explain with parameters; simplify IN expr without consts Oct 28, 2025
@chenzl25 chenzl25 enabled auto-merge October 28, 2025 08:31
@chenzl25 chenzl25 added this pull request to the merge queue Oct 28, 2025
Merged via the queue into main with commit d15602b Oct 28, 2025
35 of 36 checks passed
@chenzl25 chenzl25 deleted the dylan/fix_in_expr_with_parameters branch October 28, 2025 09:26
yuhao-su pushed a commit that referenced this pull request Oct 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type/fix Type: Bug fix. Only for pull requests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants