@@ -93,12 +93,12 @@ func (b *logicalPropsBuilder) buildScanProps(scan *ScanExpr, rel *props.Relation
93
93
rel .NotNullCols = makeTableNotNullCols (md , scan .Table ).Copy ()
94
94
// Union not-NULL columns with not-NULL columns in the constraint.
95
95
if scan .Constraint != nil {
96
- rel . NotNullCols . UnionWith ( scan .Constraint .ExtractNotNullCols (b .sb .ctx , b .evalCtx ) )
96
+ scan .Constraint .ExtractNotNullCols (b .sb .ctx , b .evalCtx , & rel . NotNullCols )
97
97
}
98
98
// Union not-NULL columns with not-NULL columns in the partial index
99
99
// predicate.
100
100
if pred != nil {
101
- rel . NotNullCols . UnionWith ( b . rejectNullCols (pred ) )
101
+ b . extractNotNullCols (pred , & rel . NotNullCols )
102
102
}
103
103
rel .NotNullCols .IntersectionWith (rel .OutputCols )
104
104
@@ -267,7 +267,8 @@ func (b *logicalPropsBuilder) buildSelectProps(sel *SelectExpr, rel *props.Relat
267
267
// SELECT y FROM xy WHERE y=5
268
268
//
269
269
// "y" cannot be null because the SQL equality operator rejects nulls.
270
- rel .NotNullCols = b .rejectNullCols (sel .Filters )
270
+ rel .NotNullCols = opt.ColSet {}
271
+ b .extractNotNullCols (sel .Filters , & rel .NotNullCols )
271
272
rel .NotNullCols .UnionWith (inputProps .NotNullCols )
272
273
rel .NotNullCols .IntersectionWith (rel .OutputCols )
273
274
@@ -2215,26 +2216,24 @@ func (b *logicalPropsBuilder) makeSetCardinality(
2215
2216
return card
2216
2217
}
2217
2218
2218
- // NullColsRejectedByFilter returns a set of columns that are "null rejected"
2219
- // by the filters. An input row with a NULL value on any of these columns will
2220
- // not pass the filter.
2221
- func NullColsRejectedByFilter (
2222
- ctx context.Context , evalCtx * eval.Context , filters FiltersExpr ,
2223
- ) opt.ColSet {
2224
- var notNullCols opt.ColSet
2219
+ // ExtractNullColsRejectedByFilter finds the set of columns that are "null
2220
+ // rejected" by the filters and adds them to the given column set. An input row
2221
+ // with a NULL value on any of these columns will not pass the filter.
2222
+ func ExtractNullColsRejectedByFilter (
2223
+ ctx context.Context , evalCtx * eval.Context , filters FiltersExpr , cols * opt.ColSet ,
2224
+ ) {
2225
2225
for i := range filters {
2226
2226
filterProps := filters [i ].ScalarProps ()
2227
2227
if filterProps .Constraints != nil {
2228
- notNullCols . UnionWith ( filterProps .Constraints .ExtractNotNullCols (ctx , evalCtx ) )
2228
+ filterProps .Constraints .ExtractNotNullCols (ctx , evalCtx , cols )
2229
2229
}
2230
2230
}
2231
- return notNullCols
2232
2231
}
2233
2232
2234
- // rejectNullCols returns the set of all columns that are inferred to be not-
2235
- // null, based on the filter conditions .
2236
- func (b * logicalPropsBuilder ) rejectNullCols (filters FiltersExpr ) opt.ColSet {
2237
- return NullColsRejectedByFilter (b .sb .ctx , b .evalCtx , filters )
2233
+ // extractNotNullCols finds the set of columns that are "null rejected" by the
2234
+ // filters and adds them to the given column set .
2235
+ func (b * logicalPropsBuilder ) extractNotNullCols (filters FiltersExpr , cols * opt.ColSet ) {
2236
+ ExtractNullColsRejectedByFilter (b .sb .ctx , b .evalCtx , filters , cols )
2238
2237
}
2239
2238
2240
2239
// addFiltersToFuncDep returns the union of all functional dependencies from
@@ -2548,7 +2547,7 @@ func (h *joinPropsHelper) init(b *logicalPropsBuilder, joinExpr RelExpr) {
2548
2547
h .rightProps = & join .lookupProps
2549
2548
h .filters = append (join .On , join .AllLookupFilters ... )
2550
2549
b .addFiltersToFuncDep (h .filters , & h .filtersFD )
2551
- h . filterNotNullCols = b . rejectNullCols (h .filters )
2550
+ b . extractNotNullCols (h .filters , & h . filterNotNullCols )
2552
2551
2553
2552
// Apply the lookup join equalities.
2554
2553
index := md .Table (join .Table ).Index (join .Index )
@@ -2574,7 +2573,7 @@ func (h *joinPropsHelper) init(b *logicalPropsBuilder, joinExpr RelExpr) {
2574
2573
h .rightProps = & join .lookupProps
2575
2574
h .filters = join .On
2576
2575
b .addFiltersToFuncDep (h .filters , & h .filtersFD )
2577
- h . filterNotNullCols = b . rejectNullCols (h .filters )
2576
+ b . extractNotNullCols (h .filters , & h . filterNotNullCols )
2578
2577
2579
2578
// Apply the prefix column equalities.
2580
2579
index := md .Table (join .Table ).Index (join .Index )
@@ -2599,7 +2598,7 @@ func (h *joinPropsHelper) init(b *logicalPropsBuilder, joinExpr RelExpr) {
2599
2598
h .rightProps = join .Right .Relational ()
2600
2599
h .filters = join .On
2601
2600
b .addFiltersToFuncDep (h .filters , & h .filtersFD )
2602
- h . filterNotNullCols = b . rejectNullCols (h .filters )
2601
+ b . extractNotNullCols (h .filters , & h . filterNotNullCols )
2603
2602
2604
2603
// Apply the merge join equalities.
2605
2604
for i := range join .LeftEq {
@@ -2621,7 +2620,7 @@ func (h *joinPropsHelper) init(b *logicalPropsBuilder, joinExpr RelExpr) {
2621
2620
h .rightProps = & join .rightProps
2622
2621
h .filters = join .On
2623
2622
b .addFiltersToFuncDep (h .filters , & h .filtersFD )
2624
- h . filterNotNullCols = b . rejectNullCols (h .filters )
2623
+ b . extractNotNullCols (h .filters , & h . filterNotNullCols )
2625
2624
2626
2625
// Apply the zigzag join equalities.
2627
2626
for i := range join .LeftEqCols {
@@ -2640,7 +2639,7 @@ func (h *joinPropsHelper) init(b *logicalPropsBuilder, joinExpr RelExpr) {
2640
2639
2641
2640
h .filters = * join .Child (2 ).(* FiltersExpr )
2642
2641
b .addFiltersToFuncDep (h .filters , & h .filtersFD )
2643
- h . filterNotNullCols = b . rejectNullCols (h .filters )
2642
+ b . extractNotNullCols (h .filters , & h . filterNotNullCols )
2644
2643
h .filterIsTrue = h .filters .IsTrue ()
2645
2644
h .filterIsFalse = h .filters .IsFalse ()
2646
2645
}
0 commit comments