pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Question about clustering multiple columns
4+ messages / 2 participants
[nested] [flat]

* Question about clustering multiple columns
@ 2006-06-13 16:04 Benjamin Arai <benjamin@araisoft.com>
  2006-06-16 15:31 ` Re: Question about clustering multiple columns Bruno Wolff III <bruno@wolff.to>
  0 siblings, 1 reply; 4+ messages in thread

From: Benjamin Arai @ 2006-06-13 16:04 UTC (permalink / raw)
  To: pgsql-general@postgresql.org; pgsql-performance

Hi,
 
I have a database where there are three columns (name,date,data).  The
queries are almost always something like SELECT date,data FROM table WHERE
name=blah AND date > 1/1/2005 AND date < 1/1/2006;.  I currently have three
B-tree indexes, one for each of the columns.  Is clustering on date index
going to be what I want, or do I need a index that contains both name and
date?
 
Benjamin Arai
barai@cs.ucr.edu
http://www.benjaminarai.com <http://www.benjaminarai.com/; 
 
 

Attachments:

barai@cs.ucr.edu.vcf (text/x-vcard, 709B) download BEGIN:VCARD VERSION:2.1 N:Arai;Benjamin FN:barai@cs.ucr.edu ORG:University of California, Riverside TITLE:PhD Student TEL;WORK;VOICE:(951) 827-2838 TEL;HOME;VOICE:(951) 682-6816 TEL;CELL;VOICE:(626) 378-2992 ADR;WORK;ENCODING=QUOTED-PRINTABLE:;;Department of Computer Science and Engineering=0D=0AEngineering BU2, Room = 351=0D=0AUniversity of California;Riverside;CA;92521;United States of Americ= a LABEL;WORK;ENCODING=QUOTED-PRINTABLE:Department of Computer Science and Engineering=0D=0AEngineering BU2, Room 35= 1=0D=0AUniversity of California=0D=0ARiverside, CA 92521=0D=0AUnited States = of America URL;WORK:http://www.benjaminarai.com EMAIL;PREF;INTERNET:barai@cs.ucr.edu REV:20060520T165426Z END:VCARD
^ permalink raw reply [nested|flat] 4+ messages in thread

* Re: Question about clustering multiple columns
  2006-06-13 16:04 Question about clustering multiple columns Benjamin Arai <benjamin@araisoft.com>
@ 2006-06-16 15:31 ` Bruno Wolff III <bruno@wolff.to>
  2006-06-16 18:55   ` Re: Question about clustering multiple columns Bruno Wolff III <bruno@wolff.to>
  0 siblings, 1 reply; 4+ messages in thread

From: Bruno Wolff III @ 2006-06-16 15:31 UTC (permalink / raw)
  To: Benjamin Arai <benjamin@araisoft.com>; +Cc: pgsql-general@postgresql.org; pgsql-performance

On Tue, Jun 13, 2006 at 09:04:15 -0700,
  Benjamin Arai <benjamin@araisoft.com> wrote:
> Hi,
>  
> I have a database where there are three columns (name,date,data).  The
> queries are almost always something like SELECT date,data FROM table WHERE
> name=blah AND date > 1/1/2005 AND date < 1/1/2006;.  I currently have three
> B-tree indexes, one for each of the columns.  Is clustering on date index
> going to be what I want, or do I need a index that contains both name and
> date?

I would expect that clustering on the name would be better for the above
query.
You probably want an index on name and date combined.



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

* Re: Question about clustering multiple columns
  2006-06-13 16:04 Question about clustering multiple columns Benjamin Arai <benjamin@araisoft.com>
  2006-06-16 15:31 ` Re: Question about clustering multiple columns Bruno Wolff III <bruno@wolff.to>
@ 2006-06-16 18:55   ` Bruno Wolff III <bruno@wolff.to>
  2006-06-16 18:55     ` Re: Question about clustering multiple columns Benjamin Arai <benjamin@araisoft.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Bruno Wolff III @ 2006-06-16 18:55 UTC (permalink / raw)
  To: Benjamin Arai <benjamin@araisoft.com>; +Cc: pgsql-performance

On Fri, Jun 16, 2006 at 11:11:59 -0700,
  Benjamin Arai <benjamin@araisoft.com> wrote:
> Hi,
> 
> Thanks for the reply. I have one more question.  Does it matter in which
> order that I make the index?

Please keep replies copied to the lists so that other people can learn from
and crontibute to the discussion.

In this case I am just going to copy back to the performance list, since it
is generally better for perfomance questions than the general list.

> For example, should I create an index cusip,date or date,cusip, does it
> matter which order.  My goal is to cluster the entries by cusip, then for
> each cusip order the data by date (maybe the order by data occurs
> automatically).  Hm, in that case maybe I only need to cluster by cusip, but
> then how do I ensure that each cusip had its data ordered by date?

I think that you want to order by cusip (assuming that corresponds to "name"
in you sample query below) first. You won't end up having to go through values
in the index that will be filtered out if you do it that way.

