Remove the wrong assertion from match_orclause_to_indexcol()
authorAlexander Korotkov
Mon, 25 Nov 2024 07:05:26 +0000 (09:05 +0200)
committerAlexander Korotkov
Mon, 25 Nov 2024 07:07:30 +0000 (09:07 +0200)
Obviously, the constant could be zero.  Also, add the relevant check to
regression tests.

Reported-by: Richard Guo
Discussion: https://postgr.es/m/CAMbWs4-siKJdtWhcbqk4Y-xG12do2Ckm1qw672GNsSnDqL9FQg%40mail.gmail.com

src/backend/optimizer/path/indxpath.c
src/test/regress/expected/create_index.out
src/test/regress/sql/create_index.sql

index 5d8d0c389c909ce1c40879d6e86d3556fac15402..e50b6fd56a0e1d2c8260da611039a3666b90bcdb 100644 (file)
@@ -3430,7 +3430,7 @@ match_orclause_to_indexcol(PlannerInfo *root,
        elems = (Datum *) palloc(sizeof(Datum) * list_length(consts));
        foreach_node(Const, value, consts)
        {
-           Assert(!value->constisnull && value->constvalue);
+           Assert(!value->constisnull);
 
            elems[i++] = value->constvalue;
        }
index b003492c5c88c9df6ddeed041beb10997a6c48d9..1b0a5f0e9e1ac841a6b584fe4eef8e39c29e9a62 100644 (file)
@@ -1843,15 +1843,15 @@ DROP TABLE onek_with_null;
 --
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
-  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
-                                  QUERY PLAN                                  
-------------------------------------------------------------------------------
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42 OR tenthous = 0);
+                                   QUERY PLAN                                   
+--------------------------------------------------------------------------------
  Index Scan using tenk1_thous_tenthous on tenk1
-   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42}'::integer[])))
+   Index Cond: ((thousand = 42) AND (tenthous = ANY ('{1,3,42,0}'::integer[])))
 (2 rows)
 
 SELECT * FROM tenk1
-  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42 OR tenthous = 0);
  unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 
 ---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
       42 |    5530 |   0 |    2 |   2 |      2 |      42 |       42 |          42 |        42 |       42 |  84 |   85 | QBAAAA   | SEIAAA   | OOOOxx
index 216bd9660c38e790c0f74d6ec2a3bb0484c6ee91..ddd0d9ad396912457334843055b225edc75435a9 100644 (file)
@@ -728,9 +728,9 @@ DROP TABLE onek_with_null;
 
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1
-  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42 OR tenthous = 0);
 SELECT * FROM tenk1
-  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42);
+  WHERE thousand = 42 AND (tenthous = 1 OR tenthous = 3 OR tenthous = 42 OR tenthous = 0);
 
 EXPLAIN (COSTS OFF)
 SELECT * FROM tenk1