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
diff --git a/src/backend/optimizer/path/indxpath.c 
b/src/backend/optimizer/path/indxpath.c
index 7d176e7b00..31229ce16c 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -2295,7 +2295,7 @@ match_clause_to_indexcol(PlannerInfo *root,
 
        /* First check for boolean-index cases. */
        opfamily = index->opfamily[indexcol];
-       if (IsBooleanOpfamily(opfamily))
+       if (IsBooleanOpfamily(opfamily) || IsA(clause, BoolExpr) || IsA(clause, 
Var))
        {
                iclause = match_boolean_index_clause(root, rinfo, indexcol, 
index);
                if (iclause)

Reply via email to