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: enable 1PC optimization for UPSERT #13500

Merged
merged 1 commit into from Feb 12, 2017

Conversation

petermattis
Copy link
Collaborator

@petermattis petermattis commented Feb 9, 2017

When an UPSERT is being run as part of an auto-commit transaction,
commit the transaction when running the batch.


This change is Reviewable

@petermattis
Copy link
Collaborator Author

Do we have any tests for the auto-commit code path for INSERT? A quick scan didn't reveal anything, but perhaps I just missed it.

@petermattis
Copy link
Collaborator Author

Review status: 0 of 2 files reviewed at latest revision, 1 unresolved discussion, some commit checks pending.


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

		}
		if err != nil {
			return sqlbase.ConvertBatchError(tu.ri.helper.tableDesc, tu.fastPathBatch)

Noticed we had this in tableInserter.finalize. Is it needed here too? I suppose for the upsert fast-path we can't get conditional put errors because we're not performing conditional puts.


Comments from Reviewable

@knz
Copy link
Contributor

knz commented Feb 9, 2017

No we don't have separate tests for the INSERT auto-commit apparently.

:lgtm: for the rest.


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


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

Previously, petermattis (Peter Mattis) wrote…

Noticed we had this in tableInserter.finalize. Is it needed here too? I suppose for the upsert fast-path we can't get conditional put errors because we're not performing conditional puts.

yeah as long as we don't allow upsert/update to update the PKs this check here is not strictly necessary.


Comments from Reviewable

@danhhz
Copy link
Contributor

danhhz commented Feb 9, 2017

:lgtm:

my upsert test is going in as soon as teamcity finishes if you want to piggy back on that test. seems like that would work


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


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

Previously, knz (kena) wrote…

yeah as long as we don't allow upsert/update to update the PKs this check here is not strictly necessary.

correct. the fast path doesn't use cput and can't change a pk


Comments from Reviewable

@petermattis petermattis force-pushed the pmattis/1pc-upsert branch 2 times, most recently from d3793d2 to e8c0c38 Compare February 9, 2017 16:33
@petermattis
Copy link
Collaborator Author

Enhanced TestUpsertFastPath to check for 1PC transactions and enabled 1PC transactions for slow-path UPSERT (found by the test!).

PTAL


Review status: 1 of 3 files reviewed at latest revision, 1 unresolved discussion.


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

Previously, danhhz (Daniel Harrison) wrote…

correct. the fast path doesn't use cput and can't change a pk

Ok, the call to sqlbase.ConvertBatchError was removed here.


Comments from Reviewable

@danhhz
Copy link
Contributor

danhhz commented Feb 9, 2017

Review status: 1 of 3 files reviewed at latest revision, 3 unresolved discussions, some commit checks pending.


pkg/sql/tablewriter.go, line 335 at r2 (raw file):

	}

	if tu.autoCommit {

I think this one is not safe. In theory, flush is called once per N rows processed by upsert (though it seems actually doing this got left as a TODO). This would commit the txn and then try to keep using it, which IIUC is not okay


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

	}
	if s := atomic.LoadUint64(&beginTxn); s != 0 {
		t.Errorf("expected no begin-txn (1PC) but got %d", s)

we should probably add one that does expect a begin-txn


Comments from Reviewable

When an UPSERT is being run as part of an auto-commit transaction,
commit the transaction when running the batch.
@petermattis
Copy link
Collaborator Author

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


pkg/sql/tablewriter.go, line 335 at r2 (raw file):

Previously, danhhz (Daniel Harrison) wrote…

I think this one is not safe. In theory, flush is called once per N rows processed by upsert (though it seems actually doing this got left as a TODO). This would commit the txn and then try to keep using it, which IIUC is not okay

I've added a finalize parameter to flush and set it to true from the one call site. Hopefully this will future proof the code here.


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

Previously, danhhz (Daniel Harrison) wrote…

we should probably add one that does expect a begin-txn

Done.


Comments from Reviewable

@danhhz
Copy link
Contributor

danhhz commented Feb 10, 2017

:lgtm:


Review status: 1 of 3 files reviewed at latest revision, 3 unresolved discussions, some commit checks pending.


Comments from Reviewable

@petermattis petermattis merged commit d101010 into cockroachdb:master Feb 12, 2017
@petermattis petermattis deleted the pmattis/1pc-upsert branch February 12, 2017 01:24
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.

None yet

3 participants