We sometimes transform IN-clauses to a list of ORs:

postgres=# explain SELECT * FROM foo WHERE a IN (b, c);
QUERY PLAN
------------------------------------------------------
Seq Scan on foo (cost=0.00..39.10 rows=19 width=12)
Filter: ((a = b) OR (a = c))
(2 rows)

But what if you replace "a" with a volatile function? It doesn't seem
legal to do that transformation in that case, but we do it:

postgres=# explain SELECT * FROM foo WHERE (random()*2)::integer IN (b, c);
QUERY PLAN


-------------------------------------------------------------------------------------------------
-------------------
Seq Scan on foo (cost=0.00..68.20 rows=19 width=12)
Filter: ((((random() * 2::double precision))::integer = b) OR
(((random() * 2::double precision))::integer = c))
(2 rows)

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.

--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 13 | next ›
Discussion Overview
grouppgsql-hackers @
categoriespostgresql
postedApr 1, '11 at 11:25a
activeApr 19, '11 at 7:27p
posts13
users6
websitepostgresql.org...
irc#postgresql

People

Translate

site design / logo © 2021 Grokbase