Hi, I noticed that get_json_table_plan() is never executed by the existing tests. The proposed patch fixes this.
-- Best regards, Aleksander Alekseev
From a99b5e95dd095a04886b81f4ae3a7de94664fb70 Mon Sep 17 00:00:00 2001 From: Aleksander Alekseev <[email protected]> Date: Fri, 10 Jul 2026 16:27:54 +0300 Subject: [PATCH v1] Cover get_json_table_plan() with tests Function get_json_table() executes get_json_table_plan() only when json_table_plan_is_default() == false. For this reason the existing tests didn't cover get_json_table_plan() before. Author: Aleksander Alekseev <[email protected]> Reviewed-by: TODO FIXME Discussion: TODO FIXME --- .../regress/expected/sqljson_jsontable.out | 55 +++++++++++++++++++ src/test/regress/sql/sqljson_jsontable.sql | 22 ++++++++ 2 files changed, 77 insertions(+) diff --git a/src/test/regress/expected/sqljson_jsontable.out b/src/test/regress/expected/sqljson_jsontable.out index 1530ef8afe0..fc8e8d7e1a7 100644 --- a/src/test/regress/expected/sqljson_jsontable.out +++ b/src/test/regress/expected/sqljson_jsontable.out @@ -1847,3 +1847,58 @@ CREATE OR REPLACE VIEW public.json_table_view9 AS ) ) DROP VIEW json_table_view8, json_table_view9; +-- Test get_json_table_plan() +-- covers the INNER branch and the UNION branch +CREATE VIEW jt_plan_inner_union AS +SELECT * FROM JSON_TABLE( + jsonb 'null', '$' AS p + COLUMNS (NESTED PATH '$[*]' AS p1 COLUMNS (a int), + NESTED PATH '$[*]' AS p2 COLUMNS (b int)) + PLAN (p INNER (p1 UNION p2)) +); +\sv jt_plan_inner_union +CREATE OR REPLACE VIEW public.jt_plan_inner_union AS + SELECT a, + b + 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"' + ) + ) + PLAN (p INNER (p1 UNION p2)) + ) +DROP VIEW jt_plan_inner_union; +-- covers the OUTER branch and the CROSS branch +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)) + PLAN (p OUTER (p1 CROSS p2)) +); +\sv jt_plan_outer_cross +CREATE OR REPLACE VIEW public.jt_plan_outer_cross AS + SELECT a, + b + 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"' + ) + ) + PLAN (p OUTER (p1 CROSS p2)) + ) +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 d71d57e99b2..74903a75fc8 100644 --- a/src/test/regress/sql/sqljson_jsontable.sql +++ b/src/test/regress/sql/sqljson_jsontable.sql @@ -1004,3 +1004,25 @@ CREATE VIEW json_table_view9 AS SELECT * from JSON_TABLE('"a"', '$' COLUMNS (a t \sv json_table_view9; DROP VIEW json_table_view8, json_table_view9; + +-- Test get_json_table_plan() +-- covers the INNER branch and the UNION branch +CREATE VIEW jt_plan_inner_union AS +SELECT * FROM JSON_TABLE( + jsonb 'null', '$' AS p + COLUMNS (NESTED PATH '$[*]' AS p1 COLUMNS (a int), + NESTED PATH '$[*]' AS p2 COLUMNS (b int)) + PLAN (p INNER (p1 UNION p2)) +); +\sv jt_plan_inner_union +DROP VIEW jt_plan_inner_union; +-- covers the OUTER branch and the CROSS branch +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)) + PLAN (p OUTER (p1 CROSS p2)) +); +\sv jt_plan_outer_cross +DROP VIEW jt_plan_outer_cross; -- 2.43.0
