Re: strange explain

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

Tom,

one more question.

What's the difference for planner between 2 queries ?
For the first query I have plain index scan, but multiple
index scan for second.

tour=# explain analyze select * from tours where
( operator_id in (2,3,4,5,7) and type_id = 2 );
NOTICE: QUERY PLAN:

Index Scan using type_idx on tours (cost=0.00..2.03 rows=1 width=1091) (actual time=0.03..0.03 rows=0 loops=1)
Total runtime: 0.16 msec

EXPLAIN
tour=# explain analyze select * from tours where
( operator_id in (2,3,4,5,7) and type_id = 4 ) or
( operator_id = 8 and type_id = 3);
NOTICE: QUERY PLAN:

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.27..0.27 rows=0 loops=1)
Total runtime: 0.44 msec

EXPLAIN

On Mon, 13 May 2002, Tom Lane wrote:

> 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
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly
>

Regards,
Oleg
_____________________________________________________________
Oleg Bartunov, sci.researcher, hostmaster of AstroNet,
Sternberg Astronomical Institute, Moscow University (Russia)
Internet: oleg(at)sai(dot)msu(dot)su, http://www.sai.msu.su/~megera/
phone: +007(095)939-16-83, +007(095)939-23-83

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2002-05-13 17:10:23 Re: strange explain
Previous Message Stephan Szabo 2002-05-13 16:09:39 Re: Join of small table with large table