Hm, shouldn't this query notice that random() is volatile and not make the
subquery an initplan?


postgres=# select i, (select (random()*1000)::integer ) from x limit 5;
i | ?column?
---+----------
1 | 677
2 | 677
3 | 677
4 | 677
5 | 677
(5 rows)

postgres=# explain select i, (select (random()*1000)::integer ) from x limit 5;
QUERY PLAN
-----------------------------------------------------------
Limit (cost=0.02..0.11 rows=5 width=4)
InitPlan
-> Result (cost=0.00..0.02 rows=1 width=0)
-> Seq Scan on x (cost=0.00..64.80 rows=3480 width=4)
(4 rows)


--
Gregory Stark
EnterpriseDB http://www.enterprisedb.com
Ask me about EnterpriseDB's RemoteDBA services!

Search Discussions

  • Tom Lane at Aug 20, 2008 at 2:23 pm

    Gregory Stark writes:
    Hm, shouldn't this query notice that random() is volatile and not make the
    subquery an initplan?
    We've never done that in the past; in fact I recall seeing people using
    subselects deliberately to hide volatility.

    regards, tom lane

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppgsql-hackers @
categoriespostgresql
postedAug 20, '08 at 2:05p
activeAug 20, '08 at 2:23p
posts2
users2
websitepostgresql.org...
irc#postgresql

2 users in discussion

Tom Lane: 1 post Gregory Stark: 1 post

People

Translate

site design / logo © 2021 Grokbase