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): reset expression display id for explain #8006

Merged
merged 9 commits into from Feb 20, 2023

Conversation

chenzl25
Copy link
Contributor

@chenzl25 chenzl25 commented Feb 17, 2023

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

What's changed and what's your intention?

  • As title.

Checklist

  • I have written necessary rustdoc comments
  • I have added necessary unit tests and integration tests
  • I have added fuzzing tests or opened an issue to track them. (Optional, recommended for new SQL features).
  • I have demonstrated that backward compatibility is not broken by breaking changes and created issues to track deprecated features to be removed in the future. (Please refer to the issue)
  • All checks passed in ./risedev check (or alias, ./risedev c)

Documentation

  • My PR DOES NOT contain user-facing changes.
Click here for Documentation

Types of user-facing changes

Please keep the types that apply to your changes, and remove the others.

  • Installation and deployment
  • Connector (sources & sinks)
  • SQL commands, functions, and operators
  • RisingWave cluster configuration changes
  • Other (please specify in the release note below)

Release note

#8005

Comment on lines 335 to 346
// In order to let expression display id started from 1 for explaining.
// We will reset expression display id to 0 and clone the whole plan to reset the schema.
let plan = {
let rules = vec![];
// Use a optimizer without rules to clone a new plan.
let mut heuristic_optimizer = HeuristicOptimizer::new(&ApplyOrder::TopDown, &rules);
let old_expr_display_id = self.ctx().get_expr_display_id();
self.ctx().set_expr_display_id(0);
let plan = heuristic_optimizer.optimize(self.clone());
self.ctx().set_expr_display_id(old_expr_display_id);
plan
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reset logic.

@codecov
Copy link

codecov bot commented Feb 17, 2023

Codecov Report

Merging #8006 (43444aa) into main (b001ac5) will increase coverage by 0.04%.
The diff coverage is 98.43%.

@@            Coverage Diff             @@
##             main    #8006      +/-   ##
==========================================
+ Coverage   71.30%   71.35%   +0.04%     
==========================================
  Files        1123     1124       +1     
  Lines      181038   181098      +60     
==========================================
+ Hits       129093   129225     +132     
+ Misses      51945    51873      -72     
Flag Coverage Δ
rust 71.35% <98.43%> (+0.04%) ⬆️

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

Impacted Files Coverage Δ
src/frontend/planner_test/src/lib.rs 74.94% <ø> (ø)
src/frontend/src/handler/create_index.rs 89.85% <ø> (ø)
src/frontend/src/handler/create_mv.rs 95.13% <ø> (ø)
src/frontend/src/handler/create_sink.rs 97.10% <ø> (ø)
src/frontend/src/handler/explain.rs 74.80% <ø> (ø)
src/frontend/src/handler/query.rs 15.96% <ø> (ø)
src/frontend/src/lib.rs 44.00% <ø> (ø)
src/frontend/src/optimizer/mod.rs 95.38% <ø> (ø)
...tend/src/optimizer/plan_node/logical_hop_window.rs 99.21% <ø> (ø)
src/frontend/src/optimizer/plan_rewriter/mod.rs 81.25% <ø> (+6.25%) ⬆️
... and 40 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@xxchan xxchan requested a review from stdrc February 17, 2023 08:48
@fuyufjh
Copy link
Contributor

fuyufjh commented Feb 17, 2023

Don't do this! Because of #7998, the optimizer calls explain_to_string in the middle of optimization

@chenzl25
Copy link
Contributor Author

Don't do this! Because of #7998, the optimizer calls explain_to_string in the middle of optimization

Any problem? We will reset the expr_display_id back after explaining.

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.

A little tricky to clone the whole plan tree with HeuristicOptimizer but LGTM.

src/frontend/src/optimizer/plan_node/mod.rs Outdated Show resolved Hide resolved
Comment on lines +339 to +341
self.ctx().set_expr_display_id(0);
let plan = PlanCloner::clone_whole_plan(self.clone());
self.ctx().set_expr_display_id(old_expr_display_id);
Copy link
Contributor

Choose a reason for hiding this comment

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

Agree with @st1page. A little counterintuitive to me and I am not sure if it is worth it.

Copy link
Contributor Author

@chenzl25 chenzl25 Feb 20, 2023

Choose a reason for hiding this comment

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

The clone_whole_plan is restricted in Explain scope only, so I think it is acceptability. Otherwise it is painful to add a new optimization, because it would affect lots of plan tests.

@chenzl25 chenzl25 added the mergify/can-merge Indicates that the PR can be added to the merge queue label Feb 20, 2023
@mergify mergify bot merged commit 495a7a8 into main Feb 20, 2023
@mergify mergify bot deleted the dylan/improve_explain branch February 20, 2023 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mergify/can-merge Indicates that the PR can be added to the merge queue type/refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants