cherrypick-2.0: sql: fix cockroach dump
for sequences
#23062
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Picks #23051.
Prior to this patch,
cockroach dump
would attempt to determine theincrement for a given sequence using a query to
pg_catalog.pg_sequences
. Unfortunately this query did not constraintthe 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
queryappropriately.
A related issue, which also prevented earlier recognition of this bug,
is that the object
sqlConn
internal to thecli
package (thatattempts to emulate
sql.Conn
over the in-memory connection to thetest server) is not appropriately checking that queries passed to its
QueryRow
method only return 1 row. If it did, it would havedetermined 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 sequenceswith non-default parameters.
cc @cockroachdb/release