fix detection of DML (INSERT/UPDATE/DELETE) in subquery_planner
authorTomas Vondra <[email protected]>
Fri, 6 Jan 2017 21:12:15 +0000 (22:12 +0100)
committerTomas Vondra <[email protected]>
Fri, 6 Jan 2017 21:12:15 +0000 (22:12 +0100)
After the merge, there was no condition on commandType, so it was
probably triggered even on SELECT subqueries. Also, move it at the
very beginning of subquery_planner().

src/backend/optimizer/plan/planner.c

index ee232c08dc2ebedbb8b17540c45071914442ce32..759c2cb21aa570d59f05fdf78cb6f79c89f67642 100644 (file)
@@ -503,6 +503,14 @@ subquery_planner(PlannerGlobal *glob, Query *parse,
        ListCell   *l;
        bool recursiveOk = true;
 
+#ifdef XCP
+       /* XL currently does not support DML in subqueries. */
+       if ((parse->commandType != CMD_SELECT) && (parent_root->query_level > 0))
+               ereport(ERROR,
+                               (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+                                errmsg("INSERT/UPDATE/DELETE is not supported in subquery")));
+#endif
+
        /* Create a PlannerInfo data structure for this subquery */
        root = makeNode(PlannerInfo);
        root->parse = parse;
@@ -824,13 +832,6 @@ subquery_planner(PlannerGlobal *glob, Query *parse,
         */
        SS_identify_outer_params(root);
 
-#ifdef XCP
-       if (root->query_level > 1)
-               ereport(ERROR,
-                               (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
-                                errmsg("INSERT/UPDATE/DELETE is not supported in subquery")));
-#endif
-
        /*
         * If any initPlans were created in this query level, increment the
         * surviving Paths' costs to account for them.  They won't actually get