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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/NestedColumnPruning.java:
##########
@@ -265,26 +266,41 @@ private static Map<Integer, AccessPathInfo> pruneDataType(
             }
 
             // For array/map columns that are NOT in offset-only mode, strip 
OFFSET-suffix paths
-            // when a non-OFFSET path also exists for the same slot. This 
handles cases like
-            // `select cardinality(arr), arr[1]` where the OFFSET path from 
cardinality() is
-            // redundant because full element data is also needed.
-            // If the ONLY paths for a slot end in OFFSET (e.g. 
cardinality(arr[0].field) alone),
-            // keep them — they carry meaningful nested-access semantics.
+            // when a non-OFFSET path covers the same nested field or 
container. An OFFSET path
+            // P+["OFFSET"] with prefix P is redundant if a non-OFFSET path Q 
exists where P and Q
+            // share a prefix relationship (either direction):
+            //   - Q is prefix-or-equal of P: ancestor access covers P (e.g. 
["arr","*"] covers
+            //     ["arr","*","f1","OFFSET"])
+            //   - P is prefix-or-equal of Q: same container is accessed at 
deeper level (e.g.
+            //     ["arr","*"] covers ["arr","OFFSET"] because reading 
elements implies offsets)
+            // Different struct fields (e.g. arr[*].f1 vs arr[*].f2) do NOT 
share a prefix, so
+            // their OFFSET paths are independent and must NOT be stripped.

Review Comment:
   This still leaves the same FE/BE mismatch when the array or map lives under 
a `STRUCT` root slot. The dedup/rewrite block only runs when 
`slot.getDataType()` itself is `ARRAY`/`MAP`, so a query like:
   
   ```sql
   SELECT cardinality(struct_element(s, 'arr')),
          struct_element(element_at(struct_element(s, 'arr'), 1), 'int_field')
   FROM t
   ```
   
   with `s STRUCT<arr: ARRAY<STRUCT<str_field: STRING, int_field: INT>>>` will 
still emit both `[s, arr, OFFSET]` and `[s, arr, *, int_field]`. 
`StructFileColumnIterator` forwards those child paths to the array reader, and 
`ArrayFileColumnIterator::set_access_paths()` treats the leading `OFFSET` as 
`OFFSET_ONLY`, so it skips item reads even though `[* , int_field]` still needs 
them. That reproduces the same wrong-result/crash class this PR is fixing for 
top-level array/map slots.
   
   Can we move this overlap check to the actual nested container prefix instead 
of gating it on the root slot type?



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