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 simpleProjectOp in some cases #45690

Merged
merged 1 commit into from
Mar 5, 2020

Conversation

yuzefovich
Copy link
Member

simpleProjectOp doesn't work well together with unordered
synchronizers (and possibly other components that can return
coldata.Batches that point to different regions of memory). The
problem is that simpleProjectOp adds a projectingBatch wrapper on
top its input batch, but if "different internally" batches come in, the
wrapper is not updated/reset. Now this is fixed by tracking different
input batches and having a separate projectingBatch for them.

Fixes: #45686.

Release note (bug fix): Previously, an internal error could occur in
CockroachDB when executing queries via the vectorized engine in queries
that contained unordered synchronizers, and now this has been fixed.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

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.

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


pkg/sql/colexec/simple_project.go, line 110 at r1 (raw file):

		// We pass in a copy of d.projection just to be safe.
		projBatch = newProjectionBatch(append([]uint32{}, d.projection...))
		d.batches[batch] = projBatch

Do we have any guarantee that this map will grow only as large as there are nodes in the cluster? I'm worried about potential cases in which batch pointers always differ. Don't know when that would be the case though, since when we buffer batches, we usually copy to an output batch (at least in the sorter), right?

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 @jordanlewis)


pkg/sql/colexec/simple_project.go, line 110 at r1 (raw file):

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

Do we have any guarantee that this map will grow only as large as there are nodes in the cluster? I'm worried about potential cases in which batch pointers always differ. Don't know when that would be the case though, since when we buffer batches, we usually copy to an output batch (at least in the sorter), right?

We don't have such guarantee. In theory, if an upstream operator instantiates a new batch on its every Next call, this map can grow unboundedly. In practice though I also can't think of an operator that behaves this way.

@jordanlewis
Copy link
Member

Maybe another way to fix this could be during planning. We have full knowledge of both arms of the unordered synchronizer. Could we plan the simple project operators before feeding into the unordered synchronizer? Or does that make no sense.

@yuzefovich
Copy link
Member Author

yuzefovich commented Mar 4, 2020

Possibly my explanation and the example are somewhat misleading. I believe the root of the problem is with simpleProjectOp (and the unordered synchronizers in combination with some projecting operators expose that). Let's talk through it during the standup.

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:

Reviewed 1 of 2 files at r1, 2 of 2 files at r2.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @asubiotto, @jordanlewis, and @yuzefovich)


pkg/sql/colexec/simple_project.go, line 102 at r2 (raw file):

		projection:                 projection,
		batches:                    make(map[coldata.Batch]*projectingBatch),
		numBatchesLoggingThreshold: 4,

I would maybe make this larger, say 128. I think 4 could be expected.

`simpleProjectOp` doesn't work well together with unordered
synchronizers (and possibly other components that can return
`coldata.Batch`es that point to different regions of memory). The
problem is that `simpleProjectOp` adds a `projectingBatch` wrapper on
top its input batch, but if "different internally" batches come in, the
wrapper is not updated/reset. Now this is fixed by tracking different
input batches and having a separate `projectingBatch` for them.

Release note (bug fix): Previously, an internal error could occur in
CockroachDB when executing queries via the vectorized engine in queries
that contained unordered synchronizers, and now this has been fixed.
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 and @jordanlewis)


pkg/sql/colexec/simple_project.go, line 102 at r2 (raw file):

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

I would maybe make this larger, say 128. I think 4 could be expected.

Done.

@craig
Copy link
Contributor

craig bot commented Mar 4, 2020

Build failed (retrying...)

@craig
Copy link
Contributor

craig bot commented Mar 4, 2020

Build failed (retrying...)

@yuzefovich
Copy link
Member Author

bors r+

@craig
Copy link
Contributor

craig bot commented Mar 5, 2020

Build succeeded

@craig craig bot merged commit f3e1b90 into cockroachdb:master Mar 5, 2020
@yuzefovich yuzefovich deleted the fix-simple-project branch March 5, 2020 03:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

colexec: problem with simpleProjectOp
4 participants