From acdf519c059317b44142711f801fe994b37b8c4f Mon Sep 17 00:00:00 2001 From: Oliver Tan Date: Mon, 1 Feb 2021 07:16:44 +1100 Subject: [PATCH] sql: omit NOTICE about indexes not being partitioned for PARTITION ALL BY We previously would print a notice specifying that non-partitioned indexes on partitioned tables may not be performant - however, this notice does not apply for PARTITION ALL BY tables as all of their indexes will be automatically partitioned. Release note: None --- .../logictestccl/testdata/logic_test/partitioning_implicit | 6 ++++-- pkg/sql/create_index.go | 6 +++++- pkg/sql/create_table.go | 4 +++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/pkg/ccl/logictestccl/testdata/logic_test/partitioning_implicit b/pkg/ccl/logictestccl/testdata/logic_test/partitioning_implicit index e2588e7ce727..70c5a5685fd3 100644 --- a/pkg/ccl/logictestccl/testdata/logic_test/partitioning_implicit +++ b/pkg/ccl/logictestccl/testdata/logic_test/partitioning_implicit @@ -216,7 +216,7 @@ CREATE TABLE public.t ( PARTITION two VALUES IN (2) ) -statement ok +query T noticetrace CREATE TABLE public.t ( pk int PRIMARY KEY, pk2 int NOT NULL, @@ -233,14 +233,16 @@ CREATE TABLE public.t ( PARTITION one VALUES IN (1), PARTITION two VALUES IN (2) ) +---- statement error cannot define PARTITION BY on an index if the table has a PARTITION ALL BY definition CREATE INDEX created_idx ON t(c) PARTITION BY LIST (d) ( PARTITION one VALUES IN ((1)) ) -statement ok +query T noticetrace CREATE INDEX created_idx ON t(c) +---- statement ok ALTER TABLE t ADD CONSTRAINT unique_c_d UNIQUE(c, d) diff --git a/pkg/sql/create_index.go b/pkg/sql/create_index.go index 327404467217..69092e16700b 100644 --- a/pkg/sql/create_index.go +++ b/pkg/sql/create_index.go @@ -417,7 +417,11 @@ func (n *createIndexNode) startExec(params runParams) error { // Warn against creating a non-partitioned index on a partitioned table, // which is undesirable in most cases. - if n.n.PartitionByIndex == nil && n.tableDesc.GetPrimaryIndex().GetPartitioning().NumColumns > 0 { + // Avoid the warning if we have PARTITION ALL BY as all indexes will implicitly + // have relevant partitioning columns prepended at the front. + if n.n.PartitionByIndex == nil && + n.tableDesc.GetPrimaryIndex().GetPartitioning().NumColumns > 0 && + !n.tableDesc.IsPartitionAllBy() { params.p.BufferClientNotice( params.ctx, errors.WithHint( diff --git a/pkg/sql/create_table.go b/pkg/sql/create_table.go index 1ca8bcbfeff4..8c834399984f 100644 --- a/pkg/sql/create_table.go +++ b/pkg/sql/create_table.go @@ -248,10 +248,12 @@ func (n *createTableNode) startExec(params runParams) error { // Warn against creating non-partitioned indexes on a partitioned table, // which is undesirable in most cases. + // Avoid the warning if we have PARTITION ALL BY as all indexes will implicitly + // have relevant partitioning columns prepended at the front. if n.n.PartitionByTable.ContainsPartitions() { for _, def := range n.n.Defs { if d, ok := def.(*tree.IndexTableDef); ok { - if d.PartitionByIndex == nil { + if d.PartitionByIndex == nil && !n.n.PartitionByTable.All { params.p.BufferClientNotice( params.ctx, errors.WithHint(