Teach hash_ok_operator() that record_eq is only sometimes hashable.
authorTom Lane <tgl@sss.pgh.pa.us>
Sun, 16 Jan 2022 21:39:26 +0000 (16:39 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Sun, 16 Jan 2022 21:39:26 +0000 (16:39 -0500)
The need for this was foreseen long ago, but when record_eq
actually became hashable (in commit 01e658fa7), we missed updating
this spot.

Per bug #17363 from Elvis Pranskevichus.  Back-patch to v14 where
the faulty commit came in.

Discussion: https://postgr.es/m/17363-f6d42fd0d726be02@postgresql.org

src/backend/optimizer/plan/subselect.c
src/test/regress/expected/subselect.out
src/test/regress/sql/subselect.sql

index 8c9408d372daa8aeddb890abde09227b93bb273f..41bd1ae7d44484a363e4b8fcf4c24906e3411533 100644 (file)
@@ -848,10 +848,10 @@ hash_ok_operator(OpExpr *expr)
    /* quick out if not a binary operator */
    if (list_length(expr->args) != 2)
        return false;
-   if (opid == ARRAY_EQ_OP)
+   if (opid == ARRAY_EQ_OP ||
+       opid == RECORD_EQ_OP)
    {
-       /* array_eq is strict, but must check input type to ensure hashable */
-       /* XXX record_eq will need same treatment when it becomes hashable */
+       /* these are strict, but must check input type to ensure hashable */
        Node       *leftarg = linitial(expr->args);
 
        return op_hashjoinable(opid, exprType(leftarg));
index 4e8ddc70613a98d639e4dd2e2dd27e3f9249fdbb..45c75eecc5f2e836aa56b117d8b6092e9a7ae595 100644 (file)
@@ -789,6 +789,29 @@ select 'foo'::text in (select 'bar'::name union all select 'bar'::name);
  f
 (1 row)
 
+--
+-- Test that we don't try to hash nested records (bug #17363)
+-- (Hashing could be supported, but for now we don't)
+--
+explain (verbose, costs off)
+select row(row(row(1))) = any (select row(row(1)));
+                QUERY PLAN                 
+-------------------------------------------
+ Result
+   Output: (SubPlan 1)
+   SubPlan 1
+     ->  Materialize
+           Output: '("(1)")'::record
+           ->  Result
+                 Output: '("(1)")'::record
+(7 rows)
+
+select row(row(row(1))) = any (select row(row(1)));
+ ?column? 
+----------
+ t
+(1 row)
+
 --
 -- Test case for premature memory release during hashing of subplan output
 --
index e879999708bfa6355cd18cdc12e2ef8e0fa9e46b..94ba91f5bb35f65a582f52a0b115368795aa07d7 100644 (file)
@@ -463,6 +463,16 @@ select 'foo'::text in (select 'bar'::name union all select 'bar'::name);
 
 select 'foo'::text in (select 'bar'::name union all select 'bar'::name);
 
+--
+-- Test that we don't try to hash nested records (bug #17363)
+-- (Hashing could be supported, but for now we don't)
+--
+
+explain (verbose, costs off)
+select row(row(row(1))) = any (select row(row(1)));
+
+select row(row(row(1))) = any (select row(row(1)));
+
 --
 -- Test case for premature memory release during hashing of subplan output
 --