/* planner will not cope with utility statements */
if (query->commandType == CMD_UTILITY)
{
- ExplainOneUtility(query->utilityStmt, into, es, queryString, params);
+ /*
+ * If we are running EXPLAIN ANALYZE, transform the CTAS such that the
+ * target table is created first and select result is inserted into the
+ * table. The EXPLAIN ANALYZE would really just show the plan for the
+ * INSERT INTO generated by QueryRewriteCTAS, but that's OK.
+ */
+ if (es->analyze && IsA(query->utilityStmt, CreateTableAsStmt))
+ {
+ List *rewritten = QueryRewriteCTAS(query);
+ Assert(list_length(rewritten) == 1);
+ ExplainOneQuery((Query *) linitial(rewritten), into, es,
+ queryString, params);
+ }
+ else
+ ExplainOneUtility(query->utilityStmt, into, es,
+ queryString, params);
return;
}
ERROR: relation "created_table" does not exist
LINE 1: SELECT * FROM created_table;
^
+-- Try EXPLAIN ANALYZE SELECT INTO, but hide the output since it won't
+-- be stable.
+DO $$
+BEGIN
+ EXECUTE 'EXPLAIN ANALYZE SELECT * INTO TABLE easi FROM int8_tbl';
+END$$;
DROP TABLE created_table;
ERROR: table "created_table" does not exist
+DROP TABLE easi;
--
-- Disallowed uses of SELECT ... INTO. All should fail
--