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

Commitbad4943

Browse files
committed
Fix EXPLAIN (SETTINGS) to follow policy about when to print empty fields.
In non-TEXT output formats, the "Settings" field should appear whenrequested, even if it would be empty.Also, get rid of the premature optimization of counting all theGUC_EXPLAIN variables at startup. Since there was no provision foradjusting that count later, all it'd take would be some extension markinga parameter as GUC_EXPLAIN to risk an assertion failure or memory stomp.We could make get_explain_guc_options() count those variables on-the-fly,or dynamically resize its array ... but TBH I do not think that making atransient array of pointers a bit smaller is worth any extra complication,especially when you consider all the other transient space EXPLAIN eats.So just allocate that array at the max possible size.In HEAD, also add some regression test coverage for this feature.Because of the memory-stomp hazard, back-patch to v12 where thisfeature was added.Discussion:https://postgr.es/m/19416.1580069629@sss.pgh.pa.us
1 parent7294f99 commitbad4943

File tree

2 files changed

+22
-50
lines changed

2 files changed

+22
-50
lines changed

‎src/backend/commands/explain.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -616,17 +616,11 @@ ExplainPrintSettings(ExplainState *es)
616616
/* request an array of relevant settings */
617617
gucs=get_explain_guc_options(&num);
618618

619-
/* also bail out of there are no options */
620-
if (!num)
621-
return;
622-
623619
if (es->format!=EXPLAIN_FORMAT_TEXT)
624620
{
625-
inti;
626-
627621
ExplainOpenGroup("Settings","Settings", true,es);
628622

629-
for (i=0;i<num;i++)
623+
for (inti=0;i<num;i++)
630624
{
631625
char*setting;
632626
structconfig_generic*conf=gucs[i];
@@ -640,12 +634,15 @@ ExplainPrintSettings(ExplainState *es)
640634
}
641635
else
642636
{
643-
inti;
644637
StringInfoDatastr;
645638

639+
/* In TEXT mode, print nothing if there are no options */
640+
if (num <=0)
641+
return;
642+
646643
initStringInfo(&str);
647644

648-
for (i=0;i<num;i++)
645+
for (inti=0;i<num;i++)
649646
{
650647
char*setting;
651648
structconfig_generic*conf=gucs[i];
@@ -661,8 +658,7 @@ ExplainPrintSettings(ExplainState *es)
661658
appendStringInfo(&str,"%s = NULL",conf->name);
662659
}
663660

664-
if (num>0)
665-
ExplainPropertyText("Settings",str.data,es);
661+
ExplainPropertyText("Settings",str.data,es);
666662
}
667663
}
668664

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

Lines changed: 15 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4571,9 +4571,6 @@ static struct config_generic **guc_variables;
45714571
/* Current number of variables contained in the vector */
45724572
staticintnum_guc_variables;
45734573

4574-
/* Current number of variables marked with GUC_EXPLAIN */
4575-
staticintnum_guc_explain_variables;
4576-
45774574
/* Vector capacity */
45784575
staticintsize_guc_variables;
45794576

@@ -4837,7 +4834,6 @@ build_guc_variables(void)
48374834
{
48384835
intsize_vars;
48394836
intnum_vars=0;
4840-
intnum_explain_vars=0;
48414837
structconfig_generic**guc_vars;
48424838
inti;
48434839

@@ -4848,9 +4844,6 @@ build_guc_variables(void)
48484844
/* Rather than requiring vartype to be filled in by hand, do this: */
48494845
conf->gen.vartype=PGC_BOOL;
48504846
num_vars++;
4851-
4852-
if (conf->gen.flags&GUC_EXPLAIN)
4853-
num_explain_vars++;
48544847
}
48554848

48564849
for (i=0;ConfigureNamesInt[i].gen.name;i++)
@@ -4859,9 +4852,6 @@ build_guc_variables(void)
48594852

48604853
conf->gen.vartype=PGC_INT;
48614854
num_vars++;
4862-
4863-
if (conf->gen.flags&GUC_EXPLAIN)
4864-
num_explain_vars++;
48654855
}
48664856

48674857
for (i=0;ConfigureNamesReal[i].gen.name;i++)
@@ -4870,9 +4860,6 @@ build_guc_variables(void)
48704860

