pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: will@willglynn.com
To: pgsql-bugs@postgresql.org
Subject: BUG #11637: SQL function volatility is ignored on index creation
Date: Fri, 10 Oct 2014 17:19:05 +0000
Message-ID: <20141010171905.25462.4715@wrigleys.postgresql.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

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



view thread (3+ messages)  latest in thread

Message-ID: <20141010171905.25462.4715@wrigleys.postgresql.org>
Permalink:  ../20141010171905.25462.4715@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/20141010171905.25462.4715@wrigleys.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: will@willglynn.com
  Subject: Re: BUG #11637: SQL function volatility is ignored on index creation
  In-Reply-To: <20141010171905.25462.4715@wrigleys.postgresql.org>
  References: <20141010171905.25462.4715@wrigleys.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox