Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
95153: sql/schemachanger: Drop function in declarative schema changer r=chengxiong-ruan a=chengxiong-ruan

This pr contains 3 commits:
1. add function descriptor elements definition
2. a simple rename of RemoveViewBackReferencesInRelation to RemoveBackReferencesInRelation
3. drop function logics
Part of: https://cockroachlabs.atlassian.net/browse/CRDB-19495

95524: kvserver: fix race on Replica.tenantLimiter r=tbg a=pavelkalinnikov

When Replica is being destroyed, it can set tenantLimiter to nil. However, all accessors assume synchronization through IsInitialized atomic check and that this field can't be modified after the replica is initialized.

There is no particular need in nullifying this limiter, the replica is going away soon, so this commit removes this line in order to fix the data race.

Fixes #95345
Epic: none
Release note: none

96002: eval: fix internal error casting bytes to bit r=msirek a=msirek

Fixes #95543

Release note (bug fix): This patch fixes an internal error which may occur in the SHOW RANGE FROM TABLE statement when the FOR ROW clause specifies a BYTE literal and the corresponding column data type is BIT.

96030: docgen: remove redundant SQL diagrams r=nickvigilante a=taroface

Diagrams updated in #95591 were not generating HTML files as intended because of some redundant lines in the code. This removes the redundancies per `@nickvigilante.`

Epic: none

Release note: none

Release justification: non-production code change

96048: optbuilder: fix internal error in LATERAL queries with redundant function calls r=DrewKimball,mgartner a=msirek

Fixes #95615

Function `optbuilder.Builder.buildZip` may try to build 2 identical function
calls into 2 zip expressions, each one adding one or more columns to the
output. However, if buildZip's called to `buildScalar` recognizes a scalar
expression has already been built, it skips adding a new output columns and
returns the previously-built output column. This mismatch in the number of
output columns actually built, and the number of columns communicated to
the parent expression via `outScope` confuses the execution engine, and in
this case we error out because the expected data type of one column doesn't
match the actual data type.

The fix is to skip building zip expressions with redundant expressions which
already exist in `outScope`.

Release note (bug fix): This patch fixes rare internal errors in LATERAL
queries with redundant function calls.

96099: upgrades: share a column family for the new tenant columns r=ajwerner a=knz

Fixes #96093.

The previous change in that area was causing the new columns to be (implicitly) added into separate column families. However, we're expecting (from the bootstrap schema) to use a single column family for them. This patch fixes that.

Release note: None

Co-authored-by: Chengxiong Ruan <[email protected]>
Co-authored-by: Pavel Kalinnikov <[email protected]>
Co-authored-by: Tobias Grieger <[email protected]>
Co-authored-by: Mark Sirek <[email protected]>
Co-authored-by: Ryan Kuo <[email protected]>
Co-authored-by: Raphael 'kena' Poss <[email protected]>
  • Loading branch information
