Re: [HACKERS] choose_bitmap_and again (was Re: Strangely Variable Query Performance)

From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgreSQL(dot)org, PostgreSQL Performance <pgsql-performance(at)postgreSQL(dot)org>, Steve <cheetah(at)tanabi(dot)org>
Subject: Re: [HACKERS] choose_bitmap_and again (was Re: Strangely Variable Query Performance)
Date: 2007-04-13 23:24:09
Message-ID: 20070413232409.GI27255@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches pgsql-performance

Tom Lane wrote:

> One idea I thought about was to sort by index scan cost, using
> selectivity only as a tiebreaker for cost, rather than the other way
> around as is currently done. This seems fairly plausible because
> indexscans that are cheaper than other indexscans likely return fewer
> rows too, and so selectivity is already accounted for to some extent ---
> at least you can't have an enormously worse selectivity at lower cost,
> whereas Steve's example proves it doesn't work the other way. But I'm
> worried about breaking the reasoning about redundant indexes that's
> mentioned in the comments.
>
> Another alternative that would respond to the immediate problem is to
> maintain the current sort order, but as we come to each index, consider
> using that one alone, and throw away whatever AND we might have built up
> if that one alone beats the AND-so-far. This seems more conservative,
> as it's unlikely to break any cases that work well now, but on the other
> hand it feels like plastering another wart atop a structure that's
> already rather rickety.
>
> Has anyone got any thoughts about the best way to do this?

How about doing both: sort the index by index scan cost; then pick the
first index on the list and start adding indexes when they lower the
cost. When adding each index, consider it by itself against the
already stacked indexes. If the cost is lower, put this index at the
top of the list, and restart the algorithm (after the sorting step of
course).

I think the concern about condition redundancy should be attacked
separately. How about just comparing whether they have common prefixes
of conditions? I admit I don't understand what would happen with
indexes defined like (lower(A), B, C) versus (A, B) for example.

--
Alvaro Herrera http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2007-04-14 03:53:05 Re: build/install xml2 when configured with libxml
Previous Message Tom Lane 2007-04-13 22:48:21 choose_bitmap_and again (was Re: Strangely Variable Query Performance)

Browse pgsql-patches by date

  From Date Subject
Next Message Andrew Dunstan 2007-04-14 03:53:05 Re: build/install xml2 when configured with libxml
Previous Message Alvaro Herrera 2007-04-13 23:04:55 autovacuum multiworkers, patch 9

Browse pgsql-performance by date

  From Date Subject
Next Message Simon Riggs 2007-04-14 08:24:07 Re: choose_bitmap_and again (was Re: [PERFORM] StrangelyVariable Query Performance)
Previous Message Tom Lane 2007-04-13 22:48:21 choose_bitmap_and again (was Re: Strangely Variable Query Performance)