Re: Query planning around one key of a multi-column index

From: Jeff Janes <jeff(dot)janes(at)gmail(dot)com>
To: Wells Oliver <wells(dot)oliver(at)gmail(dot)com>
Cc: Craig James <cjames(at)emolecules(dot)com>, pgsql-admin <pgsql-admin(at)postgresql(dot)org>
Subject: Re: Query planning around one key of a multi-column index
Date: 2019-12-19 13:55:13
Message-ID: CAMkU=1wA=nrugoa5sbgCBbcpT2azDbzoZLc6F7Myj4e=azhNiA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

On Wed, Dec 18, 2019 at 11:19 PM Wells Oliver <wells(dot)oliver(at)gmail(dot)com>
wrote:

> But so are you guys!
>
> Thanks, this is helpful.
>
> Is it really always true that querying off any column that's not the first
> column of a multi-column index will NOT use that index?
>

Are you talking only about btree indexes? Those are certainly the most
common, but other index types exist and have other properties.

Anyway, it is not always true for btree indexes. The planner might decide
to use the index as a skinny version of the table, and scan the full index
to extract some non-leading column from it. How likely it is to do this
will depend mainly on how much smaller the index is than the table, and
your relative settings of seq_page_cost and random_page_cost. (Unlike some
other products, PostgreSQL will scan the index in logical order, not
physical order, even though it doesn't care about the order and this
generates a more random IO pattern, because this is the only practical way
to protect against concurrent page splits while it scans). Unfortunately,
the EXPLAIN output does not make it clear when a index is being used in
this way, rather than the more traditional way.

Cheers,

Jeff

>

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Pepe TD Vo 2019-12-19 16:44:53 Re: backup script error with could not connect to database
Previous Message Tom Lane 2019-12-19 13:48:43 Re: Problem with Altering a table column