7 people committed Jan 27, 2023
7 parents ea0d772 + 07ba6fb + 8611c84 + c335a4e + f7170c5 + ff87db0 + f279829 commit b23943c
Show file tree
Hide file tree
Showing 100 changed files with 3,139 additions and 354 deletions.
4 changes: 0 additions & 4 deletions docs/generated/sql/bnf/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ FILES = [
"alter_database_primary_region",
"alter_database_set_zone_config_extension_stmt",
"alter_database_set_stmt",
"alter_database_stmt",
"alter_database_survival_goal_stmt",
"alter_database_to_schema_stmt",
"alter_ddl_stmt",
Expand All @@ -34,13 +33,11 @@ FILES = [
"alter_func_dep_extension_stmt",
"alter_index_partition_by",
"alter_index",
"alter_index_stmt",
"alter_index_visible_stmt",
"alter_partition_stmt",
"alter_primary_key",
"alter_range_relocate_stmt",
"alter_range",
"alter_range_stmt",
"alter_rename_view_stmt",
"alter_role_stmt",
"alter_scatter_index_stmt",
Expand All @@ -59,7 +56,6 @@ FILES = [
"alter_table_reset_storage_param",
"alter_table_set_schema_stmt",
"alter_table_set_storage_param",
"alter_table_stmt",
"alter_type",
"alter_view",
"alter_view_owner_stmt",
Expand Down
17 changes: 0 additions & 17 deletions docs/generated/sql/bnf/alter_database_stmt.bnf

This file was deleted.

8 changes: 0 additions & 8 deletions docs/generated/sql/bnf/alter_index_stmt.bnf

This file was deleted.

3 changes: 0 additions & 3 deletions docs/generated/sql/bnf/alter_range_stmt.bnf

This file was deleted.

10 changes: 0 additions & 10 deletions docs/generated/sql/bnf/alter_table_stmt.bnf

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ pq: cannot drop sequence sq1 because other objects depend on it
exec-sql
DROP TABLE sc1.tbl1
----
pq: cannot drop relation "tbl1" because function "f1" depends on it
HINT: you can drop f1 instead.
pq: cannot drop table tbl1 because other objects depend on it

exec-sql
ALTER TABLE sc1.tbl1 RENAME TO tbl1_new
Expand Down Expand Up @@ -274,8 +273,7 @@ pq: cannot drop sequence sq1 because other objects depend on it
exec-sql
DROP TABLE sc1.tbl1
----
pq: cannot drop relation "tbl1" because function "f1" depends on it
HINT: you can drop f1 instead.
pq: cannot drop table tbl1 because other objects depend on it

exec-sql
ALTER TABLE sc1.tbl1 RENAME TO tbl1_new
Expand Down
5 changes: 5 additions & 0 deletions pkg/ccl/schemachangerccl/backup_base_generated_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ write *eventpb.DropDatabase to event log:
statement: DROP DATABASE ‹multi_region_test_db› CASCADE
tag: DROP DATABASE
user: root
## StatementPhase stage 1 of 1 with 12 MutationType ops
## StatementPhase stage 1 of 1 with 15 MutationType ops
delete database namespace entry {0 0 multi_region_test_db} -> 104
delete schema namespace entry {104 0 public} -> 105
delete object namespace entry {104 105 crdb_internal_region} -> 106
Expand Down Expand Up @@ -85,7 +85,7 @@ upsert descriptor #108
## PreCommitPhase stage 1 of 2 with 1 MutationType op
undo all catalog changes within txn #1
persist all catalog changes to storage
## PreCommitPhase stage 2 of 2 with 22 MutationType ops
## PreCommitPhase stage 2 of 2 with 25 MutationType ops
delete database namespace entry {0 0 multi_region_test_db} -> 104
delete schema namespace entry {104 0 public} -> 105
delete object namespace entry {104 105 crdb_internal_region} -> 106
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ write *eventpb.DropTable to event log:
tag: DROP TABLE
user: root
tableName: multi_region_test_db.public.table_regional_by_row
## StatementPhase stage 1 of 1 with 6 MutationType ops
## StatementPhase stage 1 of 1 with 7 MutationType ops
delete object namespace entry {104 105 table_regional_by_row} -> 108
upsert descriptor #106
...
Expand Down Expand Up @@ -65,7 +65,7 @@ upsert descriptor #108
## PreCommitPhase stage 1 of 2 with 1 MutationType op
undo all catalog changes within txn #1
persist all catalog changes to storage
## PreCommitPhase stage 2 of 2 with 14 MutationType ops
## PreCommitPhase stage 2 of 2 with 15 MutationType ops
delete object namespace entry {104 105 table_regional_by_row} -> 108
upsert descriptor #106
type:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ write *eventpb.DropTable to event log:
tag: DROP TABLE
user: root
tableName: multi_region_test_db.public.table_regional_by_table
## StatementPhase stage 1 of 1 with 3 MutationType ops
## StatementPhase stage 1 of 1 with 4 MutationType ops
delete object namespace entry {104 105 table_regional_by_table} -> 108
upsert descriptor #106
...
Expand Down Expand Up @@ -58,7 +58,7 @@ upsert descriptor #108
## PreCommitPhase stage 1 of 2 with 1 MutationType op
undo all catalog changes within txn #1
persist all catalog changes to storage
## PreCommitPhase stage 2 of 2 with 9 MutationType ops
## PreCommitPhase stage 2 of 2 with 10 MutationType ops
delete object namespace entry {104 105 table_regional_by_table} -> 108
upsert descriptor #106
type:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,16 @@ Schema change plan for DROP DATABASE ‹multi_region_test_db› CASCADE;
│ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 108, ColumnID: 1, IndexID: 1}
│ │ ├── PUBLIC → VALIDATED PrimaryIndex:{DescID: 108, IndexID: 1, ConstraintID: 1}
│ │ └── PUBLIC → ABSENT IndexName:{DescID: 108, Name: table_regional_by_table_pkey, IndexID: 1}
│ └── 12 Mutation operations
│ └── 15 Mutation operations
│ ├── MarkDescriptorAsDropped {"DescriptorID":104}
│ ├── MarkDescriptorAsDropped {"DescriptorID":105}
│ ├── RemoveSchemaParent {"Parent":{"ParentDatabaseID":104,"SchemaID":105}}
│ ├── MarkDescriptorAsDropped {"DescriptorID":106}
│ ├── RemoveObjectParent {"ObjectID":106,"ParentSchemaID":105}
│ ├── MarkDescriptorAsDropped {"DescriptorID":107}
│ ├── RemoveObjectParent {"ObjectID":107,"ParentSchemaID":105}
│ ├── MarkDescriptorAsDropped {"DescriptorID":108}
│ ├── RemoveObjectParent {"ObjectID":108,"ParentSchemaID":105}
│ ├── RemoveBackReferenceInTypes {"BackReferencedDescriptorID":108}
│ ├── DrainDescriptorName {"Namespace":{"DescriptorID":104,"Name":"multi_region_tes..."}}
│ ├── DrainDescriptorName {"Namespace":{"DatabaseID":104,"DescriptorID":105,"Name":"public"}}
Expand Down Expand Up @@ -187,14 +190,17 @@ Schema change plan for DROP DATABASE ‹multi_region_test_db› CASCADE;
│ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 108, ColumnID: 1, IndexID: 1}
│ │ ├── PUBLIC → ABSENT PrimaryIndex:{DescID: 108, IndexID: 1, ConstraintID: 1}
│ │ └── PUBLIC → ABSENT IndexName:{DescID: 108, Name: table_regional_by_table_pkey, IndexID: 1}
│ └── 22 Mutation operations
│ └── 25 Mutation operations
│ ├── MarkDescriptorAsDropped {"DescriptorID":104}
│ ├── RemoveDatabaseRoleSettings {"DatabaseID":104}
│ ├── MarkDescriptorAsDropped {"DescriptorID":105}
│ ├── RemoveSchemaParent {"Parent":{"ParentDatabaseID":104,"SchemaID":105}}
│ ├── MarkDescriptorAsDropped {"DescriptorID":106}
│ ├── RemoveObjectParent {"ObjectID":106,"ParentSchemaID":105}
│ ├── MarkDescriptorAsDropped {"DescriptorID":107}
│ ├── RemoveObjectParent {"ObjectID":107,"ParentSchemaID":105}
│ ├── MarkDescriptorAsDropped {"DescriptorID":108}
│ ├── RemoveObjectParent {"ObjectID":108,"ParentSchemaID":105}
│ ├── RemoveBackReferenceInTypes {"BackReferencedDescriptorID":108}
│ ├── DrainDescriptorName {"Namespace":{"DescriptorID":104,"Name":"multi_region_tes..."}}
│ ├── DrainDescriptorName {"Namespace":{"DatabaseID":104,"DescriptorID":105,"Name":"public"}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ Schema change plan for DROP TABLE ‹multi_region_test_db›.‹public›.‹tab
│ │ ├── PUBLIC → VALIDATED PrimaryIndex:{DescID: 108, IndexID: 1, ConstraintID: 1}
│ │ ├── PUBLIC → ABSENT IndexPartitioning:{DescID: 108, IndexID: 1}
│ │ └── PUBLIC → ABSENT IndexName:{DescID: 108, Name: table_regional_by_row_pkey, IndexID: 1}
│ └── 6 Mutation operations
│ └── 7 Mutation operations
│ ├── MarkDescriptorAsDropped {"DescriptorID":108}
│ ├── RemoveObjectParent {"ObjectID":108,"ParentSchemaID":105}
│ ├── RemoveColumnDefaultExpression {"ColumnID":2,"TableID":108}
│ ├── UpdateTableBackReferencesInTypes {"BackReferencedTableID":108}
│ ├── DrainDescriptorName {"Namespace":{"DatabaseID":104,"DescriptorID":108,"Name":"table_regional_b...","SchemaID":105}}
Expand Down Expand Up @@ -106,8 +107,9 @@ Schema change plan for DROP TABLE ‹multi_region_test_db›.‹public›.‹tab
│ │ ├── PUBLIC → ABSENT PrimaryIndex:{DescID: 108, IndexID: 1, ConstraintID: 1}
│ │ ├── PUBLIC → ABSENT IndexPartitioning:{DescID: 108, IndexID: 1}
│ │ └── PUBLIC → ABSENT IndexName:{DescID: 108, Name: table_regional_by_row_pkey, IndexID: 1}
│ └── 14 Mutation operations
│ └── 15 Mutation operations
│ ├── MarkDescriptorAsDropped {"DescriptorID":108}
│ ├── RemoveObjectParent {"ObjectID":108,"ParentSchemaID":105}
│ ├── RemoveColumnDefaultExpression {"ColumnID":2,"TableID":108}
│ ├── UpdateTableBackReferencesInTypes {"BackReferencedTableID":108}
│ ├── DrainDescriptorName {"Namespace":{"DatabaseID":104,"DescriptorID":108,"Name":"table_regional_b...","SchemaID":105}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ Schema change plan for DROP TABLE ‹multi_region_test_db›.‹public›.‹tab
│ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 108, ColumnID: 1, IndexID: 1}
│ │ ├── PUBLIC → VALIDATED PrimaryIndex:{DescID: 108, IndexID: 1, ConstraintID: 1}
│ │ └── PUBLIC → ABSENT IndexName:{DescID: 108, Name: table_regional_by_table_pkey, IndexID: 1}
│ └── 3 Mutation operations
│ └── 4 Mutation operations
│ ├── MarkDescriptorAsDropped {"DescriptorID":108}
│ ├── RemoveObjectParent {"ObjectID":108,"ParentSchemaID":105}
│ ├── RemoveBackReferenceInTypes {"BackReferencedDescriptorID":108}
│ └── DrainDescriptorName {"Namespace":{"DatabaseID":104,"DescriptorID":108,"Name":"table_regional_b...","SchemaID":105}}
├── PreCommitPhase
Expand Down Expand Up @@ -82,8 +83,9 @@ Schema change plan for DROP TABLE ‹multi_region_test_db›.‹public›.‹tab
│ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 108, ColumnID: 1, IndexID: 1}
│ │ ├── PUBLIC → ABSENT PrimaryIndex:{DescID: 108, IndexID: 1, ConstraintID: 1}
│ │ └── PUBLIC → ABSENT IndexName:{DescID: 108, Name: table_regional_by_table_pkey, IndexID: 1}
│ └── 9 Mutation operations
│ └── 10 Mutation operations
│ ├── MarkDescriptorAsDropped {"DescriptorID":108}
│ ├── RemoveObjectParent {"ObjectID":108,"ParentSchemaID":105}
│ ├── RemoveBackReferenceInTypes {"BackReferencedDescriptorID":108}
│ ├── DrainDescriptorName {"Namespace":{"DatabaseID":104,"DescriptorID":108,"Name":"table_regional_b...","SchemaID":105}}
│ ├── MakeDeleteOnlyColumnAbsent {"ColumnID":1,"TableID":108}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ EXPLAIN (ddl, verbose) DROP DATABASE multi_region_test_db CASCADE;
│ │ └── • skip PUBLIC → ABSENT operations
│ │ rule: "skip index dependents removal ops on relation drop"
│ │
│ └── • 12 Mutation operations
│ └── • 15 Mutation operations
│ │
│ ├── • MarkDescriptorAsDropped
│ │ DescriptorID: 104
Expand All @@ -482,12 +482,24 @@ EXPLAIN (ddl, verbose) DROP DATABASE multi_region_test_db CASCADE;
│ ├── • MarkDescriptorAsDropped
│ │ DescriptorID: 106
│ │
│ ├── • RemoveObjectParent
│ │ ObjectID: 106
│ │ ParentSchemaID: 105
│ │
│ ├── • MarkDescriptorAsDropped
│ │ DescriptorID: 107
│ │
│ ├── • RemoveObjectParent
│ │ ObjectID: 107
│ │ ParentSchemaID: 105
│ │
│ ├── • MarkDescriptorAsDropped
│ │ DescriptorID: 108
│ │
│ ├── • RemoveObjectParent
│ │ ObjectID: 108
│ │ ParentSchemaID: 105
│ │
│ ├── • RemoveBackReferenceInTypes
│ │ BackReferencedDescriptorID: 108
│ │ TypeIDs:
Expand Down Expand Up @@ -1192,7 +1204,7 @@ EXPLAIN (ddl, verbose) DROP DATABASE multi_region_test_db CASCADE;
│ │ └── • skip PUBLIC → ABSENT operations
│ │ rule: "skip index dependents removal ops on relation drop"
│ │
│ └── • 22 Mutation operations
│ └── • 25 Mutation operations
│ │
│ ├── • MarkDescriptorAsDropped
│ │ DescriptorID: 104
Expand All @@ -1211,12 +1223,24 @@ EXPLAIN (ddl, verbose) DROP DATABASE multi_region_test_db CASCADE;
│ ├── • MarkDescriptorAsDropped
│ │ DescriptorID: 106
│ │
│ ├── • RemoveObjectParent
│ │ ObjectID: 106
│ │ ParentSchemaID: 105
│ │
│ ├── • MarkDescriptorAsDropped
│ │ DescriptorID: 107
│ │
│ ├── • RemoveObjectParent
│ │ ObjectID: 107
│ │ ParentSchemaID: 105
│ │
│ ├── • MarkDescriptorAsDropped
│ │ DescriptorID: 108
│ │
│ ├── • RemoveObjectParent
│ │ ObjectID: 108
│ │ ParentSchemaID: 105
│ │
│ ├── • RemoveBackReferenceInTypes
│ │ BackReferencedDescriptorID: 108
│ │ TypeIDs:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,15 @@ EXPLAIN (ddl, verbose) DROP TABLE multi_region_test_db.public.table_regional_by_
│ │ └── • skip PUBLIC → ABSENT operations
│ │ rule: "skip index dependents removal ops on relation drop"
│ │
│ └── • 6 Mutation operations
│ └── • 7 Mutation operations
│ │
│ ├── • MarkDescriptorAsDropped
│ │ DescriptorID: 108
│ │
│ ├── • RemoveObjectParent
│ │ ObjectID: 108
│ │ ParentSchemaID: 105
│ │
│ ├── • RemoveColumnDefaultExpression
│ │ ColumnID: 2
│ │ TableID: 108
Expand Down Expand Up @@ -735,11 +739,15 @@ EXPLAIN (ddl, verbose) DROP TABLE multi_region_test_db.public.table_regional_by_
│ │ └── • skip PUBLIC → ABSENT operations
│ │ rule: "skip index dependents removal ops on relation drop"
│ │
│ └── • 14 Mutation operations
│ └── • 15 Mutation operations
│ │
│ ├── • MarkDescriptorAsDropped
│ │ DescriptorID: 108
│ │
│ ├── • RemoveObjectParent
│ │ ObjectID: 108
│ │ ParentSchemaID: 105
│ │
│ ├── • RemoveColumnDefaultExpression
│ │ ColumnID: 2
│ │ TableID: 108
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,15 @@ EXPLAIN (ddl, verbose) DROP TABLE multi_region_test_db.public.table_regional_by_
│ │ └── • skip PUBLIC → ABSENT operations
│ │ rule: "skip index dependents removal ops on relation drop"
│ │
│ └── • 3 Mutation operations
│ └── • 4 Mutation operations
│ │
│ ├── • MarkDescriptorAsDropped
│ │ DescriptorID: 108
│ │
│ ├── • RemoveObjectParent
│ │ ObjectID: 108
│ │ ParentSchemaID: 105
│ │
│ ├── • RemoveBackReferenceInTypes
│ │ BackReferencedDescriptorID: 108
│ │ TypeIDs:
Expand Down Expand Up @@ -520,11 +524,15 @@ EXPLAIN (ddl, verbose) DROP TABLE multi_region_test_db.public.table_regional_by_
│ │ └── • skip PUBLIC → ABSENT operations
│ │ rule: "skip index dependents removal ops on relation drop"
│ │
│ └── • 9 Mutation operations
│ └── • 10 Mutation operations
│ │
│ ├── • MarkDescriptorAsDropped
│ │ DescriptorID: 108
│ │
│ ├── • RemoveObjectParent
│ │ ObjectID: 108
│ │ ParentSchemaID: 105
│ │
│ ├── • RemoveBackReferenceInTypes
│ │ BackReferencedDescriptorID: 108
│ │ TypeIDs:
Expand Down
Loading

0 comments on commit b23943c

Please sign in to comment.