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


##########
regression-test/suites/recursive_cte/must_inline_volatile_cte_test.groovy:
##########
@@ -0,0 +1,112 @@
+// 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("must_inline_volatile_cte_test", "rec_cte") {
+    // The cte is only referenced by the non-recursive term of the recursive 
cte, which is executed once.
+    // uuid() lives in a materialized cte there, so the query is allowed.
+    qt_anchor_only """
+        WITH RECURSIVE
+        u AS (SELECT uuid() AS v),
+        r(n) AS (
+            SELECT CAST(1 AS INT) FROM u
+            UNION ALL
+            SELECT CAST(n + 1 AS INT) FROM r WHERE n < 3
+        )
+        SELECT n FROM r ORDER BY n
+    """
+
+    // The reference of the volatile cte is eliminated together with the dead 
branch, so nothing has to
+    // be inlined and the query only returns the anchor row.
+    qt_dead_branch """
+        WITH RECURSIVE
+        u AS (SELECT uuid() AS v),
+        r(n) AS (
+            SELECT CAST(1 AS INT)
+            UNION ALL
+            SELECT CAST(n + 1 AS INT) FROM r JOIN u ON TRUE WHERE n < 3 AND 
FALSE
+        )
+        SELECT n FROM r ORDER BY n
+    """
+
+    // The recursive child only uses k, so the volatile output v is pruned 
from the inlined copy
+    // instead of rejecting the query.
+    qt_unused_volatile_output """
+        WITH RECURSIVE
+        u AS (SELECT 1 AS k, uuid() AS v),
+        r(n) AS (
+            SELECT CAST(1 AS INT)
+            UNION ALL
+            SELECT CAST(n + u.k AS INT) FROM r JOIN u ON TRUE WHERE n < 3
+        )
+        SELECT n FROM r ORDER BY n
+    """
+
+    // The outer consumer needs v, the recursive child only needs k: the 
volatile producer stays
+    // materialized for the outer consumer while a pruned copy is inlined into 
the recursive child.
+    qt_mixed_consumer """
+        WITH RECURSIVE
+        u AS (SELECT 1 AS k, uuid() AS v),
+        r(n) AS (
+            SELECT CAST(1 AS INT)
+            UNION ALL
+            SELECT CAST(n + u.k AS INT) FROM r JOIN u ON TRUE WHERE n < 3
+        )
+        SELECT r.n FROM r, u WHERE u.v IS NOT NULL ORDER BY r.n

Review Comment:
   [P2] Keep the outer volatile output live in this regression
   
   `uuid()` is `AlwaysNotNullable`, the CTE consumer preserves that 
nullability, and constant folding turns `u.v IS NOT NULL` into `TRUE` before 
CTE output collection. The outer cross join then needs only row multiplicity, 
so column pruning can retain `k` and remove `v`/`uuid()` globally. This query 
and its success-only FE companion can therefore pass without retaining a 
materialized volatile output outside the recursion or exercising the claimed 
mixed-consumer split. Please make `v` affect a deterministic result (for 
example, select `char_length(u.v)` and expect 36) and assert the FE rewritten 
shape so the outer materialized consumer and recursive `k`-only copy are both 
verified.



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