Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcafde58

Browse files
committed
Allow compute_query_id to be set to 'auto' and make it default
Allowing only on/off meant that all either all existing configurationguides would become obsolete if we disabled it by default, or that wewould have to accept a performance loss in the default config if weenabled it by default. By allowing 'auto' as a middle ground, theperformance cost is only paid by those who enable pg_stat_statements andsimilar modules.I only edited the release notes to comment-out a paragraph that is nowfactually wrong; further edits are probably needed to describe therelated change in more detail.Author: Julien Rouhaud <rjuju123@gmail.com>Reviewed-by: Justin Pryzby <pryzby@telsasoft.com>Discussion:https://postgr.es/m/20210513002623.eugftm4nk2lvvks3@nol
1 parent30d8bad commitcafde58

File tree

14 files changed

+108
-30
lines changed

14 files changed

+108
-30
lines changed

‎contrib/pg_stat_statements/pg_stat_statements.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,12 @@ _PG_init(void)
369369
if (!process_shared_preload_libraries_in_progress)
370370
return;
371371

372+
/*
373+
* Inform the postmaster that we want to enable query_id calculation if
374+
* compute_query_id is set to auto.
375+
*/
376+
EnableQueryId();
377+
372378
/*
373379
* Define (or redefine) custom GUC variables.
374380
*/
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
shared_preload_libraries = 'pg_stat_statements'
2-
compute_query_id = on

‎doc/src/sgml/config.sgml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7627,7 +7627,7 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv;
76277627
<variablelist>
76287628

76297629
<varlistentry id="guc-compute-query-id" xreflabel="compute_query_id">
7630-
<term><varname>compute_query_id</varname> (<type>boolean</type>)
7630+
<term><varname>compute_query_id</varname> (<type>enum</type>)
76317631
<indexterm>
76327632
<primary><varname>compute_query_id</varname> configuration parameter</primary>
76337633
</indexterm>
@@ -7643,7 +7643,12 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv;
76437643
identifier to be computed. Note that an external module can
76447644
alternatively be used if the in-core query identifier computation
76457645
method is not acceptable. In this case, in-core computation
7646-
must be disabled. The default is <literal>off</literal>.
7646+
must be always disabled.
7647+
Valid values are <literal>off</literal> (always disabled),
7648+
<literal>on</literal> (always enabled) and <literal>auto</literal>,
7649+
which lets modules such as <xref linkend="pgstatstatements"/>
7650+
automatically enable it.
7651+
The default is <literal>auto</literal>.
76477652
</para>
76487653
<note>
76497654
<para>

‎doc/src/sgml/pgstatstatements.sgml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,14 @@
1818
<xref linkend="guc-shared-preload-libraries"/> in
1919
<filename>postgresql.conf</filename>, because it requires additional shared memory.
2020
This means that a server restart is needed to add or remove the module.
21+
In addition, query identifier calculation must be enabled in order for the
22+
module to be active, which is done automatically if <xref linkend="guc-compute-query-id"/>
23+
is set to <literal>auto</literal> or <literal>on</literal>, or any third-party
24+
module that calculates query identifiers is loaded.
2125
</para>
2226

2327
<para>
24-
The module will not track statistics unless query
25-
identifiers are calculated. This can be done by enabling <xref
26-
linkend="guc-compute-query-id"/> or using a third-party module that
27-
computes its own query identifiers. Note that all statistics tracked
28-
by this module must be reset if the query identifier method is changed.
29-
</para>
30-
31-
<para>
32-
When <filename>pg_stat_statements</filename> is loaded, it tracks
28+
When <filename>pg_stat_statements</filename> is active, it tracks
3329
statistics across all databases of the server. To access and manipulate
3430
these statistics, the module provides views
3531
<structname>pg_stat_statements</structname> and

‎doc/src/sgml/release-14.sgml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3181,10 +3181,12 @@ Author: Bruce Momjian <bruce@momjian.us>
31813181
Move query hash computation from pg_stat_statements to the core server (Julien Rouhaud)
31823182
</para>
31833183

3184+
<!--
31843185
<para>
31853186
Extension pg_stat_statements will now need to enable query hash computation to function properly.
31863187
This can be done by enabling the server variable compute_query_id or by using an extension with a custom hash computation method.
31873188
</para>
3189+
-->
31883190
</listitem>
31893191

31903192
<listitem>

