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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/AccessPathExpressionCollector.java:
##########
@@ -618,6 +618,30 @@ private Void collectArrayPathInLambda(Lambda lambda, 
CollectorContext context) {
         } finally {
             nameToLambdaArguments.pop();
         }
+
+        // After visiting the lambda body, for any bound array whose lambda 
variable
+        // was NOT referenced in the body (e.g. x -> true where x never 
appears),
+        // visitArrayItemSlot was never called and the array column's access 
path is
+        // missing. This gap is exposed when an is-null or offset-only path 
has been
+        // registered for the same slot — NestedColumnPruning then incorrectly 
prunes
+        // the complex column to null-only / offset-only instead of reading 
full data.
+        //
+        // Must use a fresh context: when the body DOES reference some 
variables
+        // (e.g. (x,y) -> x > 0), visitArrayItemSlot mutates 
context.accessPathBuilder
+        // in-place (addPrefix without cleanup). A fresh context isolates the 
fallback
+        // path for unreferenced variables from pollution by referenced ones.
+        for (Expression argument : arguments) {
+            if (argument instanceof ArrayItemReference) {
+                Expression boundArray = argument.child(0);
+                if 
(!arguments.get(0).getInputSlots().containsAll(boundArray.getInputSlots())) {

Review Comment:
   This check is not a reliable way to decide whether the current lambda 
variable was referenced. `arguments.get(0)` is the lambda body, and 
`Expression.getInputSlots()` deliberately excludes `ArrayItemSlot`, so a 
referenced body such as `x -> element_at(x, 'f')` still does not contain the 
bound array slot and this fallback broadens the precise `a.*.f` path to full 
`a.*`. The opposite direction is also possible: `x -> a IS NULL` references the 
same outer array slot but not `x`, so this condition is false and the fallback 
does not add the full-access path for the unreferenced lambda variable, leaving 
the original null-only pruning hole. Please track references to the lambda 
argument itself, for example by marking `ArrayItemSlot` visits by expr id/name, 
and only add the full-access path for arguments that were truly not used.



##########
regression-test/suites/nereids_rules_p0/column_pruning/lambda_null_pruning.groovy:
##########
@@ -0,0 +1,150 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+suite("lambda_null_pruning") {
+    sql """ DROP TABLE IF EXISTS lambda_null_pruning_tbl """
+    sql """
+        CREATE TABLE lambda_null_pruning_tbl (
+            id  INT,
+            a   ARRAY<INT> NULL,
+            b   ARRAY<INT> NULL
+        ) ENGINE = OLAP
+        DUPLICATE KEY(id)
+        DISTRIBUTED BY HASH(id) BUCKETS 1
+        PROPERTIES ("replication_allocation" = "tag.location.default: 1")
+    """
+    sql """
+        INSERT INTO lambda_null_pruning_tbl VALUES
+            (1, [1, 2, 3],    [10, 20]),
+            (2, NULL,          NULL),
+            (3, [],            [1]),
+            (4, [null],        [1, 2, 3, 4])
+    """
+
+    // ================================================================
+    // Case 1: single-variable constant lambda body + IS NULL
+    // body = Literal(true), array item variable unreferenced
+    // collectArrayPathInLambda won't register full-access path.
+    // If IS NULL already registered [a.NULL], pruning goes wrong.
+    // ================================================================
+    explain {
+        sql """
+            SELECT id, a IS NULL, array_count(x -> true, a)
+            FROM lambda_null_pruning_tbl ORDER BY id
+        """
+        contains "nested columns"
+        notContains "a.NULL"
+    }
+
+    order_qt_case1 """

Review Comment:
   This suite adds several `order_qt_*` checks but the matching generated 
output file is not added 
(`regression-test/data/nereids_rules_p0/column_pruning/lambda_null_pruning.out` 
is missing). In normal regression mode the first `order_qt_case1` comparison 
has no expected section to match, so the new test will fail instead of covering 
the NCP fix. Please generate and commit the `.out` file for this suite.



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