Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id A943FB5DC66 for ; Thu, 27 Oct 2011 14:20:53 -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 38962-02-3 for ; Thu, 27 Oct 2011 17:20:47 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from mail-vw0-f46.google.com (mail-vw0-f46.google.com [209.85.212.46]) by mail.postgresql.org (Postfix) with ESMTP id 1D935B5DDDF for ; Thu, 27 Oct 2011 14:06:55 -0300 (ADT) Received: by vws1 with SMTP id 1so2653784vws.19 for ; Thu, 27 Oct 2011 10:06:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=subject:mime-version:content-type:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to:x-mailer; bh=9IfJQg0NCdPD8JgPihr7EqX6WuybCW87Bn8nVOlLZkk=; b=JpP8ccGMVFnWWNA3JS1PnYQLHPXnt5p1BkeL6B/hPUfHAeJ/+Smtfz+oWoeDpjCvOq 7MUamjTFEv0HVONbjYecw9y8EsUJzkXi24EOG4OiR2b3WgY0uvRBGCzDeZ61tJ8si0FE ghDRlbYBbfYiLjtKL2AnneNUt3bnQugleYGh0= Received: by 10.68.32.194 with SMTP id l2mr74947930pbi.57.1319735213421; Thu, 27 Oct 2011 10:06:53 -0700 (PDT) Received: from [10.9.73.20] (173-164-88-9-Oregon.hfc.comcastbusiness.net. [173.164.88.9]) by mx.google.com with ESMTPS id p5sm16104367pbk.12.2011.10.27.10.06.51 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 27 Oct 2011 10:06:52 -0700 (PDT) Subject: Re: how to use explain analyze Mime-Version: 1.0 (Apple Message framework v1084) Content-Type: text/plain; charset=us-ascii From: Brent Dombrowski In-Reply-To: <7be7d91b-c054-41c6-8a7c-08e77d29625e@v2g2000yqf.googlegroups.com> Date: Thu, 27 Oct 2011 10:06:49 -0700 Cc: pgsql-sql@postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: <88D946EE-F9E8-4DC0-8140-0C0C3F378328@gmail.com> References: <7be7d91b-c054-41c6-8a7c-08e77d29625e@v2g2000yqf.googlegroups.com> To: alan X-Mailer: Apple Mail (2.1084) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.899 tagged_above=-5 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001 X-Spam-Level: X-Archive-Number: 201110/81 X-Sequence-Number: 35965 On Oct 25, 2011, at 7:12 AM, alan wrote: > I'm new to postgres and was wondering how to use EXPLAIN ANALYZE .... >=20 > Can I use the output from ANALYZE EXPLAIN to estimate or predict the > actual time > it would take for a given query to return? >=20 > I ask because I'm writing a typical web app that allows the user to > build and submit a query > to my DB. Since I don't know how "simple" or "complex" the user- > generated queries will be > I thought it might be possible to use the ANALYZE EXPLAIN output to > make a "guestimation" > about the expected return time of the query. >=20 > I'd like to use this in my web-app to determine whether to run the > query in real-time (user waits > for results) or queue up the query (and notify the user once the query > is finished). E.g.: > if (the Total runtime" reported by explain analyze is > n ms) { > tell the user that his request was submitted for processing, and > notify the user once resuilts are available > } else { > run the query and wait for the results in real time. > } >=20 > Thanks, > Alan Check out the docs on EXPLAIN, = http://www.postgresql.org/docs/9.0/static/sql-explain.html EXPLAIN will give you an estimation. How well the internal statistics = match the actual data will determine how close the estimation is. EXPLAIN ANALYZE will give you an estimation and the actuals. WARNING: = EXPLAIN ANALYZE carries out the query. If there any data modifications = in the query (UPDATE, INSERT, etc.) they will be carried out. Note: ANALYZE is a different command and EXPLAIN is not a valid option = for it. You'll be researching this command if the estimates are way off. Brent.