Re: Query not using the indexes properly.

From: David Wilson <david(dot)t(dot)wilson(at)gmail(dot)com>
To: Chris <dmagick(at)gmail(dot)com>
Cc: Tim Uckun <timuckun(at)gmail(dot)com>, pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Query not using the indexes properly.
Date: 2009-10-02 02:18:56
Message-ID: e7f9235d0910011918s575cdd70mca1ea1fa61a7c5e1@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Oct 1, 2009 at 10:04 PM, Chris <dmagick(at)gmail(dot)com> wrote:

> Tim Uckun wrote:
>
> If this is a common query you could probably do a multi-column index on all
> 3 columns (id, company_id, source_model_name) - but if company_id and
> source_model_name have a low number of distinct values, then it's not going
> to help.
>

If you try the multi-column index (which is a good idea), be sure that "id"
is the last of the three columns, since that's the column on which you have
an inequality test rather than an equality test; eg,
(company_id,source_model_name,id).

--
- David T. Wilson
david(dot)t(dot)wilson(at)gmail(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tim Uckun 2009-10-02 02:19:57 Re: Query not using the indexes properly.
Previous Message Chris 2009-10-02 02:04:29 Re: Query not using the indexes properly.