pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Stats for indexes on expressions
2+ messages / 2 participants
[nested] [flat]

* Stats for indexes on expressions
@ 2020-12-25 05:32 Shantanu Shekhar <shekharshan@yahoo.com>
  2020-12-25 06:09 ` Re: Stats for indexes on expressions Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 2+ messages in thread

From: Shantanu Shekhar @ 2020-12-25 05:32 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>

Hello,
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? (2) Whenever an index on an expression is defined like this, should we rebuild the stats? 
Thanks,
Shantanu

^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Stats for indexes on expressions
  2020-12-25 05:32 Stats for indexes on expressions Shantanu Shekhar <shekharshan@yahoo.com>
@ 2020-12-25 06:09 ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2020-12-25 06:09 UTC (permalink / raw)
  To: Shantanu Shekhar <shekharshan@yahoo.com>; +Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>

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





^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2020-12-25 06:09 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-12-25 05:32 Stats for indexes on expressions Shantanu Shekhar <shekharshan@yahoo.com>
2020-12-25 06:09 ` Tom Lane <tgl@sss.pgh.pa.us>

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