Unix Technical Forum

=?KOI8-R?Q?Get execution plan of dynamic query?=

This is a discussion on =?KOI8-R?Q?Get execution plan of dynamic query?= within the Pgsql General forums, part of the PostgreSQL category; --> How to get results of EXPLAIN of dynamic query maked up in PL/PGSQL function? I found option 'debug_print_plan', but ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql General

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-08-2008, 06:45 PM
=?KOI8-R?Q?=E1=CC=C5=CB=D3=C5=CA =FB.?=
 
Posts: n/a
Default =?KOI8-R?Q?Get execution plan of dynamic query?=

How to get results of EXPLAIN of dynamic query maked up in PL/PGSQL function?
I found option 'debug_print_plan', but it produces incomprehensible output. Is there an option to dump execution plan in EXPLAIN format?

EXPLAIN return generic result set in client application, as 'SELECT' command do. But in PL/PGSQL function
FOR rec IN EXPLAIN query_text LOOP ...
and
FOR rec IN EXECUTE('EXPLAIN '||query_text) LOOP ...
both failed with error "cannot open non-SELECT query as cursor".

I can receive EXPLAIN results through
select * from dblink('EXPLAIN '||query_text) (query_plan text)
but it doesn't work if queries use temporary tables.

PL/Perl function spi_exec_query('EXPLAIN select ...') returns no rows and status=SPI_OK_UTILITY (PostgreSQL 8.0.0rc1 on i686-pc-mingw32).

Is it another way?


---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-08-2008, 06:45 PM
Tom Lane
 
Posts: n/a
Default Re: =?KOI8-R?Q?Get execution plan of dynamic query?=

"=?KOI8-R?Q?=E1=CC=C5=CB=D3=C5=CA =FB.?=" <savbr@rin.ru> writes:
> How to get results of EXPLAIN of dynamic query maked up in PL/PGSQL function?


Pretend that it's a prepared statement.

For example, if your plpgsql function has

declare x int;
y int;
begin
...
select f1 into x from tab1 where f2 = y;

then this will show the same plan as plpgsql will be using:

prepare foo(int) as select f1 from tab1 where f2 = $1;

explain analyze execute foo(42);

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 12:47 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com