Index scans when bitmap scans disabled

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Index scans when bitmap scans disabled
Date: 2006-04-24 02:02:05
Message-ID: 20060424020205.GA74180@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Is it expected that the planner in 8.1.3 (CVS) and HEAD doesn't use
an index scan for the second query below when bitmap scans are
disabled? Disabling sequential scans as well results in the planner
using a bitmap scan.

test=> CREATE TABLE foo (id integer PRIMARY KEY);
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "foo_pkey" for table "foo"
CREATE TABLE
test=> INSERT INTO foo SELECT * FROM generate_series(1, 100000);
INSERT 0 100000
test=> ANALYZE foo;
ANALYZE
test=> SET enable_bitmapscan TO off;
SET
test=> EXPLAIN SELECT * FROM foo WHERE id IN (1);
QUERY PLAN
--------------------------------------------------------------------
Index Scan using foo_pkey on foo (cost=0.00..3.01 rows=1 width=4)
Index Cond: (id = 1)
(2 rows)

test=> EXPLAIN SELECT * FROM foo WHERE id IN (1, 2);
QUERY PLAN
------------------------------------------------------
Seq Scan on foo (cost=0.00..2041.00 rows=2 width=4)
Filter: ((id = 1) OR (id = 2))
(2 rows)

test=> SET enable_seqscan TO off;
SET
test=> EXPLAIN SELECT * FROM foo WHERE id IN (1, 2);
QUERY PLAN
-----------------------------------------------------------------------------
Bitmap Heap Scan on foo (cost=100000004.01..100000008.03 rows=2 width=4)
Recheck Cond: ((id = 1) OR (id = 2))
-> BitmapOr (cost=4.01..4.01 rows=2 width=0)
-> Bitmap Index Scan on foo_pkey (cost=0.00..2.00 rows=1 width=0)
Index Cond: (id = 1)
-> Bitmap Index Scan on foo_pkey (cost=0.00..2.00 rows=1 width=0)
Index Cond: (id = 2)
(7 rows)

Here's the same query in 8.0.7:

test=> EXPLAIN SELECT * FROM foo WHERE id IN (1, 2);
QUERY PLAN
------------------------------------------------------------------------------
Index Scan using foo_pkey, foo_pkey on foo (cost=0.00..6.03 rows=2 width=4)
Index Cond: ((id = 1) OR (id = 2))
(2 rows)

--
Michael Fuhr

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Qingqing Zhou 2006-04-24 02:23:07 Re: Unresolved Win32 bug reports
Previous Message Alvaro Herrera 2006-04-24 01:41:30 Re: Can't commit due to perl upgrade