Skip to content

Commit

Permalink
Merge pull request #59272 from yuzefovich/backport20.1-59213
Browse files Browse the repository at this point in the history
release-20.1: sql: fix ALTER INDEX ... SPLIT/UNSPLIT AT in error cases
  • Loading branch information
yuzefovich authored Jan 25, 2021
2 parents 6f3fec0 + 0833e05 commit 8710560
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/ranges
Original file line number Diff line number Diff line change
Expand Up @@ -538,3 +538,15 @@ SHOW RANGES FROM TABLE crdb_internal.tables

query error \"crdb_internal.tables\" is a virtual table
SHOW RANGE FROM TABLE crdb_internal.tables FOR ROW (0, 0)

# Regression test for incorrectly handling an excessive number of values in
# SPLIT/UNSPLIT AT statements (#59011).
statement ok
CREATE TABLE t59011 (id UUID NOT NULL DEFAULT gen_random_uuid(), level INT8 NULL DEFAULT 0:::INT8, CONSTRAINT "primary" PRIMARY KEY (id ASC), INDEX i59011 (level ASC));
INSERT INTO t59011(level) SELECT 2 FROM generate_series(1, 10);

statement error excessive number of values provided: expected 1, got 2
ALTER INDEX i59011 SPLIT AT VALUES (2, '6cf22b39-a1eb-43ee-8edf-0da8543c5c38'::UUID);

statement error excessive number of values provided: expected 1, got 2
ALTER INDEX i59011 UNSPLIT AT VALUES (2, '6cf22b39-a1eb-43ee-8edf-0da8543c5c38'::UUID);
5 changes: 5 additions & 0 deletions pkg/sql/split.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"context"

"github.com/cockroachdb/cockroach/pkg/keys"
"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgcode"
"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror"
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
"github.com/cockroachdb/cockroach/pkg/sql/sqlbase"
"github.com/cockroachdb/cockroach/pkg/util/hlc"
Expand Down Expand Up @@ -85,6 +87,9 @@ func (n *splitNode) Close(ctx context.Context) {
func getRowKey(
tableDesc *sqlbase.TableDescriptor, index *sqlbase.IndexDescriptor, values []tree.Datum,
) ([]byte, error) {
if len(index.ColumnIDs) < len(values) {
return nil, pgerror.Newf(pgcode.Syntax, "excessive number of values provided: expected %d, got %d", len(index.ColumnIDs), len(values))
}
colMap := make(map[sqlbase.ColumnID]int)
for i := range values {
colMap[index.ColumnIDs[i]] = i
Expand Down

0 comments on commit 8710560

Please sign in to comment.