Skip to content

Commit

Permalink
scpb: add new Status values, add and adopt TargetStatus type
Browse files Browse the repository at this point in the history
This commit also adds a TemporaryIndex element and fixes a nasty bug in
the generated element iterator code.

These changes are motivated by the need to support the MVCC-compatible
backfill scheme.

Release note: None
  • Loading branch information
Marius Posta committed Feb 25, 2022
1 parent 978744d commit c8507bc
Show file tree
Hide file tree
Showing 56 changed files with 1,278 additions and 1,190 deletions.
2 changes: 1 addition & 1 deletion pkg/ccl/backupccl/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3618,7 +3618,7 @@ func TestBackupRestoreCrossTableReferences(t *testing.T) {
db.Exec(t, `DROP TABLE otherstore.receipts`)

db.ExpectErr(
t, `cannot drop relation "customers" because view "early_customers" depends on it`,
t, `cannot drop relation "customers" because view "unused_view" depends on it`,
`DROP TABLE otherstore.customers`,
)

Expand Down
12 changes: 6 additions & 6 deletions pkg/ccl/schemachangerccl/testdata/end_to_end/drop_multiregion
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ upsert descriptor #108
+ - ABSENT
+ - ABSENT
+ - ABSENT
+ - DELETE_AND_WRITE_ONLY
+ - WRITE_ONLY
+ - ABSENT
+ - ABSENT
+ - ABSENT
+ - DELETE_AND_WRITE_ONLY
+ - WRITE_ONLY
+ - ABSENT
+ - ABSENT
+ - ABSENT
Expand Down Expand Up @@ -428,11 +428,11 @@ upsert descriptor #108
- - ABSENT
- - ABSENT
- - ABSENT
- - DELETE_AND_WRITE_ONLY
- - WRITE_ONLY
- - ABSENT
- - ABSENT
- - ABSENT
- - DELETE_AND_WRITE_ONLY
- - WRITE_ONLY
- - ABSENT
- - ABSENT
- - ABSENT
Expand Down Expand Up @@ -779,7 +779,7 @@ upsert descriptor #109
+ - ABSENT
+ - ABSENT
+ - ABSENT
+ - DELETE_AND_WRITE_ONLY
+ - WRITE_ONLY
+ - ABSENT
+ - ABSENT
+ - ABSENT
Expand Down Expand Up @@ -1021,7 +1021,7 @@ upsert descriptor #109
- - ABSENT
- - ABSENT
- - ABSENT
- - DELETE_AND_WRITE_ONLY
- - WRITE_ONLY
- - ABSENT
- - ABSENT
- - ABSENT
Expand Down
12 changes: 6 additions & 6 deletions pkg/sql/catalog/internal/validate/schema_changer_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestValidateSchemaChangerState(t *testing.T) {
ds: ds{
JobID: 1,
Targets: []scpb.Target{
scpb.MakeTarget(scpb.Status_PUBLIC, &scpb.Namespace{
scpb.MakeTarget(scpb.ToPublic, &scpb.Namespace{
DatabaseID: 2,
SchemaID: 2,
DescriptorID: 3,
Expand All @@ -89,7 +89,7 @@ func TestValidateSchemaChangerState(t *testing.T) {
ds: ds{
JobID: 1,
Targets: []scpb.Target{
scpb.MakeTarget(scpb.Status_PUBLIC, &scpb.Namespace{
scpb.MakeTarget(scpb.ToPublic, &scpb.Namespace{
DatabaseID: 2,
SchemaID: 2,
DescriptorID: 3,
Expand Down Expand Up @@ -122,7 +122,7 @@ func TestValidateSchemaChangerState(t *testing.T) {
ds: ds{
JobID: 1,
Targets: []scpb.Target{
scpb.MakeTarget(scpb.Status_PUBLIC, &scpb.Namespace{
scpb.MakeTarget(scpb.ToPublic, &scpb.Namespace{
DatabaseID: 2,
SchemaID: 2,
DescriptorID: 3,
Expand All @@ -132,7 +132,7 @@ func TestValidateSchemaChangerState(t *testing.T) {
SourceElementID: 1,
StatementID: 0,
}),
scpb.MakeTarget(scpb.Status_PUBLIC, &scpb.Namespace{
scpb.MakeTarget(scpb.ToPublic, &scpb.Namespace{
DatabaseID: 2,
SchemaID: 2,
DescriptorID: 3,
Expand Down Expand Up @@ -170,7 +170,7 @@ func TestValidateSchemaChangerState(t *testing.T) {
ds: ds{
JobID: 1,
Targets: []scpb.Target{
scpb.MakeTarget(scpb.Status_PUBLIC, &scpb.Namespace{
scpb.MakeTarget(scpb.ToPublic, &scpb.Namespace{
DatabaseID: 2,
SchemaID: 2,
DescriptorID: 3,
Expand All @@ -180,7 +180,7 @@ func TestValidateSchemaChangerState(t *testing.T) {
SourceElementID: 1,
StatementID: 1,
}),
scpb.MakeTarget(scpb.Status_PUBLIC, &scpb.Namespace{
scpb.MakeTarget(scpb.ToPublic, &scpb.Namespace{
DatabaseID: 2,
SchemaID: 2,
DescriptorID: 3,
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/logictest/testdata/logic_test/fk
Original file line number Diff line number Diff line change
Expand Up @@ -655,10 +655,10 @@ ALTER TABLE delivery DROP COLUMN "item"
statement ok
DROP INDEX products@products_upc_key CASCADE

statement error "products" is referenced by foreign key from table "orders"
statement error "products" is referenced by foreign key from table "customer reviews"
DROP TABLE products

statement error referenced by foreign key from table "orders"
statement error referenced by foreign key from table "customer reviews"
DROP TABLE products RESTRICT

statement error referenced by foreign key from table "customer reviews"
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/logictest/testdata/logic_test/new_schema_changer
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ CREATE VIEW v4Dep AS (SELECT n2, n1 FROM v2Dep);
statement ok
explain (DDL, DEPS) DROP VIEW v1Dep CASCADE;

statement error pq: cannot drop relation "v1dep" because view "v2dep" depends on it
statement error pq: cannot drop relation "v1dep" because view "v3dep" depends on it
DROP VIEW v1Dep RESTRICT;

statement error pq: "v1dep" is not a materialized view
Expand Down Expand Up @@ -446,7 +446,7 @@ CREATE TABLE defaultdb.shipments (
CONSTRAINT fk_orders FOREIGN KEY (customer_id) REFERENCES defaultdb.orders(customer)
);

statement error "customers" is referenced by foreign key from table "orders"
statement error "customers" is referenced by foreign key from table "shipments"
DROP TABLE defaultdb.customers;

statement ok
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/logictest/testdata/logic_test/views
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ DROP TABLE v1
statement error pgcode 42809 "t" is not a view
DROP VIEW t

statement error cannot drop relation "v1" because view "v6" depends on it
statement error cannot drop relation "v1" because view "v7" depends on it
DROP VIEW v1

statement error cannot drop relation "v2" because view "test2.public.v1" depends on it
Expand Down

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions pkg/sql/schemachanger/scbuild/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ func Build(
// Explicity-set targets have non-zero values in the target metadata.
continue
}
ts.Targets = append(ts.Targets, scpb.MakeTarget(e.targetStatus, e.element, &e.metadata))
current = append(current, e.currentStatus)
ts.Targets = append(ts.Targets, scpb.MakeTarget(e.target, e.element, &e.metadata))
current = append(current, e.current)
}
return scpb.CurrentState{TargetState: ts, Current: current}, nil
}
Expand All @@ -90,9 +90,10 @@ type (
)

type elementState struct {
element scpb.Element
targetStatus, currentStatus scpb.Status
metadata scpb.TargetMetadata
element scpb.Element
current scpb.Status
target scpb.TargetStatus
metadata scpb.TargetMetadata
}

// builderState is the backing struct for scbuildstmt.BuilderState interface.
Expand Down Expand Up @@ -146,7 +147,7 @@ func newBuilderState(ctx context.Context, d Dependencies, initial scpb.CurrentSt
bs.ensureDescriptor(screl.GetDescID(t.Element()))
}
for i, t := range initial.TargetState.Targets {
bs.Ensure(initial.Current[i], t.TargetStatus, t.Element(), t.Metadata)
bs.Ensure(initial.Current[i], scpb.AsTargetStatus(t.TargetStatus), t.Element(), t.Metadata)
}
return &bs
}
Expand Down Expand Up @@ -213,12 +214,12 @@ var _ scbuildstmt.BuildCtx = buildCtx{}

// Add implements the scbuildstmt.BuildCtx interface.
func (b buildCtx) Add(element scpb.Element) {
b.Ensure(scpb.Status_UNKNOWN, scpb.Status_PUBLIC, element, b.TargetMetadata())
b.Ensure(scpb.Status_UNKNOWN, scpb.ToPublic, element, b.TargetMetadata())
}

// Drop implements the scbuildstmt.BuildCtx interface.
func (b buildCtx) Drop(element scpb.Element) {
b.Ensure(scpb.Status_UNKNOWN, scpb.Status_ABSENT, element, b.TargetMetadata())
b.Ensure(scpb.Status_UNKNOWN, scpb.ToAbsent, element, b.TargetMetadata())
}

// WithNewSourceElementID implements the scbuildstmt.BuildCtx interface.
Expand Down
Loading

0 comments on commit c8507bc

Please sign in to comment.