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

colexec: fix type management in execplan #47938

Merged
merged 1 commit into from Apr 27, 2020

Conversation

yuzefovich
Copy link
Member

@yuzefovich yuzefovich commented Apr 22, 2020

This commit fixes the column type management in execplan.go by
requiring that we allocate new []types.T slice whenever a projecting
operator wants to append a column to the passed-in type schema. Previous
behavior could result in "type schema corruption" (when it was captured
by batchSchemaPrefixEnforcer and possibly in other places), and this
is now fixed. The requirement is enforced by a linter rule that
prohibits code lines that have yps = append( or ypes = append(
inside (this is not perfect, but it should be good enough).

Fixes: #47889.

Release note (bug fix): Previously, CockroachDB could return an internal
error when performing a query with CASE, AND, OR operators in some cases
when it was executed via the vectorized engine, and this has been fixed.

@yuzefovich yuzefovich requested review from asubiotto and a team April 22, 2020 20:18
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@yuzefovich
Copy link
Member Author

My guess is that there have been some recent changes in the optimizer so that a new plan is now generated which exposed this problem (I didn't fully investigate this). The problem itself was introduced when we added batchSchemaPrefixEnforcer.

@yuzefovich
Copy link
Member Author

cc @jordanlewis

@yuzefovich yuzefovich force-pushed the fix-type-schema branch 2 times, most recently from 562cfaf to 1a8f3d9 Compare April 23, 2020 18:04
@yuzefovich
Copy link
Member Author

Updated the code as we discussed.

@yuzefovich yuzefovich changed the title colexec: fix type management in filter expr planning colexec: fix type management in execplan Apr 24, 2020
Copy link
Contributor

@asubiotto asubiotto 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 @yuzefovich)


pkg/sql/colexec/execplan.go, line 218 at r1 (raw file):

				return false, errors.Newf("aggregates with arguments not supported")
			}
			inputTypes := make([]types.T, len(agg.ColIdx))

I think we should keep cases like this untouched. I would say we only pass in a copy if those types are referenced for later use? That's maybe not as clear though.


pkg/sql/colexec/execplan.go, line 523 at r1 (raw file):

// described below.
//
// Without explicit new allocations, tt is possible that planSelectionOperators

nit: s/tt/it

Copy link
Member Author

@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.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @asubiotto and @yuzefovich)


pkg/sql/colexec/execplan.go, line 218 at r1 (raw file):

Previously, asubiotto (Alfonso Subiotto Marqués) wrote…

I think we should keep cases like this untouched. I would say we only pass in a copy if those types are referenced for later use? That's maybe not as clear though.

It's quite unclear - this would imply that the caller (execplan.go) would need to know whether each callee (constructors of operators) stores the passed-in types and how those are used. I think it could be error-prone, and the situation would be pretty much the same as before this PR.

I agree it is a little unfortunate that cases like this need to be modified, but I'd rather lean on the safe side and enforce the linter rule throughout this file rather than trying to decide whether a copy is necessary or not - always make a copy and don't think about it. The performance implications should be very minor in the grand scheme of things.

Copy link
Contributor

@asubiotto asubiotto left a comment

Choose a reason for hiding this comment

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

:lgtm:

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

Copy link
Member Author

@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.

TFTR!

bors r+

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


pkg/sql/colexec/execplan.go, line 523 at r1 (raw file):

Previously, asubiotto (Alfonso Subiotto Marqués) wrote…

nit: s/tt/it

Done.

@blathers-crl
Copy link

blathers-crl bot commented Apr 27, 2020

❌ The GitHub CI (Cockroach) build has failed on 7253fa45.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan.

@yuzefovich
Copy link
Member Author

CI flake.

bors r+

This commit fixes the column type management in `execplan.go` by
requiring that we allocate new `[]types.T` slice whenever a projecting
operator wants to append a column to the passed-in type schema. Previous
behavior could result in "type schema corruption" (when it was captured
by `batchSchemaPrefixEnforcer` and possibly in other places), and this
is now fixed. The requirement is enforced by a linter rule that
prohibits code lines that have `yps = append(` or `ypes = append(`
inside (this is not perfect, but it should be good enough).

Release note (bug fix): Previously, CockroachDB could return an internal
error when performing a query with CASE, AND, OR operators in some cases
when it was executed via the vectorized engine, and this has been fixed.
@yuzefovich
Copy link
Member Author

bors r-

@yuzefovich
Copy link
Member Author

bors r+

@blathers-crl
Copy link

blathers-crl bot commented Apr 27, 2020

❌ The GitHub CI (Cockroach) build has failed on 01860973.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan.

@craig
Copy link
Contributor

craig bot commented Apr 27, 2020

Build succeeded

@craig craig bot merged commit 0b797a6 into cockroachdb:master Apr 27, 2020
@yuzefovich yuzefovich deleted the fix-type-schema branch April 27, 2020 18:50
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.

roachtest: tpcdsvec failed
3 participants