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

refactor(optimizer): make ExprVisitor an object safe trait. #13512

Merged
merged 6 commits into from
Nov 22, 2023

Conversation

chenzl25
Copy link
Contributor

@chenzl25 chenzl25 commented Nov 20, 2023

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

What's changed and what's your intention?

Checklist

  • I have written necessary rustdoc comments
  • I have added necessary unit tests and integration tests
  • I have added test labels as necessary. See details.
  • I have added fuzzing tests or opened an issue to track them. (Optional, recommended for new SQL features Sqlsmith: Sql feature generation #7934).
  • My PR contains breaking changes. (If it deprecates some features, please create a tracking issue to remove them in the future).
  • All checks passed in ./risedev check (or alias, ./risedev c)
  • My PR changes performance-critical code. (Please run macro/micro-benchmarks and show the results.)
  • My PR contains critical fixes that are necessary to be merged into the latest release. (Please check out the details)

Documentation

  • My PR needs documentation updates. (Please use the Release note section below to summarize the impact on users)

Release note

If this PR includes changes that directly affect users or other significant modifications relevant to the community, kindly draft a release note to provide a concise summary of these changes. Please prioritize highlighting the impact these changes will have on users.

Copy link

codecov bot commented Nov 20, 2023

Codecov Report

Attention: 23 lines in your changes are missing coverage. Please review.

Comparison is base (c89c99c) 68.37% compared to head (5be7ef7) 68.42%.
Report is 9 commits behind head on main.

Files Patch % Lines
src/frontend/src/expr/mod.rs 78.72% 10 Missing ⚠️
src/frontend/src/expr/pure.rs 66.66% 5 Missing ⚠️
src/frontend/src/expr/expr_visitor.rs 85.71% 3 Missing ⚠️
.../src/optimizer/plan_visitor/input_ref_validator.rs 76.92% 3 Missing ⚠️
...ontend/src/optimizer/plan_node/logical_sys_scan.rs 83.33% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #13512      +/-   ##
==========================================
+ Coverage   68.37%   68.42%   +0.04%     
==========================================
  Files        1511     1511              
  Lines      259862   259798      -64     
==========================================
+ Hits       177692   177756      +64     
+ Misses      82170    82042     -128     
Flag Coverage Δ
rust 68.42% <84.76%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@BugenZhao BugenZhao left a comment

Choose a reason for hiding this comment

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

  • Is merge and Result really a good practice of a visitor pattern? As all visit methods take &mut self, this seems to imply that one should maintain the states or results in self. In this way, the signature of merge could be like

    fn merge(&mut self, b: Self::Result);

    Or rather, we should never have a merge function?

  • Once a method is overridden, users have to duplicate the default implementation there and merge does not help us for boilerplate reduction. Will this work somehow related to optimizer: what's the "correct" form of visitor? #13477?

@chenzl25
Copy link
Contributor Author

Is merge and Result really a good practice of a visitor pattern?

Although some visitors, such as Has, can easily eliminate the need for merge by using a state, other visitors, like TableScanIoEstimator, might find it challenging to calculate the cost by visiting expressions with the use of only a state, because expressions structure also matters. Therefore, I believe this method still serves a purpose. However, I agree that using &mut self instead of &self for merge would be more appropriate.

@chenzl25
Copy link
Contributor Author

As mentioned above, I think fn merge is mainly used to capture the expression structure instead of boilerplate reduction, so maybe we can use another PR to resolve that issue.

@chenzl25 chenzl25 requested a review from BugenZhao November 20, 2023 11:53
@BugenZhao
Copy link
Member

However, I agree that using &mut self instead of &self for merge would be more appropriate.

Actually I suggest we either... 🥵

  • Make visit take &self,
  • or either remove merge but keep visit take &mut self

@chenzl25
Copy link
Contributor Author

However, I agree that using &mut self instead of &self for merge would be more appropriate.

Actually I suggest we either... 🥵

  • Make visit take &self,
  • or either remove merge but keep visit take &mut self

I prefer to remove merge and return type if we have to.

@chenzl25
Copy link
Contributor Author

TableScanIoEstimator

But as I mentioned before without a return type and merge function, visitors like TableScanIoEstimator could need to maintain a state by itself which is nontrivial.

@chenzl25
Copy link
Contributor Author

cc @BugenZhao I removed the merge function right now. PTAL.

@chenzl25 chenzl25 requested a review from xxchan November 21, 2023 07:28
Copy link
Member

@BugenZhao BugenZhao left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for doing this refactoring!

Copy link
Member

@xxchan xxchan left a comment

Choose a reason for hiding this comment

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

I revisited #4520 (add return value to visitor) and #5058 (add merge). Still has no strong opinion for either way. So rubber stamp.

@chenzl25
Copy link
Contributor Author

I revisited #4520 (add return value to visitor) and #5058 (add merge). Still has no strong opinion for either way. So rubber stamp.

Oh, I have already forgotten that both of them were introduced by myself. 🥵 Now I removed them all.

Copy link
Contributor

@st1page st1page left a comment

Choose a reason for hiding this comment

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

LGTM

@chenzl25 chenzl25 added this pull request to the merge queue Nov 22, 2023
Merged via the queue into main with commit 11011b1 Nov 22, 2023
26 of 27 checks passed
@chenzl25 chenzl25 deleted the dylan/make_expr_visitor_be_able_to_trait_object branch November 22, 2023 06:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants