"Paul Mackay" <mackaypaul@xxxxxxxxx> writes: > ... > EXPLAIN shows that an index scan is used by the planner. A query returning > the maximum 200 number of records takes around 20 ms. What is surprising is > that the same query executed several times takes practically the same time, > as if the result was not cached. > ... > Could the problem be that an index on a function result is not cached or > less well cached ? I can't see how that would be. The index machinery has no idea what it's indexing, and the kernel disk cache even less. Perhaps the majority of the runtime is going somewhere else, like the initial evaluation of the function value to compare against? Or maybe you've found some inefficiency in the planner's handling of function indexes. Try comparing EXPLAIN ANALYZE output for the two cases to see if the discrepancy exists during query runtime, or if it's upstream at plan time. regards, tom lane