Hi Shihao,

> Small fix: add a third path and use both sibling joins in the plan --
> PLAN (p OUTER ((p1 UNION p2) CROSS p3)). Now UNION is added so
> region coverage goes to 100% (line stays 100%). Patch attached, test
> passes.
>
> Also, given there is no other comments, move to wait for committer

Thanks for the input. The patch needed a rebase, here is v5.

It looks like you removed the previous reviewer from the commit
message and summarized only your changes, not the changes in the
entire commit. Please don't do this. In any doubt, better leave the
commit message as is. I corrected this in v5.

-- 
Best regards,
Aleksander Alekseev
From e3a29d1733cf5c9af9423ea220e7ed8ed12164e0 Mon Sep 17 00:00:00 2001
From: Aleksander Alekseev <[email protected]>
Date: Fri, 4 Sep 2026 20:32:12 -0400
Subject: [PATCH v5] Improve get_json_table_plan() test coverage

Add a test with PLAN (p OUTER ((p1 UNION p2) CROSS p3)). CROSS makes
the plan non-default so get_json_table_plan() is reached, and the
JsonTableSiblingJoin branch is exercised. UNION ensures 100% operator
coverage.

Author: Aleksander Alekseev <[email protected]>
Reviewed-by: Jonathan Gonzalez V. <[email protected]>
Reviewed-by: Shihao Zhong <[email protected]>
Discussion: https://postgr.es/m/caj7c6tp0kgan1hjtj1pytqvf0vyr+ce01oax9li_upgdg2n...@mail.gmail.com
---
 .../regress/expected/sqljson_jsontable.out    | 34 +++++++++++++++++++
 src/test/regress/sql/sqljson_jsontable.sql    | 13 +++++++
 2 files changed, 47 insertions(+)

diff --git a/src/test/regress/expected/sqljson_jsontable.out b/src/test/regress/expected/sqljson_jsontable.out
index 1dcb9479de3..5b4763850a5 100644
--- a/src/test/regress/expected/sqljson_jsontable.out
+++ b/src/test/regress/expected/sqljson_jsontable.out
@@ -2019,6 +2019,40 @@ CREATE OR REPLACE VIEW public.json_table_view_on_empty AS
             ) ERROR ON ERROR
         )
 DROP VIEW json_table_view_on_empty;
+-- Test that JSON_TABLE with an explicit CROSS plan is correctly reproduced
+-- in a view definition.
+CREATE VIEW jt_plan_outer_cross AS
+SELECT * FROM JSON_TABLE(
+    jsonb 'null', '$' AS p
+    COLUMNS (NESTED PATH '$[*]' AS p1 COLUMNS (a int),
+             NESTED PATH '$[*]' AS p2 COLUMNS (b int),
+             NESTED PATH '$[*]' AS p3 COLUMNS (c int))
+    PLAN (p OUTER ((p1 UNION p2) CROSS p3))
+);
+\sv jt_plan_outer_cross
+CREATE OR REPLACE VIEW public.jt_plan_outer_cross AS
+ SELECT a,
+    b,
+    c
+   FROM JSON_TABLE(
+            'null'::jsonb, '$' AS p
+            COLUMNS (
+                NESTED PATH '$[*]' AS p1
+                COLUMNS (
+                    a integer PATH '$."a"'
+                ),
+                NESTED PATH '$[*]' AS p2
+                COLUMNS (
+                    b integer PATH '$."b"'
+                ),
+                NESTED PATH '$[*]' AS p3
+                COLUMNS (
+                    c integer PATH '$."c"'
+                )
+            )
+            PLAN (p OUTER ((p1 UNION p2) CROSS p3))
+        )
+DROP VIEW jt_plan_outer_cross;
 -- Collations must be assigned to expressions in the context item and in
 -- the PASSING arguments (bug #19768)
 SELECT * FROM JSON_TABLE(jsonb_build_object('k', ROW(1, 2) < ROW(3, 4)), '$'
diff --git a/src/test/regress/sql/sqljson_jsontable.sql b/src/test/regress/sql/sqljson_jsontable.sql
index 73e60411df6..87064e50e07 100644
--- a/src/test/regress/sql/sqljson_jsontable.sql
+++ b/src/test/regress/sql/sqljson_jsontable.sql
@@ -1107,6 +1107,19 @@ SELECT * FROM JSON_TABLE(jsonb '{}', '$' AS p0
 
 DROP VIEW json_table_view_on_empty;
 
+-- Test that JSON_TABLE with an explicit CROSS plan is correctly reproduced
+-- in a view definition.
+CREATE VIEW jt_plan_outer_cross AS
+SELECT * FROM JSON_TABLE(
+    jsonb 'null', '$' AS p
+    COLUMNS (NESTED PATH '$[*]' AS p1 COLUMNS (a int),
+             NESTED PATH '$[*]' AS p2 COLUMNS (b int),
+             NESTED PATH '$[*]' AS p3 COLUMNS (c int))
+    PLAN (p OUTER ((p1 UNION p2) CROSS p3))
+);
+\sv jt_plan_outer_cross
+DROP VIEW jt_plan_outer_cross;
+
 -- Collations must be assigned to expressions in the context item and in
 -- the PASSING arguments (bug #19768)
 SELECT * FROM JSON_TABLE(jsonb_build_object('k', ROW(1, 2) < ROW(3, 4)), '$'
-- 
2.43.0

Reply via email to