pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Is unique index always used if query is on first constituent column ?
3+ messages / 3 participants
[nested] [flat]

* Is unique index always used if query is on first constituent column ?
@ 2006-12-30 10:38 Rajesh Kumar Mallah <mallah.rajesh@gmail.com>
  2006-12-30 17:15 ` Re: Is unique index always used if query is on first constituent column ? Bruno Wolff III <bruno@wolff.to>
  0 siblings, 1 reply; 3+ messages in thread

From: Rajesh Kumar Mallah @ 2006-12-30 10:38 UTC (permalink / raw)
  To: pgsql-admin

Hi,

suppose we have  2 columns a and b  . we need to query by a and sometimes
by b  for data consistency UNIQUE(a,b) also needs to be there. we create
indexes below:

create unique index ab on t(a,b);
create index b on t(b);

it has been observed that index ab is used while querying
for a , can we always avoid creating the extra index on a ie,
create index a on t(a); (does other databases also behave
similar?)

Regds
mallah.



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

* Re: Is unique index always used if query is on first constituent column ?
  2006-12-30 10:38 Is unique index always used if query is on first constituent column ? Rajesh Kumar Mallah <mallah.rajesh@gmail.com>
@ 2006-12-30 17:15 ` Bruno Wolff III <bruno@wolff.to>
  2006-12-30 18:06   ` Re: Is unique index always used if query is on first constituent column ? Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 3+ messages in thread

From: Bruno Wolff III @ 2006-12-30 17:15 UTC (permalink / raw)
  To: Rajesh Kumar Mallah <mallah.rajesh@gmail.com>; +Cc: pgsql-admin

On Sat, Dec 30, 2006 at 16:08:39 +0530,
  Rajesh Kumar Mallah <mallah.rajesh@gmail.com> wrote:
> Hi,
> 
> suppose we have  2 columns a and b  . we need to query by a and sometimes
> by b  for data consistency UNIQUE(a,b) also needs to be there. we create
> indexes below:
> 
> create unique index ab on t(a,b);
> create index b on t(b);
> 
> it has been observed that index ab is used while querying
> for a , can we always avoid creating the extra index on a ie,
> create index a on t(a); (does other databases also behave
> similar?)

If the b data is large you might get some performance increase from adding
an index on just a. You will be trading off increased work when doing updates
to handle the extra index versus faster searches in a more compact index.



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

* Re: Is unique index always used if query is on first constituent column ?
  2006-12-30 10:38 Is unique index always used if query is on first constituent column ? Rajesh Kumar Mallah <mallah.rajesh@gmail.com>
  2006-12-30 17:15 ` Re: Is unique index always used if query is on first constituent column ? Bruno Wolff III <bruno@wolff.to>
@ 2006-12-30 18:06   ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 3+ messages in thread

From: Tom Lane @ 2006-12-30 18:06 UTC (permalink / raw)
  To: Bruno Wolff III <bruno@wolff.to>; +Cc: Rajesh Kumar Mallah <mallah.rajesh@gmail.com>; pgsql-admin

Bruno Wolff III <bruno@wolff.to> writes:
>   Rajesh Kumar Mallah <mallah.rajesh@gmail.com> wrote:
>> create unique index ab on t(a,b);
>> create index b on t(b);

> If the b data is large you might get some performance increase from adding
> an index on just a. You will be trading off increased work when doing updates
> to handle the extra index versus faster searches in a more compact index.

This is covered in some detail in TFM:
http://www.postgresql.org/docs/8.2/static/indexes-multicolumn.html
http://www.postgresql.org/docs/8.2/static/indexes-bitmap-scans.html

			regards, tom lane



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


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

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-12-30 10:38 Is unique index always used if query is on first constituent column ? Rajesh Kumar Mallah <mallah.rajesh@gmail.com>
2006-12-30 17:15 ` Bruno Wolff III <bruno@wolff.to>
2006-12-30 18:06   ` Tom Lane <tgl@sss.pgh.pa.us>

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