pgsql: Fix convert_IN_to_join to properly handle the case where the

From: tgl(at)postgresql(dot)org (Tom Lane)
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Fix convert_IN_to_join to properly handle the case where the
Date: 2008-04-21 20:54:24
Message-ID: 20080421205424.588327559CC@cvs.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Log Message:
-----------
Fix convert_IN_to_join to properly handle the case where the subselect's
output is not of the same type that's needed for the IN comparison (ie,
where the parser inserted an implicit coercion above the subselect result).
We should record the coerced expression, not just a raw Var referencing
the subselect output, as the quantity that needs to be unique-ified if
we choose to implement the IN as Unique followed by a plain join.

As of 8.3 this error was causing crashes, as seen in bug #4113 from Javier
Hernandez, because the executor was being told to hash or sort the raw
subselect output column using operators appropriate to the coerced type.

In prior versions there was no crash because the executor chose the
hash or sort operators for itself based on the column type it saw.
However, that's still not really right, because what's unique for one data
type might not be unique for another. In corner cases we could get multiple
outputs of a row that should appear only once, as demonstrated by the
regression test case included in this commit.

However, this patch doesn't apply cleanly to 8.2 or before, and the code
involved has shifted enough over time that I'm hesitant to try to back-patch.
Given the lack of complaints from the field about such corner cases, I think
the bug may not be important enough to risk breaking other things with a
back-patch.

Tags:
----
REL8_3_STABLE

Modified Files:
--------------
pgsql/src/backend/optimizer/plan:
subselect.c (r1.129 -> r1.129.2.1)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/optimizer/plan/subselect.c?r1=1.129&r2=1.129.2.1)
pgsql/src/backend/optimizer/util:
pathnode.c (r1.142 -> r1.142.2.1)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/optimizer/util/pathnode.c?r1=1.142&r2=1.142.2.1)
pgsql/src/include/nodes:
relation.h (r1.154.2.1 -> r1.154.2.2)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/include/nodes/relation.h?r1=1.154.2.1&r2=1.154.2.2)
pgsql/src/test/regress/expected:
subselect.out (r1.16 -> r1.16.2.1)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/test/regress/expected/subselect.out?r1=1.16&r2=1.16.2.1)
pgsql/src/test/regress/sql:
subselect.sql (r1.11 -> r1.11.2.1)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/test/regress/sql/subselect.sql?r1=1.11&r2=1.11.2.1)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2008-04-22 01:34:34 pgsql: Issue explicit error messages for attempts to use "shell"
Previous Message Tom Lane 2008-04-21 20:54:15 pgsql: Fix convert_IN_to_join to properly handle the case where the