pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Shantanu Shekhar <shekharshan@yahoo.com>
Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: Stats for indexes on expressions
Date: Fri, 25 Dec 2020 01:09:02 -0500
Message-ID: <1135857.1608876542@sss.pgh.pa.us> (raw)
In-Reply-To: <1258055935.2714481.1608874336314@mail.yahoo.com>
References: <1258055935.2714481.1608874336314.ref@mail.yahoo.com>
	<1258055935.2714481.1608874336314@mail.yahoo.com>

Shantanu Shekhar <shekharshan@yahoo.com> writes:
> I am trying to understand how the cost for a query involving indexes on expressions is calculated. How is the statistics on the expression maintained? For example Postgres documentation on 'Indexes on Expressions' mentions the following example:
> CREATE INDEX people_names ON people ((first_name || ' ' || last_name));SELECT * FROM people WHERE (first_name || ' ' || last_name) = 'John Smith';
> The index is created on an expression involving first name and last name. My confusion is basically around:
> (1) When using this index how will the query planner get the stats on this expression?

ANALYZE on a table will (re)build statistics for any expression indexes on
that table, in addition to the stats for the table's own columns.

(2) Whenever an index on an expression is defined like this, should we rebuild the stats?

If you don't want to wait around for auto-analyze to do it, yes.

			regards, tom lane





view thread (2+ messages)

Message-ID: <1135857.1608876542@sss.pgh.pa.us>
Permalink:  ../1135857.1608876542@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/1135857.1608876542@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, shekharshan@yahoo.com
  Subject: Re: Stats for indexes on expressions
  In-Reply-To: <1135857.1608876542@sss.pgh.pa.us>
  References: <1258055935.2714481.1608874336314.ref@mail.yahoo.com> <1258055935.2714481.1608874336314@mail.yahoo.com> <1135857.1608876542@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox