Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 63d2ac2

Browse files
committed
Undo double-quoting of index names in non-text EXPLAIN output formats.
explain_get_index_name() applied quote_identifier() to the index name. This is fine for text output, but the non-text output formats all have their own quoting conventions and would much rather start from the actual index name. For example in JSON you'd get something like "Index Name": "\"My Index\"", which is surely not desirable, especially when the same does not happen for table names. Hence, move the responsibility for applying quoting out to the callers, where it can go into already-existing special code paths for text format. This changes the API spec for users of explain_get_index_name_hook: before, they were supposed to apply quote_identifier() if necessary, now they should not. Research suggests that the only publicly available user of the hook is hypopg, and it actually forgot to apply quoting anyway, so it's fine. (In any case, there's no behavioral change for the output of a hook as seen in non-text EXPLAIN formats, so this won't break any case that programs should be relying on.) Digging in the commit logs, it appears that quoting was included in explain_get_index_name's duties when commit 604ffd2 invented it; and that was fine at the time because we only had text output format. This should have been rethought when non-text formats were invented, but it wasn't. This is a fairly clear bug for users of non-text EXPLAIN formats, so back-patch to all supported branches. Per bug #16502 from Maciek Sakrejda. Patch by me (based on investigation by Euler Taveira); thanks to Julien Rouhaud for review. Discussion: https://postgr.es/m/16502-57bd1c9f913ed1d1@postgresql.org
1 parent fe186b4 commit 63d2ac2

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/backend/commands/explain.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,7 +1456,8 @@ ExplainNode(PlanState *planstate, List *ancestors,
14561456
explain_get_index_name(bitmapindexscan->indexid);
14571457

14581458
if (es->format == EXPLAIN_FORMAT_TEXT)
1459-
appendStringInfo(es->str, " on %s", indexname);
1459+
appendStringInfo(es->str, " on %s",
1460+
quote_identifier(indexname));
14601461
else
14611462
ExplainPropertyText("Index Name", indexname, es);
14621463
}
@@ -3267,6 +3268,10 @@ show_eval_params(Bitmapset *bms_params, ExplainState *es)
32673268
*
32683269
* We allow plugins to get control here so that plans involving hypothetical
32693270
* indexes can be explained.
3271+
*
3272+
* Note: names returned by this function should be "raw"; the caller will
3273+
* apply quoting if needed. Formerly the convention was to do quoting here,
3274+
* but we don't want that in non-text output formats.
32703275
*/
32713276
static const char *
32723277
explain_get_index_name(Oid indexId)
@@ -3279,11 +3284,10 @@ explain_get_index_name(Oid indexId)
32793284
result = NULL;
32803285
if (result == NULL)
32813286
{
3282-
/* default behavior: look in the catalogs and quote it */
3287+
/* default behavior: look it up in the catalogs */
32833288
result = get_rel_name(indexId);
32843289
if (result == NULL)
32853290
elog(ERROR, "cache lookup failed for index %u", indexId);
3286-
result = quote_identifier(result);
32873291
}
32883292
return result;
32893293
}
@@ -3463,7 +3467,7 @@ ExplainIndexScanDetails(Oid indexid, ScanDirection indexorderdir,
34633467
{
34643468
if (ScanDirectionIsBackward(indexorderdir))
34653469
appendStringInfoString(es->str, " Backward");
3466-
appendStringInfo(es->str, " using %s", indexname);
3470+
appendStringInfo(es->str, " using %s", quote_identifier(indexname));
34673471
}
34683472
else
34693473
{

0 commit comments

Comments
 (0)