From: | Greg Stark <gsstark(at)mit(dot)edu> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | non-{immutable, cacheable} function being treated as if they're immutable ? |
Date: | 2003-02-27 16:56:21 |
Message-ID: | 87d6ldmzm2.fsf@stark.dyndns.tv |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
I'm trying to seed a table with random data for foreign key references. Some
keys are missing so I have to check if they exist before inserting. Postgres
seems to be optimizing out the random() call. I thought it would only do that
for cacheable/immutable functions?
This is happening on 7.3.1 as well as on CVS built about a week ago.
db=> create function r(integer,integer) returns integer as 'select (random()*($2 - $1))::integer + $1' language sql;
db=> explain insert into foo_bar (
foo_id, bar_id
) (
select foo_id, bar_id
from (select foo_id, r(1,13512) as bar_id
from foo
) as x
where exists (select 1 from bar where bar_id = x.bar_id)
);
QUERY PLAN
-----------------------------------------------------------------------------------------------
Result (cost=442.53..1564.49 rows=1 width=4)
One-Time Filter: $0
InitPlan
-> Seq Scan on bar (cost=0.00..442.53 rows=1 width=0)
Filter: (bar_id = (((random() * 13511::double precision))::integer + 1))
-> Seq Scan on foo (cost=0.00..1121.95 rows=1 width=4)
--
greg
From | Date | Subject | |
---|---|---|---|
Next Message | Diogo de Oliveira Biazus | 2003-02-27 16:57:01 | Problems with pgxml and encoding. |
Previous Message | Dennis Gearon | 2003-02-27 16:39:36 | Re: selective copy |