Skip to content

Commit

Permalink
opt: fix panic due to concurrent map writes when copying metadata
Browse files Browse the repository at this point in the history
This commit fixes a bug that caused a panic due to concurrent map writes
when copying table metadata. The fix is to make a deep copy of the map
before updating it.

Fixes cockroachdb#66717

Release note (bug fix): Fixed a panic that could occur in the optimizer
when executing a prepared plan with placeholders. This could happen when
one of the tables used by the query had computed columns or a partial
index.
  • Loading branch information
rytaft committed Jun 23, 2021
1 parent d0cdd73 commit 94fbb9d
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pkg/sql/opt/table_meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,18 @@ func (tm *TableMeta) copyScalars(copyScalar func(Expr) Expr) {
if tm.Constraints != nil {
tm.Constraints = copyScalar(tm.Constraints).(ScalarExpr)
}

computedCols := make(map[ColumnID]ScalarExpr, len(tm.ComputedCols))
for col, e := range tm.ComputedCols {
tm.ComputedCols[col] = copyScalar(e).(ScalarExpr)
computedCols[col] = copyScalar(e).(ScalarExpr)
}
tm.ComputedCols = computedCols

partialIndexPredicates := make(map[cat.IndexOrdinal]ScalarExpr, len(tm.partialIndexPredicates))
for idx, e := range tm.partialIndexPredicates {
tm.partialIndexPredicates[idx] = copyScalar(e).(ScalarExpr)
partialIndexPredicates[idx] = copyScalar(e).(ScalarExpr)
}
tm.partialIndexPredicates = partialIndexPredicates
}

// IndexColumns returns the set of table columns in the given index.
Expand Down

0 comments on commit 94fbb9d

Please sign in to comment.