Skip to content

Commit

Permalink
sql: add ALTER ALL PARTITIONS command
Browse files Browse the repository at this point in the history
`ALTER ALL PARTITIONS ... OF TABLE` applies a zone configuration to
all the partitions of a table and its indexes which have the specified
name.

Refers #39357

Release note (sql change): Added the `ALTER ALL PARTITIONS ... OF TABLE`
command, which allows applying a zone configuration to all the
partitions of a table and its indexes with the specified name.
  • Loading branch information
solongordon committed Aug 19, 2019
1 parent cc66493 commit 3a53df8
Show file tree
Hide file tree
Showing 4 changed files with 310 additions and 239 deletions.
27 changes: 27 additions & 0 deletions pkg/ccl/logictestccl/testdata/logic_test/zone
Original file line number Diff line number Diff line change
Expand Up @@ -566,3 +566,30 @@ ALTER PARTITION p1 OF INDEX "my database".public.show_test@primary CONFIGURE ZON
constraints = '[+dc=dc1]';
ALTER PARTITION p2 OF INDEX "my database".public.show_test@primary CONFIGURE ZONE USING
constraints = '[+dc=dc2]'

subtest alter_all_partitions

statement ok
CREATE TABLE t2 (x INT PRIMARY KEY) PARTITION BY LIST (x) (
PARTITION p1 VALUES IN (1),
PARTITION p2 VALUES IN (2)
);
CREATE INDEX x1 ON t2 (x) PARTITION BY LIST (x) (
PARTITION p1 VALUES IN (1),
PARTITION p2 VALUES IN (2)
);
CREATE INDEX x2 ON t2 (x) PARTITION BY LIST (x) (
PARTITION p1 VALUES IN (1),
PARTITION p2 VALUES IN (2)
);
ALTER ALL PARTITIONS p1 OF TABLE t2 CONFIGURE ZONE USING num_replicas = 1

query TT
SELECT * FROM [SHOW ALL ZONE CONFIGURATIONS] WHERE target LIKE '%t2@%'
----
PARTITION p1 OF INDEX "my database".public.t2@primary ALTER PARTITION p1 OF INDEX "my database".public.t2@primary CONFIGURE ZONE USING
num_replicas = 1
PARTITION p1 OF INDEX "my database".public.t2@x1 ALTER PARTITION p1 OF INDEX "my database".public.t2@x1 CONFIGURE ZONE USING
num_replicas = 1
PARTITION p1 OF INDEX "my database".public.t2@x2 ALTER PARTITION p1 OF INDEX "my database".public.t2@x2 CONFIGURE ZONE USING
num_replicas = 1
11 changes: 11 additions & 0 deletions pkg/sql/parser/sql.y
Original file line number Diff line number Diff line change
Expand Up @@ -1442,6 +1442,17 @@ alter_zone_table_stmt:
}
$$.val = s
}
| ALTER ALL PARTITIONS partition_name OF TABLE table_name set_zone_config
{
name := $7.unresolvedObjectName().ToTableName()
s := $8.setZoneConfig()
s.ZoneSpecifier = tree.ZoneSpecifier{
TableOrIndex: tree.TableIndexName{Table: name},
Partition: tree.Name($4),
}
s.SetAll = true
$$.val = s
}

alter_zone_index_stmt:
ALTER INDEX table_index_name set_zone_config
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/sem/tree/zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func (node *ShowZoneConfig) Format(ctx *FmtCtx) {
type SetZoneConfig struct {
ZoneSpecifier
SetDefault bool
SetAll bool
YAMLConfig Expr
Options KVOptions
}
Expand Down
Loading

0 comments on commit 3a53df8

Please sign in to comment.