Skip to content

Commit

Permalink
schemachanger: added a field in CheckConstraint element protobuf
Browse files Browse the repository at this point in the history
We added a field bool field, `FromHashShardedColumn`, in the
CheckConstraint element protobuf. This will be needed in the future
when we translate it to a descpb.CheckConstraint when doing check
constraint related work.
  • Loading branch information
Xiang-Gu committed Nov 1, 2022
1 parent c98c82b commit c6bc7b4
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/sql/schemachanger/scbuild/testdata/drop_index
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ DROP INDEX idx3 CASCADE
- [[IndexData:{DescID: 104, IndexID: 6}, ABSENT], PUBLIC]
{indexId: 6, tableId: 104}
- [[CheckConstraint:{DescID: 104, ConstraintID: 2}, ABSENT], PUBLIC]
{columnIds: [5], constraintId: 2, expr: 'crdb_internal_i_shard_16 IN (0:::INT8, 1:::INT8, 2:::INT8, 3:::INT8, 4:::INT8, 5:::INT8, 6:::INT8, 7:::INT8, 8:::INT8, 9:::INT8, 10:::INT8, 11:::INT8, 12:::INT8, 13:::INT8, 14:::INT8, 15:::INT8)', referencedColumnIds: [5], tableId: 104}
{columnIds: [5], constraintId: 2, expr: 'crdb_internal_i_shard_16 IN (0:::INT8, 1:::INT8, 2:::INT8, 3:::INT8, 4:::INT8, 5:::INT8, 6:::INT8, 7:::INT8, 8:::INT8, 9:::INT8, 10:::INT8, 11:::INT8, 12:::INT8, 13:::INT8, 14:::INT8, 15:::INT8)', fromHashShardedColumn: true, referencedColumnIds: [5], tableId: 104}
- [[ConstraintName:{DescID: 104, Name: check_crdb_internal_i_shard_16, ConstraintID: 2}, ABSENT], PUBLIC]
{constraintId: 2, name: check_crdb_internal_i_shard_16, tableId: 104}
9 changes: 5 additions & 4 deletions pkg/sql/schemachanger/scdecomp/decomp.go
Original file line number Diff line number Diff line change
Expand Up @@ -606,10 +606,11 @@ func (w *walkCtx) walkCheckConstraint(
}
// TODO(postamar): proper handling of constraint status
w.ev(scpb.Status_PUBLIC, &scpb.CheckConstraint{
TableID: tbl.GetID(),
ConstraintID: c.ConstraintID,
ColumnIDs: catalog.MakeTableColSet(c.ColumnIDs...).Ordered(),
Expression: *expr,
TableID: tbl.GetID(),
ConstraintID: c.ConstraintID,
ColumnIDs: catalog.MakeTableColSet(c.ColumnIDs...).Ordered(),
Expression: *expr,
FromHashShardedColumn: c.FromHashShardedColumn,
})
w.ev(scpb.Status_PUBLIC, &scpb.ConstraintName{
TableID: tbl.GetID(),
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/schemachanger/scdecomp/testdata/type
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ ElementState:
- 5
constraintId: 2
expr: s::STRING = name
fromHashShardedColumn: false
referencedColumnIds:
- 3
- 5
Expand Down
2 changes: 2 additions & 0 deletions pkg/sql/schemachanger/scpb/elements.proto
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,8 @@ message CheckConstraint {
uint32 constraint_id = 2 [(gogoproto.customname) = "ConstraintID", (gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/sql/sem/catid.ConstraintID"];
repeated uint32 column_ids = 3 [(gogoproto.customname) = "ColumnIDs", (gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/sql/sem/catid.ColumnID"];
Expression embedded_expr = 4 [(gogoproto.nullable) = false, (gogoproto.embed) = true];
// FromHashShardedColumn indicates whether this check constraint comes from a hash sharded column.
bool from_hash_sharded_column = 5;
}

message ForeignKeyConstraint {
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/schemachanger/scpb/uml/table.puml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ CheckConstraint : TableID
CheckConstraint : ConstraintID
CheckConstraint : []ColumnIDs
CheckConstraint : Expression
CheckConstraint : FromHashShardedColumn

object ForeignKeyConstraint

Expand Down

0 comments on commit c6bc7b4

Please sign in to comment.