Skip to content

Commit 7cb097a

Browse files
committed
sql/opt_catalog: Use index offset as tombstone index ordinal
Previously, when the optimizer stored the ordinal of an index to use for writing tombstones in non-SERIALIZABLE transactions, it would call the Ordinal() method, which returns the value from the table's descriptor. We would later use this value as an input to the Index() method to retrieve the index in question. However, Ordinal() can differ from the catalog's view of the schema during schema change, resulting in sometimes getting the wrong index ordinal from the optimizer's point of view, sometimes resulting in an out of bounds error. This patch switches the ordinal we save to be the actual index used when creating the optTable, which feels janky, but is at least correct. Fixes: #151477 Release note (bug fix): A bug which could occasionally cause DML on regional by row tables with unique indexes that don't reference the region to fail under READ-COMMITTED isolation has been corrected.
1 parent 9c2c6af commit 7cb097a

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

pkg/sql/opt_catalog.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,12 +1157,13 @@ func newOptTable(
11571157
canUseTombstones := idx.ImplicitPartitioningColumnCount() == 1 &&
11581158
partitionColumn.GetType().Family() == types.EnumFamily
11591159
ot.uniqueConstraints = append(ot.uniqueConstraints, optUniqueConstraint{
1160-
name: idx.GetName(),
1161-
table: ot.ID(),
1162-
columns: idx.IndexDesc().KeyColumnIDs[idx.IndexDesc().ExplicitColumnStartIdx():],
1163-
withoutIndex: true,
1164-
canUseTombstones: canUseTombstones,
1165-
tombstoneIndexOrdinal: idx.Ordinal(),
1160+
name: idx.GetName(),
1161+
table: ot.ID(),
1162+
columns: idx.IndexDesc().KeyColumnIDs[idx.IndexDesc().ExplicitColumnStartIdx():],
1163+
withoutIndex: true,
1164+
canUseTombstones: canUseTombstones,
1165+
// One would assume that this would be idx.Ordinal(), but they can differ during schema change
1166+
tombstoneIndexOrdinal: i,
11661167
predicate: idx.GetPredicate(),
11671168
// TODO(rytaft): will we ever support an unvalidated unique constraint
11681169
// here?

0 commit comments

Comments
 (0)