Skip to content

sql: allow references to top-level WITH from apply-join#65550

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
RaduBerinde:cte-from-apply
May 22, 2021
Merged

sql: allow references to top-level WITH from apply-join#65550
craig[bot] merged 1 commit intocockroachdb:masterfrom
RaduBerinde:cte-from-apply

Conversation

@RaduBerinde
Copy link
Copy Markdown
Member

This change fixes an unsupported case where the "inner" plan of an
apply-join refers to a WITH that is above the apply join. This change
adds support for this case by populating the necessary metadata in the
memo and the execbuilder.

Release note (sql change): references to WITH expressions from
correlated subqueries are now always supported.

@RaduBerinde RaduBerinde requested review from mgartner and rytaft May 21, 2021 03:28
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@RaduBerinde
Copy link
Copy Markdown
Member Author

This is needed for the graphile introspection query.

Copy link
Copy Markdown
Contributor

@mgartner mgartner left a comment

Choose a reason for hiding this comment

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

Cool! :lgtm:

Reviewed 2 of 2 files at r1.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @rytaft)

Copy link
Copy Markdown
Contributor

@mgartner mgartner left a comment

Choose a reason for hiding this comment

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

Sorry, left a few questions/nits.

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


pkg/sql/opt/exec/execbuilder/relational.go, line 885 at r1 (raw file):

		o.Init(b.evalCtx, b.catalog)
		f := o.Factory()
		md := f.Memo().Metadata()

nit: md := f.Metadata()


pkg/sql/opt/exec/execbuilder/relational.go, line 889 at r1 (raw file):

			withID := withExprs[i].id
			memoExpr := b.mem.Metadata().WithBinding(withID)
			md.AddWithBinding(withID, memoExpr)

If the new lines below allow referrign to "outer" Withs, what does adding the with bindings do here?


pkg/sql/opt/exec/execbuilder/relational.go, line 909 at r1 (raw file):

					if withExprs[i].id == t.With {
						memoExpr := b.mem.Metadata().WithBinding(t.With)
						f.Metadata().AddWithBinding(t.With, memoExpr)

nit: md.AddWithBinding(...)

This change fixes an unsupported case where the "inner" plan of an
apply-join refers to a WITH that is above the apply join. This change
adds support for this case by populating the necessary metadata in the
memo and the execbuilder.

Release note (sql change): references to WITH expressions from
correlated subqueries are now always supported.
Copy link
Copy Markdown
Member Author

@RaduBerinde RaduBerinde left a comment

Choose a reason for hiding this comment

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

TFTR!

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


pkg/sql/opt/exec/execbuilder/relational.go, line 889 at r1 (raw file):

Previously, mgartner (Marcus Gartner) wrote…

If the new lines below allow referrign to "outer" Withs, what does adding the with bindings do here?

Oops, I meant to remove this. This doesn't do anything because CopyAndReplace clears the metadata.

Copy link
Copy Markdown
Contributor

@mgartner mgartner 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! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @mgartner and @rytaft)


pkg/sql/opt/exec/execbuilder/relational.go, line 889 at r1 (raw file):

Previously, RaduBerinde wrote…

Oops, I meant to remove this. This doesn't do anything because CopyAndReplace clears the metadata.

👍

Copy link
Copy Markdown
Member Author

@RaduBerinde RaduBerinde left a comment

Choose a reason for hiding this comment

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

bors r+

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

@craig
Copy link
Copy Markdown
Contributor

craig bot commented May 22, 2021

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.

3 participants