pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
1-/2-dimensional indexes for common columns, rationale?
7+ messages / 5 participants
[nested] [flat]

* 1-/2-dimensional indexes for common columns, rationale?
@ 2008-03-26 14:18  Marinos Yannikos <mjy@geizhals.at>
  0 siblings, 1 reply; 7+ messages in thread

From: Marinos Yannikos @ 2008-03-26 14:18 UTC (permalink / raw)
  To: pgsql-performance

Hello,

we have several indexes such as:

create index foo1 on bla (a);
create index foo2 on bla (b);
create index foo3 on bla (a,b);

They are all used often by frequently used queries (according to 
pg_statio_user_indexes), but we need somewhat higher INSERT/UPDATE 
performance (having tuned most other things) so we'd like to remove some.

Which of the above would generally speaking be most redundant / best to 
remove? Is a 2-dimensional index always much slower than a 1-dimensional 
with the first column for queries on the first column? Any other 
suggestions?

Thanks,
  Marinos




^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: 1-/2-dimensional indexes for common columns, rationale?
@ 2008-03-26 15:02  A. Kretschmer <andreas.kretschmer@schollglas.com>
  parent: Marinos Yannikos <mjy@geizhals.at>
  0 siblings, 2 replies; 7+ messages in thread

From: A. Kretschmer @ 2008-03-26 15:02 UTC (permalink / raw)
  To: pgsql-performance

am  Wed, dem 26.03.2008, um 15:18:53 +0100 mailte Marinos Yannikos folgendes:
> Hello,
> 
> we have several indexes such as:
> 
> create index foo1 on bla (a);
> create index foo2 on bla (b);
> create index foo3 on bla (a,b);
> 
> They are all used often by frequently used queries (according to 
> pg_statio_user_indexes), but we need somewhat higher INSERT/UPDATE 
> performance (having tuned most other things) so we'd like to remove some.

Which version do you have? Since 8.1 pg can use a so called 'bitmap
index scan', because of this feature i guess you don't need the index
foo3. (if you have 8.1 or higher)


Andreas
-- 
Andreas Kretschmer
Kontakt:  Heynitz: 035242/47150,   D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID:   0x3FFF606C, privat 0x7F4584DA   http://wwwkeys.de.pgp.net



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: 1-/2-dimensional indexes for common columns, rationale?
@ 2008-03-26 15:15  Marinos Yannikos <mjy@geizhals.at>
  parent: A. Kretschmer <andreas.kretschmer@schollglas.com>
  1 sibling, 2 replies; 7+ messages in thread

From: Marinos Yannikos @ 2008-03-26 15:15 UTC (permalink / raw)
  To: pgsql-performance

A. Kretschmer schrieb:
>> create index foo1 on bla (a);
>> create index foo2 on bla (b);
>> create index foo3 on bla (a,b);
>>[...]
> 
> Which version do you have? Since 8.1 pg can use a so called 'bitmap
> index scan', because of this feature i guess you don't need the index
> foo3. (if you have 8.1 or higher)

8.3.1 - foo3 is being used though in presence of both foo1 and foo2, so 
I'd suppose that it's a better choice even with bitmap index scan 
available...

-mjy





^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: 1-/2-dimensional indexes for common columns, rationale?
@ 2008-03-26 15:16  Matthew <matthew@flymine.org>
  parent: A. Kretschmer <andreas.kretschmer@schollglas.com>
  1 sibling, 1 reply; 7+ messages in thread

From: Matthew @ 2008-03-26 15:16 UTC (permalink / raw)
  To: pgsql-performance

On Wed, 26 Mar 2008, A. Kretschmer wrote:
>> create index foo1 on bla (a);
>> create index foo2 on bla (b);
>> create index foo3 on bla (a,b);
>
> Which version do you have? Since 8.1 pg can use a so called 'bitmap
> index scan', because of this feature i guess you don't need the index
> foo3. (if you have 8.1 or higher)

Depending on your query, the bitmap index scan could be a good deal slower 
than index foo3.

All of this depends on what queries you are going to be running, and how 
much you value insert performance compared to select performance. I know 
that foo3 can do everything that foo1 can, so foo1 could be viewed as 
redundant. I'd be interested in hearing from the Powers That Be whether 
foo2 is redundant too. It wasn't a while back.

My impression is that foo3 isn't much more expensive to alter than foo1 - 
is that correct?

Matthew

-- 
Lord grant me patience, and I want it NOW!



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: 1-/2-dimensional indexes for common columns, rationale?
@ 2008-03-26 15:25  A. Kretschmer <andreas.kretschmer@schollglas.com>
  parent: Marinos Yannikos <mjy@geizhals.at>
  1 sibling, 0 replies; 7+ messages in thread

