Doris-Breakwater commented on issue #68716:
URL: https://github.com/apache/doris/issues/68716#issuecomment-5978347546

   Breakwater-GitHub-Analysis-Slot: slot_f4f9c6c44605
   
   **Triage:** This is a reproducible FE constant-folding / BE execution result 
mismatch for the reported 4.1.4 build. The issue supplies a minimal SQL 
reproduction and version; no logs or profile are needed to establish this 
particular mismatch. I reviewed the source at the reported `ad35a140c7f` commit 
(also unchanged in the relevant files from `4.1.4-rc04`); I have not run a 
Doris cluster independently.
   
   **Verified mechanism:** The FE executable 
[`substringIndex`](https://github.com/apache/doris/blob/ad35a140c7f/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/StringArithmetic.java#L799-L828)
 uses Java `split(Pattern.quote(delim), -1)` from the left and then takes the 
last part for `count = -1`. Splitting `aaa` on `aa` yields `['', 'a']`, so 
folding produces `a`. The BE 
[`FunctionSubstringIndex`](https://github.com/apache/doris/blob/ad35a140c7f/be/src/exprs/function/function_string_search.cpp#L505-L546)
 uses `rfind` for a negative count: the rightmost `aa` in `aaa` starts at 
offset 1, and the suffix after that two-character delimiter is empty. The 
issue's `EXPLAIN` and `debug_skip_fold_constant` observations are consistent 
with these paths. This makes query results depend on whether the planner folds 
the expression.
   
   **Expected result:** [Doris 
documentation](https://doris.apache.org/docs/3.x/sql-manual/sql-functions/scalar-functions/string-functions/substring-index/)
 says a negative count selects content after the delimiter counted from the 
right. On that reading, the BE's empty string is the intended result for this 
input, and the FE fold is the divergent path. The documentation does not 
explicitly define how overlapping delimiter occurrences are counted, so please 
confirm the intended compatibility behavior for overlapping matches before 
choosing the implementation change.
   
   **Suggested next steps:** Add a regression that compares the literal-folded 
and column-executed results for `('aaa', 'aa', -1)`, plus overlapping 
multi-character delimiters and counts `-2` and `+1`; retain non-overlapping 
cases as controls. Once the overlap rule is confirmed, make FE folding and BE 
execution follow the same rule and check both plans. `debug_skip_fold_constant 
= true` is a useful session-level diagnostic or temporary workaround for 
affected expressions, with the usual cost of disabling folding.
   


-- 
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