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 #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 authored and JuanLeon1 committed Jul 1, 2021
1 parent 92e342b commit 1fd13c9
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions pkg/sql/opt/table_meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,21 @@ func (tm *TableMeta) copyScalars(copyScalar func(Expr) Expr) {
if tm.Constraints != nil {
tm.Constraints = copyScalar(tm.Constraints).(ScalarExpr)
}
for col, e := range tm.ComputedCols {
tm.ComputedCols[col] = copyScalar(e).(ScalarExpr)

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

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

Expand Down

0 comments on commit 1fd13c9

Please sign in to comment.