From 51c115933c81549a168fe0f2cb2a3c06b497f465 Mon Sep 17 00:00:00 2001 From: Aleksander Alekseev Date: Fri, 4 Sep 2026 20:32:12 -0400 Subject: [PATCH v4] Improve get_json_table_plan() test coverage Extend the plan to (p1 UNION p2) CROSS p3 so deparsing exercises the UNION sibling-join arm, which the existing test never reached. This takes get_json_table_plan() from 97% to 100% region coverage (it was already at 100% line coverage). Author: Aleksander Alekseev Reviewed-by: Shihao Zhong Discussion: https://postgr.es/m/CAJ7c6TP0kgaN1Hjtj1PYtQVF0vyr+ce01oAx9Li_UpGDG2NMmA@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 ae64dbed303..4fa812f53a5 100644 --- a/src/test/regress/expected/sqljson_jsontable.out +++ b/src/test/regress/expected/sqljson_jsontable.out @@ -1926,3 +1926,37 @@ 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; diff --git a/src/test/regress/sql/sqljson_jsontable.sql b/src/test/regress/sql/sqljson_jsontable.sql index 2a33aaec57f..dc9b1433645 100644 --- a/src/test/regress/sql/sqljson_jsontable.sql +++ b/src/test/regress/sql/sqljson_jsontable.sql @@ -1052,3 +1052,16 @@ SELECT * FROM JSON_TABLE(jsonb '{}', '$' AS p0 \sv json_table_view_on_empty; 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; -- 2.37.1 (Apple Git-137.1)