]> granicus.if.org Git - postgresql/commitdiff
Disallow UNION/INTERSECT/EXCEPT over no columns.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 22 Dec 2017 17:08:28 +0000 (12:08 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 22 Dec 2017 17:08:28 +0000 (12:08 -0500)
Since 9.4, we've allowed the syntax "select union select" and variants
of that.  However, the planner wasn't expecting a no-column set operation
and ended up treating the set operation as if it were UNION ALL.

Pre-v10, there seem to be some executor issues that would need to be
fixed to support such cases, and it doesn't really seem worth expending
much effort on.  Just disallow it, instead.

Per report from Victor Yegorov.

Discussion: https://postgr.es/m/CAGnEbojGJrRSOgJwNGM7JSJZpVAf8xXcVPbVrGdhbVEHZ-BUMw@mail.gmail.com

src/backend/optimizer/prep/prepunion.c

index 7d0279ec3ef1e11d33a325419c514272e5500d83..b441f7e5cacf07551650f3ad55ff8a91f150e710 100644 (file)
@@ -697,9 +697,13 @@ generate_nonunion_path(SetOperationStmt *op, PlannerInfo *root,
        /* Identify the grouping semantics */
        groupList = generate_setop_grouplist(op, tlist);
 
-       /* punt if nothing to group on (can this happen?) */
+       /* punt if nothing to group on (not worth fixing in back branches) */
        if (groupList == NIL)
-               return path;
+               ereport(ERROR,
+                               (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+                                /* translator: %s is UNION, INTERSECT, or EXCEPT */
+                                errmsg("%s over no columns is not supported",
+                                               (op->op == SETOP_INTERSECT) ? "INTERSECT" : "EXCEPT")));
 
        /*
         * Estimate number of distinct groups that we'll need hashtable entries
@@ -850,9 +854,12 @@ make_union_unique(SetOperationStmt *op, Path *path, List *tlist,
        /* Identify the grouping semantics */
        groupList = generate_setop_grouplist(op, tlist);
 
-       /* punt if nothing to group on (can this happen?) */
+       /* punt if nothing to group on (not worth fixing in back branches) */
        if (groupList == NIL)
-               return path;
+               ereport(ERROR,
+                               (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+                                /* translator: %s is UNION, INTERSECT, or EXCEPT */
+                                errmsg("%s over no columns is not supported", "UNION")));
 
        /*
         * XXX for the moment, take the number of distinct groups as equal to the