Skip to content

opt: fix functional deps and stats for WithScanExpr #40523

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

Merged
merged 1 commit into from
Sep 9, 2019

Conversation

rytaft
Copy link
Collaborator

@rytaft rytaft commented Sep 5, 2019

This commit fixes the functional dependencies and stats calculation
for WithScanExpr so they use the output columns rather than the input
columns.

Fixes #40296

Release note: None

@rytaft rytaft requested a review from a team as a code owner September 5, 2019 21:02
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Contributor

@justinj justinj left a comment

Choose a reason for hiding this comment

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

:lgtm:, nice fix on the FDs!

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @justinj, @RaduBerinde, and @rytaft)


pkg/sql/opt/memo/statistics_builder.go, line 2112 at r1 (raw file):

	inColSet := translateColSet(colSet, withScan.OutCols, withScan.InCols)

	// TODO(rytaft): Is there an easy way to access the WithExpr itself?

This was how it worked originally, but it was problematic because the WithExpr can change out from underneath the WithScan (via, say, the replacement of placeholders). I forget exactly why this caused problems but it made a lot of things difficult.

@rytaft
Copy link
Collaborator Author

rytaft commented Sep 9, 2019


pkg/sql/opt/memo/statistics_builder.go, line 2112 at r1 (raw file):

Previously, justinj (Justin Jaffray) wrote…

This was how it worked originally, but it was problematic because the WithExpr can change out from underneath the WithScan (via, say, the replacement of placeholders). I forget exactly why this caused problems but it made a lot of things difficult.

But wouldn't we want to re-optimize the full tree if things change in the WithExpr? Like if we learn after placeholder replacement that the size of the WithExpr is much smaller than originally thought?

Copy link
Contributor

@justinj justinj left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @RaduBerinde and @rytaft)


pkg/sql/opt/memo/statistics_builder.go, line 2112 at r1 (raw file):

Previously, rytaft (Rebecca Taft) wrote…

But wouldn't we want to re-optimize the full tree if things change in the WithExpr? Like if we learn after placeholder replacement that the size of the WithExpr is much smaller than originally thought?

We don't have any precedent for re-optimizing expressions that haven't themselves changed, do we? We'd have to add in an extra mechanism that walks and re-interns (or something) WithScanExprs that reference WithExprs that have changed? Sounds doable but a little tricky, and like it might invalidate a handful of assumptions

This commit fixes the functional dependencies and stats calculation
for WithScanExpr so they use the output columns rather than the input
columns.

Fixes cockroachdb#40296

Release note: None
Copy link
Collaborator Author

@rytaft rytaft left a comment

Choose a reason for hiding this comment

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

TFTR!

I had to add a buildWithScan function to the statisticsBuilder since the shallow copy of stats from the BindingProps was causing some nasty memory overwriting issues. PTAL.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @justinj and @RaduBerinde)


pkg/sql/opt/memo/statistics_builder.go, line 2112 at r1 (raw file):

Previously, justinj (Justin Jaffray) wrote…

We don't have any precedent for re-optimizing expressions that haven't themselves changed, do we? We'd have to add in an extra mechanism that walks and re-interns (or something) WithScanExprs that reference WithExprs that have changed? Sounds doable but a little tricky, and like it might invalidate a handful of assumptions

Yea, good point. Seems like it might be worth doing in the future, but not for 19.2. I rephrased this TODO a bit so we can come back to it later.

@rytaft
Copy link
Collaborator Author

rytaft commented Sep 9, 2019

@justinj ok to merge with the latest changes?

Copy link
Contributor

@justinj justinj left a comment

Choose a reason for hiding this comment

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

:lgtm_strong:

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @justinj and @RaduBerinde)

Copy link
Collaborator Author

@rytaft rytaft left a comment

Choose a reason for hiding this comment

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

TFTR!

bors r+

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @justinj and @RaduBerinde)

craig bot pushed a commit that referenced this pull request Sep 9, 2019
40523: opt: fix functional deps and stats for WithScanExpr r=rytaft a=rytaft

This commit fixes the functional dependencies and stats calculation
for `WithScanExpr` so they use the output columns rather than the input
columns.

Fixes #40296

Release note: None

40601: sql: fix wrong representation of SHOW JOBS r=spaskob a=spaskob

`WHEN COMPLETE` was wrongly being put in the end of the string
representation of `SHOW JOBS WHEN COMPLETE SELECT...` stmt.

Fixes: #40534.

Release note (bug fix): None

Co-authored-by: Rebecca Taft <[email protected]>
Co-authored-by: Spas Bojanov <[email protected]>
@craig
Copy link
Contributor

craig bot commented Sep 9, 2019

Build succeeded

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.

sql: internal error: needed column not produced by group-by input
3 participants