Skip site navigation (1) Skip section navigation (2)

Re: Transforming IN (...) to ORs, volatility

From: Gianni Ciolli <gianni(dot)ciolli(at)2ndquadrant(dot)it>
To: Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Transforming IN (...) to ORs, volatility
Date: 2011-04-01 12:08:51
Message-ID: 20110401120850.GH6543@albo.gi.lan (view raw or flat)
Thread:
Lists: pgsql-hackers
On Fri, Apr 01, 2011 at 02:24:53PM +0300, Heikki Linnakangas wrote:

> I tried to read the SQL spec to see if it has anything to say about
> that, but I couldn't find anything. My common sense says that that
> transformation is not legal.

Your feeling is correct; I would motivate it as follows.

  random() IN (b,c)

is not equivalent to

  (random() = b) OR (random() = c)

because the two random() will evaluate to two different numbers.  So,
for instance, if you define random_boolean() as either true or false
randomly (and VOLATILEly), then

  random_boolean() IN (true, false)

is always true, while

  (random_boolean() = true) OR (random_boolean() = false)

is not (has probability 75%). For instance, the first random_boolean()
might return false while the second one returns true.

Best regards,
Dr. Gianni Ciolli - 2ndQuadrant Italia
PostgreSQL Training, Services and Support
gianni(dot)ciolli(at)2ndquadrant(dot)it | www.2ndquadrant.it

In response to

pgsql-hackers by date

Next:From: Andrew DunstanDate: 2011-04-01 12:13:34
Subject: Re: Should psql support URI syntax?
Previous:From: Shigeru HANADADate: 2011-04-01 11:57:14
Subject: Re: Foreign table permissions and cloning

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group