diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2017-12-22 12:08:41 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2017-12-22 12:08:41 -0500 |
commit | e1b8e0e4a61ed100510d70e63930273a6614cec4 (patch) | |
tree | 32ed7e27155a87613961a12651a6c85083d2747c | |
parent | 02f66d8656e8fb1ba56604994149f063c7230a18 (diff) | |
download | postgresql-e1b8e0e4a61ed100510d70e63930273a6614cec4.tar.gz |
Disallow UNION/INTERSECT/EXCEPT over no columns.
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
-rw-r--r-- | src/backend/optimizer/prep/prepunion.c | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/backend/optimizer/prep/prepunion.c b/src/backend/optimizer/prep/prepunion.c index 1cec511e0f..64829404e6 100644 --- a/src/backend/optimizer/prep/prepunion.c +++ b/src/backend/optimizer/prep/prepunion.c @@ -592,12 +592,13 @@ generate_nonunion_plan(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) - { - *sortClauses = NIL; - return plan; - } + 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 @@ -736,12 +737,12 @@ make_union_unique(SetOperationStmt *op, Plan *plan, /* Identify the grouping semantics */ groupList = generate_setop_grouplist(op, plan->targetlist); - /* punt if nothing to group on (can this happen?) */ + /* punt if nothing to group on (not worth fixing in back branches) */ if (groupList == NIL) - { - *sortClauses = NIL; - return plan; - } + 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 |