pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedClarification on Expression indexes
2+ messages / 2 participants
[nested] [flat]
* Clarification on Expression indexes
@ 2020-06-16 21:53 Koen De Groote <kdg.dev@gmail.com>
0 siblings, 1 reply; 2+ messages in thread
From: Koen De Groote @ 2020-06-16 21:53 UTC (permalink / raw)
To: PostgreSQL General <pgsql-general@lists.postgresql.org>
Greetings all.
The following page:
https://www.postgresql.org/docs/11/indexes-expressional.html
States the following:
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". For instance, compared
to a partial index, which is split on one or more boolean values. As
opposed to making a function for this that serves the same identical
calculation.
Let's say that over the lifetime of a row, it rarely gets updated more than
2000 times, and the majority of this is right after creation?
Is this a concern?
Regards,
Koen De Groote
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Clarification on Expression indexes
@ 2020-06-16 22:20 Tom Lane <tgl@sss.pgh.pa.us>
parent: Koen De Groote <kdg.dev@gmail.com>
0 siblings, 0 replies; 2+ messages in thread
From: Tom Lane @ 2020-06-16 22:20 UTC (permalink / raw)
To: Koen De Groote <kdg.dev@gmail.com>; +Cc: PostgreSQL General <pgsql-general@lists.postgresql.org>
Koen De Groote <kdg.dev@gmail.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
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2020-06-16 22:20 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-06-16 21:53 Clarification on Expression indexes Koen De Groote <kdg.dev@gmail.com>
2020-06-16 22:20 ` 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