Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 229BCB5DC02 for ; Sun, 10 Jul 2011 16:21:12 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 26640-02; Sun, 10 Jul 2011 19:21:05 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pz0-f46.google.com (mail-pz0-f46.google.com [209.85.210.46]) by mail.postgresql.org (Postfix) with ESMTP id 0FAA3B5DC01; Sun, 10 Jul 2011 16:21:04 -0300 (ADT) Received: by pzk9 with SMTP id 9so2555400pzk.19 for ; Sun, 10 Jul 2011 12:21:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:subject:date:user-agent:cc:references:in-reply-to :mime-version:content-type:content-transfer-encoding:message-id; bh=6NQEfDNIkLTj4VQlyvv9BZ2GGL1r4qGKibLix0xZio0=; b=RB7YKEqqCP4KunRPJadf2eTUOoOqk6btg3NOWNybl8STY2rM5HBEShE5lE69wTJ9CY RlvpncTxnqC2HuNhWKHYGopUYbXAxvya1LWmy2jcFK2mubEnGhsZFmT+GVWynbzzOP4K 2RdJvZ8t+iwoninktJx3xOjT8L8Q7MGKefPgo= Received: by 10.68.68.98 with SMTP id v2mr4537081pbt.487.1310325663401; Sun, 10 Jul 2011 12:21:03 -0700 (PDT) Received: from tucker.localnet (c-24-17-164-54.hsd1.wa.comcast.net [24.17.164.54]) by mx.google.com with ESMTPS id q5sm7917637pbk.10.2011.07.10.12.21.01 (version=SSLv3 cipher=OTHER); Sun, 10 Jul 2011 12:21:02 -0700 (PDT) From: Adrian Klaver To: pgsql-sql@postgresql.org Subject: Re: [SQL] using explain output within pgsql Date: Sun, 10 Jul 2011 12:20:58 -0700 User-Agent: KMail/1.13.5 (Linux/2.6.32-32-generic; KDE/4.4.5; i686; ; ) Cc: Uwe Bartels , pgsql-admin@postgresql.org References: In-Reply-To: MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-15" Content-Transfer-Encoding: quoted-printable Message-Id: <201107101220.59167.adrian.klaver@gmail.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.889 tagged_above=-10 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, T_TO_NO_BRKTS_FREEMAIL=0.01 X-Spam-Level: X-Archive-Number: 201107/58 X-Sequence-Number: 37837 On Sunday, July 10, 2011 11:54:10 am Uwe Bartels wrote: > Hi, >=20 > I'm starting up a datawarehouse with patitioning. > my etl processes write directly into the corresponding partitions instead > of using triggers. >=20 > The reports I run in the datawarehouse are stored in a cache within the > same database. > Now I'd like to store besides the results the dependencies to the tables > which were used to generate the report. with this information i could > invalidate cache results for the tables I'm going to import with my etl > processes. >=20 > explain analyze gives me the information which table or patition is read > from for each report. e.g > explain analyze (FORMAT YAML) create table cache.report234 as select > col1,col2,sum(clicks) from dwh.event_log_weekly where week >=3D '2011-06-= 27' > and week <=3D '2011-07-11' group by col1,col2; >=20 > now I'd like to store the output of explain analyze in a pgsql variable f= or > further processing. that looks something like this. >=20 > DO $$declare l_explain text; > begin > l_explain :=3D explain analyze (FORMAT YAML) create table cache.report234= as > select col1,col2,sum(clicks) from dwh.event_log_weekly where week >=3D > '2011-06-27' and week <=3D '2011-07-11' group by col1,col2; > select l_explain; > end$$; >=20 > But that doesn't work. I get a syntax error. =46rom here: http://www.postgresql.org/docs/9.0/interactive/sql-explain.html I believe you are looking for: explain (ANALYZE, FORMAT YAML) create table... >=20 > Does anybody has an idea how to retrieve the output of explain within pgs= ql > and store this in a variable? > An alternative would be any other way to extract the information about > tables used by arbitrary sql statements. >=20 > best regards, > Uwe =2D-=20 Adrian Klaver adrian.klaver@gmail.com