48714861
conf->gen.vartype=PGC_REAL;
48724862
num_vars++;
4873-
4874-
if (conf->gen.flags&GUC_EXPLAIN)
4875-
num_explain_vars++;
48764863
}
48774864

48784865
for (i=0;ConfigureNamesString[i].gen.name;i++)
@@ -4881,9 +4868,6 @@ build_guc_variables(void)
48814868

48824869
conf->gen.vartype=PGC_STRING;
48834870
num_vars++;
4884-
4885-
if (conf->gen.flags&GUC_EXPLAIN)
4886-
num_explain_vars++;
48874871
}
48884872

48894873
for (i=0;ConfigureNamesEnum[i].gen.name;i++)
@@ -4892,9 +4876,6 @@ build_guc_variables(void)
48924876

48934877
conf->gen.vartype=PGC_ENUM;
48944878
num_vars++;
4895-
4896-
if (conf->gen.flags&GUC_EXPLAIN)
4897-
num_explain_vars++;
48984879
}
48994880

49004881
/*
@@ -4926,7 +4907,6 @@ build_guc_variables(void)
49264907
free(guc_variables);
49274908
guc_variables=guc_vars;
49284909
num_guc_variables=num_vars;
4929-
num_guc_explain_variables=num_explain_vars;
49304910
size_guc_variables=size_vars;
49314911
qsort((void*)guc_variables,num_guc_variables,
49324912
sizeof(structconfig_generic*),guc_var_compare);
@@ -8875,41 +8855,40 @@ ShowAllGUCConfig(DestReceiver *dest)
88758855
}
88768856

88778857
/*
8878-
* Returns an array of modified GUC options to show in EXPLAIN. Only options
8879-
* related to query planning (marked with GUC_EXPLAIN), with values different
8880-
* from built-in defaults.
8858+
* Return an array of modified GUC options to show in EXPLAIN.
8859+
*
8860+
* We only report options related to query planning (marked with GUC_EXPLAIN),
8861+
* with values different from their built-in defaults.
88818862
*/
88828863
structconfig_generic**
88838864
get_explain_guc_options(int*num)
88848865
{
8885-
inti;
88868866
structconfig_generic**result;
88878867

88888868
*num=0;
88898869

88908870
/*
8891-
* Allocate enough space to fit all GUC_EXPLAIN options. We may not need
8892-
* all the space, but there are fairly few such options so we don't waste
8893-
* a lot of memory.
8871+
* While only a fraction of all the GUC variables are marked GUC_EXPLAIN,
8872+
* it doesn't seem worth dynamically resizing this array.
88948873
*/
8895-
result=palloc(sizeof(structconfig_generic*)*num_guc_explain_variables);
8874+
result=palloc(sizeof(structconfig_generic*)*num_guc_variables);
88968875

8897-
for (i=0;i<num_guc_variables;i++)
8876+
for (inti=0;i<num_guc_variables;i++)
88988877
{
88998878
boolmodified;
89008879
structconfig_generic*conf=guc_variables[i];
89018880

8902-
/* return only options visible to the user */
8881+
/* return only parameters marked for inclusion in explain */
8882+
if (!(conf->flags&GUC_EXPLAIN))
8883+
continue;
8884+
8885+
/* return only options visible to the current user */
89038886
if ((conf->flags&GUC_NO_SHOW_ALL)||
89048887
((conf->flags&GUC_SUPERUSER_ONLY)&&
89058888
!is_member_of_role(GetUserId(),DEFAULT_ROLE_READ_ALL_SETTINGS)))
89068889
continue;
89078890

8908-
/* only parameters explicitly marked for inclusion in explain */
8909-
if (!(conf->flags&GUC_EXPLAIN))
8910-
continue;
8911-
8912-
/* return only options that were modified (w.r.t. config file) */
8891+
/* return only options that are different from their boot values */
89138892
modified= false;
89148893

89158894
switch (conf->vartype)
@@ -8958,15 +8937,12 @@ get_explain_guc_options(int *num)
89588937
elog(ERROR,"unexpected GUC type: %d",conf->vartype);
89598938
}
89608939

8961-
/* skip GUC variables that match the built-in default */
89628940
if (!modified)
89638941
continue;
89648942

8965-
/*assign to the values array */
8943+
/*OK, report it */
89668944
result[*num]=conf;
89678945
*num=*num+1;
8968-
8969-
Assert(*num <=num_guc_explain_variables);
89708946
}
89718947

89728948
returnresult;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp