aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/explain.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2008-10-04 21:56:55 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2008-10-04 21:56:55 +0000
commit44d5be0e5308e951c0c5dc522b4bcacf2bcbc476 (patch)
tree516f1c70436225751f631e7e686f7ea61b3db9df /src/backend/commands/explain.c
parent607b2be7bb230ea4c558cb3101794f94de35ab85 (diff)
downloadpostgresql-44d5be0e5308e951c0c5dc522b4bcacf2bcbc476.tar.gz
postgresql-44d5be0e5308e951c0c5dc522b4bcacf2bcbc476.zip
Implement SQL-standard WITH clauses, including WITH RECURSIVE.
There are some unimplemented aspects: recursive queries must use UNION ALL (should allow UNION too), and we don't have SEARCH or CYCLE clauses. These might or might not get done for 8.4, but even without them it's a pretty useful feature. There are also a couple of small loose ends and definitional quibbles, which I'll send a memo about to pgsql-hackers shortly. But let's land the patch now so we can get on with other development. Yoshiyuki Asaba, with lots of help from Tatsuo Ishii and Tom Lane
Diffstat (limited to 'src/backend/commands/explain.c')
-rw-r--r--src/backend/commands/explain.c50
1 files changed, 49 insertions, 1 deletions
diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c
index 81f1dd0c31f..48334d1947b 100644
--- a/src/backend/commands/explain.c
+++ b/src/backend/commands/explain.c
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994-5, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/explain.c,v 1.178 2008/08/19 18:30:04 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/explain.c,v 1.179 2008/10/04 21:56:52 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -429,6 +429,9 @@ explain_outNode(StringInfo str,
case T_Append:
pname = "Append";
break;
+ case T_RecursiveUnion:
+ pname = "Recursive Union";
+ break;
case T_BitmapAnd:
pname = "BitmapAnd";
break;
@@ -537,6 +540,12 @@ explain_outNode(StringInfo str,
case T_ValuesScan:
pname = "Values Scan";
break;
+ case T_CteScan:
+ pname = "CTE Scan";
+ break;
+ case T_WorkTableScan:
+ pname = "WorkTable Scan";
+ break;
case T_Material:
pname = "Materialize";
break;
@@ -721,6 +730,40 @@ explain_outNode(StringInfo str,
quote_identifier(valsname));
}
break;
+ case T_CteScan:
+ if (((Scan *) plan)->scanrelid > 0)
+ {
+ RangeTblEntry *rte = rt_fetch(((Scan *) plan)->scanrelid,
+ es->rtable);
+
+ /* Assert it's on a non-self-reference CTE */
+ Assert(rte->rtekind == RTE_CTE);
+ Assert(!rte->self_reference);
+
+ appendStringInfo(str, " on %s",
+ quote_identifier(rte->ctename));
+ if (strcmp(rte->eref->aliasname, rte->ctename) != 0)
+ appendStringInfo(str, " %s",
+ quote_identifier(rte->eref->aliasname));
+ }
+ break;
+ case T_WorkTableScan:
+ if (((Scan *) plan)->scanrelid > 0)
+ {
+ RangeTblEntry *rte = rt_fetch(((Scan *) plan)->scanrelid,
+ es->rtable);
+
+ /* Assert it's on a self-reference CTE */
+ Assert(rte->rtekind == RTE_CTE);
+ Assert(rte->self_reference);
+
+ appendStringInfo(str, " on %s",
+ quote_identifier(rte->ctename));
+ if (strcmp(rte->eref->aliasname, rte->ctename) != 0)
+ appendStringInfo(str, " %s",
+ quote_identifier(rte->eref->aliasname));
+ }
+ break;
default:
break;
}
@@ -787,6 +830,8 @@ explain_outNode(StringInfo str,
case T_SeqScan:
case T_FunctionScan:
case T_ValuesScan:
+ case T_CteScan:
+ case T_WorkTableScan:
show_scan_qual(plan->qual,
"Filter",
((Scan *) plan)->scanrelid,
@@ -1071,6 +1116,9 @@ show_plan_tlist(Plan *plan,
/* The tlist of an Append isn't real helpful, so suppress it */
if (IsA(plan, Append))
return;
+ /* Likewise for RecursiveUnion */
+ if (IsA(plan, RecursiveUnion))
+ return;
/* Set up deparsing context */
context = deparse_context_for_plan((Node *) outerPlan(plan),