Re: [HACKERS] Index Puzzle for you - Mailing list pgsql-hackers

From Tom Lane
Subject Re: [HACKERS] Index Puzzle for you
Date
Msg-id 3226.946446552@sss.pgh.pa.us
Whole thread Raw
In response to Index Puzzle for you  (Kristofer Munn <kmunn@munn.com>)
Responses Re: [HACKERS] Index Puzzle for you
List pgsql-hackers
Kristofer Munn <kmunn@munn.com> writes:
> [ why does the second example not use an index? ]

> mail=> explain select 1 from tblissuearticle where ixissue = 7 
>     and ixarticle = 9;

> Index Scan using tblissuearticle_idx1 on tblissuearticle  
>     (cost=228.04 rows=1 width=0)

> mail=> explain select 1 from tblissuearticle where ixissue = 7;

> Seq Scan on tblissuearticle  (cost=4076.63 rows=76338 width=0)

The thing that jumps out at me from this example is the much larger
estimate of returned rows in the second case.  The planner is clearly
estimating that "ixissue = 7" alone is not very selective.  That might
or might not be reasonable (how many rows are in the table, and what's
the actual distribution of ixissue values?), but if it is reasonable
then a sequential scan might indeed be the right choice.  Index scans
are not always better than sequential scans --- the planner's job would
be far simpler if they were ;-)
        regards, tom lane


pgsql-hackers by date:

Previous
From: Kristofer Munn
Date:
Subject: Index Puzzle for you
Next
From: Kristofer Munn
Date:
Subject: Re: [HACKERS] Index Puzzle for you