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

Commitdd9af92

Browse files
committed
Add display of sort keys to the default EXPLAIN output.
1 parenta5b3709 commitdd9af92

File tree

3 files changed

+87
-4
lines changed

3 files changed

+87
-4
lines changed

‎src/backend/commands/explain.c

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
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.77 2002/05/12 20:10:02 tgl Exp $
8+
* $Header: /cvsroot/pgsql/src/backend/commands/explain.c,v 1.78 2002/05/18 21:38:40 tgl Exp $
99
*
1010
*/
1111

@@ -56,6 +56,8 @@ static void show_upper_qual(List *qual, const char *qlabel,
5656
constchar*outer_name,intouter_varno,Plan*outer_plan,
5757
constchar*inner_name,intinner_varno,Plan*inner_plan,
5858
StringInfostr,intindent,ExplainState*es);
59+
staticvoidshow_sort_keys(List*tlist,intnkeys,constchar*qlabel,
60+
StringInfostr,intindent,ExplainState*es);
5961
staticNode*make_ors_ands_explicit(List*orclauses);
6062
staticTextOutputState*begin_text_output(CommandDestdest,char*title);
6163
staticvoiddo_text_output(TextOutputState*tstate,char*aline);
@@ -410,7 +412,7 @@ explain_outNode(StringInfo str, Plan *plan, Plan *outer_plan,
410412
}
411413
appendStringInfo(str,"\n");
412414

413-
/* quals */
415+
/* quals, sort keys, etc */
414416
switch (nodeTag(plan))
415417
{
416418
caseT_IndexScan:
@@ -495,6 +497,11 @@ explain_outNode(StringInfo str, Plan *plan, Plan *outer_plan,
495497
"",0,NULL,
496498
str,indent,es);
497499
break;
500+
caseT_Sort:
501+
show_sort_keys(plan->targetlist, ((Sort*)plan)->keycount,
502+
"Sort Key",
503+
str,indent,es);
504+
break;
498505
caseT_Result:
499506
show_upper_qual((List*) ((Result*)plan)->resconstantqual,
500507
"One-Time Filter",
@@ -731,6 +738,60 @@ show_upper_qual(List *qual, const char *qlabel,
731738
appendStringInfo(str," %s: %s\n",qlabel,exprstr);
732739
}
733740

741+
/*
742+
* Show the sort keys for a Sort node.
743+
*/
744+
staticvoid
745+
show_sort_keys(List*tlist,intnkeys,constchar*qlabel,
746+
StringInfostr,intindent,ExplainState*es)
747+
{
748+
List*context;
749+
booluseprefix;
750+
intkeyno;
751+
List*tl;
752+
char*exprstr;
753+
inti;
754+
755+
if (nkeys <=0)
756+
return;
757+
758+
for (i=0;i<indent;i++)
759+
appendStringInfo(str," ");
760+
appendStringInfo(str," %s: ",qlabel);
761+
762+
/*
763+
* In this routine we expect that the plan node's tlist has not been
764+
* processed by set_plan_references(), so any Vars will contain valid
765+
* varnos referencing the actual rtable.
766+
*/
767+
context=deparse_context_from_rtable(es->rtable);
768+
useprefix=length(es->rtable)>1;
769+
770+
for (keyno=1;keyno <=nkeys;keyno++)
771+
{
772+
/* find key expression in tlist */
773+
foreach(tl,tlist)
774+
{
775+
TargetEntry*target= (TargetEntry*)lfirst(tl);
776+
777+
if (target->resdom->reskey==keyno)
778+
{
779+
/* Deparse the expression */
780+
exprstr=deparse_expression(target->expr,context,useprefix);
781+
/* And add to str */
782+
if (keyno>1)
783+
appendStringInfo(str,", ");
784+
appendStringInfo(str,"%s",exprstr);
785+
break;
786+
}
787+
}
788+
if (tl==NIL)
789+
elog(ERROR,"show_sort_keys: no tlist entry for key %d",keyno);
790+
}
791+
792+
appendStringInfo(str,"\n");
793+
}
794+
734795
/*
735796
* Indexscan qual lists have an implicit OR-of-ANDs structure. Make it
736797
* explicit so deparsing works properly.

‎src/backend/utils/adt/ruleutils.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*back to source text
44
*
55
* IDENTIFICATION
6-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.105 2002/05/17 01:19:18 tgl Exp $
6+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.106 2002/05/18 21:38:40 tgl Exp $
77
*
88
* This software is copyrighted by Jan Wieck - Hamburg.
99
*
@@ -779,6 +779,27 @@ deparse_context_for_subplan(const char *name, List *tlist,
779779
return (Node*)rte;
780780
}
781781

782+
/*
783+
* deparse_context_from_rtable- Build deparse context given a rangetable
784+
*
785+
* This is suitable for deparsing expressions that refer to only a single
786+
* level of variables (no outer-reference Vars).
787+
*/
788+
List*
789+
deparse_context_from_rtable(List*rtable)
790+
{
791+
deparse_namespace*dpns;
792+
793+
dpns= (deparse_namespace*)palloc(sizeof(deparse_namespace));
794+
795+
dpns->rtable=rtable;
796+
dpns->outer_varno=dpns->inner_varno=0;
797+
dpns->outer_rte=dpns->inner_rte=NULL;
798+
799+
/* Return a one-deep namespace stack */
800+
returnmakeList1(dpns);
801+
}
802+
782803
/* ----------
783804
* make_ruledef- reconstruct the CREATE RULE command
784805
* for a given pg_rewrite tuple

‎src/include/utils/builtins.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: builtins.h,v 1.181 2002/05/12 20:10:05 tgl Exp $
10+
* $Id: builtins.h,v 1.182 2002/05/18 21:38:41 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -357,6 +357,7 @@ extern List *deparse_context_for_plan(int outer_varno, Node *outercontext,
357357
externNode*deparse_context_for_rte(RangeTblEntry*rte);
358358
externNode*deparse_context_for_subplan(constchar*name,List*tlist,
359359
List*rtable);
360+
externList*deparse_context_from_rtable(List*rtable);
360361
externconstchar*quote_identifier(constchar*ident);
361362
externchar*quote_qualified_identifier(constchar*namespace,
362363
constchar*ident);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp