Skip to content

sql: fix cockroach dump for sequences#23051

Merged
knz merged 2 commits intocockroachdb:masterfrom
knz:20180225-fix-sequence-dump
Feb 25, 2018
Merged

sql: fix cockroach dump for sequences#23051
knz merged 2 commits intocockroachdb:masterfrom
knz:20180225-fix-sequence-dump

Conversation

@knz
Copy link
Copy Markdown
Contributor

@knz knz commented Feb 25, 2018

Prior to this patch, cockroach dump would attempt to determine the
increment for a given sequence using a query to
pg_catalog.pg_sequences. Unfortunately this query did not constraint
the OID to the sequence considered, and so it would always retrieve
the metata for the 1st sequence defined in the cluster overall, not
the sequence being considered. This wasn't visible in tests because
the tests all used the default sequence parameters.

This patch fixes the issue by constraining the pg_sequence query
appropriately.

A related issue, which also prevented earlier recognition of this bug,
is that the object sqlConn internal to the cli package (that
attempts to emulate sql.Conn over the in-memory connection to the
test server) is not appropriately checking that queries passed to its
QueryRow method only return 1 row. If it did, it would have
determined earlier that there were multiple results for the query on
pg_sequences. This will be addressed separately.

Release note (bug fix): cockroach dump is now able to dump sequences
with non-default parameters.

Prior to this patch, `cockroach dump` would attempt to determine the
increment for a given sequence using a query to
`pg_catalog.pg_sequences`. Unfortunately this query did not constraint
the OID to the sequence considered, and so it would always retrieve
the metata for the 1st sequence defined in the cluster overall, not
the sequence being considered. This wasn't visible in tests because
the tests all used the default sequence parameters.

This patch fixes the issue by constraining the `pg_sequence` query
appropriately.

A related issue, which also prevented earlier recognition of this bug,
is that the object `sqlConn` internal to the `cli` package (that
attempts to emulate `sql.Conn` over the in-memory connection to the
test server) is not appropriately checking that queries passed to its
`QueryRow` method only return 1 row. If it did, it would have
determined earlier that there were multiple results for the query on
`pg_sequences`. This will be addressed separately.

Release note (bug fix): `cockroach dump` is now able to dump sequences
with non-default parameters.
@knz knz requested a review from vilterp February 25, 2018 00:08
@knz knz requested a review from a team as a code owner February 25, 2018 00:08
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@knz knz requested a review from a team February 25, 2018 00:43
@vilterp
Copy link
Copy Markdown
Contributor

vilterp commented Feb 25, 2018

:lgtm: thank you for finding and fixing this! Can't believe I made such a basic mistake.

Looking forward to @justinj's #22403, which will make it faster to write good tests. Thanks for the QueryRow fix as well.


Reviewed 2 of 2 files at r1, 1 of 1 files at r2.
Review status: :shipit: all files reviewed at latest revision, all discussions resolved, all commit checks successful.


Comments from Reviewable

@knz
Copy link
Copy Markdown
Contributor Author

knz commented Feb 25, 2018

TFYR!

@knz knz merged commit ffdf424 into cockroachdb:master Feb 25, 2018
@knz knz deleted the 20180225-fix-sequence-dump branch April 27, 2018 18:42
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.

3 participants