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