diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2007-06-23 22:12:52 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2007-06-23 22:12:52 +0000 |
commit | 46379d6e60f0f95e127a5045ca1fa74dfdc48a85 (patch) | |
tree | 7d6fe8004575203b40a38184c154dc7f34a20345 /src/backend/tcop/utility.c | |
parent | ec0bb02db8452d4098023f82b100ba68d8f7dfab (diff) | |
download | postgresql-46379d6e60f0f95e127a5045ca1fa74dfdc48a85.tar.gz postgresql-46379d6e60f0f95e127a5045ca1fa74dfdc48a85.zip |
Separate parse-analysis for utility commands out of parser/analyze.c
(which now deals only in optimizable statements), and put that code
into a new file parser/parse_utilcmd.c. This helps clarify and enforce
the design rule that utility statements shouldn't be processed during
the regular parse analysis phase; all interpretation of their meaning
should happen after they are given to ProcessUtility to execute.
(We need this because we don't retain any locks for a utility statement
that's in a plan cache, nor have any way to detect that it's stale.)
We are also able to simplify the API for parse_analyze() and related
routines, because they will now always return exactly one Query structure.
In passing, fix bug #3403 concerning trying to add a serial column to
an existing temp table (this is largely Heikki's work, but we needed
all that restructuring to make it safe).
Diffstat (limited to 'src/backend/tcop/utility.c')
-rw-r--r-- | src/backend/tcop/utility.c | 89 |
1 files changed, 76 insertions, 13 deletions
diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c index baa203a2d19..c334743adaf 100644 --- a/src/backend/tcop/utility.c +++ b/src/backend/tcop/utility.c @@ -10,7 +10,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/tcop/utility.c,v 1.280 2007/05/30 20:12:01 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/tcop/utility.c,v 1.281 2007/06/23 22:12:52 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -45,7 +45,7 @@ #include "commands/vacuum.h" #include "commands/view.h" #include "miscadmin.h" -#include "parser/analyze.h" +#include "parser/parse_utilcmd.h" #include "postmaster/bgwriter.h" #include "rewrite/rewriteDefine.h" #include "rewrite/rewriteRemove.h" @@ -544,17 +544,47 @@ ProcessUtility(Node *parsetree, case T_CreateStmt: { + List *stmts; + ListCell *l; Oid relOid; - relOid = DefineRelation((CreateStmt *) parsetree, - RELKIND_RELATION); + /* Run parse analysis ... */ + stmts = transformCreateStmt((CreateStmt *) parsetree, + queryString); - /* - * Let AlterTableCreateToastTable decide if this one needs a - * secondary relation too. - */ - CommandCounterIncrement(); - AlterTableCreateToastTable(relOid); + /* ... and do it */ + foreach(l, stmts) + { + Node *stmt = (Node *) lfirst(l); + + if (IsA(stmt, CreateStmt)) + { + /* Create the table itself */ + relOid = DefineRelation((CreateStmt *) stmt, + RELKIND_RELATION); + + /* + * Let AlterTableCreateToastTable decide if this one + * needs a secondary relation too. + */ + CommandCounterIncrement(); + AlterTableCreateToastTable(relOid); + } + else + { + /* Recurse for anything else */ + ProcessUtility(stmt, + queryString, + params, + false, + None_Receiver, + NULL); + } + + /* Need CCI between commands */ + if (lnext(l) != NULL) + CommandCounterIncrement(); + } } break; @@ -693,7 +723,40 @@ ProcessUtility(Node *parsetree, break; case T_AlterTableStmt: - AlterTable((AlterTableStmt *) parsetree); + { + List *stmts; + ListCell *l; + + /* Run parse analysis ... */ + stmts = transformAlterTableStmt((AlterTableStmt *) parsetree, + queryString); + + /* ... and do it */ + foreach(l, stmts) + { + Node *stmt = (Node *) lfirst(l); + + if (IsA(stmt, AlterTableStmt)) + { + /* Do the table alteration proper */ + AlterTable((AlterTableStmt *) stmt); + } + else + { + /* Recurse for anything else */ + ProcessUtility(stmt, + queryString, + params, + false, + None_Receiver, + NULL); + } + + /* Need CCI between commands */ + if (lnext(l) != NULL) + CommandCounterIncrement(); + } + } break; case T_AlterDomainStmt: @@ -812,7 +875,7 @@ ProcessUtility(Node *parsetree, CheckRelationOwnership(stmt->relation, true); /* Run parse analysis ... */ - stmt = analyzeIndexStmt(stmt, queryString); + stmt = transformIndexStmt(stmt, queryString); /* ... and do it */ DefineIndex(stmt->relation, /* relation */ @@ -1605,7 +1668,7 @@ CreateCommandTag(Node *parsetree) /* * We might be supporting ALTER INDEX here, so set the - * completion table appropriately. Catch all other + * completion tag appropriately. Catch all other * possibilities with ALTER TABLE */ |