pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: mallah@trade-india.com
To: pmarian@cnlo.ro
Cc: pgsql-sql@postgresql.org
Subject: Re: explain
Date: Fri, 21 Mar 2003 22:02:11 +0530 (IST)
Message-ID: <1114.219.65.253.113.1048264331.squirrel@mail.trade-india.com> (raw)



Popeanga  ,

Its basically possible to get the info programatically.
see below is an example perl code that is getting the
plan data:

############### file test.pl #################

#!/usr/bin/perl

use DBI;
$dbh = DBI->connect('dbi:Pg:dbname=rmallah' , '','');
$your_query_here= 'select * from test';
$rows = $dbh -> selectall_arrayref("EXPLAIN ANALYZE $your_query_here");
foreach (@$rows) {
        print "$_->[0]\n";
}
$dbh -> disconnect();
#############################################

on running you get:

[rmallah@subho rmallah]$ ./test.pl
Seq Scan on test  (cost=0.00..20.00 rows=1000 width=32) (actual time=0.02..0.05 rows=11 loops=1)
Total runtime: 0.19 msec

But be careful abt explain analyzing
queries that potentially modify data. (read more on docs of EXPLAIN)
we have to put the explain analyze in a transaction block which
shud eventually be rollbacked.

now that you have seen how to get lines of output from EXPLAIN using/hadling this
data is upto you application.

also note that the last like of EXPLAIN analyze carries  the runtime.

hope it helps
Mallah.






-----------------------------------------
Get your free web based email at trade-india.com.
   "India's Leading B2B eMarketplace.!"
http://www.trade-india.com/





view thread (13+ messages)  latest in thread

Message-ID: <1114.219.65.253.113.1048264331.squirrel@mail.trade-india.com>
Permalink:  ../1114.219.65.253.113.1048264331.squirrel@mail.trade-india.com/
Also on:    postgresql.org/message-id/1114.219.65.253.113.1048264331.squirrel@mail.trade-india.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: mallah@trade-india.com, pmarian@cnlo.ro
  Subject: Re: explain
  In-Reply-To: <1114.219.65.253.113.1048264331.squirrel@mail.trade-india.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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