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

feat(planner): logical plan for rcte #16680

Merged
merged 24 commits into from May 15, 2024

Conversation

xzhseh
Copy link
Contributor

@xzhseh xzhseh commented May 10, 2024

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

What's changed and what's your intention?

refer #16483.

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.

@xzhseh
Copy link
Contributor Author

xzhseh commented May 10, 2024

Copy link

gitguardian bot commented May 10, 2024

️✅ There are no secrets present in this pull request anymore.

If these secrets were true positive and are still valid, we highly recommend you to revoke them.
Once a secret has been leaked into a git repository, you should consider it compromised, even if it was deleted immediately.
Find here more information about risks.


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

_predicate: Condition,
_ctx: &mut PredicatePushdownContext,
) -> PlanRef {
self.clone().into()
Copy link
Contributor

Choose a reason for hiding this comment

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

We should handle predicate pushdown as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep this should be handled once the optimization is enabled - since there is no actual implementation for predicate pushdown at present, it's alright.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need to change it to unimplemented!(), if we don't handle it right now, because the current implementation doesn't handle the push down predicate and it will generate a wrong 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.

it will generate a wrong plan

I don't quite get this, why directly cloning the current plan without predicate pushdown will lead to a wrong plan? 👀

Copy link
Contributor

Choose a reason for hiding this comment

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

If you don't want to push down the predicate you should implement it like this, because the predicate in this function couldn't be thrown away, at least we need to generate a filter for it.

fn predicate_pushdown(
        &self,
        predicate: Condition,
        ctx: &mut PredicatePushdownContext,
    ) -> PlanRef {
        // No pushdown.
        gen_filter_and_pushdown(self, predicate, Condition::true_cond(), ctx)
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

update the implementation for predicate_pushdown, I think it's reasonable to push predicate down to the base and recursive plan.

Comment on lines +80 to +90
fn prune_col(&self, required_cols: &[usize], ctx: &mut ColumnPruningContext) -> PlanRef {
let new_inputs = self
.inputs()
.iter()
.map(|input| input.prune_col(required_cols, ctx))
.collect_vec();
let new_plan = self.clone_with_inputs(&new_inputs);
self.ctx()
.insert_rcte_cache_plan(self.core.id, new_plan.clone());
new_plan
}
Copy link
Contributor

@chenzl25 chenzl25 May 10, 2024

Choose a reason for hiding this comment

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

Here we reuse the ShareId but insert a new_plan which might have a different schema from the old_plan, but cte_ref has a base field which represents a plan at the beginning of planning, so it would be inconsistent with the rcte_cache_plan updated here. That's why I think we should never use base of cte_ref after the initial planning.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but cte_ref has a base field which represents a plan at the beginning of planning, so it would be inconsistent with the rcte_cache_plan updated here.

agree. the only essential use case for base is to get the current OptimizerContext, for GenericPlanNode's impl methods I think we could just stick with the current stream_key's logic - in this case everything is consistent with the on-the-fly plan cache stored in the context.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

implementation of the current stream_key is here (the consistent one we should stick to): https://github.com/risingwavelabs/risingwave/pull/16680/files#diff-1d6ad1cdae116ec20167aafcc080d20606c2fb3da492cea9c6a398412456d96bR63.

Copy link
Contributor

@chenzl25 chenzl25 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!

@xzhseh
Copy link
Contributor Author

xzhseh commented May 14, 2024

@chenzl25 could you help me merge this pr, thanks!

@chenzl25
Copy link
Contributor

@chenzl25 could you help me merge this pr, thanks!

Sure

@chenzl25 chenzl25 added this pull request to the merge queue May 15, 2024
Merged via the queue into risingwavelabs:main with commit a63fa8c May 15, 2024
27 of 28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants