Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id F0FAB9FB39D for ; Wed, 24 Jan 2007 16:33:38 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-new, port 10024) with ESMTP id 95815-01-3 for ; Wed, 24 Jan 2007 16:33:27 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.172]) by postgresql.org (Postfix) with ESMTP id 78C909FB5FA for ; Wed, 24 Jan 2007 16:33:29 -0400 (AST) Received: by ug-out-1314.google.com with SMTP id k3so256328ugf for ; Wed, 24 Jan 2007 12:33:24 -0800 (PST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=uY/KTXvWJ4qvUW0YuUUnEDNSRNStYZ1AkHF7O4p5bQXjsmU+rh992C5KYpFxlv/0QNcVzCti/21DsUiHzC7Zp7aGi0VEth1g+Ce9hlhlueEjUDzx5NqjGUCax2RsKMkrgd9s+RE6/cOzdpKvE07YdNEyWsXrm9NfGLYXIiGslhU= Received: by 10.82.105.13 with SMTP id d13mr491404buc.1169670803764; Wed, 24 Jan 2007 12:33:23 -0800 (PST) Received: by 10.82.161.3 with HTTP; Wed, 24 Jan 2007 12:33:23 -0800 (PST) Message-ID: <1f30b80c0701241233m6be5c9ffj38be2d10e4875e82@mail.gmail.com> Date: Thu, 25 Jan 2007 01:33:23 +0500 From: imad To: "Feng Chen" Subject: Re: Postgres Stored Procedure Call Function Return Type OID Caching Problem Cc: pgsql-odbc@postgresql.org In-Reply-To: <0D1719326D64BD4E9F92A0C1202376780192A28C@eserv.covergence.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_15665_9280144.1169670803547" References: <0D1719326D64BD4E9F92A0C1202376780192A257@eserv.covergence.com> <1f30b80c0701241150h597ae274wb10265fa29921386@mail.gmail.com> <0D1719326D64BD4E9F92A0C1202376780192A28C@eserv.covergence.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200701/57 X-Sequence-Number: 8596 ------=_Part_15665_9280144.1169670803547 Content-Type: text/plain; charset=WINDOWS-1252; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Well, there is somehow you are dropping the type and recreating it without updating the function? BTW, are you sure about these states of pg_proc and pg_type? Are you sure you drop the custom type always using the CASCADE keyword? --Imad www.EnterpriseDB.com On 1/25/07, Feng Chen wrote: > > Hi Imad, > > > > The problem is that I should not have to and cannot re-load the functions > every now and then. Why would the type id change and the function still > references to the old type id thus fails to get the right results? > > > > FC > > > ------------------------------ > > *From:* imad [mailto:immaad@gmail.com] > *Sent:* Wednesday, January 24, 2007 2:51 PM > *To:* Feng Chen > *Cc:* pgsql-odbc@postgresql.org > *Subject:* Re: [ODBC] Postgres Stored Procedure Call Function Return Type > OID Caching Problem > > > > You are not looking at the right type OID. 34487 is not the type oid, its > the OID of the corresponding implicit relation. > The problem is the compiled state of your function which persists for > performance reasons. You told yourself that this error goes away when you > recreate the function. > > --Imad > www.EnterpriseDB.com > > On 1/25/07, *Feng Chen* wrote: > > Hello, > > > > > > I'm wondering if anyone has experienced the same problem and is it fixed = in the new Postgres release (We use Posgtgres 8.1.2, psqlodbc.so 7.2.5 (mov= ing to 8.2.200), unixODBC 2.2.11 (moving to > > 2.2.12), running on Linux OS.): > > > > We have a recurring problem that the return type (a customer defined type= ) was changed somehow, which resulted in a failure: lookup for that type fa= iled when trying to call that function. > > > > Specifically, we have a file defining the following type and function. It= is loaded at the start of the Postgres start time and the function then is= called many times. > > > > drop type type_foo cascade; > > > CREATE TYPE type_foo AS > ( > =85=85 > > =85=85 > > > ); > > > > CREATE OR REPLACE FUNCTION sp_foo(int4, int4 , text, text , text , text, > text , text) > RETURNS SETOF type_foo AS > $BODY$ > DECLARE > temp_row type_foo ; /** the type of data to be returned **/ > insert_statement text; /** placeholder for populating the page **/ > BEGIN > > > /** create a temp table to put everything in **/ > EXECUTE 'CREATE TEMP TABLE temp_foo_page > ( > =85=85 > > =85=85 > > ) '; > > /** build the insert statement to load initial values from > cxcsession **/ > insert_statement =3D 'INSERT INTO temp_foo_page SELECT * from bar > where ( date( "timestamp" ) =3D date( ''' || DATE_TO_USE || ''' )) ' ; > > =85=85 > > =85=85 > > > /** execute the select **/ > EXECUTE insert_statement; > > /** return the result set **/ > FOR temp_row IN EXECUTE 'SELECT * FROM temp_foo_page order by "' || > SORT_COLUMN || '" desc ' > LOOP > RETURN NEXT temp_row ; > END LOOP; > > /** drop the table we no longer need **/ > EXECUTE 'drop table temp_foo_page '; > > END; > $BODY$ > LANGUAGE 'plpgsql' VOLATILE; > ALTER FUNCTION sp_foo(int4, int4 , text, text , text , text, text , text) > OWNER TO postgres; > > > > The problem after a period of time (10 days or so not consistent), functi= on sp_foo referenced an oid for an old return type that no longer existed. = We had to explicitly drop the function sp_foo reload from the SQL source fi= le to correct the problem. > > > > I knew that there was a bug of Postgres with sp functions caching the tem= p table ids, and there is a temp table used in this function, but the probl= em is with the type id changing underneath: > > > > Here is the results of system tables query. The oid 25266 no longer exist= s and the current type oid is somehow changed to 34487??? > > > > # select prorettype, proname from pg_proc where proname like 'sp_%'; > > prorettype | proname > > > > 16450 | sp_session > > 25226 | sp_foo > > > > 25 | sp_resolve > > =85=85 > > (12 rows) > > > > > > > > spotlite=3D# select * from pg_type where typname =3D 'type_foo'; > > typname | typnamespace | typowner | typlen | typbyval | typt= ype | > > t > > ypisdefined | typdelim | typrelid | typelem | typinput | typoutput | > > typreceiv > > e | typsend | typanalyze | typalign | typstorage | typnotnull | > > typbasetype > > | typtypmod | typndims | typdefaultbin | typdefault > > ---------------------+--------------+----------+--------+----------+-----= ----+- > > > > - > > ------------+----------+----------+---------+-----------+------------+---= ------ > > - > > ---+-------------+------------+----------+------------+------------+-----= ------ > > - > > -+-----------+----------+---------------+------------ > > type_foo | 2200 | 10 | -1 | f | c | > > > > t > > | , | 34487 | 0 | record_in | record_out | > > > > record_re > > cv | record_send | - | d | x | f | > > 0 > > | -1 | 0 | | > > (1 row) > > > > > > Any help would be greatly appreciated! > > > > FC > > > ------=_Part_15665_9280144.1169670803547 Content-Type: text/html; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Well, there is somehow you are dropping the type and recreating it without = updating the function?
BTW, are you sure about these states of pg_proc a= nd pg_type? Are you sure you drop the custom type
always using the CASCA= DE keyword?

--Imad
www.EnterpriseDB.= com


On 1/25/07, Feng Chen <fchen@covergence.com > wrote:

Hi Imad,

 

The problem is that I should not h= ave to and cannot re-load the functions every now and then. Why would the type id chan= ge and the function still references to the old type id thus fails to get the right results?

 

FC

 


From: im= ad [mailto:immaad@gmail.com]
Sent: Wednesday, January 2= 4, 2007 2:51 PM
To: Feng Chen
Cc: pgsql-odbc@postgresql.org
Subject: Re: [ODBC] Postgr= es Stored Procedure Call Function Return Type OID Caching Problem

 

You are not looking at the right type OID. 34487 is not the type oid, its the OID of the correspon= ding implicit relation.
The problem is the compiled state of your function which persists for performance reasons. You told yourself that this error goes away when you recreate the function.

--Imad
www.EnterpriseDB.com

On 1/25/07, Feng Chen <fchen@covergenc= e.com > wrote:

Hello,
=
 

 
I'm wonder=
ing if anyone has experienced the same problem and is it fixed in the new P=
ostgres release (We use Posgtgres=20
8.1.2, psqlodbc.so 7.2.5 (moving to 8.2.200), unixODBC 2.2.11 (moving to 
2.2.12), running on Linux OS.):
=

 
We have a recu=
rring problem that the return type (a customer defined type) was changed so=
mehow, which resulted in a failure: lookup for that type failed when trying=
 to call that function.
 
Specifically, we have a fi=
le defining the following type and function. It is loaded at the start of t=
he Postgres start time and the function then is called many times.
 

&= nbsp;     drop type type_foo cascade;

<= br>       CREATE TYPE type_foo AS
      (
            =85=85

=85=85


);

 

C= REATE OR REPLACE FUNCTION sp_foo(int4, int4 , text, text , text , text, text , text)
  RETURNS SETOF type_foo AS
$BODY$
  DECLARE
      temp_row type_foo ; /** the type of data to = be returned **/
      insert_statement text; /** placeholder for populating the page **/
   BEGIN


        /** create a temp table to put everything in **/
        EXECUTE 'CREATE TEMP TABLE t= emp_foo_page
        (
            =85=85

=85=85

&= nbsp;       ) ';

       /** build the insert statement to load initial values from cxcsession **/
       insert_statement =3D 'INSERT INTO temp_foo_page SELECT * from bar where  ( date( "timestamp" ) =3D  date( ''' || DATE_TO_USE || ''' )) ' = ;

            =85=85

=85=85


       /** execute the select **/
       EXECUTE insert_statement;

      /** return the result set **/
      FOR temp_row IN EXECUTE 'SELECT * FROM temp_foo_page order by "' || SORT_COLUMN || '" desc '=
      LOOP
          RETURN NEXT temp_row= ;
      END LOOP;

      /** drop the table we no longer need **/
      EXECUTE 'drop table temp_foo_page ';=

END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;
ALTER FUNCTION sp_foo(int4, int4 , text, text , text , text, text , text) O= WNER TO postgres;

 
The problem after a period of time (10 days or =
so not consistent), function sp_foo referenced an oid for an old return typ=
e that no longer existed. We had to explicitly drop the function sp_foo rel=
oad from the SQL source file to correct the problem.
 
I knew that there was a bu=
g of Postgres with sp functions caching the temp table ids, and there is a =
temp table used in this function, but the problem is with the type id chang=
ing underneath:
 
Here is the results of sys=
tem tables query. The oid 25266 no longer exists and the current type oid i=
s somehow changed to 34487???
 
# select prorettype, prona=
me from pg_proc where proname like 'sp_%';
 prorettype |      &nbs=
p;            &=
nbsp;   proname

 
      16450 | sp_sessio=
n
      25226 | sp_foo
 
    &n=
bsp;    25 | sp_resolve
=85=85
(12 rows)

 
 <=
/font>
 
spotlite=3D# select * from pg_type where typname =3D 'typ=
e_foo';
<=
span style=3D"font-size: 10pt;">
       typname     &=
nbsp; | typnamespace | typowner | typlen | typbyval | typtype | 
t

ypisdefined | typdelim | typrelid | typele=
m | typinput  | typoutput  | 
typreceiv
e  |   typsend   | typanalyze | typalign | typsto=
rage | typnotnull | 

typbasetype
<=
span style=3D"font-size: 10pt;"> | typtypmod | typndims | typdefaultbin | t=
ypdefault

---------------------+--------------+----------+--------+----------+-------=
--+-
 

-
------------+-------=
---+----------+---------+-----------+------------+---------
-
---+-------------+------------+----------+----------=
--+------------+-----------
-
-+-----------+----------+------=
---------+------------
 type_foo |       =
  2200 |       10 |   &nb=
sp; -1 | f        | c   &=
nbsp;   | 

 
t
    &n=
bsp;       | ,     &=
nbsp;  |    34487 |      =
 0 | record_in | record_out |=20
 
record_re

cv | record_send | -   &nbs=
p;      | d      &nb=
sp; | x          | f &nbs=
p;        |     =
;      
0
 |        -1 |    &=
nbsp;   0 |         =
      |
(1 row)
 

 

Any help would be greatly appreciated!

 

FC

 


------=_Part_15665_9280144.1169670803547--