Re: SORT and Merge Join via Index

From: Robert James <srobertjames(at)gmail(dot)com>
To: Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: SORT and Merge Join via Index
Date: 2013-08-14 00:04:44
Message-ID: CAGYyBgjW3J7TU5yV=6G2_e_hiEYSourh0ukQnNUXND9HjedgYQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 8/13/13, Robert James <srobertjames(at)gmail(dot)com> wrote:
> I noticed that when I have an index on (a,b) of table t, and I do an
> SELECT * FROM t ORDER BY a ASC, it doesn't use the index. When I
> create a new index of only a, it does use the index. Why is that?
>
> And, more importantly, when I do a query involving a merge join of
> table t, which requires sorting table t, the planner does the sort
> manually using quicksort, not using the index. The time that step
> takes is identical to the ORDER BY without using the index. What do I
> need to do to have Postgres use the index for the merge join?
>
> (Postgres 8.3)

Interestingly enough, in the JOIN query, if I replace "t" with:
(SELECT f1, f2 FROM t ORDER BY f1 ASC) AS t_
Postgres does use the index, getting the query done in half the time!

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Gavin Flower 2013-08-14 00:21:01 Re: SORT and Merge Join via Index
Previous Message Robert James 2013-08-14 00:02:03 SORT and Merge Join via Index