pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Arjen van der Meijden <acmmailing@tweakers.net>
Cc: Jim C. Nasby <jim@nasby.net>
Cc: pgsql-performance@postgresql.org
Subject: Re: 8.2rc1 (much) slower than 8.2dev?
Date: Thu, 07 Dec 2006 10:38:10 -0500
Message-ID: <15452.1165505890@sss.pgh.pa.us> (raw)
In-Reply-To: <4577DB2D.6090205@tweakers.net>
References: <4573D1F7.600@tweakers.net>
	<16696.1165244024@sss.pgh.pa.us>
	<45744FAA.20603@tweakers.net>
	<20061207060133.GU44124@nasby.net>
	<4577DB2D.6090205@tweakers.net>

Arjen van der Meijden <acmmailing@tweakers.net> writes:
> I've been mailing off-list with Tom and we found at least one 
> query that in some circumstances takes a lot more time than it should, 
> due to it mistakenly chosing to do a bitmap index scan rather than a 
> normal index scan.

Just to clue folks in: the problem queries seem to be cases like

  WHERE col1 = 'const'
        AND col2 = othertab.colx
        AND col3 IN (several hundred integers)

where the table has an index on (col1,col2,col3).  8.2 is generating
a plan involving a nestloop with inner bitmap indexscan on this index,
and using all three of these WHERE clauses with the index.  The ability
to use an IN clause (ie, ScalarArrayOpExpr) in an index condition is
new in 8.2, and we seem to have a few bugs left in the cost estimation
for it.  The problem is that a ScalarArrayOpExpr effectively causes a
BitmapOr across N index scans using each of the array elements as an
individual scan qualifier.  So the above amounts to several hundred
index probes for each outer row.  In Arjen's scenario it seems that
the first two index columns are already pretty selective, and it comes
out a lot faster if you just do one indexscan using the first two
columns and then apply the IN-condition as a filter to the relatively
small number of rows you get that way.

What's not clear to me yet is why the 8.2dev code didn't fall into this
same trap, because the ScalarArrayOpExpr indexing code was already there
on 3-June.  But we didn't and still don't have any code that considers
the possibility that a potential indexqual condition should be
deliberately *not* used with the index.

			regards, tom lane



view thread (7+ messages)  latest in thread

Message-ID: <15452.1165505890@sss.pgh.pa.us>
Permalink:  ../15452.1165505890@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/15452.1165505890@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: tgl@sss.pgh.pa.us, acmmailing@tweakers.net, jim@nasby.net
  Subject: Re: 8.2rc1 (much) slower than 8.2dev?
  In-Reply-To: <15452.1165505890@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox