Skip to content

Commit 06473f5

Browse files
committed
Allow to log raw parse tree.
This commit allows to log the raw parse tree in the same way we currently log the parse tree, rewritten tree, and plan tree. To avoid unnecessary log noise for users not interested in this detail, a new GUC option, "debug_print_raw_parse", has been added. When starting the PostgreSQL process with "-d N", and N is 3 or higher, debug_print_raw_parse is enabled automatically, alongside debug_print_parse. Author: Chao Li <lic@highgo.com> Reviewed-by: Tender Wang <tndrwang@gmail.com> Reviewed-by: Tatsuo Ishii <ishii@postgresql.org> Reviewed-by: John Naylor <johncnaylorls@gmail.com> Discussion: https://postgr.es/m/CAEoWx2mcO0Gpo4vd8kPMAFWeJLSp0MeUUnaLdE1x0tSVd-VzUw%40mail.gmail.com
1 parent 2c78940 commit 06473f5

File tree

7 files changed

+26
-3
lines changed

7 files changed

+26
-3
lines changed

doc/src/sgml/config.sgml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7383,6 +7383,11 @@ local0.* /var/log/postgresql
73837383
</varlistentry>
73847384

73857385
<varlistentry id="guc-debug-print-parse">
7386+
<term><varname>debug_print_raw_parse</varname> (<type>boolean</type>)
7387+
<indexterm>
7388+
<primary><varname>debug_print_raw_parse</varname> configuration parameter</primary>
7389+
</indexterm>
7390+
</term>
73867391
<term><varname>debug_print_parse</varname> (<type>boolean</type>)
73877392
<indexterm>
73887393
<primary><varname>debug_print_parse</varname> configuration parameter</primary>
@@ -7401,8 +7406,8 @@ local0.* /var/log/postgresql
74017406
<listitem>
74027407
<para>
74037408
These parameters enable various debugging output to be emitted.
7404-
When set, they print the resulting parse tree, the query rewriter
7405-
output, or the execution plan for each executed query.
7409+
When set, they print the resulting raw parse tree, the parse tree, the query
7410+
rewriter output, or the execution plan for each executed query.
74067411
These messages are emitted at <literal>LOG</literal> message level, so by
74077412
default they will appear in the server log but will not be sent to the
74087413
client. You can change that by adjusting
@@ -7422,7 +7427,8 @@ local0.* /var/log/postgresql
74227427
<listitem>
74237428
<para>
74247429
When set, <varname>debug_pretty_print</varname> indents the messages
7425-
produced by <varname>debug_print_parse</varname>,
7430+
produced by <varname>debug_print_raw_parse</varname>,
7431+
<varname>debug_print_parse</varname>,
74267432
<varname>debug_print_rewritten</varname>, or
74277433
<varname>debug_print_plan</varname>. This results in more readable
74287434
but much longer output than the <quote>compact</quote> format used when

doc/src/sgml/rules.sgml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
<acronym>SQL</acronym> statement where the single parts that it is
6161
built from are stored separately. These query trees can be shown
6262
in the server log if you set the configuration parameters
63+
<varname>debug_print_raw_parse</varname>,
6364
<varname>debug_print_parse</varname>,
6465
<varname>debug_print_rewritten</varname>, or
6566
<varname>debug_print_plan</varname>. The rule actions are also

src/backend/tcop/postgres.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,10 @@ pg_parse_query(const char *query_string)
649649

650650
TRACE_POSTGRESQL_QUERY_PARSE_DONE(query_string);
651651

652+
if (Debug_print_raw_parse)
653+
elog_node_display(LOG, "raw parse tree", raw_parsetree_list,
654+
Debug_pretty_print);
655+
652656
return raw_parsetree_list;
653657
}
654658

@@ -3697,7 +3701,10 @@ set_debug_options(int debug_flag, GucContext context, GucSource source)
36973701
if (debug_flag >= 2)
36983702
SetConfigOption("log_statement", "all", context, source);
36993703
if (debug_flag >= 3)
3704+
{
3705+
SetConfigOption("debug_print_raw_parse", "true", context, source);
37003706
SetConfigOption("debug_print_parse", "true", context, source);
3707+
}
37013708
if (debug_flag >= 4)
37023709
SetConfigOption("debug_print_plan", "true", context, source);
37033710
if (debug_flag >= 5)

src/backend/utils/misc/guc_parameters.dat

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,12 @@
414414
ifdef => 'DEBUG_NODE_TESTS_ENABLED',
415415
},
416416

417+
{ name => 'debug_print_raw_parse', type => 'bool', context => 'PGC_USERSET', group => 'LOGGING_WHAT',
418+
short_desc => 'Logs each query\'s raw parse tree.',
419+
variable => 'Debug_print_raw_parse',
420+
boot_val => 'false',
421+
},
422+
417423
{ name => 'debug_print_parse', type => 'bool', context => 'PGC_USERSET', group => 'LOGGING_WHAT',
418424
short_desc => 'Logs each query\'s parse tree.',
419425
variable => 'Debug_print_parse',

src/backend/utils/misc/guc_tables.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,7 @@ bool AllowAlterSystem = true;
507507
bool log_duration = false;
508508
bool Debug_print_plan = false;
509509
bool Debug_print_parse = false;
510+
bool Debug_print_raw_parse = false;
510511
bool Debug_print_rewritten = false;
511512
bool Debug_pretty_print = true;
512513

src/backend/utils/misc/postgresql.conf.sample

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,7 @@
581581

582582
# - What to Log -
583583

584+
#debug_print_raw_parse = off
584585
#debug_print_parse = off
585586
#debug_print_rewritten = off
586587
#debug_print_plan = off

src/include/utils/guc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ typedef enum
247247
/* GUC vars that are actually defined in guc_tables.c, rather than elsewhere */
248248
extern PGDLLIMPORT bool Debug_print_plan;
249249
extern PGDLLIMPORT bool Debug_print_parse;
250+
extern PGDLLIMPORT bool Debug_print_raw_parse;
250251
extern PGDLLIMPORT bool Debug_print_rewritten;
251252
extern PGDLLIMPORT bool Debug_pretty_print;
252253

0 commit comments

Comments
 (0)