diff --git a/docs/generated/settings/settings-for-tenants.txt b/docs/generated/settings/settings-for-tenants.txt index b6708057c3ae..fd3802a92a98 100644 --- a/docs/generated/settings/settings-for-tenants.txt +++ b/docs/generated/settings/settings-for-tenants.txt @@ -67,6 +67,7 @@ server.web_session_timeout duration 168h0m0s the duration that a newly created w sql.cross_db_fks.enabled boolean false if true, creating foreign key references across databases is allowed sql.cross_db_sequence_owners.enabled boolean false if true, creating sequences owned by tables from other databases is allowed sql.cross_db_views.enabled boolean false if true, creating views that refer to other databases is allowed +sql.defaults.copy_partitioning_when_deinterleaving_table.enabled boolean false default value for enable_copying_partitioning_when_deinterleaving_table session variable sql.defaults.default_int_size integer 8 the size, in bytes, of an INT type sql.defaults.disallow_full_table_scans.enabled boolean false setting to true rejects queries that have planned a full table scan sql.defaults.idle_in_session_timeout duration 0s default value for the idle_in_session_timeout; default value for the idle_in_session_timeout session setting; controls the duration a session is permitted to idle before the session is terminated; if set to 0, there is no timeout diff --git a/docs/generated/settings/settings.html b/docs/generated/settings/settings.html index eb65dca784db..6831e970124d 100644 --- a/docs/generated/settings/settings.html +++ b/docs/generated/settings/settings.html @@ -69,6 +69,7 @@ sql.cross_db_fks.enabledbooleanfalseif true, creating foreign key references across databases is allowed sql.cross_db_sequence_owners.enabledbooleanfalseif true, creating sequences owned by tables from other databases is allowed sql.cross_db_views.enabledbooleanfalseif true, creating views that refer to other databases is allowed +sql.defaults.copy_partitioning_when_deinterleaving_table.enabledbooleanfalsedefault value for enable_copying_partitioning_when_deinterleaving_table session variable sql.defaults.default_int_sizeinteger8the size, in bytes, of an INT type sql.defaults.disallow_full_table_scans.enabledbooleanfalsesetting to true rejects queries that have planned a full table scan sql.defaults.idle_in_session_timeoutduration0sdefault value for the idle_in_session_timeout; default value for the idle_in_session_timeout session setting; controls the duration a session is permitted to idle before the session is terminated; if set to 0, there is no timeout diff --git a/pkg/ccl/logictestccl/testdata/logic_test/partitioning_deinterleave b/pkg/ccl/logictestccl/testdata/logic_test/partitioning_deinterleave new file mode 100644 index 000000000000..b1e3bebd4a2c --- /dev/null +++ b/pkg/ccl/logictestccl/testdata/logic_test/partitioning_deinterleave @@ -0,0 +1,509 @@ +# LogicTest: multiregion-9node-3region-3azs + +statement ok +SET enable_copying_partitioning_when_deinterleaving_table = true + +subtest range + +statement ok +CREATE TABLE parent (i INT8 PRIMARY KEY, FAMILY "primary" (i)) + PARTITION BY RANGE (i) + ( + PARTITION negative VALUES FROM (minvalue) TO (0), + PARTITION zero VALUES FROM (0) TO (1), + PARTITION positive VALUES FROM (1) TO (maxvalue) + ); +CREATE TABLE child (i INT, j INT, PRIMARY KEY (i, j), FAMILY "primary" (i, j)) INTERLEAVE IN PARENT parent(i); +CREATE TABLE grandchild (i INT, j INT, k INT, PRIMARY KEY (i, j, k), FAMILY "primary" (i, j, k)) INTERLEAVE IN PARENT child(i, j); +ALTER PARTITION negative OF TABLE parent CONFIGURE ZONE USING constraints='[+region=ap-southeast-2]'; +ALTER PARTITION zero OF TABLE parent CONFIGURE ZONE USING constraints='[+region=ca-central-1]'; +ALTER PARTITION positive OF TABLE parent CONFIGURE ZONE USING constraints='[+region=us-east-1]'; +CREATE INDEX idx_j_i ON child (j, i) + PARTITION BY RANGE (j) + ( + PARTITION negative VALUES FROM (minvalue) TO (0), + PARTITION zero VALUES FROM (0) TO (1), + PARTITION positive VALUES FROM (1) TO (maxvalue) + ); +CREATE INDEX idx_k_j_i ON grandchild (k, j, i) + PARTITION BY RANGE (k) + ( + PARTITION negative VALUES FROM (minvalue) TO (0), + PARTITION zero VALUES FROM (0) TO (1), + PARTITION positive VALUES FROM (1) TO (maxvalue) + ); +ALTER PARTITION negative OF INDEX grandchild@idx_k_j_i CONFIGURE ZONE USING constraints='[+region=ap-southeast-2]'; +ALTER PARTITION zero OF INDEX grandchild@idx_k_j_i CONFIGURE ZONE USING constraints='[+region=ca-central-1]'; +ALTER PARTITION positive OF INDEX grandchild@idx_k_j_i CONFIGURE ZONE USING constraints='[+region=us-east-1]'; + +query T +SELECT create_statement FROM [SHOW CREATE TABLE parent] +---- +CREATE TABLE public.parent ( + i INT8 NOT NULL, + CONSTRAINT "primary" PRIMARY KEY (i ASC), + FAMILY "primary" (i) +) PARTITION BY RANGE (i) ( + PARTITION negative VALUES FROM (MINVALUE) TO (0), + PARTITION zero VALUES FROM (0) TO (1), + PARTITION positive VALUES FROM (1) TO (MAXVALUE) +); +ALTER PARTITION negative OF INDEX test.public.parent@primary CONFIGURE ZONE USING + constraints = '[+region=ap-southeast-2]'; +ALTER PARTITION positive OF INDEX test.public.parent@primary CONFIGURE ZONE USING + constraints = '[+region=us-east-1]'; +ALTER PARTITION zero OF INDEX test.public.parent@primary CONFIGURE ZONE USING + constraints = '[+region=ca-central-1]' + +query T +SELECT create_statement FROM [SHOW CREATE TABLE child] +---- +CREATE TABLE public.child ( + i INT8 NOT NULL, + j INT8 NOT NULL, + CONSTRAINT "primary" PRIMARY KEY (i ASC, j ASC), + INDEX idx_j_i (j ASC, i ASC) PARTITION BY RANGE (j) ( + PARTITION negative VALUES FROM (MINVALUE) TO (0), + PARTITION zero VALUES FROM (0) TO (1), + PARTITION positive VALUES FROM (1) TO (MAXVALUE) + ), + FAMILY "primary" (i, j) +) INTERLEAVE IN PARENT public.parent (i) +-- Warning: Partitioned table with no zone configurations. + +query T +SELECT create_statement FROM [SHOW CREATE TABLE grandchild] +---- +CREATE TABLE public.grandchild ( + i INT8 NOT NULL, + j INT8 NOT NULL, + k INT8 NOT NULL, + CONSTRAINT "primary" PRIMARY KEY (i ASC, j ASC, k ASC), + INDEX idx_k_j_i (k ASC, j ASC, i ASC) PARTITION BY RANGE (k) ( + PARTITION negative VALUES FROM (MINVALUE) TO (0), + PARTITION zero VALUES FROM (0) TO (1), + PARTITION positive VALUES FROM (1) TO (MAXVALUE) + ), + FAMILY "primary" (i, j, k) +) INTERLEAVE IN PARENT public.child (i, j); +ALTER PARTITION negative OF INDEX test.public.grandchild@idx_k_j_i CONFIGURE ZONE USING + constraints = '[+region=ap-southeast-2]'; +ALTER PARTITION positive OF INDEX test.public.grandchild@idx_k_j_i CONFIGURE ZONE USING + constraints = '[+region=us-east-1]'; +ALTER PARTITION zero OF INDEX test.public.grandchild@idx_k_j_i CONFIGURE ZONE USING + constraints = '[+region=ca-central-1]' + +statement ok +ALTER TABLE grandchild ALTER PRIMARY KEY USING COLUMNS (i); + +query T +SELECT create_statement FROM [SHOW CREATE TABLE grandchild] +---- +CREATE TABLE public.grandchild ( + i INT8 NOT NULL, + j INT8 NOT NULL, + k INT8 NOT NULL, + CONSTRAINT "primary" PRIMARY KEY (i ASC), + UNIQUE INDEX grandchild_i_j_k_key (i ASC, j ASC, k ASC), + INDEX idx_k_j_i (k ASC, j ASC, i ASC) PARTITION BY RANGE (k) ( + PARTITION negative VALUES FROM (MINVALUE) TO (0), + PARTITION zero VALUES FROM (0) TO (1), + PARTITION positive VALUES FROM (1) TO (MAXVALUE) + ), + FAMILY "primary" (i, j, k) +) PARTITION BY RANGE (i) ( + PARTITION negative VALUES FROM (MINVALUE) TO (0), + PARTITION zero VALUES FROM (0) TO (1), + PARTITION positive VALUES FROM (1) TO (MAXVALUE) +); +ALTER PARTITION negative OF INDEX test.public.grandchild@idx_k_j_i CONFIGURE ZONE USING + constraints = '[+region=ap-southeast-2]'; +ALTER PARTITION negative OF INDEX test.public.grandchild@primary CONFIGURE ZONE USING + constraints = '[+region=ap-southeast-2]'; +ALTER PARTITION positive OF INDEX test.public.grandchild@idx_k_j_i CONFIGURE ZONE USING + constraints = '[+region=us-east-1]'; +ALTER PARTITION positive OF INDEX test.public.grandchild@primary CONFIGURE ZONE USING + constraints = '[+region=us-east-1]'; +ALTER PARTITION zero OF INDEX test.public.grandchild@idx_k_j_i CONFIGURE ZONE USING + constraints = '[+region=ca-central-1]'; +ALTER PARTITION zero OF INDEX test.public.grandchild@primary CONFIGURE ZONE USING + constraints = '[+region=ca-central-1]' + +statement ok +DROP TABLE parent, child, grandchild CASCADE; + +subtest list + +statement ok +CREATE TABLE parent (i INT8 PRIMARY KEY, FAMILY "primary" (i)) + PARTITION BY LIST (i) + ( + PARTITION negative VALUES IN (DEFAULT, -1), + PARTITION zero VALUES IN (0), + PARTITION positive VALUES IN (1) + ); +CREATE TABLE child (i INT, j INT, PRIMARY KEY (i, j), FAMILY "primary" (i, j)) INTERLEAVE IN PARENT parent(i); +CREATE TABLE grandchild (i INT, j INT, k INT, PRIMARY KEY (i, j, k), FAMILY "primary" (i, j, k)) INTERLEAVE IN PARENT child(i, j); +ALTER PARTITION negative OF TABLE parent CONFIGURE ZONE USING constraints='[+region=ap-southeast-2]'; +ALTER PARTITION zero OF TABLE parent CONFIGURE ZONE USING constraints='[+region=ca-central-1]'; +ALTER PARTITION positive OF TABLE parent CONFIGURE ZONE USING constraints='[+region=us-east-1]'; +CREATE INDEX idx_j_i ON child (j, i) + PARTITION BY LIST (j) + ( + PARTITION negative VALUES IN (DEFAULT, -1), + PARTITION zero VALUES IN (0), + PARTITION positive VALUES IN (1) + ); +CREATE INDEX idx_k_j_i ON grandchild (k, j, i) + PARTITION BY LIST (k) + ( + PARTITION negative VALUES IN (DEFAULT, -1), + PARTITION zero VALUES IN (0), + PARTITION positive VALUES IN (1) + ); +ALTER PARTITION negative OF INDEX grandchild@idx_k_j_i CONFIGURE ZONE USING constraints='[+region=ap-southeast-2]'; +ALTER PARTITION zero OF INDEX grandchild@idx_k_j_i CONFIGURE ZONE USING constraints='[+region=ca-central-1]'; +ALTER PARTITION positive OF INDEX grandchild@idx_k_j_i CONFIGURE ZONE USING constraints='[+region=us-east-1]'; + +query T +SELECT create_statement FROM [SHOW CREATE TABLE parent] +---- +CREATE TABLE public.parent ( + i INT8 NOT NULL, + CONSTRAINT "primary" PRIMARY KEY (i ASC), + FAMILY "primary" (i) +) PARTITION BY LIST (i) ( + PARTITION negative VALUES IN ((DEFAULT), (-1)), + PARTITION zero VALUES IN ((0)), + PARTITION positive VALUES IN ((1)) +); +ALTER PARTITION negative OF INDEX test.public.parent@primary CONFIGURE ZONE USING + constraints = '[+region=ap-southeast-2]'; +ALTER PARTITION positive OF INDEX test.public.parent@primary CONFIGURE ZONE USING + constraints = '[+region=us-east-1]'; +ALTER PARTITION zero OF INDEX test.public.parent@primary CONFIGURE ZONE USING + constraints = '[+region=ca-central-1]' + +query T +SELECT create_statement FROM [SHOW CREATE TABLE child] +---- +CREATE TABLE public.child ( + i INT8 NOT NULL, + j INT8 NOT NULL, + CONSTRAINT "primary" PRIMARY KEY (i ASC, j ASC), + INDEX idx_j_i (j ASC, i ASC) PARTITION BY LIST (j) ( + PARTITION negative VALUES IN ((DEFAULT), (-1)), + PARTITION zero VALUES IN ((0)), + PARTITION positive VALUES IN ((1)) + ), + FAMILY "primary" (i, j) +) INTERLEAVE IN PARENT public.parent (i) +-- Warning: Partitioned table with no zone configurations. + +query T +SELECT create_statement FROM [SHOW CREATE TABLE grandchild] +---- +CREATE TABLE public.grandchild ( + i INT8 NOT NULL, + j INT8 NOT NULL, + k INT8 NOT NULL, + CONSTRAINT "primary" PRIMARY KEY (i ASC, j ASC, k ASC), + INDEX idx_k_j_i (k ASC, j ASC, i ASC) PARTITION BY LIST (k) ( + PARTITION negative VALUES IN ((DEFAULT), (-1)), + PARTITION zero VALUES IN ((0)), + PARTITION positive VALUES IN ((1)) + ), + FAMILY "primary" (i, j, k) +) INTERLEAVE IN PARENT public.child (i, j); +ALTER PARTITION negative OF INDEX test.public.grandchild@idx_k_j_i CONFIGURE ZONE USING + constraints = '[+region=ap-southeast-2]'; +ALTER PARTITION positive OF INDEX test.public.grandchild@idx_k_j_i CONFIGURE ZONE USING + constraints = '[+region=us-east-1]'; +ALTER PARTITION zero OF INDEX test.public.grandchild@idx_k_j_i CONFIGURE ZONE USING + constraints = '[+region=ca-central-1]' + +statement error cannot change primary key of table child because table\(s\) \[grandchild\] are interleaved into it +ALTER TABLE child ALTER PRIMARY KEY USING COLUMNS (i); + +statement ok +ALTER TABLE grandchild ALTER PRIMARY KEY USING COLUMNS (i); + +query T +SELECT create_statement FROM [SHOW CREATE TABLE grandchild] +---- +CREATE TABLE public.grandchild ( + i INT8 NOT NULL, + j INT8 NOT NULL, + k INT8 NOT NULL, + CONSTRAINT "primary" PRIMARY KEY (i ASC), + UNIQUE INDEX grandchild_i_j_k_key (i ASC, j ASC, k ASC), + INDEX idx_k_j_i (k ASC, j ASC, i ASC) PARTITION BY LIST (k) ( + PARTITION negative VALUES IN ((DEFAULT), (-1)), + PARTITION zero VALUES IN ((0)), + PARTITION positive VALUES IN ((1)) + ), + FAMILY "primary" (i, j, k) +) PARTITION BY LIST (i) ( + PARTITION negative VALUES IN ((DEFAULT), (-1)), + PARTITION zero VALUES IN ((0)), + PARTITION positive VALUES IN ((1)) +); +ALTER PARTITION negative OF INDEX test.public.grandchild@idx_k_j_i CONFIGURE ZONE USING + constraints = '[+region=ap-southeast-2]'; +ALTER PARTITION negative OF INDEX test.public.grandchild@primary CONFIGURE ZONE USING + constraints = '[+region=ap-southeast-2]'; +ALTER PARTITION positive OF INDEX test.public.grandchild@idx_k_j_i CONFIGURE ZONE USING + constraints = '[+region=us-east-1]'; +ALTER PARTITION positive OF INDEX test.public.grandchild@primary CONFIGURE ZONE USING + constraints = '[+region=us-east-1]'; +ALTER PARTITION zero OF INDEX test.public.grandchild@idx_k_j_i CONFIGURE ZONE USING + constraints = '[+region=ca-central-1]'; +ALTER PARTITION zero OF INDEX test.public.grandchild@primary CONFIGURE ZONE USING + constraints = '[+region=ca-central-1]' + +statement ok +DROP TABLE parent, child, grandchild CASCADE; + +statement ok +SET enable_copying_partitioning_when_deinterleaving_table = false; + +subtest range_disabled + +statement ok +CREATE TABLE parent (i INT8 PRIMARY KEY, FAMILY "primary" (i)) + PARTITION BY RANGE (i) + ( + PARTITION negative VALUES FROM (minvalue) TO (0), + PARTITION zero VALUES FROM (0) TO (1), + PARTITION positive VALUES FROM (1) TO (maxvalue) + ); +CREATE TABLE child (i INT, j INT, PRIMARY KEY (i, j), FAMILY "primary" (i, j)) INTERLEAVE IN PARENT parent(i); +CREATE TABLE grandchild (i INT, j INT, k INT, PRIMARY KEY (i, j, k), FAMILY "primary" (i, j, k)) INTERLEAVE IN PARENT child(i, j); +ALTER PARTITION negative OF TABLE parent CONFIGURE ZONE USING constraints='[+region=ap-southeast-2]'; +ALTER PARTITION zero OF TABLE parent CONFIGURE ZONE USING constraints='[+region=ca-central-1]'; +ALTER PARTITION positive OF TABLE parent CONFIGURE ZONE USING constraints='[+region=us-east-1]'; +CREATE INDEX idx_j_i ON child (j, i) + PARTITION BY RANGE (j) + ( + PARTITION negative VALUES FROM (minvalue) TO (0), + PARTITION zero VALUES FROM (0) TO (1), + PARTITION positive VALUES FROM (1) TO (maxvalue) + ); +CREATE INDEX idx_k_j_i ON grandchild (k, j, i) + PARTITION BY RANGE (k) + ( + PARTITION negative VALUES FROM (minvalue) TO (0), + PARTITION zero VALUES FROM (0) TO (1), + PARTITION positive VALUES FROM (1) TO (maxvalue) + ); +ALTER PARTITION negative OF INDEX grandchild@idx_k_j_i CONFIGURE ZONE USING constraints='[+region=ap-southeast-2]'; +ALTER PARTITION zero OF INDEX grandchild@idx_k_j_i CONFIGURE ZONE USING constraints='[+region=ca-central-1]'; +ALTER PARTITION positive OF INDEX grandchild@idx_k_j_i CONFIGURE ZONE USING constraints='[+region=us-east-1]'; + +query T +SELECT create_statement FROM [SHOW CREATE TABLE parent] +---- +CREATE TABLE public.parent ( + i INT8 NOT NULL, + CONSTRAINT "primary" PRIMARY KEY (i ASC), + FAMILY "primary" (i) +) PARTITION BY RANGE (i) ( + PARTITION negative VALUES FROM (MINVALUE) TO (0), + PARTITION zero VALUES FROM (0) TO (1), + PARTITION positive VALUES FROM (1) TO (MAXVALUE) +); +ALTER PARTITION negative OF INDEX test.public.parent@primary CONFIGURE ZONE USING + constraints = '[+region=ap-southeast-2]'; +ALTER PARTITION positive OF INDEX test.public.parent@primary CONFIGURE ZONE USING + constraints = '[+region=us-east-1]'; +ALTER PARTITION zero OF INDEX test.public.parent@primary CONFIGURE ZONE USING + constraints = '[+region=ca-central-1]' + +query T +SELECT create_statement FROM [SHOW CREATE TABLE child] +---- +CREATE TABLE public.child ( + i INT8 NOT NULL, + j INT8 NOT NULL, + CONSTRAINT "primary" PRIMARY KEY (i ASC, j ASC), + INDEX idx_j_i (j ASC, i ASC) PARTITION BY RANGE (j) ( + PARTITION negative VALUES FROM (MINVALUE) TO (0), + PARTITION zero VALUES FROM (0) TO (1), + PARTITION positive VALUES FROM (1) TO (MAXVALUE) + ), + FAMILY "primary" (i, j) +) INTERLEAVE IN PARENT public.parent (i) +-- Warning: Partitioned table with no zone configurations. + +query T +SELECT create_statement FROM [SHOW CREATE TABLE grandchild] +---- +CREATE TABLE public.grandchild ( + i INT8 NOT NULL, + j INT8 NOT NULL, + k INT8 NOT NULL, + CONSTRAINT "primary" PRIMARY KEY (i ASC, j ASC, k ASC), + INDEX idx_k_j_i (k ASC, j ASC, i ASC) PARTITION BY RANGE (k) ( + PARTITION negative VALUES FROM (MINVALUE) TO (0), + PARTITION zero VALUES FROM (0) TO (1), + PARTITION positive VALUES FROM (1) TO (MAXVALUE) + ), + FAMILY "primary" (i, j, k) +) INTERLEAVE IN PARENT public.child (i, j); +ALTER PARTITION negative OF INDEX test.public.grandchild@idx_k_j_i CONFIGURE ZONE USING + constraints = '[+region=ap-southeast-2]'; +ALTER PARTITION positive OF INDEX test.public.grandchild@idx_k_j_i CONFIGURE ZONE USING + constraints = '[+region=us-east-1]'; +ALTER PARTITION zero OF INDEX test.public.grandchild@idx_k_j_i CONFIGURE ZONE USING + constraints = '[+region=ca-central-1]' + +statement ok +ALTER TABLE grandchild ALTER PRIMARY KEY USING COLUMNS (i); + +query T +SELECT create_statement FROM [SHOW CREATE TABLE grandchild] +---- +CREATE TABLE public.grandchild ( + i INT8 NOT NULL, + j INT8 NOT NULL, + k INT8 NOT NULL, + CONSTRAINT "primary" PRIMARY KEY (i ASC), + UNIQUE INDEX grandchild_i_j_k_key (i ASC, j ASC, k ASC), + INDEX idx_k_j_i (k ASC, j ASC, i ASC) PARTITION BY RANGE (k) ( + PARTITION negative VALUES FROM (MINVALUE) TO (0), + PARTITION zero VALUES FROM (0) TO (1), + PARTITION positive VALUES FROM (1) TO (MAXVALUE) + ), + FAMILY "primary" (i, j, k) +); +ALTER PARTITION negative OF INDEX test.public.grandchild@idx_k_j_i CONFIGURE ZONE USING + constraints = '[+region=ap-southeast-2]'; +ALTER PARTITION positive OF INDEX test.public.grandchild@idx_k_j_i CONFIGURE ZONE USING + constraints = '[+region=us-east-1]'; +ALTER PARTITION zero OF INDEX test.public.grandchild@idx_k_j_i CONFIGURE ZONE USING + constraints = '[+region=ca-central-1]' + +statement ok +DROP TABLE parent, child, grandchild CASCADE; + +subtest list_disabled + +statement ok +CREATE TABLE parent (i INT8 PRIMARY KEY, FAMILY "primary" (i)) + PARTITION BY LIST (i) + ( + PARTITION negative VALUES IN (DEFAULT, -1), + PARTITION zero VALUES IN (0), + PARTITION positive VALUES IN (1) + ); +CREATE TABLE child (i INT, j INT, PRIMARY KEY (i, j), FAMILY "primary" (i, j)) INTERLEAVE IN PARENT parent(i); +CREATE TABLE grandchild (i INT, j INT, k INT, PRIMARY KEY (i, j, k), FAMILY "primary" (i, j, k)) INTERLEAVE IN PARENT child(i, j); +ALTER PARTITION negative OF TABLE parent CONFIGURE ZONE USING constraints='[+region=ap-southeast-2]'; +ALTER PARTITION zero OF TABLE parent CONFIGURE ZONE USING constraints='[+region=ca-central-1]'; +ALTER PARTITION positive OF TABLE parent CONFIGURE ZONE USING constraints='[+region=us-east-1]'; +CREATE INDEX idx_j_i ON child (j, i) + PARTITION BY LIST (j) + ( + PARTITION negative VALUES IN (DEFAULT, -1), + PARTITION zero VALUES IN (0), + PARTITION positive VALUES IN (1) + ); +CREATE INDEX idx_k_j_i ON grandchild (k, j, i) + PARTITION BY LIST (k) + ( + PARTITION negative VALUES IN (DEFAULT, -1), + PARTITION zero VALUES IN (0), + PARTITION positive VALUES IN (1) + ); +ALTER PARTITION negative OF INDEX grandchild@idx_k_j_i CONFIGURE ZONE USING constraints='[+region=ap-southeast-2]'; +ALTER PARTITION zero OF INDEX grandchild@idx_k_j_i CONFIGURE ZONE USING constraints='[+region=ca-central-1]'; +ALTER PARTITION positive OF INDEX grandchild@idx_k_j_i CONFIGURE ZONE USING constraints='[+region=us-east-1]'; + +query T +SELECT create_statement FROM [SHOW CREATE TABLE parent] +---- +CREATE TABLE public.parent ( + i INT8 NOT NULL, + CONSTRAINT "primary" PRIMARY KEY (i ASC), + FAMILY "primary" (i) +) PARTITION BY LIST (i) ( + PARTITION negative VALUES IN ((DEFAULT), (-1)), + PARTITION zero VALUES IN ((0)), + PARTITION positive VALUES IN ((1)) +); +ALTER PARTITION negative OF INDEX test.public.parent@primary CONFIGURE ZONE USING + constraints = '[+region=ap-southeast-2]'; +ALTER PARTITION positive OF INDEX test.public.parent@primary CONFIGURE ZONE USING + constraints = '[+region=us-east-1]'; +ALTER PARTITION zero OF INDEX test.public.parent@primary CONFIGURE ZONE USING + constraints = '[+region=ca-central-1]' + +query T +SELECT create_statement FROM [SHOW CREATE TABLE child] +---- +CREATE TABLE public.child ( + i INT8 NOT NULL, + j INT8 NOT NULL, + CONSTRAINT "primary" PRIMARY KEY (i ASC, j ASC), + INDEX idx_j_i (j ASC, i ASC) PARTITION BY LIST (j) ( + PARTITION negative VALUES IN ((DEFAULT), (-1)), + PARTITION zero VALUES IN ((0)), + PARTITION positive VALUES IN ((1)) + ), + FAMILY "primary" (i, j) +) INTERLEAVE IN PARENT public.parent (i) +-- Warning: Partitioned table with no zone configurations. + +query T +SELECT create_statement FROM [SHOW CREATE TABLE grandchild] +---- +CREATE TABLE public.grandchild ( + i INT8 NOT NULL, + j INT8 NOT NULL, + k INT8 NOT NULL, + CONSTRAINT "primary" PRIMARY KEY (i ASC, j ASC, k ASC), + INDEX idx_k_j_i (k ASC, j ASC, i ASC) PARTITION BY LIST (k) ( + PARTITION negative VALUES IN ((DEFAULT), (-1)), + PARTITION zero VALUES IN ((0)), + PARTITION positive VALUES IN ((1)) + ), + FAMILY "primary" (i, j, k) +) INTERLEAVE IN PARENT public.child (i, j); +ALTER PARTITION negative OF INDEX test.public.grandchild@idx_k_j_i CONFIGURE ZONE USING + constraints = '[+region=ap-southeast-2]'; +ALTER PARTITION positive OF INDEX test.public.grandchild@idx_k_j_i CONFIGURE ZONE USING + constraints = '[+region=us-east-1]'; +ALTER PARTITION zero OF INDEX test.public.grandchild@idx_k_j_i CONFIGURE ZONE USING + constraints = '[+region=ca-central-1]' + +statement error cannot change primary key of table child because table\(s\) \[grandchild\] are interleaved into it +ALTER TABLE child ALTER PRIMARY KEY USING COLUMNS (i); + +statement ok +ALTER TABLE grandchild ALTER PRIMARY KEY USING COLUMNS (i); + +query T +SELECT create_statement FROM [SHOW CREATE TABLE grandchild] +---- +CREATE TABLE public.grandchild ( + i INT8 NOT NULL, + j INT8 NOT NULL, + k INT8 NOT NULL, + CONSTRAINT "primary" PRIMARY KEY (i ASC), + UNIQUE INDEX grandchild_i_j_k_key (i ASC, j ASC, k ASC), + INDEX idx_k_j_i (k ASC, j ASC, i ASC) PARTITION BY LIST (k) ( + PARTITION negative VALUES IN ((DEFAULT), (-1)), + PARTITION zero VALUES IN ((0)), + PARTITION positive VALUES IN ((1)) + ), + FAMILY "primary" (i, j, k) +); +ALTER PARTITION negative OF INDEX test.public.grandchild@idx_k_j_i CONFIGURE ZONE USING + constraints = '[+region=ap-southeast-2]'; +ALTER PARTITION positive OF INDEX test.public.grandchild@idx_k_j_i CONFIGURE ZONE USING + constraints = '[+region=us-east-1]'; +ALTER PARTITION zero OF INDEX test.public.grandchild@idx_k_j_i CONFIGURE ZONE USING + constraints = '[+region=ca-central-1]' + +statement ok +DROP TABLE parent, child, grandchild CASCADE; diff --git a/pkg/sql/alter_primary_key.go b/pkg/sql/alter_primary_key.go index 861d96ca0344..124501c7855c 100644 --- a/pkg/sql/alter_primary_key.go +++ b/pkg/sql/alter_primary_key.go @@ -14,6 +14,7 @@ import ( "context" "strings" + "github.com/cockroachdb/cockroach/pkg/config/zonepb" "github.com/cockroachdb/cockroach/pkg/server/telemetry" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" "github.com/cockroachdb/cockroach/pkg/sql/catalog/resolver" @@ -26,6 +27,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/util/errorutil/unimplemented" "github.com/cockroachdb/cockroach/pkg/util/protoutil" "github.com/cockroachdb/errors" + "github.com/gogo/protobuf/proto" ) // alterPrimaryKeyLocalitySwap contains metadata on a locality swap for @@ -339,6 +341,12 @@ func (p *planner) AlterPrimaryKey( if err != nil { return err } + } else { + if err := maybeCopyPartitioningWhenDeinterleaving( + ctx, p, tableDesc, newPrimaryIndexDesc, + ); err != nil { + return err + } } if partitionAllBy != nil { @@ -545,6 +553,95 @@ func (p *planner) AlterPrimaryKey( return nil } +func maybeCopyPartitioningWhenDeinterleaving( + ctx context.Context, + p *planner, + tableDesc *tabledesc.Mutable, + newPrimaryIndexDesc *descpb.IndexDescriptor, +) error { + if tableDesc.GetPrimaryIndex().NumInterleaveAncestors() == 0 || + !p.SessionData().CopyPartitioningWhenDeinterleavingTable || + len(newPrimaryIndexDesc.Interleave.Ancestors) > 0 { + return nil + } + + // The old primary key was interleaved in a parent and the new one is not. + // In this case, we need to clone out the old primary key's partitioning + // and zone configs and apply them to the new primary index. We do this + // if the old primary index and the new primary index have the exact same + // columns. That also allows us to side-step discussions of what to do + // about partitioning for any newly created unique index we might create + // below. + + root := tableDesc.GetPrimaryIndex().GetInterleaveAncestor(0) + interleaveRoot, err := p.Descriptors().GetImmutableTableByID(ctx, p.txn, root.TableID, tree.ObjectLookupFlags{ + CommonLookupFlags: tree.CommonLookupFlags{ + Required: true, + AvoidCached: true, + }, + DesiredObjectKind: tree.TableObject, + }) + if err != nil { + return errors.Wrap(err, "looking up interleaved root") + } + rootIndex, err := interleaveRoot.FindIndexWithID(root.IndexID) + if err != nil { + return errors.Wrap(err, "looking up interleaved root index") + } + + // If the new primary key does not have the interleave root as a prefix, + // do not copy the interleave. + if rootKeys := rootIndex.IndexDesc().ColumnIDs; !descpb.ColumnIDs.Equals( + rootKeys, newPrimaryIndexDesc.ColumnIDs[:len(rootKeys)], + ) { + return nil + } + + // The parent is not partitioned, return. + if rootIndex.GetPartitioning().NumColumns == 0 { + return nil + } + part := rootIndex.GetPartitioning() + newPrimaryIndexDesc.Partitioning = *protoutil.Clone(&part).(*descpb.PartitioningDescriptor) + rootCfg, err := getZoneConfigRaw(ctx, p.txn, p.execCfg.Codec, root.TableID) + if err != nil { + return errors.Wrapf(err, "retrieving zone config for table %s [%d]", + interleaveRoot.GetName(), interleaveRoot.GetID()) + } + tableCfg, err := getZoneConfigRaw(ctx, p.txn, p.execCfg.Codec, tableDesc.GetID()) + if err != nil { + return errors.Wrapf(err, "retrieving zone config for table %s [%d]", + tableDesc.GetName(), tableDesc.GetID()) + } + // Initialize the zone config for the child. We expect it to be nil because + // the table was an interleaved child and we did not allow such children to + // have zone configs. It may be a subzone placeholder because other indexes + // might be partitioned and have zone configs. + if tableCfg == nil { + // Marking NumReplicas as 0 indicates that this zone config is a + // subzone placeholder. We assume that the value in copying out the + // partitioning is to copy out the configuration as it applies to the + // partitions of the primary index. + tableCfg = &zonepb.ZoneConfig{ + NumReplicas: proto.Int(0), + } + } else if !tableCfg.IsSubzonePlaceholder() { + return errors.AssertionFailedf("child table %s [%d] of interleave was not a subzone placeholder", + tableDesc.GetName(), tableDesc.GetID()) + } + + for _, s := range rootCfg.Subzones { + if s.IndexID == uint32(root.IndexID) { + s.IndexID = uint32(newPrimaryIndexDesc.ID) + tableCfg.Subzones = append(tableCfg.Subzones, s) + } + } + _, err = writeZoneConfig( + ctx, p.txn, tableDesc.GetID(), tableDesc, tableCfg, p.execCfg, true, + ) + return err +} + // Given the current table descriptor and the new primary keys // index descriptor this function determines if the two are // equivalent and if any index creation operations are needed diff --git a/pkg/sql/exec_util.go b/pkg/sql/exec_util.go index 1f148f2a7b7f..d51857cc8c24 100644 --- a/pkg/sql/exec_util.go +++ b/pkg/sql/exec_util.go @@ -421,6 +421,12 @@ var experimentalComputedColumnRewrites = settings.RegisterValidatedStringSetting }, ) +var copyPartitioningWhenDeinterleavingTable = settings.RegisterBoolSetting( + `sql.defaults.copy_partitioning_when_deinterleaving_table.enabled`, + `default value for enable_copying_partitioning_when_deinterleaving_table session variable`, + false, +).WithPublic() + // ExperimentalDistSQLPlanningClusterSettingName is the name for the cluster // setting that controls experimentalDistSQLPlanningClusterMode below. const ExperimentalDistSQLPlanningClusterSettingName = "sql.defaults.experimental_distsql_planning" @@ -2444,11 +2450,17 @@ func (m *sessionDataMutator) initSequenceCache() { m.data.SequenceCache = sessiondata.SequenceCache{} } -// SetStubCatalogTableEnabled sets default value for stub_catalog_tables. +// SetStubCatalogTablesEnabled sets default value for stub_catalog_tables. func (m *sessionDataMutator) SetStubCatalogTablesEnabled(enabled bool) { m.data.StubCatalogTablesEnabled = enabled } +// SetCopyPartitioningWhenDeinterleavingTable sets the value for +// CopyPartitioningWhenDeinterleavingTable. +func (m *sessionDataMutator) SetCopyPartitioningWhenDeinterleavingTable(b bool) { + m.data.CopyPartitioningWhenDeinterleavingTable = b +} + func (m *sessionDataMutator) SetExperimentalComputedColumnRewrites(val string) { m.data.ExperimentalComputedColumnRewrites = val } diff --git a/pkg/sql/logictest/testdata/logic_test/information_schema b/pkg/sql/logictest/testdata/logic_test/information_schema index 6557eedf233e..dc2bbb1c6046 100755 --- a/pkg/sql/logictest/testdata/logic_test/information_schema +++ b/pkg/sql/logictest/testdata/logic_test/information_schema @@ -3596,82 +3596,83 @@ subtest variables query TT colnames SELECT * FROM information_schema.session_variables where variable not in ('crdb_version', 'session_id', 'distsql', 'vectorize', 'experimental_distsql_planning') ---- -variable value -allow_prepare_as_opt_plan off -application_name · -bytea_output hex -client_encoding UTF8 -client_min_messages notice -database test -datestyle ISO, MDY -default_int_size 8 -default_tablespace · -default_transaction_isolation serializable -default_transaction_priority normal -default_transaction_read_only off -default_transaction_use_follower_reads off -disable_partially_distributed_plans off -disallow_full_table_scans off -enable_drop_enum_value off -enable_experimental_alter_column_type_general off -enable_experimental_stream_replication off -enable_implicit_select_for_update on -enable_insert_fast_path on -enable_seqscan on -enable_zigzag_join on -escape_string_warning on -experimental_computed_column_rewrites · -experimental_enable_hash_sharded_indexes off -experimental_enable_implicit_column_partitioning off -experimental_enable_temp_tables off -experimental_enable_unique_without_index_constraints on -experimental_use_new_schema_changer off -extra_float_digits 0 -force_savepoint_restart off -foreign_key_cascades_limit 10000 -idle_in_session_timeout 0 -idle_in_transaction_session_timeout 0 -integer_datetimes on -intervalstyle postgres -locality region=test,dc=dc1 -locality_optimized_partitioned_index_scan on -lock_timeout 0 -max_identifier_length 128 -max_index_keys 32 -node_id 1 -optimizer on -optimizer_improve_disjunction_selectivity off -optimizer_use_histograms on -optimizer_use_multicol_stats on -override_multi_region_zone_config off -prefer_lookup_joins_for_fks off -reorder_joins_limit 8 -require_explicit_primary_keys off -results_buffer_size 16384 -row_security off -save_tables_prefix · -search_path $user,public -serial_normalization rowid -server_encoding UTF8 -server_version 13.0.0 -server_version_num 130000 -session_authorization root -session_user root -sql_safe_updates off -ssl_renegotiation_limit 0 -standard_conforming_strings on -statement_timeout 0 -stub_catalog_tables on -synchronize_seqscans on -synchronous_commit on -testing_vectorize_inject_panics off -timezone UTC -tracing off -transaction_isolation serializable -transaction_priority normal -transaction_read_only off -transaction_status NoTxn -vectorize_row_count_threshold 0 +variable value +allow_prepare_as_opt_plan off +application_name · +bytea_output hex +client_encoding UTF8 +client_min_messages notice +database test +datestyle ISO, MDY +default_int_size 8 +default_tablespace · +default_transaction_isolation serializable +default_transaction_priority normal +default_transaction_read_only off +default_transaction_use_follower_reads off +disable_partially_distributed_plans off +disallow_full_table_scans off +enable_copying_partitioning_when_deinterleaving_table off +enable_drop_enum_value off +enable_experimental_alter_column_type_general off +enable_experimental_stream_replication off +enable_implicit_select_for_update on +enable_insert_fast_path on +enable_seqscan on +enable_zigzag_join on +escape_string_warning on +experimental_computed_column_rewrites · +experimental_enable_hash_sharded_indexes off +experimental_enable_implicit_column_partitioning off +experimental_enable_temp_tables off +experimental_enable_unique_without_index_constraints on +experimental_use_new_schema_changer off +extra_float_digits 0 +force_savepoint_restart off +foreign_key_cascades_limit 10000 +idle_in_session_timeout 0 +idle_in_transaction_session_timeout 0 +integer_datetimes on +intervalstyle postgres +locality region=test,dc=dc1 +locality_optimized_partitioned_index_scan on +lock_timeout 0 +max_identifier_length 128 +max_index_keys 32 +node_id 1 +optimizer on +optimizer_improve_disjunction_selectivity off +optimizer_use_histograms on +optimizer_use_multicol_stats on +override_multi_region_zone_config off +prefer_lookup_joins_for_fks off +reorder_joins_limit 8 +require_explicit_primary_keys off +results_buffer_size 16384 +row_security off +save_tables_prefix · +search_path $user,public +serial_normalization rowid +server_encoding UTF8 +server_version 13.0.0 +server_version_num 130000 +session_authorization root +session_user root +sql_safe_updates off +ssl_renegotiation_limit 0 +standard_conforming_strings on +statement_timeout 0 +stub_catalog_tables on +synchronize_seqscans on +synchronous_commit on +testing_vectorize_inject_panics off +timezone UTC +tracing off +transaction_isolation serializable +transaction_priority normal +transaction_read_only off +transaction_status NoTxn +vectorize_row_count_threshold 0 # information_schema can be used with the anonymous database. # It should show information across all databases. diff --git a/pkg/sql/logictest/testdata/logic_test/pg_catalog b/pkg/sql/logictest/testdata/logic_test/pg_catalog index 016c88f5e2d0..9f98e7939078 100644 --- a/pkg/sql/logictest/testdata/logic_test/pg_catalog +++ b/pkg/sql/logictest/testdata/logic_test/pg_catalog @@ -2088,79 +2088,80 @@ FROM WHERE name != 'optimizer' AND name != 'crdb_version' AND name != 'session_id' ---- -name setting category short_desc extra_desc vartype -application_name · NULL NULL NULL string -bytea_output hex NULL NULL NULL string -client_encoding UTF8 NULL NULL NULL string -client_min_messages notice NULL NULL NULL string -database test NULL NULL NULL string -datestyle ISO, MDY NULL NULL NULL string -default_int_size 8 NULL NULL NULL string -default_tablespace · NULL NULL NULL string -default_transaction_isolation serializable NULL NULL NULL string -default_transaction_priority normal NULL NULL NULL string -default_transaction_read_only off NULL NULL NULL string -default_transaction_use_follower_reads off NULL NULL NULL string -disable_partially_distributed_plans off NULL NULL NULL string -disallow_full_table_scans off NULL NULL NULL string -distsql off NULL NULL NULL string -enable_drop_enum_value off NULL NULL NULL string -enable_experimental_alter_column_type_general off NULL NULL NULL string -enable_experimental_stream_replication off NULL NULL NULL string -enable_implicit_select_for_update on NULL NULL NULL string -enable_insert_fast_path on NULL NULL NULL string -enable_seqscan on NULL NULL NULL string -enable_zigzag_join on NULL NULL NULL string -escape_string_warning on NULL NULL NULL string -experimental_distsql_planning off NULL NULL NULL string -experimental_enable_hash_sharded_indexes off NULL NULL NULL string -experimental_enable_implicit_column_partitioning off NULL NULL NULL string -experimental_enable_temp_tables off NULL NULL NULL string -experimental_enable_unique_without_index_constraints on NULL NULL NULL string -experimental_use_new_schema_changer off NULL NULL NULL string -extra_float_digits 0 NULL NULL NULL string -force_savepoint_restart off NULL NULL NULL string -foreign_key_cascades_limit 10000 NULL NULL NULL string -idle_in_session_timeout 0 NULL NULL NULL string -idle_in_transaction_session_timeout 0 NULL NULL NULL string -integer_datetimes on NULL NULL NULL string -intervalstyle postgres NULL NULL NULL string -locality region=test,dc=dc1 NULL NULL NULL string -locality_optimized_partitioned_index_scan on NULL NULL NULL string -lock_timeout 0 NULL NULL NULL string -max_identifier_length 128 NULL NULL NULL string -max_index_keys 32 NULL NULL NULL string -node_id 1 NULL NULL NULL string -optimizer_improve_disjunction_selectivity off NULL NULL NULL string -optimizer_use_histograms on NULL NULL NULL string -optimizer_use_multicol_stats on NULL NULL NULL string -override_multi_region_zone_config off NULL NULL NULL string -prefer_lookup_joins_for_fks off NULL NULL NULL string -reorder_joins_limit 8 NULL NULL NULL string -require_explicit_primary_keys off NULL NULL NULL string -results_buffer_size 16384 NULL NULL NULL string -row_security off NULL NULL NULL string -search_path $user,public NULL NULL NULL string -serial_normalization rowid NULL NULL NULL string -server_encoding UTF8 NULL NULL NULL string -server_version 13.0.0 NULL NULL NULL string -server_version_num 130000 NULL NULL NULL string -session_user root NULL NULL NULL string -sql_safe_updates off NULL NULL NULL string -standard_conforming_strings on NULL NULL NULL string -statement_timeout 0 NULL NULL NULL string -stub_catalog_tables on NULL NULL NULL string -synchronize_seqscans on NULL NULL NULL string -synchronous_commit on NULL NULL NULL string -testing_vectorize_inject_panics off NULL NULL NULL string -timezone UTC NULL NULL NULL string -tracing off NULL NULL NULL string -transaction_isolation serializable NULL NULL NULL string -transaction_priority normal NULL NULL NULL string -transaction_read_only off NULL NULL NULL string -transaction_status NoTxn NULL NULL NULL string -vectorize on NULL NULL NULL string -vectorize_row_count_threshold 0 NULL NULL NULL string +name setting category short_desc extra_desc vartype +application_name · NULL NULL NULL string +bytea_output hex NULL NULL NULL string +client_encoding UTF8 NULL NULL NULL string +client_min_messages notice NULL NULL NULL string +database test NULL NULL NULL string +datestyle ISO, MDY NULL NULL NULL string +default_int_size 8 NULL NULL NULL string +default_tablespace · NULL NULL NULL string +default_transaction_isolation serializable NULL NULL NULL string +default_transaction_priority normal NULL NULL NULL string +default_transaction_read_only off NULL NULL NULL string +default_transaction_use_follower_reads off NULL NULL NULL string +disable_partially_distributed_plans off NULL NULL NULL string +disallow_full_table_scans off NULL NULL NULL string +distsql off NULL NULL NULL string +enable_copying_partitioning_when_deinterleaving_table off NULL NULL NULL string +enable_drop_enum_value off NULL NULL NULL string +enable_experimental_alter_column_type_general off NULL NULL NULL string +enable_experimental_stream_replication off NULL NULL NULL string +enable_implicit_select_for_update on NULL NULL NULL string +enable_insert_fast_path on NULL NULL NULL string +enable_seqscan on NULL NULL NULL string +enable_zigzag_join on NULL NULL NULL string +escape_string_warning on NULL NULL NULL string +experimental_distsql_planning off NULL NULL NULL string +experimental_enable_hash_sharded_indexes off NULL NULL NULL string +experimental_enable_implicit_column_partitioning off NULL NULL NULL string +experimental_enable_temp_tables off NULL NULL NULL string +experimental_enable_unique_without_index_constraints on NULL NULL NULL string +experimental_use_new_schema_changer off NULL NULL NULL string +extra_float_digits 0 NULL NULL NULL string +force_savepoint_restart off NULL NULL NULL string +foreign_key_cascades_limit 10000 NULL NULL NULL string +idle_in_session_timeout 0 NULL NULL NULL string +idle_in_transaction_session_timeout 0 NULL NULL NULL string +integer_datetimes on NULL NULL NULL string +intervalstyle postgres NULL NULL NULL string +locality region=test,dc=dc1 NULL NULL NULL string +locality_optimized_partitioned_index_scan on NULL NULL NULL string +lock_timeout 0 NULL NULL NULL string +max_identifier_length 128 NULL NULL NULL string +max_index_keys 32 NULL NULL NULL string +node_id 1 NULL NULL NULL string +optimizer_improve_disjunction_selectivity off NULL NULL NULL string +optimizer_use_histograms on NULL NULL NULL string +optimizer_use_multicol_stats on NULL NULL NULL string +override_multi_region_zone_config off NULL NULL NULL string +prefer_lookup_joins_for_fks off NULL NULL NULL string +reorder_joins_limit 8 NULL NULL NULL string +require_explicit_primary_keys off NULL NULL NULL string +results_buffer_size 16384 NULL NULL NULL string +row_security off NULL NULL NULL string +search_path $user,public NULL NULL NULL string +serial_normalization rowid NULL NULL NULL string +server_encoding UTF8 NULL NULL NULL string +server_version 13.0.0 NULL NULL NULL string +server_version_num 130000 NULL NULL NULL string +session_user root NULL NULL NULL string +sql_safe_updates off NULL NULL NULL string +standard_conforming_strings on NULL NULL NULL string +statement_timeout 0 NULL NULL NULL string +stub_catalog_tables on NULL NULL NULL string +synchronize_seqscans on NULL NULL NULL string +synchronous_commit on NULL NULL NULL string +testing_vectorize_inject_panics off NULL NULL NULL string +timezone UTC NULL NULL NULL string +tracing off NULL NULL NULL string +transaction_isolation serializable NULL NULL NULL string +transaction_priority normal NULL NULL NULL string +transaction_read_only off NULL NULL NULL string +transaction_status NoTxn NULL NULL NULL string +vectorize on NULL NULL NULL string +vectorize_row_count_threshold 0 NULL NULL NULL string query TTTTTTT colnames SELECT @@ -2170,159 +2171,161 @@ FROM WHERE name != 'optimizer' AND name != 'crdb_version' AND name != 'session_id' ---- -name setting unit context enumvals boot_val reset_val -application_name · NULL user NULL · · -bytea_output hex NULL user NULL hex hex -client_encoding UTF8 NULL user NULL UTF8 UTF8 -client_min_messages notice NULL user NULL notice notice -database test NULL user NULL · test -datestyle ISO, MDY NULL user NULL ISO, MDY ISO, MDY -default_int_size 8 NULL user NULL 8 8 -default_tablespace · NULL user NULL · · -default_transaction_isolation serializable NULL user NULL default default -default_transaction_priority normal NULL user NULL normal normal -default_transaction_read_only off NULL user NULL off off -default_transaction_use_follower_reads off NULL user NULL off off -disable_partially_distributed_plans off NULL user NULL off off -disallow_full_table_scans off NULL user NULL off off -distsql off NULL user NULL off off -enable_drop_enum_value off NULL user NULL off off -enable_experimental_alter_column_type_general off NULL user NULL off off -enable_experimental_stream_replication off NULL user NULL off off -enable_implicit_select_for_update on NULL user NULL on on -enable_insert_fast_path on NULL user NULL on on -enable_seqscan on NULL user NULL on on -enable_zigzag_join on NULL user NULL on on -escape_string_warning on NULL user NULL on on -experimental_distsql_planning off NULL user NULL off off -experimental_enable_hash_sharded_indexes off NULL user NULL off off -experimental_enable_implicit_column_partitioning off NULL user NULL off off -experimental_enable_temp_tables off NULL user NULL off off -experimental_enable_unique_without_index_constraints on NULL user NULL off off -experimental_use_new_schema_changer off NULL user NULL off off -extra_float_digits 0 NULL user NULL 0 2 -force_savepoint_restart off NULL user NULL off off -foreign_key_cascades_limit 10000 NULL user NULL 10000 10000 -idle_in_session_timeout 0 NULL user NULL 0s 0s -idle_in_transaction_session_timeout 0 NULL user NULL 0s 0s -integer_datetimes on NULL user NULL on on -intervalstyle postgres NULL user NULL postgres postgres -locality region=test,dc=dc1 NULL user NULL region=test,dc=dc1 region=test,dc=dc1 -locality_optimized_partitioned_index_scan on NULL user NULL on on -lock_timeout 0 NULL user NULL 0 0 -max_identifier_length 128 NULL user NULL 128 128 -max_index_keys 32 NULL user NULL 32 32 -node_id 1 NULL user NULL 1 1 -optimizer_improve_disjunction_selectivity off NULL user NULL off off -optimizer_use_histograms on NULL user NULL on on -optimizer_use_multicol_stats on NULL user NULL on on -override_multi_region_zone_config off NULL user NULL off off -prefer_lookup_joins_for_fks off NULL user NULL off off -reorder_joins_limit 8 NULL user NULL 8 8 -require_explicit_primary_keys off NULL user NULL off off -results_buffer_size 16384 NULL user NULL 16384 16384 -row_security off NULL user NULL off off -search_path $user,public NULL user NULL $user,public $user,public -serial_normalization rowid NULL user NULL rowid rowid -server_encoding UTF8 NULL user NULL UTF8 UTF8 -server_version 13.0.0 NULL user NULL 13.0.0 13.0.0 -server_version_num 130000 NULL user NULL 130000 130000 -session_user root NULL user NULL root root -sql_safe_updates off NULL user NULL off off -standard_conforming_strings on NULL user NULL on on -statement_timeout 0 NULL user NULL 0s 0s -stub_catalog_tables on NULL user NULL on on -synchronize_seqscans on NULL user NULL on on -synchronous_commit on NULL user NULL on on -testing_vectorize_inject_panics off NULL user NULL off off -timezone UTC NULL user NULL UTC UTC -tracing off NULL user NULL off off -transaction_isolation serializable NULL user NULL serializable serializable -transaction_priority normal NULL user NULL normal normal -transaction_read_only off NULL user NULL off off -transaction_status NoTxn NULL user NULL NoTxn NoTxn -vectorize on NULL user NULL on on -vectorize_row_count_threshold 0 NULL user NULL 0 0 +name setting unit context enumvals boot_val reset_val +application_name · NULL user NULL · · +bytea_output hex NULL user NULL hex hex +client_encoding UTF8 NULL user NULL UTF8 UTF8 +client_min_messages notice NULL user NULL notice notice +database test NULL user NULL · test +datestyle ISO, MDY NULL user NULL ISO, MDY ISO, MDY +default_int_size 8 NULL user NULL 8 8 +default_tablespace · NULL user NULL · · +default_transaction_isolation serializable NULL user NULL default default +default_transaction_priority normal NULL user NULL normal normal +default_transaction_read_only off NULL user NULL off off +default_transaction_use_follower_reads off NULL user NULL off off +disable_partially_distributed_plans off NULL user NULL off off +disallow_full_table_scans off NULL user NULL off off +distsql off NULL user NULL off off +enable_copying_partitioning_when_deinterleaving_table off NULL user NULL off off +enable_drop_enum_value off NULL user NULL off off +enable_experimental_alter_column_type_general off NULL user NULL off off +enable_experimental_stream_replication off NULL user NULL off off +enable_implicit_select_for_update on NULL user NULL on on +enable_insert_fast_path on NULL user NULL on on +enable_seqscan on NULL user NULL on on +enable_zigzag_join on NULL user NULL on on +escape_string_warning on NULL user NULL on on +experimental_distsql_planning off NULL user NULL off off +experimental_enable_hash_sharded_indexes off NULL user NULL off off +experimental_enable_implicit_column_partitioning off NULL user NULL off off +experimental_enable_temp_tables off NULL user NULL off off +experimental_enable_unique_without_index_constraints on NULL user NULL off off +experimental_use_new_schema_changer off NULL user NULL off off +extra_float_digits 0 NULL user NULL 0 2 +force_savepoint_restart off NULL user NULL off off +foreign_key_cascades_limit 10000 NULL user NULL 10000 10000 +idle_in_session_timeout 0 NULL user NULL 0s 0s +idle_in_transaction_session_timeout 0 NULL user NULL 0s 0s +integer_datetimes on NULL user NULL on on +intervalstyle postgres NULL user NULL postgres postgres +locality region=test,dc=dc1 NULL user NULL region=test,dc=dc1 region=test,dc=dc1 +locality_optimized_partitioned_index_scan on NULL user NULL on on +lock_timeout 0 NULL user NULL 0 0 +max_identifier_length 128 NULL user NULL 128 128 +max_index_keys 32 NULL user NULL 32 32 +node_id 1 NULL user NULL 1 1 +optimizer_improve_disjunction_selectivity off NULL user NULL off off +optimizer_use_histograms on NULL user NULL on on +optimizer_use_multicol_stats on NULL user NULL on on +override_multi_region_zone_config off NULL user NULL off off +prefer_lookup_joins_for_fks off NULL user NULL off off +reorder_joins_limit 8 NULL user NULL 8 8 +require_explicit_primary_keys off NULL user NULL off off +results_buffer_size 16384 NULL user NULL 16384 16384 +row_security off NULL user NULL off off +search_path $user,public NULL user NULL $user,public $user,public +serial_normalization rowid NULL user NULL rowid rowid +server_encoding UTF8 NULL user NULL UTF8 UTF8 +server_version 13.0.0 NULL user NULL 13.0.0 13.0.0 +server_version_num 130000 NULL user NULL 130000 130000 +session_user root NULL user NULL root root +sql_safe_updates off NULL user NULL off off +standard_conforming_strings on NULL user NULL on on +statement_timeout 0 NULL user NULL 0s 0s +stub_catalog_tables on NULL user NULL on on +synchronize_seqscans on NULL user NULL on on +synchronous_commit on NULL user NULL on on +testing_vectorize_inject_panics off NULL user NULL off off +timezone UTC NULL user NULL UTC UTC +tracing off NULL user NULL off off +transaction_isolation serializable NULL user NULL serializable serializable +transaction_priority normal NULL user NULL normal normal +transaction_read_only off NULL user NULL off off +transaction_status NoTxn NULL user NULL NoTxn NoTxn +vectorize on NULL user NULL on on +vectorize_row_count_threshold 0 NULL user NULL 0 0 query TTTTTT colnames SELECT name, source, min_val, max_val, sourcefile, sourceline FROM pg_catalog.pg_settings ---- -name source min_val max_val sourcefile sourceline -application_name NULL NULL NULL NULL NULL -bytea_output NULL NULL NULL NULL NULL -client_encoding NULL NULL NULL NULL NULL -client_min_messages NULL NULL NULL NULL NULL -crdb_version NULL NULL NULL NULL NULL -database NULL NULL NULL NULL NULL -datestyle NULL NULL NULL NULL NULL -default_int_size NULL NULL NULL NULL NULL -default_tablespace NULL NULL NULL NULL NULL -default_transaction_isolation NULL NULL NULL NULL NULL -default_transaction_priority NULL NULL NULL NULL NULL -default_transaction_read_only NULL NULL NULL NULL NULL -default_transaction_use_follower_reads NULL NULL NULL NULL NULL -disable_partially_distributed_plans NULL NULL NULL NULL NULL -disallow_full_table_scans NULL NULL NULL NULL NULL -distsql NULL NULL NULL NULL NULL -enable_drop_enum_value NULL NULL NULL NULL NULL -enable_experimental_alter_column_type_general NULL NULL NULL NULL NULL -enable_experimental_stream_replication NULL NULL NULL NULL NULL -enable_implicit_select_for_update NULL NULL NULL NULL NULL -enable_insert_fast_path NULL NULL NULL NULL NULL -enable_seqscan NULL NULL NULL NULL NULL -enable_zigzag_join NULL NULL NULL NULL NULL -escape_string_warning NULL NULL NULL NULL NULL -experimental_distsql_planning NULL NULL NULL NULL NULL -experimental_enable_hash_sharded_indexes NULL NULL NULL NULL NULL -experimental_enable_implicit_column_partitioning NULL NULL NULL NULL NULL -experimental_enable_temp_tables NULL NULL NULL NULL NULL -experimental_enable_unique_without_index_constraints NULL NULL NULL NULL NULL -experimental_use_new_schema_changer NULL NULL NULL NULL NULL -extra_float_digits NULL NULL NULL NULL NULL -force_savepoint_restart NULL NULL NULL NULL NULL -foreign_key_cascades_limit NULL NULL NULL NULL NULL -idle_in_session_timeout NULL NULL NULL NULL NULL -idle_in_transaction_session_timeout NULL NULL NULL NULL NULL -integer_datetimes NULL NULL NULL NULL NULL -intervalstyle NULL NULL NULL NULL NULL -locality NULL NULL NULL NULL NULL -locality_optimized_partitioned_index_scan NULL NULL NULL NULL NULL -lock_timeout NULL NULL NULL NULL NULL -max_identifier_length NULL NULL NULL NULL NULL -max_index_keys NULL NULL NULL NULL NULL -node_id NULL NULL NULL NULL NULL -optimizer NULL NULL NULL NULL NULL -optimizer_improve_disjunction_selectivity NULL NULL NULL NULL NULL -optimizer_use_histograms NULL NULL NULL NULL NULL -optimizer_use_multicol_stats NULL NULL NULL NULL NULL -override_multi_region_zone_config NULL NULL NULL NULL NULL -prefer_lookup_joins_for_fks NULL NULL NULL NULL NULL -reorder_joins_limit NULL NULL NULL NULL NULL -require_explicit_primary_keys NULL NULL NULL NULL NULL -results_buffer_size NULL NULL NULL NULL NULL -row_security NULL NULL NULL NULL NULL -search_path NULL NULL NULL NULL NULL -serial_normalization NULL NULL NULL NULL NULL -server_encoding NULL NULL NULL NULL NULL -server_version NULL NULL NULL NULL NULL -server_version_num NULL NULL NULL NULL NULL -session_id NULL NULL NULL NULL NULL -session_user NULL NULL NULL NULL NULL -sql_safe_updates NULL NULL NULL NULL NULL -standard_conforming_strings NULL NULL NULL NULL NULL -statement_timeout NULL NULL NULL NULL NULL -stub_catalog_tables NULL NULL NULL NULL NULL -synchronize_seqscans NULL NULL NULL NULL NULL -synchronous_commit NULL NULL NULL NULL NULL -testing_vectorize_inject_panics NULL NULL NULL NULL NULL -timezone NULL NULL NULL NULL NULL -tracing NULL NULL NULL NULL NULL -transaction_isolation NULL NULL NULL NULL NULL -transaction_priority NULL NULL NULL NULL NULL -transaction_read_only NULL NULL NULL NULL NULL -transaction_status NULL NULL NULL NULL NULL -vectorize NULL NULL NULL NULL NULL -vectorize_row_count_threshold NULL NULL NULL NULL NULL +name source min_val max_val sourcefile sourceline +application_name NULL NULL NULL NULL NULL +bytea_output NULL NULL NULL NULL NULL +client_encoding NULL NULL NULL NULL NULL +client_min_messages NULL NULL NULL NULL NULL +crdb_version NULL NULL NULL NULL NULL +database NULL NULL NULL NULL NULL +datestyle NULL NULL NULL NULL NULL +default_int_size NULL NULL NULL NULL NULL +default_tablespace NULL NULL NULL NULL NULL +default_transaction_isolation NULL NULL NULL NULL NULL +default_transaction_priority NULL NULL NULL NULL NULL +default_transaction_read_only NULL NULL NULL NULL NULL +default_transaction_use_follower_reads NULL NULL NULL NULL NULL +disable_partially_distributed_plans NULL NULL NULL NULL NULL +disallow_full_table_scans NULL NULL NULL NULL NULL +distsql NULL NULL NULL NULL NULL +enable_copying_partitioning_when_deinterleaving_table NULL NULL NULL NULL NULL +enable_drop_enum_value NULL NULL NULL NULL NULL +enable_experimental_alter_column_type_general NULL NULL NULL NULL NULL +enable_experimental_stream_replication NULL NULL NULL NULL NULL +enable_implicit_select_for_update NULL NULL NULL NULL NULL +enable_insert_fast_path NULL NULL NULL NULL NULL +enable_seqscan NULL NULL NULL NULL NULL +enable_zigzag_join NULL NULL NULL NULL NULL +escape_string_warning NULL NULL NULL NULL NULL +experimental_distsql_planning NULL NULL NULL NULL NULL +experimental_enable_hash_sharded_indexes NULL NULL NULL NULL NULL +experimental_enable_implicit_column_partitioning NULL NULL NULL NULL NULL +experimental_enable_temp_tables NULL NULL NULL NULL NULL +experimental_enable_unique_without_index_constraints NULL NULL NULL NULL NULL +experimental_use_new_schema_changer NULL NULL NULL NULL NULL +extra_float_digits NULL NULL NULL NULL NULL +force_savepoint_restart NULL NULL NULL NULL NULL +foreign_key_cascades_limit NULL NULL NULL NULL NULL +idle_in_session_timeout NULL NULL NULL NULL NULL +idle_in_transaction_session_timeout NULL NULL NULL NULL NULL +integer_datetimes NULL NULL NULL NULL NULL +intervalstyle NULL NULL NULL NULL NULL +locality NULL NULL NULL NULL NULL +locality_optimized_partitioned_index_scan NULL NULL NULL NULL NULL +lock_timeout NULL NULL NULL NULL NULL +max_identifier_length NULL NULL NULL NULL NULL +max_index_keys NULL NULL NULL NULL NULL +node_id NULL NULL NULL NULL NULL +optimizer NULL NULL NULL NULL NULL +optimizer_improve_disjunction_selectivity NULL NULL NULL NULL NULL +optimizer_use_histograms NULL NULL NULL NULL NULL +optimizer_use_multicol_stats NULL NULL NULL NULL NULL +override_multi_region_zone_config NULL NULL NULL NULL NULL +prefer_lookup_joins_for_fks NULL NULL NULL NULL NULL +reorder_joins_limit NULL NULL NULL NULL NULL +require_explicit_primary_keys NULL NULL NULL NULL NULL +results_buffer_size NULL NULL NULL NULL NULL +row_security NULL NULL NULL NULL NULL +search_path NULL NULL NULL NULL NULL +serial_normalization NULL NULL NULL NULL NULL +server_encoding NULL NULL NULL NULL NULL +server_version NULL NULL NULL NULL NULL +server_version_num NULL NULL NULL NULL NULL +session_id NULL NULL NULL NULL NULL +session_user NULL NULL NULL NULL NULL +sql_safe_updates NULL NULL NULL NULL NULL +standard_conforming_strings NULL NULL NULL NULL NULL +statement_timeout NULL NULL NULL NULL NULL +stub_catalog_tables NULL NULL NULL NULL NULL +synchronize_seqscans NULL NULL NULL NULL NULL +synchronous_commit NULL NULL NULL NULL NULL +testing_vectorize_inject_panics NULL NULL NULL NULL NULL +timezone NULL NULL NULL NULL NULL +tracing NULL NULL NULL NULL NULL +transaction_isolation NULL NULL NULL NULL NULL +transaction_priority NULL NULL NULL NULL NULL +transaction_read_only NULL NULL NULL NULL NULL +transaction_status NULL NULL NULL NULL NULL +vectorize NULL NULL NULL NULL NULL +vectorize_row_count_threshold NULL NULL NULL NULL NULL # pg_catalog.pg_sequence diff --git a/pkg/sql/logictest/testdata/logic_test/show_source b/pkg/sql/logictest/testdata/logic_test/show_source index 2552aae06b2d..56ecc960184f 100644 --- a/pkg/sql/logictest/testdata/logic_test/show_source +++ b/pkg/sql/logictest/testdata/logic_test/show_source @@ -25,79 +25,80 @@ SELECT * FROM [SHOW ALL] WHERE variable != 'optimizer' AND variable != 'crdb_version' AND variable != 'session_id' ---- -variable value -application_name · -bytea_output hex -client_encoding UTF8 -client_min_messages notice -database test -datestyle ISO, MDY -default_int_size 8 -default_tablespace · -default_transaction_isolation serializable -default_transaction_priority normal -default_transaction_read_only off -default_transaction_use_follower_reads off -disable_partially_distributed_plans off -disallow_full_table_scans off -distsql off -enable_drop_enum_value off -enable_experimental_alter_column_type_general off -enable_experimental_stream_replication off -enable_implicit_select_for_update on -enable_insert_fast_path on -enable_seqscan on -enable_zigzag_join on -escape_string_warning on -experimental_distsql_planning off -experimental_enable_hash_sharded_indexes off -experimental_enable_implicit_column_partitioning off -experimental_enable_temp_tables off -experimental_enable_unique_without_index_constraints off -experimental_use_new_schema_changer off -extra_float_digits 0 -force_savepoint_restart off -foreign_key_cascades_limit 10000 -idle_in_session_timeout 0 -idle_in_transaction_session_timeout 0 -integer_datetimes on -intervalstyle postgres -locality region=test,dc=dc1 -locality_optimized_partitioned_index_scan on -lock_timeout 0 -max_identifier_length 128 -max_index_keys 32 -node_id 1 -optimizer_improve_disjunction_selectivity off -optimizer_use_histograms on -optimizer_use_multicol_stats on -override_multi_region_zone_config off -prefer_lookup_joins_for_fks off -reorder_joins_limit 8 -require_explicit_primary_keys off -results_buffer_size 16384 -row_security off -search_path $user,public -serial_normalization rowid -server_encoding UTF8 -server_version 13.0.0 -server_version_num 130000 -session_user root -sql_safe_updates off -standard_conforming_strings on -statement_timeout 0 -stub_catalog_tables on -synchronize_seqscans on -synchronous_commit on -testing_vectorize_inject_panics off -timezone UTC -tracing off -transaction_isolation serializable -transaction_priority normal -transaction_read_only off -transaction_status NoTxn -vectorize on -vectorize_row_count_threshold 0 +variable value +application_name · +bytea_output hex +client_encoding UTF8 +client_min_messages notice +database test +datestyle ISO, MDY +default_int_size 8 +default_tablespace · +default_transaction_isolation serializable +default_transaction_priority normal +default_transaction_read_only off +default_transaction_use_follower_reads off +disable_partially_distributed_plans off +disallow_full_table_scans off +distsql off +enable_copying_partitioning_when_deinterleaving_table off +enable_drop_enum_value off +enable_experimental_alter_column_type_general off +enable_experimental_stream_replication off +enable_implicit_select_for_update on +enable_insert_fast_path on +enable_seqscan on +enable_zigzag_join on +escape_string_warning on +experimental_distsql_planning off +experimental_enable_hash_sharded_indexes off +experimental_enable_implicit_column_partitioning off +experimental_enable_temp_tables off +experimental_enable_unique_without_index_constraints off +experimental_use_new_schema_changer off +extra_float_digits 0 +force_savepoint_restart off +foreign_key_cascades_limit 10000 +idle_in_session_timeout 0 +idle_in_transaction_session_timeout 0 +integer_datetimes on +intervalstyle postgres +locality region=test,dc=dc1 +locality_optimized_partitioned_index_scan on +lock_timeout 0 +max_identifier_length 128 +max_index_keys 32 +node_id 1 +optimizer_improve_disjunction_selectivity off +optimizer_use_histograms on +optimizer_use_multicol_stats on +override_multi_region_zone_config off +prefer_lookup_joins_for_fks off +reorder_joins_limit 8 +require_explicit_primary_keys off +results_buffer_size 16384 +row_security off +search_path $user,public +serial_normalization rowid +server_encoding UTF8 +server_version 13.0.0 +server_version_num 130000 +session_user root +sql_safe_updates off +standard_conforming_strings on +statement_timeout 0 +stub_catalog_tables on +synchronize_seqscans on +synchronous_commit on +testing_vectorize_inject_panics off +timezone UTC +tracing off +transaction_isolation serializable +transaction_priority normal +transaction_read_only off +transaction_status NoTxn +vectorize on +vectorize_row_count_threshold 0 query T colnames SELECT * FROM [SHOW CLUSTER SETTING sql.defaults.distsql] diff --git a/pkg/sql/sessiondata/session_data.go b/pkg/sql/sessiondata/session_data.go index c5a4fc14cd3e..dbf40ff228e1 100644 --- a/pkg/sql/sessiondata/session_data.go +++ b/pkg/sql/sessiondata/session_data.go @@ -263,6 +263,12 @@ type LocalOnlySessionData struct { // format. ExperimentalComputedColumnRewrites string + // CopyPartitioningWhenDeinterleavingTable indicates that when running an + // ALTER PRIMARY KEY that retains the same columns but removes any + // interleaving that zone configurations and partitioning from the root + // of that interleave should be applied to the new primary index. + CopyPartitioningWhenDeinterleavingTable bool + /////////////////////////////////////////////////////////////////////////// // WARNING: consider whether a session parameter you're adding needs to // // be propagated to the remote nodes. If so, that parameter should live // diff --git a/pkg/sql/vars.go b/pkg/sql/vars.go index f1ce67662836..7e653873e59a 100644 --- a/pkg/sql/vars.go +++ b/pkg/sql/vars.go @@ -1356,6 +1356,24 @@ var varGen = map[string]sessionVar{ return experimentalComputedColumnRewrites.Get(sv) }, }, + + `enable_copying_partitioning_when_deinterleaving_table`: { + GetStringVal: makePostgresBoolGetStringValFn(`enable_experimental_stream_replication`), + Set: func(_ context.Context, m *sessionDataMutator, s string) error { + b, err := paramparse.ParseBoolVar(`enable_experimental_stream_replication`, s) + if err != nil { + return err + } + m.SetCopyPartitioningWhenDeinterleavingTable(b) + return nil + }, + Get: func(evalCtx *extendedEvalContext) string { + return formatBoolAsPostgresSetting(evalCtx.SessionData.CopyPartitioningWhenDeinterleavingTable) + }, + GlobalDefault: func(sv *settings.Values) string { + return formatBoolAsPostgresSetting(copyPartitioningWhenDeinterleavingTable.Get(sv)) + }, + }, } const compatErrMsg = "this parameter is currently recognized only for compatibility and has no effect in CockroachDB."