@@ -16,6 +16,7 @@ import (
16
16
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree/treecmp"
17
17
"github.com/cockroachdb/cockroach/pkg/sql/sem/volatility"
18
18
"github.com/cockroachdb/cockroach/pkg/sql/types"
19
+ "github.com/cockroachdb/cockroach/pkg/util/buildutil"
19
20
"github.com/cockroachdb/cockroach/pkg/util/collatedstring"
20
21
"github.com/cockroachdb/cockroach/pkg/util/duration"
21
22
"github.com/cockroachdb/cockroach/pkg/util/errorutil/unimplemented"
@@ -78,6 +79,13 @@ type SemaContext struct {
78
79
// UsePre_25_2VariadicBuiltins is set to true when we should use the pre-25.2
79
80
// variadic builtins behavior.
80
81
UsePre_25_2VariadicBuiltins bool
82
+
83
+ // TestingKnobs only has effect under buildutil.CrdbTestBuild.
84
+ TestingKnobs struct {
85
+ // DisallowAlwaysNullShortCut, if set, disables short-circuiting logic
86
+ // for "always NULL" case during type checking.
87
+ DisallowAlwaysNullShortCut bool
88
+ }
81
89
}
82
90
83
91
// SemaProperties is a holder for required and derived properties
@@ -2370,9 +2378,12 @@ func typeCheckComparisonOpWithSubOperator(
2370
2378
rightTyped = array
2371
2379
cmpTypeRight = retType
2372
2380
2373
- // Return early without looking up a CmpOp if the comparison type is types.Null.
2374
- if leftTyped .ResolvedType ().Family () == types .UnknownFamily || retType .Family () == types .UnknownFamily {
2375
- return leftTyped , rightTyped , nil , true /* alwaysNull */ , nil
2381
+ // Return early without looking up a CmpOp if the comparison type is types.Null
2382
+ // (unless the short-cut is disabled in tests).
2383
+ if ! buildutil .CrdbTestBuild || semaCtx == nil || ! semaCtx .TestingKnobs .DisallowAlwaysNullShortCut {
2384
+ if leftTyped .ResolvedType ().Family () == types .UnknownFamily || retType .Family () == types .UnknownFamily {
2385
+ return leftTyped , rightTyped , nil , true /* alwaysNull */ , nil
2386
+ }
2376
2387
}
2377
2388
} else {
2378
2389
// If the right expression is not an array constructor, we type the left
@@ -2403,8 +2414,10 @@ func typeCheckComparisonOpWithSubOperator(
2403
2414
}
2404
2415
2405
2416
rightReturn := rightTyped .ResolvedType ()
2406
- if rightReturn .Family () == types .UnknownFamily {
2407
- return leftTyped , rightTyped , nil , true /* alwaysNull */ , nil
2417
+ if ! buildutil .CrdbTestBuild || semaCtx == nil || ! semaCtx .TestingKnobs .DisallowAlwaysNullShortCut {
2418
+ if rightReturn .Family () == types .UnknownFamily {
2419
+ return leftTyped , rightTyped , nil , true /* alwaysNull */ , nil
2420
+ }
2408
2421
}
2409
2422
2410
2423
switch rightReturn .Family () {
@@ -2739,8 +2752,10 @@ func typeCheckComparisonOp(
2739
2752
break
2740
2753
}
2741
2754
}
2742
- if noneAcceptNull {
2743
- return leftExpr , rightExpr , nil , true /* alwaysNull */ , nil
2755
+ if ! buildutil .CrdbTestBuild || semaCtx == nil || ! semaCtx .TestingKnobs .DisallowAlwaysNullShortCut {
2756
+ if noneAcceptNull {
2757
+ return leftExpr , rightExpr , nil , true /* alwaysNull */ , nil
2758
+ }
2744
2759
}
2745
2760
}
2746
2761
}
0 commit comments