Graphical representation of query plans

Started by Viktor Rosenfeldalmost 17 years ago17 messagesgeneral
Jump to latest
#1Viktor Rosenfeld
rosenfel@informatik.hu-berlin.de

Hi everybody,

is there a (stand-alone, command line) tool that converts the output
of EXPLAIN ANALYZE into a tree-like representation of the plan?

Cheers,
Viktor

#2Grzegorz Jaśkiewicz
gryzman@gmail.com
In reply to: Viktor Rosenfeld (#1)
Re: Graphical representation of query plans
#3Viktor Rosenfeld
rosenfel@informatik.hu-berlin.de
In reply to: Grzegorz Jaśkiewicz (#2)
Re: Graphical representation of query plans

Thank you, this does indeed look very nice.

I would still be interested in alternatives, though. Specifically, I
want to be able to quickly see the cost of query subplans á la http://explain-analyze.inf
o. A tool that outputs a dot file or something which I can further
edit would also work.

Cheers,
Viktor

Am 22.06.2009 um 14:04 schrieb Grzegorz Jaśkiewicz:

Show quoted text

pgadmin does it pretty nicely:
http://pgadmin.org/images/screenshots/pgadmin3_macosx.png

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

#4Dragan Sahpaski
dragan.sahpaskix@gmail.com
In reply to: Viktor Rosenfeld (#3)
Re: Graphical representation of query plans

Viktor Rosenfeld wrote:

Thank you, this does indeed look very nice.

I would still be interested in alternatives, though. Specifically, I
want to be able to quickly see the cost of query subplans á la
http://explain-analyze.info. A tool that outputs a dot file or
something which I can further edit would also work.

Cheers,
Viktor

Am 22.06.2009 um 14:04 schrieb Grzegorz Jaśkiewicz:

pgadmin does it pretty nicely:
http://pgadmin.org/images/screenshots/pgadmin3_macosx.png

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

http://explain.depesz.com/

Regards

#5Viktor Rosenfeld
rosenfel@informatik.hu-berlin.de
In reply to: Dragan Sahpaski (#4)
Re: Graphical representation of query plans

Much better than explain-analyze.info

Many thanks!

Am 23.06.2009 um 11:25 schrieb Dragan Sahpaski:

Show quoted text

Viktor Rosenfeld wrote:

Thank you, this does indeed look very nice.

I would still be interested in alternatives, though. Specifically,
I want to be able to quickly see the cost of query subplans á la http://explain-analyze.inf
o. A tool that outputs a dot file or something which I can further
edit would also work.

Cheers,
Viktor

Am 22.06.2009 um 14:04 schrieb Grzegorz Jaśkiewicz:

pgadmin does it pretty nicely:
http://pgadmin.org/images/screenshots/pgadmin3_macosx.png

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

http://explain.depesz.com/

Regards

#6Hartman, Matthew
Matthew.Hartman@krcc.on.ca
In reply to: Viktor Rosenfeld (#5)
Explaining functions.

Is there a recommended approach when trying to use EXPLAIN on a
function? Specifically, a function that is more than the typical SELECT
statement or tiny loop. The one in question that I'm hoping to optimize
is around 250 lines.

Thanks,

Matthew Hartman
Programmer/Analyst
Information Management, ICP
Kingston General Hospital
(613) 549-6666 x4294

#7Merlin Moncure
mmoncure@gmail.com
In reply to: Hartman, Matthew (#6)
Re: Explaining functions.

On Tue, Jun 23, 2009 at 8:03 AM, Hartman,
Matthew<Matthew.Hartman@krcc.on.ca> wrote:

Is there a recommended approach when trying to use EXPLAIN on a
function? Specifically, a function that is more than the typical SELECT
statement or tiny loop. The one in question that I'm hoping to optimize
is around 250 lines.

What I normally do for benchmarking of complex functions is to
sprinkle the source with "raise notice '%', timeofday();" to figure
out where the bottlenecks are. Following that, I micro-optimize
problem queries or expressions outside of the function body in psql.

merlin

#8Hartman, Matthew
Matthew.Hartman@krcc.on.ca
In reply to: Merlin Moncure (#7)
Re: Explaining functions.

Heeeey the raise notice is a good idea, thanks. I use raise notice
already for other uses, may as well go with it. Thanks.

Matthew Hartman
Programmer/Analyst
Information Management, ICP
Kingston General Hospital
(613) 549-6666 x4294

-----Original Message-----
From: Merlin Moncure [mailto:mmoncure@gmail.com]
Sent: Tuesday, June 23, 2009 9:20 AM
To: Hartman, Matthew
Cc: pgsql-general@postgresql.org
Subject: Re: [GENERAL] Explaining functions.

On Tue, Jun 23, 2009 at 8:03 AM, Hartman,
Matthew<Matthew.Hartman@krcc.on.ca> wrote:

Is there a recommended approach when trying to use EXPLAIN on a
function? Specifically, a function that is more than the typical

SELECT

statement or tiny loop. The one in question that I'm hoping to

optimize

is around 250 lines.

What I normally do for benchmarking of complex functions is to
sprinkle the source with "raise notice '%', timeofday();" to figure
out where the bottlenecks are. Following that, I micro-optimize
problem queries or expressions outside of the function body in psql.

merlin

#9Tom Lane
tgl@sss.pgh.pa.us
In reply to: Merlin Moncure (#7)
Re: Explaining functions.

Merlin Moncure <mmoncure@gmail.com> writes:

On Tue, Jun 23, 2009 at 8:03 AM, Hartman,
Matthew<Matthew.Hartman@krcc.on.ca> wrote:

Is there a recommended approach when trying to use EXPLAIN on a
function? Specifically, a function that is more than the typical SELECT
statement or tiny loop. The one in question that I'm hoping to optimize
is around 250 lines.

What I normally do for benchmarking of complex functions is to
sprinkle the source with "raise notice '%', timeofday();" to figure
out where the bottlenecks are. Following that, I micro-optimize
problem queries or expressions outside of the function body in psql.

There was some discussion once of using the same infrastructure the
plpgsql debugger uses to build a plpgsql profiler. That would help
automate the first part of this, at least. Anybody know the status
of that project?

regards, tom lane

#10Dave Page
dpage@pgadmin.org
In reply to: Tom Lane (#9)
Re: Explaining functions.

On Tue, Jun 23, 2009 at 3:04 PM, Tom Lane<tgl@sss.pgh.pa.us> wrote:

Merlin Moncure <mmoncure@gmail.com> writes:

On Tue, Jun 23, 2009 at 8:03 AM, Hartman,
Matthew<Matthew.Hartman@krcc.on.ca> wrote:

Is there a recommended approach when trying to use EXPLAIN on a
function? Specifically, a function that is more than the typical SELECT
statement or tiny loop. The one in question that I'm hoping to optimize
is around 250 lines.

What I normally do for benchmarking of complex functions is to
sprinkle the source with "raise notice '%', timeofday();" to figure
out where the bottlenecks are.  Following that, I micro-optimize
problem queries or expressions outside of the function body in psql.

There was some discussion once of using the same infrastructure the
plpgsql debugger uses to build a plpgsql profiler.  That would help
automate the first part of this, at least.  Anybody know the status
of that project?

There is a profiler in the debugger source tree. Iirc, it dumps it's
data out to an XML in a not-so-friendly manner. I haven't ever tested
it, so it may have been broken since Korry handed it over.

http://pgfoundry.org/scm/?group_id=1000175

--
Dave Page
EnterpriseDB UK: http://www.enterprisedb.com

#11Chris Spotts
rfusca@gmail.com
In reply to: Hartman, Matthew (#8)
Re: Explaining functions.

is around 250 lines.

What I normally do for benchmarking of complex functions is to
sprinkle the source with "raise notice '%', timeofday();" to figure
out where the bottlenecks are. Following that, I micro-optimize
problem queries or expressions outside of the function body in psql.

[Spotts, Christopher]
I use this set of functions towards this end, sprinkled about...
I'm sure there are better ways to write it,but it works.

CREATE OR REPLACE FUNCTION set_var(name text, val text) RETURNS text AS $$
if ($_SHARED{$_[0]} = $_[1]) {
return 'ok';
} else {
return "cannot set shared variable $_[0] to $_[1]";
}
$$ LANGUAGE plperl;

CREATE OR REPLACE FUNCTION get_var(name text) RETURNS text AS $$
return $_SHARED{$_[0]};
$$ LANGUAGE plperl;

CREATE OR REPLACE FUNCTION time_between_calls() RETURNS interval AS $$
DECLARE
ot text;
BEGIN
ot := get_var('calltime');
PERFORM set_var('calltime',timeofday());
RETURN timeofday():: timestamp - ot :: timestamp;
END;
$$ LANGUAGE plpgsql;

CREATE OR REPLACE FUNCTION start_time_between_calls() RETURNS void AS $$
BEGIN
PERFORM set_var('calltime',timeofday());
END;
$$ LANGUAGE plpgsql;

CREATE OR REPLACE FUNCTION test() RETURNS void AS $$
BEGIN
PERFORM start_time_between_calls();
raise notice '%',time_between_calls();
PERFORM pg_sleep(3);
raise notice '%',time_between_calls();
END
$$ LANGUAGE plpgsql;

#12Hartman, Matthew
Matthew.Hartman@krcc.on.ca
In reply to: Chris Spotts (#11)
Re: Explaining functions.

Thanks! That'll reduce the amount of copy/pasting I have to do to figure
out the differences in times.

Matthew Hartman
Programmer/Analyst
Information Management, ICP
Kingston General Hospital
(613) 549-6666 x4294

-----Original Message-----
From: Chris Spotts [mailto:rfusca@gmail.com]
Sent: Tuesday, June 23, 2009 10:48 AM
To: Hartman, Matthew; 'Merlin Moncure'
Cc: pgsql-general@postgresql.org
Subject: RE: [GENERAL] Explaining functions.

is around 250 lines.

What I normally do for benchmarking of complex functions is to
sprinkle the source with "raise notice '%', timeofday();" to figure
out where the bottlenecks are. Following that, I micro-optimize
problem queries or expressions outside of the function body in psql.

[Spotts, Christopher]
I use this set of functions towards this end, sprinkled about...
I'm sure there are better ways to write it,but it works.

CREATE OR REPLACE FUNCTION set_var(name text, val text) RETURNS text AS
$$
if ($_SHARED{$_[0]} = $_[1]) {
return 'ok';
} else {
return "cannot set shared variable $_[0] to $_[1]";
}
$$ LANGUAGE plperl;

CREATE OR REPLACE FUNCTION get_var(name text) RETURNS text AS $$
return $_SHARED{$_[0]};
$$ LANGUAGE plperl;

CREATE OR REPLACE FUNCTION time_between_calls() RETURNS interval AS $$
DECLARE
ot text;
BEGIN
ot := get_var('calltime');
PERFORM set_var('calltime',timeofday());
RETURN timeofday():: timestamp - ot :: timestamp;
END;
$$ LANGUAGE plpgsql;

CREATE OR REPLACE FUNCTION start_time_between_calls() RETURNS void AS $$

BEGIN
PERFORM set_var('calltime',timeofday());
END;
$$ LANGUAGE plpgsql;

CREATE OR REPLACE FUNCTION test() RETURNS void AS $$
BEGIN
PERFORM start_time_between_calls();
raise notice '%',time_between_calls();
PERFORM pg_sleep(3);
raise notice '%',time_between_calls();
END
$$ LANGUAGE plpgsql;

#13Greg Smith
gsmith@gregsmith.com
In reply to: Hartman, Matthew (#6)
Re: Explaining functions.

On Tue, 23 Jun 2009, Hartman, Matthew wrote:

Is there a recommended approach when trying to use EXPLAIN on a
function? Specifically, a function that is more than the typical SELECT
statement or tiny loop. The one in question that I'm hoping to optimize
is around 250 lines.

Take a look at
http://www.justatheory.com/computers/databases/postgresql/benchmarking_functions.html
which can help you run stuff multiple times even.

--
* Greg Smith gsmith@gregsmith.com http://www.gregsmith.com Baltimore, MD

#14Emi Lu
emilu@encs.concordia.ca
In reply to: Grzegorz Jaśkiewicz (#2)
Re: Graphical representation of query plans

Grzegorz Jaśkiewicz wrote:

pgadmin does it pretty nicely:
http://pgadmin.org/images/screenshots/pgadmin3_macosx.png

As shown in the mackintosh version, it is a very nice and helpful feature!

I have pgadmin 1.2.0 for PostgreSQL 8.0.15 on i686-pc-linux-gnu,
compiled by GCC gcc (GCC) 3.3.2.

I did not see this "explain" in my version. I only have "Data Output,
Message, and History".

May I know in which pgadmin version the "query plan visualization" was
added please?

Did not see it from pgadmin online doc either?

Thanks a lot!

--
Ying Lu

In reply to: Emi Lu (#14)
Re: Graphical representation of query plans

On 22/09/2009 21:48, Emi Lu wrote:

Grzegorz Jaśkiewicz wrote:

pgadmin does it pretty nicely:
http://pgadmin.org/images/screenshots/pgadmin3_macosx.png

As shown in the mackintosh version, it is a very nice and helpful feature!

I have pgadmin 1.2.0 for PostgreSQL 8.0.15 on i686-pc-linux-gnu,
compiled by GCC gcc (GCC) 3.3.2.

That's a *really* old version - pgAdmin is up to 1.10 now, and it's well
worth your while upgrading. 8.0 is a really old version of PG too....

Ray.

------------------------------------------------------------------
Raymond O'Donnell, Director of Music, Galway Cathedral, Ireland
rod@iol.ie
Galway Cathedral Recitals: http://www.galwaycathedral.org/recitals
------------------------------------------------------------------

#16Guillaume Lelarge
guillaume@lelarge.info
In reply to: Emi Lu (#14)
Re: Graphical representation of query plans

Le mardi 22 septembre 2009 à 22:48:57, Emi Lu a écrit :

Grzegorz Jaśkiewicz wrote:

pgadmin does it pretty nicely:
http://pgadmin.org/images/screenshots/pgadmin3_macosx.png

As shown in the mackintosh version, it is a very nice and helpful feature!

I have pgadmin 1.2.0 for PostgreSQL 8.0.15 on i686-pc-linux-gnu,
compiled by GCC gcc (GCC) 3.3.2.

I did not see this "explain" in my version. I only have "Data Output,
Message, and History".

May I know in which pgadmin version the "query plan visualization" was
added please?

At least, 1.4 has it.

Did not see it from pgadmin online doc either?

http://www.pgadmin.org/docs/dev/query.html

--
Guillaume.
http://www.postgresqlfr.org
http://dalibo.com

#17Emi Lu
emilu@encs.concordia.ca
In reply to: Guillaume Lelarge (#16)
Re: Graphical representation of query plans

pgadmin does it pretty nicely:
http://pgadmin.org/images/screenshots/pgadmin3_macosx.png

As shown in the mackintosh version, it is a very nice and helpful feature!

I have pgadmin 1.2.0 for PostgreSQL 8.0.15 on i686-pc-linux-gnu,
compiled by GCC gcc (GCC) 3.3.2.

I did not see this "explain" in my version. I only have "Data Output,
Message, and History".

May I know in which pgadmin version the "query plan visualization" was
added please?

At least, 1.4 has it.

Did not see it from pgadmin online doc either?

http://www.pgadmin.org/docs/dev/query.html

That's great! It is exactly what I am looking for!

Thanks a lot!

--
Lu Ying