chesnokoff commented on code in PR #12723:
URL: https://github.com/apache/ignite/pull/12723#discussion_r2792442407


##########
modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2QueryInfo.java:
##########
@@ -258,19 +270,85 @@ public String planWithoutScanCount(String plan) {
      * @param startPattern Start pattern.
      * @param endMarker End marker.
      */
-    private void removePattern(StringBuilder sb, String startPattern, String 
endMarker) {
-        int start = sb.lastIndexOf(startPattern);
+    private void removeLineWithPattern(StringBuilder sb, String startPattern, 
String endMarker) {
+        int searchFrom = 0;
+        int start = sb.indexOf(startPattern, searchFrom);
 
         while (start != -1) {
+            while (start > 0 && sb.charAt(start) != '\n')
+                --start;
+
             int end = sb.indexOf(endMarker, start);
 
             if (end == -1)
                 break;
 
             sb.delete(start, end + endMarker.length());
 
-            start = sb.lastIndexOf(startPattern);
+            searchFrom = start;
+            start = sb.indexOf(startPattern, searchFrom);
+        }
+    }
+
+    /**
+     * Normalizes H2 auto-generated numeric aliases (e.g. "_1", "_4") in a 
plan to make plan history stable
+     * across repeated executions of the same logical query.
+     */
+    private String planWithoutSystemAliases(String plan) {
+        if (plan.indexOf('_') < 0)
+            return plan;
+
+        int n = plan.length();
+
+        Map<String, String> aliasMap = new HashMap<>();
+        StringBuilder out = new StringBuilder(n);
+
+        for (int l = 0; l < n; ) {
+            char c = plan.charAt(l);
+
+            if (c != '_') {
+                out.append(c);
+                ++l;
+                continue;
+            }
+
+            if (l > 0 && plan.charAt(l - 1) != ' ') {
+                out.append(c);
+                ++l;
+                continue;
+            }
+
+            int r = l + 1;
+
+            if (r >= n || !Character.isDigit(plan.charAt(r))) {
+                out.append(c);
+                ++l;
+                continue;
+            }

Review Comment:
   Checks that we do not have _customAlias



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

Reply via email to