Unix Technical Forum

BUG #2441: All useable indexes for an IN are used, not just one

This is a discussion on BUG #2441: All useable indexes for an IN are used, not just one within the pgsql Bugs forums, part of the PostgreSQL category; --> The following bug has been logged online: Bug reference: 2441 Logged by: Arjen van der Meijden Email address: acmmailing@tweakers.net ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Bugs

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-10-2008, 11:00 AM
Arjen van der Meijden
 
Posts: n/a
Default BUG #2441: All useable indexes for an IN are used, not just one


The following bug has been logged online:

Bug reference: 2441
Logged by: Arjen van der Meijden
Email address: acmmailing@tweakers.net
PostgreSQL version: 8.2devel, 05-16
Operating system: Solaris 10
Description: All useable indexes for an IN are used, not just one
Details:

Using this table:
Column | Type | Modifiers
------------+---------+-----------
field1 | integer |
somefk | integer |
someswitch | boolean |
somefield | integer |
Indexes:
"testcase_1" btree (somefk)
"testcase_2" btree (somefk) WHERE someswitch
"testcase_3" btree (somefk, somefield)


filled with enough data to have it use indexes, it yields a plan involving
all three indexes with this query:

select * from testcase where somefk in (1, 2) and someswitch;

Bitmap Heap Scan on testcase (cost=7.43..330.58 rows=136 width=13)
Recheck Cond: ((somefk = ANY ('{1,2}'::integer[])) OR (somefk = ANY
('{1,2}'::integer[])) OR (somefk = ANY ('{1,2}'::integer[])))
Filter: ((somefk = ANY ('{1,2}'::integer[])) AND someswitch)
-> BitmapOr (cost=7.43..7.43 rows=410 width=0)
-> Bitmap Index Scan on testcase_3 (cost=0.00..2.48 rows=137
width=0)
Index Cond: (somefk = ANY ('{1,2}'::integer[]))
-> Bitmap Index Scan on testcase_2 (cost=0.00..2.48 rows=136
width=0)
Index Cond: (somefk = ANY ('{1,2}'::integer[]))
-> Bitmap Index Scan on testcase_1 (cost=0.00..2.48 rows=137
width=0)
Index Cond: (somefk = ANY ('{1,2}'::integer[]))


If the in-condition is changed to just one item, only one index is used.
Btw, it doesn't matter whether the indexes are exact copies, nor does the
boolean where-clause matter, I just added that to display all useable
indexes are involved in the bitmapOr. If you'd leave out the boolean switch,
the plan only shows two indexes used.

---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-10-2008, 11:00 AM
Tom Lane
 
Posts: n/a
Default Re: BUG #2441: All useable indexes for an IN are used, not just one

"Arjen van der Meijden" <acmmailing@tweakers.net> writes:
> filled with enough data to have it use indexes, it yields a plan involving
> all three indexes with this query:


> select * from testcase where somefk in (1, 2) and someswitch;


> Bitmap Heap Scan on testcase (cost=7.43..330.58 rows=136 width=13)
> Recheck Cond: ((somefk = ANY ('{1,2}'::integer[])) OR (somefk = ANY
> ('{1,2}'::integer[])) OR (somefk = ANY ('{1,2}'::integer[])))
> Filter: ((somefk = ANY ('{1,2}'::integer[])) AND someswitch)
> -> BitmapOr (cost=7.43..7.43 rows=410 width=0)
> -> Bitmap Index Scan on testcase_3 (cost=0.00..2.48 rows=137
> width=0)
> Index Cond: (somefk = ANY ('{1,2}'::integer[]))
> -> Bitmap Index Scan on testcase_2 (cost=0.00..2.48 rows=136
> width=0)
> Index Cond: (somefk = ANY ('{1,2}'::integer[]))
> -> Bitmap Index Scan on testcase_1 (cost=0.00..2.48 rows=137
> width=0)
> Index Cond: (somefk = ANY ('{1,2}'::integer[]))


Thanks for the report. I've applied patches to improve this.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 04:39 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com