uros-b commented on code in PR #58362:
URL: https://github.com/apache/spark/pull/58362#discussion_r3890866686


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala:
##########
@@ -830,11 +830,13 @@ object LikeSimplification extends Rule[LogicalPlan] with 
PredicateHelper {
         case endsWith(postfix) =>
           Some(EndsWith(input, Literal.create(postfix, input.dataType)))
         // 'a%a' pattern is basically same with 'a%' && '%a'.
-        // However, the additional `Length` condition is required to prevent 
'a' match 'a%a'.
+        // However, the additional length condition is required to prevent 'a' 
match 'a%a'.
+        // Since StartsWith/EndsWith already pin the prefix and suffix at 
code-point boundaries,
+        // a byte-length guard (OctetLength, O(1)) is equivalent to a 
char-length guard and cheaper.
         case startsAndEndsWith(prefix, postfix) =>
-          Some(And(GreaterThanOrEqual(Length(input),
-            Literal.create(prefix.codePointCount(0, prefix.length)
-              + postfix.codePointCount(0, postfix.length))),
+          Some(And(GreaterThanOrEqual(OctetLength(input),

Review Comment:
   The main thing to be aware of here is that collation-aware anchors can match 
code points with different UTF-8 lengths.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to