‎src/backend/commands/explain.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ ExplainQuery(ParseState *pstate, ExplainStmt *stmt,
245245
es->summary= (summary_set) ?es->summary :es->analyze;
246246

247247
query=castNode(Query,stmt->query);
248-
if (compute_query_id)
248+
if (IsQueryIdEnabled())
249249
jstate=JumbleQuery(query,pstate->p_sourcetext);
250250

251251
if (post_parse_analyze_hook)

‎src/backend/parser/analyze.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ parse_analyze(RawStmt *parseTree, const char *sourceText,
124124

125125
query=transformTopLevelStmt(pstate,parseTree);
126126

127-
if (compute_query_id)
127+
if (IsQueryIdEnabled())
128128
jstate=JumbleQuery(query,sourceText);
129129

130130
if (post_parse_analyze_hook)
@@ -163,7 +163,7 @@ parse_analyze_varparams(RawStmt *parseTree, const char *sourceText,
163163
/* make sure all is well with parameter types */
164164
check_variable_parameters(pstate,query);
165165

166-
if (compute_query_id)
166+
if (IsQueryIdEnabled())
167167
jstate=JumbleQuery(query,sourceText);
168168

169169
if (post_parse_analyze_hook)

‎src/backend/postmaster/postmaster.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ typedef struct
521521
pg_time_tfirst_syslogger_file_time;
522522
boolredirection_done;
523523
boolIsBinaryUpgrade;
524+
boolauto_query_id_enabled;
524525
intmax_safe_fds;
525526
intMaxBackends;
526527
#ifdefWIN32
@@ -6168,6 +6169,7 @@ save_backend_variables(BackendParameters *param, Port *port,
61686169

61696170
param->redirection_done=redirection_done;
61706171
param->IsBinaryUpgrade=IsBinaryUpgrade;
6172+
param->auto_query_id_enabled=auto_query_id_enabled;
61716173
param->max_safe_fds=max_safe_fds;
61726174

61736175
param->MaxBackends=MaxBackends;
@@ -6401,6 +6403,7 @@ restore_backend_variables(BackendParameters *param, Port *port)
64016403

64026404
redirection_done=param->redirection_done;
64036405
IsBinaryUpgrade=param->IsBinaryUpgrade;
6406+
auto_query_id_enabled=param->auto_query_id_enabled;
64046407
max_safe_fds=param->max_safe_fds;
64056408

64066409
MaxBackends=param->MaxBackends;

‎src/backend/tcop/postgres.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ pg_analyze_and_rewrite_params(RawStmt *parsetree,
704704

705705
query=transformTopLevelStmt(pstate,parsetree);
706706

707-
if (compute_query_id)
707+
if (IsQueryIdEnabled())
708708
jstate=JumbleQuery(query,query_string);
709709

710710
if (post_parse_analyze_hook)

‎src/backend/utils/misc/guc.c

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
#include"utils/plancache.h"
102102
#include"utils/portal.h"
103103
#include"utils/ps_status.h"
104+
#include"utils/queryjumble.h"
104105
#include"utils/rls.h"
105106
#include"utils/snapmgr.h"
106107
#include"utils/tzparser.h"
@@ -402,6 +403,23 @@ static const struct config_enum_entry backslash_quote_options[] = {
402403
{NULL,0, false}
403404
};
404405

406+
/*
407+
* Although only "on", "off", and "auto" are documented, we accept
408+
* all the likely variants of "on" and "off".
409+
*/
410+
staticconststructconfig_enum_entrycompute_query_id_options[]= {
411+
{"auto",COMPUTE_QUERY_ID_AUTO, false},
412+
{"on",COMPUTE_QUERY_ID_ON, false},
413+
{"off",COMPUTE_QUERY_ID_OFF, false},
414+
{"true",COMPUTE_QUERY_ID_ON, true},
415+
{"false",COMPUTE_QUERY_ID_OFF, true},
416+
{"yes",COMPUTE_QUERY_ID_ON, true},
417+
{"no",COMPUTE_QUERY_ID_OFF, true},
418+
{"1",COMPUTE_QUERY_ID_ON, true},
419+
{"0",COMPUTE_QUERY_ID_OFF, true},
420+
{NULL,0, false}
421+
};
422+
405423
/*
406424
* Although only "on", "off", and "partition" are documented, we
407425
* accept all the likely variants of "on" and "off".
@@ -534,7 +552,6 @@ extern const struct config_enum_entry dynamic_shared_memory_options[];
534552
/*
535553
* GUC option variables that are exported from this module
536554
*/
537-
boolcompute_query_id= false;
538555
boollog_duration= false;
539556
boolDebug_print_plan= false;
540557
boolDebug_print_parse= false;
@@ -1441,15 +1458,6 @@ static struct config_bool ConfigureNamesBool[] =
14411458
true,
14421459
NULL,NULL,NULL
14431460
},
1444-
{
1445-
{"compute_query_id",PGC_SUSET,STATS_MONITORING,
1446-
gettext_noop("Compute query identifiers."),
1447-
NULL
1448-
},
1449-
&compute_query_id,
1450-
false,
1451-
NULL,NULL,NULL
1452-
},
14531461
{
14541462
{"log_parser_stats",PGC_SUSET,STATS_MONITORING,
14551463
gettext_noop("Writes parser performance statistics to the server log."),
@@ -4619,6 +4627,16 @@ static struct config_enum ConfigureNamesEnum[] =
46194627
NULL,NULL,NULL
46204628
},
46214629

4630+
{
4631+
{"compute_query_id",PGC_SUSET,STATS_MONITORING,
4632+
gettext_noop("Compute query identifiers."),
4633+
NULL
4634+
},
4635+
&compute_query_id,
4636+
COMPUTE_QUERY_ID_AUTO,compute_query_id_options,
4637+
NULL,NULL,NULL
4638+
},
4639+
46224640
{
46234641
{"constraint_exclusion",PGC_USERSET,QUERY_TUNING_OTHER,
46244642
gettext_noop("Enables the planner to use constraints to optimize queries."),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@
604604

605605
# - Monitoring -
606606

607-
#compute_query_id =off
607+
#compute_query_id =auto
608608
#log_statement_stats = off
609609
#log_parser_stats = off
610610
#log_planner_stats = off

‎src/backend/utils/misc/queryjumble.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@
3939

4040
#defineJUMBLE_SIZE1024/* query serialization buffer size */
4141

42+
/* GUC parameters */
43+
intcompute_query_id=COMPUTE_QUERY_ID_AUTO;
44+
45+
/* True when compute_query_id is ON, or AUTO and a module requests them */
46+
boolquery_id_enabled= false;
47+
4248
staticuint64compute_utility_query_id(constchar*str,intquery_location,intquery_len);
4349
staticvoidAppendJumble(JumbleState*jstate,
4450
constunsignedchar*item,Sizesize);
@@ -96,6 +102,8 @@ JumbleQuery(Query *query, const char *querytext)
96102
{
97103
JumbleState*jstate=NULL;
98104

105+
Assert(IsQueryIdEnabled());
106+
99107
if (query->utilityStmt)
100108
{
101109
query->queryId=compute_utility_query_id(querytext,
@@ -132,6 +140,19 @@ JumbleQuery(Query *query, const char *querytext)
132140
returnjstate;
133141
}
134142

143+
/*
144+
* Enables query identifier computation.
145+
*
146+
* Third-party plugins can use this function to inform core that they require
147+
* a query identifier to be computed.
148+
*/
149+
void
150+
EnableQueryId(void)
151+
{
152+
if (compute_query_id!=COMPUTE_QUERY_ID_OFF)
153+
query_id_enabled= true;
154+
}
155+
135156
/*
136157
* Compute a query identifier for the given utility query string.
137158
*/

‎src/include/utils/guc.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,6 @@ extern bool log_btree_build_stats;
247247
externPGDLLIMPORTboolcheck_function_bodies;
248248
externboolsession_auth_is_superuser;
249249

250-
externboolcompute_query_id;
251250
externboollog_duration;
252251
externintlog_parameter_max_length;
253252
externintlog_parameter_max_length_on_error;

‎src/include/utils/queryjumble.h

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,36 @@ typedef struct JumbleState
5252
inthighest_extern_param_id;
5353
}JumbleState;
5454

55-
constchar*CleanQuerytext(constchar*query,int*location,int*len);
56-
JumbleState*JumbleQuery(Query*query,constchar*querytext);
55+
/* Values for the compute_query_id GUC */
56+
typedefenum
57+
{
58+
COMPUTE_QUERY_ID_OFF,
59+
COMPUTE_QUERY_ID_ON,
60+
COMPUTE_QUERY_ID_AUTO
61+
}ComputeQueryIdType;
62+
63+
/* GUC parameters */
64+
externintcompute_query_id;
65+
66+
67+
externconstchar*CleanQuerytext(constchar*query,int*location,int*len);
68+
externJumbleState*JumbleQuery(Query*query,constchar*querytext);
69+
externvoidEnableQueryId(void);
70+
71+
externboolquery_id_enabled;
72+
73+
/*
74+
* Returns whether query identifier computation has been enabled, either
75+
* directly in the GUC or by a module when the setting is 'auto'.
76+
*/
77+
staticinlinebool
78+
IsQueryIdEnabled(void)
79+
{
80+
if (compute_query_id==COMPUTE_QUERY_ID_OFF)
81+
return false;
82+
if (compute_query_id==COMPUTE_QUERY_ID_ON)
83+
return true;
84+
returnquery_id_enabled;
85+
}
5786

5887
#endif/* QUERYJUMBLE_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp