Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7ab3214

Browse filesBrowse files
committed
Fix crash in assign_collations_walker for EXISTS with empty SELECT list.
We (I think I, actually) forgot about this corner case while coding collation resolution. Per bug #8648 from Arjen Nienhuis.
1 parent 02bb4bb commit 7ab3214
Copy full SHA for 7ab3214

File tree

3 files changed

+24
-2
lines changed
Filter options

3 files changed

+24
-2
lines changed

‎src/backend/parser/parse_collate.c

Copy file name to clipboardExpand all lines: src/backend/parser/parse_collate.c
+8-2Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,16 +484,22 @@ assign_collations_walker(Node *node, assign_collations_context *context)
484484
* SubLink. Act as though the Query returns its first output
485485
* column, which indeed is what it does for EXPR_SUBLINK and
486486
* ARRAY_SUBLINK cases. In the cases where the SubLink
487-
* returns boolean, this info will be ignored.
487+
* returns boolean, this info will be ignored. Special case:
488+
* in EXISTS, the Query might return no columns, in which case
489+
* we need do nothing.
488490
*
489491
* We needn't recurse, since the Query is already processed.
490492
*/
491493
Query *qtree = (Query *) node;
492494
TargetEntry *tent;
493495

496+
if (qtree->targetList == NIL)
497+
return false;
494498
tent = (TargetEntry *) linitial(qtree->targetList);
495499
Assert(IsA(tent, TargetEntry));
496-
Assert(!tent->resjunk);
500+
if (tent->resjunk)
501+
return false;
502+
497503
collation = exprCollation((Node *) tent->expr);
498504
/* collation doesn't change if it's converted to array */
499505
strength = COLLATE_IMPLICIT;

‎src/test/regress/expected/subselect.out

Copy file name to clipboardExpand all lines: src/test/regress/expected/subselect.out
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,3 +700,13 @@ explain (verbose, costs off)
700700
One-Time Filter: ("*VALUES*".column1 = "*VALUES*".column1)
701701
(8 rows)
702702

703+
--
704+
-- Check we behave sanely in corner case of empty SELECT list (bug #8648)
705+
--
706+
create temp table nocolumns();
707+
select exists(select * from nocolumns);
708+
exists
709+
--------
710+
f
711+
(1 row)
712+

‎src/test/regress/sql/subselect.sql

Copy file name to clipboardExpand all lines: src/test/regress/sql/subselect.sql
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,3 +405,9 @@ explain (verbose, costs off)
405405
explain (verbose, costs off)
406406
select x, x from
407407
(select (select random() where y=y) as x from (values(1),(2)) v(y)) ss;
408+
409+
--
410+
-- Check we behave sanely in corner case of empty SELECT list (bug #8648)
411+
--
412+
create temp table nocolumns();
413+
select exists(select * from nocolumns);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.