diff --git a/src/backend/optimizer/path/equivclass.c b/src/backend/optimizer/path/equivclass.c index 0e50ad5f34..503246f96d 100644 --- a/src/backend/optimizer/path/equivclass.c +++ b/src/backend/optimizer/path/equivclass.c @@ -424,8 +424,9 @@ canonicalize_ec_expression(Expr *expr, Oid req_type, Oid req_collation) /* * For a polymorphic-input-type opclass, just keep the same exposed type. + * RECORD opclasses work like polymorphic-type ones for this purpose. */ - if (IsPolymorphicType(req_type)) + if (IsPolymorphicType(req_type) || req_type == RECORDOID) req_type = expr_type; /* diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out index ae760e6142..4f016b6c05 100644 --- a/src/test/regress/expected/join.out +++ b/src/test/regress/expected/join.out @@ -2650,6 +2650,36 @@ select * from a left join b on i = x and i = y and x = i; ---+---+--- (0 rows) +rollback; +-- +-- test handling of merge clauses using record_ops +-- +begin; +create type mycomptype as (id int, v bigint); +create temp table tidv (idv mycomptype); +create index on tidv (idv); +explain (costs off) +select a.idv, b.idv from tidv a, tidv b where a.idv = b.idv; + QUERY PLAN +---------------------------------------------------------- + Merge Join + Merge Cond: (a.idv = b.idv) + -> Index Only Scan using tidv_idv_idx on tidv a + -> Materialize + -> Index Only Scan using tidv_idv_idx on tidv b +(5 rows) + +set enable_mergejoin = 0; +explain (costs off) +select a.idv, b.idv from tidv a, tidv b where a.idv = b.idv; + QUERY PLAN +---------------------------------------------------- + Nested Loop + -> Seq Scan on tidv a + -> Index Only Scan using tidv_idv_idx on tidv b + Index Cond: (idv = a.idv) +(4 rows) + rollback; -- -- test NULL behavior of whole-row Vars, per bug #5025 diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql index 174eec0ba4..8f1698648c 100644 --- a/src/test/regress/sql/join.sql +++ b/src/test/regress/sql/join.sql @@ -664,6 +664,26 @@ select * from a left join b on i = x and i = y and x = i; rollback; +-- +-- test handling of merge clauses using record_ops +-- +begin; + +create type mycomptype as (id int, v bigint); + +create temp table tidv (idv mycomptype); +create index on tidv (idv); + +explain (costs off) +select a.idv, b.idv from tidv a, tidv b where a.idv = b.idv; + +set enable_mergejoin = 0; + +explain (costs off) +select a.idv, b.idv from tidv a, tidv b where a.idv = b.idv; + +rollback; + -- -- test NULL behavior of whole-row Vars, per bug #5025 --