The documentation for the cluster command says that it clusters on indexes,
not columns. So if the index is on (cusip, date), then the records will be
ordered by cusip, date immediately after the cluster. (New records added 
after the cluster are not guarenteed to be ordered by the index.)

> 
> Benjamin
> 
> -----Original Message-----
> From: Bruno Wolff III [mailto:bruno@wolff.to] 
> Sent: Friday, June 16, 2006 8:32 AM
> To: Benjamin Arai
> Cc: pgsql-general@postgresql.org; pgsql-performance@postgresql.org
> Subject: Re: Question about clustering multiple columns
> 
> On Tue, Jun 13, 2006 at 09:04:15 -0700,
>   Benjamin Arai <benjamin@araisoft.com> wrote:
> > Hi,
> >  
> > I have a database where there are three columns (name,date,data).  The 
> > queries are almost always something like SELECT date,data FROM table 
> > WHERE name=blah AND date > 1/1/2005 AND date < 1/1/2006;.  I currently 
> > have three B-tree indexes, one for each of the columns.  Is clustering 
> > on date index going to be what I want, or do I need a index that 
> > contains both name and date?
> 
> I would expect that clustering on the name would be better for the above
> query.
> You probably want an index on name and date combined.
> 
> !DSPAM:4492ce0d180368658827628!
> 



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

* Re: Question about clustering multiple columns
  2006-06-13 16:04 Question about clustering multiple columns Benjamin Arai <benjamin@araisoft.com>
  2006-06-16 15:31 ` Re: Question about clustering multiple columns Bruno Wolff III <bruno@wolff.to>
  2006-06-16 18:55   ` Re: Question about clustering multiple columns Bruno Wolff III <bruno@wolff.to>
@ 2006-06-16 18:55     ` Benjamin Arai <benjamin@araisoft.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Benjamin Arai @ 2006-06-16 18:55 UTC (permalink / raw)
  To: 'Bruno Wolff III' <bruno@wolff.to>; +Cc: pgsql-performance

Thanks! This exactly what I was looking for.  

Benjamin Arai
Benjamin@araisoft.com
http://www.benjaminarai.com

-----Original Message-----
From: Bruno Wolff III [mailto:bruno@wolff.to] 
Sent: Friday, June 16, 2006 11:56 AM
To: Benjamin Arai
Cc: pgsql-performance@postgresql.org
Subject: Re: Question about clustering multiple columns

On Fri, Jun 16, 2006 at 11:11:59 -0700,
  Benjamin Arai <benjamin@araisoft.com> wrote:
> Hi,
> 
> Thanks for the reply. I have one more question.  Does it matter in 
> which order that I make the index?

Please keep replies copied to the lists so that other people can learn from
and crontibute to the discussion.

In this case I am just going to copy back to the performance list, since it
is generally better for perfomance questions than the general list.

> For example, should I create an index cusip,date or date,cusip, does 
> it matter which order.  My goal is to cluster the entries by cusip, 
> then for each cusip order the data by date (maybe the order by data 
> occurs automatically).  Hm, in that case maybe I only need to cluster 
> by cusip, but then how do I ensure that each cusip had its data ordered by
date?

I think that you want to order by cusip (assuming that corresponds to "name"
in you sample query below) first. You won't end up having to go through
values in the index that will be filtered out if you do it that way.

The documentation for the cluster command says that it clusters on indexes,
not columns. So if the index is on (cusip, date), then the records will be
ordered by cusip, date immediately after the cluster. (New records added
after the cluster are not guarenteed to be ordered by the index.)

> 
> Benjamin
> 
> -----Original Message-----
> From: Bruno Wolff III [mailto:bruno@wolff.to]
> Sent: Friday, June 16, 2006 8:32 AM
> To: Benjamin Arai
> Cc: pgsql-general@postgresql.org; pgsql-performance@postgresql.org
> Subject: Re: Question about clustering multiple columns
> 
> On Tue, Jun 13, 2006 at 09:04:15 -0700,
>   Benjamin Arai <benjamin@araisoft.com> wrote:
> > Hi,
> >  
> > I have a database where there are three columns (name,date,data).  
> > The queries are almost always something like SELECT date,data FROM 
> > table WHERE name=blah AND date > 1/1/2005 AND date < 1/1/2006;.  I 
> > currently have three B-tree indexes, one for each of the columns.  
> > Is clustering on date index going to be what I want, or do I need a 
> > index that contains both name and date?
> 
> I would expect that clustering on the name would be better for the 
> above query.
> You probably want an index on name and date combined.
> 
> 
> 

!DSPAM:4492fdfd193631139819016!




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


end of thread, other threads:[~2006-06-16 18:55 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-06-13 16:04 Question about clustering multiple columns Benjamin Arai <benjamin@araisoft.com>
2006-06-16 15:31 ` Bruno Wolff III <bruno@wolff.to>
2006-06-16 18:55   ` Bruno Wolff III <bruno@wolff.to>
2006-06-16 18:55     ` Benjamin Arai <benjamin@araisoft.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