Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XceLt-0007eO-C2 for pgsql-bugs@arkaria.postgresql.org; Fri, 10 Oct 2014 17:51:41 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XceLr-00072n-Rp for pgsql-bugs@arkaria.postgresql.org; Fri, 10 Oct 2014 17:51:39 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XcdrN-0006zX-5K for pgsql-bugs@postgresql.org; Fri, 10 Oct 2014 17:20:09 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XcdrI-0000X8-M1 for pgsql-bugs@postgresql.org; Fri, 10 Oct 2014 17:20:06 +0000 MIME-Version: 1.0 Subject: BUG #11637: SQL function volatility is ignored on index creation To: pgsql-bugs@postgresql.org From: will@willglynn.com Date: Fri, 10 Oct 2014 17:19:05 +0000 Message-ID: <20141010171905.25462.4715@wrigleys.postgresql.org> X-Pg-Spam-Score: -1.2 (-) Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org The following bug has been logged on the website: Bug reference: 11637 Logged by: Will Glynn Email address: will@willglynn.com PostgreSQL version: 9.3.5 Operating system: Mac OS X Description: Steps to reproduce: CREATE FUNCTION immutable_but_marked_volatile() RETURNS integer AS $$ SELECT floor(random() * 4)::integer; $$ LANGUAGE sql VOLATILE; CREATE TABLE foo (bar int); CREATE INDEX foo_index ON foo (immutable_but_marked_volatile()); Expected results: CREATE FUNCTION CREATE TABLE ERROR: functions in index expression must be marked IMMUTABLE Actual results: CREATE FUNCTION CREATE TABLE CREATE INDEX The CREATE INDEX documentation and the wording of that error message strongly imply that it's a function's volatility *marking* that is important, but in at least some situations, PostgreSQL ignores pg_proc.provolatile='v' and allows index creation anyway if the function is in fact immutable. I suspect this qualifier is ignored because the SQL function call is being inlined prior to the CheckMutability() in ComputeIndexAttrs(); there isn't a volatile function call, just an immutable expression. Proposed solutions: 1. Prevent index creation on VOLATILE functions in all situations, i.e. even if the function call is inlined away. 2. Update the CREATE INDEX documentation and error message to indicate that certain VOLATILE functions are acceptable for use in indexes if PostgreSQL can demonstrate that they are not, in fact, actually volatile. -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs