-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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 (bug): adnum in pg_attrdef and attnum in pg_attribute do not match. #46799
Comments
How does this issue relate to #39787? Running the example you gave against Postgres does seem to produce the same results:
|
@nvanbenschoten Ah if that's the case then this looks correct. adnum and attnum both are defined as |
Interesting. For these kinds of issues, it's usually best to present CRDB's output vs. Postgres'. PGs docs aren't always the easiest to understand and often have some ambiguity, but showing a difference in behavior that everyone can reproduce is irrefutable. Is there a sequence of queries that cause |
Oops forgot to include this example - but heres one where adnum and attnum differ on CRDB but not in Postgres. Postgres:
CRDB:
|
Got it, so to confirm, the bug is that cockroach/pkg/sql/pg_catalog.go Line 413 in 998abbe
|
Yep - planning to fix this in a separate PR for adding LogicalColumnIDs to ColumnDescriptors. LogicalColumnID is added to support swapping the order of columns to allow ALTER COLUMN TYPE (uses a column swap after creating and backfilling a column with the new type) |
Fixed by |
adnum in pg_attrdef should match attnum in pg_attribute.
In CRDB, the numbers can mismatch - this is because pg_attrdef currently uses the colNum (position in Columns slice in TableDescriptor) to generate adnum instead of ordinal_position / ColumnID.
In PG - adnum / attnum should match.
Here's an example where it differs from PG.
Postgres:
CRDB:
The text was updated successfully, but these errors were encountered: