Skip site navigation (1) Skip section navigation (2)

Re: indexes multicolumn

From: Michael Wood <esiotrot(at)gmail(dot)com>
To: "Jean-Yves F(dot) Barbier" <12ukwn(at)gmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: indexes multicolumn
Date: 2011-05-31 13:47:45
Message-ID: BANLkTi=oBef2eKDWR2oXTuDeU9m3_QZPMg@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-novice
Hi

On 31 May 2011 15:18, Jean-Yves F. Barbier <12ukwn(at)gmail(dot)com> wrote:
> Hi list,
>
> as the doc says:
>
> SELECT name FROM test2 WHERE major = constant AND minor = constant;
>
> then it might be appropriate to define an index on the columns major and minor
> together, e.g.:
>
> CREATE INDEX test2_mm_idx ON test2 (major, minor);
>
> I may ask a dumb question, but does the query planner also use such an
> index with the inversed query, e.g.:
>
> SELECT name FROM test2 WHERE minor = constant AND major = constant;
>
> or am I obliged to define an inversed index?

If you run:

explain analyze select name from test2 where major = const and minor = const;

and

explain analyze select name from test2 where minor = const and major = const;

you will see that the query planner is clever enough to see that they
are the same.

-- 
Michael Wood <esiotrot(at)gmail(dot)com>

In response to

Responses

pgsql-novice by date

Next:From: Jean-Yves F. BarbierDate: 2011-05-31 14:30:47
Subject: Re: indexes multicolumn
Previous:From: Jean-Yves F. BarbierDate: 2011-05-31 13:18:42
Subject: indexes multicolumn

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group