Commit 4d1816ec authored by Tomas Vondra's avatar Tomas Vondra

Don't print extra parens around expressions in extended stats

The code printing expressions for extended statistics doubled the
parens, producing results like ((a+1)), which is unnecessary and not
consistent with how we print expressions elsewhere.

Fixed by tweaking the code to produce just a single set of parens.

Reported by Mark Dilger, fix by me. Backpatch to 14, where support for
extended statistics on expressions was added.

Reported-by: Mark Dilger
Discussion: https://postgr.es/m/20210122040101.GF27167%40telsasoft.com
parent 3eda9fc0
...@@ -1712,7 +1712,7 @@ pg_get_statisticsobj_worker(Oid statextid, bool columns_only, bool missing_ok) ...@@ -1712,7 +1712,7 @@ pg_get_statisticsobj_worker(Oid statextid, bool columns_only, bool missing_ok)
{ {
Node *expr = (Node *) lfirst(lc); Node *expr = (Node *) lfirst(lc);
char *str; char *str;
int prettyFlags = PRETTYFLAG_INDENT; int prettyFlags = PRETTYFLAG_PAREN;
str = deparse_expression_pretty(expr, context, false, false, str = deparse_expression_pretty(expr, context, false, false,
prettyFlags, 0); prettyFlags, 0);
......
...@@ -2756,7 +2756,7 @@ my %tests = ( ...@@ -2756,7 +2756,7 @@ my %tests = (
create_sql => 'CREATE STATISTICS dump_test.test_ext_stats_expr create_sql => 'CREATE STATISTICS dump_test.test_ext_stats_expr
ON (2 * col1) FROM dump_test.test_fifth_table', ON (2 * col1) FROM dump_test.test_fifth_table',
regexp => qr/^ regexp => qr/^
\QCREATE STATISTICS dump_test.test_ext_stats_expr ON ((2 * col1)) FROM dump_test.test_fifth_table;\E \QCREATE STATISTICS dump_test.test_ext_stats_expr ON (2 * col1) FROM dump_test.test_fifth_table;\E
/xms, /xms,
like => like =>
{ %full_runs, %dump_test_schema_runs, section_post_data => 1, }, { %full_runs, %dump_test_schema_runs, section_post_data => 1, },
......
...@@ -417,7 +417,7 @@ Check constraints: ...@@ -417,7 +417,7 @@ Check constraints:
"ctlt1_a_check" CHECK (length(a) > 2) "ctlt1_a_check" CHECK (length(a) > 2)
Statistics objects: Statistics objects:
"public.ctlt_all_a_b_stat" ON a, b FROM ctlt_all "public.ctlt_all_a_b_stat" ON a, b FROM ctlt_all
"public.ctlt_all_expr_stat" ON ((a || b)) FROM ctlt_all "public.ctlt_all_expr_stat" ON (a || b) FROM ctlt_all
SELECT c.relname, objsubid, description FROM pg_description, pg_index i, pg_class c WHERE classoid = 'pg_class'::regclass AND objoid = i.indexrelid AND c.oid = i.indexrelid AND i.indrelid = 'ctlt_all'::regclass ORDER BY c.relname, objsubid; SELECT c.relname, objsubid, description FROM pg_description, pg_index i, pg_class c WHERE classoid = 'pg_class'::regclass AND objoid = i.indexrelid AND c.oid = i.indexrelid AND i.indrelid = 'ctlt_all'::regclass ORDER BY c.relname, objsubid;
relname | objsubid | description relname | objsubid | description
...@@ -457,7 +457,7 @@ Check constraints: ...@@ -457,7 +457,7 @@ Check constraints:
"ctlt1_a_check" CHECK (length(a) > 2) "ctlt1_a_check" CHECK (length(a) > 2)
Statistics objects: Statistics objects:
"public.pg_attrdef_a_b_stat" ON a, b FROM public.pg_attrdef "public.pg_attrdef_a_b_stat" ON a, b FROM public.pg_attrdef
"public.pg_attrdef_expr_stat" ON ((a || b)) FROM public.pg_attrdef "public.pg_attrdef_expr_stat" ON (a || b) FROM public.pg_attrdef
DROP TABLE public.pg_attrdef; DROP TABLE public.pg_attrdef;
-- Check that LIKE isn't confused when new table masks the old, either -- Check that LIKE isn't confused when new table masks the old, either
...@@ -479,7 +479,7 @@ Check constraints: ...@@ -479,7 +479,7 @@ Check constraints:
"ctlt1_a_check" CHECK (length(a) > 2) "ctlt1_a_check" CHECK (length(a) > 2)
Statistics objects: Statistics objects:
"ctl_schema.ctlt1_a_b_stat" ON a, b FROM ctlt1 "ctl_schema.ctlt1_a_b_stat" ON a, b FROM ctlt1
"ctl_schema.ctlt1_expr_stat" ON ((a || b)) FROM ctlt1 "ctl_schema.ctlt1_expr_stat" ON (a || b) FROM ctlt1
ROLLBACK; ROLLBACK;
DROP TABLE ctlt1, ctlt2, ctlt3, ctlt4, ctlt12_storage, ctlt12_comments, ctlt1_inh, ctlt13_inh, ctlt13_like, ctlt_all, ctla, ctlb CASCADE; DROP TABLE ctlt1, ctlt2, ctlt3, ctlt4, ctlt12_storage, ctlt12_comments, ctlt1_inh, ctlt13_inh, ctlt13_like, ctlt_all, ctla, ctlb CASCADE;
......
...@@ -3002,8 +3002,8 @@ set search_path to public, stts_s1, stts_s2, tststats; ...@@ -3002,8 +3002,8 @@ set search_path to public, stts_s1, stts_s2, tststats;
\dX \dX
List of extended statistics List of extended statistics
Schema | Name | Definition | Ndistinct | Dependencies | MCV Schema | Name | Definition | Ndistinct | Dependencies | MCV
----------+------------------------+------------------------------------------------------------------------+-----------+--------------+--------- ----------+------------------------+------------------------------------------------------------------+-----------+--------------+---------
public | func_deps_stat | ((a * 2)), upper(b), ((c + (1)::numeric)) FROM functional_dependencies | | defined | public | func_deps_stat | (a * 2), upper(b), (c + 1::numeric) FROM functional_dependencies | | defined |
public | mcv_lists_arrays_stats | a, b, c FROM mcv_lists_arrays | | | defined public | mcv_lists_arrays_stats | a, b, c FROM mcv_lists_arrays | | | defined
public | mcv_lists_bool_stats | a, b, c FROM mcv_lists_bool | | | defined public | mcv_lists_bool_stats | a, b, c FROM mcv_lists_bool | | | defined
public | mcv_lists_stats | a, b, d FROM mcv_lists | | | defined public | mcv_lists_stats | a, b, d FROM mcv_lists | | | defined
...@@ -3037,8 +3037,8 @@ set search_path to public, stts_s1, stts_s2, tststats; ...@@ -3037,8 +3037,8 @@ set search_path to public, stts_s1, stts_s2, tststats;
\dX+ \dX+
List of extended statistics List of extended statistics
Schema | Name | Definition | Ndistinct | Dependencies | MCV Schema | Name | Definition | Ndistinct | Dependencies | MCV
----------+------------------------+------------------------------------------------------------------------+-----------+--------------+--------- ----------+------------------------+------------------------------------------------------------------+-----------+--------------+---------
public | func_deps_stat | ((a * 2)), upper(b), ((c + (1)::numeric)) FROM functional_dependencies | | defined | public | func_deps_stat | (a * 2), upper(b), (c + 1::numeric) FROM functional_dependencies | | defined |
public | mcv_lists_arrays_stats | a, b, c FROM mcv_lists_arrays | | | defined public | mcv_lists_arrays_stats | a, b, c FROM mcv_lists_arrays | | | defined
public | mcv_lists_bool_stats | a, b, c FROM mcv_lists_bool | | | defined public | mcv_lists_bool_stats | a, b, c FROM mcv_lists_bool | | | defined
public | mcv_lists_stats | a, b, d FROM mcv_lists | | | defined public | mcv_lists_stats | a, b, d FROM mcv_lists | | | defined
...@@ -3080,8 +3080,8 @@ set search_path to public, stts_s1; ...@@ -3080,8 +3080,8 @@ set search_path to public, stts_s1;
\dX \dX
List of extended statistics List of extended statistics
Schema | Name | Definition | Ndistinct | Dependencies | MCV Schema | Name | Definition | Ndistinct | Dependencies | MCV
---------+------------------------+------------------------------------------------------------------------+-----------+--------------+--------- ---------+------------------------+------------------------------------------------------------------+-----------+--------------+---------
public | func_deps_stat | ((a * 2)), upper(b), ((c + (1)::numeric)) FROM functional_dependencies | | defined | public | func_deps_stat | (a * 2), upper(b), (c + 1::numeric) FROM functional_dependencies | | defined |
public | mcv_lists_arrays_stats | a, b, c FROM mcv_lists_arrays | | | defined public | mcv_lists_arrays_stats | a, b, c FROM mcv_lists_arrays | | | defined
public | mcv_lists_bool_stats | a, b, c FROM mcv_lists_bool | | | defined public | mcv_lists_bool_stats | a, b, c FROM mcv_lists_bool | | | defined
public | mcv_lists_stats | a, b, d FROM mcv_lists | | | defined public | mcv_lists_stats | a, b, d FROM mcv_lists | | | defined
...@@ -3098,8 +3098,8 @@ set role regress_stats_ext; ...@@ -3098,8 +3098,8 @@ set role regress_stats_ext;
\dX \dX
List of extended statistics List of extended statistics
Schema | Name | Definition | Ndistinct | Dependencies | MCV Schema | Name | Definition | Ndistinct | Dependencies | MCV
--------+------------------------+------------------------------------------------------------------------+-----------+--------------+--------- --------+------------------------+------------------------------------------------------------------+-----------+--------------+---------
public | func_deps_stat | ((a * 2)), upper(b), ((c + (1)::numeric)) FROM functional_dependencies | | defined | public | func_deps_stat | (a * 2), upper(b), (c + 1::numeric) FROM functional_dependencies | | defined |
public | mcv_lists_arrays_stats | a, b, c FROM mcv_lists_arrays | | | defined public | mcv_lists_arrays_stats | a, b, c FROM mcv_lists_arrays | | | defined
public | mcv_lists_bool_stats | a, b, c FROM mcv_lists_bool | | | defined public | mcv_lists_bool_stats | a, b, c FROM mcv_lists_bool | | | defined
public | mcv_lists_stats | a, b, d FROM mcv_lists | | | defined public | mcv_lists_stats | a, b, d FROM mcv_lists | | | defined
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment