Re: Query performance issue - Mailing list pgsql-performance

From Chris
Subject Re: Query performance issue
Date
Msg-id 46A5BD6F.7000108@gmail.com
Whole thread Raw
In response to Re: Query performance issue  (Chris <dmagick@gmail.com>)
Responses Re: Query performance issue  ("Jonathan Gray" <jgray@streamy.com>)
List pgsql-performance
Chris wrote:
> Jonathan Gray wrote:
>> We’re experiencing a query performance problem related to the planner
>> and its ability to perform a specific type of merge.
>>
>>
>>
>> We have created a test case (as attached, or here:
>> http://www3.streamy.com/postgres/indextest.sql) which involves a
>> hypothetical customer ordering system, with customers, orders, and
>> customer groups.
>>
>>
>>
>> If we want to retrieve a single customers 10 most recent orders,
>> sorted by date, we can use a double index on (customer,date);
>> Postgres’s query planner will use the double index with  a backwards
>> index scan on the second indexed column (date).
>>
>>
>>
>> However, if we want to retrieve a “customer class’s” 10 most recent
>> orders, sorted by date, we are not able to get Postgres to use double
>> indexes.
>
> You don't have any indexes on the 'customerclass' table.
>
> Creating a foreign key doesn't create an index, you need to do that
> separately.
>
> Try
>
> create index cc_customerid_class on indextest.customerclass(classid,
> customerid);
>

It could also be that since you don't have very much data (10,000) rows
- postgres is ignoring the indexes because it'll be quicker to scan the
tables.

If you bump it up to say 100k rows, what happens?

--
Postgresql & php tutorials
http://www.designmagick.com/

pgsql-performance by date:

Previous
From: Chris
Date:
Subject: Re: Query performance issue
Next
From: "Jonathan Gray"
Date:
Subject: Re: Query performance issue