Re: strange explain

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Oleg Bartunov <oleg(at)sai(dot)msu(dot)su>
Cc: Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: strange explain
Date: 2002-05-13 14:04:50
Message-ID: 29086.1021298690@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Oleg Bartunov <oleg(at)sai(dot)msu(dot)su> writes:
> tour=# explain analyze select * from tours where
> ( operator_id in (2,3,4,5,7) and type_id = 2 ) or
> ( operator_id = 8 and type_id=4 );

> Index Scan using type_idx, type_idx, type_idx, type_idx, type_idx, type_idx on tours (cost=0.00..12.25 rows=1 width=1091) (actual time=0.26..0.26 rows=0 loops=1)

> What does many 'type_idx' means ?

Multiple indexscans.

It looks to me like your WHERE clause is being flattened into

( operator_id = 2 and type_id=2 ) or
( operator_id = 3 and type_id=2 ) or
( operator_id = 4 and type_id=2 ) or
( operator_id = 5 and type_id=2 ) or
( operator_id = 7 and type_id=2 ) or
( operator_id = 8 and type_id=4 )

and then it has a choice of repeated indexscans on operator_id or
type_id. Depending on the selectivity stats it might pick either.
You might find that a 2-column index on both would be a win.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Rod Taylor 2002-05-13 14:11:21 Re: Join of small table with large table
Previous Message Jason Tishler 2002-05-13 13:59:04 Re: Native Win32, How about this?