Skip to content

Commit d662f29

Browse files
committed
Use quote_identifier on relation names in EXPLAIN output, per suggestion
from Liam Stewart. Minor code cleanups also.
1 parent 4a2fe8e commit d662f29

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

src/backend/commands/explain.c

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
66
* Portions Copyright (c) 1994-5, Regents of the University of California
77
*
8-
* $Header: /cvsroot/pgsql/src/backend/commands/explain.c,v 1.75 2002/03/24 17:11:36 tgl Exp $
8+
* $Header: /cvsroot/pgsql/src/backend/commands/explain.c,v 1.76 2002/05/03 15:56:45 tgl Exp $
99
*
1010
*/
1111

1212
#include "postgres.h"
1313

14+
#include "access/genam.h"
1415
#include "access/heapam.h"
1516
#include "catalog/pg_type.h"
1617
#include "commands/explain.h"
@@ -26,7 +27,6 @@
2627
#include "utils/builtins.h"
2728
#include "utils/guc.h"
2829
#include "utils/lsyscache.h"
29-
#include "utils/relcache.h"
3030

3131

3232
typedef struct ExplainState
@@ -62,9 +62,6 @@ static void do_text_output(TextOutputState *tstate, char *aline);
6262
static void do_text_output_multiline(TextOutputState *tstate, char *text);
6363
static void end_text_output(TextOutputState *tstate);
6464

65-
/* Convert a null string pointer into "<>" */
66-
#define stringStringInfo(s) (((s) == NULL) ? "<>" : (s))
67-
6865

6966
/*
7067
* ExplainQuery -
@@ -227,7 +224,6 @@ explain_outNode(StringInfo str, Plan *plan, Plan *outer_plan,
227224
int indent, ExplainState *es)
228225
{
229226
List *l;
230-
Relation relation;
231227
char *pname;
232228
int i;
233229

@@ -322,13 +318,13 @@ explain_outNode(StringInfo str, Plan *plan, Plan *outer_plan,
322318
i = 0;
323319
foreach(l, ((IndexScan *) plan)->indxid)
324320
{
325-
relation = RelationIdGetRelation(lfirsti(l));
326-
Assert(relation);
321+
Relation relation;
322+
323+
relation = index_open(lfirsti(l));
327324
appendStringInfo(str, "%s%s",
328325
(++i > 1) ? ", " : "",
329-
stringStringInfo(RelationGetRelationName(relation)));
330-
/* drop relcache refcount from RelationIdGetRelation */
331-
RelationDecrementReferenceCount(relation);
326+
quote_identifier(RelationGetRelationName(relation)));
327+
index_close(relation);
332328
}
333329
/* FALL THRU */
334330
case T_SeqScan:
@@ -346,10 +342,10 @@ explain_outNode(StringInfo str, Plan *plan, Plan *outer_plan,
346342
relname = get_rel_name(rte->relid);
347343

348344
appendStringInfo(str, " on %s",
349-
stringStringInfo(relname));
345+
quote_identifier(relname));
350346
if (strcmp(rte->eref->aliasname, relname) != 0)
351347
appendStringInfo(str, " %s",
352-
stringStringInfo(rte->eref->aliasname));
348+
quote_identifier(rte->eref->aliasname));
353349
}
354350
break;
355351
case T_SubqueryScan:
@@ -359,7 +355,7 @@ explain_outNode(StringInfo str, Plan *plan, Plan *outer_plan,
359355
es->rtable);
360356

361357
appendStringInfo(str, " %s",
362-
stringStringInfo(rte->eref->aliasname));
358+
quote_identifier(rte->eref->aliasname));
363359
}
364360
break;
365361
default:

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy