pgsql: Fix misprocessing of equivalence classes involving record_eq().

2018-05-16 Thread Tom Lane
Fix misprocessing of equivalence classes involving record_eq().

canonicalize_ec_expression() is supposed to agree with coerce_type() as to
whether a RelabelType should be inserted to make a subexpression be valid
input for the operators of a given opclass.  However, it did the wrong
thing with named-composite-type inputs to record_eq(): it put in a
RelabelType to RECORDOID, which the parser doesn't.  In some cases this was
harmless because all code paths involving a particular equivalence class
did the same thing, but in other cases this would result in failing to
recognize a composite-type expression as being a member of an equivalence
class that it actually is a member of.  The most obvious bad effect was to
fail to recognize that an index on a composite column could provide the
sort order needed for a mergejoin on that column, as reported by Teodor
Sigaev.  I think there might be other, subtler, cases that result in
misoptimization.  It also seems possible that an unwanted RelabelType
would sometimes get into an emitted plan --- but because record_eq and
friends don't examine the declared type of their input expressions, that
would not create any visible problems.

To fix, just treat RECORDOID as if it were a polymorphic type, which in
some sense it is.  We might want to consider formalizing that a bit more
someday, but for the moment this seems to be the only place where an
IsPolymorphicType() test ought to include RECORDOID as well.

This has been broken for a long time, so back-patch to all supported
branches.

Discussion: https://postgr.es/m/a6b22369-e3bf-4d49-f59d-0c41d3551...@sigaev.ru

Branch
--
REL9_4_STABLE

Details
---
https://git.postgresql.org/pg/commitdiff/62e0020ad4914899d416edaa7d676499afcdc113

Modified Files
--
src/backend/optimizer/path/equivclass.c |  3 ++-
src/test/regress/expected/join.out  | 30 ++
src/test/regress/sql/join.sql   | 20 
3 files changed, 52 insertions(+), 1 deletion(-)



pgsql: Fix misprocessing of equivalence classes involving record_eq().

2018-05-16 Thread Tom Lane
Fix misprocessing of equivalence classes involving record_eq().

canonicalize_ec_expression() is supposed to agree with coerce_type() as to
whether a RelabelType should be inserted to make a subexpression be valid
input for the operators of a given opclass.  However, it did the wrong
thing with named-composite-type inputs to record_eq(): it put in a
RelabelType to RECORDOID, which the parser doesn't.  In some cases this was
harmless because all code paths involving a particular equivalence class
did the same thing, but in other cases this would result in failing to
recognize a composite-type expression as being a member of an equivalence
class that it actually is a member of.  The most obvious bad effect was to
fail to recognize that an index on a composite column could provide the
sort order needed for a mergejoin on that column, as reported by Teodor
Sigaev.  I think there might be other, subtler, cases that result in
misoptimization.  It also seems possible that an unwanted RelabelType
would sometimes get into an emitted plan --- but because record_eq and
friends don't examine the declared type of their input expressions, that
would not create any visible problems.

To fix, just treat RECORDOID as if it were a polymorphic type, which in
some sense it is.  We might want to consider formalizing that a bit more
someday, but for the moment this seems to be the only place where an
IsPolymorphicType() test ought to include RECORDOID as well.

This has been broken for a long time, so back-patch to all supported
branches.

Discussion: https://postgr.es/m/a6b22369-e3bf-4d49-f59d-0c41d3551...@sigaev.ru

Branch
--
REL9_6_STABLE

Details
---
https://git.postgresql.org/pg/commitdiff/ace3c7cc0518269733c37b37b7aebb9adec2454e

Modified Files
--
src/backend/optimizer/path/equivclass.c |  3 ++-
src/test/regress/expected/join.out  | 30 ++
src/test/regress/sql/join.sql   | 20 
3 files changed, 52 insertions(+), 1 deletion(-)



pgsql: Fix misprocessing of equivalence classes involving record_eq().

2018-05-16 Thread Tom Lane
Fix misprocessing of equivalence classes involving record_eq().

canonicalize_ec_expression() is supposed to agree with coerce_type() as to
whether a RelabelType should be inserted to make a subexpression be valid
input for the operators of a given opclass.  However, it did the wrong
thing with named-composite-type inputs to record_eq(): it put in a
RelabelType to RECORDOID, which the parser doesn't.  In some cases this was
harmless because all code paths involving a particular equivalence class
did the same thing, but in other cases this would result in failing to
recognize a composite-type expression as being a member of an equivalence
class that it actually is a member of.  The most obvious bad effect was to
fail to recognize that an index on a composite column could provide the
sort order needed for a mergejoin on that column, as reported by Teodor
Sigaev.  I think there might be other, subtler, cases that result in
misoptimization.  It also seems possible that an unwanted RelabelType
would sometimes get into an emitted plan --- but because record_eq and
friends don't examine the declared type of their input expressions, that
would not create any visible problems.

To fix, just treat RECORDOID as if it were a polymorphic type, which in
some sense it is.  We might want to consider formalizing that a bit more
someday, but for the moment this seems to be the only place where an
IsPolymorphicType() test ought to include RECORDOID as well.

This has been broken for a long time, so back-patch to all supported
branches.

Discussion: https://postgr.es/m/a6b22369-e3bf-4d49-f59d-0c41d3551...@sigaev.ru

Branch
--
REL_10_STABLE

Details
---
https://git.postgresql.org/pg/commitdiff/aada0a7648e220d6e7a852e827b0d66d04280aed

Modified Files
--
src/backend/optimizer/path/equivclass.c |  3 ++-
src/test/regress/expected/join.out  | 30 ++
src/test/regress/sql/join.sql   | 20 
3 files changed, 52 insertions(+), 1 deletion(-)



