aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/cache
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2012-03-19 21:37:19 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2012-03-19 21:38:12 -0400
commit9dbf2b7d75de5af38d087cbe2b1147dd0fd10f0a (patch)
treed58e41d2855f7ac2a5c4c1c4893aaf6f03e1aabc /src/backend/utils/cache
parent77503a7638a35eedd9cb08d9ca4c54deb203521d (diff)
downloadpostgresql-9dbf2b7d75de5af38d087cbe2b1147dd0fd10f0a.tar.gz
postgresql-9dbf2b7d75de5af38d087cbe2b1147dd0fd10f0a.zip
Restructure SELECT INTO's parsetree representation into CreateTableAsStmt.
Making this operation look like a utility statement seems generally a good idea, and particularly so in light of the desire to provide command triggers for utility statements. The original choice of representing it as SELECT with an IntoClause appendage had metastasized into rather a lot of places, unfortunately, so that this patch is a great deal more complicated than one might at first expect. In particular, keeping EXPLAIN working for SELECT INTO and CREATE TABLE AS subcommands required restructuring some EXPLAIN-related APIs. Add-on code that calls ExplainOnePlan or ExplainOneUtility, or uses ExplainOneQuery_hook, will need adjustment. Also, the cases PREPARE ... SELECT INTO and CREATE RULE ... SELECT INTO, which formerly were accepted though undocumented, are no longer accepted. The PREPARE case can be replaced with use of CREATE TABLE AS EXECUTE. The CREATE RULE case doesn't seem to have much real-world use (since the rule would work only once before failing with "table already exists"), so we'll not bother with that one. Both SELECT INTO and CREATE TABLE AS still return a command tag of "SELECT nnnn". There was some discussion of returning "CREATE TABLE nnnn", but for the moment backwards compatibility wins the day. Andres Freund and Tom Lane
Diffstat (limited to 'src/backend/utils/cache')
-rw-r--r--src/backend/utils/cache/plancache.c30
1 files changed, 12 insertions, 18 deletions
diff --git a/src/backend/utils/cache/plancache.c b/src/backend/utils/cache/plancache.c
index 7e66645b2b6..6292f8dc6c9 100644
--- a/src/backend/utils/cache/plancache.c
+++ b/src/backend/utils/cache/plancache.c
@@ -1232,20 +1232,16 @@ AcquireExecutorLocks(List *stmt_list, bool acquire)
if (!IsA(plannedstmt, PlannedStmt))
{
/*
- * Ignore utility statements, except EXPLAIN which contains a
- * parsed-but-not-planned query. Note: it's okay to use
+ * Ignore utility statements, except those (such as EXPLAIN) that
+ * contain a parsed-but-not-planned query. Note: it's okay to use
* ScanQueryForLocks, even though the query hasn't been through
* rule rewriting, because rewriting doesn't change the query
* representation.
*/
- if (IsA(plannedstmt, ExplainStmt))
- {
- Query *query;
+ Query *query = UtilityContainsQuery((Node *) plannedstmt);
- query = (Query *) ((ExplainStmt *) plannedstmt)->query;
- Assert(IsA(query, Query));
+ if (query)
ScanQueryForLocks(query, acquire);
- }
continue;
}
@@ -1304,13 +1300,10 @@ AcquirePlannerLocks(List *stmt_list, bool acquire)
if (query->commandType == CMD_UTILITY)
{
- /* Ignore utility statements, except EXPLAIN */
- if (IsA(query->utilityStmt, ExplainStmt))
- {
- query = (Query *) ((ExplainStmt *) query->utilityStmt)->query;
- Assert(IsA(query, Query));
+ /* Ignore utility statements, unless they contain a Query */
+ query = UtilityContainsQuery(query->utilityStmt);
+ if (query)
ScanQueryForLocks(query, acquire);
- }
continue;
}
@@ -1648,9 +1641,9 @@ ResetPlanCache(void)
* aborted transactions when we can't revalidate them (cf bug #5269).
* In general there is no point in invalidating utility statements
* since they have no plans anyway. So invalidate it only if it
- * contains at least one non-utility statement. (EXPLAIN counts as a
- * non-utility statement, though, since it contains an analyzed query
- * that might have dependencies.)
+ * contains at least one non-utility statement, or contains a utility
+ * statement that contains a pre-analyzed query (which could have
+ * dependencies.)
*/
foreach(lc, plansource->query_list)
{
@@ -1658,12 +1651,13 @@ ResetPlanCache(void)
Assert(IsA(query, Query));
if (query->commandType != CMD_UTILITY ||
- IsA(query->utilityStmt, ExplainStmt))
+ UtilityContainsQuery(query->utilityStmt))
{
/* non-utility statement, so invalidate */
plansource->is_valid = false;
if (plansource->gplan)
plansource->gplan->is_valid = false;
+ /* no need to look further */
break;
}
}