Skip to content

Commit

Permalink
sql: Remove unnecessary constraints check in show create
Browse files Browse the repository at this point in the history
The show create table function would not display a zone configuration
if the constraints list was empty. However, this isn't a valid check
because the constraints list could be empty but other fields set. We
instead need to check that all the fields are default/empty values
before not showing anything in the create statements.

Release note: None
  • Loading branch information
rohany committed Sep 3, 2019
1 parent d51fa78 commit 10d76cc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
23 changes: 23 additions & 0 deletions pkg/ccl/logictestccl/testdata/logic_test/zone
Original file line number Diff line number Diff line change
Expand Up @@ -593,3 +593,26 @@ PARTITION p1 OF INDEX "my database".public.t2@x1 ALTER PARTITION p1 OF IND
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

# regression for #40417
statement ok
CREATE TABLE t40417 (x INT PRIMARY KEY)

statement ok
ALTER TABLE t40417 PARTITION BY LIST (x) ( PARTITION p1 VALUES IN (1));

statement ok
ALTER PARTITION p1 OF TABLE t40417 CONFIGURE ZONE USING num_replicas = 1

query TT
SHOW CREATE TABLE t40417
----
t40417 CREATE TABLE t40417 (
x INT8 NOT NULL,
CONSTRAINT "primary" PRIMARY KEY (x ASC),
FAMILY "primary" (x)
) PARTITION BY LIST (x) (
PARTITION p1 VALUES IN ((1))
);
ALTER PARTITION p1 OF INDEX "my database".public.t40417@primary CONFIGURE ZONE USING
num_replicas = 1
5 changes: 4 additions & 1 deletion pkg/sql/crdb_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -1215,7 +1215,10 @@ CREATE TABLE crdb_internal.create_statements (
if err != nil {
return err
}
if len(zoneConfig.Constraints) > 0 {
// If all constraints are default, then don't show anything.
if zoneConfig.RangeMinBytes != nil || zoneConfig.RangeMaxBytes != nil ||
zoneConfig.NumReplicas != nil || len(zoneConfig.Constraints) != 0 ||
len(zoneConfig.LeasePreferences) != 0 {
sqlString := string(tree.MustBeDString(row[2]))
zoneConfigStmts[tableName] = append(zoneConfigStmts[tableName], sqlString)
}
Expand Down

0 comments on commit 10d76cc

Please sign in to comment.