]> granicus.if.org Git - postgresql/commitdiff
Fix crash in assign_collations_walker for EXISTS with empty SELECT list.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 3 Dec 2013 01:28:45 +0000 (20:28 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 3 Dec 2013 01:28:45 +0000 (20:28 -0500)
We (I think I, actually) forgot about this corner case while coding
collation resolution.  Per bug #8648 from Arjen Nienhuis.

src/backend/parser/parse_collate.c
src/test/regress/expected/subselect.out
src/test/regress/sql/subselect.sql

index fe57c596183a82395f22e99927e97c4ac04231a9..c02f98acc712db4757524b7d3b03f3cd6c84701e 100644 (file)
@@ -484,16 +484,22 @@ assign_collations_walker(Node *node, assign_collations_context *context)
                                 * SubLink.  Act as though the Query returns its first output
                                 * column, which indeed is what it does for EXPR_SUBLINK and
                                 * ARRAY_SUBLINK cases.  In the cases where the SubLink
-                                * returns boolean, this info will be ignored.
+                                * returns boolean, this info will be ignored.  Special case:
+                                * in EXISTS, the Query might return no columns, in which case
+                                * we need do nothing.
                                 *
                                 * We needn't recurse, since the Query is already processed.
                                 */
                                Query      *qtree = (Query *) node;
                                TargetEntry *tent;
 
+                               if (qtree->targetList == NIL)
+                                       return false;
                                tent = (TargetEntry *) linitial(qtree->targetList);
                                Assert(IsA(tent, TargetEntry));
-                               Assert(!tent->resjunk);
+                               if (tent->resjunk)
+                                       return false;
+
                                collation = exprCollation((Node *) tent->expr);
                                /* collation doesn't change if it's converted to array */
                                strength = COLLATE_IMPLICIT;
index 1baf3d3e23eecbe00080b6c21984e5b4624565d6..39c12f91e8cce329f2d4d30bd5e20ecceff8bc5e 100644 (file)
@@ -700,3 +700,13 @@ explain (verbose, costs off)
                  One-Time Filter: ("*VALUES*".column1 = "*VALUES*".column1)
 (8 rows)
 
+--
+-- Check we behave sanely in corner case of empty SELECT list (bug #8648)
+--
+create temp table nocolumns();
+select exists(select * from nocolumns);
+ exists 
+--------
+ f
+(1 row)
+
index 0795d4353461a800be54936f898ed6c276417bd9..278580797ecb41b81aef1984116334536e4fb721 100644 (file)
@@ -405,3 +405,9 @@ explain (verbose, costs off)
 explain (verbose, costs off)
   select x, x from
     (select (select random() where y=y) as x from (values(1),(2)) v(y)) ss;
+
+--
+-- Check we behave sanely in corner case of empty SELECT list (bug #8648)
+--
+create temp table nocolumns();
+select exists(select * from nocolumns);