Re: Index ot being used - Mailing list pgsql-performance

From Tom Lane
Subject Re: Index ot being used
Date
Msg-id 24636.1118591783@sss.pgh.pa.us
Whole thread Raw
In response to Re: Index ot being used  (Madison Kelly <linux@alteeve.com>)
Responses Re: Index ot being used
List pgsql-performance
Madison Kelly <linux@alteeve.com> writes:
>    Here is my full query:

> tle-bu=> EXPLAIN ANALYZE SELECT file_name, file_parent_dir, file_type
> FROM file_info_7 WHERE file_type='d' ORDER BY file_parent_dir ASC,
> file_name ASC;

>    This is my index (which I guess is wrong):

> tle-bu=> \d file_info_7_display_idx
>   Index "public.file_info_7_display_idx"
>       Column      |         Type
> -----------------+----------------------
>   file_type       | character varying(2)
>   file_parent_dir | text
>   file_name       | text
> btree, for table "public.file_info_7"

The index is fine, but you need to phrase the query as

    ... ORDER BY file_type, file_parent_dir, file_name;

(Whether you use ASC or not doesn't matter.)  Otherwise the planner
won't make the connection to the sort ordering of the index.

            regards, tom lane

pgsql-performance by date:

Previous
From: Madison Kelly
Date:
Subject: Re: Index ot being used
Next
From: Bruno Wolff III
Date:
Subject: Re: Index ot being used