Skip to content

Commit

Permalink
Merge pull request #42461 from rohany/backport19.2-42456
Browse files Browse the repository at this point in the history
release-19.2: builtins: fix potential panic in crdb_internal.encode_key
  • Loading branch information
rohany authored Nov 13, 2019
2 parents 1c95d3d + edd1cd4 commit c2b2cd1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
18 changes: 18 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/ranges
Original file line number Diff line number Diff line change
Expand Up @@ -498,3 +498,21 @@ query TT
SELECT start_key, end_key from [SHOW RANGE FROM INDEX range_for_row_nulls@i FOR ROW (1, NULL)]
----
/NULL NULL

# Regression for #42456
statement ok
CREATE TABLE t42456 (x int primary key);

statement ok
CREATE INDEX i1 on t42456 (x);
CREATE INDEX i2 on t42456 (x);
DROP INDEX t42456@i1;
DROP INDEX t42456@i2;
CREATE INDEX i3 on t42456 (x)

query T
SELECT crdb_internal.pretty_key(crdb_internal.encode_key(70, 4, (1, )), 0)
----
/70/4/1/0


5 changes: 4 additions & 1 deletion pkg/sql/sem/builtins/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -2994,7 +2994,10 @@ may increase either contention or retry errors, or both.`,
datums = append(datums, newDatum)
}

indexDesc := tableDesc.AllNonDropIndexes()[indexID-1]
indexDesc, err := tableDesc.FindIndexByID(sqlbase.IndexID(indexID))
if err != nil {
return nil, err
}

// Create a column id to row index map. In this case, each column ID just maps to the i'th ordinal.
colMap := make(map[sqlbase.ColumnID]int)
Expand Down

0 comments on commit c2b2cd1

Please sign in to comment.