From: A. Kretschmer @ 2008-03-26 15:25 UTC (permalink / raw)
  To: pgsql-performance

am  Wed, dem 26.03.2008, um 16:15:20 +0100 mailte Marinos Yannikos folgendes:
> A. Kretschmer schrieb:
> >>create index foo1 on bla (a);
> >>create index foo2 on bla (b);
> >>create index foo3 on bla (a,b);
> >>[...]
> >
> >Which version do you have? Since 8.1 pg can use a so called 'bitmap
> >index scan', because of this feature i guess you don't need the index
> >foo3. (if you have 8.1 or higher)
> 
> 8.3.1 - foo3 is being used though in presence of both foo1 and foo2, so 
> I'd suppose that it's a better choice even with bitmap index scan 
> available...

Maybe...


Andreas
-- 
Andreas Kretschmer
Kontakt:  Heynitz: 035242/47150,   D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID:   0x3FFF606C, privat 0x7F4584DA   http://wwwkeys.de.pgp.net



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: 1-/2-dimensional indexes for common columns, rationale?
@ 2008-03-26 15:27  Craig Ringer <craig@postnewspapers.com.au>
  parent: Marinos Yannikos <mjy@geizhals.at>
  1 sibling, 0 replies; 7+ messages in thread

From: Craig Ringer @ 2008-03-26 15:27 UTC (permalink / raw)
  To: Marinos Yannikos <mjy@geizhals.at>; +Cc: pgsql-performance

Marinos Yannikos wrote:
>>
>> Which version do you have? Since 8.1 pg can use a so called 'bitmap
>> index scan', because of this feature i guess you don't need the index
>> foo3. (if you have 8.1 or higher)
>
> 8.3.1 - foo3 is being used though in presence of both foo1 and foo2, 
> so I'd suppose that it's a better choice even with bitmap index scan 
> available...
>
PostgreSQL can also partially use a multi-column index. For example, if 
you dropped your index on (a) Pg could use index (a,b) to help with 
queries for `a'. However, the index would be slower than an index on a 
alone would be.

See:

http://www.postgresql.org/docs/8.3/interactive/indexes-multicolumn.html

As usual, the best answer is really "do some testing with your queries, 
and with EXPLAIN ANALYZE, and see what works best". Test with inserts 
too, because it's likely that the cost of updating each of the three 
indexes isn't equal.

It might also be worth looking into using partial indexes if some of 
your data is "hotter" than others and perhaps more worth the index 
update cost.

--
Craig Ringer



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: 1-/2-dimensional indexes for common columns, rationale?
@ 2008-03-26 16:24  PFC <lists@peufeu.com>
  parent: Matthew <matthew@flymine.org>
  0 siblings, 0 replies; 7+ messages in thread

From: PFC @ 2008-03-26 16:24 UTC (permalink / raw)
  To: Matthew <matthew@flymine.org>; pgsql-performance



>>> create index foo1 on bla (a);
>>> create index foo2 on bla (b);
>>> create index foo3 on bla (a,b);

	You say you need faster INSERT performance. Getting rid of some indexes  
is a way, but can you tell a bit more about your hardware setup ?
	For instance, if you only have one HDD, put an extra HDD in the machine,  
and put the database on it, but leave the pg_xlog on the OS's disk. Or the  
reverse, depending on which disk is faster, and other factors. Since heavy  
INSERTs mean heavy log writing traffic, this almost doubles your write  
bandwidth for the cost of a disk. Cheap and efficient. You can also put  
the indexes on a third disk, but separating database and log on 2 disks  
will give you the most benefits.
	If you already have a monster hardware setup, though...



^ permalink  raw  reply  [nested|flat] 7+ messages in thread


end of thread, other threads:[~2008-03-26 16:24 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2008-03-26 14:18 1-/2-dimensional indexes for common columns, rationale? Marinos Yannikos <mjy@geizhals.at>
2008-03-26 15:02 ` A. Kretschmer <andreas.kretschmer@schollglas.com>
2008-03-26 15:15   ` Marinos Yannikos <mjy@geizhals.at>
2008-03-26 15:25     ` A. Kretschmer <andreas.kretschmer@schollglas.com>
2008-03-26 15:27     ` Craig Ringer <craig@postnewspapers.com.au>
2008-03-26 15:16   ` Matthew <matthew@flymine.org>
2008-03-26 16:24     ` PFC <lists@peufeu.com>

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