Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TXZjQ-0003f3-T5 for pgsql-bugs@postgresql.org; Sun, 11 Nov 2012 15:45:57 +0000 Received: from mahout.postgresql.org ([98.129.198.123]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TXZjP-0006tc-AZ for pgsql-bugs@postgresql.org; Sun, 11 Nov 2012 15:45:56 +0000 Received: from [204.145.124.246] (helo=wrigleys.postgresql.org) by mahout.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TXZjO-0004jc-Pb for pgsql-bugs@postgresql.org; Sun, 11 Nov 2012 15:45:55 +0000 Received: from www-data by wrigleys.postgresql.org with local (Exim 4.72) (envelope-from ) id 1TXZjO-0000S2-1e for pgsql-bugs@postgresql.org; Sun, 11 Nov 2012 15:45:54 +0000 Date: Sun, 11 Nov 2012 15:45:54 +0000 Message-Id: Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #7651: Superfluous calls to functions used for indexing To: pgsql-bugs@postgresql.org From: m-pg@8d.no X-Pg-Spam-Score: -2.1 (--) X-Archive-Number: 201211/52 X-Sequence-Number: 34610 The following bug has been logged on the website: Bug reference: 7651 Logged by: Morten Minde Neergaard Email address: m-pg@8d.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