diff --git a/docs/generated/redact_safe.md b/docs/generated/redact_safe.md index 1f0980f720f1..916763f4e7ea 100644 --- a/docs/generated/redact_safe.md +++ b/docs/generated/redact_safe.md @@ -42,6 +42,7 @@ pkg/sql/sem/catid/ids.go | `ConstraintID` pkg/sql/sem/catid/ids.go | `DescID` pkg/sql/sem/catid/ids.go | `FamilyID` pkg/sql/sem/catid/ids.go | `IndexID` +pkg/sql/sem/catid/ids.go | `PGAttributeNum` pkg/sql/sqlliveness/sqlliveness.go | `SessionID` pkg/storage/enginepb/mvcc.go | `TxnEpoch` pkg/storage/enginepb/mvcc.go | `TxnSeq` diff --git a/pkg/ccl/schemachangerccl/testdata/decomp/multiregion b/pkg/ccl/schemachangerccl/testdata/decomp/multiregion index 94f3e898e587..552aa0008d07 100644 --- a/pkg/ccl/schemachangerccl/testdata/decomp/multiregion +++ b/pkg/ccl/schemachangerccl/testdata/decomp/multiregion @@ -69,11 +69,13 @@ ElementState: Status: PUBLIC - Column: columnId: 1 + pgAttributeNum: 1 tableId: 110 Status: PUBLIC - Column: columnId: 2 isHidden: true + pgAttributeNum: 2 tableId: 110 Status: PUBLIC - PrimaryIndex: @@ -189,11 +191,13 @@ ElementState: Status: PUBLIC - Column: columnId: 1 + pgAttributeNum: 1 tableId: 109 Status: PUBLIC - Column: columnId: 2 isHidden: true + pgAttributeNum: 2 tableId: 109 Status: PUBLIC - PrimaryIndex: @@ -311,15 +315,18 @@ ElementState: Status: PUBLIC - Column: columnId: 1 + pgAttributeNum: 1 tableId: 108 Status: PUBLIC - Column: columnId: 2 + pgAttributeNum: 2 tableId: 108 Status: PUBLIC - Column: columnId: 3 isHidden: true + pgAttributeNum: 3 tableId: 108 Status: PUBLIC - PrimaryIndex: diff --git a/pkg/ccl/schemachangerccl/testdata/decomp/partitioning b/pkg/ccl/schemachangerccl/testdata/decomp/partitioning index 1670ac80a40e..262244fa5bff 100644 --- a/pkg/ccl/schemachangerccl/testdata/decomp/partitioning +++ b/pkg/ccl/schemachangerccl/testdata/decomp/partitioning @@ -35,14 +35,17 @@ ElementState: Status: PUBLIC - Column: columnId: 1 + pgAttributeNum: 1 tableId: 104 Status: PUBLIC - Column: columnId: 2 + pgAttributeNum: 2 tableId: 104 Status: PUBLIC - Column: columnId: 3 + pgAttributeNum: 3 tableId: 104 Status: PUBLIC - PrimaryIndex: @@ -217,10 +220,12 @@ ElementState: Status: PUBLIC - Column: columnId: 1 + pgAttributeNum: 1 tableId: 105 Status: PUBLIC - Column: columnId: 2 + pgAttributeNum: 2 tableId: 105 Status: PUBLIC - PrimaryIndex: diff --git a/pkg/ccl/schemachangerccl/testdata/end_to_end/drop_multiregion b/pkg/ccl/schemachangerccl/testdata/end_to_end/drop_multiregion index 72ee0242f184..7e1bd14431e4 100644 --- a/pkg/ccl/schemachangerccl/testdata/end_to_end/drop_multiregion +++ b/pkg/ccl/schemachangerccl/testdata/end_to_end/drop_multiregion @@ -197,6 +197,7 @@ upsert descriptor #108 + - elementProto: + column: + columnId: 1 + + pgAttributeNum: 1 + tableId: 108 + metadata: + sourceElementId: 1 @@ -238,6 +239,7 @@ upsert descriptor #108 + column: + columnId: 2 + isHidden: true + + pgAttributeNum: 2 + tableId: 108 + metadata: + sourceElementId: 1 @@ -537,6 +539,7 @@ upsert descriptor #108 - - elementProto: - column: - columnId: 1 + - pgAttributeNum: 1 - tableId: 108 - metadata: - sourceElementId: 1 @@ -578,6 +581,7 @@ upsert descriptor #108 - column: - columnId: 2 - isHidden: true + - pgAttributeNum: 2 - tableId: 108 - metadata: - sourceElementId: 1 @@ -873,6 +877,7 @@ upsert descriptor #109 + - elementProto: + column: + columnId: 1 + + pgAttributeNum: 1 + tableId: 109 + metadata: + sourceElementId: 1 @@ -1106,6 +1111,7 @@ upsert descriptor #109 - - elementProto: - column: - columnId: 1 + - pgAttributeNum: 1 - tableId: 109 - metadata: - sourceElementId: 1 diff --git a/pkg/internal/sqlsmith/schema.go b/pkg/internal/sqlsmith/schema.go index faf34e40c80e..5b1f9a38c5ac 100644 --- a/pkg/internal/sqlsmith/schema.go +++ b/pkg/internal/sqlsmith/schema.go @@ -503,7 +503,6 @@ var functions = func() map[tree.FunctionClass]map[oid.Oid][]function { "crdb_internal.start_replication_stream", "crdb_internal.replication_stream_progress", "crdb_internal.complete_replication_stream", - "crdb_internal.reset_multi_region_zone_configs_for_database", } { skip = skip || strings.Contains(def.Name, substr) } diff --git a/pkg/sql/catalog/colinfo/result_columns.go b/pkg/sql/catalog/colinfo/result_columns.go index 118124555a03..4d648dbe105d 100644 --- a/pkg/sql/catalog/colinfo/result_columns.go +++ b/pkg/sql/catalog/colinfo/result_columns.go @@ -60,7 +60,7 @@ func ResultColumnsFromColDescs( Typ: typ, Hidden: colDesc.Hidden, TableID: tableID, - PGAttributeNum: colDesc.GetPGAttributeNum(), + PGAttributeNum: uint32(colDesc.GetPGAttributeNum()), } } return cols diff --git a/pkg/sql/catalog/descpb/column.go b/pkg/sql/catalog/descpb/column.go index a42a1a8fb9bf..3b2f4166efdc 100644 --- a/pkg/sql/catalog/descpb/column.go +++ b/pkg/sql/catalog/descpb/column.go @@ -99,12 +99,12 @@ func (desc *ColumnDescriptor) CheckCanBeInboundFKRef() error { // GetPGAttributeNum returns the PGAttributeNum of the ColumnDescriptor // if the PGAttributeNum is set (non-zero). Returns the ID of the // ColumnDescriptor if the PGAttributeNum is not set. -func (desc ColumnDescriptor) GetPGAttributeNum() uint32 { +func (desc ColumnDescriptor) GetPGAttributeNum() PGAttributeNum { if desc.PGAttributeNum != 0 { return desc.PGAttributeNum } - return uint32(desc.ID) + return PGAttributeNum(desc.ID) } // SQLStringNotHumanReadable returns the SQL statement describing the column. diff --git a/pkg/sql/catalog/descpb/structured.go b/pkg/sql/catalog/descpb/structured.go index b36e231b9d46..a1adecc048df 100644 --- a/pkg/sql/catalog/descpb/structured.go +++ b/pkg/sql/catalog/descpb/structured.go @@ -119,6 +119,9 @@ const ( LatestIndexDescriptorVersion = PrimaryIndexWithStoredColumnsVersion ) +// PGAttributeNum is a custom type for ColumnDescriptor's PGAttributeNum field. +type PGAttributeNum = catid.PGAttributeNum + // ColumnID is a custom type for ColumnDescriptor IDs. type ColumnID = catid.ColumnID diff --git a/pkg/sql/catalog/descpb/structured.proto b/pkg/sql/catalog/descpb/structured.proto index 258beadae90b..5d33eac50e6a 100644 --- a/pkg/sql/catalog/descpb/structured.proto +++ b/pkg/sql/catalog/descpb/structured.proto @@ -198,7 +198,9 @@ message ColumnDescriptor { // This only differs from ID when the Column order is swapped or // the ColumnDescriptor must be remade while remaining visual ordering. // This does not exist in TableDescriptors pre 20.2. - optional uint32 pg_attribute_num = 13 [(gogoproto.nullable) = false, (gogoproto.customname) = "PGAttributeNum"]; + optional uint32 pg_attribute_num = 13 [(gogoproto.nullable) = false, + (gogoproto.customname) = "PGAttributeNum", + (gogoproto.casttype) = "PGAttributeNum"]; // Used to indicate column is used and dropped for ALTER COLUMN TYPE mutation. optional bool alter_column_type_in_progress = 14 [(gogoproto.nullable) = false]; diff --git a/pkg/sql/catalog/descriptor.go b/pkg/sql/catalog/descriptor.go index c11099f853ea..c188879c0090 100644 --- a/pkg/sql/catalog/descriptor.go +++ b/pkg/sql/catalog/descriptor.go @@ -526,6 +526,12 @@ type TableDescriptor interface { // provided target ID, in the canonical order. // If no column is found then an error is also returned. FindColumnWithID(id descpb.ColumnID) (Column, error) + + // FindColumnWithPGAttributeNum returns the first column found whose + // PGAttributeNum (if set, otherwise ID) matches the provider id. + // Error is returned if no column is found. + FindColumnWithPGAttributeNum(id descpb.PGAttributeNum) (Column, error) + // FindColumnWithName returns the first column found whose name matches the // provided target name, in the canonical order. // If no column is found then an error is also returned. diff --git a/pkg/sql/catalog/table_elements.go b/pkg/sql/catalog/table_elements.go index 142eb67c6aa6..b632a5902597 100644 --- a/pkg/sql/catalog/table_elements.go +++ b/pkg/sql/catalog/table_elements.go @@ -332,7 +332,7 @@ type Column interface { // GetPGAttributeNum returns the PGAttributeNum of the column descriptor // if the PGAttributeNum is set (non-zero). Returns the ID of the // column descriptor if the PGAttributeNum is not set. - GetPGAttributeNum() uint32 + GetPGAttributeNum() descpb.PGAttributeNum // IsSystemColumn returns true iff the column is a system column. IsSystemColumn() bool diff --git a/pkg/sql/catalog/tabledesc/column.go b/pkg/sql/catalog/tabledesc/column.go index ca72c27bba23..0d0bc0d83a1d 100644 --- a/pkg/sql/catalog/tabledesc/column.go +++ b/pkg/sql/catalog/tabledesc/column.go @@ -195,7 +195,7 @@ func (w column) CheckCanBeOutboundFKRef() error { // GetPGAttributeNum returns the PGAttributeNum of the column descriptor // if the PGAttributeNum is set (non-zero). Returns the ID of the // column descriptor if the PGAttributeNum is not set. -func (w column) GetPGAttributeNum() uint32 { +func (w column) GetPGAttributeNum() descpb.PGAttributeNum { return w.desc.GetPGAttributeNum() } diff --git a/pkg/sql/catalog/tabledesc/structured_test.go b/pkg/sql/catalog/tabledesc/structured_test.go index ca5546e61f4d..d09cf38692c2 100644 --- a/pkg/sql/catalog/tabledesc/structured_test.go +++ b/pkg/sql/catalog/tabledesc/structured_test.go @@ -917,7 +917,7 @@ func TestLogicalColumnID(t *testing.T) { actual := tests[i].desc.Columns[0].GetPGAttributeNum() expected := tests[i].expected - if expected != actual { + if expected != uint32(actual) { t.Fatalf("Expected PGAttributeNum to be %d, got %d.", expected, actual) } } diff --git a/pkg/sql/catalog/tabledesc/table_desc.go b/pkg/sql/catalog/tabledesc/table_desc.go index fb62cff41fd5..15d52d1ed3cd 100644 --- a/pkg/sql/catalog/tabledesc/table_desc.go +++ b/pkg/sql/catalog/tabledesc/table_desc.go @@ -539,6 +539,19 @@ func (desc *wrapper) FindColumnWithID(id descpb.ColumnID) (catalog.Column, error return nil, pgerror.Newf(pgcode.UndefinedColumn, "column-id \"%d\" does not exist", id) } +// FindColumnWithPGAttributeNum implements the TableDescriptor interface. +func (desc *wrapper) FindColumnWithPGAttributeNum( + id descpb.PGAttributeNum, +) (catalog.Column, error) { + for _, col := range desc.AllColumns() { + if col.GetPGAttributeNum() == id { + return col, nil + } + } + + return nil, pgerror.Newf(pgcode.UndefinedColumn, "column with logical order %q does not exist", id) +} + // FindColumnWithName implements the TableDescriptor interface. func (desc *wrapper) FindColumnWithName(name tree.Name) (catalog.Column, error) { for _, col := range desc.AllColumns() { diff --git a/pkg/sql/copy.go b/pkg/sql/copy.go index a619e3c6ae78..26984d1c58a0 100644 --- a/pkg/sql/copy.go +++ b/pkg/sql/copy.go @@ -214,7 +214,7 @@ func newCopyMachine( Name: col.GetName(), Typ: col.GetType(), TableID: tableDesc.GetID(), - PGAttributeNum: col.GetPGAttributeNum(), + PGAttributeNum: uint32(col.GetPGAttributeNum()), } } // If there are no column specifiers and we expect non-visible columns diff --git a/pkg/sql/indexbackfiller_test.go b/pkg/sql/indexbackfiller_test.go index 3c684f66f6f6..bd2a9bfb0ed5 100644 --- a/pkg/sql/indexbackfiller_test.go +++ b/pkg/sql/indexbackfiller_test.go @@ -298,7 +298,7 @@ INSERT INTO foo VALUES (1), (10), (100); Nullable: false, DefaultExpr: proto.String("42"), Hidden: false, - PGAttributeNum: uint32(mut.NextColumnID), + PGAttributeNum: descpb.PGAttributeNum(mut.NextColumnID), } mut.NextColumnID++ mut.AddColumnMutation(&columnWithDefault, descpb.DescriptorMutation_ADD) @@ -311,7 +311,7 @@ INSERT INTO foo VALUES (1), (10), (100); Nullable: false, ComputeExpr: proto.String("i + def"), Hidden: false, - PGAttributeNum: uint32(mut.NextColumnID), + PGAttributeNum: descpb.PGAttributeNum(mut.NextColumnID), } mut.NextColumnID++ mut.AddColumnMutation(&computedColumnNotInPrimaryIndex, descpb.DescriptorMutation_ADD) diff --git a/pkg/sql/logictest/testdata/logic_test/show_create b/pkg/sql/logictest/testdata/logic_test/show_create index bf17557d0f75..0e4d21073240 100644 --- a/pkg/sql/logictest/testdata/logic_test/show_create +++ b/pkg/sql/logictest/testdata/logic_test/show_create @@ -106,3 +106,37 @@ c CREATE TABLE public.c ( COMMENT ON TABLE public.c IS 'table'; COMMENT ON COLUMN public.c.a IS 'column'; COMMENT ON INDEX public.c@c_a_b_idx IS 'index' + +subtest alter_column_type_not_break_show_create + +statement ok +SET enable_experimental_alter_column_type_general = true; + +statement ok +CREATE TABLE t (c INT); + +statement ok +COMMENT ON COLUMN t.c IS 'first comment'; + +query T +SELECT @2 FROM [SHOW CREATE TABLE t]; +---- +CREATE TABLE public.t ( + c INT8 NULL, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT t_pkey PRIMARY KEY (rowid ASC) +); +COMMENT ON COLUMN public.t.c IS 'first comment' + +statement ok +ALTER TABLE t ALTER COLUMN c TYPE character varying; + +query T +SELECT @2 FROM [SHOW CREATE TABLE t]; +---- +CREATE TABLE public.t ( + c VARCHAR NULL, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT t_pkey PRIMARY KEY (rowid ASC) +); +COMMENT ON COLUMN public.t.c IS 'first comment' diff --git a/pkg/sql/opt/exec/execbuilder/testdata/show_trace_nonmetamorphic b/pkg/sql/opt/exec/execbuilder/testdata/show_trace_nonmetamorphic index ffdb70c97493..efaaf8590ba2 100644 --- a/pkg/sql/opt/exec/execbuilder/testdata/show_trace_nonmetamorphic +++ b/pkg/sql/opt/exec/execbuilder/testdata/show_trace_nonmetamorphic @@ -164,7 +164,7 @@ query TT $trace_query ---- sql query rows affected: 0 -commit sql txn Put /Table/3/1/109/2/1 -> table: parent_id:106 unexposed_parent_schema_id:107 columns: nullable:true hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > columns: nullable:true hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > columns: nullable:false default_expr:"unique_rowid()" hidden:true inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > next_column_id:4 families: next_family_id:1 primary_index: interleave:<> partitioning: type:FORWARD created_explicitly:false encoding_type:1 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:false created_at_nanos:... constraint_id:1 > next_index_id:2 privileges: users: owner_proto:"root" version:2 > next_mutation_id:1 format_version:3 state:DROP offline_reason:"" view_query:"" is_materialized_view:false declarative_schema_changer_state:<...> > metadata:<...> target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_nullable:true is_relation_being_dropped:true > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_nullable:true is_relation_being_dropped:true > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_relation_being_dropped:true > > metadata: target_status:ABSENT > targets: > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:DROPPED current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:WRITE_ONLY current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:WRITE_ONLY current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:WRITE_ONLY current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:VALIDATED current_statuses:ABSENT current_statuses:ABSENT target_ranks:0 target_ranks:1 target_ranks:2 target_ranks:3 target_ranks:4 target_ranks:5 target_ranks:6 target_ranks:7 target_ranks:8 target_ranks:9 target_ranks:10 target_ranks:11 target_ranks:12 target_ranks:13 target_ranks:14 target_ranks:15 target_ranks:16 target_ranks:17 target_ranks:18 target_ranks:19 target_ranks:20 target_ranks:21 target_ranks:22 target_ranks:23 relevant_statements: > authorization: > drop_time:... replacement_of: > audit_mode:DISABLED drop_job_id:0 create_query:"TABLE t.public.kv" create_as_of_time:<...> temporary:false partition_all_by:false exclude_data_from_backup:false next_constraint_id:2 > +commit sql txn Put /Table/3/1/109/2/1 -> table: parent_id:106 unexposed_parent_schema_id:107 columns: nullable:true hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > columns: nullable:true hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > columns: nullable:false default_expr:"unique_rowid()" hidden:true inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > next_column_id:4 families: next_family_id:1 primary_index: interleave:<> partitioning: type:FORWARD created_explicitly:false encoding_type:1 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:false created_at_nanos:... constraint_id:1 > next_index_id:2 privileges: users: owner_proto:"root" version:2 > next_mutation_id:1 format_version:3 state:DROP offline_reason:"" view_query:"" is_materialized_view:false declarative_schema_changer_state:<...> > metadata:<...> target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_nullable:true is_relation_being_dropped:true > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_nullable:true is_relation_being_dropped:true > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_relation_being_dropped:true > > metadata: target_status:ABSENT > targets: > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:DROPPED current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:WRITE_ONLY current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:WRITE_ONLY current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:WRITE_ONLY current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:VALIDATED current_statuses:ABSENT current_statuses:ABSENT target_ranks:0 target_ranks:1 target_ranks:2 target_ranks:3 target_ranks:4 target_ranks:5 target_ranks:6 target_ranks:7 target_ranks:8 target_ranks:9 target_ranks:10 target_ranks:11 target_ranks:12 target_ranks:13 target_ranks:14 target_ranks:15 target_ranks:16 target_ranks:17 target_ranks:18 target_ranks:19 target_ranks:20 target_ranks:21 target_ranks:22 target_ranks:23 relevant_statements: > authorization: > drop_time:... replacement_of: > audit_mode:DISABLED drop_job_id:0 create_query:"TABLE t.public.kv" create_as_of_time:<...> temporary:false partition_all_by:false exclude_data_from_backup:false next_constraint_id:2 > commit sql txn Del /NamespaceTable/30/1/106/107/"kv2"/4/1 statement ok @@ -205,7 +205,7 @@ query TT $trace_query ---- sql query rows affected: 0 -commit sql txn Put /Table/3/1/108/2/1 -> table: parent_id:106 unexposed_parent_schema_id:107 columns: nullable:false hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > columns: nullable:true hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > next_column_id:3 families: next_family_id:1 primary_index: interleave:<> partitioning: type:FORWARD created_explicitly:false encoding_type:1 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:false created_at_nanos:... constraint_id:1 > next_index_id:4 privileges: users: owner_proto:"root" version:2 > next_mutation_id:3 format_version:3 state:DROP offline_reason:"" view_query:"" is_materialized_view:false declarative_schema_changer_state:<...> > metadata:<...> target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_relation_being_dropped:true > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_nullable:true is_relation_being_dropped:true > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:DROPPED current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:WRITE_ONLY current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:WRITE_ONLY current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:VALIDATED current_statuses:ABSENT current_statuses:ABSENT target_ranks:0 target_ranks:1 target_ranks:2 target_ranks:3 target_ranks:4 target_ranks:5 target_ranks:6 target_ranks:7 target_ranks:8 target_ranks:9 target_ranks:10 target_ranks:11 target_ranks:12 target_ranks:13 target_ranks:14 target_ranks:15 target_ranks:16 target_ranks:17 target_ranks:18 relevant_statements: > authorization: > drop_time:... replacement_of: > audit_mode:DISABLED drop_job_id:0 create_query:"" create_as_of_time:<...> temporary:false partition_all_by:false exclude_data_from_backup:false next_constraint_id:4 > +commit sql txn Put /Table/3/1/108/2/1 -> table: parent_id:106 unexposed_parent_schema_id:107 columns: nullable:false hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > columns: nullable:true hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > next_column_id:3 families: next_family_id:1 primary_index: interleave:<> partitioning: type:FORWARD created_explicitly:false encoding_type:1 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:false created_at_nanos:... constraint_id:1 > next_index_id:4 privileges: users: owner_proto:"root" version:2 > next_mutation_id:3 format_version:3 state:DROP offline_reason:"" view_query:"" is_materialized_view:false declarative_schema_changer_state:<...> > metadata:<...> target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_relation_being_dropped:true > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_nullable:true is_relation_being_dropped:true > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:DROPPED current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:WRITE_ONLY current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:WRITE_ONLY current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:VALIDATED current_statuses:ABSENT current_statuses:ABSENT target_ranks:0 target_ranks:1 target_ranks:2 target_ranks:3 target_ranks:4 target_ranks:5 target_ranks:6 target_ranks:7 target_ranks:8 target_ranks:9 target_ranks:10 target_ranks:11 target_ranks:12 target_ranks:13 target_ranks:14 target_ranks:15 target_ranks:16 target_ranks:17 target_ranks:18 relevant_statements: > authorization: > drop_time:... replacement_of: > audit_mode:DISABLED drop_job_id:0 create_query:"" create_as_of_time:<...> temporary:false partition_all_by:false exclude_data_from_backup:false next_constraint_id:4 > commit sql txn Del /NamespaceTable/30/1/106/107/"kv"/4/1 # Check that session tracing does not inhibit the fast path for inserts & diff --git a/pkg/sql/pg_catalog.go b/pkg/sql/pg_catalog.go index 5c25f9f4784b..ff3588ec2dc8 100644 --- a/pkg/sql/pg_catalog.go +++ b/pkg/sql/pg_catalog.go @@ -454,7 +454,7 @@ https://www.postgresql.org/docs/12/catalog-pg-attribute.html`, // Columns for table. for _, column := range table.AccessibleColumns() { tableID := tableOid(table.GetID()) - if err := addColumn(column, tableID, column.GetPGAttributeNum()); err != nil { + if err := addColumn(column, tableID, uint32(column.GetPGAttributeNum())); err != nil { return err } } @@ -466,7 +466,7 @@ https://www.postgresql.org/docs/12/catalog-pg-attribute.html`, colID := index.GetKeyColumnID(i) idxID := h.IndexOid(table.GetID(), index.GetID()) column := table.PublicColumns()[columnIdxMap.GetDefault(colID)] - if err := addColumn(column, idxID, column.GetPGAttributeNum()); err != nil { + if err := addColumn(column, idxID, uint32(column.GetPGAttributeNum())); err != nil { return err } } diff --git a/pkg/sql/plan_opt.go b/pkg/sql/plan_opt.go index cf9d10839b60..7c2ebb9657d1 100644 --- a/pkg/sql/plan_opt.go +++ b/pkg/sql/plan_opt.go @@ -167,7 +167,7 @@ func (p *planner) prepareUsingOptimizer(ctx context.Context) (planFlags, error) column = catTable.getCol(colOrdinal) } if column != nil { - resultCols[i].PGAttributeNum = column.GetPGAttributeNum() + resultCols[i].PGAttributeNum = uint32(column.GetPGAttributeNum()) } else { resultCols[i].PGAttributeNum = uint32(tab.Column(colOrdinal).ColID()) } diff --git a/pkg/sql/resolver.go b/pkg/sql/resolver.go index 1f7e954fbfd5..e62910f6610b 100644 --- a/pkg/sql/resolver.go +++ b/pkg/sql/resolver.go @@ -443,7 +443,7 @@ func validateColumnForHasPrivilegeSpecifier( } if specifier.ColumnAttNum != nil { for _, col := range table.PublicColumns() { - if col.GetPGAttributeNum() == *specifier.ColumnAttNum { + if uint32(col.GetPGAttributeNum()) == *specifier.ColumnAttNum { return nil } } diff --git a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_add_column.go b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_add_column.go index 351f8db766b6..ecdfb0acf730 100644 --- a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_add_column.go +++ b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_add_column.go @@ -70,7 +70,7 @@ func alterTableAddColumn( IsHidden: desc.Hidden, IsInaccessible: desc.Inaccessible, GeneratedAsIdentityType: desc.GeneratedAsIdentityType, - PgAttributeNum: desc.PGAttributeNum, + PgAttributeNum: desc.GetPGAttributeNum(), }, } if ptr := desc.GeneratedAsIdentitySequenceOption; ptr != nil { diff --git a/pkg/sql/schemachanger/scbuild/testdata/drop_database b/pkg/sql/schemachanger/scbuild/testdata/drop_database index 326496b0376f..1e4b5e07b548 100644 --- a/pkg/sql/schemachanger/scbuild/testdata/drop_database +++ b/pkg/sql/schemachanger/scbuild/testdata/drop_database @@ -68,66 +68,82 @@ DROP DATABASE db1 CASCADE - [[Column:{DescID: 109, ColumnID: 1}, ABSENT], PUBLIC] details: columnId: 1 + pgAttributeNum: 1 tableId: 109 - [[Column:{DescID: 109, ColumnID: 2}, ABSENT], PUBLIC] details: columnId: 2 + pgAttributeNum: 2 tableId: 109 - [[Column:{DescID: 109, ColumnID: 3}, ABSENT], PUBLIC] details: columnId: 3 + pgAttributeNum: 3 tableId: 109 - [[Column:{DescID: 110, ColumnID: 1}, ABSENT], PUBLIC] details: columnId: 1 + pgAttributeNum: 1 tableId: 110 - [[Column:{DescID: 110, ColumnID: 2}, ABSENT], PUBLIC] details: columnId: 2 + pgAttributeNum: 2 tableId: 110 - [[Column:{DescID: 110, ColumnID: 3}, ABSENT], PUBLIC] details: columnId: 3 + pgAttributeNum: 3 tableId: 110 - [[Column:{DescID: 111, ColumnID: 1}, ABSENT], PUBLIC] details: columnId: 1 + pgAttributeNum: 1 tableId: 111 - [[Column:{DescID: 112, ColumnID: 1}, ABSENT], PUBLIC] details: columnId: 1 + pgAttributeNum: 1 tableId: 112 - [[Column:{DescID: 112, ColumnID: 2}, ABSENT], PUBLIC] details: columnId: 2 + pgAttributeNum: 2 tableId: 112 - [[Column:{DescID: 113, ColumnID: 1}, ABSENT], PUBLIC] details: columnId: 1 + pgAttributeNum: 1 tableId: 113 - [[Column:{DescID: 113, ColumnID: 2}, ABSENT], PUBLIC] details: columnId: 2 + pgAttributeNum: 2 tableId: 113 - [[Column:{DescID: 114, ColumnID: 1}, ABSENT], PUBLIC] details: columnId: 1 + pgAttributeNum: 1 tableId: 114 - [[Column:{DescID: 114, ColumnID: 2}, ABSENT], PUBLIC] details: columnId: 2 + pgAttributeNum: 2 tableId: 114 - [[Column:{DescID: 117, ColumnID: 1}, ABSENT], PUBLIC] details: columnId: 1 + pgAttributeNum: 1 tableId: 117 - [[Column:{DescID: 117, ColumnID: 2}, ABSENT], PUBLIC] details: columnId: 2 + pgAttributeNum: 2 tableId: 117 - [[Column:{DescID: 117, ColumnID: 3}, ABSENT], PUBLIC] details: columnId: 3 + pgAttributeNum: 3 tableId: 117 - [[ColumnComment:{DescID: 109, ColumnID: 1}, ABSENT], PUBLIC] details: diff --git a/pkg/sql/schemachanger/scbuild/testdata/drop_schema b/pkg/sql/schemachanger/scbuild/testdata/drop_schema index dcb169b60c68..228e7c2ab4a4 100644 --- a/pkg/sql/schemachanger/scbuild/testdata/drop_schema +++ b/pkg/sql/schemachanger/scbuild/testdata/drop_schema @@ -64,66 +64,82 @@ DROP SCHEMA defaultdb.SC1 CASCADE - [[Column:{DescID: 107, ColumnID: 1}, ABSENT], PUBLIC] details: columnId: 1 + pgAttributeNum: 1 tableId: 107 - [[Column:{DescID: 107, ColumnID: 2}, ABSENT], PUBLIC] details: columnId: 2 + pgAttributeNum: 2 tableId: 107 - [[Column:{DescID: 107, ColumnID: 3}, ABSENT], PUBLIC] details: columnId: 3 + pgAttributeNum: 3 tableId: 107 - [[Column:{DescID: 108, ColumnID: 1}, ABSENT], PUBLIC] details: columnId: 1 + pgAttributeNum: 1 tableId: 108 - [[Column:{DescID: 109, ColumnID: 1}, ABSENT], PUBLIC] details: columnId: 1 + pgAttributeNum: 1 tableId: 109 - [[Column:{DescID: 109, ColumnID: 2}, ABSENT], PUBLIC] details: columnId: 2 + pgAttributeNum: 2 tableId: 109 - [[Column:{DescID: 110, ColumnID: 1}, ABSENT], PUBLIC] details: columnId: 1 + pgAttributeNum: 1 tableId: 110 - [[Column:{DescID: 110, ColumnID: 2}, ABSENT], PUBLIC] details: columnId: 2 + pgAttributeNum: 2 tableId: 110 - [[Column:{DescID: 111, ColumnID: 1}, ABSENT], PUBLIC] details: columnId: 1 + pgAttributeNum: 1 tableId: 111 - [[Column:{DescID: 111, ColumnID: 2}, ABSENT], PUBLIC] details: columnId: 2 + pgAttributeNum: 2 tableId: 111 - [[Column:{DescID: 114, ColumnID: 1}, ABSENT], PUBLIC] details: columnId: 1 + pgAttributeNum: 1 tableId: 114 - [[Column:{DescID: 114, ColumnID: 2}, ABSENT], PUBLIC] details: columnId: 2 + pgAttributeNum: 2 tableId: 114 - [[Column:{DescID: 114, ColumnID: 3}, ABSENT], PUBLIC] details: columnId: 3 + pgAttributeNum: 3 tableId: 114 - [[Column:{DescID: 115, ColumnID: 1}, ABSENT], PUBLIC] details: columnId: 1 + pgAttributeNum: 1 tableId: 115 - [[Column:{DescID: 115, ColumnID: 2}, ABSENT], PUBLIC] details: columnId: 2 + pgAttributeNum: 2 tableId: 115 - [[Column:{DescID: 115, ColumnID: 3}, ABSENT], PUBLIC] details: columnId: 3 + pgAttributeNum: 3 tableId: 115 - [[ColumnComment:{DescID: 107, ColumnID: 1}, ABSENT], PUBLIC] details: diff --git a/pkg/sql/schemachanger/scbuild/testdata/drop_table b/pkg/sql/schemachanger/scbuild/testdata/drop_table index deae7b365f8e..9ca2fe7b46c6 100644 --- a/pkg/sql/schemachanger/scbuild/testdata/drop_table +++ b/pkg/sql/schemachanger/scbuild/testdata/drop_table @@ -46,34 +46,42 @@ DROP TABLE defaultdb.shipments CASCADE; - [[Column:{DescID: 109, ColumnID: 1}, ABSENT], PUBLIC] details: columnId: 1 + pgAttributeNum: 1 tableId: 109 - [[Column:{DescID: 109, ColumnID: 2}, ABSENT], PUBLIC] details: columnId: 2 + pgAttributeNum: 2 tableId: 109 - [[Column:{DescID: 109, ColumnID: 3}, ABSENT], PUBLIC] details: columnId: 3 + pgAttributeNum: 3 tableId: 109 - [[Column:{DescID: 109, ColumnID: 4}, ABSENT], PUBLIC] details: columnId: 4 + pgAttributeNum: 4 tableId: 109 - [[Column:{DescID: 109, ColumnID: 5}, ABSENT], PUBLIC] details: columnId: 5 + pgAttributeNum: 5 tableId: 109 - [[Column:{DescID: 109, ColumnID: 6}, ABSENT], PUBLIC] details: columnId: 6 + pgAttributeNum: 6 tableId: 109 - [[Column:{DescID: 111, ColumnID: 1}, ABSENT], PUBLIC] details: columnId: 1 + pgAttributeNum: 1 tableId: 111 - [[Column:{DescID: 111, ColumnID: 2}, ABSENT], PUBLIC] details: columnId: 2 + pgAttributeNum: 2 tableId: 111 - [[ColumnComment:{DescID: 109, ColumnID: 1}, ABSENT], PUBLIC] details: diff --git a/pkg/sql/schemachanger/scbuild/testdata/drop_view b/pkg/sql/schemachanger/scbuild/testdata/drop_view index 67e8dc5ec794..3de3ef611f97 100644 --- a/pkg/sql/schemachanger/scbuild/testdata/drop_view +++ b/pkg/sql/schemachanger/scbuild/testdata/drop_view @@ -12,6 +12,7 @@ DROP VIEW defaultdb.v1 - [[Column:{DescID: 105, ColumnID: 1}, ABSENT], PUBLIC] details: columnId: 1 + pgAttributeNum: 1 tableId: 105 - [[ColumnComment:{DescID: 105, ColumnID: 1}, ABSENT], PUBLIC] details: @@ -95,42 +96,52 @@ DROP VIEW defaultdb.v1 CASCADE - [[Column:{DescID: 105, ColumnID: 1}, ABSENT], PUBLIC] details: columnId: 1 + pgAttributeNum: 1 tableId: 105 - [[Column:{DescID: 106, ColumnID: 1}, ABSENT], PUBLIC] details: columnId: 1 + pgAttributeNum: 1 tableId: 106 - [[Column:{DescID: 106, ColumnID: 2}, ABSENT], PUBLIC] details: columnId: 2 + pgAttributeNum: 2 tableId: 106 - [[Column:{DescID: 107, ColumnID: 1}, ABSENT], PUBLIC] details: columnId: 1 + pgAttributeNum: 1 tableId: 107 - [[Column:{DescID: 107, ColumnID: 2}, ABSENT], PUBLIC] details: columnId: 2 + pgAttributeNum: 2 tableId: 107 - [[Column:{DescID: 108, ColumnID: 1}, ABSENT], PUBLIC] details: columnId: 1 + pgAttributeNum: 1 tableId: 108 - [[Column:{DescID: 108, ColumnID: 2}, ABSENT], PUBLIC] details: columnId: 2 + pgAttributeNum: 2 tableId: 108 - [[Column:{DescID: 111, ColumnID: 1}, ABSENT], PUBLIC] details: columnId: 1 + pgAttributeNum: 1 tableId: 111 - [[Column:{DescID: 111, ColumnID: 2}, ABSENT], PUBLIC] details: columnId: 2 + pgAttributeNum: 2 tableId: 111 - [[Column:{DescID: 111, ColumnID: 3}, ABSENT], PUBLIC] details: columnId: 3 + pgAttributeNum: 3 tableId: 111 - [[ColumnComment:{DescID: 105, ColumnID: 1}, ABSENT], PUBLIC] details: diff --git a/pkg/sql/schemachanger/scdecomp/decomp.go b/pkg/sql/schemachanger/scdecomp/decomp.go index 2fe3e99be4c9..70ebd44bcdde 100644 --- a/pkg/sql/schemachanger/scdecomp/decomp.go +++ b/pkg/sql/schemachanger/scdecomp/decomp.go @@ -310,7 +310,7 @@ func (w *walkCtx) walkColumn(tbl catalog.TableDescriptor, col catalog.Column) { IsInaccessible: col.IsInaccessible(), GeneratedAsIdentityType: col.GetGeneratedAsIdentityType(), GeneratedAsIdentitySequenceOption: col.GetGeneratedAsIdentitySequenceOption(), - PgAttributeNum: col.ColumnDesc().PGAttributeNum, + PgAttributeNum: col.GetPGAttributeNum(), } w.ev(maybeMutationStatus(col), column) w.ev(scpb.Status_PUBLIC, &scpb.ColumnName{ diff --git a/pkg/sql/schemachanger/scdecomp/testdata/other b/pkg/sql/schemachanger/scdecomp/testdata/other index e9a037abc86d..a85877fb8bfe 100644 --- a/pkg/sql/schemachanger/scdecomp/testdata/other +++ b/pkg/sql/schemachanger/scdecomp/testdata/other @@ -182,6 +182,7 @@ ElementState: Status: PUBLIC - Column: columnId: 1 + pgAttributeNum: 1 tableId: 112 Status: PUBLIC - TableComment: @@ -248,10 +249,12 @@ ElementState: Status: PUBLIC - Column: columnId: 1 + pgAttributeNum: 1 tableId: 113 Status: PUBLIC - Column: columnId: 2 + pgAttributeNum: 2 tableId: 113 Status: PUBLIC - TableComment: diff --git a/pkg/sql/schemachanger/scdecomp/testdata/sequence b/pkg/sql/schemachanger/scdecomp/testdata/sequence index 2a095e52bd18..00c68a40f3c3 100644 --- a/pkg/sql/schemachanger/scdecomp/testdata/sequence +++ b/pkg/sql/schemachanger/scdecomp/testdata/sequence @@ -100,10 +100,12 @@ ElementState: Status: PUBLIC - Column: columnId: 1 + pgAttributeNum: 1 tableId: 105 Status: PUBLIC - Column: columnId: 2 + pgAttributeNum: 2 tableId: 105 Status: PUBLIC - PrimaryIndex: @@ -235,10 +237,12 @@ ElementState: Status: PUBLIC - Column: columnId: 1 + pgAttributeNum: 1 tableId: 105 Status: PUBLIC - Column: columnId: 2 + pgAttributeNum: 2 tableId: 105 Status: PUBLIC - PrimaryIndex: diff --git a/pkg/sql/schemachanger/scdecomp/testdata/table b/pkg/sql/schemachanger/scdecomp/testdata/table index bae9cfe5a21a..f83097996e76 100644 --- a/pkg/sql/schemachanger/scdecomp/testdata/table +++ b/pkg/sql/schemachanger/scdecomp/testdata/table @@ -24,6 +24,7 @@ ElementState: Status: PUBLIC - Column: columnId: 1 + pgAttributeNum: 1 tableId: 104 Status: PUBLIC - PrimaryIndex: @@ -108,14 +109,17 @@ ElementState: Status: PUBLIC - Column: columnId: 1 + pgAttributeNum: 1 tableId: 105 Status: PUBLIC - Column: columnId: 2 + pgAttributeNum: 2 tableId: 105 Status: PUBLIC - Column: columnId: 3 + pgAttributeNum: 3 tableId: 105 Status: PUBLIC - PrimaryIndex: @@ -300,10 +304,12 @@ ElementState: Status: PUBLIC - Column: columnId: 1 + pgAttributeNum: 1 tableId: 104 Status: PUBLIC - Column: columnId: 2 + pgAttributeNum: 2 tableId: 104 Status: PUBLIC - PrimaryIndex: @@ -416,11 +422,13 @@ ElementState: Status: PUBLIC - Column: columnId: 1 + pgAttributeNum: 1 tableId: 108 Status: PUBLIC - Column: columnId: 2 isHidden: true + pgAttributeNum: 2 tableId: 108 Status: PUBLIC - PrimaryIndex: diff --git a/pkg/sql/schemachanger/scdecomp/testdata/type b/pkg/sql/schemachanger/scdecomp/testdata/type index 68553d88ff68..e61450f444cc 100644 --- a/pkg/sql/schemachanger/scdecomp/testdata/type +++ b/pkg/sql/schemachanger/scdecomp/testdata/type @@ -66,22 +66,27 @@ ElementState: Status: PUBLIC - Column: columnId: 1 + pgAttributeNum: 1 tableId: 108 Status: PUBLIC - Column: columnId: 2 + pgAttributeNum: 2 tableId: 108 Status: PUBLIC - Column: columnId: 3 + pgAttributeNum: 3 tableId: 108 Status: PUBLIC - Column: columnId: 4 + pgAttributeNum: 4 tableId: 108 Status: PUBLIC - Column: columnId: 5 + pgAttributeNum: 5 tableId: 108 Status: PUBLIC - PrimaryIndex: diff --git a/pkg/sql/schemachanger/scpb/elements.proto b/pkg/sql/schemachanger/scpb/elements.proto index fc44a86257ef..e57c61d01cca 100644 --- a/pkg/sql/schemachanger/scpb/elements.proto +++ b/pkg/sql/schemachanger/scpb/elements.proto @@ -139,7 +139,7 @@ message Column { bool is_inaccessible = 4; uint32 generated_as_identity_type = 5 [(gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/sql/catalog/catpb.GeneratedAsIdentityType"]; string generated_as_identity_sequence_option = 6; - uint32 pg_attribute_num = 7 [(gogoproto.customname) = "PgAttributeNum"]; + uint32 pg_attribute_num = 7 [(gogoproto.customname) = "PgAttributeNum", (gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/sql/sem/catid.PGAttributeNum"]; } // ColumnType needs to be an element distinct from Column although they have a diff --git a/pkg/sql/schemachanger/testdata/drop b/pkg/sql/schemachanger/testdata/drop index c2b321f65bbe..aee5fff615c8 100644 --- a/pkg/sql/schemachanger/testdata/drop +++ b/pkg/sql/schemachanger/testdata/drop @@ -316,6 +316,7 @@ upsert descriptor #108 + - elementProto: + column: + columnId: 1 + + pgAttributeNum: 1 + tableId: 108 + metadata: + sourceElementId: 1 @@ -357,6 +358,7 @@ upsert descriptor #108 + - elementProto: + column: + columnId: 2 + + pgAttributeNum: 2 + tableId: 108 + metadata: + sourceElementId: 1 @@ -398,6 +400,7 @@ upsert descriptor #108 + column: + columnId: 3 + isHidden: true + + pgAttributeNum: 3 + tableId: 108 + metadata: + sourceElementId: 1 @@ -635,6 +638,7 @@ upsert descriptor #108 - - elementProto: - column: - columnId: 1 + - pgAttributeNum: 1 - tableId: 108 - metadata: - sourceElementId: 1 @@ -676,6 +680,7 @@ upsert descriptor #108 - - elementProto: - column: - columnId: 2 + - pgAttributeNum: 2 - tableId: 108 - metadata: - sourceElementId: 1 @@ -717,6 +722,7 @@ upsert descriptor #108 - column: - columnId: 3 - isHidden: true + - pgAttributeNum: 3 - tableId: 108 - metadata: - sourceElementId: 1 @@ -2115,6 +2121,7 @@ upsert descriptor #116 + - elementProto: + column: + columnId: 1 + + pgAttributeNum: 1 + tableId: 116 + metadata: + sourceElementId: 7 @@ -2155,6 +2162,7 @@ upsert descriptor #116 + - elementProto: + column: + columnId: 2 + + pgAttributeNum: 2 + tableId: 116 + metadata: + sourceElementId: 7 @@ -2197,6 +2205,7 @@ upsert descriptor #116 + - elementProto: + column: + columnId: 3 + + pgAttributeNum: 3 + tableId: 116 + metadata: + sourceElementId: 7 @@ -2430,6 +2439,7 @@ upsert descriptor #117 + - elementProto: + column: + columnId: 1 + + pgAttributeNum: 1 + tableId: 117 + metadata: + sourceElementId: 3 @@ -2470,6 +2480,7 @@ upsert descriptor #117 + - elementProto: + column: + columnId: 2 + + pgAttributeNum: 2 + tableId: 117 + metadata: + sourceElementId: 3 @@ -2512,6 +2523,7 @@ upsert descriptor #117 + - elementProto: + column: + columnId: 3 + + pgAttributeNum: 3 + tableId: 117 + metadata: + sourceElementId: 3 @@ -2737,6 +2749,7 @@ upsert descriptor #118 + - elementProto: + column: + columnId: 1 + + pgAttributeNum: 1 + tableId: 118 + metadata: + sourceElementId: 3 @@ -2778,6 +2791,7 @@ upsert descriptor #118 + column: + columnId: 2 + isHidden: true + + pgAttributeNum: 2 + tableId: 118 + metadata: + sourceElementId: 3 @@ -2990,6 +3004,7 @@ upsert descriptor #119 + - elementProto: + column: + columnId: 1 + + pgAttributeNum: 1 + tableId: 119 + metadata: + sourceElementId: 9 @@ -3149,6 +3164,7 @@ upsert descriptor #120 + - elementProto: + column: + columnId: 1 + + pgAttributeNum: 1 + tableId: 120 + metadata: + sourceElementId: 10 @@ -3191,6 +3207,7 @@ upsert descriptor #120 + - elementProto: + column: + columnId: 2 + + pgAttributeNum: 2 + tableId: 120 + metadata: + sourceElementId: 10 @@ -3351,6 +3368,7 @@ upsert descriptor #121 + - elementProto: + column: + columnId: 1 + + pgAttributeNum: 1 + tableId: 121 + metadata: + sourceElementId: 11 @@ -3393,6 +3411,7 @@ upsert descriptor #121 + - elementProto: + column: + columnId: 2 + + pgAttributeNum: 2 + tableId: 121 + metadata: + sourceElementId: 11 @@ -3552,6 +3571,7 @@ upsert descriptor #122 + - elementProto: + column: + columnId: 1 + + pgAttributeNum: 1 + tableId: 122 + metadata: + sourceElementId: 11 @@ -3594,6 +3614,7 @@ upsert descriptor #122 + - elementProto: + column: + columnId: 2 + + pgAttributeNum: 2 + tableId: 122 + metadata: + sourceElementId: 11 @@ -3973,6 +3994,7 @@ upsert descriptor #125 + - elementProto: + column: + columnId: 1 + + pgAttributeNum: 1 + tableId: 125 + metadata: + sourceElementId: 13 @@ -4013,6 +4035,7 @@ upsert descriptor #125 + - elementProto: + column: + columnId: 2 + + pgAttributeNum: 2 + tableId: 125 + metadata: + sourceElementId: 13 @@ -4055,6 +4078,7 @@ upsert descriptor #125 + - elementProto: + column: + columnId: 3 + + pgAttributeNum: 3 + tableId: 125 + metadata: + sourceElementId: 13 @@ -4445,6 +4469,7 @@ upsert descriptor #116 - - elementProto: - column: - columnId: 1 + - pgAttributeNum: 1 - tableId: 116 - metadata: - sourceElementId: 7 @@ -4485,6 +4510,7 @@ upsert descriptor #116 - - elementProto: - column: - columnId: 2 + - pgAttributeNum: 2 - tableId: 116 - metadata: - sourceElementId: 7 @@ -4527,6 +4553,7 @@ upsert descriptor #116 - - elementProto: - column: - columnId: 3 + - pgAttributeNum: 3 - tableId: 116 - metadata: - sourceElementId: 7 @@ -4753,6 +4780,7 @@ upsert descriptor #117 - - elementProto: - column: - columnId: 1 + - pgAttributeNum: 1 - tableId: 117 - metadata: - sourceElementId: 3 @@ -4793,6 +4821,7 @@ upsert descriptor #117 - - elementProto: - column: - columnId: 2 + - pgAttributeNum: 2 - tableId: 117 - metadata: - sourceElementId: 3 @@ -4835,6 +4864,7 @@ upsert descriptor #117 - - elementProto: - column: - columnId: 3 + - pgAttributeNum: 3 - tableId: 117 - metadata: - sourceElementId: 3 @@ -5057,6 +5087,7 @@ upsert descriptor #118 - - elementProto: - column: - columnId: 1 + - pgAttributeNum: 1 - tableId: 118 - metadata: - sourceElementId: 3 @@ -5098,6 +5129,7 @@ upsert descriptor #118 - column: - columnId: 2 - isHidden: true + - pgAttributeNum: 2 - tableId: 118 - metadata: - sourceElementId: 3 diff --git a/pkg/sql/sem/catid/ids.go b/pkg/sql/sem/catid/ids.go index 7847a6139806..2736e0a65e36 100644 --- a/pkg/sql/sem/catid/ids.go +++ b/pkg/sql/sem/catid/ids.go @@ -43,3 +43,9 @@ type ConstraintID uint32 // SafeValue implements the redact.SafeValue interface. func (ConstraintID) SafeValue() {} + +// PGAttributeNum is a custom type for Column's logical order. +type PGAttributeNum uint32 + +// SafeValue implements the redact.SafeValue interface. +func (PGAttributeNum) SafeValue() {} diff --git a/pkg/sql/show_create_clauses.go b/pkg/sql/show_create_clauses.go index d61d86f59212..78c132cd60ba 100644 --- a/pkg/sql/show_create_clauses.go +++ b/pkg/sql/show_create_clauses.go @@ -268,7 +268,7 @@ func showComments( } for _, columnComment := range tc.columns { - col, err := table.FindColumnWithID(descpb.ColumnID(columnComment.subID)) + col, err := table.FindColumnWithPGAttributeNum(descpb.PGAttributeNum(columnComment.subID)) if err != nil { return err } diff --git a/pkg/sql/virtual_schema.go b/pkg/sql/virtual_schema.go index 83bd7ab6470a..01215c362c2b 100644 --- a/pkg/sql/virtual_schema.go +++ b/pkg/sql/virtual_schema.go @@ -499,7 +499,7 @@ func (e *virtualDefEntry) getPlanInfo( Name: col.GetName(), Typ: col.GetType(), TableID: table.GetID(), - PGAttributeNum: col.GetPGAttributeNum(), + PGAttributeNum: uint32(col.GetPGAttributeNum()), }) }