Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql General > functions, sele...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 15813 of 17437
Post > Topic >>

functions, selects and the planner

by mdennis@[EMAIL PROTECTED] ("Matthew Dennis") Jun 14, 2008 at 10:39 PM

------=_Part_28947_7766735.1213501157123
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

In PostgreSQL 8.3 lets say I have a table:

create table t(c1 int, c2 int, ts0 timestamp with time zone, ts1 timestamp
with time zone, data varchar);

an index:

create index t_c1_c2_ts0_idx on t using btree(c1, c2, ts0 desc);

and a function:

create function f(_ts timestamp(0) with time zone, _c1 int, _c2 int)
returns
varchar as $$
declare
  _data varchar := null;
begin
  select into _data data from t where _ts >= ts0 and c1 = _c1 and c2 = _c2
and (ts1 is null or _ts < ts1);
  return _data;
end
$$ language plpgsql;

My question is when is the "select into _data" query planned/replanned? 
I'm
concerned that the query might only be planned once (e.g. the first time
it's executed or when the function is first defined) and cached
indefinitely.  The table t is initially empty, but grows at a fairly
steady
rate over time.  So if the table is essentially empty when the query is
planned, a seqscan is certainly what the planner would do.  However, as
time
goes on and table t is filled with data and the stats change, will the
query
eventually be replanned?  If not, what are some suggested ways to handle
this?

------=_Part_28947_7766735.1213501157123
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

In PostgreSQL 8.3 lets say I have a table:<br><br>create table t(c1 int,
c2 int, ts0 timestamp with time zone, ts1 timestamp with time zone, data
varchar);<br><br>an index:<br><br>create index t_c1_c2_ts0_idx on t using
btree(c1, c2, ts0 desc);<br>
<br>and a function:<br><br>create function f(_ts timestamp(0) with time
zone, _c1 int, _c2 int) returns varchar as $$<br>declare<br>&nbsp; _data
varchar := null;<br>begin<br>&nbsp; select into _data data from t where
_ts &gt;= ts0 and c1 = _c1 and c2 = _c2 and (ts1 is null or _ts &lt;
ts1);<br>
&nbsp; return _data;<br>end<br>$$ language plpgsql;<br><br>My question is
when is the &quot;select into _data&quot; query planned/replanned?&nbsp;
I&#39;m concerned that the query might only be planned once (e.g. the
first time it&#39;s executed or when the function is first defined) and
cached indefinitely.&nbsp; The table t is initially empty, but grows at a
fairly steady rate over time.&nbsp; So if the table is essentially empty
when the query is planned, a seqscan is certainly what the planner would
do.&nbsp; However, as time goes on and table t is filled with data and the
stats change, will the query eventually be replanned?&nbsp; If not, what
are some suggested ways to handle this?<br>
<br>

------=_Part_28947_7766735.1213501157123--
 




 1 Posts in Topic:
functions, selects and the planner
mdennis@[EMAIL PROTECTED]  2008-06-14 22:39:17 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Nov 22 16:23:01 CST 2008.