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

sql: fix UPSERT fast path regression #13488

Merged
merged 1 commit into from Feb 9, 2017
Merged

Conversation

danhhz
Copy link
Contributor

@danhhz danhhz commented Feb 8, 2017

And add a test to prevent future regressions.

A second bug was unearthed which caused the upsert fast path to be
incorrect during schema changes. This was caught by the schema change
tests when the regression was fixed.

Closes #13437.

cc @petermattis


This change is Reviewable

Copy link
Collaborator

@petermattis petermattis left a comment

Choose a reason for hiding this comment

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

LGTM

tu.evaler != nil && tu.evaler.isIdentityEvaler()
tu.evaler != nil && tu.evaler.isIdentityEvaler() &&
// Disable the upsert fast path when columns or indexes are being added
// or dropped.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is mildly unfortunate as the fast-path is ~2x faster than the slow-path. So adding a column will cause performance to temporarily drop in half? Is there any hope to fix this eventually? Perhaps file an issue.

filter := func(filterArgs storagebase.FilterArgs) *roachpb.Error {
if filterArgs.Req.Method() == roachpb.Scan &&
bytes.Compare(filterArgs.Req.Header().Key, keys.UserTableDataMin) >= 0 {
scans++
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm mildly surprised this doesn't need to be done atomically.

@danhhz
Copy link
Contributor Author

danhhz commented Feb 8, 2017

Review status: 0 of 4 files reviewed at latest revision, 2 unresolved discussions.


pkg/sql/tablewriter.go, line 231 at r1 (raw file):

Previously, petermattis (Peter Mattis) wrote…

This is mildly unfortunate as the fast-path is ~2x faster than the slow-path. So adding a column will cause performance to temporarily drop in half? Is there any hope to fix this eventually? Perhaps file an issue.

IIRC, when you're adding a column, you can't set it as a user while the schema change is being run. Which I think makes it impossible to fast path during that time


pkg/sql/upsert_test.go, line 42 at r1 (raw file):

Previously, petermattis (Peter Mattis) wrote…

I'm mildly surprised this doesn't need to be done atomically.

Same. atomic'd it


Comments from Reviewable

@petermattis
Copy link
Collaborator

:lgtm:


Review status: 0 of 4 files reviewed at latest revision, 1 unresolved discussion, all commit checks successful.


pkg/sql/tablewriter.go, line 231 at r1 (raw file):

Previously, danhhz (Daniel Harrison) wrote…

IIRC, when you're adding a column, you can't set it as a user while the schema change is being run. Which I think makes it impossible to fast path during that time

Ok, thinking about it more this makes sense, but shouldn't the conditional be part of the next line. What do mutations have to do with allColsIdentityExpr. I think you should let the value remain the same but change the following line to:

if len(tu.tableDesc.Indexes) == 0 && len(tu.tableDesc.Mutations) == 0 && allColsIdentityExpr {

Comments from Reviewable

@knz
Copy link
Contributor

knz commented Feb 9, 2017

:lgtm_strong:


Reviewed 3 of 4 files at r1, 1 of 1 files at r2.
Review status: all files reviewed at latest revision, 1 unresolved discussion, all commit checks successful.


pkg/sql/upsert_test.go, line 43 at r2 (raw file):

		if filterArgs.Req.Method() == roachpb.Scan &&
			bytes.Compare(filterArgs.Req.Header().Key, keys.UserTableDataMin) >= 0 {
			atomic.AddUint64(&scans, 1)

That's a very clever approach to testing this. TIL!


Comments from Reviewable

@petermattis
Copy link
Collaborator

Review status: all files reviewed at latest revision, 1 unresolved discussion, all commit checks successful.


pkg/sql/upsert_test.go, line 43 at r2 (raw file):

Previously, knz (kena) wrote…

That's a very clever approach to testing this. TIL!

Yes, I can probably enhance this to verify that we have a 1PC transaction. See #13500.


Comments from Reviewable

And add a test to prevent future regressions.

A second bug was unearthed which caused the upsert fast path to be
incorrect during schema changes. This was caught by the schema change
tests when the regression was fixed.

Closes cockroachdb#13437.
@danhhz
Copy link
Contributor Author

danhhz commented Feb 9, 2017

Thanks for the reviews!


Review status: 3 of 4 files reviewed at latest revision, 2 unresolved discussions.


pkg/sql/tablewriter.go, line 231 at r1 (raw file):

Previously, petermattis (Peter Mattis) wrote…

Ok, thinking about it more this makes sense, but shouldn't the conditional be part of the next line. What do mutations have to do with allColsIdentityExpr. I think you should let the value remain the same but change the following line to:

if len(tu.tableDesc.Indexes) == 0 && len(tu.tableDesc.Mutations) == 0 && allColsIdentityExpr {

I was thinking of when the mutation is a column, then it can't be specified as the identity expr by the user. But you're right that indexes don't fall into this. Moved.

I also improved this comment a bit


Comments from Reviewable

@danhhz danhhz merged commit 2aa1ee7 into cockroachdb:master Feb 9, 2017
@danhhz danhhz deleted the upsert branch February 9, 2017 15:34
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: UPSERT fast-path broken
3 participants