Skip to content

Commit cdf2449

Browse files
committed
opt: refactor NormalizeLikeAny
The NormalizeLikeAny rule no longer allocates, memoizes, and interns a constant string expression for the literal "%" value. Release note: None
1 parent ac3b2b7 commit cdf2449

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

pkg/sql/opt/norm/general_funcs.go

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,11 +1545,6 @@ func (c *CustomFuncs) IntConst(d *tree.DInt) opt.ScalarExpr {
15451545
return c.f.ConstructConst(d, types.Int)
15461546
}
15471547

1548-
// StrConst constructs a Const holding a DString.
1549-
func (c *CustomFuncs) StrConst(d *tree.DString) opt.ScalarExpr {
1550-
return c.f.ConstructConst(d, types.String)
1551-
}
1552-
15531548
// StringFromConst extracts a string from a Const expression. It returns the
15541549
// string and a boolean indicating whether the extraction was successful.
15551550
func (c *CustomFuncs) StringFromConst(expr opt.ScalarExpr) (string, bool) {
@@ -1565,14 +1560,13 @@ func (c *CustomFuncs) StringFromConst(expr opt.ScalarExpr) (string, bool) {
15651560
return "", false
15661561
}
15671562

1568-
// EqualConstString compares two Const expressions to see if they hold equal string values.
1569-
func (c *CustomFuncs) EqualConstStrings(left, right opt.ScalarExpr) bool {
1570-
leftStr, okLeft := c.StringFromConst(left)
1571-
rightStr, okRight := c.StringFromConst(right)
1572-
if !okLeft || !okRight {
1573-
return false
1563+
// ConstStringEquals returns true if e is a constant string expression and is
1564+
// equal to other.
1565+
func (c *CustomFuncs) ConstStringEquals(e opt.ScalarExpr, other *tree.DString) bool {
1566+
if eStr, ok := c.StringFromConst(e); ok {
1567+
return eStr == string(*other)
15741568
}
1575-
return leftStr == rightStr
1569+
return false
15761570
}
15771571

15781572
// IsGreaterThan returns true if the first datum compares as greater than the

pkg/sql/opt/norm/rules/select.opt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ $input
534534
$left:* &
535535
(ExprIsNeverNull $left (NotNullCols $input))
536536
$pattern:(Const) &
537-
(EqualConstStrings $pattern (StrConst "%"))
537+
(ConstStringEquals $pattern "%")
538538
)
539539
)
540540
...

0 commit comments

Comments
 (0)