Skip to content

Commit

Permalink
opt: fix data race when building filters item props
Browse files Browse the repository at this point in the history
This commit fixes a race condition where two threads could be
simultaneously trying to build the logical properties of a filters
item and stepping on each others toes. In particular, one thread
could set scalar.Constraints to nil, causing a panic when another
thread tries to check whether scalar.Constraints.IsUnconstrained().
This commit fixes the issue by using a local variable to check whether
the constraint set is unconstrained.

Fixes #37951
Informs #37073
Informs #36148

Release note (bug fix): Fixed a race condition that could cause a
panic during query planning.
  • Loading branch information
rytaft committed Jun 2, 2019
1 parent 4aa32dc commit d3d9c2d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pkg/sql/opt/memo/logical_props_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1128,9 +1128,13 @@ func (b *logicalPropsBuilder) buildFiltersItemProps(item *FiltersItem, scalar *p
// Constraints
// -----------
cb := constraintsBuilder{md: b.mem.Metadata(), evalCtx: b.evalCtx}
scalar.Constraints, scalar.TightConstraints = cb.buildConstraints(item.Condition)
if scalar.Constraints.IsUnconstrained() {
// TODO(rytaft): Using local variables here to avoid a data race. It would be
// better to avoid lazy building of props altogether.
constraints, tightConstraints := cb.buildConstraints(item.Condition)
if constraints.IsUnconstrained() {
scalar.Constraints, scalar.TightConstraints = nil, false
} else {
scalar.Constraints, scalar.TightConstraints = constraints, tightConstraints
}

// Functional Dependencies
Expand Down

0 comments on commit d3d9c2d

Please sign in to comment.