pgsql: Fix misprocessing of equivalence classes involving record_eq().

2018-05-16 Thread Tom Lane
Fix misprocessing of equivalence classes involving record_eq().

canonicalize_ec_expression() is supposed to agree with coerce_type() as to
whether a RelabelType should be inserted to make a subexpression be valid
input for the operators of a given opclass.  However, it did the wrong
thing with named-composite-type inputs to record_eq(): it put in a
RelabelType to RECORDOID, which the parser doesn't.  In some cases this was
harmless because all code paths involving a particular equivalence class
did the same thing, but in other cases this would result in failing to
recognize a composite-type expression as being a member of an equivalence
class that it actually is a member of.  The most obvious bad effect was to
fail to recognize that an index on a composite column could provide the
sort order needed for a mergejoin on that column, as reported by Teodor
Sigaev.  I think there might be other, subtler, cases that result in
misoptimization.  It also seems possible that an unwanted RelabelType
would sometimes get into an emitted plan --- but because record_eq and
friends don't examine the declared type of their input expressions, that
would not create any visible problems.

To fix, just treat RECORDOID as if it were a polymorphic type, which in
some sense it is.  We might want to consider formalizing that a bit more
someday, but for the moment this seems to be the only place where an
IsPolymorphicType() test ought to include RECORDOID as well.

This has been broken for a long time, so back-patch to all supported
branches.

Discussion: https://postgr.es/m/a6b22369-e3bf-4d49-f59d-0c41d3551...@sigaev.ru

Branch
--
REL9_5_STABLE

Details
---
https://git.postgresql.org/pg/commitdiff/6d7629094a527bd33f38426b012172cfc9e02e44

Modified Files
--
src/backend/optimizer/path/equivclass.c |  3 ++-
src/test/regress/expected/join.out  | 30 ++
src/test/regress/sql/join.sql   | 20 
3 files changed, 52 insertions(+), 1 deletion(-)



pgsql: Fix misprocessing of equivalence classes involving record_eq().

2018-05-16 Thread Tom Lane
Fix misprocessing of equivalence classes involving record_eq().

canonicalize_ec_expression() is supposed to agree with coerce_type() as to
whether a RelabelType should be inserted to make a subexpression be valid
input for the operators of a given opclass.  However, it did the wrong
thing with named-composite-type inputs to record_eq(): it put in a
RelabelType to RECORDOID, which the parser doesn't.  In some cases this was
harmless because all code paths involving a particular equivalence class
did the same thing, but in other cases this would result in failing to
recognize a composite-type expression as being a member of an equivalence
class that it actually is a member of.  The most obvious bad effect was to
fail to recognize that an index on a composite column could provide the
sort order needed for a mergejoin on that column, as reported by Teodor
Sigaev.  I think there might be other, subtler, cases that result in
misoptimization.  It also seems possible that an unwanted RelabelType
would sometimes get into an emitted plan --- but because record_eq and
friends don't examine the declared type of their input expressions, that
would not create any visible problems.

To fix, just treat RECORDOID as if it were a polymorphic type, which in
some sense it is.  We might want to consider formalizing that a bit more
someday, but for the moment this seems to be the only place where an
IsPolymorphicType() test ought to include RECORDOID as well.

This has been broken for a long time, so back-patch to all supported
branches.

Discussion: https://postgr.es/m/a6b22369-e3bf-4d49-f59d-0c41d3551...@sigaev.ru

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/a11b3bd37f14386310f25e89529bd3de8cd64383

Modified Files
--
src/backend/optimizer/path/equivclass.c |  3 ++-
src/test/regress/expected/join.out  | 30 ++
src/test/regress/sql/join.sql   | 20 
3 files changed, 52 insertions(+), 1 deletion(-)



pgsql: Fix misprocessing of equivalence classes involving record_eq().

2018-05-16 Thread Tom Lane
Fix misprocessing of equivalence classes involving record_eq().

canonicalize_ec_expression() is supposed to agree with coerce_type() as to
whether a RelabelType should be inserted to make a subexpression be valid
input for the operators of a given opclass.  However, it did the wrong
thing with named-composite-type inputs to record_eq(): it put in a
RelabelType to RECORDOID, which the parser doesn't.  In some cases this was
harmless because all code paths involving a particular equivalence class
did the same thing, but in other cases this would result in failing to
recognize a composite-type expression as being a member of an equivalence
class that it actually is a member of.  The most obvious bad effect was to
fail to recognize that an index on a composite column could provide the
sort order needed for a mergejoin on that column, as reported by Teodor
Sigaev.  I think there might be other, subtler, cases that result in
misoptimization.  It also seems possible that an unwanted RelabelType
would sometimes get into an emitted plan --- but because record_eq and
friends don't examine the declared type of their input expressions, that
would not create any visible problems.

To fix, just treat RECORDOID as if it were a polymorphic type, which in
some sense it is.  We might want to consider formalizing that a bit more
someday, but for the moment this seems to be the only place where an
IsPolymorphicType() test ought to include RECORDOID as well.

This has been broken for a long time, so back-patch to all supported
branches.

Discussion: https://postgr.es/m/a6b22369-e3bf-4d49-f59d-0c41d3551...@sigaev.ru

Branch
--
REL9_3_STABLE

Details
---
https://git.postgresql.org/pg/commitdiff/bc711befd6ce24033175584f900e0cf43af81f5c

Modified Files
--
src/backend/optimizer/path/equivclass.c |  3 ++-
src/test/regress/expected/join.out  | 30 ++
src/test/regress/sql/join.sql   | 20 
3 files changed, 52 insertions(+), 1 deletion(-)