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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Cast.java:
##########
@@ -93,6 +93,17 @@ protected Cast(List<Expression> child, DataType targetType, 
boolean isExplicitTy
         this.isStrict = isStrict;
     }
 
+    @Override
+    public boolean isDeterministic() {

Review Comment:
   [P3] Preserve folding for a typed NULL TIME cast. In `SELECT count(*) FROM t 
WHERE CAST(CAST(NULL AS TIME) AS DATETIME) IS NULL`, the outer cast always 
returns NULL, but this type-only rule marks it nondeterministic and makes 
`foldable()` false. `FoldConstantRuleOnFE.preProcess` then exits before NULL 
propagation, so `FoldConstantForSqlCache` rejects an otherwise stable query. 
Propagate the known NULL before applying the query-clock volatility rule, while 
retaining the guard for non-NULL TIME values.



##########
regression-test/suites/query_p0/cache/condition_cache_eligibility.groovy:
##########
@@ -0,0 +1,78 @@
+// 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("condition_cache_eligibility") {
+    sql "DROP TABLE IF EXISTS condition_cache_eligibility"
+    sql """
+        CREATE TABLE condition_cache_eligibility (
+            k BIGINT,
+            a ARRAY<INT>,
+            dt1 DATETIME,
+            dt2 DATETIME
+        ) DUPLICATE KEY(k)
+        DISTRIBUTED BY HASH(k) BUCKETS 1
+        PROPERTIES ("replication_num" = "1")
+    """
+    sql """
+        INSERT INTO condition_cache_eligibility
+        SELECT number, [1,2,3,4,5,6,7], '2026-09-30 12:00:00', '2026-09-30 
12:00:00'
+        FROM numbers("number" = "100000")
+    """
+
+    // Keep seeded random sequences stable across scans; isolate condition 
cache from result caches.
+    sql "set enable_parallel_scan = false"
+    sql "set enable_sql_cache = false"
+    sql "set enable_query_cache = false"
+    sql "set enable_condition_cache = false"
+    order_qt_rand_baseline """
+        SELECT count(*) FROM condition_cache_eligibility WHERE k < 0 OR 
rand(1) < 0.0001
+    """
+    order_qt_shuffle_baseline """
+        SELECT count(*) FROM condition_cache_eligibility WHERE 
array_shuffle(a, 1) = [1,2,3,4,5,6,7]
+    """
+
+    sql "set enable_condition_cache = true"
+    order_qt_rand_first """
+        SELECT count(*) FROM condition_cache_eligibility WHERE k < 0 OR 
rand(1) < 0.0001
+    """
+    order_qt_rand_second """
+        SELECT count(*) FROM condition_cache_eligibility WHERE k < 0 OR 
rand(1) < 0.0001
+    """
+    order_qt_shuffle_first """
+        SELECT count(*) FROM condition_cache_eligibility WHERE 
array_shuffle(a, 1) = [1,2,3,4,5,6,7]
+    """
+    order_qt_shuffle_second """
+        SELECT count(*) FROM condition_cache_eligibility WHERE 
array_shuffle(a, 1) = [1,2,3,4,5,6,7]
+    """
+    order_qt_shuffle_alias """
+        SELECT count(*) FROM condition_cache_eligibility WHERE shuffle(a, 1) = 
[1,2,3,4,5,6,7]
+    """
+    order_qt_time_date """
+        SELECT count(*) FROM condition_cache_eligibility
+        WHERE CAST(TIMEDIFF(dt1, dt2) AS DATE) = CURRENT_DATE()
+    """
+    order_qt_time_date_second """
+        SELECT count(*) FROM condition_cache_eligibility
+        WHERE CAST(TIMEDIFF(dt1, dt2) AS DATE) = CURRENT_DATE()
+    """
+    order_qt_deterministic_first """
+        SELECT count(*) FROM condition_cache_eligibility WHERE k % 10000 = 0
+    """
+    order_qt_deterministic_second """

Review Comment:
   [P2] Assert BE cache behavior in both halves of this regression. These 
queries compare only counts: the volatile rand/shuffle/TIME counts can match 
even if condition-cache lookup or reuse occurs, while both deterministic `k % 
10000 = 0` counts stay 10 even if the BE gate disables caching entirely. The 
DUP-key fixture's complex predicates do reach the BE common-expression cache 
path. Assert no lookups for the volatile scans using a per-scan counter or 
isolated search metric, and assert `ConditionCacheHit > 0` on the second 
deterministic scan; the FE test only checks the serialized flag.



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayShuffle.java:
##########
@@ -36,7 +37,7 @@
  * ScalarFunction 'array_shuffle'
  *  with 1 or 2 arguments : array_shuffle(arr) or array_shuffle(arr, seed)
  */
-public class ArrayShuffle extends ScalarFunction
+public class ArrayShuffle extends UniqueFunction

Review Comment:
   [P3] Preserve NULL propagation for shuffle. `array_shuffle(CAST(NULL AS 
ARRAY<INT>), 1)` always returns NULL, but changing this class to 
`UniqueFunction` makes `foldable()` false. `FoldConstantRuleOnFE.preProcess` 
exits before its `PropagateNullable` NULL branch, leaving a volatile expression 
that disables SQL and query cache reuse for a stable result. Fold the 
known-NULL case before applying volatility; keep non-NULL shuffle calls 
volatile.



##########
regression-test/data/query_p0/cache/condition_cache_eligibility.out:
##########
@@ -0,0 +1,34 @@
+-- This file is automatically generated. You should know what you did if you 
want to edit this
+-- !rand_baseline --
+11
+
+-- !shuffle_baseline --
+13

Review Comment:
   [P2] Avoid a fixed seeded-shuffle count here. `array_shuffle(a, 1)` creates 
a fresh seeded generator for each BE input block, so the result depends on 
block boundaries. This suite does not pin `batch_size`; with the supported 
`batch_size=1`, every one of its 100000 identical arrays gets the same 
permutation and this count is either 0 or 100000, never 13. Assert cache 
behavior with profile counters, or control the scan block shape before 
recording a fixed result.



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