pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #8046: PL/pgSQL plan caching regression
3+ messages / 3 participants
[nested] [flat]

* BUG #8046: PL/pgSQL plan caching regression
@ 2013-04-08 21:33  dmitigr@gmail.com
  0 siblings, 1 reply; 3+ messages in thread

From: dmitigr@gmail.com @ 2013-04-08 21:33 UTC (permalink / raw)
  To: pgsql-bugs

The following bug has been logged on the website:

Bug reference:      8046
Logged by:          Dmitriy Igrishin
Email address:      dmitigr@gmail.com
PostgreSQL version: 9.2.4
Operating system:   Linux Debian Wheezy x64
Description:        

-- -*- sql -*-
-- A bug test case.
-- PostgreSQL 9.2.4 on x86_64-unknown-linux-gnu, compiled by gcc (Debian
4.7.2-5) 4.7.2, 64-bit

BEGIN;

CREATE OR REPLACE FUNCTION rec(type_name_ regclass, id_ bigint)
 RETURNS record
 LANGUAGE plpgsql
 STABLE
AS $function$
DECLARE
  r_ record;
BEGIN
  EXECUTE 'SELECT * FROM '||type_name_::text||' WHERE id = $1'
    INTO r_ USING id_;

  RAISE NOTICE '%', pg_typeof(r_.id);

  RETURN r_;
END;
$function$;

CREATE TABLE t1 (id integer);
CREATE TABLE t2 (id bigint);

SELECT rec('t1', 1); -- NOTICE:  integer
SELECT rec('t2', 2); -- Should NOTICE:  bigint, but RAISE ERROR:  type of
parameter 5 (bigint) does not match that when preparing the plan (integer)

ROLLBACK;




-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #8046: PL/pgSQL plan caching regression
@ 2013-04-08 23:23  Tom Lane <tgl@sss.pgh.pa.us>
  parent: dmitigr@gmail.com
  0 siblings, 1 reply; 3+ messages in thread

From: Tom Lane @ 2013-04-08 23:23 UTC (permalink / raw)
  To: dmitigr@gmail.com; +Cc: pgsql-bugs

dmitigr@gmail.com writes:
> CREATE OR REPLACE FUNCTION rec(type_name_ regclass, id_ bigint)
>  RETURNS record
>  LANGUAGE plpgsql
>  STABLE
> AS $function$
> DECLARE
>   r_ record;
> BEGIN
>   EXECUTE 'SELECT * FROM '||type_name_::text||' WHERE id = $1'
>     INTO r_ USING id_;

>   RAISE NOTICE '%', pg_typeof(r_.id);

>   RETURN r_;
> END;
> $function$;

> CREATE TABLE t1 (id integer);
> CREATE TABLE t2 (id bigint);

> SELECT rec('t1', 1); -- NOTICE:  integer
> SELECT rec('t2', 2); -- Should NOTICE:  bigint, but RAISE ERROR:  type of
> parameter 5 (bigint) does not match that when preparing the plan (integer)

What's your grounds for calling that a regression?  It's always worked
like that, or at least back to 8.4 which is as far as I checked (since
pg_typeof didn't exist before that).  The fine manual documents the
problem thus:

	The mutable nature of record variables presents another problem
	in this connection. When fields of a record variable are used in
	expressions or statements, the data types of the fields must not
	change from one call of the function to the next, since each
	expression will be analyzed using the data type that is present
	when the expression is first reached. EXECUTE can be used to get
	around this problem when necessary.

We might think of a nicer solution sooner or later, but don't hold your
breath (and don't expect it to be back-patched into released branches).

			regards, tom lane


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #8046: PL/pgSQL plan caching regression
@ 2013-04-09 06:37  Dmitriy Igrishin <dmitigr@gmail.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 3+ messages in thread

From: Dmitriy Igrishin @ 2013-04-09 06:37 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-bugs

2013/4/9 Tom Lane <tgl@sss.pgh.pa.us>

> dmitigr@gmail.com writes:
> > CREATE OR REPLACE FUNCTION rec(type_name_ regclass, id_ bigint)
> >  RETURNS record
> >  LANGUAGE plpgsql
> >  STABLE
> > AS $function$
> > DECLARE
> >   r_ record;
> > BEGIN
> >   EXECUTE 'SELECT * FROM '||type_name_::text||' WHERE id = $1'
> >     INTO r_ USING id_;
>
> >   RAISE NOTICE '%', pg_typeof(r_.id);
>
> >   RETURN r_;
> > END;
> > $function$;
>
> > CREATE TABLE t1 (id integer);
> > CREATE TABLE t2 (id bigint);
>
> > SELECT rec('t1', 1); -- NOTICE:  integer
> > SELECT rec('t2', 2); -- Should NOTICE:  bigint, but RAISE ERROR:  type of
> > parameter 5 (bigint) does not match that when preparing the plan
> (integer)
>
> What's your grounds for calling that a regression?  It's always worked
> like that, or at least back to 8.4 which is as far as I checked (since
> pg_typeof didn't exist before that).  The fine manual documents the
> problem thus:
>
>         The mutable nature of record variables presents another problem
>         in this connection. When fields of a record variable are used in
>         expressions or statements, the data types of the fields must not
>         change from one call of the function to the next, since each
>         expression will be analyzed using the data type that is present
>         when the expression is first reached. EXECUTE can be used to get
>         around this problem when necessary.
>
Oops, I am sorry, it's documented indeed. It was too late tomorrow and I was
sure that variables (including record variables) are function-scoped,
rather than
session-scoped. (Which is natural.) So I was confused.


-- 
// Dmitriy.

^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2013-04-09 06:37 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2013-04-08 21:33 BUG #8046: PL/pgSQL plan caching regression dmitigr@gmail.com
2013-04-08 23:23 ` Tom Lane <tgl@sss.pgh.pa.us>
2013-04-09 06:37   ` Dmitriy Igrishin <dmitigr@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox