github-actions[bot] commented on code in PR #64535:
URL: https://github.com/apache/doris/pull/64535#discussion_r3421085100


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/NestedColumnPruning.java:
##########
@@ -488,27 +581,149 @@ private static void stripCoveredOffsetSuffixPaths(
             return;
         }
 
-        List<List<String>> nonOffsetPaths = new ArrayList<>();
+        // Row 1: deeper data paths cover OFFSET (with map key 
supplementation).
+        List<List<String>> dataPaths = new ArrayList<>();
         for (Pair<ColumnAccessPathType, List<String>> p : 
coveringAccessPaths.get(slotId)) {
             List<String> path = p.second;
-            if (path.isEmpty()
-                    || 
!AccessPathInfo.ACCESS_STRING_OFFSET.equals(path.get(path.size() - 1))) {
-                nonOffsetPaths.add(path);
+            if (!path.isEmpty() && !isMetaPath(path)) {
+                dataPaths.add(path);
+            }
+        }
+        for (Pair<ColumnAccessPathType, List<String>> p : targetPaths) {
+            List<String> path = p.second;
+            if (!path.isEmpty() && !isMetaPath(path)) {
+                dataPaths.add(path);
+            }
+        }
+        stripCoveredOffsetByPaths(slot, targetAccessPaths, dataPaths);
+
+        // Rows 2+3: deeper OFFSET/NULL paths cover shallower OFFSET.
+        // Merge meta paths from covering + target so both inbound and 
intra-target
+        // coverage are checked.
+        List<List<String>> deeperMetaPaths = new ArrayList<>();
+        for (Pair<ColumnAccessPathType, List<String>> p : 
coveringAccessPaths.get(slotId)) {
+            if (!p.second.isEmpty() && isMetaPath(p.second)) {
+                deeperMetaPaths.add(p.second);
+            }
+        }
+        for (Pair<ColumnAccessPathType, List<String>> p : targetPaths) {
+            if (!p.second.isEmpty() && isMetaPath(p.second)) {
+                deeperMetaPaths.add(p.second);
+            }
+        }
+        stripCoveredMetaByPrefix(slotId, AccessPathInfo.ACCESS_OFFSET,
+                deeperMetaPaths, targetAccessPaths);
+    }
+
+    /**
+     * Level 2 — deeper paths cover shallower NULL paths:
+     * <ul>
+     *   <li>Deeper {@code Data}: any deeper non-meta path whose prefix 
strictly
+     *       contains the NULL path's prefix strips it.</li>
+     *   <li>Deeper {@code OFFSET} / {@code NULL}: delegates to
+     *       {@link #stripCoveredMetaByPrefix}.</li>
+     * </ul>
+     */
+    private static void stripShallowerNullPaths(
+            Slot slot, Multimap<Integer, Pair<ColumnAccessPathType, 
List<String>>> allAccessPaths) {
+        int slotId = slot.getExprId().asInt();
+        Collection<Pair<ColumnAccessPathType, List<String>>> slotPaths = 
allAccessPaths.get(slotId);
+        if (slotPaths.isEmpty()) {
+            return;
+        }
+
+        // Row 1: deeper data paths cover shallower NULL paths.
+        List<Pair<ColumnAccessPathType, List<String>>> toRemove = new 
ArrayList<>();
+        for (Pair<ColumnAccessPathType, List<String>> p : slotPaths) {
+            List<String> path = p.second;
+            if (path.isEmpty() || 
!AccessPathInfo.ACCESS_NULL.equals(path.get(path.size() - 1))) {
+                continue;
+            }
+            List<String> prefix = path.subList(0, path.size() - 1);
+            for (Pair<ColumnAccessPathType, List<String>> q : slotPaths) {
+                List<String> other = q.second;
+                if (other == path || other.isEmpty() || isMetaPath(other)) {
+                    continue;
+                }
+                // [a] strips [a, NULL]; [a, b, c] strips [a, b, NULL].
+                if (other.equals(prefix) || hasStrictPrefix(other, prefix)) {
+                    toRemove.add(p);
+                    break;
+                }
+            }
+        }
+        for (Pair<ColumnAccessPathType, List<String>> r : toRemove) {
+            allAccessPaths.remove(slotId, r);
+        }
+
+        // Rows 2+3: deeper OFFSET/NULL paths cover shallower NULL paths.
+        List<List<String>> metaPaths = new ArrayList<>();
+        for (Pair<ColumnAccessPathType, List<String>> p : slotPaths) {
+            if (!p.second.isEmpty() && isMetaPath(p.second)) {
+                metaPaths.add(p.second);
             }
         }
+        stripCoveredMetaByPrefix(slotId, AccessPathInfo.ACCESS_NULL,
+                metaPaths, allAccessPaths);
+    }
+
+    /**
+     * Level 2 — for each target path ending with {@code targetSuffix}, remove 
it
+     * when a strictly deeper meta path (ending with OFFSET or NULL) has the 
target
+     * prefix as a strict prefix.
+     *
+     * <p>Both target and covering paths have their meta suffix stripped before
+     * comparison, so only genuinely deeper paths match. Same-depth cross-type
+     * (e.g. {@code [a, OFFSET]} vs {@code [a, NULL]}) is handled by
+     * {@link #stripNullBySameDepthOffset} instead.
+     */
+    private static void stripCoveredMetaByPrefix(
+            int slotId, String targetSuffix,
+            List<List<String>> coveringMetaPaths,
+            Multimap<Integer, Pair<ColumnAccessPathType, List<String>>> 
targetAccessPaths) {
+        Collection<Pair<ColumnAccessPathType, List<String>>> targetPaths =
+                targetAccessPaths.get(slotId);
+        if (targetPaths.isEmpty() || coveringMetaPaths.isEmpty()) {
+            return;
+        }
+
+        List<Pair<ColumnAccessPathType, List<String>>> toRemove = new 
ArrayList<>();
         for (Pair<ColumnAccessPathType, List<String>> p : targetPaths) {
             List<String> path = p.second;
-            if (path.isEmpty()
-                    || 
!AccessPathInfo.ACCESS_STRING_OFFSET.equals(path.get(path.size() - 1))) {
-                nonOffsetPaths.add(path);
+            if (path.isEmpty() || !targetSuffix.equals(path.get(path.size() - 
1))) {
+                continue;
             }
+            List<String> targetPrefix = path.subList(0, path.size() - 1);
+            for (List<String> other : coveringMetaPaths) {
+                if (other == path || other.isEmpty()) {
+                    continue;
+                }
+                List<String> otherPrefix = other.subList(0, other.size() - 1);
+                if (hasStrictPrefix(otherPrefix, targetPrefix)) {
+                    toRemove.add(p);

Review Comment:
   This still leaves the same unsafe BE reader-mode combination after map value 
normalization, but in a different path shape from the earlier root-array thread.
   
   Reduced plan:
   
   ```text
   Project(cardinality(element_at(m, 'a')), is_null(element_at(element_at(m, 
'a'), 1)))
     OlapScan(m: MAP<STRING, ARRAY<INT>>)
   ```
   
   `AccessPathExpressionCollector` emits `[m, *, OFFSET]` for 
`cardinality(element_at(m,'a'))` and `[m, *, *, NULL]` for the element null 
check. `normalizeMapValueMetaOnlyAccessPaths` rewrites only the first path to 
`[m, KEYS]` + `[m, VALUES, OFFSET]`; the deeper null path remains `[m, *, *, 
NULL]`. At this line the comparison is a plain lexical prefix check, so `[m, *, 
*]` is not treated as a value-side child of `[m, VALUES]`, and `[m, VALUES, 
OFFSET]` survives.
   
   BE then splits `[m, *, *, NULL]` to the value array as `[value, *, NULL]` 
and also sends `[value, OFFSET]`. `ArrayFileColumnIterator::set_access_paths` 
sees the value-array `OFFSET`, switches that iterator to `OFFSET_ONLY`, and 
skips the item iterator, so the deeper `NULL` path is never applied. The `IS 
NULL` result can be evaluated from default-filled item/null columns.
   
   Please make the deeper-meta coverage map-aware here as well, e.g. reuse the 
`compareOffsetPrefixCoverage` semantics for `*` vs `VALUES` while preserving 
the supplemental `[m, KEYS]` path, or normalize deeper map-star meta paths to 
`VALUES` before this comparison. A unit/regression case with 
`cardinality(map_arr_col['a'])` plus `element_at(map_arr_col['a'], 1) is null` 
would catch this.



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