Re: explain

From: <mallah(at)trade-india(dot)com>
To: <pmarian(at)cnlo(dot)ro>
Cc: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: explain
Date: 2003-03-21 16:32:11
Message-ID: 1114.219.65.253.113.1048264331.squirrel@mail.trade-india.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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(at)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/

Responses

  • Re: explain at 2003-03-22 06:11:11 from Popeanga Marian

Browse pgsql-sql by date

  From Date Subject
Next Message Dan Winslow 2003-03-21 17:41:29 Diffcult query
Previous Message Dan Winslow 2003-03-21 15:51:40 Seeking help with a query....