github-actions[bot] commented on code in PR #62631:
URL: https://github.com/apache/doris/pull/62631#discussion_r3109409938
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/NestedColumnPruning.java:
##########
@@ -265,26 +266,45 @@ 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.
if (slot.getDataType().isArrayType() ||
slot.getDataType().isMapType()) {
int slotId = slot.getExprId().asInt();
- boolean hasNonOffsetPath =
allAccessPaths.get(slotId).stream().anyMatch(p -> {
+ Collection<Pair<ColumnAccessPathType, List<String>>> paths =
allAccessPaths.get(slotId);
+ List<List<String>> nonOffsetPaths = new ArrayList<>();
+ for (Pair<ColumnAccessPathType, List<String>> p : paths) {
List<String> path = p.second;
- return path.isEmpty()
- ||
!AccessPathInfo.ACCESS_STRING_OFFSET.equals(path.get(path.size() - 1));
- });
- if (hasNonOffsetPath) {
- allAccessPaths.get(slotId).removeIf(p -> {
- List<String> path = p.second;
- return !path.isEmpty()
- && AccessPathInfo.ACCESS_STRING_OFFSET.equals(
- path.get(path.size() - 1));
- });
+ if (path.isEmpty()
+ ||
!AccessPathInfo.ACCESS_STRING_OFFSET.equals(path.get(path.size() - 1))) {
+ nonOffsetPaths.add(path);
+ }
}
+ paths.removeIf(p -> {
+ List<String> path = p.second;
+ if (path.isEmpty()
+ ||
!AccessPathInfo.ACCESS_STRING_OFFSET.equals(path.get(path.size() - 1))) {
+ return false;
+ }
+ List<String> prefix = path.subList(0, path.size() - 1);
+ for (List<String> nonOffset : nonOffsetPaths) {
+ if (nonOffset.isEmpty()) {
+ return true;
+ }
+ int minLen = Math.min(nonOffset.size(), prefix.size());
+ if (minLen == 0
+ || nonOffset.subList(0,
minLen).equals(prefix.subList(0, minLen))) {
Review Comment:
This raw-prefix comparison misses overlapping map-value accesses that are
spelled with different path tokens. `length(map_col['a'])` is collected as
`[map_col, *, OFFSET]`, but `map_values(map_col)[1]` becomes `[map_col,
VALUES]`. Those two paths still target the same value container, yet `*` and
`VALUES` are not prefix-equal here, so the OFFSET path survives.
That leaves both `val_col.OFFSET` and `val_col` on the BE side.
`MapFileColumnIterator::set_access_paths()` forwards both to the value
iterator, and `StringFileColumnIterator::set_access_paths()` switches to
`OFFSET_ONLY` as soon as it sees the first one, so the full-value consumer
reads zero-filled strings instead of the real payload.
A query like `select length(map_col['a']), map_values(map_col)[1] from ...`
should still suppress the OFFSET path. The dedup needs to normalize the map
aliases (`*` vs `VALUES`/`KEYS`) or compare semantic container coverage instead
of raw string prefixes.
--
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]