Bug: When user-defined AM is used, the index path cannot be selected correctly

Quan Zongliang <quanzongliang@yeah.net>

From: Quan Zongliang <quanzongliang@yeah.net>
To: pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2022-08-17T01:43:54Z
Lists: pgsql-hackers

Attachments

Hi,

1. When using extended PGroonga

CREATE EXTENSION pgroonga;

CREATE TABLE memos (
   id boolean,
   content varchar
);

CREATE INDEX idxA ON memos USING pgroonga (id);

2. Disable bitmapscan and seqscan:

SET enable_seqscan=off;
SET enable_indexscan=on;
SET enable_bitmapscan=off;

3. Neither ID = 'f' nor id= 't' can use the index correctly.

postgres=# explain select * from memos where id='f';
                                 QUERY PLAN
--------------------------------------------------------------------------
  Seq Scan on memos  (cost=10000000000.00..10000000001.06 rows=3 width=33)
    Filter: (NOT id)
(2 rows)

postgres=# explain select * from memos where id='t';
                                 QUERY PLAN
--------------------------------------------------------------------------
  Seq Scan on memos  (cost=10000000000.00..10000000001.06 rows=3 width=33)
    Filter: id
(2 rows)

postgres=# explain select * from memos where id>='t';
                             QUERY PLAN
-------------------------------------------------------------------
  Index Scan using idxa on memos  (cost=0.00..4.01 rows=2 width=33)
    Index Cond: (id >= true)
(2 rows)



The reason is that these expressions are converted to BoolExpr and Var.
match_clause_to_indexcol does not use them to check boolean-index.

patch attached.

--
Quan Zongliang
Beijing Vastdata

Commits

  1. Fix planner to consider matches to boolean columns in extension indexes.