BUG #7651: Superfluous calls to functions used for indexing

From: m-pg(at)8d(dot)no
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #7651: Superfluous calls to functions used for indexing
Date: 2012-11-11 15:45:54
Message-ID: E1TXZjO-0000S2-1e@wrigleys.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 7651
Logged by: Morten Minde Neergaard
Email address: m-pg(at)8d(dot)no
PostgreSQL version: 9.1.6
Operating system: Debian Wheezy
Description:

Bug: When making an index over a function, then selecting a result that does
not contain the function call (but orders on it), Superfluous function calls
are made. This possibly because the plan creates a projection containing the
function value.

Steps to reproduce:

1. Create a function that gives you a immutable reply. In my real function,
runtime is several ms. The SQL script referred to at the bottom contains a
more minimal, if horribly ugly, example. It prints a NOTICE every time it is
run.

2. Use this function to create an index. In the attached example, this
prints one NOTICE for each row, as expected.

3. Select a small number of rows using e.g. ORDER BY and LIMIT. This returns
correctly, but takes longer than expected to execute. The NOTICE is printed
five times, even though the function should not need be called.

I have made a minimal script reproducing this, and run it with simple test
data. All URLs below.

SQL script: http://xim.akuma.no/psql_bug/psql_bug.txt
Script output: http://xim.akuma.no/psql_bug/psql_bug_log.txt
Data for test: http://xim.akuma.no/psql_bug/file_containing_ints

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Andreas.Heiduk 2012-11-11 18:35:35 BUG #7652: Documentation index lacks functions from "Additional Supplied Modules"
Previous Message jfb 2012-11-11 15:17:34 BUG #7650: DROP TABLE IF EXISTS fails if schema does not exist