Skip to content

sql: fix a bug with unset type metadata on some join processors#51481

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
rohany:joiner-panic
Jul 16, 2020
Merged

sql: fix a bug with unset type metadata on some join processors#51481
craig[bot] merged 1 commit intocockroachdb:masterfrom
rohany:joiner-panic

Conversation

@rohany
Copy link
Copy Markdown
Contributor

@rohany rohany commented Jul 15, 2020

Fixes #51474.

This commit fixes a bug where some joiner processors would not hydrate
their input type metadata in certain cases, leading to panics at
execution.

Release note: None

@rohany rohany requested a review from yuzefovich July 15, 2020 21:12
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

Copy link
Copy Markdown
Member

@yuzefovich yuzefovich left a comment

Choose a reason for hiding this comment

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

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


pkg/sql/rowexec/joinerbase.go, line 115 at r1 (raw file):

	// If we didn't pass all of the input types into ProcessorBase.Init() we could
	// be missing out on hydrating some of the input types. So hydrate the rest here.
	if len(outputTypes) < len(condTypes) {

Hm, this seems error-prone - we added the hydration to ProcessorBase.InitWithEvalCtx with the assumption that pretty much all processors do call that method, and here we found a case when types argument of that method might not contain the types of all internal columns of a processor. I'm worried that there might be other cases apart from this joinerbase when such scenario can arise although I can't immediately think of any such cases.

Maybe a better place would be to do this hydration in ExprHelper.Init? Do we cache the fact that the hydration has been performed on a particular types.T object? If so, we could just run the hydration on all of the types in that method.

@rohany
Copy link
Copy Markdown
Contributor Author

rohany commented Jul 15, 2020

ExprHelper.init is only called on with types passed to processorbase.Init. I think that this is just a oneoff case that needs to be considered. The hash joiner did the right job of passing all its types to joinerBase.Init, the joinerBase didn't finish the job.

Do we cache the fact that the hydration has been performed on a particular types.T object?

yeah we do

Copy link
Copy Markdown
Member

@yuzefovich yuzefovich left a comment

Choose a reason for hiding this comment

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

ExprHelper.init is only called on with types passed to processorbase.Init.

That's not always true - take a look at joinerBase.onCond.Init. Another possible cases where this bug might occur are invertedJoiner and projectSetProcessor.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @rohany)

@rohany
Copy link
Copy Markdown
Contributor Author

rohany commented Jul 16, 2020

Oh, i didn't see that. But I'm still not convinced exprhelper.Init is the right place to do this, since it doesn't look like we are guaranteed to call it -- if there are no filters or renders then we wouldn't call it in some procs.

@yuzefovich
Copy link
Copy Markdown
Member

I guess my point is that putting the hydration into ExprHelper.Init seems more reliable than performing the hydration explicitly in joinerBase.init (since the latter also calls the former).

@rohany
Copy link
Copy Markdown
Contributor Author

rohany commented Jul 16, 2020

I guess my point is that putting the hydration into ExprHelper.Init seems more reliable than performing the hydration explicitly in joinerBase.init (since the latter also calls the former).

Oh you're not suggesting to not hydrate in processorbase -- you're just saying to do it both in processor base and exprhelper?

@yuzefovich
Copy link
Copy Markdown
Member

Actually, maybe a better model is to do what we have in the colexec package - perform the hydration on input sync specs and "table readers" (all processors that interact with tables directly, like tableReader, interleavedReaderJoiner)?

@yuzefovich
Copy link
Copy Markdown
Member

you're just saying to do it both in processor base and exprhelper

Yeah, basically, just to be safer.

@rohany rohany force-pushed the joiner-panic branch 3 times, most recently from e4fcc8f to 289583f Compare July 16, 2020 17:26
@rohany rohany requested a review from yuzefovich July 16, 2020 20:53
Copy link
Copy Markdown
Member

@yuzefovich yuzefovich left a comment

Choose a reason for hiding this comment

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

:lgtm:

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


pkg/sql/rowflow/row_based_flow.go, line 272 at r2 (raw file):

			// Before we can safely use types we received over the wire in the
			// operators, we need to make sure they are hydrated. All operators other

nit: s/operators/processors/.

Fixes cockroachdb#51474.

This commit fixes a bug where some joiner processors would not hydrate
their input type metadata in certain cases, leading to panics at
execution.

Release note: None
@rohany
Copy link
Copy Markdown
Contributor Author

rohany commented Jul 16, 2020

nit: s/operators/processors/.

fixed

bors r=yuzefovich

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Jul 16, 2020

Build succeeded

@craig craig bot merged commit dc736e8 into cockroachdb:master Jul 16, 2020
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: enum metadata unset

3 participants