Re: [HACKERS] Surjective functional indexes - Mailing list pgsql-hackers

From Tom Lane
Subject Re: [HACKERS] Surjective functional indexes
Date
Msg-id 12290.1541719635@sss.pgh.pa.us
Whole thread Raw
In response to Re: [HACKERS] Surjective functional indexes  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: [HACKERS] Surjective functional indexes  (Konstantin Knizhnik <k.knizhnik@postgrespro.ru>)
List pgsql-hackers
I wrote:
> The bigger picture here, and the reason for my skepticism about having
> any intelligence in the enabling logic, is that there is no scenario
> in which this code can be smarter than the user about what to do.
> We have no insight today, and are unlikely to have any in future, about
> whether a specific index expression is many-to-one or not.

Hmm ... actually, I take that back.  Since we're only interested in this
for expression indexes, we can expect that statistics will be available
for the expression index, at least for tables that have been around
long enough that UPDATE performance is really an exciting topic.
So you could imagine pulling up the stadistinct numbers for the index
column(s) and the underlying column(s), and enabling the optimization
when their ratio is less than $something.  Figuring out how to merge
numbers for multiple columns might be tricky, but it's not going to be
completely fact-free.  (I still think that the cost-estimate logic is
quite bogus, however.)

Another issue in all this is the cost of doing this work over again
after any relcache flush.  Maybe we could move the responsibility
into ANALYZE?

BTW, the existing code appears to be prepared to enable this logic
if *any* index column is an expression, but surely we should do so
only if they are *all* expressions?

            regards, tom lane


pgsql-hackers by date:

Previous
From: "Jonah H. Harris"
Date:
Subject: Re: Disallow setting client_min_messages > ERROR?
Next
From: "David G. Johnston"
Date:
Subject: Re: Connection limit doesn't work for superuser