Re: Clarification on Expression indexes

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Koen De Groote <kdg(dot)dev(at)gmail(dot)com>
Cc: PostgreSQL General <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Clarification on Expression indexes
Date: 2020-06-16 22:20:59
Message-ID: 1403342.1592346059@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Koen De Groote <kdg(dot)dev(at)gmail(dot)com> writes:
>> Index expressions are relatively expensive to maintain, because the derived
>> expression(s) must be computed for each row upon insertion and whenever it
>> is updated

> I'd like to get an idea on "relatively expensive".

It's basically whatever the cost of evaluating that expression is,
plus the normal costs of index insertion. If the expression is
something built-in like sin(x), probably the evaluation cost is
negligible ... but with a user-defined function in SQL or some PL,
maybe not so much.

In any case, the real question is "how many expression evaluations am I
going to save over the life of the row, versus how many I pay up-front?"
You didn't address how many queries would benefit from having the index,
so the question is unanswerable with just these facts.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Toomas Kristin 2020-06-17 05:42:52 Conflict with recovery on PG version 11.6
Previous Message Koen De Groote 2020-06-16 21:53:13 Clarification on Expression indexes