diff --git "a/pgsql-performance.200305" "b/pgsql-performance.200305" new file mode 100644--- /dev/null +++ "b/pgsql-performance.200305" @@ -0,0 +1,29649 @@ +From pgsql-performance-owner@postgresql.org Wed Apr 30 20:10:42 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id F304D475C15 + for ; + Wed, 30 Apr 2003 20:10:40 -0400 (EDT) +Received: from sss.pgh.pa.us (unknown [192.204.191.242]) + by postgresql.org (Postfix) with ESMTP id 3D519475B85 + for ; + Wed, 30 Apr 2003 20:10:40 -0400 (EDT) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h410AcU6025283; + Wed, 30 Apr 2003 20:10:38 -0400 (EDT) +To: "Ron Mayer" +Cc: josh@agliodbs.com, "Achilleus Mantzios" , + pgsql-performance@postgresql.org +Subject: Re: [SQL] 7.3 analyze & vacuum analyze problem +In-reply-to: +References: +Comments: In-reply-to "Ron Mayer" + message dated "Wed, 30 Apr 2003 15:16:58 -0700" +Date: Wed, 30 Apr 2003 20:10:38 -0400 +Message-ID: <25282.1051747838@sss.pgh.pa.us> +From: Tom Lane +X-Spam-Status: No, hits=-32.5 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REFERENCES,REPLY_WITH_QUOTES autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200304/272 +X-Sequence-Number: 1778 + +"Ron Mayer" writes: +> Short summary: Later in the thread Tom explained my problem as free +> space not being evenly distributed across the table so ANALYZE's +> sampling gave skewed results. In my case, "pgstatuple" was a +> good tool for diagnosing the problem, "vacuum full" fixed my table +> and a much larger fsm_* would have probably prevented it. + +Not sure if that is Achilleus' problem or not. IIRC, there should be +no difference at all in what VACUUM ANALYZE and ANALYZE put into +pg_statistic (modulo random sampling variations of course). The only +difference is that VACUUM ANALYZE puts an exact tuple count into +pg_class.reltuples (since the VACUUM part groveled over every tuple, +this info is available) whereas ANALYZE does not scan the entire table +and so has to put an estimate into pg_class.reltuples. + +It would be interesting to see the pg_class and pg_stats rows for this +table after VACUUM ANALYZE and after ANALYZE --- but I suspect the main +difference will be the reltuples values. + + regards, tom lane + + +From pgsql-performance-owner@postgresql.org Wed Apr 30 21:51:41 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id C76D7475B85 + for ; + Wed, 30 Apr 2003 21:51:39 -0400 (EDT) +Received: from houston.familyhealth.com.au (unknown [203.59.48.253]) + by postgresql.org (Postfix) with ESMTP id E5D0C475A45 + for ; + Wed, 30 Apr 2003 21:51:37 -0400 (EDT) +Received: (from root@localhost) + by houston.familyhealth.com.au (8.11.6p2/8.11.6) id h411pep53708 + for pgsql-performance@postgresql.org; + Thu, 1 May 2003 09:51:40 +0800 (WST) + (envelope-from chriskl@familyhealth.com.au) +Received: from mariner (mariner.internal [192.168.0.101]) + by houston.familyhealth.com.au (8.11.6p2/8.9.3) with SMTP id + h411pWJ53573; Thu, 1 May 2003 09:51:32 +0800 (WST) +Message-ID: <0a1301c30f84$39a2dbe0$6500a8c0@fhp.internal> +From: "Christopher Kings-Lynne" +To: , + "Achilleus Mantzios" +Cc: +References: + <200304301148.18322.josh@agliodbs.com> +Subject: Re: [SQL] 7.3 analyze & vacuum analyze problem +Date: Thu, 1 May 2003 09:51:41 +0800 +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit +X-Priority: 3 +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook Express 6.00.2800.1158 +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 +X-scanner: scanned by Inflex 0.1.5c - (http://www.inflex.co.za/) +X-Spam-Status: No, hits=-13.4 required=5.0 + tests=BAYES_20,QUOTED_EMAIL_TEXT,QUOTE_TWICE_1,REFERENCES + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200304/273 +X-Sequence-Number: 1779 + +> > I am afraid it is not so simple. +> > What i (unsuccessfully) implied is that +> > dynacom=# VACUUM ANALYZE status ; +> > VACUUM +> > dynacom=# ANALYZE status ; +> > ANALYZE +> > dynacom=# +> +> You're right, that is mysterious. If you don't get a response from one +of +> the major developers on this forum, I suggest that you post those EXPLAIN +> results to PGSQL-BUGS. + +Is it mysterious? The ANALYZE histogram algorithm does do random sampling +doesn't it? + +Chris + + +From pgsql-performance-owner@postgresql.org Thu May 1 10:57:41 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id BC288475E9D + for ; + Thu, 1 May 2003 10:57:40 -0400 (EDT) +Received: from rtlocal.trade-india.com (mail-relay.trade-india.com + [203.196.129.235]) + by postgresql.org (Postfix) with SMTP id A6EE5475FBA + for ; + Thu, 1 May 2003 10:57:29 -0400 (EDT) +Received: (qmail 13200 invoked from network); 1 May 2003 14:58:25 -0000 +Received: from unknown (HELO system67.trade-india-local.com) (unknown) + by unknown with SMTP; 1 May 2003 14:58:25 -0000 +From: Rajesh Kumar Mallah +Organization: Infocom Network Limited +To: Tom Lane +Subject: Re: profiling plpgsql functions.. +Date: Thu, 1 May 2003 20:29:16 +0530 +User-Agent: KMail/1.5 +Cc: pgsql-performance@postgresql.org +References: <200304291655.01035.mallah@trade-india.com> + <1066.219.65.230.214.1051631768.squirrel@mail.trade-india.com> + <1910.1051632095@sss.pgh.pa.us> +In-Reply-To: <1910.1051632095@sss.pgh.pa.us> +MIME-Version: 1.0 +Content-Type: text/plain; + charset="utf-8" +Content-Transfer-Encoding: 7bit +Content-Disposition: inline +Message-Id: <200305012029.16516.mallah@trade-india.com> +X-Spam-Status: No, hits=-33.1 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REFERENCES,REPLY_WITH_QUOTES,SIGNATURE_SHORT_SPARSE, USER_AGENT + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/1 +X-Sequence-Number: 1780 + + + +the profiling was really helpful to track down +an absense of an appropriate index. + +believe me or not the overall speed improvement was 50 times :)) + +from the order of .4 sec to .008 secs per function call + +regds +mallah. + + + +On Tuesday 29 Apr 2003 9:31 pm, Tom Lane wrote: +> writes: +> > hmm shud i cast timeofday to timestamp and use timestamp +> > arithmatic ? +> +> Yeah. It's only historical accident that it doesn't return timestamp... +> (or better use timestamptz) +> +> regards, tom lane +> +> +> ---------------------------(end of broadcast)--------------------------- +> TIP 6: Have you searched our list archives? +> +> http://archives.postgresql.org + +-- +Rajesh Kumar Mallah, +Project Manager (Development) +Infocom Network Limited, New Delhi +phone: +91(11)6152172 (221) (L) ,9811255597 (M) + +Visit http://www.trade-india.com , +India's Leading B2B eMarketplace. + + +From pgsql-performance-owner@postgresql.org Fri May 2 08:54:50 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 1CDB1475ED4 + for ; + Fri, 2 May 2003 08:54:49 -0400 (EDT) +Received: from smtp.blueyonder.co.uk (pc-62-31-245-32-gl.blueyonder.co.uk + [62.31.245.32]) by postgresql.org (Postfix) with ESMTP id 6D1DE475E9D + for ; + Fri, 2 May 2003 08:54:48 -0400 (EDT) +Received: from reddragon.localdomain ([127.0.0.1] helo=localhost) + by smtp.blueyonder.co.uk with esmtp (Exim 4.10) id 19Ba45-0001ll-00 + for pgsql-performance@postgresql.org; Fri, 02 May 2003 13:55:01 +0100 +Date: Fri, 2 May 2003 13:55:01 +0100 (BST) +From: Peter Childs +X-X-Sender: peter@RedDragon.Childs +To: pgsql-performance@postgresql.org +Subject: Query Priority +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-Spam-Status: No, hits=-12.3 required=5.0 tests=BAYES_01,USER_AGENT_PINE + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/3 +X-Sequence-Number: 1782 + + Is there some way to give some postgres backends higher priority. +Hence on a very busy server "important" queries get done faster than less +priority that unimportant queries. + I don't think this would be too difficult to do as certainly on +Linux the process could just be reniced and the os left to figure it out. +of course any query that is holding up another query with locks needs to +get done quickly. + I find my self with a database thats slowed to a craw because of a +slow batch program it not letting the gui clients the speed they require +to be usable. + +Peter Childs + + +From pgsql-performance-owner@postgresql.org Fri May 2 10:05:44 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 8AA84476361 + for ; + Fri, 2 May 2003 10:05:40 -0400 (EDT) +Received: from mail.libertyrms.com (unknown [209.167.124.227]) + by postgresql.org (Postfix) with ESMTP id AC18147635E + for ; + Fri, 2 May 2003 10:05:39 -0400 (EDT) +Received: from [10.1.2.130] (helo=dba2) + by mail.libertyrms.com with esmtp (Exim 3.22 #3 (Debian)) + id 19BbAW-0004ky-00 + for ; Fri, 02 May 2003 10:05:44 -0400 +Received: by dba2 (Postfix, from userid 1019) + id 0D759CF78; Fri, 2 May 2003 10:05:44 -0400 (EDT) +Date: Fri, 2 May 2003 10:05:44 -0400 +From: Andrew Sullivan +To: pgsql-performance@postgresql.org +Subject: Re: Query Priority +Message-ID: <20030502140543.GA13419@libertyrms.info> +Mail-Followup-To: Andrew Sullivan , + pgsql-performance@postgresql.org +References: +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: +User-Agent: Mutt/1.5.3i +X-Spam-Status: No, hits=-38.0 required=5.0 + tests=BAYES_10,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REFERENCES,REPLY_WITH_QUOTES,USER_AGENT_MUTT + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/5 +X-Sequence-Number: 1784 + +On Fri, May 02, 2003 at 01:55:01PM +0100, Peter Childs wrote: +> Is there some way to give some postgres backends higher priority. +> Hence on a very busy server "important" queries get done faster than less +> priority that unimportant queries. + +No. + +> I don't think this would be too difficult to do as certainly on +> Linux the process could just be reniced and the os left to figure it out. +> of course any query that is holding up another query with locks needs to +> get done quickly. + +It's the latter condition that causes the problem for the nice-ing +(among other things -- there's plenty of discussion about this in the +archives. Tom Lane gave a quite long explanation one time, but I +can't find it right now.) + +> I find my self with a database thats slowed to a craw because of a +> slow batch program it not letting the gui clients the speed they require +> to be usable. + +Sounds like what you really need is a replica database which you can +use for batch reports, &c. You could do this with a small-ish box, +because you'd only have one client. + +A + +-- +---- +Andrew Sullivan 204-4141 Yonge Street +Liberty RMS Toronto, Ontario Canada + M2P 2A8 + +1 416 646 3304 x110 + + +From pgsql-performance-owner@postgresql.org Fri May 2 10:23:11 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 0EC33475F16 + for ; + Fri, 2 May 2003 10:23:08 -0400 (EDT) +Received: from sss.pgh.pa.us (unknown [192.204.191.242]) + by postgresql.org (Postfix) with ESMTP id 416D4475C3D + for ; + Fri, 2 May 2003 10:23:07 -0400 (EDT) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h42ENAU6010242; + Fri, 2 May 2003 10:23:10 -0400 (EDT) +To: Peter Childs +Cc: pgsql-performance@postgresql.org +Subject: Re: Query Priority +In-reply-to: +References: +Comments: In-reply-to Peter Childs + message dated "Fri, 02 May 2003 13:55:01 +0100" +Date: Fri, 02 May 2003 10:23:10 -0400 +Message-ID: <10241.1051885390@sss.pgh.pa.us> +From: Tom Lane +X-Spam-Status: No, hits=-32.3 required=5.0 + tests=BAYES_00,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REFERENCES,REPLY_WITH_QUOTES autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/6 +X-Sequence-Number: 1785 + +Peter Childs writes: +> Is there some way to give some postgres backends higher priority. + +No. + +> I don't think this would be too difficult to do as certainly on +> Linux the process could just be reniced and the os left to figure it out. + +Read about "priority inversion" in any handy CS textbook ... renicing a +process won't buy you much if the locking mechanisms don't cooperate. + + regards, tom lane + + +From pgsql-performance-owner@postgresql.org Fri May 2 07:27:13 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id C49AD4758F1 + for ; + Fri, 2 May 2003 07:27:10 -0400 (EDT) +Received: from matrix.gatewaynet.com (unknown [217.19.69.50]) + by postgresql.org (Postfix) with ESMTP id D452F474E4F + for ; + Fri, 2 May 2003 07:27:08 -0400 (EDT) +Received: from matrix.gatewaynet.com (localhost [127.0.0.1]) + by matrix.gatewaynet.com (8.12.5/8.12.5) with ESMTP id h42GTb1s019424; + Fri, 2 May 2003 14:29:37 -0200 +Received: from localhost (achill@localhost) + by matrix.gatewaynet.com (8.12.5/8.12.5/Submit) with ESMTP id + h42GTYH0019420; Fri, 2 May 2003 14:29:35 -0200 +Date: Fri, 2 May 2003 14:29:34 -0200 (GMT+2) +From: Achilleus Mantzios +To: Tom Lane +Cc: Ron Mayer , , + , + Achilleus Mantzios +Subject: Re: [SQL] 7.3 analyze & vacuum analyze problem +In-Reply-To: <25282.1051747838@sss.pgh.pa.us> +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-Spam-Status: No, hits=-38.6 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + QUOTE_TWICE_1,REPLY_WITH_QUOTES,SIGNATURE_LONG_DENSE, + USER_AGENT_PINE autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/2 +X-Sequence-Number: 1781 + +On Wed, 30 Apr 2003, Tom Lane wrote: + +> "Ron Mayer" writes: +> > Short summary: Later in the thread Tom explained my problem as free +> > space not being evenly distributed across the table so ANALYZE's +> > sampling gave skewed results. In my case, "pgstatuple" was a +> > good tool for diagnosing the problem, "vacuum full" fixed my table +> > and a much larger fsm_* would have probably prevented it. +> +> Not sure if that is Achilleus' problem or not. IIRC, there should be +> no difference at all in what VACUUM ANALYZE and ANALYZE put into +> pg_statistic (modulo random sampling variations of course). The only +> difference is that VACUUM ANALYZE puts an exact tuple count into +> pg_class.reltuples (since the VACUUM part groveled over every tuple, +> this info is available) whereas ANALYZE does not scan the entire table +> and so has to put an estimate into pg_class.reltuples. +> +> It would be interesting to see the pg_class and pg_stats rows for this +> table after VACUUM ANALYZE and after ANALYZE --- but I suspect the main +> difference will be the reltuples values. + +Unfortunately i did a VACUUM FULL, and later a dump/reload +which eliminated (vanished) the problem regarding the difference between +plain ANALYZE and VACUUM ANALYZE. + +However, now the condition is much more wierd, in the sense +that after the reload, some planner costs seem too low (~ 6) +the expected number of rows is very often 1, +and the correct index is used, resulting in a +ultra speed situation (that i never had expected!). + +After vacuum full analyze, or vacuum analyze +things get slow again. + +I surely must generate a reproducable scenario, +describing the exact steps made, so i'll focus +on that. + +In the meantime if Tom or some other hacker +has any ideas that would be great. + + +> +> regards, tom lane +> + +-- +================================================================== +Achilleus Mantzios +S/W Engineer +IT dept +Dynacom Tankers Mngmt +Nikis 4, Glyfada +Athens 16610 +Greece +tel: +30-210-8981112 +fax: +30-210-8981877 +email: achill@matrix.gatewaynet.com + mantzios@softlab.ece.ntua.gr + + +From pgsql-performance-owner@postgresql.org Fri May 2 14:53:54 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 09CB74763EC + for ; + Fri, 2 May 2003 14:53:51 -0400 (EDT) +Received: from utahisp.com (mail.utahisp.com [66.239.12.3]) + by postgresql.org (Postfix) with ESMTP id DAF144763F8 + for ; + Fri, 2 May 2003 14:53:45 -0400 (EDT) +Received: from chad [63.230.8.76] by utahisp.com + (SMTPD32-7.14) id ADE8D8630268; Fri, 02 May 2003 12:50:16 -0600 +Message-ID: <0c2101c310dc$28e3c090$32021aac@chad> +From: "Chad Thompson" +To: "pgsql-performance" +Subject: Looking for a cheap upgrade (RAID) +Date: Fri, 2 May 2003 12:53:45 -0600 +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit +X-Priority: 3 +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook Express 6.00.2720.3000 +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 +X-Declude-Sender: chad@weblinkservices.com [63.230.8.76] +X-Declude-Spoolname: Dbde8d86302685945.SMD +X-Note: This E-mail was scanned by Declude JunkMail (www.declude.com) for + spam. +X-Spam-Status: No, hits=-2.7 required=5.0 tests=BAYES_20,SMTPD_IN_RCVD + version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/7 +X-Sequence-Number: 1786 + +I have a server on a standard pc right now. +PIII 700, 1Gig ram (SD), 40 Gig IDE, RedHat 8.0, PostgreSQL 7.3.1 + +The database has 3 tables that just broke 10 million tuples (yeah, i think +im entering in to the world of real databases ;-) +Its primarly bulk (copy) inserts and queries, rarely an update. + +I am looking at moving this to a P4 2.4G, 2 Gig Ram(DDR), RedHat 8, +PostgreSQL 7.3.latest + +My primary reason for posting this is to help filter through the noise, and +get me pointed in the right direction. + +I realize that Im a raid on linux newbie so any suggestions are appreciated. +Im thinking I want to put this on an IDE Raid array, probably 0+1. IDE seems +to be cheap and effective these days. +What ive been able to glean from other postings is that I should have 3 +drives, 2 for the database w/ striping and another for the WAL. +Am I way off base here? +I would also appreciate raid hardware suggestions (brands, etc) +And as always im not afraid to RTFM if someone can point me to the FM :-) + +Cost seems to be quite a high priority, I'm getting pretty good at making +something out of nothing for everyone :) + +TIA for any suggestions. +Chad + + +From pgsql-performance-owner@postgresql.org Fri May 2 10:00:56 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id D279F475A45 + for ; + Fri, 2 May 2003 10:00:53 -0400 (EDT) +Received: from matrix.gatewaynet.com (unknown [217.19.69.50]) + by postgresql.org (Postfix) with ESMTP id 3E4634758F1 + for ; + Fri, 2 May 2003 10:00:50 -0400 (EDT) +Received: from matrix.gatewaynet.com (localhost [127.0.0.1]) + by matrix.gatewaynet.com (8.12.5/8.12.5) with ESMTP id h42J3L1s020114; + Fri, 2 May 2003 17:03:21 -0200 +Received: from localhost (achill@localhost) + by matrix.gatewaynet.com (8.12.5/8.12.5/Submit) with ESMTP id + h42J3LfX020110; Fri, 2 May 2003 17:03:21 -0200 +Date: Fri, 2 May 2003 17:03:21 -0200 (GMT+2) +From: Achilleus Mantzios +To: Tom Lane +Cc: Ron Mayer , , + +Subject: Re: [SQL] 7.3 analyze & vacuum analyze problem +In-Reply-To: +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-Spam-Status: No, hits=-38.0 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REPLY_WITH_QUOTES,SIGNATURE_LONG_DENSE,USER_AGENT_PINE + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/4 +X-Sequence-Number: 1783 + +On Fri, 2 May 2003, Achilleus Mantzios wrote: + +> On Wed, 30 Apr 2003, Tom Lane wrote: +> +> > +> > It would be interesting to see the pg_class and pg_stats rows for this +> > table after VACUUM ANALYZE and after ANALYZE --- but I suspect the main +> > difference will be the reltuples values. +> +> I surely must generate a reproducable scenario, +> describing the exact steps made, so i'll focus +> on that. + +I use a freebsd-current (hereafter called FBSD) as a test environment, +with a freshly reloaded db and NO VACUUM or ANALYZE ever run, and i +EXPLAIN ANALYZE some queries against a linux 2.4.18SMP (hereafter called +LNX) which is the production environment, and on which a recent VACUUM +FULL ANALYZE is run. + +Some queries run *very* fast on FBSD and very slow on LNX, +where others run very slow on FBSD and very fast on LNX. +(Here the oper system is not an issue, i just use these +2 acronyms as aliases for the 2 situations/environments. + +So i have: + +================= FBSD =================== +========= QueryA (A VERY FAST PLAN) ===== +dynacom=# EXPLAIN ANALYZE select count(*) from status where +assettable='vessels' and appname='ISM PMS' and apptblname='items' and +status='warn' and isvalid and assetidval=57; + +QUERY PLAN + +----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + Aggregate (cost=6.02..6.02 rows=1 width=0) (actual time=14.16..14.16 +rows=1 loops=1) + -> Index Scan using status_all on status (cost=0.00..6.02 rows=1 +width=0) (actual time=13.09..13.95 rows=75 loops=1) + Index Cond: ((assettable = 'vessels'::character varying) AND +(assetidval = 57) AND (appname = 'ISM PMS'::character varying) AND +(apptblname = 'items'::character +varying) AND (status = 'warn'::character varying)) + Filter: isvalid + Total runtime: 14.40 msec +(5 rows) + +dynacom=# +===============QueryB A VERY SLOW PLAN ===== +dynacom=# EXPLAIN ANALYZE select it.id from items it,machdefs md where +it.defid = md.defid and first(md.parents)=16492 and it.vslwhid = 53 and +it.machtypecount = 1 order +by md.description,md.partno; + QUERY +PLAN +---------------------------------------------------------------------------------------------------------------------------------------------- + Sort (cost=457.76..457.77 rows=1 width=68) (actual time=150.31..150.31 +rows=0 loops=1) + Sort Key: md.description, md.partno + -> Nested Loop (cost=0.00..457.75 rows=1 width=68) (actual +time=150.16..150.16 rows=0 loops=1) + -> Index Scan using items_machtypecount on items it +(cost=0.00..451.73 rows=1 width=8) (actual time=0.99..89.30 rows=2245 +loops=1) + Index Cond: (machtypecount = 1) + Filter: (vslwhid = 53) + -> Index Scan using machdefs_pkey on machdefs md +(cost=0.00..6.01 rows=1 width=60) (actual time=0.02..0.02 rows=0 +loops=2245) + Index Cond: ("outer".defid = md.defid) + Filter: (first(parents) = 16492) + Total runtime: 150.58 msec +(10 rows) + +dynacom=# +=================END FBSD================= + +=================LNX ===================== +========= QueryA (A VERY SLOW PLAN) ===== +dynacom=# EXPLAIN ANALYZE select count(*) from status where +assettable='vessels' and appname='ISM PMS' and apptblname='items' and +status='warn' and isvalid and assetidval=57; + +QUERY PLAN + +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + Aggregate (cost=1346.56..1346.56 rows=1 width=0) (actual +time=244.05..244.05 rows=1 loops=1) + -> Seq Scan on status (cost=0.00..1345.81 rows=300 width=0) (actual +time=0.63..243.93 rows=75 loops=1) + Filter: ((assettable = 'vessels'::character varying) AND (appname += 'ISM PMS'::character varying) AND (apptblname = 'items'::character +varying) AND (status = 'warn'::character varying) AND isvalid AND +(assetidval = 57)) + Total runtime: 244.12 msec +(4 rows) + +dynacom=# +=========== QueryB (A VERY FAST PLAN)======= +dynacom=# EXPLAIN ANALYZE select it.id from items it,machdefs md where +it.defid = md.defid and first(md.parents)=16492 and it.vslwhid = 53 and +it.machtypecount = 1 order by md.description,md.partno; + QUERY PLAN +---------------------------------------------------------------------------------------------------------------------------------------- + Sort (cost=631.23..631.26 rows=11 width=42) (actual time=0.08..0.08 +rows=0 loops=1) + Sort Key: md.description, md.partno + -> Nested Loop (cost=0.00..631.05 rows=11 width=42) (actual +time=0.03..0.03 rows=0 loops=1) + -> Index Scan using machdefs_dad on machdefs md +(cost=0.00..228.38 rows=67 width=34) (actual time=0.02..0.02 rows=0 +loops=1) + Index Cond: (first(parents) = 16492) + -> Index Scan using items_defid_vslid_mtcnt on items it +(cost=0.00..5.99 rows=1 width=8) (never executed) + Index Cond: ((it.defid = "outer".defid) AND (it.vslwhid = +53) AND (it.machtypecount = 1)) + Total runtime: 0.15 msec +(8 rows) + +dynacom=# + +======= END LNX ===================================== + +* first is a function: + integer first(integer[]), +that returns the first element of a [1xN] array. + +Now i run a VACUUM FULL ANALYZE; on the FBSD system +and after taht,i get *identical* plans as on the LNX system. +So, the VACUUM FULL ANALYZE command helps QueryB, but screws +QueryA. + +Here i paste pg_stats,pg_class data for the 3 tables (status, +machdefs, items) on the FBSD system + +====BEFORE the VACUUM FULL ANALYZE===== +dynacom=# SELECT * from pg_class where relname='status'; +-[ RECORD 1 ]--+-------- +relname | status +relnamespace | 2200 +reltype | 3470164 +relowner | 1 +relam | 0 +relfilenode | 3470163 +relpages | 562 +reltuples | 33565 +reltoastrelid | 0 +reltoastidxid | 0 +relhasindex | t +relisshared | f +relkind | r +relnatts | 12 +relchecks | 0 +reltriggers | 0 +relukeys | 0 +relfkeys | 0 +relrefs | 0 +relhasoids | t +relhaspkey | f +relhasrules | f +relhassubclass | f +relacl | + +dynacom=# +dynacom=# SELECT * from pg_class where relname='machdefs'; +-[ RECORD 1 ]--+--------- +relname | machdefs +relnamespace | 2200 +reltype | 3470079 +relowner | 1 +relam | 0 +relfilenode | 3470078 +relpages | 175 +reltuples | 13516 +reltoastrelid | 3470081 +reltoastidxid | 0 +relhasindex | t +relisshared | f +relkind | r +relnatts | 20 +relchecks | 0 +reltriggers | 7 +relukeys | 0 +relfkeys | 0 +relrefs | 0 +relhasoids | t +relhaspkey | t +relhasrules | f +relhassubclass | f +relacl | + +dynacom=# SELECT * from pg_class where relname='items'; +-[ RECORD 1 ]--+-------- +relname | items +relnamespace | 2200 +reltype | 3470149 +relowner | 1 +relam | 0 +relfilenode | 3470148 +relpages | 233 +reltuples | 29433 +reltoastrelid | 3470153 +reltoastidxid | 0 +relhasindex | t +relisshared | f +relkind | r +relnatts | 25 +relchecks | 0 +reltriggers | 10 +relukeys | 0 +relfkeys | 0 +relrefs | 0 +relhasoids | t +relhaspkey | t +relhasrules | f +relhassubclass | f +relacl | + +dynacom=# + +Before the VACUUM [FULL] ANALYZE No statistics are produced + + +====AFTER the VACUUM FULL ANALYZE===== + +=========================================================== +dynacom=# SELECT * from pg_class where relname='status'; +-[ RECORD 1 ]--+-------- +relname | status +relnamespace | 2200 +reltype | 3191663 +relowner | 1 +relam | 0 +relfilenode | 3191662 +relpages | 562 +reltuples | 33565 +reltoastrelid | 0 +reltoastidxid | 0 +relhasindex | t +relisshared | f +relkind | r +relnatts | 12 +relchecks | 0 +reltriggers | 0 +relukeys | 0 +relfkeys | 0 +relrefs | 0 +relhasoids | t +relhaspkey | f +relhasrules | f +relhassubclass | f +relacl | + +dynacom=# + +dynacom=# SELECT * from pg_class where relname='machdefs'; +-[ RECORD 1 ]--+--------- +relname | machdefs +relnamespace | 2200 +reltype | 3191578 +relowner | 1 +relam | 0 +relfilenode | 3191577 +relpages | 175 +reltuples | 13516 +reltoastrelid | 3191580 +reltoastidxid | 0 +relhasindex | t +relisshared | f +relkind | r +relnatts | 20 +relchecks | 0 +reltriggers | 7 +relukeys | 0 +relfkeys | 0 +relrefs | 0 +relhasoids | t +relhaspkey | t +relhasrules | f +relhassubclass | f +relacl | + +dynacom=# + +dynacom=# SELECT * from pg_class where relname='items'; +-[ RECORD 1 ]--+-------- +relname | items +relnamespace | 2200 +reltype | 3191648 +relowner | 1 +relam | 0 +relfilenode | 3191647 +relpages | 232 +reltuples | 29433 +reltoastrelid | 3191652 +reltoastidxid | 0 +relhasindex | t +relisshared | f +relkind | r +relnatts | 25 +relchecks | 0 +reltriggers | 10 +relukeys | 0 +relfkeys | 0 +relrefs | 0 +relhasoids | t +relhaspkey | t +relhasrules | f +relhassubclass | f +relacl | + +dynacom=# SELECT +tablename,attname,null_frac,avg_width,n_distinct,most_common_vals,most_common_freqs,histogram_bounds,correlation +from pg_stats where tablename='status'; + + tablename | attname | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation +-----------+-------------+-----------+-----------+------------+--------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------- + status | id | 0 | 4 | -1 | | | {8,3677,6977,10159,13753,17012,20228,23620,26864,30311,33859} | 0.795126 + status | checkdate | 0 | 8 | -1 | | | {"2002-10-19 10:54:53.764+03","2003-03-01 05:00:22.691+02","2003-03-03 05:00:23.876+02","2003-03-04 05:00:28.912+02","2003-03-29 05:00:28.099+02","2003-03-30 05:00:24.009+03","2003-04-02 12:14:34.221+03","2003-04-26 05:02:53.133+03","2003-04-29 05:01:43.716+03","2003-04-30 05:01:05.727+03","2003-04-30 05:01:46.749+03"} | 0.844914 + status | assettable | 0 | 11 | 1 | {vessels} | {1} | | 1 + status | assetidval | 0 | 4 | 21 | {53,57,48,65,33,61,49} | {0.11,0.108667,0.0916667,0.079,0.073,0.0693333,0.0626667} | {20,24,26,29,32,35,36,43,44,47,79} | 0.15861 + status | appname | 0 | 11 | 6 | {"ISM PMS",Class.Certificates,Class.Surveys,Repairs,Class.CMS,Class.Recommendations} | {0.975333,0.01,0.00633333,0.004,0.003,0.00133333} | | 0.963033 + status | apptblname | 0 | 9 | 5 | {items,certificates,surveys,repdat,recommendations} | {0.978333,0.01,0.00633333,0.004,0.00133333} | | 0.96127 + status | apptblidval | 0 | 4 | -0.165914 | {18799,2750,9025,12364,12491,20331,20546,20558,21665,22913} | {0.00166667,0.00133333,0.00133333,0.00133333,0.00133333,0.00133333,0.00133333,0.00133333,0.00133333,0.00133333} | {1,4996,8117,12367,14441,16488,19586,21155,22762,24026,32802} | 0.104023 + status | colname | 0 | 14 | 6 | {lastrepdate,lastinspdate,rh,N/A,status,classsurvey} | {0.685,0.241333,0.049,0.0176667,0.004,0.003} | | 0.487112 + status | colval | 0 | 8 | -0.56769 | {0,1,2991,27,146,1102,412,784,136,1126} | {0.0206667,0.004,0.002,0.00166667,0.00166667,0.00166667,0.00133333,0.00133333,0.001,0.001} | {21,14442.908,14506.476,18028.868,18038.256,18045.821,18053.101,18062.404,18076.057,150212.049,96805423.065} | 0.197915 + status | status | 0 | 8 | 2 | {warn,alarm} | {0.524333,0.475667} | | 0.514211 + status | isvalid | 0 | 1 | 2 | {f,t} | {0.789333,0.210667} | | 0.967602 + status | username | 0 | 12 | 7 | {periodic,amantzio,ckaklaman,secretuser,mitsios,birtsia,lignos} | {0.856333,0.053,0.0433333,0.029,0.013,0.00266667,0.00266667} | | 0.769222 +(12 rows) + +dynacom=# SELECT +tablename,attname,null_frac,avg_width,n_distinct,most_common_vals,most_common_freqs,histogram_bounds,correlation +from pg_stats where tablename='machdefs'; + + tablename | attname | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation +-----------+-------------+-----------+-----------+------------+---------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------- + machdefs | defid | 0 | 4 | -1 | | | {2482,4607,6556,7957,9339,10662,12006,13822,15082,16533,18224} | 0.315706 + machdefs | parents | 0.124667 | 29 | -0.345266 | {"{8673}","{4456}","{9338}","{11565}","{6865}","{11183}","{10810}","{9852}","{7016}","{7636}"} | {0.0166667,0.016,0.016,0.0156667,0.013,0.0126667,0.0106667,0.01,0.01,0.00966667} | | + machdefs | description | 0.281333 | 20 | -0.101338 | {Inspection,Rings,Overhaul,Greasing/Lubrication,Bearings,Oil,"Safety devices",Motor,Cleaning,Crankcase} | {0.0296667,0.01,0.008,0.00733333,0.00633333,0.00633333,0.006,0.00533333,0.005,0.00433333} | {"1T11 Vortex Pump","Camshaft drive","Cylinder Lubricator Pump body","Ejector pump","Fuel injection pump No5","Inlet valve","Main bearing No6","Piston & Connecting rod No6","Safety cut out device No7","Stuffing box","dP/I Transmitter flow meter kit"} | 0.04711 + machdefs | partno | 0.840667 | 10 | 327 | | | {0137,151623-54101,302,51.04101-0479,90401-48-296,"G 21401","Z 11918","Z 23165","Z 27242","Z 27533",ZK34402} | 0.394772 + machdefs | machtypeid | 0 | 4 | 739 | {358,632,207,364,16,633,1006,31,533,723} | {0.0853333,0.0326667,0.0226667,0.0223333,0.0203333,0.0203333,0.0203333,0.0196667,0.0196667,0.0196667} | {19,64,129,330,456,631,809,932,1048,1242,1575} | 0.128535 + machdefs | rhbec | 0.782667 | 4 | 20 | {6000} | {0.073} | {375,750,1500,1500,3000,3750,3750,7500,9000,12000,37500} | 0.300707 + machdefs | rhdue | 0.782667 | 4 | 20 | {8000} | {0.073} | {500,1000,2000,2000,4000,5000,5000,10000,12000,16000,50000} | 0.300707 + machdefs | periodbec | 0.458667 | 4 | 11 | {22} | {0.262333} | {5,67,67,67,135,135,270,270,675,1350} | 0.415895 + machdefs | perioddue | 0.458667 | 4 | 10 | {30,90,180,360,1800,7,900,720,120,60} | {0.262333,0.0833333,0.053,0.0456667,0.0233333,0.021,0.021,0.0156667,0.0153333,0.000666667} | | 0.419195 + machdefs | action | 0.474333 | 13 | 56 | {Inspection,Overhaul,Cleaning,Clearances,"Megger Report"} | {0.151333,0.0966667,0.0746667,0.0273333,0.0236667} | {"Actuation test",Check,"Check Position",Greasing/Lubrication,Landing,"Pressure Test",Renewal,Renewal,"Report Receipt",Test,"Water Washing"} | 0.180053 + machdefs | application | 0.973333 | 18 | 2 | {"Megger Report","CrankShaft Deflection Report"} | {0.0236667,0.003} | | 0.999508 +(11 rows) + +dynacom=# SELECT +tablename,attname,null_frac,avg_width,n_distinct,most_common_vals,most_common_freqs,histogram_bounds,correlation +from pg_stats where tablename='items'; + + tablename | attname | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation +-----------+-----------------+-----------+-----------+------------+-------------------------------------------------------------+------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------- + items | id | 0 | 4 | -1 | | | {2315,7279,12104,15875,19170,22170,25511,28420,32582,35753,38322} | 0.427626 + items | vslwhid | 0 | 4 | 19 | {57,53,65,74} | {0.130333,0.125,0.116667,0.0746667} | {24,29,31,33,43,44,48,49,61,76,79} | 0.0679692 + items | serialno | 0.952 | 10 | 149 | | | {014-3255,120092,1294207,20081,318216,56678,80-51,A1-0548,BV54654,KC60525,XL5334} | -0.0161482 + items | rh | 0.863667 | 4 | 191 | {0} | {0.008} | {1,172,400,855,1292,2322,3191,4328,4906,6421,37679} | 0.0437569 + items | lastinspdate | 0.885 | 4 | 120 | | | {1999-05-28,2002-04-23,2002-12-06,2003-01-15,2003-02-01,2003-02-22,2003-03-04,2003-03-15,2003-03-21,2003-03-28,2003-10-09} | 0.101498 + items | classused | 0 | 4 | 2 | {0,1} | {0.985333,0.0146667} | | 0.979994 + items | classaa | 0.985333 | 4 | 43 | | | {5,24,50,69,93,104,132,178,686,1072,1241} | -0.114588 + items | classsurvey | 0.985333 | 31 | 44 | | | {"Aux Boiler Feed Inner Pump (No.1)","Ballast Inner Pump (No.1)","Emergency Fire Pump","M/E Cylinder Relief valve No2","M/E Piston No4","No.1 Cooling S.W.Pump for G/E","No.2 Cargo Oil Pump","No.2 Main Generator Diesel Engine","No.4 Connecting rod, top end and guides","No.6 Safety valve of M/E","Sea Water Service Pump"} | -0.0264975 + items | classsurveydate | 0.987333 | 4 | 20 | | | {1998-05-31,1998-05-31,2000-01-31,2000-05-31,2001-03-31,2001-09-30,2002-02-28,2002-07-31,2002-12-31,2003-02-16,2003-04-23} | 0.305832 + items | classduedate | 0.985333 | 4 | 22 | | | {2003-05-31,2003-07-31,2004-07-31,2005-01-31,2005-10-18,2006-07-31,2006-09-30,2007-07-31,2007-12-31,2008-02-28,2008-04-30} | 0.0222692 + items | classcomment | 0.997333 | 26 | 1 | {"Main Propulsion System"} | {0.00266667} | | 1 + items | defid | 0 | 4 | -0.243872 | {15856,15859,15851,13801,14179,14181,15860,15865,2771,2775} | {0.00333333,0.00233333,0.002,0.00166667,0.00166667,0.00166667,0.00166667,0.00166667,0.00133333,0.00133333} | {2319,3192,5182,7387,9296,11020,12862,14001,15190,16852,18221} | 0.321816 + items | machtypecount | 0 | 4 | 8 | {1,2,3,4,6,5,7,8} | {0.62,0.22,0.139667,0.0113333,0.00466667,0.003,0.000666667,0.000666667} | | 0.489828 + items | totalrh | 0 | 4 | 2 | {0} | {0.999667} | | 0.999829 + items | comment | 0.928667 | 7 | 34 | | | {1,3,"90KVA-General service",No1,No1,No1,No2,No2,No2,No3,Stbd} | 0.384123 + items | lastrepdate | 0.742667 | 4 | 10 | {2003-03-31} | {0.187333} | {2002-06-30,2003-02-28,2003-02-28,2003-02-28,2003-04-01,2003-04-04,2003-04-04,2003-04-04,2003-04-08} | 0.887771 +(16 rows) + + +================================================================================ +It seems that the presence of Statistics really hurt status table. +In the other cases (machdefs,items) VACUUM ANALYZE does +a pretty good job. (or at least compared to the "no stats at all" case). + +Also Tom, i could give you access, if you want, to the test environment :) + + > > +> > +> > regards, tom lane +> > +> +> + +-- +================================================================== +Achilleus Mantzios +S/W Engineer +IT dept +Dynacom Tankers Mngmt +Nikis 4, Glyfada +Athens 16610 +Greece +tel: +30-210-8981112 +fax: +30-210-8981877 +email: achill@matrix.gatewaynet.com + mantzios@softlab.ece.ntua.gr + + +From pgsql-performance-owner@postgresql.org Fri May 2 16:15:13 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 9E2954763EE + for ; + Fri, 2 May 2003 16:15:10 -0400 (EDT) +Received: from mail1.ihs.com (mail1.ihs.com [170.207.70.222]) + by postgresql.org (Postfix) with ESMTP id 1DE734763E4 + for ; + Fri, 2 May 2003 16:15:06 -0400 (EDT) +Received: from css120.ihs.com (css120.ihs.com [170.207.105.120]) + by mail1.ihs.com (8.12.9/8.12.9) with ESMTP id h42KDrXL009253; + Fri, 2 May 2003 14:13:54 -0600 (MDT) +Date: Fri, 2 May 2003 14:04:37 -0600 (MDT) +From: "scott.marlowe" +To: Chad Thompson +Cc: pgsql-performance +Subject: Re: Looking for a cheap upgrade (RAID) +In-Reply-To: <0c2101c310dc$28e3c090$32021aac@chad> +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-MailScanner: Found to be clean +X-MailScanner-SpamCheck: +X-Spam-Status: No, hits=-31.7 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REPLY_WITH_QUOTES,USER_AGENT_PINE autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/9 +X-Sequence-Number: 1788 + +On Fri, 2 May 2003, Chad Thompson wrote: + +> I have a server on a standard pc right now. +> PIII 700, 1Gig ram (SD), 40 Gig IDE, RedHat 8.0, PostgreSQL 7.3.1 +> +> The database has 3 tables that just broke 10 million tuples (yeah, i think +> im entering in to the world of real databases ;-) +> Its primarly bulk (copy) inserts and queries, rarely an update. +> +> I am looking at moving this to a P4 2.4G, 2 Gig Ram(DDR), RedHat 8, +> PostgreSQL 7.3.latest +> +> My primary reason for posting this is to help filter through the noise, and +> get me pointed in the right direction. +> +> I realize that Im a raid on linux newbie so any suggestions are appreciated. +> Im thinking I want to put this on an IDE Raid array, probably 0+1. IDE seems +> to be cheap and effective these days. +> What ive been able to glean from other postings is that I should have 3 +> drives, 2 for the database w/ striping and another for the WAL. +> Am I way off base here? +> I would also appreciate raid hardware suggestions (brands, etc) +> And as always im not afraid to RTFM if someone can point me to the FM :-) +> +> Cost seems to be quite a high priority, I'm getting pretty good at making +> something out of nothing for everyone :) + +My experience has been that with IDEs, RAID-5 is pretty good (85% the +performance of RAID-1 in real use) X+0 in linux kernel (2.4.7 is what I +tested, no idea on the newer kernel versions) is no faster than X where X +is 1 or 5. I think there are parallel issues with stacking with linux +software kernel arrays. That said, their performance in stock RAID1 and +RAID5 configurations is quite good. + +If your writes happen during off hours, or only account for a small +portion of your IO then a seperate drive is not gonna win you much, it's a +heavily written environment that will gain from that. + + +From pgsql-performance-owner@postgresql.org Fri May 2 16:11:17 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 48C504763EE + for ; + Fri, 2 May 2003 16:11:15 -0400 (EDT) +Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) + by postgresql.org (Postfix) with ESMTP id 8EE694763E4 + for ; + Fri, 2 May 2003 16:11:14 -0400 (EDT) +Received: from [66.219.92.2] (HELO temoku) + by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) + with ESMTP id 3003887; Fri, 02 May 2003 13:11:14 -0700 +Content-Type: text/plain; + charset="iso-8859-1" +From: Josh Berkus +Reply-To: josh@agliodbs.com +Organization: Aglio Database Solutions +To: "Chad Thompson" , + "pgsql-performance" +Subject: Re: Looking for a cheap upgrade (RAID) +Date: Fri, 2 May 2003 13:10:46 -0700 +User-Agent: KMail/1.4.3 +References: <0c2101c310dc$28e3c090$32021aac@chad> +In-Reply-To: <0c2101c310dc$28e3c090$32021aac@chad> +MIME-Version: 1.0 +Content-Transfer-Encoding: quoted-printable +Message-Id: <200305021310.46770.josh@agliodbs.com> +X-Spam-Status: No, hits=-31.6 required=5.0 + tests=BAYES_10,IN_REP_TO,QUOTED_EMAIL_TEXT,REFERENCES, + REPLY_WITH_QUOTES,USER_AGENT_KMAIL autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/8 +X-Sequence-Number: 1787 + +Chad, + +> I realize that Im a raid on linux newbie so any suggestions are appreciat= +ed. +> Im thinking I want to put this on an IDE Raid array, probably 0+1. IDE se= +ems +> to be cheap and effective these days. +> What ive been able to glean from other postings is that I should have 3 +> drives, 2 for the database w/ striping and another for the WAL. + +Well, RAID 0+1 is only relevant if you have more than 2 drives. Otherwise,= +=20 +it's just RAID 1 (which is a good choice for PostgreSQL). + +More disks is almost always better. Putting WAL on a seperate (non-RAID) d= +isk=20 +is usually a very good idea. + +> I would also appreciate raid hardware suggestions (brands, etc) +> And as always im not afraid to RTFM if someone can point me to the FM :-) + +Use Linux Software RAID. To get hardware RAID better than Linux Software= +=20 +RAID, you have to spend $800 or more.=20 + + +--=20 +-Josh Berkus + Aglio Database Solutions + San Francisco + + +From pgsql-performance-owner@postgresql.org Fri May 2 16:53:35 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 7425E4763E4 + for ; + Fri, 2 May 2003 16:53:34 -0400 (EDT) +Received: from utahisp.com (pop3.cyberwires.com [66.239.12.3]) + by postgresql.org (Postfix) with ESMTP id D98824763C2 + for ; + Fri, 2 May 2003 16:53:32 -0400 (EDT) +Received: from chad [63.230.8.76] by utahisp.com + (SMTPD32-7.14) id A9FB9007012C; Fri, 02 May 2003 14:50:03 -0600 +Message-ID: <0c9a01c310ec$e5605d90$32021aac@chad> +From: "Chad Thompson" +To: , + "pgsql-performance" +References: <0c2101c310dc$28e3c090$32021aac@chad> + <200305021310.46770.josh@agliodbs.com> +Subject: Re: Looking for a cheap upgrade (RAID) +Date: Fri, 2 May 2003 14:53:33 -0600 +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit +X-Priority: 3 +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook Express 6.00.2720.3000 +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 +X-Declude-Sender: chad@weblinkservices.com [63.230.8.76] +X-Declude-Spoolname: Dd9fb9007012c035e.SMD +X-Note: This E-mail was scanned by Declude JunkMail (www.declude.com) for + spam. +X-Spam-Status: No, hits=-18.7 required=5.0 + tests=BAYES_20,ORIGINAL_MESSAGE,QUOTED_EMAIL_TEXT,REFERENCES, + SMTPD_IN_RCVD autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/10 +X-Sequence-Number: 1789 + +Can WAL and the swap partition be on the same drive? + +Thanks +Chad +----- Original Message ----- +From: "Josh Berkus" +To: "Chad Thompson" ; "pgsql-performance" + +Sent: Friday, May 02, 2003 2:10 PM +Subject: Re: [PERFORM] Looking for a cheap upgrade (RAID) + + +Chad, + +> I realize that Im a raid on linux newbie so any suggestions are +appreciated. +> Im thinking I want to put this on an IDE Raid array, probably 0+1. IDE +seems +> to be cheap and effective these days. +> What ive been able to glean from other postings is that I should have 3 +> drives, 2 for the database w/ striping and another for the WAL. + +Well, RAID 0+1 is only relevant if you have more than 2 drives. Otherwise, +it's just RAID 1 (which is a good choice for PostgreSQL). + +More disks is almost always better. Putting WAL on a seperate (non-RAID) +disk +is usually a very good idea. + +> I would also appreciate raid hardware suggestions (brands, etc) +> And as always im not afraid to RTFM if someone can point me to the FM :-) + +Use Linux Software RAID. To get hardware RAID better than Linux Software +RAID, you have to spend $800 or more. + + +-- +-Josh Berkus + Aglio Database Solutions + San Francisco + + +From pgsql-performance-owner@postgresql.org Fri May 2 17:31:32 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 36D4B47642C + for ; + Fri, 2 May 2003 17:31:31 -0400 (EDT) +Received: from mail1.ihs.com (mail1.ihs.com [170.207.70.222]) + by postgresql.org (Postfix) with ESMTP id 3689447642A + for ; + Fri, 2 May 2003 17:31:30 -0400 (EDT) +Received: from css120.ihs.com (css120.ihs.com [170.207.105.120]) + by mail1.ihs.com (8.12.9/8.12.9) with ESMTP id h42LUDXL014670; + Fri, 2 May 2003 15:30:13 -0600 (MDT) +Date: Fri, 2 May 2003 15:20:56 -0600 (MDT) +From: "scott.marlowe" +To: Chad Thompson +Cc: , pgsql-performance +Subject: Re: Looking for a cheap upgrade (RAID) +In-Reply-To: <0c9a01c310ec$e5605d90$32021aac@chad> +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-MailScanner: Found to be clean +X-MailScanner-SpamCheck: +X-Spam-Status: No, hits=-31.7 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REPLY_WITH_QUOTES,USER_AGENT_PINE autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/11 +X-Sequence-Number: 1790 + +Seeing as you'll have 2 gigs of RAM, your swap partition is likely to grow +cob webs, so where you put it probably isn't that critical. + +What I usually do is say take 4 120 Gig drives, allocate 1 gig on each for +swap, so you have 4 gigs swap (your swap should be larger than available +memory in Linux for performance reasons) and the rest of the drives split +so that say, the first 5 or so gigs of each is used to house most of the +OS, and the rest for another RAID array hosting the database. Since the +root partition can't be on RAID5, you'd have to set up either a single +drive or a mirror set to handle that. + +With that setup, you'd have 15 Gigs for the OS, 4 gigs for swap, and about +300 gigs for the database. The nice thing about RAID 5 is that random +read performance for parallel load gets better as you add drives. Write +performance gets a little better with more drives since it's likely that +the drives you're writing to aren't the same ones being read. + +Since your swap os likely to never see much use, except for offline +storage of long running processes that haven't been accessed recently, +it's probably fine to put them on the same drive, but honestly, I've not +found a great increase from drive configuration under IDE. With SCSI, +rearranging can make a bigger difference, maybe it's the better buss +design, i don't know for sure. Test them if you have the time now, you +won't get to take apart a working machine after it's up to test it. :) + +On Fri, 2 May 2003, Chad Thompson wrote: + +> Can WAL and the swap partition be on the same drive? +> +> Thanks +> Chad +> ----- Original Message ----- +> From: "Josh Berkus" +> To: "Chad Thompson" ; "pgsql-performance" +> +> Sent: Friday, May 02, 2003 2:10 PM +> Subject: Re: [PERFORM] Looking for a cheap upgrade (RAID) +> +> +> Chad, +> +> > I realize that Im a raid on linux newbie so any suggestions are +> appreciated. +> > Im thinking I want to put this on an IDE Raid array, probably 0+1. IDE +> seems +> > to be cheap and effective these days. +> > What ive been able to glean from other postings is that I should have 3 +> > drives, 2 for the database w/ striping and another for the WAL. +> +> Well, RAID 0+1 is only relevant if you have more than 2 drives. Otherwise, +> it's just RAID 1 (which is a good choice for PostgreSQL). +> +> More disks is almost always better. Putting WAL on a seperate (non-RAID) +> disk +> is usually a very good idea. +> +> > I would also appreciate raid hardware suggestions (brands, etc) +> > And as always im not afraid to RTFM if someone can point me to the FM :-) +> +> Use Linux Software RAID. To get hardware RAID better than Linux Software +> RAID, you have to spend $800 or more. +> +> +> -- +> -Josh Berkus +> Aglio Database Solutions +> San Francisco +> +> +> ---------------------------(end of broadcast)--------------------------- +> TIP 5: Have you checked our extensive FAQ? +> +> http://www.postgresql.org/docs/faqs/FAQ.html +> + + +From pgsql-performance-owner@postgresql.org Fri May 2 18:11:08 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id A1D1047645A + for ; + Fri, 2 May 2003 18:11:04 -0400 (EDT) +Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) + by postgresql.org (Postfix) with ESMTP id C3507476440 + for ; + Fri, 2 May 2003 18:11:03 -0400 (EDT) +Received: from [66.219.92.2] (HELO temoku) + by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) + with ESMTP id 3004166; Fri, 02 May 2003 15:10:54 -0700 +Content-Type: text/plain; + charset="iso-8859-1" +From: Josh Berkus +Reply-To: josh@agliodbs.com +Organization: Aglio Database Solutions +To: "scott.marlowe" , + Chad Thompson +Subject: Re: Looking for a cheap upgrade (RAID) +Date: Fri, 2 May 2003 15:10:25 -0700 +User-Agent: KMail/1.4.3 +Cc: pgsql-performance +References: +In-Reply-To: +MIME-Version: 1.0 +Content-Transfer-Encoding: quoted-printable +Message-Id: <200305021510.25982.josh@agliodbs.com> +X-Spam-Status: No, hits=-32.4 required=5.0 + tests=BAYES_01,IN_REP_TO,QUOTED_EMAIL_TEXT,REFERENCES, + REPLY_WITH_QUOTES,USER_AGENT_KMAIL autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/12 +X-Sequence-Number: 1791 + +Scott, + +> With that setup, you'd have 15 Gigs for the OS, 4 gigs for swap, and abou= +t=20 +> 300 gigs for the database. The nice thing about RAID 5 is that random=20 +> read performance for parallel load gets better as you add drives. Write= +=20 +> performance gets a little better with more drives since it's likely that= +=20 +> the drives you're writing to aren't the same ones being read.=20=20 + +Yeah, but I've found with relatively few drives (such as the minimum of 3)= +=20 +that RAID 5 performance is considerably worse for writes than RAID 1 -- as= +=20 +bad as 30-40% of the speed of a raw SCSI disk. This problem goes away wit= +h=20 +more disks, of course. + +--=20 +-Josh Berkus + +______AGLIO DATABASE SOLUTIONS___________________________ + Josh Berkus + Complete information technology josh@agliodbs.com + and data management solutions (415) 565-7293 + for law firms, small businesses fax 621-2533 + and non-profit organizations. San Francisco + + +From pgsql-performance-owner@postgresql.org Fri May 2 18:28:24 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 820FC4763E5 + for ; + Fri, 2 May 2003 18:28:23 -0400 (EDT) +Received: from mail1.ihs.com (mail1.ihs.com [170.207.70.222]) + by postgresql.org (Postfix) with ESMTP id B1DB04763A1 + for ; + Fri, 2 May 2003 18:28:22 -0400 (EDT) +Received: from css120.ihs.com (css120.ihs.com [170.207.105.120]) + by mail1.ihs.com (8.12.9/8.12.9) with ESMTP id h42MRbXL018333; + Fri, 2 May 2003 16:27:37 -0600 (MDT) +Date: Fri, 2 May 2003 16:18:21 -0600 (MDT) +From: "scott.marlowe" +To: Josh Berkus +Cc: Chad Thompson , + pgsql-performance +Subject: Re: Looking for a cheap upgrade (RAID) +In-Reply-To: <200305021510.25982.josh@agliodbs.com> +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-MailScanner: Found to be clean +X-MailScanner-SpamCheck: +X-Spam-Status: No, hits=-31.7 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REPLY_WITH_QUOTES,USER_AGENT_PINE autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/13 +X-Sequence-Number: 1792 + +On Fri, 2 May 2003, Josh Berkus wrote: + +> Scott, +> +> > With that setup, you'd have 15 Gigs for the OS, 4 gigs for swap, and about +> > 300 gigs for the database. The nice thing about RAID 5 is that random +> > read performance for parallel load gets better as you add drives. Write +> > performance gets a little better with more drives since it's likely that +> > the drives you're writing to aren't the same ones being read. +> +> Yeah, but I've found with relatively few drives (such as the minimum of 3) +> that RAID 5 performance is considerably worse for writes than RAID 1 -- as +> bad as 30-40% of the speed of a raw SCSI disk. This problem goes away with +> more disks, of course. + +Yeah, My RAID test box is an old dual PPro 200 with 6 to 8 2 gig drives in +it and on two seperate scsi channels. It's truly amazing how much better +RAID5 is when you get that many drives together. OF course, RAID 0 on +that setup really flies. :-0 + +I'd have to say if you're only gonna need 50 or so gigs max, then a RAID1 +is much easier to configure, and with a hot spare is very reliable. + + +From pgsql-performance-owner@postgresql.org Fri May 2 23:18:23 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 4E5B5475A8D + for ; + Fri, 2 May 2003 23:18:22 -0400 (EDT) +Received: from torque.intervideoinc.com (mail.intervideo.com + [206.112.112.151]) + by postgresql.org (Postfix) with ESMTP id 25575475A80 + for ; + Fri, 2 May 2003 23:18:21 -0400 (EDT) +Received: from ronpc [63.68.5.2] by torque.intervideoinc.com + (SMTPD32-5.05) id A9DF739007E; Fri, 02 May 2003 20:39:11 -0700 +From: "Ron Mayer" +To: "Peter Childs" +Cc: +Subject: Re: Query Priority +Date: Fri, 2 May 2003 20:10:02 -0700 +Message-ID: +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit +X-Priority: 3 (Normal) +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2727.1300 +Importance: Normal +In-Reply-To: <10241.1051885390@sss.pgh.pa.us> +X-Spam-Status: No, hits=-20.8 required=5.0 + tests=BAYES_10,EMAIL_ATTRIBUTION,IN_REP_TO,MSGID_GOOD_EXCHANGE, + SMTPD_IN_RCVD autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/14 +X-Sequence-Number: 1793 + +Peter Childs writes: +>Is there some way to give some postgres backends higher priority. + +>I find my self with a database thats slowed to a craw because of a +>slow batch program it not letting the gui clients the speed they require +>to be usable. + + +Well, if your backend-process is CPU bound (large in memory sorts & joins)... + + The Linux (and SunOS and Ultrix and most certainly others) scheduler, + has logic to make "interactive tasks" more responsive automatically provides + whatever the benefit you might expect by automatically adjusting the + priority of such processes. + + If you have one backend hogging the CPU, it _will_ use its entire time + slice, and not get a "bonus" to it's priority. In contrast, backends + that do simple fast queries will _not_ use their whole time slice, so + they look like "interactive processes" to the kernel and do get a bonus + to their priority. + + I think that this means that a reporting system where some people are + doing big sorts and others are doing little fast queries, the little + fast ones actually do run at a higher priority (assuming they don't + have to block waiting for each other). + + These slides: + http://www.inf.fu-berlin.de/lehre/SS01/OS/Lectures/Lecture08.pdf + explain how this works. + +On the other hand, if your process is IO bound (large table seq_scan)... + + I don't think setting the scheduler priority will help your application + much anyway. + + I strongly suspect which I/O scheduler you're using would have a bigger + effect than a priority setting. There are a few to choose from. + http://lwn.net/Articles/23411/ + http://www.cs.rice.edu/~ssiyer/r/antsched/shines.html + I haven't tried any except the default. + +If the batch process you're worrying about is I/O bound and doing lots of writes... + ... you might want to play with one of the newer I/O schedulers in + the newer kernel... + + It looks like the 2.4 I/O scheduler has a bad behavior where a process + doing lots of writes starves other processes that are trying to do + reads... + http://www.ussg.iu.edu/hypermail/linux/kernel/0302.2/1370.html + all the newer schedulers seem to improve this. + + + +PS: Did anyone try any of the newer I/O schedulers? I have a reporting + system that gets pretty unresponsive while large loads of data are + occurring, and was curious if those patches would be the answer... + + +From pgsql-performance-owner@postgresql.org Sat May 3 01:51:05 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 4F8CC475E9D + for ; + Sat, 3 May 2003 01:51:04 -0400 (EDT) +Received: from nycsmtp4out-eri0.rdc-nyc.rr.com + (nycsmtp4out-eri0.rdc-nyc.rr.com [24.29.99.227]) + by postgresql.org (Postfix) with ESMTP id EA645475A80 + for ; + Sat, 3 May 2003 01:50:57 -0400 (EDT) +Received: from [192.168.1.100] (24-193-64-140.nyc.rr.com [24.193.64.140]) + by nycsmtp4out-eri0.rdc-nyc.rr.com (8.12.1/Road Runner SMTP Server 1.0) + with ESMTP id h435ovPc027560 for ; + Sat, 3 May 2003 01:50:57 -0400 (EDT) +Subject: looking for large dataset +From: Antoine +To: pgsql-performance@postgresql.org +Content-Type: text/plain +Organization: +Message-Id: <1051941161.4247.12.camel@logic> +Mime-Version: 1.0 +X-Mailer: Ximian Evolution 1.2.2 (1.2.2-4) +Date: 03 May 2003 01:52:41 -0400 +Content-Transfer-Encoding: 7bit +X-Spam-Status: No, hits=-10.8 required=5.0 + tests=BAYES_10,FROM_ENDS_IN_NUMS,MAILTO_TO_SPAM_ADDR, + USER_AGENT_XIMIAN autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/15 +X-Sequence-Number: 1794 + +I was woundering where could I find a nice large dataset. Perhaps 50 +thousand records or more +-- +Antoine + + +From pgsql-performance-owner@postgresql.org Sat May 3 01:56:06 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id CD57C475E9D + for ; + Sat, 3 May 2003 01:56:03 -0400 (EDT) +Received: from pantheon-po03.its.yale.edu (pantheon-po03.its.yale.edu + [130.132.50.19]) + by postgresql.org (Postfix) with ESMTP id 0033B475A80 + for ; + Sat, 3 May 2003 01:56:02 -0400 (EDT) +Received: from termite.zoo.cs.yale.edu (termite.zoo.cs.yale.edu + [128.36.232.28]) + by pantheon-po03.its.yale.edu (8.11.6p2/8.11.6) with ESMTP id + h435u2e12140 for ; + Sat, 3 May 2003 01:56:02 -0400 (EDT) +Date: Sat, 3 May 2003 01:56:02 -0400 (EDT) +From: Becky Neville +X-X-Sender: ran26@termite.zoo.cs.yale.edu +To: pgsql-performance@postgresql.org +Subject: NOT IN doesn't use index? +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-YaleITSMailFilter: Version 1.0c (attachment(s) not renamed) +X-Spam-Status: No, hits=-12.3 required=5.0 tests=BAYES_01,USER_AGENT_PINE + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/16 +X-Sequence-Number: 1795 + +I have been looking through the archives but can't find anything on this. + +Does the use of WHERE field NOT IN ('A','B' etc) prevent the use of an +index? +Would changing the query to WHERE field <> 'A' and field <> 'B' etc help? + +The query only involves one table, and this is the only field in the where +clause. Explain plan indicates a Sort and Seq Scan are being done. + +THanks + + +From pgsql-performance-owner@postgresql.org Sat May 3 03:57:56 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id EFAE0475F16 + for ; + Sat, 3 May 2003 03:57:54 -0400 (EDT) +Received: from druid.net (druid.net [216.126.72.98]) + by postgresql.org (Postfix) with ESMTP id 64B27475A80 + for ; + Sat, 3 May 2003 03:57:54 -0400 (EDT) +Received: by druid.net (Postfix, from userid 1000) + id 885541A50; Sat, 3 May 2003 03:57:55 -0400 (EDT) +From: "D'Arcy J.M. Cain" +To: josh@agliodbs.com, "Chad Thompson" , + "pgsql-performance" +Subject: Re: Looking for a cheap upgrade (RAID) +Date: Sat, 3 May 2003 03:57:54 -0400 +User-Agent: KMail/1.5.1 +References: <0c2101c310dc$28e3c090$32021aac@chad> + <200305021310.46770.josh@agliodbs.com> +In-Reply-To: <200305021310.46770.josh@agliodbs.com> +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: quoted-printable +Content-Disposition: inline +Message-Id: <200305030357.54875.darcy@druid.net> +X-Spam-Status: No, hits=-35.7 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,REFERENCES, + REPLY_WITH_QUOTES,USER_AGENT_KMAIL autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/17 +X-Sequence-Number: 1796 + +On Friday 02 May 2003 16:10, Josh Berkus wrote: +> More disks is almost always better. Putting WAL on a seperate (non-RAID) +> disk is usually a very good idea. + + From a performance POV perhaps. The subject came up on hackers recently an= +d=20 +it was pointed out that if you use RAID for reliability and redundancy rath= +er=20 +than for performance, you need to keep the WAL files on the RAID too. + +--=20 +D'Arcy J.M. Cain | Democracy is three wolves +http://www.druid.net/darcy/ | and a sheep voting on ++1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. + + +From pgsql-performance-owner@postgresql.org Sat May 3 04:03:28 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id BF0ED4763DB + for ; + Sat, 3 May 2003 04:03:26 -0400 (EDT) +Received: from www.pspl.co.in (www.pspl.co.in [202.54.11.65]) + by postgresql.org (Postfix) with ESMTP id 9D6414763D8 + for ; + Sat, 3 May 2003 04:03:21 -0400 (EDT) +Received: (from root@localhost) + by www.pspl.co.in (8.11.6/8.11.6) id h4383LO26920 + for ; Sat, 3 May 2003 13:33:21 +0530 +Received: from daithan.intranet.pspl.co.in (daithan.intranet.pspl.co.in + [192.168.7.161]) + by www.pspl.co.in (8.11.6/8.11.0) with ESMTP id h4383La26915 + for ; Sat, 3 May 2003 13:33:21 +0530 +From: Shridhar Daithankar +To: pgsql-performance +Subject: Re: Looking for a cheap upgrade (RAID) +Date: Sat, 3 May 2003 13:32:49 +0530 +User-Agent: KMail/1.5.1 +References: +In-Reply-To: +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit +Content-Disposition: inline +Message-Id: <200305031332.49756.shridhar_daithankar@nospam.persistent.co.in> +X-Spam-Status: No, hits=-38.9 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REFERENCES,REPLY_WITH_QUOTES,USER_AGENT_KMAIL + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/18 +X-Sequence-Number: 1797 + +On Saturday 03 May 2003 02:50, scott.marlowe wrote: +> Seeing as you'll have 2 gigs of RAM, your swap partition is likely to grow +> cob webs, so where you put it probably isn't that critical. +> +> What I usually do is say take 4 120 Gig drives, allocate 1 gig on each for +> swap, so you have 4 gigs swap (your swap should be larger than available +> memory in Linux for performance reasons) and the rest of the drives split +> so that say, the first 5 or so gigs of each is used to house most of the +> OS, and the rest for another RAID array hosting the database. Since the +> root partition can't be on RAID5, you'd have to set up either a single +> drive or a mirror set to handle that. + +Setting swap in linux is a tricky proposition. If there is no swap at all, +linux has behaved crazily in past. These days situation is much better. + +In my experience with single IDE disk, if swap usage goes above 20-30MB due to +shortage of memory, machine is dead in waters. Linux sometimes does memory +inversion where swap used is half the free memory but swap is not freed but +that does not hurt really.. + +So my advice is, setting swap more tahn 128MB is waste of disk space. OK 256 +in ultra-extreme situations.. but more than that would a be unadvisable +situation.. + + Shridhar + + +From pgsql-performance-owner@postgresql.org Sat May 3 04:16:21 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 37E0A475A80 + for ; + Sat, 3 May 2003 04:16:17 -0400 (EDT) +Received: from www.pspl.co.in (www.pspl.co.in [202.54.11.65]) + by postgresql.org (Postfix) with ESMTP id 947424763BE + for ; + Sat, 3 May 2003 04:16:11 -0400 (EDT) +Received: (from root@localhost) + by www.pspl.co.in (8.11.6/8.11.6) id h438GB127338 + for ; Sat, 3 May 2003 13:46:11 +0530 +Received: from daithan.intranet.pspl.co.in (daithan.intranet.pspl.co.in + [192.168.7.161]) + by www.pspl.co.in (8.11.6/8.11.0) with ESMTP id h438GBa27333 + for ; Sat, 3 May 2003 13:46:11 +0530 +From: Shridhar Daithankar +To: "pgsql-performance" +Subject: Re: Looking for a cheap upgrade (RAID) +Date: Sat, 3 May 2003 13:45:40 +0530 +User-Agent: KMail/1.5.1 +References: <0c2101c310dc$28e3c090$32021aac@chad> + <200305021310.46770.josh@agliodbs.com> + <200305030357.54875.darcy@druid.net> +In-Reply-To: <200305030357.54875.darcy@druid.net> +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit +Content-Disposition: inline +Message-Id: <200305031345.40156.shridhar_daithankar@nospam.persistent.co.in> +X-Spam-Status: No, hits=-38.9 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REFERENCES,REPLY_WITH_QUOTES,USER_AGENT_KMAIL + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/19 +X-Sequence-Number: 1798 + +On Saturday 03 May 2003 13:27, D'Arcy J.M. Cain wrote: +> On Friday 02 May 2003 16:10, Josh Berkus wrote: +> > More disks is almost always better. Putting WAL on a seperate (non-RAID) +> > disk is usually a very good idea. +> +> From a performance POV perhaps. The subject came up on hackers recently +> and it was pointed out that if you use RAID for reliability and redundancy +> rather than for performance, you need to keep the WAL files on the RAID +> too. + +but for performance reason, that RAID can be separate from the data RAID..:-) + + Shridhar + +-- +"Gee, Toto, I don't think we are in Kansas anymore." + + +From pgsql-performance-owner@postgresql.org Sat May 3 06:05:40 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 2A403475458 + for ; + Sat, 3 May 2003 06:05:39 -0400 (EDT) +Received: from houston.familyhealth.com.au (unknown [203.59.48.253]) + by postgresql.org (Postfix) with ESMTP id F18D3475458 + for ; + Sat, 3 May 2003 06:04:35 -0400 (EDT) +Received: from localhost (chriskl@localhost) + by houston.familyhealth.com.au (8.11.6p2/8.11.6) with ESMTP id + h43A4Mb30668; Sat, 3 May 2003 18:04:24 +0800 (WST) + (envelope-from chriskl@familyhealth.com.au) +Date: Sat, 3 May 2003 18:04:22 +0800 (WST) +From: Christopher Kings-Lynne +To: Antoine +Cc: pgsql-performance@postgresql.org +Subject: Re: looking for large dataset +In-Reply-To: <1051941161.4247.12.camel@logic> +Message-ID: <20030503180415.N30216-100000@houston.familyhealth.com.au> +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-Spam-Status: No, hits=-24.1 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,MAILTO_TO_SPAM_ADDR, + NO_DNS_FOR_FROM,QUOTED_EMAIL_TEXT,REPLY_WITH_QUOTES + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/20 +X-Sequence-Number: 1799 + +That's a very small dataset :) + +Chris + +On 3 May 2003, Antoine wrote: + +> I was woundering where could I find a nice large dataset. Perhaps 50 +> thousand records or more +> -- +> Antoine +> +> +> ---------------------------(end of broadcast)--------------------------- +> TIP 2: you can get off all lists at once with the unregister command +> (send "unregister YourEmailAddressHere" to majordomo@postgresql.org) +> + + +From pgsql-performance-owner@postgresql.org Sat May 3 10:53:16 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 197C0476349 + for ; + Sat, 3 May 2003 10:53:15 -0400 (EDT) +Received: from mail.libertyrms.com (unknown [209.167.124.227]) + by postgresql.org (Postfix) with ESMTP id 62A02476349 + for ; + Sat, 3 May 2003 10:52:14 -0400 (EDT) +Received: from [10.1.2.130] (helo=dba2) + by mail.libertyrms.com with esmtp (Exim 3.22 #3 (Debian)) + id 19ByN4-0003P6-00 + for ; Sat, 03 May 2003 10:52:14 -0400 +Received: by dba2 (Postfix, from userid 1019) + id 20308CF78; Sat, 3 May 2003 10:52:12 -0400 (EDT) +Date: Sat, 3 May 2003 10:52:12 -0400 +From: Andrew Sullivan +To: pgsql-performance@postgresql.org +Subject: Re: NOT IN doesn't use index? +Message-ID: <20030503145212.GB16290@libertyrms.info> +Mail-Followup-To: Andrew Sullivan , + pgsql-performance@postgresql.org +References: +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: +User-Agent: Mutt/1.5.3i +X-Spam-Status: No, hits=-36.7 required=5.0 + tests=BAYES_10,EMAIL_ATTRIBUTION,IN_REP_TO,NO_DNS_FOR_FROM, + QUOTED_EMAIL_TEXT,REFERENCES,REPLY_WITH_QUOTES, USER_AGENT_MUTT + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/21 +X-Sequence-Number: 1800 + +On Sat, May 03, 2003 at 01:56:02AM -0400, Becky Neville wrote: +> Does the use of WHERE field NOT IN ('A','B' etc) prevent the use of an +> index? + +That '&c.' is hiding a lot. Why not post your query and the explain +analyse output? + +A +-- +---- +Andrew Sullivan 204-4141 Yonge Street +Liberty RMS Toronto, Ontario Canada + M2P 2A8 + +1 416 646 3304 x110 + + +From pgsql-performance-owner@postgresql.org Sat May 3 11:13:23 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 08FA2476420 + for ; + Sat, 3 May 2003 11:13:21 -0400 (EDT) +Received: from pantheon-po03.its.yale.edu (pantheon-po03.its.yale.edu + [130.132.50.19]) + by postgresql.org (Postfix) with ESMTP id 2EA9947641F + for ; + Sat, 3 May 2003 11:13:20 -0400 (EDT) +Received: from termite.zoo.cs.yale.edu (termite.zoo.cs.yale.edu + [128.36.232.28]) + by pantheon-po03.its.yale.edu (8.11.6p2/8.11.6) with ESMTP id + h43FDHt12592; Sat, 3 May 2003 11:13:17 -0400 (EDT) +Date: Sat, 3 May 2003 11:13:17 -0400 (EDT) +From: Becky Neville +X-X-Sender: ran26@termite.zoo.cs.yale.edu +To: Christopher Kings-Lynne +Cc: Antoine , + +Subject: Re: looking for large dataset +In-Reply-To: <20030503180415.N30216-100000@houston.familyhealth.com.au> +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-YaleITSMailFilter: Version 1.0c (attachment(s) not renamed) +X-Spam-Status: No, hits=-31.1 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,MAILTO_TO_SPAM_ADDR, + QUOTED_EMAIL_TEXT,REPLY_WITH_QUOTES,USER_AGENT_PINE + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/22 +X-Sequence-Number: 1801 + +If you can create a flat file with some rows, it's pretty easy to +duplicate them as many times as you need to get up to 50k (which, as +previously mentioned, is relatively small) + +This might not work if you need "real" data - but I started with 67k rows +of real data in my table, then copied them to a temp table, +updated the 3 key fields with previous value + max value, +and inserted back into the original table. (Just to ensure my new rows +had new values for those 3 fields.) + +On Sat, 3 May 2003, Christopher Kings-Lynne wrote: + +> That's a very small dataset :) +> +> Chris +> +> On 3 May 2003, Antoine wrote: +> +> > I was woundering where could I find a nice large dataset. Perhaps 50 +> > thousand records or more +> > -- +> > Antoine +> > +> > +> > ---------------------------(end of broadcast)--------------------------- +> > TIP 2: you can get off all lists at once with the unregister command +> > (send "unregister YourEmailAddressHere" to majordomo@postgresql.org) +> > +> +> +> ---------------------------(end of broadcast)--------------------------- +> TIP 5: Have you checked our extensive FAQ? +> +> http://www.postgresql.org/docs/faqs/FAQ.html +> + + +From pgsql-performance-owner@postgresql.org Sat May 3 13:41:05 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 53A94475A8D + for ; + Sat, 3 May 2003 13:41:03 -0400 (EDT) +Received: from pantheon-po03.its.yale.edu (pantheon-po03.its.yale.edu + [130.132.50.19]) + by postgresql.org (Postfix) with ESMTP id D7A1B476394 + for ; + Sat, 3 May 2003 13:40:30 -0400 (EDT) +Received: from termite.zoo.cs.yale.edu (termite.zoo.cs.yale.edu + [128.36.232.28]) + by pantheon-po03.its.yale.edu (8.11.6p2/8.11.6) with ESMTP id + h43HeUt09518 for ; + Sat, 3 May 2003 13:40:30 -0400 (EDT) +Date: Sat, 3 May 2003 13:40:28 -0400 (EDT) +From: Becky Neville +X-X-Sender: ran26@termite.zoo.cs.yale.edu +To: pgsql-performance@postgresql.org +Subject: why is the db so slow? +In-Reply-To: <20030503054340.A82CA475E9D@postgresql.org> +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-YaleITSMailFilter: Version 1.0c (attachment(s) not renamed) +X-Spam-Status: No, hits=-14.2 required=5.0 + tests=BAYES_01,IN_REP_TO,NO_DNS_FOR_FROM,USER_AGENT_PINE + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/23 +X-Sequence-Number: 1802 + +I am running my own database server but I don't have root privilege (and +no hope of getting it.) + +I only have 3 tables, with rowcounts of 3000, 48000 and 2 million. +I don't think this is that many rows but most things take a long time to +run. There are a lot of indexes on each table and creating an index on +the 2mil row table takes forever, which I could perhaps live with BUT - + +typing something as dumb as \! pwd is not instantaneous either and there +doesn't seem to be anyone else hogging up the CPU. + +I am on Linux and due to lack of space in my own account, I have PGDATA +pointing to /tmp. +(This is for a class project to analyze query performance ...I can +recreate the data at any time if necessary.) + +Are there any parameters I can set to speed things up? + +Thanks +Becky + + +From pgsql-performance-owner@postgresql.org Sat May 3 13:58:01 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 27CDB475B99 + for ; + Sat, 3 May 2003 13:57:59 -0400 (EDT) +Received: from pantheon-po03.its.yale.edu (pantheon-po03.its.yale.edu + [130.132.50.19]) + by postgresql.org (Postfix) with ESMTP id EDBF9475A8D + for ; + Sat, 3 May 2003 13:57:52 -0400 (EDT) +Received: from termite.zoo.cs.yale.edu (termite.zoo.cs.yale.edu + [128.36.232.28]) + by pantheon-po03.its.yale.edu (8.11.6p2/8.11.6) with ESMTP id + h43Hvqt19487; Sat, 3 May 2003 13:57:52 -0400 (EDT) +Date: Sat, 3 May 2003 13:57:52 -0400 (EDT) +From: Becky Neville +X-X-Sender: ran26@termite.zoo.cs.yale.edu +To: andrew@libertyrms.info +Cc: pgsql-performance@postgresql.org +Subject: Re: NOT IN doesn't use index? (fwd) +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-YaleITSMailFilter: Version 1.0c (attachment(s) not renamed) +X-Spam-Status: No, hits=-20.1 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,MAILTO_TO_SPAM_ADDR, + NO_DNS_FOR_FROM,QUOTED_EMAIL_TEXT,USER_AGENT_PINE + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/24 +X-Sequence-Number: 1803 + +Here is the EXPLAIN output from the two queries. The first is the one +that uses WHERE field NOT IN ( 'a','b' etc ). The second is the (much +faster) one +that uses WHERE NOT (field = 'a' and field = 'b' etc). + +I don't understand why the query planner thinks there are only 38055 rows +in the table on the slow one. I didn't run analyze in between them and the +second try seems to know (correctly) that there are 1799976 rows. + +Also, why does the first (slow) one think there are 38055 rows and only +evaluate 48 rows - and yet it still takes longer. ? I assume it's due to +the lack of a sort, but I don't understand why using NOT IN should +prohibit a sort. + +-------------slow one - ~9 minutes----------------------- +/home/accts/ran26/cs437/Proj/code/scripts/sql +test=# \i query3.sql +psql:query3.sql:76: NOTICE: QUERY PLAN: + +Seq Scan on uabopen (cost=0.00..3305914.86 rows=38055 width=7) (actual +time=36577.26..494243.37 rows=48 loops=1) +Total runtime: 494243.67 msec + +--------------faster one - 2 minutes----------------- +psql:query3Mod2.sql:77: NOTICE: QUERY PLAN: + +Unique (cost=3592408.28..3596908.22 rows=179998 width=7) (actual +time=104959.31..114131.22 rows=101 loops=1) + -> Sort (cost=3592408.28..3592408.28 rows=1799976 width=7) (actual +time=104959.30..108425.61 rows=1799976 loops=1) + -> Seq Scan on uabopen (cost=0.00..3305914.86 rows=1799976 +width=7) (actual time=30.13..14430.99 rows=1799976 loops=1) +Total runtime: 114220.66 msec + + + +---------- Forwarded message ---------- +Date: Sat, 3 May 2003 13:09:22 -0400 (EDT) +From: Becky Neville +To: Andrew Sullivan +Subject: Re: [PERFORM] NOT IN doesn't use index? + +I didn't post it because the rest of the query is exactly the same (and +the NOT IN list is about a page long - although it's +apparently still shorter than the IN list.) + +I need to verify something and then can send the EXPLAIN output. + +I am running my own server and have no idea what parameters I should use +to speed things up. Everything is dog slow. + + +On Sat, 3 May 2003, Andrew Sullivan wrote: + +> On Sat, May 03, 2003 at 01:56:02AM -0400, Becky Neville wrote: +> > Does the use of WHERE field NOT IN ('A','B' etc) prevent the use of an +> > index? +> +> That '&c.' is hiding a lot. Why not post your query and the explain +> analyse output? +> +> A +> + + +From pgsql-performance-owner@postgresql.org Sat May 3 14:32:00 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 79D5A475B99 + for ; + Sat, 3 May 2003 14:31:57 -0400 (EDT) +Received: from joeconway.com (66-146-172-86.skyriver.net [66.146.172.86]) + by postgresql.org (Postfix) with ESMTP id ACFDC475A8D + for ; + Sat, 3 May 2003 14:31:36 -0400 (EDT) +Received: from [192.168.5.3] (account jconway HELO joeconway.com) + by joeconway.com (CommuniGate Pro SMTP 4.0.4) + with ESMTP-TLS id 1727818; Sat, 03 May 2003 12:07:09 -0700 +Message-ID: <3EB40AE4.8080007@joeconway.com> +Date: Sat, 03 May 2003 11:31:00 -0700 +From: Joe Conway +User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; + rv:1.3) Gecko/20030312 +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: Becky Neville +Cc: pgsql-performance@postgresql.org +Subject: Re: why is the db so slow? +References: +In-Reply-To: +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit +X-Spam-Status: No, hits=-34.3 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,NO_DNS_FOR_FROM, + REFERENCES,REPLY_WITH_QUOTES,USER_AGENT_MOZILLA_UA + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/25 +X-Sequence-Number: 1804 + +Becky Neville wrote: +> Are there any parameters I can set to speed things up? +> + +You haven't given us much in the way of specifics to work with, but here +is a short list of things to try/do: + +- read (amongst other things): +http://www.us.postgresql.org/users-lounge/docs/7.3/postgres/performance-tips.html +http://www.us.postgresql.org/users-lounge/docs/7.3/postgres/runtime-config.html + +- run "VACUUM ANALYZE" on your database +- adjust key default configuration settings: + shared_buffers = 1000 (or maybe 2000 or even 4000 -- above that you'd + need root access, and it might not help anyway) + sort_mem = 8192 (depending on the amount of RAM in the server, this + might be too high/low, but start with something in + the 4000 to 8000K range) +- run "EXPLAIN ANALYZE" on your queries, and send in the results and the +table structure details to the list. + +HTH, + +Joe + + +From pgsql-performance-owner@postgresql.org Sat May 3 14:34:16 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 45312475B99 + for ; + Sat, 3 May 2003 14:34:14 -0400 (EDT) +Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) + by postgresql.org (Postfix) with ESMTP id 69D08475A8D + for ; + Sat, 3 May 2003 14:34:08 -0400 (EDT) +Received: from [63.195.55.98] (HELO spooky) + by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) + with ESMTP id 3006026; Sat, 03 May 2003 11:33:33 -0700 +Content-Type: text/plain; + charset="iso-8859-1" +From: Josh Berkus +Organization: Aglio Database Solutions +To: Becky Neville , pgsql-performance@postgresql.org +Subject: Re: why is the db so slow? +Date: Sat, 3 May 2003 11:32:56 -0700 +User-Agent: KMail/1.4.3 +References: +In-Reply-To: +MIME-Version: 1.0 +Message-Id: <200305031132.56012.josh@agliodbs.com> +Content-Transfer-Encoding: quoted-printable +X-Spam-Status: No, hits=-31.1 required=5.0 + tests=BAYES_01,IN_REP_TO,NO_DNS_FOR_FROM,QUOTED_EMAIL_TEXT, + REFERENCES,REPLY_WITH_QUOTES,USER_AGENT_KMAIL + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/26 +X-Sequence-Number: 1805 + +Becky, + +> I am running my own database server but I don't have root privilege (and +> no hope of getting it.) + +> typing something as dumb as \! pwd is not instantaneous either and there +> doesn't seem to be anyone else hogging up the CPU. + +It sounds to me like the system has something wrong with it if "pwd" takes = +a=20 +while to respond. Even if CPU isn't in heavy use, I'd guess some other=20 +process is eating RAM or disk I/O + +> I am on Linux and due to lack of space in my own account, I have PGDATA +> pointing to /tmp. +> (This is for a class project to analyze query performance ...I can +> recreate the data at any time if necessary.) + +Really? What class? I'm personally very interested to know of schools t= +hat=20 +are teaching PostgreSQL. + +However, if this is for school, PostgreSQL is not very efficient being run = +as=20 +a seperate installation for each user. For multiuser installations, it i= +s=20 +far better to have one installation and many databases with restricted=20 +permissions. + +I also suspect that you database being in /tmp may be causing you problems;= +=20 +many sysadmins put the /tmp partition on their slowest drive since it's=20 +regarded as disposable. + +> Are there any parameters I can set to speed things up? + +Lots, the settings of many of which are a matter of debate. I suggest tha= +t=20 +you browse through the online archives of this list, which will be far more= +=20 +educational than me giving you a few tips. + +However, be aware that no postgresql.conf settings, however clever, can mak= +e=20 +up for an overloaded system, poor disk configuration, or slow system I/O.= +=20=20=20 +At best correct settings ameliorate poor performance. + +--=20 +Josh Berkus +Aglio Database Solutions +San Francisco + + +From pgsql-performance-owner@postgresql.org Sat May 3 14:36:00 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 0A994476237 + for ; + Sat, 3 May 2003 14:35:58 -0400 (EDT) +Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) + by postgresql.org (Postfix) with ESMTP id 543D3475B99 + for ; + Sat, 3 May 2003 14:35:52 -0400 (EDT) +Received: from [63.195.55.98] (HELO spooky) + by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) + with ESMTP id 3006027; Sat, 03 May 2003 11:35:17 -0700 +Content-Type: text/plain; + charset="iso-8859-1" +From: Josh Berkus +Organization: Aglio Database Solutions +To: Becky Neville , andrew@libertyrms.info +Subject: Re: NOT IN doesn't use index? (fwd) +Date: Sat, 3 May 2003 11:34:40 -0700 +User-Agent: KMail/1.4.3 +Cc: pgsql-performance@postgresql.org +References: +In-Reply-To: +MIME-Version: 1.0 +Message-Id: <200305031134.40508.josh@agliodbs.com> +Content-Transfer-Encoding: quoted-printable +X-Spam-Status: No, hits=-31.1 required=5.0 + tests=BAYES_01,IN_REP_TO,NO_DNS_FOR_FROM,QUOTED_EMAIL_TEXT, + REFERENCES,REPLY_WITH_QUOTES,USER_AGENT_KMAIL + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/27 +X-Sequence-Number: 1806 + +Becky, + +> Here is the EXPLAIN output from the two queries. The first is the one +> that uses WHERE field NOT IN ( 'a','b' etc ). The second is the (much +> faster) one +> that uses WHERE NOT (field =3D 'a' and field =3D 'b' etc). + +We still can't help you if you're not posting your actual queries. We have= + no=20 +idea what's in query3.sql. We're not clairvoyant, y'know. + +--=20 +Josh Berkus +Aglio Database Solutions +San Francisco + + +From pgsql-performance-owner@postgresql.org Sat May 3 14:36:05 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 11186476355 + for ; + Sat, 3 May 2003 14:36:02 -0400 (EDT) +Received: from joeconway.com (66-146-172-86.skyriver.net [66.146.172.86]) + by postgresql.org (Postfix) with ESMTP id 4CF46475A8D + for ; + Sat, 3 May 2003 14:35:31 -0400 (EDT) +Received: from [192.168.5.3] (account jconway HELO joeconway.com) + by joeconway.com (CommuniGate Pro SMTP 4.0.4) + with ESMTP-TLS id 1727827; Sat, 03 May 2003 12:11:03 -0700 +Message-ID: <3EB40BCF.9010203@joeconway.com> +Date: Sat, 03 May 2003 11:34:55 -0700 +From: Joe Conway +User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; + rv:1.3) Gecko/20030312 +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: Becky Neville +Cc: andrew@libertyrms.info, pgsql-performance@postgresql.org +Subject: Re: NOT IN doesn't use index? (fwd) +References: +In-Reply-To: +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit +X-Spam-Status: No, hits=-37.5 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,NO_DNS_FOR_FROM, + QUOTED_EMAIL_TEXT,REFERENCES,REPLY_WITH_QUOTES, + USER_AGENT_MOZILLA_UA autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/28 +X-Sequence-Number: 1807 + +Becky Neville wrote: +> Here is the EXPLAIN output from the two queries. The first is the one +> that uses WHERE field NOT IN ( 'a','b' etc ). The second is the (much + +Unless you are working with Postgres 7.4devel (i.e. cvs HEAD), the IN +construct is notoriously slow in Postgres. In cvs it is vastly improved. + +Also, as I mentioned in the other reply, send in "EXPLAIN ANALYZE" +results instead of "EXPLAIN" (and make sure you run "VACUUM ANALYZE" first). + +Joe + + +From pgsql-performance-owner@postgresql.org Sat May 3 15:08:40 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 1697D4762A2 + for ; + Sat, 3 May 2003 15:08:37 -0400 (EDT) +Received: from pantheon-po03.its.yale.edu (pantheon-po03.its.yale.edu + [130.132.50.19]) + by postgresql.org (Postfix) with ESMTP id D59A5476392 + for ; + Sat, 3 May 2003 15:08:04 -0400 (EDT) +Received: from newt.zoo.cs.yale.edu (newt.zoo.cs.yale.edu [128.36.232.43]) + by pantheon-po03.its.yale.edu (8.11.6p2/8.11.6) with ESMTP id + h43J83t28936; Sat, 3 May 2003 15:08:03 -0400 (EDT) +Date: Sat, 3 May 2003 15:08:03 -0400 (EDT) +From: Becky Neville +X-X-Sender: ran26@newt.zoo.cs.yale.edu +To: Joe Conway +Cc: andrew@libertyrms.info, +Subject: Re: NOT IN doesn't use index? (fwd) +In-Reply-To: <3EB40BCF.9010203@joeconway.com> +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-YaleITSMailFilter: Version 1.0c (attachment(s) not renamed) +X-Spam-Status: No, hits=-29.8 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,NO_DNS_FOR_FROM, + QUOTED_EMAIL_TEXT,REPLY_WITH_QUOTES,UPPERCASE_25_50, + USER_AGENT_PINE autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/29 +X-Sequence-Number: 1808 + +Well I think you answered my question already, but just in case +here are the explain results again and the query follows (I warned, it is +long.) And I did run VACUUM ANALYZE beforehand. + +psql:sql/query3.sql:76: NOTICE: QUERY PLAN: + +Seq Scan on uabopen (cost=0.00..3305914.86 rows=56580 width=7) (actual +time=36077.26..491592.22 rows=48 loops=1) +Total runtime: 491592.52 msec +------------------------------------------- + +explain analyze +select uabopen_srat_code + FROM UABOPEN + where uabopen_srat_code not in +('1A','1B','1C','1E','1AC','1BC','1CC','1EC','PG1A', + +'PG1B','PG1C','PG1E','R1A','R1B', + +'R1C','R1E','RD1A','RD1B','RD1C','RD1E','TRF','WN1A', + 'WN1B','WN1C','WN1E', 'APS') + AND uabopen_srat_code not in +('1F','1FD','3A','3AD','3B','3B1','3BD','3C','3CD','3F', + +'3FD','3G','3GD','3H','3HD','4A','4AD','5A','5AD','5B','5BD','5C','5CD', + +'5D','5DD','5E','5ED','5F','5FD','5G','5GD','6A','6AD','6B','6BD','6C', + +'6CD','6D','6DD','8A','8B','8AD','9A','9TA','9AD','9B','9BD','9C','9CD','9D','9D\ +D', + +'9E','9ED','9F','9FD','9G','9GD','9H','9I','9T','ACC','CM3A','CM3B','CM3C','CM3F\ +', + +'CM3G','CM3H','DEM','GR3A','GR3B','GR3C','GR3H','GR4A','GR5A','GR5B','GR5C', + +'GR5D','GR5E','GR5F','GR6A','GR6B','GR6C','GR6D','GR9A','GR9B','GR9C','GR9D','GR\ +9E', + +'GR9F','GR9G','GR9H','GR9T','MT3B','MT3C','MT3G','MT3H','MT4A','MT9A','MT9B','MT\ +9C', + +'MT9D','MT9E','MT9F','MT9G','N1','N10','N100','N101','N102','N103','N104','N105'\ +, + +'N106','N107','N108','N109','ITCP','1FC','3AP','3CP','5AC', + +'5AP','5BC','5BP','5CC','5CP','5DC','5DP','5GC','6AC','6AP','6BC','6BP','6CC','6\ +CP', + +'6DC','6DP','MT5A','MT5B','MT6A','MT6B','MT5H','MT6I','MT6H', + +'5HP','6H','6HC','6HP','6I','6IC','6IP','3BP','5H','5HC', + +'5I','5IC','5IP','GR5H','GR5I','GR6H','GR6I', + +'MT5I','PG5H','PG5I','PG6H','PG6I','WN5H','WN5I','WN6H','WN6I', + +'5CT','6CT','6DT','MT6C','MT6D','MT5C','MT5D','5DT','5HD') + AND UABOPEN_SRAT_CODE NOT IN +('N11','N110','N111','N112','N113','N114','N115','N116','N117','N118','N119','N12', + +'N120','N121','N122','N123','N124','N125','N126','N127','N128','N129','N13','N13\ +0', + +'N131','N132','N133','N134','N135','N136','N137','N138','N139','N14','N140', + +'N141','N142','N143','N144','N145','N146','N147','N148','N149','N15','N150', + +'N151','N152','N153','N154','N155','N156','N157','N158' + + +On Sat, 3 May 2003, Joe Conway wrote: + +> Becky Neville wrote: +> > Here is the EXPLAIN output from the two queries. The first is the one +> > that uses WHERE field NOT IN ( 'a','b' etc ). The second is the (much +> +> Unless you are working with Postgres 7.4devel (i.e. cvs HEAD), the IN +> construct is notoriously slow in Postgres. In cvs it is vastly improved. +> +> Also, as I mentioned in the other reply, send in "EXPLAIN ANALYZE" +> results instead of "EXPLAIN" (and make sure you run "VACUUM ANALYZE" first). +> +> Joe +> +> +> ---------------------------(end of broadcast)--------------------------- +> TIP 2: you can get off all lists at once with the unregister command +> (send "unregister YourEmailAddressHere" to majordomo@postgresql.org) +> + + +From pgsql-performance-owner@postgresql.org Sat May 3 15:31:56 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id E8043475956 + for ; + Sat, 3 May 2003 15:31:53 -0400 (EDT) +Received: from joeconway.com (66-146-172-86.skyriver.net [66.146.172.86]) + by postgresql.org (Postfix) with ESMTP id 446504762A2 + for ; + Sat, 3 May 2003 15:31:48 -0400 (EDT) +Received: from [192.168.5.3] (account jconway HELO joeconway.com) + by joeconway.com (CommuniGate Pro SMTP 4.0.4) + with ESMTP-TLS id 1727853; Sat, 03 May 2003 13:07:21 -0700 +Message-ID: <3EB41900.5010407@joeconway.com> +Date: Sat, 03 May 2003 12:31:12 -0700 +From: Joe Conway +User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; + rv:1.3) Gecko/20030312 +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: Becky Neville +Cc: andrew@libertyrms.info, pgsql-performance@postgresql.org +Subject: Re: NOT IN doesn't use index? (fwd) +References: +In-Reply-To: +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit +X-Spam-Status: No, hits=-37.5 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,NO_DNS_FOR_FROM, + QUOTED_EMAIL_TEXT,REFERENCES,REPLY_WITH_QUOTES, + USER_AGENT_MOZILLA_UA autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/30 +X-Sequence-Number: 1809 + +Becky Neville wrote: +> Well I think you answered my question already, but just in case +> here are the explain results again and the query follows (I warned, it is +> long.) And I did run VACUUM ANALYZE beforehand. + +[snipped ugly query with three NOT IN clauses] + +Hmmm, no surprise that's slow. How are those three lists of constants +generated? One idea is to recast this as a left join with a FROM clause +subselect, e.g. + +select + uabopen_srat_code +from + uabopen u left join + (select '1F' as uabopen_srat_code union all + '1FD' union all + '3A' ...) as ss + on u.uabopen_srat_code = ss.uabopen_srat_code +where ss.uabopen_srat_code is null; + +But I'm not sure that will be much quicker. If the list of +uabopen_srat_code you're filtering on comes from one of the other +tables, you might be able to do better -- back to the question above, +how is that list generated? What do the other table look like? + +Joe + + +From pgsql-performance-owner@postgresql.org Sat May 3 15:57:05 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id B2F69475B99 + for ; + Sat, 3 May 2003 15:57:02 -0400 (EDT) +Received: from pantheon-po03.its.yale.edu (pantheon-po03.its.yale.edu + [130.132.50.19]) + by postgresql.org (Postfix) with ESMTP id D62E6475956 + for ; + Sat, 3 May 2003 15:56:56 -0400 (EDT) +Received: from newt.zoo.cs.yale.edu (newt.zoo.cs.yale.edu [128.36.232.43]) + by pantheon-po03.its.yale.edu (8.11.6p2/8.11.6) with ESMTP id + h43Jurt24995; Sat, 3 May 2003 15:56:53 -0400 (EDT) +Date: Sat, 3 May 2003 15:56:53 -0400 (EDT) +From: Becky Neville +X-X-Sender: ran26@newt.zoo.cs.yale.edu +To: Joe Conway +Cc: pgsql-performance@postgresql.org +Subject: Re: NOT IN doesn't use index? (fwd) +In-Reply-To: <3EB41900.5010407@joeconway.com> +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-YaleITSMailFilter: Version 1.0c (attachment(s) not renamed) +X-Spam-Status: No, hits=-17.4 required=5.0 + tests=BAYES_01,IN_REP_TO,NO_DNS_FOR_FROM,QUOTED_EMAIL_TEXT, + USER_AGENT_PINE autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/31 +X-Sequence-Number: 1810 + +I think that list is actually (gulp) hard coded. It's not my query. I am +trying to speed it up for someone else - to hopefully learn something in +the process that isn't dependent on what version of postgres i'm +running :) + +I assume it's from another table but can't find it on their data model at +the moment. Those are all valid billing codes. The query is checking to see if +anyone was billed under an invalid code. So if everything is ok, the query +returns nothing. + +But there must be more to it than that...otherwise, they could just add a +Valid flag to the lookup table. + +If you have any ideas for speeding it up other than using another table +please let me know. It only takes me 9 min to run with 2 mil rows but it +takes them 7 hours (51 mil rows in Oracle with many other jobs running and +poor system maintenance.) + + + + On Sat, 3 May 2003, Joe Conway +wrote: + +> Becky Neville wrote: +> > Well I think you answered my question already, but just in case +> > here are the explain results again and the query follows (I warned, it is +> > long.) And I did run VACUUM ANALYZE beforehand. +> +> [snipped ugly query with three NOT IN clauses] +> +> Hmmm, no surprise that's slow. How are those three lists of constants +> generated? One idea is to recast this as a left join with a FROM clause +> subselect, e.g. +> +> select +> uabopen_srat_code +> from +> uabopen u left join +> (select '1F' as uabopen_srat_code union all +> '1FD' union all +> '3A' ...) as ss +> on u.uabopen_srat_code = ss.uabopen_srat_code +> where ss.uabopen_srat_code is null; +> +> But I'm not sure that will be much quicker. If the list of +> uabopen_srat_code you're filtering on comes from one of the other +> tables, you might be able to do better -- back to the question above, +> how is that list generated? What do the other table look like? +> +> Joe +> + + +From pgsql-performance-owner@postgresql.org Sat May 3 16:25:47 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 746624763F0 + for ; + Sat, 3 May 2003 16:25:44 -0400 (EDT) +Received: from joeconway.com (66-146-172-86.skyriver.net [66.146.172.86]) + by postgresql.org (Postfix) with ESMTP id 7C1EF475B99 + for ; + Sat, 3 May 2003 16:25:23 -0400 (EDT) +Received: from [192.168.5.3] (account jconway HELO joeconway.com) + by joeconway.com (CommuniGate Pro SMTP 4.0.4) + with ESMTP-TLS id 1727875; Sat, 03 May 2003 14:00:47 -0700 +Message-ID: <3EB42586.6080301@joeconway.com> +Date: Sat, 03 May 2003 13:24:38 -0700 +From: Joe Conway +User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; + rv:1.3) Gecko/20030312 +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: Becky Neville +Cc: pgsql-performance@postgresql.org +Subject: Re: NOT IN doesn't use index? (fwd) +References: +In-Reply-To: +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit +X-Spam-Status: No, hits=-37.5 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,NO_DNS_FOR_FROM, + QUOTED_EMAIL_TEXT,REFERENCES,REPLY_WITH_QUOTES, + USER_AGENT_MOZILLA_UA autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/32 +X-Sequence-Number: 1811 + +Becky Neville wrote: +> I think that list is actually (gulp) hard coded. It's not my query. +> I am trying to speed it up for someone else - to hopefully learn something +> in the process that isn't dependent on what version of postgres i'm +> running :) +> +> I assume it's from another table but can't find it on their data +> model at the moment. Those are all valid billing codes. The query +> is checking to see if anyone was billed under an invalid code. So if +> everything is ok, the query returns nothing. + +Yeah -- that sounds like there has to be a table of valid codes +somewhere. In that case you can substitute the "valid_codes" table in +the left join where I had the subselect with all the UNIONs. +Alternatively you might find a NOT EXISTS method would work best. If +there isn't a "valid_codes" table, but that hard coded list is static, +perhaps you could build one and use that. + +> But there must be more to it than that...otherwise, they could just +> add a Valid flag to the lookup table. + +Well I certainly wouldn't query a whole table of historical information +over and over. Can you use and date column (suitably indexed) to just +check recent transactions (like since the last time you checked)? + +> If you have any ideas for speeding it up other than using another +> table please let me know. It only takes me 9 min to run with 2 mil +> rows but it takes them 7 hours (51 mil rows in Oracle with many other +> jobs running and poor system maintenance.) + +As above, are all 51 million rows recent transactions, or is that all of +eternity? If its the latter, I'd scan the whole thing once and produce a +report, or maybe a "transactions_with_invalid_codes" table. + + From that point on, I'd only check the transactions since the last time +I'd checked, either based on a timestamp or even a sequence generated id +field. All you need to do is save off the max value each time you run, +and then use that as the starting point next time. + +HTH, + +Joe + + +From pgsql-performance-owner@postgresql.org Sat May 3 16:30:46 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id CD6DE4763F0 + for ; + Sat, 3 May 2003 16:30:43 -0400 (EDT) +Received: from themode.com (themode.com [161.58.169.198]) + by postgresql.org (Postfix) with ESMTP id 48966475B99 + for ; + Sat, 3 May 2003 16:30:37 -0400 (EDT) +Received: from localhost (mode@localhost) by themode.com (8.12.9) id + h43KUcYU063913; Sat, 3 May 2003 16:30:38 -0400 (EDT) +Date: Sat, 3 May 2003 16:30:38 -0400 (EDT) +From: brew@theMode.com +X-X-Sender: mode@themode.com +To: pgsql-performance@postgresql.org +Subject: Re: why is the db so slow? +In-Reply-To: <200305031132.56012.josh@agliodbs.com> +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-Spam-Status: No, hits=-16.4 required=5.0 + tests=BAYES_01,IN_REP_TO,NO_DNS_FOR_FROM,NO_REAL_NAME, + QUOTED_EMAIL_TEXT,USER_AGENT_PINE autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/33 +X-Sequence-Number: 1812 + + +replying to Becky and Josh's reply..... + +> It sounds to me like the system has something wrong with it if "pwd" +> takes a while to respond. Even if CPU isn't in heavy use, I'd guess +> some other process is eating RAM or disk I/O + +Look into the unix command 'top'. It lists processes and the amount of +resources they are using. Although if it's another user using them it may +not detail them.... but I think you can get some idea of what other users +are up to from the CPU idle time and server load averages from the 'top' +display. + +> However, if this is for school, PostgreSQL is not very efficient being +> run as a seperate installation for each user. For multiuser +> installations, it is far better to have one installation and many +> databases with restricted permissions. + +I can attest to that, I run a web site using virtual hosting (about 80 +users, each with their own version of Apache (and in my case, my own +version of postgreSQL, I have no idea what the other users are running). +My development Linux laptop is 5 to 10 times faster than the web site, of +course, I'm it's ONLY user. + +brew + + +From pgsql-performance-owner@postgresql.org Sat May 3 16:40:06 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 2A0BD4763F0 + for ; + Sat, 3 May 2003 16:40:04 -0400 (EDT) +Received: from lakemtao04.cox.net (lakemtao04.cox.net [68.1.17.241]) + by postgresql.org (Postfix) with ESMTP id 39251475B99 + for ; + Sat, 3 May 2003 16:39:33 -0400 (EDT) +Received: from [192.168.1.1] ([68.11.66.83]) by lakemtao04.cox.net + (InterMail vM.5.01.04.05 201-253-122-122-105-20011231) with ESMTP + id <20030503203935.RWUY13930.lakemtao04.cox.net@[192.168.1.1]> + for ; + Sat, 3 May 2003 16:39:35 -0400 +Subject: Re: Looking for a cheap upgrade (RAID) +From: Ron Johnson +To: PgSQL Performance ML +In-Reply-To: <0c2101c310dc$28e3c090$32021aac@chad> +References: <0c2101c310dc$28e3c090$32021aac@chad> +Content-Type: text/plain +Organization: +Message-Id: <1051994374.1086.13.camel@haggis> +Mime-Version: 1.0 +X-Mailer: Ximian Evolution 1.2.4 +Date: 03 May 2003 15:39:34 -0500 +Content-Transfer-Encoding: 7bit +X-Spam-Status: No, hits=-43.0 required=5.0 + tests=BAYES_10,EMAIL_ATTRIBUTION,IN_REP_TO,NO_DNS_FOR_FROM, + QUOTED_EMAIL_TEXT,REFERENCES,REPLY_WITH_QUOTES, + SIGNATURE_LONG_DENSE,USER_AGENT_XIMIAN + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/34 +X-Sequence-Number: 1813 + +On Fri, 2003-05-02 at 13:53, Chad Thompson wrote: +> I have a server on a standard pc right now. +> PIII 700, 1Gig ram (SD), 40 Gig IDE, RedHat 8.0, PostgreSQL 7.3.1 +> +> The database has 3 tables that just broke 10 million tuples (yeah, i think +> im entering in to the world of real databases ;-) +> Its primarly bulk (copy) inserts and queries, rarely an update. +> +> I am looking at moving this to a P4 2.4G, 2 Gig Ram(DDR), RedHat 8, +> PostgreSQL 7.3.latest +[snip] + +How big do you expect the database to get? + +If I may be a contrarian, if under 70GB, then why not just get a 72GB +10K RPM SCSI drive ($160) and a SCSI 160 card? OS, swap, input files, +etc, can go on a 7200RPM IDE drive. + +Much fewer moving parts than RAID, so more reliable... + +-- ++-----------------------------------------------------------+ +| Ron Johnson, Jr. Home: ron.l.johnson@cox.net | +| Jefferson, LA USA http://members.cox.net/ron.l.johnson | +| | +| An ad currently being run by the NEA (the US's biggest | +| public school TEACHERS UNION) asks a teenager if he can | +| find sodium and *chloride* in the periodic table of the | +| elements. | +| And they wonder why people think public schools suck... | ++-----------------------------------------------------------+ + + +From pgsql-performance-owner@postgresql.org Sat May 3 17:17:22 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 59B28476376 + for ; + Sat, 3 May 2003 17:17:20 -0400 (EDT) +Received: from nat.inquent.com + (CPE00508b028d7d-CM00803785c5e0.cpe.net.cable.rogers.com + [24.103.22.28]) by postgresql.org (Postfix) with ESMTP id 0CA60475D91 + for ; + Sat, 3 May 2003 17:16:49 -0400 (EDT) +Received: from [127.0.0.1] (localhost [127.0.0.1]) + by nat.inquent.com (8.12.8p1/8.12.8) with ESMTP id h43LGf6h003193; + Sat, 3 May 2003 17:16:41 -0400 (EDT) (envelope-from rbt@rbt.ca) +Subject: Re: NOT IN doesn't use index? (fwd) +From: Rod Taylor +To: Becky Neville +Cc: Joe Conway , + Postgresql Performance +In-Reply-To: +References: +Content-Type: multipart/signed; micalg=pgp-sha1; + protocol="application/pgp-signature"; + boundary="=-vgz3izuTIe49H4MG2sJa" +Organization: +Message-Id: <1051996600.1656.36.camel@jester> +Mime-Version: 1.0 +X-Mailer: Ximian Evolution 1.2.4 +Date: 03 May 2003 17:16:41 -0400 +X-Spam-Status: No, hits=-43.8 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,NO_DNS_FOR_FROM, + PGP_SIGNATURE_2,QUOTED_EMAIL_TEXT,REFERENCES, + REPLY_WITH_QUOTES,USER_AGENT_XIMIAN autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/35 +X-Sequence-Number: 1814 + +--=-vgz3izuTIe49H4MG2sJa +Content-Type: text/plain +Content-Transfer-Encoding: quoted-printable + +On Sat, 2003-05-03 at 15:56, Becky Neville wrote: +> I think that list is actually (gulp) hard coded. It's not my query. I a= +m=20 +> trying to speed it up for someone else - to hopefully learn something in= +=20 +> the process that isn't dependent on what version of postgres i'm=20 +> running :) + +An interesting test might be to see if the overhead of doing a character +based comparison (as opposed to integer based) is significant. If it +is, previous tests show it can be significant for CPU bound queries, +convert all of those codes into integers and use a lookup table table to +do the conversion. + +Another interesting thought, since you have a long running query would +be to attempt an inversion. Create a temporary table with the *valid* +codes if count(valid codes) < 2 * count(invalid codes). Run the query +replacing NOT IN with a join to the temporary table. This will reduce +the number of comparisons required, as a match can move onto the next +datum, but a NOT IN must check all values. If this helps, try indexing +(and analyzing) the temporary table. + +By far the fastest results can be achieved by not allowing invalid +billing codes to be inserted into the table via a constraint of somekind +(check or fkey to summary table). + +--=20 +Rod Taylor + +PGP Key: http://www.rbt.ca/rbtpub.asc + +--=-vgz3izuTIe49H4MG2sJa +Content-Type: application/pgp-signature; name=signature.asc +Content-Description: This is a digitally signed message part + +-----BEGIN PGP SIGNATURE----- +Version: GnuPG v1.2.1 (FreeBSD) + +iD8DBQA+tDG46DETLow6vwwRAoqTAJ9afxXgCKItJ5BtTRZTp8/bceNVbgCfdd30 +f2WZpjjmo7yO2VIOVAf/XGg= +=yU7A +-----END PGP SIGNATURE----- + +--=-vgz3izuTIe49H4MG2sJa-- + + +From pgsql-performance-owner@postgresql.org Sat May 3 22:30:29 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 4B662475F39 + for ; + Sat, 3 May 2003 22:30:26 -0400 (EDT) +Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) + by postgresql.org (Postfix) with ESMTP id A94D2475F39 + for ; + Sat, 3 May 2003 22:29:53 -0400 (EDT) +Received: from [66.219.92.2] (HELO temoku) + by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) + with ESMTP id 3006558 for pgsql-performance@postgresql.org; + Sat, 03 May 2003 19:29:22 -0700 +Content-Type: text/plain; + charset="us-ascii" +From: Josh Berkus +Reply-To: josh@agliodbs.com +Organization: Aglio Database Solutions +To: PgSQL Performance ML +Subject: Suggestions wanted for 7.2.4 query +Date: Sat, 3 May 2003 19:28:52 -0700 +User-Agent: KMail/1.4.3 +MIME-Version: 1.0 +Content-Transfer-Encoding: quoted-printable +Message-Id: <200305031928.52906.josh@agliodbs.com> +X-Spam-Status: No, hits=-11.7 required=5.0 + tests=BAYES_01,NO_DNS_FOR_FROM,USER_AGENT_KMAIL + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/36 +X-Sequence-Number: 1815 + +Folks, + +I have a common query on a production database that's running a little too= +=20 +slow (3-6 seconds). I can currently drop the time to 0.8 seconds by=20 +setting enable_seqscan =3D false; the main reason is the planner poorly=20 +deciding to use a seq scan for the hash join between "events" and "cases",= +=20 +mostly due to a dramatically bad estimate of the number of rows required fr= +om=20 +"cases". + +Suggestions on how to get Postgres to use cases_pkey instead of a seq scan = +on=20 +cases without messing with global query settings in the database which migh= +t=20 +make other queries run slower? (And yes, a VACUUM FULL ANALYZE was=20 +involved).=20=20 + +The View: +create view sv_events as +select events.event_id, events.status, status_label, status.rollup as rstat= +us,=20 +events.etype_id, type_name, + event_cats.ecat_id, cat_name, events.event_date, events.event_name, + jw_date_format(events.event_date, events.event_tz, events.duration) as=20 +show_date, + cases.case_name || '(' || cases.docket || ')' as event_case, + events.case_id, cases.case_name, cases.docket, NULL::VARCHAR as tgroup_nam= +e, + events.location_id, location_name, locations.zip_code, locations.address,= +=20 +locations.state_code, locations.city, + lu.user_name as lock_name, lu.email as lock_email, lu.user_id AS lock_user +FROM status, locations, event_types, event_cats, cases, + events LEFT OUTER JOIN lock_users lu ON events.event_id =3D lock_record +WHERE events.status <> 0 + AND (events.status =3D status.status AND status.relation =3D 'events') + AND events.location_id =3D locations.location_id + AND event_types.etype_id =3D events.etype_id + AND event_cats.ecat_id =3D event_types.ecat_id + AND events.case_id =3D cases.case_id; + +The Query: +SELECT sv_events.*, FALSE AS fuzzy_team FROM sv_events WHERE EXISTS ( SELE= +CT=20 +event_id FROM event_days + WHERE event_days.event_id =3D sv_events.event_id AND (event_day BETWEEN= +=20 +('2003-04-08'::TIMESTAMP WITHOUT TIME ZONE) + AND ('2003-06-17 23:59'::TIMESTAMP WITHOUT TIME ZONE) ) ); + + +The Explain: +jwnet_test=3D> \i perform.sql +psql:perform.sql:9: NOTICE: QUERY PLAN: + +Limit (cost=3D199572.58..199572.58 rows=3D10 width=3D368) (actual=20 +time=3D3239.95..3239.96 rows=3D10 loops=3D1) + -> Sort (cost=3D199572.58..199572.58 rows=3D33575 width=3D368) (actual= +=20 +time=3D3239.92..3239.93 rows=3D41 loops=3D1) + -> Hash Join (cost=3D6576.62..191013.53 rows=3D33575 width=3D368)= + (actual=20 +time=3D513.49..3220.38 rows=3D1790 loops=3D1) + -> Hash Join (cost=3D6574.72..189924.26 rows=3D14837 width= +=3D350)=20 +(actual time=3D509.20..3063.85 rows=3D1790 loops=3D1) + -> Hash Join (cost=3D38.81..180804.32 rows=3D14837=20 +width=3D304) (actual time=3D16.38..452.80 rows=3D1919 loops=3D1) + -> Hash Join (cost=3D33.92..180539.78 rows=3D14= +837=20 +width=3D252) (actual time=3D15.68..428.38 rows=3D1919 loops=3D1) + -> Hash Join (cost=3D22.17..180231.28=20 +rows=3D14837 width=3D155) (actual time=3D13.98..406.61 rows=3D1919 loops=3D= +1) + -> Seq Scan on events=20=20 +(cost=3D0.00..179874.82 rows=3D14837 width=3D67) (actual time=3D0.27..382.4= +7=20 +rows=3D1919 loops=3D1) + SubPlan + -> Index Scan using=20 +event_days_pk on event_days (cost=3D0.00..6.01 rows=3D1 width=3D4) (actual= +=20 +time=3D0.01..0.01 rows=3D0 loops=3D29734) + -> Hash (cost=3D21.99..21.99 rows= +=3D72=20 +width=3D83) (actual time=3D13.66..13.66 rows=3D0 loops=3D1) + -> Subquery Scan lu=20=20 +(cost=3D12.61..21.99 rows=3D72 width=3D83) (actual time=3D13.64..13.65 rows= +=3D1=20 +loops=3D1) + -> Hash Join=20=20 +(cost=3D12.61..21.99 rows=3D72 width=3D83) (actual time=3D13.63..13.64 rows= +=3D1=20 +loops=3D1) + -> Seq Scan on=20 +edit_locks (cost=3D0.00..7.94 rows=3D72 width=3D26) (actual time=3D12.82..= +12.83=20 +rows=3D1 loops=3D1) + -> Hash=20=20 +(cost=3D6.50..6.50 rows=3D150 width=3D57) (actual time=3D0.71..0.71 rows=3D= +0 loops=3D1) + -> Seq Scan = +on=20 +users (cost=3D0.00..6.50 rows=3D150 width=3D57) (actual time=3D0.01..0.47 = +rows=3D150=20 +loops=3D1) + -> Hash (cost=3D11.00..11.00 rows=3D300= +=20 +width=3D97) (actual time=3D1.66..1.66 rows=3D0 loops=3D1) + -> Seq Scan on locations=20=20 +(cost=3D0.00..11.00 rows=3D300 width=3D97) (actual time=3D0.01..1.11 rows= +=3D300=20 +loops=3D1) + -> Hash (cost=3D4.75..4.75 rows=3D56 width=3D52= +) (actual=20 +time=3D0.60..0.60 rows=3D0 loops=3D1) + -> Hash Join (cost=3D1.21..4.75 rows=3D56= +=20 +width=3D52) (actual time=3D0.17..0.51 rows=3D56 loops=3D1) + -> Seq Scan on event_types=20=20 +(cost=3D0.00..2.56 rows=3D56 width=3D31) (actual time=3D0.01..0.15 rows=3D5= +6 loops=3D1) + -> Hash (cost=3D1.17..1.17 rows=3D1= +7=20 +width=3D21) (actual time=3D0.07..0.07 rows=3D0 loops=3D1) + -> Seq Scan on event_cats=20= +=20 +(cost=3D0.00..1.17 rows=3D17 width=3D21) (actual time=3D0.01..0.05 rows=3D1= +7 loops=3D1) + -> Hash (cost=3D3800.07..3800.07 rows=3D112107 width= +=3D46)=20 +(actual time=3D491.84..491.84 rows=3D0 loops=3D1) + -> Seq Scan on cases (cost=3D0.00..3800.07=20 +rows=3D112107 width=3D46) (actual time=3D0.01..277.20 rows=3D112107 loops= +=3D1) + -> Hash (cost=3D1.88..1.88 rows=3D10 width=3D18) (actual=20 +time=3D0.12..0.12 rows=3D0 loops=3D1) + -> Seq Scan on status (cost=3D0.00..1.88 rows=3D10 wi= +dth=3D18)=20 +(actual time=3D0.03..0.11 rows=3D10 loops=3D1) +Total runtime: 3241.09 msec + +The Index Scan: +jwnet_test=3D> set enable_seqscan =3D false; +SET VARIABLE +jwnet_test=3D> \i perform.sql +psql:perform.sql:9: NOTICE: QUERY PLAN: + +Limit (cost=3D252608.52..252608.52 rows=3D10 width=3D368) (actual=20 +time=3D740.62..740.64 rows=3D10 loops=3D1) + -> Sort (cost=3D252608.52..252608.52 rows=3D33469 width=3D368) (actual= +=20 +time=3D740.60..740.61 rows=3D41 loops=3D1) + -> Hash Join (cost=3D86.85..244083.21 rows=3D33469 width=3D368) (= +actual=20 +time=3D20.93..720.70 rows=3D1790 loops=3D1) + -> Hash Join (cost=3D80.75..242992.18 rows=3D14812 width=3D= +350)=20 +(actual time=3D16.69..554.62 rows=3D1790 loops=3D1) + -> Nested Loop (cost=3D49.20..242664.38 rows=3D14812= +=20 +width=3D253) (actual time=3D14.56..519.42 rows=3D1790 loops=3D1) + -> Hash Join (cost=3D49.20..158631.12 rows=3D14= +812=20 +width=3D207) (actual time=3D14.40..459.91 rows=3D1919 loops=3D1) + -> Hash Join (cost=3D32.78..158355.48=20 +rows=3D14812 width=3D155) (actual time=3D13.59..442.08 rows=3D1919 loops=3D= +1) + -> Index Scan using idx_events_statu= +s=20 +on events (cost=3D0.00..157988.97 rows=3D14812 width=3D67) (actual=20 +time=3D0.08..416.67 rows=3D1919 loops=3D1) + SubPlan + -> Index Scan using=20 +event_days_pk on event_days (cost=3D0.00..5.26 rows=3D1 width=3D4) (actual= +=20 +time=3D0.01..0.01 rows=3D0 loops=3D29734) + -> Hash (cost=3D32.60..32.60 rows= +=3D72=20 +width=3D83) (actual time=3D13.47..13.47 rows=3D0 loops=3D1) + -> Subquery Scan lu=20=20 +(cost=3D0.00..32.60 rows=3D72 width=3D83) (actual time=3D1.60..13.46 rows= +=3D1 loops=3D1) + -> Merge Join=20=20 +(cost=3D0.00..32.60 rows=3D72 width=3D83) (actual time=3D1.59..13.45 rows= +=3D1 loops=3D1) + -> Index Scan usin= +g=20 +users_pkey on users (cost=3D0.00..19.63 rows=3D150 width=3D57) (actual=20 +time=3D0.09..0.12 rows=3D3 loops=3D1) + -> Index Scan usin= +g=20 +edit_locks_user_id on edit_locks (cost=3D0.00..11.51 rows=3D72 width=3D26)= + (actual=20 +time=3D1.43..13.28 rows=3D1 loops=3D1) + -> Hash (cost=3D16.28..16.28 rows=3D56 wi= +dth=3D52)=20 +(actual time=3D0.77..0.77 rows=3D0 loops=3D1) + -> Hash Join (cost=3D5.67..16.28 ro= +ws=3D56=20 +width=3D52) (actual time=3D0.29..0.68 rows=3D56 loops=3D1) + -> Index Scan using=20 +event_types_pkey on event_types (cost=3D0.00..9.63 rows=3D56 width=3D31) (= +actual=20 +time=3D0.08..0.28 rows=3D56 loops=3D1) + -> Hash (cost=3D5.63..5.63 ro= +ws=3D17=20 +width=3D21) (actual time=3D0.15..0.15 rows=3D0 loops=3D1) + -> Index Scan using=20 +event_cats_pkey on event_cats (cost=3D0.00..5.63 rows=3D17 width=3D21) (ac= +tual=20 +time=3D0.08..0.13 rows=3D17 loops=3D1) + -> Index Scan using cases_pkey on cases=20=20 +(cost=3D0.00..5.66 rows=3D1 width=3D46) (actual time=3D0.02..0.02 rows=3D1 = +loops=3D1919) + -> Hash (cost=3D30.80..30.80 rows=3D300 width=3D97) (= +actual=20 +time=3D2.07..2.07 rows=3D0 loops=3D1) + -> Index Scan using locations_pkey on locations= +=20=20 +(cost=3D0.00..30.80 rows=3D300 width=3D97) (actual time=3D0.09..1.61 rows= +=3D300=20 +loops=3D1) + -> Hash (cost=3D6.07..6.07 rows=3D10 width=3D18) (actual=20 +time=3D0.08..0.08 rows=3D0 loops=3D1) + -> Index Scan using status_relation on status=20=20 +(cost=3D0.00..6.07 rows=3D10 width=3D18) (actual time=3D0.03..0.06 rows=3D1= +0 loops=3D1) +Total runtime: 741.72 msec + + + +--=20 +-Josh Berkus + Aglio Database Solutions + San Francisco + + +From pgsql-performance-owner@postgresql.org Sun May 4 00:06:13 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 448E747648B + for ; + Sun, 4 May 2003 00:06:10 -0400 (EDT) +Received: from houston.familyhealth.com.au (unknown [203.59.48.253]) + by postgresql.org (Postfix) with ESMTP id 2DD0247646F + for ; + Sun, 4 May 2003 00:06:00 -0400 (EDT) +Received: from localhost (chriskl@localhost) + by houston.familyhealth.com.au (8.11.6p2/8.11.6) with ESMTP id + h4445gd43297; Sun, 4 May 2003 12:05:43 +0800 (WST) + (envelope-from chriskl@familyhealth.com.au) +Date: Sun, 4 May 2003 12:05:42 +0800 (WST) +From: Christopher Kings-Lynne +To: Joe Conway +Cc: Becky Neville , + , +Subject: Re: NOT IN doesn't use index? (fwd) +In-Reply-To: <3EB40BCF.9010203@joeconway.com> +Message-ID: <20030504120511.M43020-100000@houston.familyhealth.com.au> +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-Spam-Status: No, hits=-25.8 required=5.0 + tests=BAYES_00,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REPLY_WITH_QUOTES autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/37 +X-Sequence-Number: 1816 + +AFAIK, it's only the IN (large subquery) form that is slow... + +Chris + +On Sat, 3 May 2003, Joe Conway wrote: + +> Becky Neville wrote: +> > Here is the EXPLAIN output from the two queries. The first is the one +> > that uses WHERE field NOT IN ( 'a','b' etc ). The second is the (much +> +> Unless you are working with Postgres 7.4devel (i.e. cvs HEAD), the IN +> construct is notoriously slow in Postgres. In cvs it is vastly improved. +> +> Also, as I mentioned in the other reply, send in "EXPLAIN ANALYZE" +> results instead of "EXPLAIN" (and make sure you run "VACUUM ANALYZE" first). +> +> Joe +> +> +> ---------------------------(end of broadcast)--------------------------- +> TIP 2: you can get off all lists at once with the unregister command +> (send "unregister YourEmailAddressHere" to majordomo@postgresql.org) +> + + +From pgsql-performance-owner@postgresql.org Sun May 4 00:42:03 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 8AACD4763E7 + for ; + Sun, 4 May 2003 00:41:57 -0400 (EDT) +Received: from sss.pgh.pa.us (unknown [192.204.191.242]) + by postgresql.org (Postfix) with ESMTP id 9E17E4763D8 + for ; + Sun, 4 May 2003 00:41:56 -0400 (EDT) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h444g0U6025879; + Sun, 4 May 2003 00:42:00 -0400 (EDT) +To: josh@agliodbs.com +Cc: PgSQL Performance ML +Subject: Re: Suggestions wanted for 7.2.4 query +In-reply-to: <200305031928.52906.josh@agliodbs.com> +References: <200305031928.52906.josh@agliodbs.com> +Comments: In-reply-to Josh Berkus + message dated "Sat, 03 May 2003 19:28:52 -0700" +Date: Sun, 04 May 2003 00:42:00 -0400 +Message-ID: <25878.1052023320@sss.pgh.pa.us> +From: Tom Lane +X-Spam-Status: No, hits=-31.7 required=5.0 + tests=BAYES_00,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REFERENCES,REPLY_WITH_QUOTES,UPPERCASE_25_50 + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/38 +X-Sequence-Number: 1817 + +Josh Berkus writes: +> SELECT sv_events.*, FALSE AS fuzzy_team FROM sv_events WHERE EXISTS ( SELECT +> event_id FROM event_days +> WHERE event_days.event_id = sv_events.event_id AND (event_day BETWEEN +> ('2003-04-08'::TIMESTAMP WITHOUT TIME ZONE) +> AND ('2003-06-17 23:59'::TIMESTAMP WITHOUT TIME ZONE) ) ); + +Is event_days.event_id unique? If so, try + +SELECT sv_events.*, FALSE AS fuzzy_team FROM sv_events, event_days +WHERE +event_days.event_id = sv_events.event_id AND + (event_days.event_day BETWEEN +('2003-04-08'::TIMESTAMP WITHOUT TIME ZONE) + AND ('2003-06-17 23:59'::TIMESTAMP WITHOUT TIME ZONE) ); + +This at least gives you some glimmer of a chance that the restriction on +event_day can be used to avoid computing the entire join represented by +sv_events. With the exists() form, there's no chance... + + regards, tom lane + + +From pgsql-performance-owner@postgresql.org Sun May 4 12:07:53 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 7EA19476485 + for ; + Sun, 4 May 2003 12:07:52 -0400 (EDT) +Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) + by postgresql.org (Postfix) with ESMTP id ACD33476481 + for ; + Sun, 4 May 2003 12:07:47 -0400 (EDT) +Received: from [63.195.55.98] (HELO spooky) + by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) + with ESMTP id 3007182; Sun, 04 May 2003 09:07:47 -0700 +Content-Type: text/plain; + charset="iso-8859-1" +From: Josh Berkus +Organization: Aglio Database Solutions +To: Tom Lane +Subject: Re: Suggestions wanted for 7.2.4 query +Date: Sun, 4 May 2003 09:07:03 -0700 +User-Agent: KMail/1.4.3 +Cc: PgSQL Performance ML +References: <200305031928.52906.josh@agliodbs.com> + <25878.1052023320@sss.pgh.pa.us> +In-Reply-To: <25878.1052023320@sss.pgh.pa.us> +MIME-Version: 1.0 +Message-Id: <200305040907.03306.josh@agliodbs.com> +Content-Transfer-Encoding: quoted-printable +X-Spam-Status: No, hits=-33.0 required=5.0 + tests=BAYES_01,IN_REP_TO,QUOTED_EMAIL_TEXT,QUOTE_TWICE_1, + REFERENCES,REPLY_WITH_QUOTES,USER_AGENT_KMAIL + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/39 +X-Sequence-Number: 1818 + +Tom, + +> > SELECT sv_events.*, FALSE AS fuzzy_team FROM sv_events WHERE EXISTS ( +> > SELECT event_id FROM event_days +> > WHERE event_days.event_id =3D sv_events.event_id AND (event_day BETWE= +EN +> > ('2003-04-08'::TIMESTAMP WITHOUT TIME ZONE) +> > AND ('2003-06-17 23:59'::TIMESTAMP WITHOUT TIME ZONE) ) ); +> +> Is event_days.event_id unique? If so, try + +Regrettably, no. Event_days is an iterative list of all of the days cover= +ed=20 +by the event. What's unique is event_days_pk, which is event_id, event_da= +y.=20=20 +If I did a direct join to event_days, multi-day events would appear on the= +=20 +search results more than once .... which we *don't* want. + +> This at least gives you some glimmer of a chance that the restriction on +> event_day can be used to avoid computing the entire join represented by +> sv_events. With the exists() form, there's no chance... + +Hmmm. There are other ways I can get at the date limit for sv_events; I'll= +=20 +try that. Unfortunately, those ways require a seq scan on events, so I'm n= +ot=20 +sure we have a net gain here (that is, I can't imagine that a two-column= +=20 +date calculation between two parameters could be indexed) + + However, by my reading, 75% of the cost of the query is the unindexed join= +=20 +between "events" and "cases". Are you saying that the planner being vagu= +e=20 +about what will be returned from the EXISTS clause is what's triggering the= +=20 +seq scan on "cases"? + +--=20 +Josh Berkus +Aglio Database Solutions +San Francisco + + +From pgsql-performance-owner@postgresql.org Sun May 4 12:22:12 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id B17824763EF + for ; + Sun, 4 May 2003 12:22:10 -0400 (EDT) +Received: from flake.decibel.org (flake.decibel.org [66.143.173.58]) + by postgresql.org (Postfix) with SMTP id E35CD475F00 + for ; + Sun, 4 May 2003 12:22:09 -0400 (EDT) +Received: (qmail 55052 invoked by uid 1001); 4 May 2003 16:22:14 -0000 +Date: Sun, 4 May 2003 11:22:14 -0500 +From: "Jim C. Nasby" +To: Manfred Koizar +Cc: Tom Lane , pgsql-performance@postgresql.org +Subject: Re: More tablescanning fun +Message-ID: <20030504112214.V66185@flake.decibel.org> +Reply-To: jim@nasby.net +References: <20030424183817.A66185@flake.decibel.org> + <3660.1051228710@sss.pgh.pa.us> + <20030424235924.B66185@flake.decibel.org> + <13549.1051248190@sss.pgh.pa.us> + <20030425093800.C66185@flake.decibel.org> + +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +User-Agent: Mutt/1.2.5.1i +In-Reply-To: ; + from mkoi-pg@aon.at on Wed, Apr 30, 2003 at 04:14:46PM +0200 +X-Operating-System: FreeBSD 4.8-RELEASE i386 +X-Distributed: Join the Effort! http://www.distributed.net +X-Spam-Status: No, hits=-39.4 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REFERENCES,REPLY_WITH_QUOTES,SIGNATURE_SHORT_SPARSE, + USER_AGENT_MUTT autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/40 +X-Sequence-Number: 1819 + +On Wed, Apr 30, 2003 at 04:14:46PM +0200, Manfred Koizar wrote: +> On Fri, 25 Apr 2003 09:38:01 -0500, "Jim C. Nasby" +> wrote: +> >In this case, the interpolation can't be at fault, because correlation +> >is 1 (unless the interpolation is backwards, but that doesn't appear to +> >be the case). +> +> But your index has 3 columns which causes the index correlation to be +> assumed as 1/3. So the interpolation uses 1/9 (correlation squared) +> and you get a cost estimation that almost equals the upper bound. + +Hmm... interesting... maybe it would also be a good idea to expand +ANALYZE so that it will analyze actual index correlation? ie: in this +case, it would notice that the index on project_id, id, date is highly +correlated, across all 3 columns. + +Supporting something close to a real clustered index would also work as +well, since the optimizer would treat that case differently (essentially +as a combination between an index scan but doing a seq. scan within each +page). +-- +Jim C. Nasby (aka Decibel!) jim@nasby.net +Member: Triangle Fraternity, Sports Car Club of America +Give your computer some brain candy! www.distributed.net Team #1828 + +Windows: "Where do you want to go today?" +Linux: "Where do you want to go tomorrow?" +FreeBSD: "Are you guys coming, or what?" + + +From pgsql-performance-owner@postgresql.org Sun May 4 13:23:14 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 62759476331 + for ; + Sun, 4 May 2003 13:23:12 -0400 (EDT) +Received: from sss.pgh.pa.us (unknown [192.204.191.242]) + by postgresql.org (Postfix) with ESMTP id 6C655475F00 + for ; + Sun, 4 May 2003 13:23:11 -0400 (EDT) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h44HN9U6004613; + Sun, 4 May 2003 13:23:10 -0400 (EDT) +To: Josh Berkus +Cc: PgSQL Performance ML +Subject: Re: Suggestions wanted for 7.2.4 query +In-reply-to: <200305040907.03306.josh@agliodbs.com> +References: <200305031928.52906.josh@agliodbs.com> + <25878.1052023320@sss.pgh.pa.us> + <200305040907.03306.josh@agliodbs.com> +Comments: In-reply-to Josh Berkus + message dated "Sun, 04 May 2003 09:07:03 -0700" +Date: Sun, 04 May 2003 13:23:09 -0400 +Message-ID: <4612.1052068989@sss.pgh.pa.us> +From: Tom Lane +X-Spam-Status: No, hits=-32.3 required=5.0 + tests=BAYES_00,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REFERENCES,REPLY_WITH_QUOTES autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/41 +X-Sequence-Number: 1820 + +Josh Berkus writes: +>> This at least gives you some glimmer of a chance that the restriction on +>> event_day can be used to avoid computing the entire join represented by +>> sv_events. With the exists() form, there's no chance... + +> Hmmm. + +I have to take that back (must have been out too late last night ;-)). +The EXISTS subquery *is* getting pushed down to become a restriction on +events alone; that's what the "SubPlan" is. However, it'd still be +worth looking for another way to express it, because the planner is +pretty clueless about the selectivity of EXISTS restrictions. That's +what's causing it to drastically overestimate the number of rows taken +from "events" (14812 vs 1919), which in turn drives it away from using +the nestloop-with-inner-indexscan join style for joining to "cases". + +> Are you saying that the planner being vague about what will be +> returned from the EXISTS clause is what's triggering the seq scan on +> "cases"? + +Right. The nestloop/indexscan style only wins if there are not too many +outer rows. If the EXISTS constraint actually did succeed for 14812 +"events" rows, the planner would probably be making the right choice to +use a hash join. + +BTW, have you tried lowering the value of "random_page_cost"? Looking +at the relative costs in these examples makes me think most of your +tables are cached in memory. Of course, if that's not true during +day-to-day production then you need to be wary about reducing the setting. + + regards, tom lane + + +From pgsql-performance-owner@postgresql.org Sun May 4 14:00:35 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 865F5475F1B + for ; + Sun, 4 May 2003 14:00:33 -0400 (EDT) +Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) + by postgresql.org (Postfix) with ESMTP id 85DC7475F00 + for ; + Sun, 4 May 2003 14:00:29 -0400 (EDT) +Received: from [63.195.55.98] (HELO spooky) + by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) + with ESMTP id 3007280; Sun, 04 May 2003 11:00:28 -0700 +Content-Type: text/plain; + charset="iso-8859-1" +From: Josh Berkus +Organization: Aglio Database Solutions +To: Tom Lane +Subject: Re: Suggestions wanted for 7.2.4 query +Date: Sun, 4 May 2003 10:59:41 -0700 +User-Agent: KMail/1.4.3 +Cc: PgSQL Performance ML +References: <200305031928.52906.josh@agliodbs.com> + <200305040907.03306.josh@agliodbs.com> + <4612.1052068989@sss.pgh.pa.us> +In-Reply-To: <4612.1052068989@sss.pgh.pa.us> +MIME-Version: 1.0 +Message-Id: <200305041059.41468.josh@agliodbs.com> +Content-Transfer-Encoding: quoted-printable +X-Spam-Status: No, hits=-32.4 required=5.0 + tests=BAYES_01,IN_REP_TO,QUOTED_EMAIL_TEXT,REFERENCES, + REPLY_WITH_QUOTES,USER_AGENT_KMAIL autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/42 +X-Sequence-Number: 1821 + +Tom, + +> I have to take that back (must have been out too late last night ;-)). +> The EXISTS subquery *is* getting pushed down to become a restriction on +> events alone; that's what the "SubPlan" is. However, it'd still be +> worth looking for another way to express it, because the planner is +> pretty clueless about the selectivity of EXISTS restrictions. That's +> what's causing it to drastically overestimate the number of rows taken +> from "events" (14812 vs 1919), which in turn drives it away from using +> the nestloop-with-inner-indexscan join style for joining to "cases". + +That may be solvable without forcing a seq scan on "events", simply by=20 +overdetermining the criteria on date. That is, I can't apply the date=20 +criteria to "events" because that would require running date calucations on= +=20 +each row forcing a seq scan ( i.e. (event_date + duration) between date_one= +=20 +and date_two would require a seq scan), but I can apply a broadend version = +of=20 +the criteria to "events" ( i.e. event_date between (date_one - 1 month) and= +=20 +(date_two + 1 day)) which would give the planner the idea that it is=20 +returning a minority of rows from "events". + +Someday, we have to come up with a way of indexing simple multi-column=20 +calculations. Unless someone did that in current source while I was behin= +d=20 +on -hackers? + +> Right. The nestloop/indexscan style only wins if there are not too many +> outer rows. If the EXISTS constraint actually did succeed for 14812 +> "events" rows, the planner would probably be making the right choice to +> use a hash join. + +Hmm. Any hope of improving this in the future? Like the IN() functionali= +ty=20 +improvements in 7.4? + +> BTW, have you tried lowering the value of "random_page_cost"? Looking +> at the relative costs in these examples makes me think most of your +> tables are cached in memory. Of course, if that's not true during +> day-to-day production then you need to be wary about reducing the setting. + +No, we're probably cached ... the machine has 1gb of RAM. Also it has a= +=20 +really fast RAID array, at least for block disk reads, although random seek= +=20 +times suck. I can tweak a little. The problem is that it's a production= +=20 +machine in use 70 hours a week, so there isn't a lot of time we can test=20 +performance settings that might cause problems. + +Thanks for the advice! + +--=20 +Josh Berkus +Aglio Database Solutions +San Francisco + + +From pgsql-sql-owner@postgresql.org Mon May 5 08:16:38 2003 +X-Original-To: pgsql-sql@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id A21004763A2 + for ; Mon, 5 May 2003 08:16:36 -0400 (EDT) +Received: from gate-w.wettzell.ifag.de (gate-w.ifag.de [141.74.1.1]) + by postgresql.org (Postfix) with ESMTP id 4BEA2476384 + for ; Mon, 5 May 2003 08:16:35 -0400 (EDT) +Received: by gate-w.wettzell.ifag.de (8.11.6p2/8.11.6) id h45CGcx13798 + for pgsql-sql@postgresql.org; Mon, 5 May 2003 12:16:38 GMT +Received: (from localhost) by gate-w.wettzell.ifag.de (MSCAN) id + 2/gate-w.wettzell.ifag.de/smtp-gw/mscan; Mon May 5 12:16:38 2003 +Message-ID: <3EB6561B.6070709@wettzell.ifag.de> +Date: Mon, 05 May 2003 14:16:27 +0200 +From: Reiner Dassing +Organization: BKG-Wettzell +User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; de-DE; + rv:1.0.2) Gecko/20021120 Netscape/7.01 +X-Accept-Language: de, en, zh +MIME-Version: 1.0 +To: pgsql-sql@postgresql.org +Subject: Indices are not used by the optimizer +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit +X-Spam-Status: No, + hits=-12.9 required=5.0 tests=BAYES_01,USER_AGENT_MOZILLA_UA + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/49 +X-Sequence-Number: 13214 + +Hello all! + +On PostgreSQL V7.3.2 on TRU64 I have a table +and applied indices for that table. +But on a simple query the indices are not used by the optimizer. +(An sequential scan is used which takes a lot of time) +I have done +VACUUM and VACUUM analyze +but without any change to the optimizer. + +Can someone give me a hint what I should do to give the +optimizer a start? +-------------------------------------- + +Well, let's start by the query + +wetter=# explain select * from wetter where epoche > '2001-01-01'; + QUERY PLAN +------------------------------------------------------------------------- + Seq Scan on wetter (cost=0.00..614795.55 rows=19054156 width=16) + Filter: (epoche > '2001-01-01 00:00:00+00'::timestamp with time zone) +(2 rows) + +wetter=# + + +The table definition is as follows: + \d wetter + Table "public.wetter" + Column | Type | Modifiers +-----------+--------------------------+----------- + sensor_id | integer | not null + epoche | timestamp with time zone | not null + wert | real | not null +Indexes: wetter_pkey primary key btree (sensor_id, epoche), + wetter_epoche_idx btree (epoche), + wetter_sensor_id_idx btree (sensor_id) +Triggers: RI_ConstraintTrigger_45702811, + t_ins_wetter_wetterakt + +wetter=# + + +The trigger information is as follows: +select * from pg_trigger where tgname='RI_ConstraintTrigger_45702811'; + tgrelid | tgname | tgfoid | tgtype | tgenabled +| tgisconstraint | tgconstrname | tgconstrrelid | tgdeferrable | +tginitdeferred | tgnargs | tgattr | + tgargs +----------+-------------------------------+--------+--------+-----------+----------------+--------------+---------------+--------------+----------------+---------+--------+--------------------------------------------------------------------------------------- + 43169106 | RI_ConstraintTrigger_45702811 | 1644 | 21 | t + | t | | 43169098 | f | f + | 6 | | +\000wetter\000sensoren_an_orten\000UNSPECIFIED\000sensor_id\000sensor_id\000 +(1 row) + +wetter=# + + +and t_ins_wetter_wetterakt +is a PLPGSQL Funktion which copies some information into another table +when an insert or update is done. + + +-- + +Mit freundlichen Gruessen / With best regards + Reiner Dassing + + +From pgsql-performance-owner@postgresql.org Mon May 5 03:27:24 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id A78E9475C3D + for ; + Mon, 5 May 2003 03:27:16 -0400 (EDT) +Received: from matrix.gatewaynet.com (unknown [217.19.69.50]) + by postgresql.org (Postfix) with ESMTP id 64BE24758F1 + for ; + Mon, 5 May 2003 03:27:14 -0400 (EDT) +Received: from matrix.gatewaynet.com (localhost [127.0.0.1]) + by matrix.gatewaynet.com (8.12.5/8.12.5) with ESMTP id h45CUq1s016163 + for ; Mon, 5 May 2003 10:30:52 -0200 +Received: from localhost (achill@localhost) + by matrix.gatewaynet.com (8.12.5/8.12.5/Submit) with ESMTP id + h45CUqgk016159 + for ; Mon, 5 May 2003 10:30:52 -0200 +Date: Mon, 5 May 2003 10:30:52 -0200 (GMT+2) +From: Achilleus Mantzios +To: pgsql-performance@postgresql.org +Subject: Wrong index usage in 7.3.2 +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-Spam-Status: No, hits=-18.4 required=5.0 + tests=BAYES_00,SIGNATURE_LONG_DENSE,USER_AGENT_PINE + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/43 +X-Sequence-Number: 1822 + +Hi, + +this is in continuation from the previous +http://archives.postgresql.org/pgsql-performance/2003-05/msg00003.php +thread. + +Summary: + +On a table i have this situation: on the queries i do, the best plan is +used only if NO statistics +are produced (via ANALYZE). +Once i run [VACUUM] [FULL] ANALYZE; the correct index is used only +in certain circumstances, and the planner fails to use it +in the most common ones. + +Since Message +http://archives.postgresql.org/pgsql-performance/2003-05/msg00003.php +had no responces, i thought that the best way to solve the problem +is to provide the pg_dump for anyone willing to examine the case. +bzip2'ed it is about 355K. + +Thanx. + +-- +================================================================== +Achilleus Mantzios +S/W Engineer +IT dept +Dynacom Tankers Mngmt +Nikis 4, Glyfada +Athens 16610 +Greece +tel: +30-210-8981112 +fax: +30-210-8981877 +email: achill@matrix.gatewaynet.com + mantzios@softlab.ece.ntua.gr + + +From pgsql-sql-owner@postgresql.org Mon May 5 09:32:50 2003 +X-Original-To: pgsql-sql@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id F1747476369 + for ; Mon, 5 May 2003 09:32:48 -0400 (EDT) +Received: from nat.inquent.com (unknown [216.208.117.7]) + by postgresql.org (Postfix) with ESMTP id 2F159474E42 + for ; Mon, 5 May 2003 09:32:48 -0400 (EDT) +Received: from [127.0.0.1] (localhost [127.0.0.1]) + by nat.inquent.com (8.12.8p1/8.12.8) with ESMTP id h45DX5QU010855; + Mon, 5 May 2003 09:33:05 -0400 (EDT) (envelope-from rbt@rbt.ca) +Subject: Re: Indices are not used by the optimizer +From: Rod Taylor +To: Reiner Dassing +Cc: pgsql-sql@postgresql.org +In-Reply-To: <3EB6561B.6070709@wettzell.ifag.de> +References: <3EB6561B.6070709@wettzell.ifag.de> +Content-Type: multipart/signed; micalg=pgp-sha1; + protocol="application/pgp-signature"; + boundary="=-Jb3895mWG4PANf3E19dW" +Organization: +Message-Id: <1052141584.9846.24.camel@jester> +Mime-Version: 1.0 +X-Mailer: Ximian Evolution 1.2.4 +Date: 05 May 2003 09:33:05 -0400 +X-Spam-Status: No, hits=-37.8 required=5.0 + tests=BAYES_10,IN_REP_TO,PGP_SIGNATURE_2,QUOTED_EMAIL_TEXT, + REFERENCES,REPLY_WITH_QUOTES,USER_AGENT_XIMIAN + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/52 +X-Sequence-Number: 13217 + +--=-Jb3895mWG4PANf3E19dW +Content-Type: text/plain +Content-Transfer-Encoding: quoted-printable + +Are you really expecting 19 million rows to be returned -- are you +really going to use them all? + +How about explain analyze output? + +Have you tried using a cursor to allow for parallel processing? (pull +1000 rows, do work, pull next 1000 rows, do work, etc.) + +> wetter=3D# explain select * from wetter where epoche > '2001-01-01'; +> QUERY PLAN +> ------------------------------------------------------------------------- +> Seq Scan on wetter (cost=3D0.00..614795.55 rows=3D19054156 width=3D16) +> Filter: (epoche > '2001-01-01 00:00:00+00'::timestamp with time zone) +> (2 rows) + +--=20 +Rod Taylor + +PGP Key: http://www.rbt.ca/rbtpub.asc + +--=-Jb3895mWG4PANf3E19dW +Content-Type: application/pgp-signature; name=signature.asc +Content-Description: This is a digitally signed message part + +-----BEGIN PGP SIGNATURE----- +Version: GnuPG v1.2.1 (FreeBSD) + +iD8DBQA+tmgQ6DETLow6vwwRAmv9AJ96xd3+IpxPan6Ks6+BQ+CYTCmQ8gCdHNWf +WJ0X8iz7f5NzoHDGyD704ok= +=46+3 +-----END PGP SIGNATURE----- + +--=-Jb3895mWG4PANf3E19dW-- + + +From pgsql-performance-owner@postgresql.org Mon May 5 12:36:36 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 2755E476414 + for ; + Mon, 5 May 2003 12:36:34 -0400 (EDT) +Received: from mail1.ihs.com (mail1.ihs.com [170.207.70.222]) + by postgresql.org (Postfix) with ESMTP id 8CE31476384 + for ; + Mon, 5 May 2003 12:36:28 -0400 (EDT) +Received: from css120.ihs.com (css120.ihs.com [170.207.105.120]) + by mail1.ihs.com (8.12.9/8.12.9) with ESMTP id h45GZDuu012020; + Mon, 5 May 2003 10:35:13 -0600 (MDT) +Date: Mon, 5 May 2003 10:25:57 -0600 (MDT) +From: "scott.marlowe" +To: Antoine +Cc: +Subject: Re: looking for large dataset +In-Reply-To: <1051941161.4247.12.camel@logic> +Message-ID: +MIME-Version: 1.0 +Content-Type: MULTIPART/MIXED; + BOUNDARY="-810911639-1994225175-1052151957=:2776" +X-MailScanner: Found to be clean +X-MailScanner-SpamCheck: +X-Spam-Status: No, hits=-18.7 required=5.0 + tests=BAYES_01,IN_REP_TO,QUOTED_EMAIL_TEXT,USER_AGENT_PINE + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/45 +X-Sequence-Number: 1824 + + This message is in MIME format. The first part should be readable text, + while the remaining parts are likely unreadable without MIME-aware tools. + Send mail to mime@docserver.cac.washington.edu for more info. + +---810911639-1994225175-1052151957=:2776 +Content-Type: TEXT/PLAIN; charset=US-ASCII + +On 3 May 2003, Antoine wrote: + +> I was woundering where could I find a nice large dataset. Perhaps 50 +> thousand records or more + +I've attached a PHP script called mktestdb that reads in the dictionary at +/usr/share/dict/words, and inserts a user defined number of rows into a +user defined number of columns. + +It's ugly and simple. Just pipe the output to a text file or psql and off +you go. + +usage: + +mktestdb tablename [rows [cols]] + +default of 1 column and 1000 rows. + +It would be easy enough to rewrite this in something more portable if +someone wanted to. + +---810911639-1994225175-1052151957=:2776 +Content-Type: TEXT/PLAIN; charset=US-ASCII; name=mktestdb +Content-Transfer-Encoding: BASE64 +Content-ID: +Content-Description: +Content-Disposition: attachment; filename=mktestdb + +IyEvdXNyL2xvY2FsL2Jpbi9waHAgLXENCjw/cGhwDQpzZXRfdGltZV9saW1p +dCgxMjAwKTsNCmlmICgkYXJnYzwyfHwkYXJnYz40KSBkaWUoIlVzYWdlOlxu +XG4gbWt0ZXN0ZGIgdGFibGVuYW1lIFtyb3dzIFtjb2xzXV1cblxuIik7DQok +dGFibGVuYW1lID0gJGFyZ3ZbMV07DQppZiAoJGFyZ2M+PTMpICRyb3dzID0g +JGFyZ3ZbMl07DQplbHNlICRyb3dzID0gMTAwMDsNCmlmICgkYXJnYz09NCkg +JGNvbHMgPSAkYXJndlszXTsNCmVsc2UgJGNvbHMgPSAxOw0KDQpmdW5jdGlv +biBtYWtlX3NlZWQoKSB7DQogICAgbGlzdCgkdXNlYywgJHNlYykgPSBleHBs +b2RlKCcgJywgbWljcm90aW1lKCkpOw0KICAgIHJldHVybiAoZmxvYXQpICRz +ZWMgKyAoKGZsb2F0KSAkdXNlYyAqIDEwMDAwMCk7DQp9DQpzcmFuZChtYWtl +X3NlZWQoKSk7DQoNCiRmaWxlbmFtZSA9ICIvdXNyL3NoYXJlL2RpY3Qvd29y +ZHMiOw0KJGZwID0gZm9wZW4oJGZpbGVuYW1lLCJyIik7DQokYm9keSA9IGZy +ZWFkKCRmcCxmaWxlc2l6ZSgkZmlsZW5hbWUpKTsNCiRsaW5lcyA9IGV4cGxv +ZGUoIlxuIiwkYm9keSk7DQokY291bnQgPSBjb3VudCgkbGluZXMpOw0KJHF1 +ZXJ5ID0gImNyZWF0ZSB0YWJsZSAkdGFibGVuYW1lIChcbiI7DQpmb3IgKCRp +PTA7JGk8JGNvbHM7JGkrKyl7DQoJJHF1ZXJ5Lj0iXHRjb2xfIi4kaTsNCgkk +cXVlcnkuPSIgdGV4dCI7DQoJaWYgKCRpPCRjb2xzLTEpICRxdWVyeS49Iiwg +XG4iOw0KCWVsc2UgJHF1ZXJ5Lj0iXG4iOw0KfQ0KJHF1ZXJ5Lj0iKTsiOw0K +DQpwcmludCAkcXVlcnkuIlxuXG4iOw0KDQpwcmludCAiLS0gRGF0YSBmb3Ig +JHRhYmxlbmFtZVxuXG4iOw0KDQpwcmludCAiQ09QWSAkdGFibGVuYW1lICgi +Ow0KZm9yICgkaT0wOyRpPCRjb2xzOyRpKyspew0KCXByaW50ICJjb2xfIi4k +aTsNCglpZiAoJGk8JGNvbHMtMSkgcHJpbnQgIiwiOw0KfQ0KcHJpbnQgIikg +RlJPTSBTVERJTjtcbiI7DQoNCg0KDQpmb3IgKCRpPTA7JGk8JHJvd3M7JGkr +Kyl7DQoJZm9yICgkaj0wOyRqPCRjb2xzOyRqKyspew0KCQkkaz1yYW5kKDAs +JGNvdW50LTEpOw0KCQlwcmludCAkbGluZXNbJGtdOw0KCQlpZiAoJGo8JGNv +bHMtMSkgcHJpbnQgIlx0IjsNCgl9DQoJcHJpbnQgIlxuIjsNCn0NCnByaW50 +ICdcLic7DQpwcmludCAiXG4iOw0KPz4NCg== + +---810911639-1994225175-1052151957=:2776-- + + +From pgsql-performance-owner@postgresql.org Mon May 5 12:42:22 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 83E90476372 + for ; + Mon, 5 May 2003 12:42:20 -0400 (EDT) +Received: from mail1.ihs.com (mail1.ihs.com [170.207.70.222]) + by postgresql.org (Postfix) with ESMTP id 4A1F2476371 + for ; + Mon, 5 May 2003 12:42:19 -0400 (EDT) +Received: from css120.ihs.com (css120.ihs.com [170.207.105.120]) + by mail1.ihs.com (8.12.9/8.12.9) with ESMTP id h45Gf9uu012610; + Mon, 5 May 2003 10:41:09 -0600 (MDT) +Date: Mon, 5 May 2003 10:31:53 -0600 (MDT) +From: "scott.marlowe" +To: Ron Johnson +Cc: PgSQL Performance ML +Subject: Re: Looking for a cheap upgrade (RAID) +In-Reply-To: <1051994374.1086.13.camel@haggis> +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-MailScanner: Found to be clean +X-MailScanner-SpamCheck: +X-Spam-Status: No, hits=-31.7 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REPLY_WITH_QUOTES,USER_AGENT_PINE autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/46 +X-Sequence-Number: 1825 + +On 3 May 2003, Ron Johnson wrote: + +> On Fri, 2003-05-02 at 13:53, Chad Thompson wrote: +> > I have a server on a standard pc right now. +> > PIII 700, 1Gig ram (SD), 40 Gig IDE, RedHat 8.0, PostgreSQL 7.3.1 +> > +> > The database has 3 tables that just broke 10 million tuples (yeah, i think +> > im entering in to the world of real databases ;-) +> > Its primarly bulk (copy) inserts and queries, rarely an update. +> > +> > I am looking at moving this to a P4 2.4G, 2 Gig Ram(DDR), RedHat 8, +> > PostgreSQL 7.3.latest +> [snip] +> +> How big do you expect the database to get? +> +> If I may be a contrarian, if under 70GB, then why not just get a 72GB +> 10K RPM SCSI drive ($160) and a SCSI 160 card? OS, swap, input files, +> etc, can go on a 7200RPM IDE drive. +> +> Much fewer moving parts than RAID, so more reliable... + +Sorry, everything else is true, but RAID is far more reliable, even if +disk failure is more likely. Since a RAID array (1 or 5) can run with one +dead disk, and supports auto-rebuild from hot spares, there's really no +way a single disk can be more reliable. It may have fewer failures, but +that's not the same thing. + + +From pgsql-performance-owner@postgresql.org Mon May 5 12:48:26 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 73D29476315 + for ; + Mon, 5 May 2003 12:48:24 -0400 (EDT) +Received: from mail1.ihs.com (mail1.ihs.com [170.207.70.222]) + by postgresql.org (Postfix) with ESMTP id 542BA476085 + for ; + Mon, 5 May 2003 12:48:23 -0400 (EDT) +Received: from css120.ihs.com (css120.ihs.com [170.207.105.120]) + by mail1.ihs.com (8.12.9/8.12.9) with ESMTP id h45GlKuu013092; + Mon, 5 May 2003 10:47:20 -0600 (MDT) +Date: Mon, 5 May 2003 10:38:03 -0600 (MDT) +From: "scott.marlowe" +To: Shridhar Daithankar +Cc: pgsql-performance +Subject: Re: Looking for a cheap upgrade (RAID) +In-Reply-To: <200305031332.49756.shridhar_daithankar@nospam.persistent.co.in> +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-MailScanner: Found to be clean +X-MailScanner-SpamCheck: +X-Spam-Status: No, hits=-30.9 required=5.0 + tests=BAYES_10,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REPLY_WITH_QUOTES,USER_AGENT_PINE autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/47 +X-Sequence-Number: 1826 + +On Sat, 3 May 2003, Shridhar Daithankar wrote: + +> On Saturday 03 May 2003 02:50, scott.marlowe wrote: +> > Seeing as you'll have 2 gigs of RAM, your swap partition is likely to grow +> > cob webs, so where you put it probably isn't that critical. +> > +> > What I usually do is say take 4 120 Gig drives, allocate 1 gig on each for +> > swap, so you have 4 gigs swap (your swap should be larger than available +> > memory in Linux for performance reasons) and the rest of the drives split +> > so that say, the first 5 or so gigs of each is used to house most of the +> > OS, and the rest for another RAID array hosting the database. Since the +> > root partition can't be on RAID5, you'd have to set up either a single +> > drive or a mirror set to handle that. +> +> Setting swap in linux is a tricky proposition. If there is no swap at all, +> linux has behaved crazily in past. These days situation is much better. +> +> In my experience with single IDE disk, if swap usage goes above 20-30MB due to +> shortage of memory, machine is dead in waters. Linux sometimes does memory +> inversion where swap used is half the free memory but swap is not freed but +> that does not hurt really.. +> +> So my advice is, setting swap more tahn 128MB is waste of disk space. OK 256 +> in ultra-extreme situations.. but more than that would a be unadvisable +> situation.. + +Whereas disks are ALL over 20 gigs now, and +whereas the linux kernel will begin killing processes when it runs out of +mem and swap, and +whereas the linux kernel STILL has issues using swap when it's smaller +than memory (those problems have been lessened, but not eliminated), and +whereas the linux kernel will parallelize access to its swap partitions +when it has more than one and they are at the same priority, providing +better swap performance, and +whereas REAL servers always use more memory than you'd ever thought they +would, + +be it declared here and now by me that using a small swap file is +penny-wise and pound foolish. + +:-) + +Seriously, though, having once had a REAL bad experience on a production +server that I was trying to increase swap on (yes, some idiot set it up +with some tiny little 64 Meg swap file (yes, that idiot was me...)) I now +just give every server a few gigs of swap from its three or four 40+ gig +drives. With 4 drives, and each one donating 256 Meg to the cause you can +have a gig of swap space. + + +From pgsql-performance-owner@postgresql.org Mon May 5 13:59:45 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 003BB476085 + for ; + Mon, 5 May 2003 13:59:44 -0400 (EDT) +Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) + by postgresql.org (Postfix) with ESMTP id 04798475EEE + for ; + Mon, 5 May 2003 13:59:43 -0400 (EDT) +Received: from [66.219.92.2] (HELO temoku) + by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) + with ESMTP id 3009656; Mon, 05 May 2003 10:59:41 -0700 +Content-Type: text/plain; + charset="iso-8859-1" +From: Josh Berkus +Reply-To: josh@agliodbs.com +Organization: Aglio Database Solutions +To: Tom Lane +Subject: Re: Suggestions wanted for 7.2.4 query +Date: Mon, 5 May 2003 10:59:11 -0700 +User-Agent: KMail/1.4.3 +Cc: PgSQL Performance ML +References: <200305031928.52906.josh@agliodbs.com> + <4612.1052068989@sss.pgh.pa.us> + <200305041059.41468.josh@agliodbs.com> +In-Reply-To: <200305041059.41468.josh@agliodbs.com> +MIME-Version: 1.0 +Content-Transfer-Encoding: quoted-printable +Message-Id: <200305051059.11751.josh@agliodbs.com> +X-Spam-Status: No, hits=-32.4 required=5.0 + tests=BAYES_01,IN_REP_TO,QUOTED_EMAIL_TEXT,REFERENCES, + REPLY_WITH_QUOTES,USER_AGENT_KMAIL autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/48 +X-Sequence-Number: 1827 + +Folks, + +> That may be solvable without forcing a seq scan on "events", simply by=20 +> overdetermining the criteria on date. That is, I can't apply the date=20 +> criteria to "events" because that would require running date calucations = +on=20 +> each row forcing a seq scan ( i.e. (event_date + duration) between date_o= +ne=20 +> and date_two would require a seq scan), but I can apply a broadend versio= +n=20 +of=20 +> the criteria to "events" ( i.e. event_date between (date_one - 1 month) a= +nd=20 +> (date_two + 1 day)) which would give the planner the idea that it is=20 +> returning a minority of rows from "events". + +If anyone is interested, the above idea worked. + + +--=20 +-Josh Berkus + Aglio Database Solutions + San Francisco + + +From pgsql-performance-owner@postgresql.org Mon May 5 09:35:02 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP + id 3580047630C; Mon, 5 May 2003 09:35:00 -0400 (EDT) +Received: from matrix.gatewaynet.com (unknown [217.19.69.50]) + by postgresql.org (Postfix) with ESMTP + id 24402474E42; Mon, 5 May 2003 09:34:57 -0400 (EDT) +Received: from matrix.gatewaynet.com (localhost [127.0.0.1]) + by matrix.gatewaynet.com (8.12.5/8.12.5) with ESMTP id h45Ich1s017596; + Mon, 5 May 2003 16:38:43 -0200 +Received: from localhost (achill@localhost) + by matrix.gatewaynet.com (8.12.5/8.12.5/Submit) with ESMTP id + h45IchOq017592; Mon, 5 May 2003 16:38:43 -0200 +Date: Mon, 5 May 2003 16:38:43 -0200 (GMT+2) +From: Achilleus Mantzios +To: Reiner Dassing +Cc: pgsql-sql@postgresql.org, +Subject: Re: [SQL] Indices are not used by the optimizer +In-Reply-To: <3EB6561B.6070709@wettzell.ifag.de> +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-Spam-Status: No, hits=-24.8 required=5.0 + tests=BAYES_00,IN_REP_TO,QUOTED_EMAIL_TEXT,SIGNATURE_LONG_DENSE, + USER_AGENT_PINE autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/44 +X-Sequence-Number: 1823 + + +Hi Reiner, + +normally these kind of subjects must go +to pgsql-performance@postgresql.org + +What's important is in pg_class and pg_statistic tables. +Especially, you may check out histgraph bounds +in pg_stats for attribute epoche. + +For a test, did you do a +# set enable_seqscan to OFF +?? +On Mon, 5 May 2003, Reiner Dassing wrote: + +> Hello all! +> +> On PostgreSQL V7.3.2 on TRU64 I have a table +> and applied indices for that table. +> But on a simple query the indices are not used by the optimizer. +> (An sequential scan is used which takes a lot of time) +> I have done +> VACUUM and VACUUM analyze +> but without any change to the optimizer. +> +> Can someone give me a hint what I should do to give the +> optimizer a start? +> -------------------------------------- +> +> Well, let's start by the query +> +> wetter=# explain select * from wetter where epoche > '2001-01-01'; +> QUERY PLAN +> ------------------------------------------------------------------------- +> Seq Scan on wetter (cost=0.00..614795.55 rows=19054156 width=16) +> Filter: (epoche > '2001-01-01 00:00:00+00'::timestamp with time zone) +> (2 rows) +> +> wetter=# +> +> +> The table definition is as follows: +> \d wetter +> Table "public.wetter" +> Column | Type | Modifiers +> -----------+--------------------------+----------- +> sensor_id | integer | not null +> epoche | timestamp with time zone | not null +> wert | real | not null +> Indexes: wetter_pkey primary key btree (sensor_id, epoche), +> wetter_epoche_idx btree (epoche), +> wetter_sensor_id_idx btree (sensor_id) +> Triggers: RI_ConstraintTrigger_45702811, +> t_ins_wetter_wetterakt +> +> wetter=# +> +> +> The trigger information is as follows: +> select * from pg_trigger where tgname='RI_ConstraintTrigger_45702811'; +> tgrelid | tgname | tgfoid | tgtype | tgenabled +> | tgisconstraint | tgconstrname | tgconstrrelid | tgdeferrable | +> tginitdeferred | tgnargs | tgattr | +> tgargs +> ----------+-------------------------------+--------+--------+-----------+----------------+--------------+---------------+--------------+----------------+---------+--------+--------------------------------------------------------------------------------------- +> 43169106 | RI_ConstraintTrigger_45702811 | 1644 | 21 | t +> | t | | 43169098 | f | f +> | 6 | | +> \000wetter\000sensoren_an_orten\000UNSPECIFIED\000sensor_id\000sensor_id\000 +> (1 row) +> +> wetter=# +> +> +> and t_ins_wetter_wetterakt +> is a PLPGSQL Funktion which copies some information into another table +> when an insert or update is done. +> +> +> + +-- +================================================================== +Achilleus Mantzios +S/W Engineer +IT dept +Dynacom Tankers Mngmt +Nikis 4, Glyfada +Athens 16610 +Greece +tel: +30-210-8981112 +fax: +30-210-8981877 +email: achill@matrix.gatewaynet.com + mantzios@softlab.ece.ntua.gr + + +From pgsql-hackers-owner@postgresql.org Mon May 5 15:20:52 2003 +X-Original-To: pgsql-hackers@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP + id 6CA14475E82; Mon, 5 May 2003 15:20:50 -0400 (EDT) +Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) + by postgresql.org (Postfix) with ESMTP + id C50F1476397; Mon, 5 May 2003 15:20:39 -0400 (EDT) +Received: from [66.219.92.2] (HELO temoku) + by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) + with ESMTP id 3009880; Mon, 05 May 2003 12:20:28 -0700 +Content-Type: text/plain; + charset="us-ascii" +From: Josh Berkus +Reply-To: josh@agliodbs.com +Organization: Aglio Database Solutions +To: pgsql-performance , + pgsql-hackers@postgresql.org +Subject: Hypothetical suggestions for planner, indexing improvement +Date: Mon, 5 May 2003 12:19:58 -0700 +User-Agent: KMail/1.4.3 +MIME-Version: 1.0 +Content-Transfer-Encoding: quoted-printable +Message-Id: <200305051219.58955.josh@agliodbs.com> +X-Spam-Status: No, hits=-13.0 required=5.0 tests=BAYES_01,USER_AGENT_KMAIL + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/72 +X-Sequence-Number: 38579 + +Folks, + +An area in which postgresql planner & indexing could be improved have occur= +red=20 +to me over the last week. I'd like to share this ideas with you in case = +it=20 +is worthy of the todo list. + +Please excuse me if this issue is already dealt with in CVS; I've been unab= +le=20 +to keep up completely on HACKERS lately. Please also excuse me if this=20 +issue has been discussed and was tabled due to some theoretical limitation,= +=20 +such as x^n scaling problems + +THE IDEA: The planner should keep statistics on the correlation of foreign= +=20 +keys and apply them to the expected row counts for EXISTS clause limitation= +s,=20 +and possibly for other query types as well. + +To illustrate: +Database "calendar" has two tables, events and event_days. +Event_days has FK on column event_id to parent table Events. +There is at lease one record in event_days for each record in events, and t= +he=20 +average parent-child relationship is 1 event -> 1.15 event_days records. + +This query: +SELECT events.* FROM events +WHERE EXISTS (SELECT event_id FROM event_days=20 + WHERE event_day BETWEEN '2003-04-08' AND '2003-05-18'); + +Currently, (in 7.2.4 and 7.3.1) the planner makes the assumption that the= +=20 +above EXISTS restriction will only filter events by 50% and makes other joi= +n=20 +and execution plans accordingly. In fact, it filters events by 96% and th= +e=20 +ideal execution plan should be quite different. + +It would be really keen if planner statistics could be expanded to include= +=20 +correlation on foriegn keys in order to make more intelligent planner=20 +decisions on the above type of query possible. + +Thanks for your attention! + + +--=20 +-Josh Berkus + Aglio Database Solutions + San Francisco + + +From pgsql-performance-owner@postgresql.org Mon May 5 15:27:59 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 68134475EEE + for ; + Mon, 5 May 2003 15:27:56 -0400 (EDT) +Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) + by postgresql.org (Postfix) with ESMTP id 4F321475E82 + for ; + Mon, 5 May 2003 15:27:55 -0400 (EDT) +Received: from [66.219.92.2] (HELO temoku) + by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) + with ESMTP id 3009888; Mon, 05 May 2003 12:27:55 -0700 +Content-Type: text/plain; + charset="iso-8859-1" +From: Josh Berkus +Reply-To: josh@agliodbs.com +Organization: Aglio Database Solutions +To: Andrew Sullivan +Subject: Re: Suggestions wanted for 7.2.4 query +Date: Mon, 5 May 2003 12:27:25 -0700 +User-Agent: KMail/1.4.3 +References: <200305031928.52906.josh@agliodbs.com> + <200305051059.11751.josh@agliodbs.com> + <20030505190201.GP20217@libertyrms.info> +In-Reply-To: <20030505190201.GP20217@libertyrms.info> +Cc: pgsql-performance +MIME-Version: 1.0 +Content-Transfer-Encoding: quoted-printable +Message-Id: <200305051227.25498.josh@agliodbs.com> +X-Spam-Status: No, hits=-23.3 required=5.0 + tests=BAYES_01,IN_REP_TO,QUOTE_TWICE_1,REFERENCES, + USER_AGENT_KMAIL autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/50 +X-Sequence-Number: 1829 + +Andrew, + +> > If anyone is interested, the above idea worked. +>=20 +> I am. Thanks, that was a clever idea. + +Thanks! In that case, I'll give you the full implementation: + +1) Build an index on the product of time and duration for the table "events= +": +jwnet_test=3D> create function add_time ( timestamp without time zone, inte= +rval=20 +) +cal_test-> returns timestamp without time zone as ' +cal_test'> select $1 + $2; +cal_test'> ' language 'sql' with (isstrict, iscachable); +cal_test=3D> create index idx_event_ends on events(add_time(event_date,=20 +duration)); +CREATE + +2) add this as a column to the view: +create view sv_events as +select events.event_id, events.status, status_label, status.rollup as rstat= +us,=20 +events.etype_id, type_name, + event_cats.ecat_id, cat_name, events.event_date, events.event_name, + jw_date_format(events.event_date, events.event_tz, events.duration)= + as=20 +show_date, + cases.case_name || '(' || cases.docket || ')' as event_case, + events.case_id, cases.case_name, cases.docket, NULL::VARCHAR as=20 +tgroup_name, + events.location_id, location_name, locations.zip_code,=20 +locations.address,=20 +locations.state_code, locations.city, + lu.user_name as lock_name, lu.email as lock_email, lu.user_id AS=20 +lock_user, add_time(events.event_date, events.duration) as end_date +FROM status, locations, event_types, event_cats, cases, + events LEFT OUTER JOIN lock_users lu ON events.event_id =3D lock_re= +cord +WHERE events.status <> 0 + AND (events.status =3D status.status AND status.relation =3D 'event= +s') + AND events.location_id =3D locations.location_id + AND event_types.etype_id =3D events.etype_id + AND event_cats.ecat_id =3D event_types.ecat_id + AND events.case_id =3D cases.case_id; + + +3) change the query as follows: +SELECT sv_events.*, FALSE AS fuzzy_team FROM sv_events WHERE +(sv_events.event_date BETWEEN ('2003-04-07'::TIMESTAMP WITHOUT TIME ZONE) = +AND=20 +('2003-05-19'::TIMESTAMP WITHOUT TIME ZONE) + or sv_events.end_date BETWEEN ('2003-04-07'::TIMESTAMP WITHOUT TIME ZONE)= +=20=20 +AND ('2003-05-19'::TIMESTAMP WITHOUT TIME ZONE) ) + AND EXISTS ( SELECT event_id FROM event_days WHERE event_days.event_id = +=3D=20 +sv_events.event_id + AND (event_day BETWEEN ('2003-04-08'::TIMESTAMP WITHOUT TIME ZONE) + AND ('2003-06-17 23:59'::TIMESTAMP WITHOUT TIME ZONE) ) ) + AND ( UPPER(case_name) LIKE 'RODRIGUEZ%' OR docket LIKE 'RODRIGUEZ%' OR + UPPER(tgroup_name) LIKE 'RODRIGUEZ%' OR EXISTS (SELECT tgroup_id FROM= +=20 +trial_groups + JOIN cases USING(tgroup_id) WHERE trial_groups.status > 0 AND=20 +((UPPER(case_name) + LIKE 'RODRIGUEZ%' OR docket LIKE 'RODRIGUEZ%') AND tgroup_id =3D=20 +sv_events.case_id) + OR (UPPER(tgroup_name) LIKE 'RODRIGUEZ%' AND cases.case_id =3D=20 +sv_events.case_id) ) ) AND rstatus <> 0; + +The new version returns in 0.85 seconds, a 75% improvement! Yahoo! + +--=20 +-Josh Berkus + Aglio Database Solutions + San Francisco + + +From pgsql-performance-owner@postgresql.org Mon May 5 17:55:27 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 7F031475B8E + for ; + Mon, 5 May 2003 17:55:25 -0400 (EDT) +Received: from lakemtao03.cox.net (lakemtao03.cox.net [68.1.17.242]) + by postgresql.org (Postfix) with ESMTP id 2E85B475AE4 + for ; + Mon, 5 May 2003 17:54:54 -0400 (EDT) +Received: from [192.168.1.1] ([68.11.66.83]) by lakemtao03.cox.net + (InterMail vM.5.01.04.05 201-253-122-122-105-20011231) with ESMTP + id <20030505215457.GLFV23518.lakemtao03.cox.net@[192.168.1.1]> + for ; + Mon, 5 May 2003 17:54:57 -0400 +Subject: Re: Looking for a cheap upgrade (RAID) +From: Ron Johnson +To: PgSQL Performance ML +In-Reply-To: +References: +Content-Type: text/plain +Organization: +Message-Id: <1052171694.3371.5.camel@haggis> +Mime-Version: 1.0 +X-Mailer: Ximian Evolution 1.2.4 +Date: 05 May 2003 16:54:54 -0500 +Content-Transfer-Encoding: 7bit +X-Spam-Status: No, hits=-45.1 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REFERENCES,REPLY_WITH_QUOTES,SIGNATURE_LONG_DENSE, + USER_AGENT_XIMIAN autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/51 +X-Sequence-Number: 1830 + +On Mon, 2003-05-05 at 11:31, scott.marlowe wrote: +> On 3 May 2003, Ron Johnson wrote: +> +> > On Fri, 2003-05-02 at 13:53, Chad Thompson wrote: +> > > I have a server on a standard pc right now. +> > > PIII 700, 1Gig ram (SD), 40 Gig IDE, RedHat 8.0, PostgreSQL 7.3.1 +> > > +> > > The database has 3 tables that just broke 10 million tuples (yeah, i think +> > > im entering in to the world of real databases ;-) +> > > Its primarly bulk (copy) inserts and queries, rarely an update. +> > > +> > > I am looking at moving this to a P4 2.4G, 2 Gig Ram(DDR), RedHat 8, +> > > PostgreSQL 7.3.latest +> > [snip] +> > +> > How big do you expect the database to get? +> > +> > If I may be a contrarian, if under 70GB, then why not just get a 72GB +> > 10K RPM SCSI drive ($160) and a SCSI 160 card? OS, swap, input files, +> > etc, can go on a 7200RPM IDE drive. +> > +> > Much fewer moving parts than RAID, so more reliable... +> +> Sorry, everything else is true, but RAID is far more reliable, even if +> disk failure is more likely. Since a RAID array (1 or 5) can run with one +> dead disk, and supports auto-rebuild from hot spares, there's really no +> way a single disk can be more reliable. It may have fewer failures, but +> that's not the same thing. + +What controller do you use for IDE hot-swapping and auto-rebuild? +3Ware? + +-- ++-----------------------------------------------------------+ +| Ron Johnson, Jr. Home: ron.l.johnson@cox.net | +| Jefferson, LA USA http://members.cox.net/ron.l.johnson | +| | +| An ad currently being run by the NEA (the US's biggest | +| public school TEACHERS UNION) asks a teenager if he can | +| find sodium and *chloride* in the periodic table of the | +| elements. | +| And they wonder why people think public schools suck... | ++-----------------------------------------------------------+ + + +From pgsql-performance-owner@postgresql.org Mon May 5 18:32:32 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 58E64476353 + for ; + Mon, 5 May 2003 18:32:31 -0400 (EDT) +Received: from mail1.ihs.com (mail1.ihs.com [170.207.70.222]) + by postgresql.org (Postfix) with ESMTP id 8F8B847634B + for ; + Mon, 5 May 2003 18:32:30 -0400 (EDT) +Received: from css120.ihs.com (css120.ihs.com [170.207.105.120]) + by mail1.ihs.com (8.12.9/8.12.9) with ESMTP id h45MVSuu011598; + Mon, 5 May 2003 16:31:28 -0600 (MDT) +Date: Mon, 5 May 2003 16:22:10 -0600 (MDT) +From: "scott.marlowe" +To: Ron Johnson +Cc: PgSQL Performance ML +Subject: Re: Looking for a cheap upgrade (RAID) +In-Reply-To: <1052171694.3371.5.camel@haggis> +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-MailScanner: Found to be clean +X-MailScanner-SpamCheck: +X-Spam-Status: No, hits=-31.7 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REPLY_WITH_QUOTES,USER_AGENT_PINE autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/52 +X-Sequence-Number: 1831 + +On 5 May 2003, Ron Johnson wrote: + +> On Mon, 2003-05-05 at 11:31, scott.marlowe wrote: +> > On 3 May 2003, Ron Johnson wrote: +> > +> > > On Fri, 2003-05-02 at 13:53, Chad Thompson wrote: +> > > > I have a server on a standard pc right now. +> > > > PIII 700, 1Gig ram (SD), 40 Gig IDE, RedHat 8.0, PostgreSQL 7.3.1 +> > > > +> > > > The database has 3 tables that just broke 10 million tuples (yeah, i think +> > > > im entering in to the world of real databases ;-) +> > > > Its primarly bulk (copy) inserts and queries, rarely an update. +> > > > +> > > > I am looking at moving this to a P4 2.4G, 2 Gig Ram(DDR), RedHat 8, +> > > > PostgreSQL 7.3.latest +> > > [snip] +> > > +> > > How big do you expect the database to get? +> > > +> > > If I may be a contrarian, if under 70GB, then why not just get a 72GB +> > > 10K RPM SCSI drive ($160) and a SCSI 160 card? OS, swap, input files, +> > > etc, can go on a 7200RPM IDE drive. +> > > +> > > Much fewer moving parts than RAID, so more reliable... +> > +> > Sorry, everything else is true, but RAID is far more reliable, even if +> > disk failure is more likely. Since a RAID array (1 or 5) can run with one +> > dead disk, and supports auto-rebuild from hot spares, there's really no +> > way a single disk can be more reliable. It may have fewer failures, but +> > that's not the same thing. +> +> What controller do you use for IDE hot-swapping and auto-rebuild? +> 3Ware? + +Linux, and I don't do hot swapping with IDE, just hot rebuild from a +spare drive. My servers are running SCSI, by the way, only the +workstations are running IDE. With the saved cost of a decent RAID +controller (good SCSI controllers are still well over $500 most the time) +I can afford enough hot spares to never have to worry about changing one +out during the day. + + +From pgsql-hackers-owner@postgresql.org Tue May 6 00:25:32 2003 +X-Original-To: pgsql-hackers@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP + id 5591F475E14; Tue, 6 May 2003 00:25:30 -0400 (EDT) +Received: from sss.pgh.pa.us (unknown [192.204.191.242]) + by postgresql.org (Postfix) with ESMTP + id 6E4F1475CBC; Tue, 6 May 2003 00:25:29 -0400 (EDT) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h464PXU6022293; + Tue, 6 May 2003 00:25:33 -0400 (EDT) +To: josh@agliodbs.com +Cc: pgsql-performance , + pgsql-hackers@postgresql.org +Subject: Re: Hypothetical suggestions for planner, indexing improvement +In-reply-to: <200305051219.58955.josh@agliodbs.com> +References: <200305051219.58955.josh@agliodbs.com> +Comments: In-reply-to Josh Berkus + message dated "Mon, 05 May 2003 12:19:58 -0700" +Date: Tue, 06 May 2003 00:25:33 -0400 +Message-ID: <22292.1052195133@sss.pgh.pa.us> +From: Tom Lane +X-Spam-Status: No, hits=-29.3 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,REFERENCES, + REPLY_WITH_QUOTES autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/93 +X-Sequence-Number: 38600 + +Josh Berkus writes: +> THE IDEA: The planner should keep statistics on the correlation of foreign +> keys and apply them to the expected row counts for EXISTS clause limitations, +> and possibly for other query types as well. + +It's a thought. Keeping complete cross-column correlation stats (for +every combination of columns in the DB) is obviously out of the +question. If you're gonna do it you need a heuristic to tell you which +combinations of columns are worth keeping track of --- and foreign-key +relationships seem like a reasonable guide to the interesting +combinations. + +I'm not sure about the long-term usefulness of optimizing EXISTS per se. +Seems to me that a lot of the present uses of EXISTS are workarounds +for Postgres' historic mistreatment of IN ... which we've attacked more +directly for 7.4. But cross-column correlations are certainly useful +for estimating join sizes in general. + + regards, tom lane + + +From pgsql-hackers-owner@postgresql.org Tue May 6 00:36:55 2003 +X-Original-To: pgsql-hackers@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP + id 76F2F475CBC; Tue, 6 May 2003 00:36:53 -0400 (EDT) +Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) + by postgresql.org (Postfix) with ESMTP + id CC9034763DA; Tue, 6 May 2003 00:36:45 -0400 (EDT) +Received: from [63.195.55.98] (HELO spooky) + by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) + with ESMTP id 3011355; Mon, 05 May 2003 21:36:49 -0700 +Content-Type: text/plain; + charset="iso-8859-1" +From: Josh Berkus +Organization: Aglio Database Solutions +To: Tom Lane +Subject: Re: Hypothetical suggestions for planner, indexing improvement +Date: Mon, 5 May 2003 21:33:33 -0700 +User-Agent: KMail/1.4.3 +Cc: pgsql-performance , + pgsql-hackers@postgresql.org +References: <200305051219.58955.josh@agliodbs.com> + <22292.1052195133@sss.pgh.pa.us> +In-Reply-To: <22292.1052195133@sss.pgh.pa.us> +MIME-Version: 1.0 +Message-Id: <200305052133.33680.josh@agliodbs.com> +Content-Transfer-Encoding: quoted-printable +X-Spam-Status: No, hits=-32.4 required=5.0 + tests=BAYES_01,IN_REP_TO,QUOTED_EMAIL_TEXT,REFERENCES, + REPLY_WITH_QUOTES,USER_AGENT_KMAIL autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/94 +X-Sequence-Number: 38601 + +Tom, + +> It's a thought. Keeping complete cross-column correlation stats (for +> every combination of columns in the DB) is obviously out of the +> question. If you're gonna do it you need a heuristic to tell you which +> combinations of columns are worth keeping track of --- and foreign-key +> relationships seem like a reasonable guide to the interesting +> combinations. + +Yes. It would also make FKs something more than just an annoying (and slow= +)=20 +constraint in PostgreSQL. And it would be a performance feature that most= +=20 +other RDBMSs don't have ;-) + +> I'm not sure about the long-term usefulness of optimizing EXISTS per se. +> Seems to me that a lot of the present uses of EXISTS are workarounds +> for Postgres' historic mistreatment of IN ... which we've attacked more +> directly for 7.4. But cross-column correlations are certainly useful +> for estimating join sizes in general. + +EXISTS is more flexible than IN; how can you do a 3-column corellation on a= +n=20 +IN clause? + +The reason that I mention EXISTS is because that's where the lack of=20 +cross-column corellation is most dramatic; the planner seems to estimate a= +=20 +flat 50% for EXISTS clauses regardless of the content. + +--=20 +Josh Berkus +Aglio Database Solutions +San Francisco + + +From pgsql-hackers-owner@postgresql.org Tue May 6 00:45:31 2003 +X-Original-To: pgsql-hackers@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP + id 32E27476394; Tue, 6 May 2003 00:45:27 -0400 (EDT) +Received: from sss.pgh.pa.us (unknown [192.204.191.242]) + by postgresql.org (Postfix) with ESMTP + id 70D72476363; Tue, 6 May 2003 00:45:26 -0400 (EDT) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h464jUU6022401; + Tue, 6 May 2003 00:45:31 -0400 (EDT) +To: Josh Berkus +Cc: pgsql-performance , + pgsql-hackers@postgresql.org +Subject: Re: Hypothetical suggestions for planner, indexing improvement +In-reply-to: <200305052133.33680.josh@agliodbs.com> +References: <200305051219.58955.josh@agliodbs.com> + <22292.1052195133@sss.pgh.pa.us> + <200305052133.33680.josh@agliodbs.com> +Comments: In-reply-to Josh Berkus + message dated "Mon, 05 May 2003 21:33:33 -0700" +Date: Tue, 06 May 2003 00:45:30 -0400 +Message-ID: <22400.1052196330@sss.pgh.pa.us> +From: Tom Lane +X-Spam-Status: No, hits=-32.5 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REFERENCES,REPLY_WITH_QUOTES autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/95 +X-Sequence-Number: 38602 + +Josh Berkus writes: +> The reason that I mention EXISTS is because that's where the lack of +> cross-column corellation is most dramatic; the planner seems to estimate a +> flat 50% for EXISTS clauses regardless of the content. + +No "seems to" about that one: see src/backend/optimizer/path/clausesel.c + + else if (is_subplan(clause)) + { + /* + * Just for the moment! FIX ME! - vadim 02/04/98 + */ + s1 = (Selectivity) 0.5; + } + +Patches to improve this are welcome ;-). But I'm not at all sure how to +write something that would extract a reliable selectivity estimate from +a subplan. + + regards, tom lane + + +From pgsql-performance-owner@postgresql.org Tue May 6 02:59:56 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 2454E4764B8 + for ; + Tue, 6 May 2003 02:59:53 -0400 (EDT) +Received: from gate-w.wettzell.ifag.de (gate-w.ifag.de [141.74.1.1]) + by postgresql.org (Postfix) with ESMTP id 2BBEB4764AD + for ; + Tue, 6 May 2003 02:59:50 -0400 (EDT) +Received: by gate-w.wettzell.ifag.de (8.11.6p2/8.11.6) id h466xo320845 + for pgsql-performance@postgresql.org; Tue, 6 May 2003 06:59:50 GMT +Received: (from localhost) by gate-w.wettzell.ifag.de (MSCAN) id + 2/gate-w.wettzell.ifag.de/smtp-gw/mscan; Tue May 6 06:59:50 2003 +Message-ID: <3EB75D5F.5080406@wettzell.ifag.de> +Date: Tue, 06 May 2003 08:59:43 +0200 +From: Reiner Dassing +Organization: BKG-Wettzell +User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; de-DE; + rv:1.0.2) Gecko/20021120 Netscape/7.01 +X-Accept-Language: de, en, zh +MIME-Version: 1.0 +To: pgsql-performance@postgresql.org +Subject: Select on timestamp-day slower than timestamp alone +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit +X-Spam-Status: No, + hits=-12.9 required=5.0 tests=BAYES_01,USER_AGENT_MOZILLA_UA + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/56 +X-Sequence-Number: 1835 + +Hello all! + +On PostgreSQL V7.3.2 on TRU64 I recognized the following phenomena +that a SELECT using a difference of a timestamp and an interval +in the WHERE clause does not use the index +but using a timestamp without a difference does use the index. +The semantic of both SELECT's is equal, i.e., the result is equal. + +Therefore, the second way is much faster. + +Any ideas? + + +In detail: + table: + +wetter=# \d wetter + Table "public.wetter" + Column | Type | Modifiers +-----------+--------------------------+----------- + sensor_id | integer | not null + epoche | timestamp with time zone | not null + wert | real | not null +Indexes: wetter_pkey primary key btree (sensor_id, epoche), + wetter_epoche_idx btree (epoche), + wetter_sensor_id_idx btree (sensor_id) +Triggers: RI_ConstraintTrigger_45702811, + t_ins_wetter_wetterakt + + + +Select not using index: +----------------------- +wetter=# explain select * from wetter where epoche between +'2003-05-06 06:50:54+00'::timestamp-'1 days'::interval +AND '2003-05-06 04:45:36'; + + QUERY PLAN + +--------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + Seq Scan on wetter (cost=0.00..768644.57 rows=10253528 width=16) + Filter: ((epoche >= ('2003-05-05 06:50:54'::timestamp without time +zone)::timestamp with time zone) AND (epoche <= '2003-05-06 +04:45:36+00'::timestamp with time zone)) +(2 rows) + +wetter=# + + + + +Select using the index: +----------------------- +explain select * from wetter where epoche between '2003-05-05 06:50:54' +AND '2003-05-06 04:45:36'; + +QUERY PLAN + +--------------------------------------------------------------------------------------------------------------------------------------------------- + Index Scan using wetter_epoche_idx on wetter (cost=0.00..5.45 rows=1 +width=16) + Index Cond: ((epoche >= '2003-05-05 06:50:54+00'::timestamp with +time zone) AND (epoche <= '2003-05-06 04:45:36+00'::timestamp with time +zone)) +(2 rows) + +wetter=# + + + + +-- + +Mit freundlichen Gruessen / With best regards + Reiner Dassing + + +From pgsql-performance-owner@postgresql.org Tue May 6 03:25:25 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP + id B5E834763DA; Tue, 6 May 2003 03:25:21 -0400 (EDT) +Received: from smtp.blueyonder.co.uk (pc-62-31-245-32-gl.blueyonder.co.uk + [62.31.245.32]) by postgresql.org (Postfix) with ESMTP + id 8E1F84763B5; Tue, 6 May 2003 03:25:20 -0400 (EDT) +Received: from reddragon.localdomain ([127.0.0.1] helo=localhost) + by smtp.blueyonder.co.uk with esmtp (Exim 4.10) + id 19Cwpd-00036o-00; Tue, 06 May 2003 08:25:45 +0100 +Date: Tue, 6 May 2003 08:25:45 +0100 (BST) +From: Peter Childs +X-X-Sender: peter@RedDragon.Childs +Cc: pgsql-performance , + +Subject: Re: [HACKERS] Hypothetical suggestions for planner, indexing +In-Reply-To: <200305052133.33680.josh@agliodbs.com> +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-Spam-Status: No, hits=-32.3 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + QUOTE_TWICE_1,REPLY_WITH_QUOTES,USER_AGENT_PINE + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/57 +X-Sequence-Number: 1836 + +On Mon, 5 May 2003, Josh Berkus wrote: + +> Tom, +> +> > It's a thought. Keeping complete cross-column correlation stats (for +> > every combination of columns in the DB) is obviously out of the +> > question. If you're gonna do it you need a heuristic to tell you which +> > combinations of columns are worth keeping track of --- and foreign-key +> > relationships seem like a reasonable guide to the interesting +> > combinations. +> +> Yes. It would also make FKs something more than just an annoying (and slow) +> constraint in PostgreSQL. And it would be a performance feature that most +> other RDBMSs don't have ;-) + + That statement seams really strange, If FKs are really only a +safety lock to stop you from putting bad data in your database, It makes +them a bit pointless if you want a nice fast database and you can trust +your users! This does not make them useless and I still have them but from +a purely performance point of view they don't help currently! + It may be worth adding Partial Matching FKs so that a user can +mark that they think might be a useful match to do. This would help the +fact that in many data sets NULL can mean more than one different thing. +(Don't Know, None, etc) plus using the index on IS NOT NULL queries would +be very handy when you need to know about all the records that you need to +find the information out for, or all the records with no relationship. + +Peter Childs + +> +> > I'm not sure about the long-term usefulness of optimizing EXISTS per se. +> > Seems to me that a lot of the present uses of EXISTS are workarounds +> > for Postgres' historic mistreatment of IN ... which we've attacked more +> > directly for 7.4. But cross-column correlations are certainly useful +> > for estimating join sizes in general. +> +> EXISTS is more flexible than IN; how can you do a 3-column corellation on an +> IN clause? +> +> The reason that I mention EXISTS is because that's where the lack of +> cross-column corellation is most dramatic; the planner seems to estimate a +> flat 50% for EXISTS clauses regardless of the content. +> +> + + +From pgsql-performance-owner@postgresql.org Tue May 6 07:04:14 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 9095347648E + for ; + Tue, 6 May 2003 07:04:12 -0400 (EDT) +Received: from lakemtao02.cox.net (lakemtao02.cox.net [68.1.17.243]) + by postgresql.org (Postfix) with ESMTP id 1EEEC476465 + for ; + Tue, 6 May 2003 07:04:08 -0400 (EDT) +Received: from [192.168.1.1] ([68.11.66.83]) by lakemtao02.cox.net + (InterMail vM.5.01.04.05 201-253-122-122-105-20011231) with ESMTP + id <20030506110411.RBZI24359.lakemtao02.cox.net@[192.168.1.1]> + for ; + Tue, 6 May 2003 07:04:11 -0400 +Subject: Re: Looking for a cheap upgrade (RAID) +From: Ron Johnson +To: PgSQL Performance ML +In-Reply-To: +References: +Content-Type: text/plain +Organization: +Message-Id: <1052219046.3368.245.camel@haggis> +Mime-Version: 1.0 +X-Mailer: Ximian Evolution 1.2.4 +Date: 06 May 2003 06:04:06 -0500 +Content-Transfer-Encoding: 7bit +X-Spam-Status: No, hits=-44.3 required=5.0 + tests=BAYES_10,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REFERENCES,REPLY_WITH_QUOTES,SIGNATURE_LONG_DENSE, + USER_AGENT_XIMIAN autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/58 +X-Sequence-Number: 1837 + +On Mon, 2003-05-05 at 17:22, scott.marlowe wrote: +> On 5 May 2003, Ron Johnson wrote: +> +> > On Mon, 2003-05-05 at 11:31, scott.marlowe wrote: +> > > On 3 May 2003, Ron Johnson wrote: +> > > +> > > > On Fri, 2003-05-02 at 13:53, Chad Thompson wrote: +[snip] +> > What controller do you use for IDE hot-swapping and auto-rebuild? +> > 3Ware? +> +> Linux, and I don't do hot swapping with IDE, just hot rebuild from a +> spare drive. My servers are running SCSI, by the way, only the +> workstations are running IDE. With the saved cost of a decent RAID +> controller (good SCSI controllers are still well over $500 most the time) +> I can afford enough hot spares to never have to worry about changing one +> out during the day. + +Ah, I guess that drives go out infrequently enough that shutting +it down at night for a swap-out isn't all that onerous... + +What controller model do you use? + +-- ++-----------------------------------------------------------+ +| Ron Johnson, Jr. Home: ron.l.johnson@cox.net | +| Jefferson, LA USA http://members.cox.net/ron.l.johnson | +| | +| An ad currently being run by the NEA (the US's biggest | +| public school TEACHERS UNION) asks a teenager if he can | +| find sodium and *chloride* in the periodic table of the | +| elements. | +| And they wonder why people think public schools suck... | ++-----------------------------------------------------------+ + + +From pgsql-performance-owner@postgresql.org Tue May 6 07:49:19 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id D7E07475CA9 + for ; + Tue, 6 May 2003 07:49:18 -0400 (EDT) +Received: from lakemtao01.cox.net (lakemtao01.cox.net [68.1.17.244]) + by postgresql.org (Postfix) with ESMTP id 881A5474E42 + for ; + Tue, 6 May 2003 07:49:17 -0400 (EDT) +Received: from [192.168.1.1] ([68.11.66.83]) by lakemtao01.cox.net + (InterMail vM.5.01.04.05 201-253-122-122-105-20011231) with ESMTP + id <20030506114920.LYFI8337.lakemtao01.cox.net@[192.168.1.1]> + for ; + Tue, 6 May 2003 07:49:20 -0400 +Subject: Re: [HACKERS] Hypothetical suggestions for planner, +From: Ron Johnson +To: PgSQL Performance ML +In-Reply-To: <22292.1052195133@sss.pgh.pa.us> +References: <200305051219.58955.josh@agliodbs.com> + <22292.1052195133@sss.pgh.pa.us> +Content-Type: text/plain +Organization: +Message-Id: <1052221755.3368.286.camel@haggis> +Mime-Version: 1.0 +X-Mailer: Ximian Evolution 1.2.4 +Date: 06 May 2003 06:49:15 -0500 +Content-Transfer-Encoding: 7bit +X-Spam-Status: No, hits=-44.3 required=5.0 + tests=BAYES_10,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REFERENCES,REPLY_WITH_QUOTES,SIGNATURE_LONG_DENSE, + USER_AGENT_XIMIAN autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/59 +X-Sequence-Number: 1838 + +On Mon, 2003-05-05 at 23:25, Tom Lane wrote: +> Josh Berkus writes: +> > THE IDEA: The planner should keep statistics on the correlation of foreign +> > keys and apply them to the expected row counts for EXISTS clause limitations, +> > and possibly for other query types as well. +> +> It's a thought. Keeping complete cross-column correlation stats (for +> every combination of columns in the DB) is obviously out of the +> question. If you're gonna do it you need a heuristic to tell you which +> combinations of columns are worth keeping track of --- and foreign-key +> relationships seem like a reasonable guide to the interesting +> combinations. + +How about generalizing this into something useful for all queries? + +And to make this problem not just guess work on the part of the +optimizer, how about having a separate "backslash command" so that +the DBA can add specific/important/crucial predicates that he needs +optimized. + +Thus, if there's a query with a large WHERE clause that has an +optimized predicate inside it, the statistics would be used. + +> WHERE event_day BETWEEN '2003-04-08' AND '2003-05-18') + +What this sounds to me like, though, is that in order for it to +work quickly, the postmaster would have to keep track in system +tables each value of event_day and it's COUNT(*), thus more I/O +overhead. + +-- ++---------------------------------------------------------------+ +| Ron Johnson, Jr. mailto:ron.l.johnson@cox.net | +| Jefferson, LA USA http://members.cox.net/ron.l.johnson | +| | +| The purpose of the military isn't to pay your college tuition | +| or give you a little extra income; it's to "kill people and | +| break things". Surprisingly, not everyone understands that. | ++---------------------------------------------------------------+ + + +From pgsql-admin-owner@postgresql.org Tue May 6 08:21:33 2003 +X-Original-To: pgsql-admin@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id A76E74763CE + for ; Tue, 6 May 2003 08:21:30 -0400 (EDT) +Received: from kernel.net.uy (ip129-2.bellsouth.net.uy [200.58.129.2]) + by postgresql.org (Postfix) with SMTP id 3CB65476385 + for ; Tue, 6 May 2003 08:21:28 -0400 (EDT) +Received: (qmail 6684 invoked by uid 89); 6 May 2003 12:49:00 -0000 +Received: from unknown (HELO fabio) (192.168.1.5) + by 0 with SMTP; 6 May 2003 12:49:00 -0000 +Reply-To: +From: "Fabio C. Bon" +To: +Subject: A query with performance problems. +Date: Tue, 6 May 2003 09:21:16 -0300 +Message-ID: <003301c313c9$fe7a2d80$0501a8c0@kdomain> +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit +X-Priority: 3 (Normal) +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook CWS, Build 9.0.2416 (9.0.2910.0) +X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300 +Importance: Normal +X-Spam-Status: No, hits=-3.1 required=5.0 + tests=BAYES_20 + version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/55 +X-Sequence-Number: 8617 + +Hi ! + +I have a database on PostgreSQL 7.2.1 and I have performance's problems with +some queries. +I'm debbuging the query below: + +Select count(*) from blcar +where manide = 3811 and blide = 58090 and bcalupcod = 'MVDUY' and bcalopcod += 'LOCAL' and bcapag <> 'P'; + + From the command prompt of Psql: + + QUERY PLAN +---------------------------------------------------------------------------- +-------------------------------------- + Aggregate (cost=3.03..3.03 rows=1 width=0) (actual time=0.20..0.20 rows=1 +loops=1) + -> Index Scan using iblsec on blcar (cost=0.00..3.02 rows=1 width=0) +(actual time=0.19..0.19 rows=0 loops=1) + Index Cond: ((manide = 3811) AND (blide = 58090)) + Filter: ((bcalupcod = 'MVDUY'::bpchar) AND (bcalopcod = +'REPRE'::bpchar) AND (bcapag <> 'P'::bpchar)) + Total runtime: 0.30 msec +(5 rows) + + From a file with a SQL sentence. (I execute it this way: \i filename) + + +QUERY PLAN +---------------------------------------------------------------------------- +---------------------------------------------------------------------------- +--------------------------------------- + Aggregate (cost=8277.10..8277.10 rows=1 width=0) (actual +time=1273.98..1273.98 rows=1 loops=1) + -> Seq Scan on blcar (cost=0.00..8277.09 rows=1 width=0) (actual +time=1273.96..1273.96 rows=0 loops=1) + Filter: (((manide)::numeric = 3811::numeric) AND ((blide)::numeric += 58090::numeric) AND (bcalupcod = 'MVDUY'::bpchar) AND (bcalopcod = +'REPRE'::bpchar) AND (bcapag <> 'P'::bpchar)) + Total runtime: 1274.08 msec +(4 rows) + +The problem is how one understands this duality of execution plans for the +same sentence in two situations which are really the same. +It's a relevant matter, because I need to solve performance problems +involved with the execution of this sentence from a program, and due to the +execution time this query required (according to the logfile of database), I +understand that it is choosing the second plan, when it is more reasonable +to use the first plan. + +Thanks + + +From pgsql-performance-owner@postgresql.org Tue May 6 09:04:33 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 1DD13475E77 + for ; + Tue, 6 May 2003 09:04:31 -0400 (EDT) +Received: from anchor-post-32.mail.demon.net (anchor-post-32.mail.demon.net + [194.217.242.90]) + by postgresql.org (Postfix) with ESMTP id C4D4F474E42 + for ; + Tue, 6 May 2003 09:04:26 -0400 (EDT) +Received: from mwynhau.demon.co.uk ([193.237.186.96] + helo=mainbox.archonet.com) + by anchor-post-32.mail.demon.net with esmtp (Exim 3.35 #1) + id 19D27R-0008L9-0W; Tue, 06 May 2003 14:04:29 +0100 +Received: from localhost (localhost.localdomain [127.0.0.1]) + by mainbox.archonet.com (Postfix) with ESMTP + id 814FF168BF; Tue, 6 May 2003 14:04:28 +0100 (BST) +Received: from client.archonet.com (client.archonet.com [192.168.1.16]) + by mainbox.archonet.com (Postfix) with ESMTP + id D49CE168B6; Tue, 6 May 2003 14:04:27 +0100 (BST) +Content-Type: text/plain; + charset="iso-8859-1" +From: Richard Huxton +Organization: Archonet Ltd +To: Reiner Dassing , + pgsql-performance@postgresql.org +Subject: Re: Select on timestamp-day slower than timestamp alone +Date: Tue, 6 May 2003 14:04:24 +0100 +User-Agent: KMail/1.4.3 +References: <3EB75D5F.5080406@wettzell.ifag.de> +In-Reply-To: <3EB75D5F.5080406@wettzell.ifag.de> +MIME-Version: 1.0 +Content-Transfer-Encoding: quoted-printable +Message-Id: <200305061404.24194.dev@archonet.com> +X-Virus-Scanned: by AMaViS snapshot-20020531 +X-Spam-Status: No, hits=-38.9 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REFERENCES,REPLY_WITH_QUOTES,USER_AGENT_KMAIL + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/60 +X-Sequence-Number: 1839 + +On Tuesday 06 May 2003 7:59 am, Reiner Dassing wrote: +> Hello all! +> +> On PostgreSQL V7.3.2 on TRU64 I recognized the following phenomena +> that a SELECT using a difference of a timestamp and an interval +> in the WHERE clause does not use the index +> but using a timestamp without a difference does use the index. +> The semantic of both SELECT's is equal, i.e., the result is equal. +> +> Therefore, the second way is much faster. +> +> Any ideas? + +> Select not using index: +> ----------------------- +> wetter=3D# explain select * from wetter where epoche between +> '2003-05-06 06:50:54+00'::timestamp-'1 days'::interval +> AND '2003-05-06 04:45:36'; +> +> QUERY PLAN +> +> -------------------------------------------------------------------------= +-- +>--------------------------------------------------------------------------= +-- +>-------------------- Seq Scan on wetter (cost=3D0.00..768644.57 rows=3D10= +253528 +> width=3D16) Filter: ((epoche >=3D ('2003-05-05 06:50:54'::timestamp witho= +ut +> time zone)::timestamp with time zone) AND (epoche <=3D '2003-05-06 +> 04:45:36+00'::timestamp with time zone)) +> (2 rows) + +Well, the "why" is because the number of rows recommended is so big=20 +(rows=3D10253528) - I'm also puzzled why we get "timestamp without time zon= +e".=20 +Does an explicit cast to "with time zone" help? + +--=20 + Richard Huxton + + +From pgsql-performance-owner@postgresql.org Tue May 6 09:07:52 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 1BF224764A9 + for ; + Tue, 6 May 2003 09:07:50 -0400 (EDT) +Received: from flake.decibel.org (flake.decibel.org [66.143.173.58]) + by postgresql.org (Postfix) with SMTP id 458EA4763CE + for ; + Tue, 6 May 2003 09:07:49 -0400 (EDT) +Received: (qmail 43944 invoked by uid 1001); 6 May 2003 13:07:47 -0000 +Date: Tue, 6 May 2003 08:07:47 -0500 +From: "Jim C. Nasby" +To: Josh Berkus +Cc: Tom Lane , + pgsql-performance , + pgsql-hackers@postgresql.org +Subject: Re: [HACKERS] Hypothetical suggestions for planner, + indexing improvement +Message-ID: <20030506080747.C66185@flake.decibel.org> +Reply-To: jim@nasby.net +References: <200305051219.58955.josh@agliodbs.com> + <22292.1052195133@sss.pgh.pa.us> + <200305052133.33680.josh@agliodbs.com> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +User-Agent: Mutt/1.2.5.1i +In-Reply-To: <200305052133.33680.josh@agliodbs.com>; + from josh@agliodbs.com on Mon, May 05, 2003 at 09:33:33PM -0700 +X-Operating-System: FreeBSD 4.8-RELEASE i386 +X-Distributed: Join the Effort! http://www.distributed.net +X-Spam-Status: No, hits=-36.2 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,REFERENCES, + REPLY_WITH_QUOTES,SIGNATURE_SHORT_SPARSE,USER_AGENT_MUTT + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/61 +X-Sequence-Number: 1840 + +On Mon, May 05, 2003 at 09:33:33PM -0700, Josh Berkus wrote: +> EXISTS is more flexible than IN; how can you do a 3-column corellation on an +> IN clause? + +It would be nice to add support for multi-column IN.. + +WHERE (a, b, c) IN (SELECT a, b, c ...) + +BTW, does postgresql handle IN and EXISTS differently? Theoretically if +the optimizer was good enough you could transform one to the other and +not worry about it. Whenever possible, I try and use IN when the +subselect will return a very small number of rows, since IN might be +faster than EXISTS in that case, though it seems most optimizers tend to +fall apart when they see ORs, and a lot of databases transform IN to a +OR b OR c. +-- +Jim C. Nasby (aka Decibel!) jim@nasby.net +Member: Triangle Fraternity, Sports Car Club of America +Give your computer some brain candy! www.distributed.net Team #1828 + +Windows: "Where do you want to go today?" +Linux: "Where do you want to go tomorrow?" +FreeBSD: "Are you guys coming, or what?" + + +From pgsql-performance-owner@postgresql.org Tue May 6 09:10:35 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 45BD94764EB + for ; + Tue, 6 May 2003 09:10:33 -0400 (EDT) +Received: from flake.decibel.org (flake.decibel.org [66.143.173.58]) + by postgresql.org (Postfix) with SMTP id DA7A8474E42 + for ; + Tue, 6 May 2003 09:10:31 -0400 (EDT) +Received: (qmail 47005 invoked by uid 1001); 6 May 2003 13:10:35 -0000 +Date: Tue, 6 May 2003 08:10:35 -0500 +From: "Jim C. Nasby" +To: Tom Lane +Cc: josh@agliodbs.com, pgsql-performance , + pgsql-hackers@postgresql.org +Subject: Re: [HACKERS] Hypothetical suggestions for planner, + indexing improvement +Message-ID: <20030506081035.D66185@flake.decibel.org> +Reply-To: jim@nasby.net +References: <200305051219.58955.josh@agliodbs.com> + <22292.1052195133@sss.pgh.pa.us> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +User-Agent: Mutt/1.2.5.1i +In-Reply-To: <22292.1052195133@sss.pgh.pa.us>; + from tgl@sss.pgh.pa.us on Tue, May 06, 2003 at 12:25:33AM -0400 +X-Operating-System: FreeBSD 4.8-RELEASE i386 +X-Distributed: Join the Effort! http://www.distributed.net +X-Spam-Status: No, hits=-38.6 required=5.0 + tests=BAYES_10,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REFERENCES,REPLY_WITH_QUOTES,SIGNATURE_SHORT_SPARSE, + USER_AGENT_MUTT version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/62 +X-Sequence-Number: 1841 + +On Tue, May 06, 2003 at 12:25:33AM -0400, Tom Lane wrote: +> Josh Berkus writes: +> > THE IDEA: The planner should keep statistics on the correlation of foreign +> > keys and apply them to the expected row counts for EXISTS clause limitations, +> > and possibly for other query types as well. +> +> It's a thought. Keeping complete cross-column correlation stats (for +> every combination of columns in the DB) is obviously out of the +> question. If you're gonna do it you need a heuristic to tell you which +> combinations of columns are worth keeping track of --- and foreign-key +> relationships seem like a reasonable guide to the interesting +> combinations. + +What if the optimizer kept on-going statistics on what columns were used +in joins to what other columns? Over time this would allow analyze to +determine on it's own what cross-column correlation stats should be +kept. +-- +Jim C. Nasby (aka Decibel!) jim@nasby.net +Member: Triangle Fraternity, Sports Car Club of America +Give your computer some brain candy! www.distributed.net Team #1828 + +Windows: "Where do you want to go today?" +Linux: "Where do you want to go tomorrow?" +FreeBSD: "Are you guys coming, or what?" + + +From pgsql-hackers-owner@postgresql.org Tue May 6 09:45:08 2003 +X-Original-To: pgsql-hackers@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP + id 31001475E77; Tue, 6 May 2003 09:45:07 -0400 (EDT) +Received: from sss.pgh.pa.us (unknown [192.204.191.242]) + by postgresql.org (Postfix) with ESMTP + id 422ED474E42; Tue, 6 May 2003 09:45:06 -0400 (EDT) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h46Dj7U6024780; + Tue, 6 May 2003 09:45:08 -0400 (EDT) +To: jim@nasby.net +Cc: Josh Berkus , + pgsql-performance , + pgsql-hackers@postgresql.org +Subject: Re: [PERFORM] Hypothetical suggestions for planner, + indexing improvement +In-reply-to: <20030506080747.C66185@flake.decibel.org> +References: <200305051219.58955.josh@agliodbs.com> + <22292.1052195133@sss.pgh.pa.us> + <200305052133.33680.josh@agliodbs.com> + <20030506080747.C66185@flake.decibel.org> +Comments: In-reply-to "Jim C. Nasby" + message dated "Tue, 06 May 2003 08:07:47 -0500" +Date: Tue, 06 May 2003 09:45:07 -0400 +Message-ID: <24779.1052228707@sss.pgh.pa.us> +From: Tom Lane +X-Spam-Status: No, hits=-32.3 required=5.0 + tests=BAYES_00,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REFERENCES,REPLY_WITH_QUOTES autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/101 +X-Sequence-Number: 38608 + +"Jim C. Nasby" writes: +> It would be nice to add support for multi-column IN.. +> WHERE (a, b, c) IN (SELECT a, b, c ...) + +RTFM... + +> BTW, does postgresql handle IN and EXISTS differently? + +Yes. + +> Theoretically if the optimizer was good enough you could transform one +> to the other and not worry about it. + +No. They have different responses to NULLs in the subselect result. + + regards, tom lane + + +From pgsql-performance-owner@postgresql.org Tue May 6 09:59:09 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 738E94763CD + for ; + Tue, 6 May 2003 09:59:08 -0400 (EDT) +Received: from sss.pgh.pa.us (unknown [192.204.191.242]) + by postgresql.org (Postfix) with ESMTP id B89C6474E42 + for ; + Tue, 6 May 2003 09:59:07 -0400 (EDT) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h46Dx8U6024864; + Tue, 6 May 2003 09:59:08 -0400 (EDT) +To: Richard Huxton +Cc: Reiner Dassing , + pgsql-performance@postgresql.org +Subject: Re: Select on timestamp-day slower than timestamp alone +In-reply-to: <200305061404.24194.dev@archonet.com> +References: <3EB75D5F.5080406@wettzell.ifag.de> + <200305061404.24194.dev@archonet.com> +Comments: In-reply-to Richard Huxton + message dated "Tue, 06 May 2003 14:04:24 +0100" +Date: Tue, 06 May 2003 09:59:08 -0400 +Message-ID: <24863.1052229548@sss.pgh.pa.us> +From: Tom Lane +X-Spam-Status: No, hits=-32.3 required=5.0 + tests=BAYES_00,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REFERENCES,REPLY_WITH_QUOTES autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/64 +X-Sequence-Number: 1843 + +Richard Huxton writes: +> Well, the "why" is because the number of rows recommended is so big +> (rows=10253528) - I'm also puzzled why we get "timestamp without time zone". + +Because that's what he specified the constant to be. + +> Does an explicit cast to "with time zone" help? + +Writing the constant as timestamp with time zone would fix it. +Casting after-the-fact would not. + +The reason: although both "timestamp minus interval" and "timestamptz +minus interval" are constant-foldable, timestamp-to-timestamptz +conversion is not (because it depends on SET TIMEZONE). So the +planner has to fall back to a default selectivity estimate. With real +constants it is able to derive a better estimate. + + regards, tom lane + + +From pgsql-performance-owner@postgresql.org Tue May 6 10:00:47 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id EDBAB475E77 + for ; + Tue, 6 May 2003 10:00:45 -0400 (EDT) +Received: from gate-w.wettzell.ifag.de (gate-w.ifag.de [141.74.1.1]) + by postgresql.org (Postfix) with ESMTP id C689B474E42 + for ; + Tue, 6 May 2003 10:00:44 -0400 (EDT) +Received: by gate-w.wettzell.ifag.de (8.11.6p2/8.11.6) id h46E0mg16565; + Tue, 6 May 2003 14:00:48 GMT +Received: (from localhost) by gate-w.wettzell.ifag.de (MSCAN) id + 2/gate-w.wettzell.ifag.de/smtp-gw/mscan; Tue May 6 14:00:48 2003 +Message-ID: <3EB7C000.9030206@wettzell.ifag.de> +Date: Tue, 06 May 2003 16:00:32 +0200 +From: Reiner Dassing +Organization: BKG-Wettzell +User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; de-DE; + rv:1.0.2) Gecko/20021120 Netscape/7.01 +X-Accept-Language: de, en, zh +MIME-Version: 1.0 +To: Richard Huxton +Cc: pgsql-performance@postgresql.org +Subject: Re: Select on timestamp-day slower than timestamp alone +References: <3EB75D5F.5080406@wettzell.ifag.de> + <200305061404.24194.dev@archonet.com> +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit +X-Spam-Status: No, hits=-22.6 required=5.0 + tests=BAYES_01,QUOTED_EMAIL_TEXT,REFERENCES,USER_AGENT_MOZILLA_UA + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/65 +X-Sequence-Number: 1844 + +Hello Richard! + + +Your proposal to use an explicit cast to "with time zone" helps: + +explain +select * from wetter where epoche between +'2003-05-06 06:50:54+00'::timestamp with time zone-'1 days'::interval +AND '2003-05-06 04:45:36'; + + +QUERY PLAN + +--------------------------------------------------------------------------------------------------------------------------------------------------- + Index Scan using wetter_epoche_idx on wetter (cost=0.00..5.45 rows=1 +width=16) + Index Cond: ((epoche >= '2003-05-05 06:50:54+00'::timestamp with +time zone) AND (epoche <= '2003-05-06 04:45:36+00'::timestamp with time +zone)) +(2 rows) + +The result now is like expected. + +Thanks for the help. +But for your question "why we get "timestamp without time zone"." +I have no answer. + +Reiner + + +> +>>Select not using index: +>>----------------------- +>>wetter=# explain select * from wetter where epoche between +>>'2003-05-06 06:50:54+00'::timestamp-'1 days'::interval +>>AND '2003-05-06 04:45:36'; +>> +>> QUERY PLAN +>> +>>--------------------------------------------------------------------------- +>>---------------------------------------------------------------------------- +>>-------------------- Seq Scan on wetter (cost=0.00..768644.57 rows=10253528 +>>width=16) Filter: ((epoche >= ('2003-05-05 06:50:54'::timestamp without +>>time zone)::timestamp with time zone) AND (epoche <= '2003-05-06 +>>04:45:36+00'::timestamp with time zone)) +>>(2 rows) +> +> +> Well, the "why" is because the number of rows recommended is so big +> (rows=10253528) - I'm also puzzled why we get "timestamp without time zone". +> Does an explicit cast to "with time zone" help? +> + + +From pgsql-hackers-owner@postgresql.org Tue May 6 10:05:33 2003 +X-Original-To: pgsql-hackers@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP + id D3EC3475E77; Tue, 6 May 2003 10:05:30 -0400 (EDT) +Received: from houston.familyhealth.com.au (unknown [203.59.48.253]) + by postgresql.org (Postfix) with ESMTP + id 82597474E42; Tue, 6 May 2003 10:05:24 -0400 (EDT) +Received: from localhost (chriskl@localhost) + by houston.familyhealth.com.au (8.11.6p2/8.11.6) with ESMTP id + h46E4gw17092; Tue, 6 May 2003 22:04:43 +0800 (WST) + (envelope-from chriskl@familyhealth.com.au) +Date: Tue, 6 May 2003 22:04:39 +0800 (WST) +From: Christopher Kings-Lynne +To: "Jim C. Nasby" +Cc: Josh Berkus , Tom Lane , + pgsql-performance , + +Subject: Re: [PERFORM] Hypothetical suggestions for planner, indexing +In-Reply-To: <20030506080747.C66185@flake.decibel.org> +Message-ID: <20030506220422.T16817-100000@houston.familyhealth.com.au> +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-Spam-Status: No, hits=-12.8 required=5.0 + tests=BAYES_00,IN_REP_TO,QUOTED_EMAIL_TEXT + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/102 +X-Sequence-Number: 38609 + +> On Mon, May 05, 2003 at 09:33:33PM -0700, Josh Berkus wrote: +> > EXISTS is more flexible than IN; how can you do a 3-column corellation on an +> > IN clause? +> +> It would be nice to add support for multi-column IN.. +> +> WHERE (a, b, c) IN (SELECT a, b, c ...) + +Umm....we DO have that... + +Chris + + +From pgsql-performance-owner@postgresql.org Tue May 6 10:39:58 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 7F014474E42 + for ; + Tue, 6 May 2003 10:39:55 -0400 (EDT) +Received: from megazone.bigpanda.com (megazone.bigpanda.com [63.150.15.178]) + by postgresql.org (Postfix) with ESMTP id E8DE84764DA + for ; + Tue, 6 May 2003 10:39:53 -0400 (EDT) +Received: by megazone.bigpanda.com (Postfix, from userid 1001) + id 15445D63D; Tue, 6 May 2003 07:39:58 -0700 (PDT) +Received: from localhost (localhost [127.0.0.1]) + by megazone.bigpanda.com (Postfix) with ESMTP + id 0ACCA5C0C; Tue, 6 May 2003 07:39:58 -0700 (PDT) +Date: Tue, 6 May 2003 07:39:57 -0700 (PDT) +From: Stephan Szabo +To: "Fabio C. Bon" +Cc: +Subject: Re: [ADMIN] A query with performance problems. +In-Reply-To: <003301c313c9$fe7a2d80$0501a8c0@kdomain> +Message-ID: <20030506073613.K7678-100000@megazone23.bigpanda.com> +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-Spam-Status: No, hits=-26.0 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REPLY_WITH_QUOTES autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/67 +X-Sequence-Number: 1846 + + +[Moving to -performance since it's more ontopic there] + +On Tue, 6 May 2003, Fabio C. Bon wrote: + +> I have a database on PostgreSQL 7.2.1 and I have performance's problems with +> some queries. +> I'm debbuging the query below: +> +> Select count(*) from blcar +> where manide = 3811 and blide = 58090 and bcalupcod = 'MVDUY' and bcalopcod +> = 'LOCAL' and bcapag <> 'P'; + +What does the schema of the table look like? + +Is the SQL query in the file exactly the same text as the above? + +> Aggregate (cost=8277.10..8277.10 rows=1 width=0) (actual +> time=1273.98..1273.98 rows=1 loops=1) +> -> Seq Scan on blcar (cost=0.00..8277.09 rows=1 width=0) (actual +> time=1273.96..1273.96 rows=0 loops=1) +> Filter: (((manide)::numeric = 3811::numeric) AND ((blide)::numeric + +It seems to want to coerce manide and blide to a numeric here, which seems +odd. + +> = 58090::numeric) AND (bcalupcod = 'MVDUY'::bpchar) AND (bcalopcod = +> 'REPRE'::bpchar) AND (bcapag <> 'P'::bpchar)) +> Total runtime: 1274.08 msec +> (4 rows) + + +From pgsql-hackers-owner@postgresql.org Tue May 6 11:33:49 2003 +X-Original-To: pgsql-hackers@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 8D7EF476351 + for ; + Tue, 6 May 2003 11:33:46 -0400 (EDT) +Received: from localhost.localdomain (unknown [65.217.53.66]) + by postgresql.org (Postfix) with ESMTP id C4480476375 + for ; + Tue, 6 May 2003 11:33:45 -0400 (EDT) +Received: from thorn.mmrd.com (thorn.mmrd.com [172.25.10.100]) + by localhost.localdomain (8.12.8/8.12.8) with ESMTP id h46GIUF0015588; + Tue, 6 May 2003 12:18:30 -0400 +Received: from gnvex001.mmrd.com (gnvex001.mmrd.com [192.168.3.55]) + by thorn.mmrd.com (8.11.6/8.11.6) with ESMTP id h46FXfC30369; + Tue, 6 May 2003 11:33:41 -0400 +Received: from camel.mmrd.com ([172.25.5.213]) by gnvex001.mmrd.com with SMTP + (Microsoft Exchange Internet Mail Service Version 5.5.2653.13) + id 2YCPXW0Q; Tue, 6 May 2003 11:33:39 -0400 +Subject: Re: Hypothetical suggestions for planner, indexing +From: Robert Treat +To: Tom Lane +Cc: Josh Berkus , pgsql-hackers@postgresql.org +In-Reply-To: <22400.1052196330@sss.pgh.pa.us> +References: <200305051219.58955.josh@agliodbs.com> + <22292.1052195133@sss.pgh.pa.us> <200305052133.33680.josh@agliodbs.com> + <22400.1052196330@sss.pgh.pa.us> +Content-Type: text/plain +Content-Transfer-Encoding: 7bit +X-Mailer: Ximian Evolution 1.0.8 +Date: 06 May 2003 11:33:41 -0400 +Message-Id: <1052235221.30177.26.camel@camel> +Mime-Version: 1.0 +X-Spam-Status: No, hits=-38.8 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REFERENCES,REPLY_WITH_QUOTES,USER_AGENT_XIMIAN + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/109 +X-Sequence-Number: 38616 + +On Tue, 2003-05-06 at 00:45, Tom Lane wrote: +> Josh Berkus writes: +> > The reason that I mention EXISTS is because that's where the lack of +> > cross-column corellation is most dramatic; the planner seems to estimate a +> > flat 50% for EXISTS clauses regardless of the content. +> +> No "seems to" about that one: see src/backend/optimizer/path/clausesel.c +> +> else if (is_subplan(clause)) +> { +> /* +> * Just for the moment! FIX ME! - vadim 02/04/98 +> */ +> s1 = (Selectivity) 0.5; +> } +> +> Patches to improve this are welcome ;-). But I'm not at all sure how to +> write something that would extract a reliable selectivity estimate from +> a subplan. +> + +given that we have so few GUC variables... + +would there be any merit in adding one that would allow folks to change +this assumption? + +Robert Treat + + +From pgsql-performance-owner@postgresql.org Tue May 6 14:23:13 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id C41644764CD + for ; + Tue, 6 May 2003 14:23:09 -0400 (EDT) +Received: from mail1.ihs.com (mail1.ihs.com [170.207.70.222]) + by postgresql.org (Postfix) with ESMTP id D790847648E + for ; + Tue, 6 May 2003 14:23:08 -0400 (EDT) +Received: from css120.ihs.com (css120.ihs.com [170.207.105.120]) + by mail1.ihs.com (8.12.9/8.12.9) with ESMTP id h46IMGuu002935; + Tue, 6 May 2003 12:22:16 -0600 (MDT) +Date: Tue, 6 May 2003 12:12:51 -0600 (MDT) +From: "scott.marlowe" +To: Ron Johnson +Cc: PgSQL Performance ML +Subject: Re: Looking for a cheap upgrade (RAID) +In-Reply-To: <1052219046.3368.245.camel@haggis> +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-MailScanner: Found to be clean +X-MailScanner-SpamCheck: +X-Spam-Status: No, hits=-31.7 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REPLY_WITH_QUOTES,USER_AGENT_PINE autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/68 +X-Sequence-Number: 1847 + +On 6 May 2003, Ron Johnson wrote: + +> On Mon, 2003-05-05 at 17:22, scott.marlowe wrote: +> > On 5 May 2003, Ron Johnson wrote: +> > +> > > On Mon, 2003-05-05 at 11:31, scott.marlowe wrote: +> > > > On 3 May 2003, Ron Johnson wrote: +> > > > +> > > > > On Fri, 2003-05-02 at 13:53, Chad Thompson wrote: +> [snip] +> > > What controller do you use for IDE hot-swapping and auto-rebuild? +> > > 3Ware? +> > +> > Linux, and I don't do hot swapping with IDE, just hot rebuild from a +> > spare drive. My servers are running SCSI, by the way, only the +> > workstations are running IDE. With the saved cost of a decent RAID +> > controller (good SCSI controllers are still well over $500 most the time) +> > I can afford enough hot spares to never have to worry about changing one +> > out during the day. +> +> Ah, I guess that drives go out infrequently enough that shutting +> it down at night for a swap-out isn't all that onerous... +> +> What controller model do you use? + +My preference is SymBIOS (LSI now) plain UW SCSI 160, but at work we use +adaptec built in UW SCSI 160 on INTEL dual CPU motherboards. I've used +RAID controllers in the past, but now I genuinely prefer linux's built in +kernel level raid to most controllers, and the load on the server is <2% +of one of the two CPUs, so it doesn't really slow anything else down. The +performance is quite good, I can read raw at about 48 Megs a second from a +pair of 10kRPM UWSCSI drives in a RAID1. These drives, individually can +pump out about 25 megs a second individually. + + +From pgsql-hackers-owner@postgresql.org Tue May 6 14:32:57 2003 +X-Original-To: pgsql-hackers@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP + id 8B5AB4764B4; Tue, 6 May 2003 14:32:55 -0400 (EDT) +Received: from zigo.dhs.org (as2-4-3.an.g.bonet.se [194.236.34.191]) + by postgresql.org (Postfix) with ESMTP + id 3BAD3476538; Tue, 6 May 2003 14:32:22 -0400 (EDT) +Received: from localhost (db@localhost) + by zigo.dhs.org (8.11.6/8.11.6) with ESMTP id h46IW1K23346; + Tue, 6 May 2003 20:32:01 +0200 +Date: Tue, 6 May 2003 20:32:01 +0200 (CEST) +From: =?ISO-8859-1?Q?Dennis_Bj=F6rklund?= +To: Tom Lane +Cc: jim@nasby.net, Josh Berkus , + pgsql-performance , + +Subject: Re: [PERFORM] Hypothetical suggestions for planner, indexing +In-Reply-To: <24779.1052228707@sss.pgh.pa.us> +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-Spam-Status: No, hits=-22.6 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTE_TWICE_1, + USER_AGENT_PINE autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/113 +X-Sequence-Number: 38620 + +On Tue, 6 May 2003, Tom Lane wrote: + +> > It would be nice to add support for multi-column IN.. +> > WHERE (a, b, c) IN (SELECT a, b, c ...) +> +> RTFM... + +Maybe he did read the manual: + +6.15.3. IN (subquery form) + +expression IN (subquery) + +The right-hand side of this form of IN is a parenthesized subquery, which +must return exactly one column. + +-- +/Dennis + + +From pgsql-performance-owner@postgresql.org Tue May 6 15:33:56 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 2AE95476495 + for ; + Tue, 6 May 2003 15:33:53 -0400 (EDT) +Received: from lakemtao03.cox.net (lakemtao03.cox.net [68.1.17.242]) + by postgresql.org (Postfix) with ESMTP id BDD374764B4 + for ; + Tue, 6 May 2003 15:33:20 -0400 (EDT) +Received: from [192.168.1.1] ([68.11.66.83]) by lakemtao03.cox.net + (InterMail vM.5.01.04.05 201-253-122-122-105-20011231) with ESMTP + id <20030506193322.RTKS23518.lakemtao03.cox.net@[192.168.1.1]> + for ; + Tue, 6 May 2003 15:33:22 -0400 +Subject: Re: Looking for a cheap upgrade (RAID) +From: Ron Johnson +To: PgSQL Performance ML +In-Reply-To: +References: +Content-Type: text/plain +Organization: +Message-Id: <1052249594.3371.405.camel@haggis> +Mime-Version: 1.0 +X-Mailer: Ximian Evolution 1.2.4 +Date: 06 May 2003 14:33:15 -0500 +Content-Transfer-Encoding: 7bit +X-Spam-Status: No, hits=-44.3 required=5.0 + tests=BAYES_10,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REFERENCES,REPLY_WITH_QUOTES,SIGNATURE_LONG_DENSE, + USER_AGENT_XIMIAN autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/70 +X-Sequence-Number: 1849 + +On Tue, 2003-05-06 at 13:12, scott.marlowe wrote: +> On 6 May 2003, Ron Johnson wrote: +> +> > On Mon, 2003-05-05 at 17:22, scott.marlowe wrote: +> > > On 5 May 2003, Ron Johnson wrote: +> > > +> > > > On Mon, 2003-05-05 at 11:31, scott.marlowe wrote: +> > > > > On 3 May 2003, Ron Johnson wrote: +> > > > > +> > > > > > On Fri, 2003-05-02 at 13:53, Chad Thompson wrote: +> > [snip] +> > > > What controller do you use for IDE hot-swapping and auto-rebuild? +> > > > 3Ware? +> > > +> > > Linux, and I don't do hot swapping with IDE, just hot rebuild from a +> > > spare drive. My servers are running SCSI, by the way, only the +> > > workstations are running IDE. With the saved cost of a decent RAID +> > > controller (good SCSI controllers are still well over $500 most the time) +> > > I can afford enough hot spares to never have to worry about changing one +> > > out during the day. +> > +> > Ah, I guess that drives go out infrequently enough that shutting +> > it down at night for a swap-out isn't all that onerous... +> > +> > What controller model do you use? +> +> My preference is SymBIOS (LSI now) plain UW SCSI 160, but at work we use +> adaptec built in UW SCSI 160 on INTEL dual CPU motherboards. I've used +> RAID controllers in the past, but now I genuinely prefer linux's built in +> kernel level raid to most controllers, and the load on the server is <2% +> of one of the two CPUs, so it doesn't really slow anything else down. The +> performance is quite good, I can read raw at about 48 Megs a second from a +> pair of 10kRPM UWSCSI drives in a RAID1. These drives, individually can +> pump out about 25 megs a second individually. + +Hmm, I'm confused (again)... + +I thought you liked IDE RAID, because of the price savings. + +-- ++---------------------------------------------------------------+ +| Ron Johnson, Jr. mailto:ron.l.johnson@cox.net | +| Jefferson, LA USA http://members.cox.net/ron.l.johnson | +| | +| The purpose of the military isn't to pay your college tuition | +| or give you a little extra income; it's to "kill people and | +| break things". Surprisingly, not everyone understands that. | ++---------------------------------------------------------------+ + + +From pgsql-performance-owner@postgresql.org Tue May 6 16:52:47 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 65EB347580B + for ; + Tue, 6 May 2003 16:52:44 -0400 (EDT) +Received: from mail1.ihs.com (mail1.ihs.com [170.207.70.222]) + by postgresql.org (Postfix) with ESMTP id 1007C474E42 + for ; + Tue, 6 May 2003 16:52:40 -0400 (EDT) +Received: from css120.ihs.com (css120.ihs.com [170.207.105.120]) + by mail1.ihs.com (8.12.9/8.12.9) with ESMTP id h46KnToK015227; + Tue, 6 May 2003 14:49:29 -0600 (MDT) +Date: Tue, 6 May 2003 14:40:04 -0600 (MDT) +From: "scott.marlowe" +To: Ron Johnson +Cc: PgSQL Performance ML +Subject: Re: Looking for a cheap upgrade (RAID) +In-Reply-To: <1052249594.3371.405.camel@haggis> +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-MailScanner: Found to be clean +X-MailScanner-SpamCheck: +X-Spam-Status: No, hits=-31.7 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REPLY_WITH_QUOTES,USER_AGENT_PINE autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/71 +X-Sequence-Number: 1850 + +On 6 May 2003, Ron Johnson wrote: + +> On Tue, 2003-05-06 at 13:12, scott.marlowe wrote: +> > On 6 May 2003, Ron Johnson wrote: +> > +> > > On Mon, 2003-05-05 at 17:22, scott.marlowe wrote: +> > > > On 5 May 2003, Ron Johnson wrote: +> > > > +> > > > > On Mon, 2003-05-05 at 11:31, scott.marlowe wrote: +> > > > > > On 3 May 2003, Ron Johnson wrote: +> > > > > > +> > > > > > > On Fri, 2003-05-02 at 13:53, Chad Thompson wrote: +> > > [snip] +> > > > > What controller do you use for IDE hot-swapping and auto-rebuild? +> > > > > 3Ware? +> > > > +> > > > Linux, and I don't do hot swapping with IDE, just hot rebuild from a +> > > > spare drive. My servers are running SCSI, by the way, only the +> > > > workstations are running IDE. With the saved cost of a decent RAID +> > > > controller (good SCSI controllers are still well over $500 most the time) +> > > > I can afford enough hot spares to never have to worry about changing one +> > > > out during the day. +> > > +> > > Ah, I guess that drives go out infrequently enough that shutting +> > > it down at night for a swap-out isn't all that onerous... +> > > +> > > What controller model do you use? +> > +> > My preference is SymBIOS (LSI now) plain UW SCSI 160, but at work we use +> > adaptec built in UW SCSI 160 on INTEL dual CPU motherboards. I've used +> > RAID controllers in the past, but now I genuinely prefer linux's built in +> > kernel level raid to most controllers, and the load on the server is <2% +> > of one of the two CPUs, so it doesn't really slow anything else down. The +> > performance is quite good, I can read raw at about 48 Megs a second from a +> > pair of 10kRPM UWSCSI drives in a RAID1. These drives, individually can +> > pump out about 25 megs a second individually. +> +> Hmm, I'm confused (again)... +> +> I thought you liked IDE RAID, because of the price savings. + +No, I was saying that software RAID is what I like. IDE or SCSI. I just +use SCSI because it's on a server that happens to have come with some nice +UW SCSI Drives. The discussion about the IDE RAID was about what +someone else was using. I was just defending the use of it, as it is +still a great value for RAID arrays, and let's face it, the slowest IDE +RAID you can build with new parts is probably still faster than the +fastest SCSI RAID arrays from less than a decade ago. Now with Serial ATA +coming out, I expect a lot more servers to use it, and it looks like the +drives made for serial ATA will come in server class versions (tested for +longer life, greater heat resistance, etc...) + +On my little 2xPPro200 I have 6 2 gig UltraWide 80 MB/sec SCSI drives, and +2 80 gig DMA-33 drives, and the two 80 gig DMA-33 drives literally stomp +the 6 2 gigs into the ground, no matter how I configure it, except at +heavy parallel access (i.e. pgbench -c 20 -t 1000) where the extra +spindle/head count makes a big difference. And even then, the SCSIs are +only a tiny bit faster, say 10% or so. + + +From pgsql-hackers-owner@postgresql.org Wed May 7 01:08:08 2003 +X-Original-To: pgsql-hackers@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 9FBAC47637A + for ; + Wed, 7 May 2003 01:08:03 -0400 (EDT) +Received: from flake.decibel.org (unknown [66.143.173.58]) + by postgresql.org (Postfix) with SMTP id DEA57476363 + for ; + Wed, 7 May 2003 01:08:01 -0400 (EDT) +Received: (qmail 34648 invoked by uid 1001); 7 May 2003 05:08:01 -0000 +Date: Wed, 7 May 2003 00:08:01 -0500 +From: "Jim C. Nasby" +To: Tom Lane +Cc: Josh Berkus , + pgsql-performance , + pgsql-hackers@postgresql.org +Subject: Re: [PERFORM] Hypothetical suggestions for planner, + indexing improvement +Message-ID: <20030507000801.E66185@flake.decibel.org> +Reply-To: jim@nasby.net +References: <200305051219.58955.josh@agliodbs.com> + <22292.1052195133@sss.pgh.pa.us> + <200305052133.33680.josh@agliodbs.com> + <20030506080747.C66185@flake.decibel.org> + <24779.1052228707@sss.pgh.pa.us> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +User-Agent: Mutt/1.2.5.1i +In-Reply-To: <24779.1052228707@sss.pgh.pa.us>; + from tgl@sss.pgh.pa.us on Tue, May 06, 2003 at 09:45:07AM -0400 +X-Operating-System: FreeBSD 4.8-RELEASE i386 +X-Distributed: Join the Effort! http://www.distributed.net +X-Spam-Status: No, hits=-40.0 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + QUOTE_TWICE_1,REFERENCES,REPLY_WITH_QUOTES, + SIGNATURE_SHORT_SPARSE,USER_AGENT_MUTT + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/139 +X-Sequence-Number: 38646 + +On Tue, May 06, 2003 at 09:45:07AM -0400, Tom Lane wrote: +> "Jim C. Nasby" writes: +> > It would be nice to add support for multi-column IN.. +> > WHERE (a, b, c) IN (SELECT a, b, c ...) +> +> RTFM... + +As someone pointed out, the documentation says you can't. In this case +the docs are wrong (I've added a note). + +> > BTW, does postgresql handle IN and EXISTS differently? +> +> Yes. +> +> > Theoretically if the optimizer was good enough you could transform one +> > to the other and not worry about it. +> +> No. They have different responses to NULLs in the subselect result. + +They appear to operate the same... what's different? +-- +Jim C. Nasby (aka Decibel!) jim@nasby.net +Member: Triangle Fraternity, Sports Car Club of America +Give your computer some brain candy! www.distributed.net Team #1828 + +Windows: "Where do you want to go today?" +Linux: "Where do you want to go tomorrow?" +FreeBSD: "Are you guys coming, or what?" + + +From pgsql-hackers-owner@postgresql.org Wed May 7 01:20:41 2003 +X-Original-To: pgsql-hackers@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP + id 35027476315; Wed, 7 May 2003 01:20:41 -0400 (EDT) +Received: from sss.pgh.pa.us (unknown [192.204.191.242]) + by postgresql.org (Postfix) with ESMTP + id EA6A5476178; Wed, 7 May 2003 01:20:39 -0400 (EDT) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h475KaU6025001; + Wed, 7 May 2003 01:20:36 -0400 (EDT) +To: jim@nasby.net +Cc: Josh Berkus , + pgsql-performance , + pgsql-hackers@postgresql.org +Subject: Re: [PERFORM] Hypothetical suggestions for planner, + indexing improvement +In-reply-to: <20030507000801.E66185@flake.decibel.org> +References: <200305051219.58955.josh@agliodbs.com> + <22292.1052195133@sss.pgh.pa.us> + <200305052133.33680.josh@agliodbs.com> + <20030506080747.C66185@flake.decibel.org> + <24779.1052228707@sss.pgh.pa.us> + <20030507000801.E66185@flake.decibel.org> +Comments: In-reply-to "Jim C. Nasby" + message dated "Wed, 07 May 2003 00:08:01 -0500" +Date: Wed, 07 May 2003 01:20:36 -0400 +Message-ID: <25000.1052284836@sss.pgh.pa.us> +From: Tom Lane +X-Spam-Status: No, hits=-32.3 required=5.0 + tests=BAYES_00,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REFERENCES,REPLY_WITH_QUOTES autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/140 +X-Sequence-Number: 38647 + +"Jim C. Nasby" writes: +> On Tue, May 06, 2003 at 09:45:07AM -0400, Tom Lane wrote: +>> RTFM... + +> As someone pointed out, the documentation says you can't. In this case +> the docs are wrong (I've added a note). + +Perhaps you should have read to the end of the section. + +>>> BTW, does postgresql handle IN and EXISTS differently? +>> +>> Yes. +> +> They appear to operate the same... what's different? + +Supposing that tab1.col1 contains 1, NULL, 2, then for an outer +table row where col2 = 42 + + WHERE outer.col2 IN (SELECT col1 FROM tab1) + +will yield NULL (not FALSE). But + + WHERE EXISTS(SELECT * FROM tab1 WHERE col1 = outer.col2) + +will yield FALSE (not NULL). + +The distinction doesn't matter at the top level of WHERE, but it +matters a lot underneath a NOT ... + + regards, tom lane + + +From pgsql-hackers-owner@postgresql.org Wed May 7 03:37:10 2003 +X-Original-To: pgsql-hackers@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP + id D45B5476141; Wed, 7 May 2003 03:37:03 -0400 (EDT) +Received: from zigo.dhs.org (as2-4-3.an.g.bonet.se [194.236.34.191]) + by postgresql.org (Postfix) with ESMTP + id 6BC3E475CE5; Wed, 7 May 2003 03:37:02 -0400 (EDT) +Received: from localhost (db@localhost) + by zigo.dhs.org (8.11.6/8.11.6) with ESMTP id h477aqg02384; + Wed, 7 May 2003 09:36:52 +0200 +Date: Wed, 7 May 2003 09:36:52 +0200 (CEST) +From: =?ISO-8859-1?Q?Dennis_Bj=F6rklund?= +To: Tom Lane +Cc: jim@nasby.net, Josh Berkus , + pgsql-performance , + +Subject: Re: [PERFORM] Hypothetical suggestions for planner, indexing +In-Reply-To: <25000.1052284836@sss.pgh.pa.us> +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-Spam-Status: No, hits=-32.3 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + QUOTE_TWICE_1,REPLY_WITH_QUOTES,USER_AGENT_PINE + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/142 +X-Sequence-Number: 38649 + +On Wed, 7 May 2003, Tom Lane wrote: + +> > As someone pointed out, the documentation says you can't. In this case +> > the docs are wrong (I've added a note). +> +> Perhaps you should have read to the end of the section. + +Oh, you are right (of course). It is documented later on in that section. + +I guess it's specified in the SQL spec, but how come a tuple is not an +expression? If it had been an expression the first part of that section +would still apply, which is why I just read the first part. + +-- +/Dennis + + +From pgsql-hackers-owner@postgresql.org Wed May 7 09:36:45 2003 +X-Original-To: pgsql-hackers@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 33A3C474E4F + for ; + Wed, 7 May 2003 09:36:43 -0400 (EDT) +Received: from flake.decibel.org (unknown [66.143.173.58]) + by postgresql.org (Postfix) with SMTP id 97F8D475D0F + for ; + Wed, 7 May 2003 09:36:13 -0400 (EDT) +Received: (qmail 42421 invoked by uid 1001); 7 May 2003 13:36:17 -0000 +Date: Wed, 7 May 2003 08:36:16 -0500 +From: "Jim C. Nasby" +To: Tom Lane +Cc: Josh Berkus , + pgsql-performance , + pgsql-hackers@postgresql.org +Subject: Re: [PERFORM] Hypothetical suggestions for planner, + indexing improvement +Message-ID: <20030507083616.F66185@flake.decibel.org> +Reply-To: jim@nasby.net +References: <200305051219.58955.josh@agliodbs.com> + <22292.1052195133@sss.pgh.pa.us> + <200305052133.33680.josh@agliodbs.com> + <20030506080747.C66185@flake.decibel.org> + <24779.1052228707@sss.pgh.pa.us> + <20030507000801.E66185@flake.decibel.org> + <25000.1052284836@sss.pgh.pa.us> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +User-Agent: Mutt/1.2.5.1i +In-Reply-To: <25000.1052284836@sss.pgh.pa.us>; + from tgl@sss.pgh.pa.us on Wed, May 07, 2003 at 01:20:36AM -0400 +X-Operating-System: FreeBSD 4.8-RELEASE i386 +X-Distributed: Join the Effort! http://www.distributed.net +X-Spam-Status: No, hits=-32.9 required=5.0 + tests=BAYES_01,IN_REP_TO,QUOTED_EMAIL_TEXT,REFERENCES, + REPLY_WITH_QUOTES,SIGNATURE_SHORT_SPARSE,USER_AGENT_MUTT + version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/144 +X-Sequence-Number: 38651 + +> Supposing that tab1.col1 contains 1, NULL, 2, then for an outer +> table row where col2 = 42 +> +> WHERE outer.col2 IN (SELECT col1 FROM tab1) +> +> will yield NULL (not FALSE). But +> +> WHERE EXISTS(SELECT * FROM tab1 WHERE col1 = outer.col2) +> +> will yield FALSE (not NULL). +> +> The distinction doesn't matter at the top level of WHERE, but it +> matters a lot underneath a NOT ... + +OK, but even if a true transform can't be done, couldn't they share the +same set of code to fetch the data for the subquery? Going back to my +original post, I tend to use IN only in cases where I think the subquery +will return a small result-set, and use EXISTS elsewhere. Presumably, +the subquery for an IN will only be run once, while EXISTS will be run +as an inner-loop (I'm guessing here, I could be wrong). It might be +useful if the subquery was executed based on how many rows it +would/might return. +-- +Jim C. Nasby (aka Decibel!) jim@nasby.net +Member: Triangle Fraternity, Sports Car Club of America +Give your computer some brain candy! www.distributed.net Team #1828 + +Windows: "Where do you want to go today?" +Linux: "Where do you want to go tomorrow?" +FreeBSD: "Are you guys coming, or what?" + + +From pgsql-performance-owner@postgresql.org Wed May 7 09:40:56 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP + id 8A871476334; Wed, 7 May 2003 09:40:54 -0400 (EDT) +Received: from fuji.krosing.net (sein.itera.ee [194.126.109.126]) + by postgresql.org (Postfix) with ESMTP + id 1DC32475EDF; Wed, 7 May 2003 09:40:26 -0400 (EDT) +Received: from fuji.krosing.net (lo [127.0.0.1]) + by fuji.krosing.net (8.12.8/8.12.8) with ESMTP id h47DeErK002547; + Wed, 7 May 2003 16:40:14 +0300 +Received: (from hannu@localhost) + by fuji.krosing.net (8.12.8/8.12.8/Submit) id h47De6Qk002544; + Wed, 7 May 2003 16:40:06 +0300 +X-Authentication-Warning: fuji.krosing.net: hannu set sender to hannu@tm.ee + using -f +Subject: Re: An unresolved performance problem. +From: Hannu Krosing +To: Achilleus Mantzios +Cc: pgsql-sql@postgresql.org, pgsql-performance@postgresql.org, + pgsql-bugs@postgresql.org +In-Reply-To: +References: +Content-Type: text/plain +Content-Transfer-Encoding: 7bit +Organization: +Message-Id: <1052314806.2205.6.camel@fuji.krosing.net> +Mime-Version: 1.0 +X-Mailer: Ximian Evolution 1.2.4 +Date: 07 May 2003 16:40:06 +0300 +X-Spam-Status: No, hits=-33.7 required=5.0 + tests=BAYES_01,IN_REP_TO,QUOTED_EMAIL_TEXT,REFERENCES, + REPLY_WITH_QUOTES,USER_AGENT_XIMIAN,X_AUTH_WARNING + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/77 +X-Sequence-Number: 1856 + +Achilleus Mantzios kirjutas K, 07.05.2003 kell 19:33: +> Hi, few days ago, i posted some really wierd (at least to me) +> situation (maybe a potentian bug) to the performance and bugs list +> and to some core hacker(s) privately as well, +> and i got no response. +> Moreover i asked for some feedback +> in order to understand/fix the problem myself, +> and again received no response. +> +> What i asked was pretty simple: +> "1. Is it possible that the absense of statistics make the planer produce +> better plans than in the case of statistcs generated with vacuum +> analyze/analyze? + +Yes, the planner is not perfect, the statistics are just statistics +(based on a random sample), etc.. + +This question comes up at least once a month on either [PERFORM] or +[HACKERS], search the mailing lists to get more thorough +discussion/explanation. + +> 2. If No, i found a bug, + +Rather a feature ;-p + +> 3. If yes then under what conditions?? + +if + +1) ANALYZE produced skewed data which was worse than default. + +or. + +2) some costs are way off for your system (try changing them in +postgresql.conf) + +> 4. If no person knows the answer or no hacker wants to dig into the +> problem then is there a direction i must follow to understand/fix whats +> going on myself??"" + +You can sturt by enabling/disabling various scan methods + +psqldb# set enable_seqscan to off; +SET + + +and see what happens, then adjust the weights in postgresql.conf or use +some combination of SETs around critical queries to force the plan you +like. + + +------------ +Hannu + + +From pgsql-performance-owner@postgresql.org Wed May 7 12:07:31 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id ABF7B4763CE + for ; + Wed, 7 May 2003 12:07:27 -0400 (EDT) +Received: from t-9.net (unknown [64.246.36.43]) + by postgresql.org (Postfix) with SMTP id E6CD64764FB + for ; + Wed, 7 May 2003 12:07:21 -0400 (EDT) +Received: (qmail 5479 invoked by uid 0); 7 May 2003 14:11:49 -0000 +Received: from localhost (HELO seahat.com) (127.0.0.1) + by localhost with SMTP; 7 May 2003 14:11:49 -0000 +Received: from 65.102.128.233 + (SquirrelMail authenticated user snubber@seahat.com) + by fordparts.com with HTTP; Wed, 7 May 2003 09:11:49 -0500 (CDT) +Message-ID: <11207.65.102.128.233.1052316709.squirrel@fordparts.com> +Date: Wed, 7 May 2003 09:11:49 -0500 (CDT) +Subject: Yet another 'why does it not use my index' question. +From: "Ryan" +To: +X-Priority: 3 +Importance: Normal +X-Mailer: SquirrelMail (version 1.2.8) +MIME-Version: 1.0 +Content-Type: text/plain; charset=iso-8859-1 +Content-Transfer-Encoding: quoted-printable +X-Spam-Status: No, hits=-5.7 required=5.0 tests=BAYES_01,MSG_ID_ADDED_BY_MTA_3 + version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/83 +X-Sequence-Number: 1862 + +Ok, I have two tables (Postgresql 7.3.2 on Debian): + + Table "public.zip" + Column | Type | Modifiers +------------+-----------------------+----------- + zip | character varying(5) | + city | character varying(25) | + county | character varying(30) | + countyfips | character varying(5) | + state_full | character varying(30) | + state | character varying(2) | + citytype | character(1) | + zipcodetyp | character(1) | + areacode | character varying(3) | + timezone | character varying(10) | + dst | character(1) | + latitude | double precision | + longitude | double precision | + country | character varying(10) | +Indexes: zip_idx btree (zip) + + Table "public.client_options" + Column | Type | Modifiers +--------------+--------+----------- + client_id | bigint | not null + option_name | text | not null + option_value | text | not null +Foreign Key constraints: [...omitted...] + +I wanted to do the following: + +midas=3D# explain analyze select * from zip where zip in + (select option_value from client_options where option_name =3D 'ZIP_CODE' = +); + QUERY PLAN +--------------------------------------------------------------------------- + Seq Scan on zip (cost=3D0.00..206467.85 rows=3D38028 width=3D112) + (actual time=3D58.45..4676.76 rows=3D8 loops=3D1) + Filter: (subplan) + SubPlan + -> Seq Scan on client_options (cost=3D0.00..5.36 rows=3D3 width=3D14) + (actual time=3D0.02..0.05 rows=3D3 loops=3D= +76056) + Filter: (option_name =3D 'ZIP_CODE'::text) + Total runtime: 4676.87 msec + +Or even: + +midas=3D# explain analyze select * from zip z, client_options c where +c.option_name =3D 'ZIP_CODE' and c.option_value =3D z.zip; + QUERY PLAN +--------------------------------------------------------------------------- + Nested Loop (cost=3D0.00..9915.14 rows=3D10 width=3D148) + (actual time=3D26.63..2864.01 rows=3D8 loops=3D1) + Join Filter: ("outer".option_value =3D ("inner".zip)::text) + -> Seq Scan on client_options c (cost=3D0.00..5.36 rows=3D3 width=3D36) + (actual time=3D0.25..0.34 rows=3D3 loop= +s=3D1) + Filter: (option_name =3D 'ZIP_CODE'::text) + -> Seq Scan on zip z (cost=3D0.00..2352.56 rows=3D76056 width=3D112) + (actual time=3D0.07..809.19 rows=3D76056 loops=3D= +3) + Total runtime: 2864.16 msec + + +If I wanted to do select the zip codes out of the client_options and then +select the zipcodes seperately, I would be looking at times of .14 msec +and 222.82 msec respectively. + +Oh, and yes, I have done a vacuum analyze. + +(the reason I'm trying to join these tables is to get longitude and +latitude coordinates to use with the earthdistance <@> operator, it just +takes entirely too long) + +What am I doing wrong? + +Ryan + + +From pgsql-hackers-owner@postgresql.org Wed May 7 10:19:32 2003 +X-Original-To: pgsql-hackers@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 91EF4475D3B + for ; + Wed, 7 May 2003 10:19:30 -0400 (EDT) +Received: from sss.pgh.pa.us (unknown [192.204.191.242]) + by postgresql.org (Postfix) with ESMTP id C1D55475CE5 + for ; + Wed, 7 May 2003 10:19:28 -0400 (EDT) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h47EJPU6026875; + Wed, 7 May 2003 10:19:26 -0400 (EDT) +To: =?ISO-8859-1?Q?Dennis_Bj=F6rklund?= +Cc: jim@nasby.net, Josh Berkus , + pgsql-performance , + pgsql-hackers@postgresql.org +Subject: Re: [PERFORM] Hypothetical suggestions for planner, indexing +In-reply-to: +References: +Comments: In-reply-to =?ISO-8859-1?Q?Dennis_Bj=F6rklund?= + message dated "Wed, 07 May 2003 09:36:52 +0200" +Date: Wed, 07 May 2003 10:19:25 -0400 +Message-ID: <26874.1052317165@sss.pgh.pa.us> +From: Tom Lane +X-Spam-Status: No, hits=-26.0 required=5.0 + tests=BAYES_01,IN_REP_TO,QUOTED_EMAIL_TEXT,REFERENCES, + REPLY_WITH_QUOTES version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/147 +X-Sequence-Number: 38654 + +=?ISO-8859-1?Q?Dennis_Bj=F6rklund?= writes: +> I guess it's specified in the SQL spec, but how come a tuple is not an +> expression? If it had been an expression the first part of that section +> would still apply, which is why I just read the first part. + +Well, if you want to think of "(42, 'foo')" as being an expression then +I suppose it could be considered to be all one syntax. Personally I +think that'd be more confusing rather than less so. + +Another alternative is to put both syntax summaries at the top of the +subsection, and combine the two textual descriptions into one. + +This is the wrong place for this discussion, though. If you want to +have a go at rewriting the section, why not put up a sketch on +pgsql-docs and see if people like it? + + regards, tom lane + + +From pgsql-performance-owner@postgresql.org Wed May 7 12:39:14 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id F20004763CE + for ; + Wed, 7 May 2003 12:39:11 -0400 (EDT) +Received: from t-9.net (unknown [64.246.36.43]) + by postgresql.org (Postfix) with SMTP id F154C476501 + for ; + Wed, 7 May 2003 12:38:59 -0400 (EDT) +Received: (qmail 16334 invoked by uid 0); 7 May 2003 14:43:28 -0000 +Received: from localhost (HELO seahat.com) (127.0.0.1) + by localhost with SMTP; 7 May 2003 14:43:28 -0000 +Received: from 65.102.128.233 + (SquirrelMail authenticated user snubber@seahat.com) + by fordparts.com with HTTP; Wed, 7 May 2003 09:43:28 -0500 (CDT) +Message-ID: <10192.65.102.128.233.1052318608.squirrel@fordparts.com> +Date: Wed, 7 May 2003 09:43:28 -0500 (CDT) +Subject: Re: Yet another 'why does it not use my index' question. +From: "Ryan" +To: +In-Reply-To: <20030507162815.GA27158@wolff.to> +References: <11207.65.102.128.233.1052316709.squirrel@fordparts.com> + <20030507162815.GA27158@wolff.to> +X-Priority: 3 +Importance: Normal +Cc: +X-Mailer: SquirrelMail (version 1.2.8) +MIME-Version: 1.0 +Content-Type: text/plain; charset=iso-8859-1 +Content-Transfer-Encoding: quoted-printable +X-Spam-Status: No, hits=-25.1 required=5.0 + tests=BAYES_01,IN_REP_TO,MSG_ID_ADDED_BY_MTA_3,QUOTED_EMAIL_TEXT, + REFERENCES,REPLY_WITH_QUOTES autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/85 +X-Sequence-Number: 1864 + +> On Wed, May 07, 2003 at 09:11:49 -0500, +> Ryan wrote: +>> I wanted to do the following: +>> +>> midas=3D# explain analyze select * from zip where zip in +>> (select option_value from client_options where option_name =3D +>> 'ZIP_CODE' ); +> +> Until 7.4 comes out IN will be slow and you should use a join to do +> this. +> +>> midas=3D# explain analyze select * from zip z, client_options c where +>> c.option_name =3D 'ZIP_CODE' and c.option_value =3D z.zip; +> +> I think the problem here might be related to option_value being text and +> zip being char varying. This might prevent an index from being used to +> do the join. +HMMMM. I'll have to re-insert that table (it was a dbf2pg job) and change +that. Any reason why postgres is so picky about varchar/text conversion, +considering they are practally the same thing? + +Something intresting however. If I do this: +select * from zip where zip =3D 98404; +I get a seq scan, as postgres types it to text. + +but if I do this: +select * from zip where zip =3D '98404'; +Postgres types it as character varying and uses the index. + +Not that it would happen any time soon, but it would be nice if explain +analyze would tell you why it chose an seq scan on an indexed field. +(e.g. You should know better than to try an index with a different type!) + +Ryan + + +From pgsql-performance-owner@postgresql.org Wed May 7 11:27:35 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 7F4E847648D + for ; + Wed, 7 May 2003 11:27:28 -0400 (EDT) +Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) + by postgresql.org (Postfix) with ESMTP id 60089475CE5 + for ; + Wed, 7 May 2003 11:26:59 -0400 (EDT) +Received: from [63.195.55.98] (HELO spooky) + by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) + with ESMTP id 3014883; Wed, 07 May 2003 08:27:04 -0700 +Content-Type: text/plain; + charset="iso-8859-1" +From: Josh Berkus +Organization: Aglio Database Solutions +To: Achilleus Mantzios , + Hannu Krosing +Subject: Re: An unresolved performance problem. +Date: Wed, 7 May 2003 08:26:52 -0700 +User-Agent: KMail/1.4.3 +Cc: pgsql-performance@postgresql.org +References: +In-Reply-To: +MIME-Version: 1.0 +Message-Id: <200305070826.52382.josh@agliodbs.com> +Content-Transfer-Encoding: quoted-printable +X-Spam-Status: No, hits=-32.4 required=5.0 + tests=BAYES_01,IN_REP_TO,QUOTED_EMAIL_TEXT,REFERENCES, + REPLY_WITH_QUOTES,USER_AGENT_KMAIL autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/80 +X-Sequence-Number: 1859 + +Achilleus, + +> My systems are (rather usual) linux/freebsd and the costs defined (by +> default) in postgresql.conf worked well for all queries except +> a cursed query on a cursed table. +> So i start to believe its an estimation selectivity +> problem. + +We can probably fix the problem by re-writing the query then; see my previ= +ous=20 +example this weekend about overdetermining criteria in order to force the u= +se=20 +of an index. + +How about posting the query and the EXPLAIN ANALYZE results? + +--=20 +Josh Berkus +Aglio Database Solutions +San Francisco + + +From pgsql-bugs-owner@postgresql.org Wed May 7 11:37:03 2003 +X-Original-To: pgsql-bugs@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP + id 928D4475B8E; Wed, 7 May 2003 11:37:01 -0400 (EDT) +Received: from pns.mm.eutelsat.org (pns.mm.eutelsat.org [194.214.173.227]) + by postgresql.org (Postfix) with ESMTP + id C89E4476141; Wed, 7 May 2003 11:36:32 -0400 (EDT) +Received: from nts-03.mm.eutelsat.org (localhost [127.0.0.1]) + by pns.mm.eutelsat.org (8.11.6/linuxconf) with ESMTP id h47EbUi04881; + Wed, 7 May 2003 16:37:30 +0200 +Received: from GMENDOLA2 (gmendola2.mm.eutelsat.org [194.214.173.26]) + by nts-03.mm.eutelsat.org (8.11.6/linuxconf) with SMTP id h47FY6R32321; + Wed, 7 May 2003 17:34:06 +0200 +Message-ID: <013301c314ae$6e1b6520$152aa8c0@GMENDOLA2> +From: "Mendola Gaetano" +To: "Achilleus Mantzios" , + , , + +References: +Subject: Re: [SQL] An unresolved performance problem. +Date: Wed, 7 May 2003 17:36:29 +0200 +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit +X-Priority: 3 +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook Express 6.00.2800.1158 +x-mimeole: Produced By Microsoft MimeOLE V6.00.2800.1165 +X-Spam-Status: No, hits=-16.1 required=5.0 + tests=BAYES_10,QUOTED_EMAIL_TEXT,QUOTE_TWICE_1,REFERENCES + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/20 +X-Sequence-Number: 5981 + +----- Original Message ----- +From: "Achilleus Mantzios" +To: ; ; + +Sent: Wednesday, May 07, 2003 6:33 PM +Subject: [SQL] An unresolved performance problem. + + +> +> Hi, few days ago, i posted some really wierd (at least to me) +> situation (maybe a potentian bug) to the performance and bugs list +> and to some core hacker(s) privately as well, +> and i got no response. + +I seen around a lot of questions are remaining without any reply, +may be in this period the guys like Tom Lane are too busy. + +> Moreover i asked for some feedback +> in order to understand/fix the problem myself, +> and again received no response. +> +> What i asked was pretty simple: +> "1. Is it possible that the absense of statistics make the planer produce +> better plans +> than in the case of statistcs generated with vacuum +> analyze/analyze? +> 2. If No, i found a bug, +> 3. If yes then under what conditions?? +> 4. If no person knows the answer or no hacker wants to dig into the +> problem then is there a direction i must follow to understand/fix whats +> going on myself??"" + +Can you give us more informations? Like the table structure, wich kind +of query are you tring to do and so on... + + +Gaetano + + +From pgsql-performance-owner@postgresql.org Wed May 7 11:54:09 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id EA08C47635A + for ; + Wed, 7 May 2003 11:54:03 -0400 (EDT) +Received: from mail1.ihs.com (mail1.ihs.com [170.207.70.222]) + by postgresql.org (Postfix) with ESMTP id C160F4764A7 + for ; + Wed, 7 May 2003 11:53:35 -0400 (EDT) +Received: from css120.ihs.com (css120.ihs.com [170.207.105.120]) + by mail1.ihs.com (8.12.9/8.12.9) with ESMTP id h47Fpw5g001137; + Wed, 7 May 2003 09:51:58 -0600 (MDT) +Date: Wed, 7 May 2003 09:42:27 -0600 (MDT) +From: "scott.marlowe" +To: Achilleus Mantzios +Cc: +Subject: Re: An unresolved performance problem. +In-Reply-To: +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-MailScanner: Found to be clean +X-MailScanner-SpamCheck: +X-Spam-Status: No, hits=-32.3 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + QUOTE_TWICE_1,REPLY_WITH_QUOTES,USER_AGENT_PINE + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/82 +X-Sequence-Number: 1861 + +On Wed, 7 May 2003, Achilleus Mantzios wrote: + +> +> Hi, few days ago, i posted some really wierd (at least to me) +> situation (maybe a potentian bug) to the performance and bugs list +> and to some core hacker(s) privately as well, +> and i got no response. +> Moreover i asked for some feedback +> in order to understand/fix the problem myself, +> and again received no response. +> +> What i asked was pretty simple: +> "1. Is it possible that the absense of statistics make the planer produce +> better plans +> than in the case of statistcs generated with vacuum +> analyze/analyze? + +One of the common examples of this happening was posted a few weeks back. +someone was basically doing this: + +delete from table; +analyze table; +insert into table (1,000,000 times); + +the problem was that the table had fk constraints to another table, and +the query planner for the inserts (all 1,000,000 of them) assumed it was +inserting into a mostly empty table, and therefore used seq scans instead +of index scans. + +It's not a bug, not quite a feature, just a corner case. + + +From pgsql-performance-owner@postgresql.org Wed May 7 12:27:03 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 72F63476341 + for ; + Wed, 7 May 2003 12:27:01 -0400 (EDT) +Received: from wolff.to (wolff.to [66.93.249.74]) + by postgresql.org (Postfix) with SMTP id B14DE475EF0 + for ; + Wed, 7 May 2003 12:26:59 -0400 (EDT) +Received: (qmail 27303 invoked by uid 500); 7 May 2003 16:28:15 -0000 +Date: Wed, 7 May 2003 11:28:15 -0500 +From: Bruno Wolff III +To: Ryan +Cc: pgsql-performance@postgresql.org +Subject: Re: Yet another 'why does it not use my index' question. +Message-ID: <20030507162815.GA27158@wolff.to> +Mail-Followup-To: Ryan , + pgsql-performance@postgresql.org +References: <11207.65.102.128.233.1052316709.squirrel@fordparts.com> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: <11207.65.102.128.233.1052316709.squirrel@fordparts.com> +User-Agent: Mutt/1.5.4i +X-Spam-Status: No, hits=-38.0 required=5.0 + tests=BAYES_10,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REFERENCES,REPLY_WITH_QUOTES,USER_AGENT_MUTT + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/84 +X-Sequence-Number: 1863 + +On Wed, May 07, 2003 at 09:11:49 -0500, + Ryan wrote: +> I wanted to do the following: +> +> midas=# explain analyze select * from zip where zip in +> (select option_value from client_options where option_name = 'ZIP_CODE' ); + +Until 7.4 comes out IN will be slow and you should use a join to do this. + +> midas=# explain analyze select * from zip z, client_options c where +> c.option_name = 'ZIP_CODE' and c.option_value = z.zip; + +I think the problem here might be related to option_value being text +and zip being char varying. This might prevent an index from being used +to do the join. + + +From pgsql-bugs-owner@postgresql.org Wed May 7 07:29:03 2003 +X-Original-To: pgsql-bugs@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP + id 47A1D4763CD; Wed, 7 May 2003 07:29:02 -0400 (EDT) +Received: from matrix.gatewaynet.com (unknown [217.19.69.50]) + by postgresql.org (Postfix) with ESMTP + id EBE14475AE5; Wed, 7 May 2003 07:28:57 -0400 (EDT) +Received: from matrix.gatewaynet.com (localhost [127.0.0.1]) + by matrix.gatewaynet.com (8.12.5/8.12.5) with ESMTP id h47GXP1s028216; + Wed, 7 May 2003 14:33:25 -0200 +Received: from localhost (achill@localhost) + by matrix.gatewaynet.com (8.12.5/8.12.5/Submit) with ESMTP id + h47GXOxQ028212; Wed, 7 May 2003 14:33:25 -0200 +Date: Wed, 7 May 2003 14:33:24 -0200 (GMT+2) +From: Achilleus Mantzios +To: pgsql-sql@postgresql.org, , + +Subject: An unresolved performance problem. +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-Spam-Status: No, hits=-17.8 required=5.0 + tests=BAYES_10,SIGNATURE_LONG_DENSE,USER_AGENT_PINE + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/18 +X-Sequence-Number: 5979 + + +Hi, few days ago, i posted some really wierd (at least to me) +situation (maybe a potentian bug) to the performance and bugs list +and to some core hacker(s) privately as well, +and i got no response. +Moreover i asked for some feedback +in order to understand/fix the problem myself, +and again received no response. + +What i asked was pretty simple: +"1. Is it possible that the absense of statistics make the planer produce +better plans +than in the case of statistcs generated with vacuum +analyze/analyze? +2. If No, i found a bug, +3. If yes then under what conditions?? +4. If no person knows the answer or no hacker wants to dig into the +problem then is there a direction i must follow to understand/fix whats +going on myself??"" + +Pretty straight i think. + +Well, i stack on step 1. + +It seemed to me that either my question was too naive to deserve some real +investigation (doubtedly), or no one was in a position to comment on +it (doubtedly), or that it is not considered an interesting case (possible), +or that some people move all the mail i send to the lists to /dev/null +(unfortunately possible too). + +So Since i really have stuck to postgresql for over 2 years for both +technical and emotional reasons, i would feel much more confident +if i would reach step 2 or greater. + +The table i have in question is a critical one in my application +since it monitors important plan maintenance data, and i have +to move on with this problem. + +Thanx + +P.S. the www (64.49.215.82) server is down for while. + +-- +================================================================== +Achilleus Mantzios +S/W Engineer +IT dept +Dynacom Tankers Mngmt +Nikis 4, Glyfada +Athens 16610 +Greece +tel: +30-210-8981112 +fax: +30-210-8981877 +email: achill@matrix.gatewaynet.com + mantzios@softlab.ece.ntua.gr + + +From pgsql-bugs-owner@postgresql.org Wed May 7 12:57:57 2003 +X-Original-To: pgsql-bugs@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP + id 5E0284764DE; Wed, 7 May 2003 12:57:50 -0400 (EDT) +Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) + by postgresql.org (Postfix) with ESMTP + id 7192F4764D9; Wed, 7 May 2003 12:57:49 -0400 (EDT) +Received: from [66.219.92.2] (HELO temoku) + by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) + with ESMTP id 3015156; Wed, 07 May 2003 09:57:55 -0700 +Content-Type: text/plain; + charset="iso-8859-1" +From: Josh Berkus +Reply-To: josh@agliodbs.com +Organization: Aglio Database Solutions +To: "Mendola Gaetano" , + "Achilleus Mantzios" , + , , + +Subject: Re: Unanswered Questions WAS: An unresolved performance problem. +Date: Wed, 7 May 2003 09:57:22 -0700 +User-Agent: KMail/1.4.3 +References: + <013301c314ae$6e1b6520$152aa8c0@GMENDOLA2> +In-Reply-To: <013301c314ae$6e1b6520$152aa8c0@GMENDOLA2> +MIME-Version: 1.0 +Content-Transfer-Encoding: quoted-printable +Message-Id: <200305070957.22833.josh@agliodbs.com> +X-Spam-Status: No, hits=-32.4 required=5.0 + tests=BAYES_01,IN_REP_TO,QUOTED_EMAIL_TEXT,REFERENCES, + REPLY_WITH_QUOTES,USER_AGENT_KMAIL autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/21 +X-Sequence-Number: 5982 + +Gaetano, + +> I seen around a lot of questions are remaining without any reply, +> may be in this period the guys like Tom Lane are too busy. + +Yes, they are. Currently the major contributors are working hard to shape= + up=20 +both 7.3.3. and 7.4 (and having a long-running discussion about the due dat= +e=20 +for 7.4), so they don't have much time for questions. + +And for my part, I'm too busy with my paying job to answer all the question= +s=20 +that get posted, as I suspect are Stephan and Bruno and several other peopl= +e=20 +who field newbie questions. Given the flood of requests, I have to=20 +prioritize ... and a question which is missing several crucial details (lik= +e=20 +a copy of the query!!!) is going to get answered way later than a questio= +n=20 +which provides all the needed information -- if at all. + +--=20 +-Josh Berkus + Aglio Database Solutions + San Francisco + + +From pgsql-performance-owner@postgresql.org Wed May 7 14:43:09 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id B3BB7475F2C + for ; + Wed, 7 May 2003 14:43:03 -0400 (EDT) +Received: from email03.aon.at (WARSL401PIP6.highway.telekom.at [195.3.96.93]) + by postgresql.org (Postfix) with SMTP id BD3FC476508 + for ; + Wed, 7 May 2003 14:42:57 -0400 (EDT) +Received: (qmail 113116 invoked from network); 7 May 2003 18:42:56 -0000 +Received: from m156p012.dipool.highway.telekom.at (HELO cantor) + ([62.46.9.108]) (envelope-sender ) + by qmail3rs.highway.telekom.at (qmail-ldap-1.03) with SMTP + for ; 7 May 2003 18:42:56 -0000 +From: Manfred Koizar +To: Achilleus Mantzios +Cc: Hannu Krosing , pgsql-performance@postgresql.org +Subject: Re: An unresolved performance problem. +Date: Wed, 07 May 2003 20:42:46 +0200 +Message-ID: <1akibvk37pfk85muvsko20egsirhvsgm2g@4ax.com> +References: <1052314806.2205.6.camel@fuji.krosing.net> + +In-Reply-To: +X-Mailer: Forte Agent 1.8/32.548 +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Transfer-Encoding: 7bit +X-Spam-Status: No, hits=-19.2 required=5.0 + tests=BAYES_01,IN_REP_TO,REFERENCES,USER_AGENT_FORTE + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/87 +X-Sequence-Number: 1866 + +On Wed, 7 May 2003 17:09:17 -0200 (GMT+2), Achilleus Mantzios + wrote: +>I have about 10 indexes on this table, and the "correct" one +>is used only if i do set enable_seqscan to off; and +>drop all other indexes. + +What we already have is + +|dynacom=# EXPLAIN ANALYZE +|SELECT count(*) +| FROM status +| WHERE assettable='vessels' AND appname='ISM PMS' AND apptblname='items' AND status='warn' AND isvalid AND assetidval=57; +| +|QUERY PLAN (fbsd) +|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +| Aggregate (cost=6.02..6.02 rows=1 width=0) (actual time=14.16..14.16 rows=1 loops=1) +| -> Index Scan using status_all on status (cost=0.00..6.02 rows=1 width=0) (actual time=13.09..13.95 rows=75 loops=1) +| Index Cond: ((assettable = 'vessels'::character varying) AND (assetidval = 57) AND (appname = 'ISM PMS'::character varying) AND (apptblname = 'items'::character varying) AND (status = 'warn'::character varying)) +| Filter: isvalid +| Total runtime: 14.40 msec +|(5 rows) +| +|QUERY PLAN (lnx) +|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +| Aggregate (cost=1346.56..1346.56 rows=1 width=0) (actual time=244.05..244.05 rows=1 loops=1) +| -> Seq Scan on status (cost=0.00..1345.81 rows=300 width=0) (actual time=0.63..243.93 rows=75 loops=1) +| Filter: ((assettable = 'vessels'::character varying) AND (appname = 'ISM PMS'::character varying) AND (apptblname = 'items'::character varying) AND (status = 'warn'::character varying) AND isvalid AND (assetidval = 57)) +| Total runtime: 244.12 msec +|(4 rows) + +Now set enable_seqscan to off, and show as the EXPLAIN ANALYSE output. +If the wrong index is used, remove it and rerun the query. Repeat +until you arrive at the correct index and show us these results, too. + +>Otherwise i get either a seq scan or the wrong index. +| -> Seq Scan on status (cost=0.00..1345.81 rows=300 width=0) (actual time=0.63..243.93 rows=75 loops=1) + ^^^^ +This seems strange, given that relpages = 562. +What are your config settings? And what hardware is this running on, +especially how much RAM? + +Servus + Manfred + + +From pgsql-performance-owner@postgresql.org Wed May 7 10:05:02 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id EC352475D3B + for ; + Wed, 7 May 2003 10:04:58 -0400 (EDT) +Received: from matrix.gatewaynet.com (unknown [217.19.69.50]) + by postgresql.org (Postfix) with ESMTP id 3E3C2475A8D + for ; + Wed, 7 May 2003 10:04:46 -0400 (EDT) +Received: from matrix.gatewaynet.com (localhost [127.0.0.1]) + by matrix.gatewaynet.com (8.12.5/8.12.5) with ESMTP id h47J9H1s028802; + Wed, 7 May 2003 17:09:17 -0200 +Received: from localhost (achill@localhost) + by matrix.gatewaynet.com (8.12.5/8.12.5/Submit) with ESMTP id + h47J9HZ3028798; Wed, 7 May 2003 17:09:17 -0200 +Date: Wed, 7 May 2003 17:09:17 -0200 (GMT+2) +From: Achilleus Mantzios +To: Hannu Krosing +Cc: pgsql-performance@postgresql.org +Subject: Re: An unresolved performance problem. +In-Reply-To: <1052314806.2205.6.camel@fuji.krosing.net> +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-Spam-Status: No, hits=-38.6 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + QUOTE_TWICE_1,REPLY_WITH_QUOTES,SIGNATURE_LONG_DENSE, + USER_AGENT_PINE autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/78 +X-Sequence-Number: 1857 + +On 7 May 2003, Hannu Krosing wrote: + +> Achilleus Mantzios kirjutas K, 07.05.2003 kell 19:33: +> > Hi, few days ago, i posted some really wierd (at least to me) +> > situation (maybe a potentian bug) to the performance and bugs list +> > and to some core hacker(s) privately as well, +> > and i got no response. +> > Moreover i asked for some feedback +> > in order to understand/fix the problem myself, +> > and again received no response. +> > +> > What i asked was pretty simple: +> > "1. Is it possible that the absense of statistics make the planer produce +> > better plans than in the case of statistcs generated with vacuum +> > analyze/analyze? +> +> Yes, the planner is not perfect, the statistics are just statistics +> (based on a random sample), etc.. +> +> This question comes up at least once a month on either [PERFORM] or +> [HACKERS], search the mailing lists to get more thorough +> discussion/explanation. + +Ooopss i am i pgsql-performance@postgresl.org newbie +(up to now i thought -sql was where all the fun takes place :) + +> +> > 2. If No, i found a bug, +> +> Rather a feature ;-p +> +> > 3. If yes then under what conditions?? +> +> if +> +> 1) ANALYZE produced skewed data which was worse than default. +> +> or. +> +> 2) some costs are way off for your system (try changing them in +> postgresql.conf) +> + +My systems are (rather usual) linux/freebsd and the costs defined (by +default) in postgresql.conf worked well for all queries except +a cursed query on a cursed table. +So i start to believe its an estimation selectivity +problem. + +> > 4. If no person knows the answer or no hacker wants to dig into the +> > problem then is there a direction i must follow to understand/fix whats +> > going on myself??"" +> +> You can sturt by enabling/disabling various scan methods +> +> psqldb# set enable_seqscan to off; +> SET +> + +I have about 10 indexes on this table, and the "correct" one +is used only if i do set enable_seqscan to off; and +drop all other indexes. +Otherwise i get either a seq scan or the wrong index. + +> +> and see what happens, then adjust the weights in postgresql.conf or use +> some combination of SETs around critical queries to force the plan you +> like. +> + +Also i played with ALTER TABLE set statistics +but could not generate this ideal situation when +no stats where available (right after a load). + +The problem is that other queries on this table +need some indexes. +I dunno whata do :( + +> +> ------------ +> Hannu +> + +-- +================================================================== +Achilleus Mantzios +S/W Engineer +IT dept +Dynacom Tankers Mngmt +Nikis 4, Glyfada +Athens 16610 +Greece +tel: +30-210-8981112 +fax: +30-210-8981877 +email: achill@matrix.gatewaynet.com + mantzios@softlab.ece.ntua.gr + + +From pgsql-performance-owner@postgresql.org Wed May 7 15:13:13 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 68F164762CF + for ; + Wed, 7 May 2003 15:13:09 -0400 (EDT) +Received: from sccrmhc02.attbi.com (sccrmhc02.attbi.com [204.127.202.62]) + by postgresql.org (Postfix) with ESMTP id 4CCE5476085 + for ; + Wed, 7 May 2003 15:13:08 -0400 (EDT) +Received: from ladamski (12-236-245-17.client.attbi.com[12.236.245.17]) + by attbi.com (sccrmhc02) with SMTP + id <20030507191308002006t32je>; Wed, 7 May 2003 19:13:08 +0000 +From: "Lucas Adamski" +To: "Postgresql Performance Mailing list (E-mail)" + +Subject: Hack around lack of CORRESPONDING BY in EXCEPT? +Date: Wed, 7 May 2003 12:11:46 -0700 +Message-ID: <000301c314cc$81c4ad20$11f5ec0c@LADAMSKI> +MIME-Version: 1.0 +Content-Type: multipart/alternative; + boundary="----=_NextPart_000_0004_01C31491.D5675BC0" +X-Priority: 3 (Normal) +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook CWS, Build 9.0.2416 (9.0.2911.0) +X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4925.2800 +Importance: Normal +X-Spam-Status: No, hits=-2.4 required=5.0 tests=BAYES_20,HTML_30_40 + version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/88 +X-Sequence-Number: 1867 + +This is a multi-part message in MIME format. + +------=_NextPart_000_0004_01C31491.D5675BC0 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit + +I'm not sure if this a performance question or a sql question really, but +since my primarily peeve here is performance, here goes: + +I'm trying to write a query which takes the output of a join and shows me +only what the items that are in the main join but not in the subselect of +just one of the tables in the join, using EXCEPT. + +This is a little complicated, so please bear with me. + +I have two tables: an event table that logs random events as they come in, +and a tracking table that keeps a state of events it cares about. In this +particular case I'm trying to obtain a list of tracking pkeys for related +event data that do not correspond to a certain (other) set of event data. + +Ideally, here is what I want: + +SELECT tracking.pk,events.data1,events.data2 FROM tracking,events WHERE +tracking.event_fk = event.pk EXCEPT (SELECT events.data1,events.data2 FROM +events WHERE event.type = 10) + +The problem I have of course is that I get an error regarding trying to use +different columns for the two queries in EXCEPT. I'm sure someone will +point this out, but the following suggestion will not work: + +SELECT tracking.pk,events.data1,events.data2 FROM tracking,events WHERE +tracking.event_fk = event.pk EXCEPT (SELECT +tracking.pk,events.data1,events.data2 FROM tracking,events WHERE +tracking.event_fk = event.pk AND event.type = 10) + +That won't work for two reasons... first, there are no matching entries in +the tracking table pointing to events where event.type = 10, meaning this +query would always return an empty set. And even if there were, I don't +want to do the join twice if its not necessary, as the events table is +liable to be very large. + +The official solution to this I believe would be to just use CORRESPONDING +BY, but that's not supported by PG (why exactly, oh why!) + +Suggestions, anyone? Thanks in advance, + Lucas. + + +------=_NextPart_000_0004_01C31491.D5675BC0 +Content-Type: text/html; + charset="iso-8859-1" +Content-Transfer-Encoding: quoted-printable + + + + + + + + +
I'm not s= +ure if this=20 +a performance question or a sql question really, but since my primarily pee= +ve=20 +here is performance, here goes:
+
 
+
I'm tryin= +g to write=20 +a query which takes the output of a join and shows me only what the items t= +hat=20 +are in the main join but not in the subselect of just one of the tables in = +the=20 +join, using EXCEPT.
+
 
+
This is a= + little=20 +complicated, so please bear with me. 
+
 
+
I have tw= +o tables:=20 +an event table that logs random events as they come in, and a tracking tabl= +e=20 +that keeps a state of events it cares about.  In this particular case = +I'm=20 +trying to obtain a list of tracking pkeys for related event data that = +do=20 +not correspond to a certain (other) set of event data.
+
 
+
Ideally, = +here is=20 +what I want:
+
 
+
SELECT=20 +tracking.pk,events.data1,events.data2 FROM tracking,events WHERE=20 +tracking.event_fk =3D event.pk EXCEPT (SELECT events.data1,events.data= +2=20 +FROM events WHERE event.type =3D 10)
+
 
+
The probl= +em I have=20 +of course is that I get an error regarding trying to use different columns = +for=20 +the two queries in EXCEPT.  I'm sure someone will point this out, but = +the=20 +following suggestion will not work:
+
+
 
+
+
SELECT=20 +tracking.pk,events.data1,events.data2 FROM tracking,events WHERE=20 +tracking.event_fk =3D event.pk EXCEPT (SELECT tracking.pk,events.data1,events.data2 FROM=20 +tracking,events WHERE tracking.event_fk =3D event.pk AND=20 +event.type =3D 10)
+
 
+
That won't work for two reasons... fi= +rst,=20 +there are no matching entries in the tracking table pointing to events wher= +e=20 +event.type =3D 10, meaning this query would always return an empty set.&nbs= +p; And=20 +even if there were, I don't want to do the join twice if its not necessary,= + as=20 +the events table is liable to be very large.
+
 
+
The offic= +ial=20 +solution to this I believe would be to just use CORRESPONDING BY, but= +=20 +that's not supported by PG (why exactly, oh why!)
+
 
+
Suggestio= +ns,=20 +anyone?  Thanks in advance,
+
 =20 +Lucas.
+
 
+
 
+ +------=_NextPart_000_0004_01C31491.D5675BC0-- + + +From pgsql-performance-owner@postgresql.org Wed May 7 15:36:45 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id DECE24764D8 + for ; + Wed, 7 May 2003 15:36:42 -0400 (EDT) +Received: from megazone.bigpanda.com (megazone.bigpanda.com [63.150.15.178]) + by postgresql.org (Postfix) with ESMTP id F1DE74764A7 + for ; + Wed, 7 May 2003 15:36:41 -0400 (EDT) +Received: by megazone.bigpanda.com (Postfix, from userid 1001) + id DEA7AD658; Wed, 7 May 2003 12:36:42 -0700 (PDT) +Received: from localhost (localhost [127.0.0.1]) + by megazone.bigpanda.com (Postfix) with ESMTP + id D44A65C0A; Wed, 7 May 2003 12:36:42 -0700 (PDT) +Date: Wed, 7 May 2003 12:36:42 -0700 (PDT) +From: Stephan Szabo +To: Lucas Adamski +Cc: "Postgresql Performance Mailing list (E-mail)" + +Subject: Re: Hack around lack of CORRESPONDING BY in EXCEPT? +In-Reply-To: <000301c314cc$81c4ad20$11f5ec0c@LADAMSKI> +Message-ID: <20030507123007.G29826-100000@megazone23.bigpanda.com> +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-Spam-Status: No, hits=-26.0 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REPLY_WITH_QUOTES autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/89 +X-Sequence-Number: 1868 + + +On Wed, 7 May 2003, Lucas Adamski wrote: + +> I'm not sure if this a performance question or a sql question really, but +> since my primarily peeve here is performance, here goes: +> +> I'm trying to write a query which takes the output of a join and shows me +> only what the items that are in the main join but not in the subselect of +> just one of the tables in the join, using EXCEPT. +> +> This is a little complicated, so please bear with me. +> +> I have two tables: an event table that logs random events as they come in, +> and a tracking table that keeps a state of events it cares about. In this +> particular case I'm trying to obtain a list of tracking pkeys for related +> event data that do not correspond to a certain (other) set of event data. +> +> Ideally, here is what I want: +> +> SELECT tracking.pk,events.data1,events.data2 FROM tracking,events WHERE +> tracking.event_fk = event.pk EXCEPT (SELECT events.data1,events.data2 FROM +> events WHERE event.type = 10) + +Maybe something like (if I'm right in assuming that you want any event +whose data1 and data2 match an event having type 10): + +select tracking.pk, e.data1, e.data2 from + tracking, + ((select data1,data2 from events) except (select data1,data2 from events + where event.type=10)) e +where tracking.event_fk=e.pk; + + +> The official solution to this I believe would be to just use CORRESPONDING +> BY, but that's not supported by PG (why exactly, oh why!) + +Because it's not entry level SQL92 and noone's implemented it yet. :) + + +From pgsql-performance-owner@postgresql.org Wed May 7 15:46:35 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP + id 775C6476530; Wed, 7 May 2003 15:46:29 -0400 (EDT) +Received: from fddlnint05.fds.com (fddlnint05.fds.com [208.15.91.52]) + by postgresql.org (Postfix) with ESMTP + id 0FA7D4763E3; Wed, 7 May 2003 15:46:21 -0400 (EDT) +In-Reply-To: <000301c314cc$81c4ad20$11f5ec0c@LADAMSKI> +Subject: Re: Hack around lack of CORRESPONDING BY in EXCEPT? +To: ladamski@manageww.com +Cc: "Postgresql Performance Mailing list (E-mail)" + , pgsql-performance-owner@postgresql.org +X-Mailer: Lotus Notes Release 6.0 September 26, 2002 +Message-ID: + +From: "Patrick Hatcher" +Date: Wed, 7 May 2003 12:40:19 -0700 +X-MIMETrack: Serialize by Router on FDDLNINT05/FSG/SVR/FDD(Release 5.0.4 |June + 8, 2000) at 05/07/2003 03:42:21 PM +MIME-Version: 1.0 +Content-type: text/plain; charset=us-ascii +X-Spam-Status: No, hits=-9.8 required=5.0 tests=BAYES_01,IN_REP_TO + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/91 +X-Sequence-Number: 1870 + + +Not sure if I'm reading your question correctly, but is this what you want? + +SELECT t.pk,e.data1,e.data2 +FROM tracking t left outer join events e on t.event_fk = e.pk +WHERE e.type <> 10 + +OR + +SELECT t.pk,e.data1,e.data2 +FROM tracking t inner join events e on t.event_fk = e.pk +WHERE e.type <> 10 + + + + + + "Lucas Adamski" + To: "Postgresql Performance Mailing list (E-mail)" + Sent by: + pgsql-performance-owner@post cc: + gresql.org Subject: [PERFORM] Hack around lack of CORRESPONDING BY in EXCEPT? + + + 05/07/2003 12:11 PM + + + + + +I'm not sure if this a performance question or a sql question really, but +since my primarily peeve here is performance, here goes: + +I'm trying to write a query which takes the output of a join and shows me +only what the items that are in the main join but not in the subselect of +just one of the tables in the join, using EXCEPT. + +This is a little complicated, so please bear with me. + +I have two tables: an event table that logs random events as they come in, +and a tracking table that keeps a state of events it cares about. In this +particular case I'm trying to obtain a list of tracking pkeys for related +event data that do not correspond to a certain (other) set of event data. + +Ideally, here is what I want: + +SELECT tracking.pk,events.data1,events.data2 FROM tracking,events WHERE +tracking.event_fk = event.pk EXCEPT (SELECT events.data1,events.data2 FROM +events WHERE event.type = 10) + +The problem I have of course is that I get an error regarding trying to use +different columns for the two queries in EXCEPT. I'm sure someone will +point this out, but the following suggestion will not work: + +SELECT tracking.pk,events.data1,events.data2 FROM tracking,events WHERE +tracking.event_fk = event.pk EXCEPT (SELECT +tracking.pk,events.data1,events.data2 FROM tracking,events WHERE +tracking.event_fk = event.pk AND event.type = 10) + +That won't work for two reasons... first, there are no matching entries in +the tracking table pointing to events where event.type = 10, meaning this +query would always return an empty set. And even if there were, I don't +want to do the join twice if its not necessary, as the events table is +liable to be very large. + +The official solution to this I believe would be to just use CORRESPONDING +BY, but that's not supported by PG (why exactly, oh why!) + +Suggestions, anyone? Thanks in advance, + Lucas. + + +From pgsql-performance-owner@postgresql.org Wed May 7 15:43:30 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 4039E47656D + for ; + Wed, 7 May 2003 15:43:29 -0400 (EDT) +Received: from megazone.bigpanda.com (megazone.bigpanda.com [63.150.15.178]) + by postgresql.org (Postfix) with ESMTP id B4BBF476566 + for ; + Wed, 7 May 2003 15:43:28 -0400 (EDT) +Received: by megazone.bigpanda.com (Postfix, from userid 1001) + id A48B6D64D; Wed, 7 May 2003 12:43:29 -0700 (PDT) +Received: from localhost (localhost [127.0.0.1]) + by megazone.bigpanda.com (Postfix) with ESMTP + id 9A2CC5C04; Wed, 7 May 2003 12:43:29 -0700 (PDT) +Date: Wed, 7 May 2003 12:43:29 -0700 (PDT) +From: Stephan Szabo +To: Lucas Adamski +Cc: "Postgresql Performance Mailing list (E-mail)" + +Subject: Re: Hack around lack of CORRESPONDING BY in EXCEPT? +In-Reply-To: <000301c314cc$81c4ad20$11f5ec0c@LADAMSKI> +Message-ID: <20030507124143.V30050-100000@megazone23.bigpanda.com> +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-Spam-Status: No, hits=-16.3 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/90 +X-Sequence-Number: 1869 + + +On Wed, 7 May 2003, Lucas Adamski wrote: + +Of course my last suggestion won't work since you need to get the event.pk +field out. The actual subquery would need to be more complicated and +probably involve an IN or EXISTS. :( + + +From pgsql-bugs-owner@postgresql.org Wed May 7 15:57:27 2003 +X-Original-To: pgsql-bugs@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP + id 017BD476544; Wed, 7 May 2003 15:57:23 -0400 (EDT) +Received: from moutng.kundenserver.de (moutng.kundenserver.de + [212.227.126.177]) by postgresql.org (Postfix) with ESMTP + id 82099476530; Wed, 7 May 2003 15:57:20 -0400 (EDT) +Received: from [212.227.126.206] (helo=mrelayng.kundenserver.de) + by moutng.kundenserver.de with esmtp (Exim 3.35 #1) + id 19DV2X-0007up-00; Wed, 07 May 2003 21:57:21 +0200 +Received: from [217.231.193.248] (helo=asa.de) + by mrelayng.kundenserver.de with asmtp (TLSv1:RC4-MD5:128) + (Exim 3.35 #1) id 19DV2X-0007lO-00; Wed, 07 May 2003 21:57:21 +0200 +Message-ID: <3EB96544.6010606@asa.de> +Date: Wed, 07 May 2003 21:57:56 +0200 +From: Bernd von den Brincken +User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; + rv:1.3) Gecko/20030312 +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: pgsql-sql@postgresql.org +Cc: pgsql-bugs@postgresql.org +Subject: Re: [SQL] An unresolved performance problem. +References: + <013301c314ae$6e1b6520$152aa8c0@GMENDOLA2> +In-Reply-To: <013301c314ae$6e1b6520$152aa8c0@GMENDOLA2> +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit +X-Spam-Status: No, hits=-33.9 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,RCVD_IN_NJABL, + RCVD_IN_OSIRUSOFT_COM,REFERENCES,REPLY_WITH_QUOTES, + USER_AGENT_MOZILLA_UA autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/22 +X-Sequence-Number: 5983 + +Hi, + +Mendola Gaetano wrote: + +> ... +> +>I seen around a lot of questions are remaining without any reply, +>may be in this period the guys like Tom Lane are too busy. ... +> +> +And we should remember that this is still free, open source software - +so we have no right to claim _any_ support whatsoever. +So thanks a lot to the PostgreSQL team for all the hard work that has +been and is being put into this software. + +// Bernd vdB + + +From pgsql-performance-owner@postgresql.org Wed May 7 16:23:09 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 745D0476583 + for ; + Wed, 7 May 2003 16:23:06 -0400 (EDT) +Received: from email06.aon.at (WARSL401PIP3.highway.telekom.at [195.3.96.75]) + by postgresql.org (Postfix) with SMTP id DA47F476582 + for ; + Wed, 7 May 2003 16:23:04 -0400 (EDT) +Received: (qmail 182930 invoked from network); 7 May 2003 20:23:05 -0000 +Received: from m156p012.dipool.highway.telekom.at (HELO cantor) + ([62.46.9.108]) (envelope-sender ) + by qmail6rs.highway.telekom.at (qmail-ldap-1.03) with SMTP + for ; 7 May 2003 20:23:05 -0000 +From: Manfred Koizar +To: "Lucas Adamski" +Cc: "Postgresql Performance Mailing list (E-mail)" + +Subject: Re: Hack around lack of CORRESPONDING BY in EXCEPT? +Date: Wed, 07 May 2003 22:22:54 +0200 +Message-ID: <5npibv8l1090ppjkt17is5ipq26honl1e1@4ax.com> +References: <000301c314cc$81c4ad20$11f5ec0c@LADAMSKI> +In-Reply-To: <000301c314cc$81c4ad20$11f5ec0c@LADAMSKI> +X-Mailer: Forte Agent 1.8/32.548 +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Transfer-Encoding: 7bit +X-Spam-Status: No, hits=-32.2 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,REFERENCES, + REPLY_WITH_QUOTES,USER_AGENT_FORTE autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/92 +X-Sequence-Number: 1871 + +On Wed, 7 May 2003 12:11:46 -0700, "Lucas Adamski" + wrote: +>I have two tables: an event table that logs random events as they come in, +>and a tracking table that keeps a state of events it cares about. In this +>particular case I'm trying to obtain a list of tracking pkeys for related +>event data that do not correspond to a certain (other) set of event data. +> +>Ideally, here is what I want: +> +>SELECT tracking.pk,events.data1,events.data2 FROM tracking,events WHERE +>tracking.event_fk = event.pk EXCEPT (SELECT events.data1,events.data2 FROM +>events WHERE event.type = 10) + +Lucas, try this untested query: + + SELECT tr.pk, ev.data1, ev.data2 + FROM tracking tr INNER JOIN events ev + ON tr.event_fk = ev.pk + WHERE ev.type != 10; + +(Should also work with AND instead of WHERE.) + +>SELECT tracking.pk,events.data1,events.data2 FROM tracking,events WHERE +>tracking.event_fk = event.pk EXCEPT (SELECT +>tracking.pk,events.data1,events.data2 FROM tracking,events WHERE +>tracking.event_fk = event.pk AND event.type = 10) +> +>That won't work for two reasons... first, there are no matching entries in +>the tracking table pointing to events where event.type = 10, meaning this +>query would always return an empty set. + +I don't understand this. If there are no entries with event.type 10, +then the subselect returns an empty result set, and EXCEPT + should give the original result? + +Servus + Manfred + + +From pgsql-performance-owner@postgresql.org Wed May 7 18:29:50 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id BC4F4475B8E + for ; + Wed, 7 May 2003 18:29:49 -0400 (EDT) +Received: from rwcrmhc53.attbi.com (rwcrmhc53.attbi.com [204.127.198.39]) + by postgresql.org (Postfix) with ESMTP id 6119C4765A5 + for ; + Wed, 7 May 2003 18:29:46 -0400 (EDT) +Received: from ladamski (12-236-245-17.client.attbi.com[12.236.245.17]) + by attbi.com (rwcrmhc53) with SMTP + id <2003050722294805300fhbvse>; Wed, 7 May 2003 22:29:48 +0000 +From: "Lucas Adamski" +To: "Postgresql Performance Mailing list (E-mail)" + +Subject: Re: Hack around lack of CORRESPONDING BY in EXCEPT? +Date: Wed, 7 May 2003 15:28:26 -0700 +Message-ID: <000801c314e7$fb236e70$11f5ec0c@LADAMSKI> +MIME-Version: 1.0 +Content-Type: text/plain; + charset="US-ASCII" +Content-Transfer-Encoding: 7bit +X-Priority: 3 (Normal) +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook CWS, Build 9.0.2416 (9.0.2911.0) +X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4925.2800 +Importance: Normal +In-Reply-To: <20030507124143.V30050-100000@megazone23.bigpanda.com> +X-Spam-Status: No, hits=-21.8 required=5.0 + tests=BAYES_10,EMAIL_ATTRIBUTION,IN_REP_TO,ORIGINAL_MESSAGE + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/93 +X-Sequence-Number: 1872 + +Stephan, + +Yup, unfortunately you are correct... I'd need to get the event.pk's out of +there somewhere to join with the tracking.event_fk. I can't put the +event.pk in the subselects as they don't match, and I would get an empty set +back. + +select tracking.pk, e.data1, e.data2 from + tracking, + ((select data1,data2 from events) except (select data1,data2 from events + where event.type=10)) e +where tracking.event_fk=e.pk; + +I wrote it originally as: + +SELECT tracking.pk,events.data1,events.data2 FROM tracking,events WHERE +tracking.event_fk = event.pk EXCEPT (SELECT events.data1,events.data2 FROM +events WHERE event.type = 10) + +because each of these subqueries restricts the dataset greatly before doing +the join. I've simplified the actual problem (as the real code has a bunch +of extraneous stuff that makes it even more obtuse), but essentially, the +tracking table maintains a record of the last record type that was entered. +The type is incremented for each batch of events that is loaded. In this +case, I'm assuming that the latest batch is type=10 (or 5000, or 100000), +and the tracking table references a small subset of previous events +(possibly of types 1-9 in this example). This particular query is supposed +to return all tracking.pk's that are present in the previous batches (types) +but not in the latest batch (10). I didn't mean to make it quite so obtuse, +sorry. :) + +So in this case I'm getting all of the relevant data for the new entries, +subtracting those from the old entries that are referred to by the tracking +system, and returning those outdated tracking.pk's. + Lucas. + +-----Original Message----- +From: Stephan Szabo [mailto:sszabo@megazone23.bigpanda.com] +Sent: Wednesday, May 07, 2003 12:43 PM +To: Lucas Adamski +Cc: Postgresql Performance Mailing list (E-mail) +Subject: Re: [PERFORM] Hack around lack of CORRESPONDING BY in EXCEPT? + + + +On Wed, 7 May 2003, Lucas Adamski wrote: + +Of course my last suggestion won't work since you need to get the event.pk +field out. The actual subquery would need to be more complicated and +probably involve an IN or EXISTS. :( + + +From pgsql-performance-owner@postgresql.org Wed May 7 18:38:55 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 3EE934763FE + for ; + Wed, 7 May 2003 18:38:54 -0400 (EDT) +Received: from rwcrmhc52.attbi.com (rwcrmhc52.attbi.com [216.148.227.88]) + by postgresql.org (Postfix) with ESMTP id 5BD8C475B8E + for ; + Wed, 7 May 2003 18:38:53 -0400 (EDT) +Received: from ladamski (12-236-245-17.client.attbi.com[12.236.245.17]) + by attbi.com (rwcrmhc52) with SMTP + id <2003050722385205200m46q5e>; Wed, 7 May 2003 22:38:52 +0000 +From: "Lucas Adamski" +To: "'Postgresql Performance Mailing list (E-mail)'" + +Subject: Re: Hack around lack of CORRESPONDING BY in EXCEPT? +Date: Wed, 7 May 2003 15:37:30 -0700 +Message-ID: <000901c314e9$3efa4370$11f5ec0c@LADAMSKI> +MIME-Version: 1.0 +Content-Type: text/plain; + charset="US-ASCII" +Content-Transfer-Encoding: 7bit +X-Priority: 3 (Normal) +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook CWS, Build 9.0.2416 (9.0.2911.0) +X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4925.2800 +Importance: Normal +In-Reply-To: + +X-Spam-Status: No, hits=-15.3 required=5.0 + tests=BAYES_10,IN_REP_TO,ORIGINAL_MESSAGE + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/94 +X-Sequence-Number: 1873 + +Patrick, + +I don't think that wouldn't quite work unfortunately, as I'm actually trying +to filter them out based upon the values in data1 and data2. I'm using the +data in set 2 (data1,data2 from events where type=10) to remove rows from +set 1 (join between events and tracking table) where set1.data1=set2.data1 +and set1.data2=set2.data2, and returning the tracking id's for any rows left +in set 1 (that were not in set 2). I probably gave a better explaination in +my response to Stephan. In the case below, I would simply get all events +where type<>10 from the join, regardless of whether they matched the data1 +and data2 for all type=10. Thanks, + Lucas. + +-----Original Message----- +From: Patrick Hatcher [mailto:PHatcher@macys.com] +Sent: Wednesday, May 07, 2003 12:40 PM +To: ladamski@manageww.com +Cc: Postgresql Performance Mailing list (E-mail); +pgsql-performance-owner@postgresql.org +Subject: Re: [PERFORM] Hack around lack of CORRESPONDING BY in EXCEPT? + + + + + + + +Not sure if I'm reading your question correctly, but is this what you want? + +SELECT t.pk,e.data1,e.data2 +FROM tracking t left outer join events e on t.event_fk = e.pk +WHERE e.type <> 10 + +OR + +SELECT t.pk,e.data1,e.data2 +FROM tracking t inner join events e on t.event_fk = e.pk +WHERE e.type <> 10 + + + + + + "Lucas Adamski" + To: "Postgresql +Performance Mailing list (E-mail)" + Sent by: + + pgsql-performance-owner@post cc: + gresql.org Subject: +[PERFORM] Hack around lack of CORRESPONDING BY in EXCEPT? + + + 05/07/2003 12:11 PM + + + + + +I'm not sure if this a performance question or a sql question really, but +since my primarily peeve here is performance, here goes: + +I'm trying to write a query which takes the output of a join and shows me +only what the items that are in the main join but not in the subselect of +just one of the tables in the join, using EXCEPT. + +This is a little complicated, so please bear with me. + +I have two tables: an event table that logs random events as they come in, +and a tracking table that keeps a state of events it cares about. In this +particular case I'm trying to obtain a list of tracking pkeys for related +event data that do not correspond to a certain (other) set of event data. + +Ideally, here is what I want: + +SELECT tracking.pk,events.data1,events.data2 FROM tracking,events WHERE +tracking.event_fk = event.pk EXCEPT (SELECT events.data1,events.data2 FROM +events WHERE event.type = 10) + +The problem I have of course is that I get an error regarding trying to use +different columns for the two queries in EXCEPT. I'm sure someone will +point this out, but the following suggestion will not work: + +SELECT tracking.pk,events.data1,events.data2 FROM tracking,events WHERE +tracking.event_fk = event.pk EXCEPT (SELECT +tracking.pk,events.data1,events.data2 FROM tracking,events WHERE +tracking.event_fk = event.pk AND event.type = 10) + +That won't work for two reasons... first, there are no matching entries in +the tracking table pointing to events where event.type = 10, meaning this +query would always return an empty set. And even if there were, I don't +want to do the join twice if its not necessary, as the events table is +liable to be very large. + +The official solution to this I believe would be to just use CORRESPONDING +BY, but that's not supported by PG (why exactly, oh why!) + +Suggestions, anyone? Thanks in advance, + Lucas. + + +From pgsql-performance-owner@postgresql.org Wed May 7 18:50:30 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id F0D68475EC9 + for ; + Wed, 7 May 2003 18:50:27 -0400 (EDT) +Received: from rwcrmhc52.attbi.com (rwcrmhc52.attbi.com [216.148.227.88]) + by postgresql.org (Postfix) with ESMTP id 77662475B8E + for ; + Wed, 7 May 2003 18:50:26 -0400 (EDT) +Received: from ladamski (12-236-245-17.client.attbi.com[12.236.245.17]) + by attbi.com (rwcrmhc52) with SMTP + id <2003050722502905200m2i3he>; Wed, 7 May 2003 22:50:29 +0000 +From: "Lucas Adamski" +To: "Postgresql Performance Mailing list (E-mail)" + +Subject: Re: Hack around lack of CORRESPONDING BY in EXCEPT? +Date: Wed, 7 May 2003 15:49:06 -0700 +Message-ID: <000a01c314ea$de8c5f30$11f5ec0c@LADAMSKI> +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit +X-Priority: 3 (Normal) +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook CWS, Build 9.0.2416 (9.0.2911.0) +X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4925.2800 +Importance: Normal +In-Reply-To: <5npibv8l1090ppjkt17is5ipq26honl1e1@4ax.com> +X-Spam-Status: No, hits=-12.8 required=5.0 + tests=BAYES_10,IN_REP_TO,QUOTED_EMAIL_TEXT,QUOTE_TWICE_1 + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/95 +X-Sequence-Number: 1874 + +Manfred, + +I think what you propose is similar to what Patrick proposed, let me see if +I can explain below: + +> -----Original Message----- +> From: Manfred Koizar [mailto:mkoi-pg@aon.at] +> Sent: Wednesday, May 07, 2003 1:23 PM +> To: Lucas Adamski +> Cc: Postgresql Performance Mailing list (E-mail) +> Subject: Re: [PERFORM] Hack around lack of CORRESPONDING BY in EXCEPT? +> + + + +> Lucas, try this untested query: +> +> SELECT tr.pk, ev.data1, ev.data2 +> FROM tracking tr INNER JOIN events ev +> ON tr.event_fk = ev.pk +> WHERE ev.type != 10; +> +> (Should also work with AND instead of WHERE.) + +The problem is that it simply removes all events where type != 10, versus +subtracting all events from subselect of type 10 where data1 and data2 match +those in the main join. The goal of the query is to remove all events that +match (matching being defined as both data1 and data2 matching) that are +present in events of type 10 and events that are referenced by the tracking +table, then return those tracking.pk's for entries that are left over. + +Its not required that I join tracking and events in the primary select +before doing the EXCEPT join, but it should make it a bit more efficient. + +> +> >SELECT tracking.pk,events.data1,events.data2 FROM +> tracking,events WHERE +> >tracking.event_fk = event.pk EXCEPT (SELECT +> >tracking.pk,events.data1,events.data2 FROM tracking,events WHERE +> >tracking.event_fk = event.pk AND event.type = 10) +> > +> >That won't work for two reasons... first, there are no +> matching entries in +> >the tracking table pointing to events where event.type = 10, +> meaning this +> >query would always return an empty set. +> +> I don't understand this. If there are no entries with event.type 10, +> then the subselect returns an empty result set, and EXCEPT +> should give the original result? + +Its not that there are no entires with event.type=10, its that there may not +be any tracking entires for events of type 10, and if I join them before +doing the EXCEPT I will lose them. That's why I have to do the EXCEPT +subselect without joining it to the table. Thanks, + Lucas. + +> +> Servus +> Manfred +> +> +> ---------------------------(end of +> broadcast)--------------------------- +> TIP 5: Have you checked our extensive FAQ? +> +> http://www.postgresql.org/docs/faqs/FAQ.html +> + + +From pgsql-performance-owner@postgresql.org Wed May 7 18:58:53 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 69C3A4764C4 + for ; + Wed, 7 May 2003 18:58:50 -0400 (EDT) +Received: from megazone.bigpanda.com (megazone.bigpanda.com [63.150.15.178]) + by postgresql.org (Postfix) with ESMTP id 4245C476453 + for ; + Wed, 7 May 2003 18:58:49 -0400 (EDT) +Received: by megazone.bigpanda.com (Postfix, from userid 1001) + id D73CDD642; Wed, 7 May 2003 15:58:51 -0700 (PDT) +Received: from localhost (localhost [127.0.0.1]) + by megazone.bigpanda.com (Postfix) with ESMTP + id CCDC05C0B; Wed, 7 May 2003 15:58:51 -0700 (PDT) +Date: Wed, 7 May 2003 15:58:51 -0700 (PDT) +From: Stephan Szabo +To: Lucas Adamski +Cc: "Postgresql Performance Mailing list (E-mail)" + +Subject: Re: Hack around lack of CORRESPONDING BY in EXCEPT? +In-Reply-To: <000801c314e7$fb236e70$11f5ec0c@LADAMSKI> +Message-ID: <20030507154625.C32502-100000@megazone23.bigpanda.com> +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-Spam-Status: No, hits=-26.0 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REPLY_WITH_QUOTES autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/96 +X-Sequence-Number: 1875 + + +On Wed, 7 May 2003, Lucas Adamski wrote: + +> I wrote it originally as: +> +> SELECT tracking.pk,events.data1,events.data2 FROM tracking,events WHERE +> tracking.event_fk = event.pk EXCEPT (SELECT events.data1,events.data2 FROM +> events WHERE event.type = 10) +> +> because each of these subqueries restricts the dataset greatly before doing +> the join. I've simplified the actual problem (as the real code has a bunch +> of extraneous stuff that makes it even more obtuse), but essentially, the +> tracking table maintains a record of the last record type that was entered. +> The type is incremented for each batch of events that is loaded. In this +> case, I'm assuming that the latest batch is type=10 (or 5000, or 100000), +> and the tracking table references a small subset of previous events +> (possibly of types 1-9 in this example). This particular query is supposed +> to return all tracking.pk's that are present in the previous batches (types) +> but not in the latest batch (10). I didn't mean to make it quite so obtuse, +> sorry. :) + +Maybe something like nominally like (quickly done so possibly wrong +again): + + select tracking.pk, events.data1, events.data2 from + tracking,events where not exists (select * from events e where + e.type=10 and e.data1=events.data1 and e.data2=events.data2) + and tracking.event_fk=event.pk + +Get all tracking/event combinations, not including those where the data1/2 +matches that of an event with type 10. + +That might give dups if there are multiple events rows with that pk for +different types (but not 10). + + +From pgsql-performance-owner@postgresql.org Wed May 7 19:52:48 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP + id 121E747655C; Wed, 7 May 2003 19:52:47 -0400 (EDT) +Received: from randalls-laptop.kicks-ass.net + (h00062577286a.ne.client2.attbi.com [24.61.43.102]) + by postgresql.org (Postfix) with ESMTP + id DDC024764FB; Wed, 7 May 2003 19:52:44 -0400 (EDT) +Received: from tercent.net (localhost [127.0.0.1]) + by randalls-laptop.kicks-ass.net (8.12.9/8.12.6) with ESMTP id + h47NqVfd005941; Wed, 7 May 2003 19:52:32 -0400 (EDT) +Date: Wed, 7 May 2003 19:52:30 -0400 +Subject: Re: [SQL] Unanswered Questions WAS: An unresolved performance + problem. +Content-Type: text/plain; charset=US-ASCII; format=flowed +Mime-Version: 1.0 (Apple Message framework v552) +Cc: "Mendola Gaetano" , + "Achilleus Mantzios" , + , , + +To: josh@agliodbs.com +From: Randall Lucas +In-Reply-To: <200305070957.22833.josh@agliodbs.com> +Message-Id: +Content-Transfer-Encoding: 7bit +X-Mailer: Apple Mail (2.552) +X-Spam-Status: No, hits=-28.3 required=5.0 + tests=BAYES_10,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REPLY_WITH_QUOTES,USER_AGENT_APPLEMAIL + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/97 +X-Sequence-Number: 1876 + +Folks, + +I suspect that a good number of fairly simple questions aren't being +answered because they're either misdirected or because the poster +hasn't included an "answerable" question (one with sufficient +information to answer). + +A suggestion to partially counter this, at least for "slow query" type +questions, has been put forth. If we make it a social norm on the +pg-lists in general to reply off-list to inadequately descriptive "slow +query" questions with a canned message of helpful guidance, we may be +able to up the level of "answerability" of most questions. Ideally, +this would make the questions more transparent, so that more responses +can come from folks other than the major contributors. + +Thoughts? Josh and I have placed a draft at +http://techdocs.postgresql.org/guides/SlowQueryPostingGuidelines + +I'd specifically like to hear whether people would suggest more of an +emphasis on heuristics for self-help in such a message, what other info +should be included in a "good" slow query question, and people's +thoughts on the netiquette of the whole idea. + +Best, + +Randall + +On Wednesday, May 7, 2003, at 12:57 PM, Josh Berkus wrote: + +> Gaetano, +> +>> I seen around a lot of questions are remaining without any reply, +>> may be in this period the guys like Tom Lane are too busy. +> +> Yes, they are. Currently the major contributors are working hard to +> shape up +> both 7.3.3. and 7.4 (and having a long-running discussion about the +> due date +> for 7.4), so they don't have much time for questions. +> +> And for my part, I'm too busy with my paying job to answer all the +> questions +> that get posted, as I suspect are Stephan and Bruno and several other +> people +> who field newbie questions. Given the flood of requests, I have to +> prioritize ... and a question which is missing several crucial details +> (like +> a copy of the query!!!) is going to get answered way later than a +> question +> which provides all the needed information -- if at all. +> +> -- +> -Josh Berkus +> Aglio Database Solutions +> San Francisco +> +> +> ---------------------------(end of +> broadcast)--------------------------- +> TIP 1: subscribe and unsubscribe commands go to +> majordomo@postgresql.org +> + + +From pgsql-performance-owner@postgresql.org Wed May 7 19:54:15 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 7C94F475EC9 + for ; + Wed, 7 May 2003 19:54:13 -0400 (EDT) +Received: from email02.aon.at (WARSL401PIP7.highway.telekom.at [195.3.96.94]) + by postgresql.org (Postfix) with SMTP id 7A06D475B8E + for ; + Wed, 7 May 2003 19:54:12 -0400 (EDT) +Received: (qmail 50174 invoked from network); 7 May 2003 23:54:14 -0000 +Received: from m170p003.dipool.highway.telekom.at (HELO cantor) + ([62.46.11.35]) (envelope-sender ) + by qmail2rs.highway.telekom.at (qmail-ldap-1.03) with SMTP + for ; 7 May 2003 23:54:14 -0000 +From: Manfred Koizar +To: "Lucas Adamski" +Cc: "Postgresql Performance Mailing list (E-mail)" + +Subject: Re: Hack around lack of CORRESPONDING BY in EXCEPT? +Date: Thu, 08 May 2003 01:54:04 +0200 +Message-ID: +References: <5npibv8l1090ppjkt17is5ipq26honl1e1@4ax.com> + <000a01c314ea$de8c5f30$11f5ec0c@LADAMSKI> +In-Reply-To: <000a01c314ea$de8c5f30$11f5ec0c@LADAMSKI> +X-Mailer: Forte Agent 1.8/32.548 +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Transfer-Encoding: 7bit +X-Spam-Status: No, hits=-32.2 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,REFERENCES, + REPLY_WITH_QUOTES,USER_AGENT_FORTE autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/98 +X-Sequence-Number: 1877 + +On Wed, 7 May 2003 15:49:06 -0700, "Lucas Adamski" + wrote: +>The problem is that it simply removes all events where type != 10, versus +>subtracting all events from subselect of type 10 where data1 and data2 match +>those in the main join. + +Yes, I realized it when I read Stephan's comment immediately after I +had sent my mail. Should have read your requirements more thoroughly. +Sorry for the noise ... + +Servus + Manfred + + +From pgsql-bugs-owner@postgresql.org Thu May 8 00:13:50 2003 +X-Original-To: pgsql-bugs@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP + id 1E868475B8E; Thu, 8 May 2003 00:13:48 -0400 (EDT) +Received: from sss.pgh.pa.us (unknown [192.204.191.242]) + by postgresql.org (Postfix) with ESMTP + id D4FC14764A7; Thu, 8 May 2003 00:13:46 -0400 (EDT) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h484DKU6017064; + Thu, 8 May 2003 00:13:21 -0400 (EDT) +To: Randall Lucas +Cc: josh@agliodbs.com, "Mendola Gaetano" , + "Achilleus Mantzios" , + pgsql-sql@postgresql.org, pgsql-performance@postgresql.org, + pgsql-bugs@postgresql.org +Subject: Re: [PERFORM] [SQL] Unanswered Questions WAS: An unresolved + performance problem. +In-reply-to: +References: +Comments: In-reply-to Randall Lucas + message dated "Wed, 07 May 2003 19:52:30 -0400" +Date: Thu, 08 May 2003 00:13:20 -0400 +Message-ID: <17063.1052367200@sss.pgh.pa.us> +From: Tom Lane +X-Spam-Status: No, hits=-32.5 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REFERENCES,REPLY_WITH_QUOTES version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/26 +X-Sequence-Number: 5987 + +Randall Lucas writes: +> I suspect that a good number of fairly simple questions aren't being +> answered because they're either misdirected or because the poster +> hasn't included an "answerable" question (one with sufficient +> information to answer). + +That's always been a problem, but it does seem to have been getting +worse lately. + +> A suggestion to partially counter this, at least for "slow query" type +> questions, has been put forth. If we make it a social norm on the +> pg-lists in general to reply off-list to inadequately descriptive "slow +> query" questions with a canned message of helpful guidance, we may be +> able to up the level of "answerability" of most questions. + +The idea of some canned guidance doesn't seem bad, but I'm not sure if +it should be off-list or not. If newbies are corrected off-list then +other newbies who might be lurking, or reading the archives, don't learn +any better and will make the same mistakes in their turn. + +How about a standard answer of "you haven't really provided enough info +for us to be helpful, please see this-URL for some hints"? That would +avoid bulking up the list archives with many copies, yet at the same +time the archives would provide evidence of the existence of hints... + +> Thoughts? Josh and I have placed a draft at +> http://techdocs.postgresql.org/guides/SlowQueryPostingGuidelines + +Looks good, though I concur with Stephan's comment that the table +schemas aren't optional. + +It might be worth including a checklist of the standard kinds of errors +(for example, datatype mismatch preventing index usage). Come to think +of it, that starts to make it look like a FAQ list directed towards +performance issues. Maybe we could make this a subsection of the main +FAQ? + + regards, tom lane + + +From pgsql-bugs-owner@postgresql.org Thu May 8 00:57:47 2003 +X-Original-To: pgsql-bugs@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP + id 59295476393; Thu, 8 May 2003 00:57:45 -0400 (EDT) +Received: from perrin.int.nxad.com (internal.ext.nxad.com [69.1.70.251]) + by postgresql.org (Postfix) with ESMTP + id B6BC5476305; Thu, 8 May 2003 00:57:44 -0400 (EDT) +Received: by perrin.int.nxad.com (Postfix, from userid 1001) + id 005C020F00; Wed, 7 May 2003 21:57:49 -0700 (PDT) +Date: Wed, 7 May 2003 21:57:49 -0700 +From: Sean Chittenden +To: Tom Lane +Cc: Randall Lucas , josh@agliodbs.com, + Mendola Gaetano , + Achilleus Mantzios , + pgsql-sql@postgresql.org, pgsql-performance@postgresql.org, + pgsql-bugs@postgresql.org +Subject: Re: [PERFORM] [SQL] Unanswered Questions WAS: An unresolved + performance problem. +Message-ID: <20030508045749.GV49916@perrin.int.nxad.com> +References: + <17063.1052367200@sss.pgh.pa.us> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: <17063.1052367200@sss.pgh.pa.us> +User-Agent: Mutt/1.4i +X-PGP-Key: finger seanc@FreeBSD.org +X-PGP-Fingerprint: 3849 3760 1AFE 7B17 11A0 83A6 DD99 E31F BC84 B341 +X-Web-Homepage: http://sean.chittenden.org/ +X-Spam-Status: No, hits=-32.9 required=5.0 + tests=BAYES_01,IN_REP_TO,QUOTED_EMAIL_TEXT,QUOTE_TWICE_1, + REFERENCES,REPLY_WITH_QUOTES,USER_AGENT_MUTT + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/27 +X-Sequence-Number: 5988 + +> > I suspect that a good number of fairly simple questions aren't +> > being answered because they're either misdirected or because the +> > poster hasn't included an "answerable" question (one with +> > sufficient information to answer). +> +> That's always been a problem, but it does seem to have been getting +> worse lately. + +I hate to point this out, but "TIP 4" is getting a bit old and the 6 +tips that we throw out to probably about 40K people about 1-200 times +a day have probably reached saturation. Without looking at the +archives, I bet anyone a shot of good scotch that, it's probably +pretty infrequent that people don't kill -9 their postmasters. + +Any chance we could flush out the TIPs at the bottom to include, +"VACUUM ANALYZE your database regularly," or "When reporting a +problem, include the output from EXPLAIN [query]," or "ANALYZE tables +before examining the output from an EXPLAIN [query]," or "Visit [url] +for a tutorial on (schemas|triggers|views)." + +-sc + +-- +Sean Chittenden + + +From pgsql-performance-owner@postgresql.org Thu May 8 07:20:18 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id D73B64763B6 + for ; + Thu, 8 May 2003 07:20:17 -0400 (EDT) +Received: from mail.libertyrms.com (unknown [209.167.124.227]) + by postgresql.org (Postfix) with ESMTP id 2446F475A80 + for ; + Thu, 8 May 2003 07:20:17 -0400 (EDT) +Received: from [10.1.2.130] (helo=dba2) + by mail.libertyrms.com with esmtp (Exim 3.22 #3 (Debian)) + id 19DjRk-0008Rb-00 + for ; Thu, 08 May 2003 07:20:20 -0400 +Received: by dba2 (Postfix, from userid 1019) + id 17714CF78; Thu, 8 May 2003 07:20:20 -0400 (EDT) +Date: Thu, 8 May 2003 07:20:20 -0400 +From: Andrew Sullivan +To: pgsql-performance@postgresql.org +Subject: Re: An unresolved performance problem. +Message-ID: <20030508112020.GB3728@libertyrms.info> +Mail-Followup-To: Andrew Sullivan , + pgsql-performance@postgresql.org +References: + +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: +User-Agent: Mutt/1.5.3i +X-Spam-Status: No, hits=-34.8 required=5.0 + tests=BAYES_10,EMAIL_ATTRIBUTION,IN_REP_TO,REFERENCES, + REPLY_WITH_QUOTES,USER_AGENT_MUTT autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/102 +X-Sequence-Number: 1881 + +On Thu, May 08, 2003 at 10:48:52AM -0200, Achilleus Mantzios wrote: + +> That is, we have a marginal decrease of the total cost +> for the index scan when random_page_cost = 1.9, +> whereas the "real cost" in the means of total runtime +> ranges from 218 msecs (seq scan) to 19 msecs (index scan). +> (is it sane?) + +You're right that the problem is the poor estimate of the cost of +that selection. I recall you mentioning that you'd expanded the +statistics on the field, but I don't recall to what. I know that +under some circumstances, you _really_ have to increase the stats to +get a meaningful sample. + +A + +-- +---- +Andrew Sullivan 204-4141 Yonge Street +Liberty RMS Toronto, Ontario Canada + M2P 2A8 + +1 416 646 3304 x110 + + +From pgsql-bugs-owner@postgresql.org Thu May 8 03:05:20 2003 +X-Original-To: pgsql-bugs@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP + id 79A4947630B; Thu, 8 May 2003 03:05:18 -0400 (EDT) +Received: from matrix.gatewaynet.com (unknown [217.19.69.50]) + by postgresql.org (Postfix) with ESMTP + id 0654A4761BC; Thu, 8 May 2003 03:05:17 -0400 (EDT) +Received: from matrix.gatewaynet.com (localhost [127.0.0.1]) + by matrix.gatewaynet.com (8.12.5/8.12.5) with ESMTP id h48C9l1s000476; + Thu, 8 May 2003 10:09:47 -0200 +Received: from localhost (achill@localhost) + by matrix.gatewaynet.com (8.12.5/8.12.5/Submit) with ESMTP id + h48C9lOo000472; Thu, 8 May 2003 10:09:47 -0200 +Date: Thu, 8 May 2003 10:09:47 -0200 (GMT+2) +From: Achilleus Mantzios +To: Bernd von den Brincken +Cc: pgsql-sql@postgresql.org, +Subject: Re: [SQL] An unresolved performance problem. +In-Reply-To: <3EB96544.6010606@asa.de> +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-Spam-Status: No, hits=-38.6 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + QUOTE_TWICE_1,REPLY_WITH_QUOTES,SIGNATURE_LONG_DENSE, + USER_AGENT_PINE autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/29 +X-Sequence-Number: 5990 + +On Wed, 7 May 2003, Bernd von den Brincken wrote: + +> Hi, +> +> Mendola Gaetano wrote: +> +> > ... +> > +> >I seen around a lot of questions are remaining without any reply, +> >may be in this period the guys like Tom Lane are too busy. ... +> > +> > +> And we should remember that this is still free, open source software - +> so we have no right to claim _any_ support whatsoever. +> So thanks a lot to the PostgreSQL team for all the hard work that has +> been and is being put into this software. + +I fully support your statement. +Also i must add that the confidense of the longterm/power users +is am essential element that applies to all software +(open source included) + +> +> // Bernd vdB +> +> +> ---------------------------(end of broadcast)--------------------------- +> TIP 6: Have you searched our list archives? +> +> http://archives.postgresql.org +> + +-- +================================================================== +Achilleus Mantzios +S/W Engineer +IT dept +Dynacom Tankers Mngmt +Nikis 4, Glyfada +Athens 16610 +Greece +tel: +30-210-8981112 +fax: +30-210-8981877 +email: achill@matrix.gatewaynet.com + mantzios@softlab.ece.ntua.gr + + +From pgsql-performance-owner@postgresql.org Thu May 8 03:44:12 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 74CE247612F + for ; + Thu, 8 May 2003 03:44:10 -0400 (EDT) +Received: from matrix.gatewaynet.com (unknown [217.19.69.50]) + by postgresql.org (Postfix) with ESMTP id 72643475EC9 + for ; + Thu, 8 May 2003 03:44:08 -0400 (EDT) +Received: from matrix.gatewaynet.com (localhost [127.0.0.1]) + by matrix.gatewaynet.com (8.12.5/8.12.5) with ESMTP id h48Cmq1s000619 + for ; Thu, 8 May 2003 10:48:52 -0200 +Received: from localhost (achill@localhost) + by matrix.gatewaynet.com (8.12.5/8.12.5/Submit) with ESMTP id + h48Cmq78000615 + for ; Thu, 8 May 2003 10:48:52 -0200 +Date: Thu, 8 May 2003 10:48:52 -0200 (GMT+2) +From: Achilleus Mantzios +To: pgsql-performance@postgresql.org +Subject: Re: An unresolved performance problem. +In-Reply-To: +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-Spam-Status: No, hits=-14.7 required=5.0 + tests=BAYES_10,IN_REP_TO,USER_AGENT_PINE + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/101 +X-Sequence-Number: 1880 + + +About the unanswered questions problem: + +There seems to be a trade off between +describing a problem as minimalistically +as possible so that it gets the chance +of being read (on one hand) and giving +the full details, explain analyze, +pg_class,pg_statistic data (on the other hand), +in order to be more informational. +At the extreme cases: provide a "query slow" post +on one hand and provide the whole pg_dump +on the other. +The problem is that in the first case +"he hasnt given any real info" +and in the second case every one is avoiding +reading 10 pages of data. +I think i must have missed the "golden intersection". + +Well now to the point. + +The problem was dealt using a hint +from Mr Kenneth Marshall. +Setting random_page_cost = 1.9 +resulted in a smaller cost calculation +for the index than the seq scan. + +Now the question is: +With random_page_cost = 4 (default) +i get +dynacom=# EXPLAIN ANALYZE select count(*) from status where +assettable='vessels' and appname='ISM PMS' and apptblname='items' and +status='warn' and isvalid and assetidval=57; + +QUERY PLAN + +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + Aggregate (cost=1669.01..1669.01 rows=1 width=0) (actual +time=258.45..258.46 rows=1 loops=1) + -> Seq Scan on status (cost=0.00..1668.62 rows=158 width=0) (actual +time=171.26..258.38 rows=42 loops=1) + Filter: ((assettable = 'vessels'::character varying) AND (appname += 'ISM PMS'::character varying) AND (apptblname = 'items'::character +varying) AND (status = 'warn'::character varying) AND isvalid AND +(assetidval = 57)) + Total runtime: 258.52 msec +(4 rows) + +dynacom=# + +And with random_page_cost = 1.9, i get +dynacom=# EXPLAIN ANALYZE select count(*) from status where +assettable='vessels' and appname='ISM PMS' and apptblname='items' and +status='warn' and isvalid and assetidval=57; + +QUERY PLAN + +----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + Aggregate (cost=1650.39..1650.39 rows=1 width=0) (actual +time=18.86..18.86 rows=1 loops=1) + -> Index Scan using status_all on status (cost=0.00..1650.04 rows=139 +width=0) (actual time=18.26..18.77 rows=42 loops=1) + Index Cond: ((assettable = 'vessels'::character varying) AND +(assetidval = 57) AND (appname = 'ISM PMS'::character varying) AND +(apptblname = 'items'::character varying) AND (status = 'warn'::character +varying)) + Filter: isvalid + Total runtime: 18.94 msec +(5 rows) + +dynacom=# + +That is, we have a marginal decrease of the total cost +for the index scan when random_page_cost = 1.9, +whereas the "real cost" in the means of total runtime +ranges from 218 msecs (seq scan) to 19 msecs (index scan). +(is it sane?) +----- +(returning to the general -performance posting problem) +Altho a FAQ with "please do VACUUM ANALYZE before +posting to the lists" is something usefull in general, +it does not provide enuf info for the users, +at least for "corner cases" (as a fellow pgsql'er +wrote) + +I think in order to stop this undesirable phaenomenon +of flooding the lists, the best way is to provide +the actual algorithms that govern the planer/optimiser, +in a form of lets say "advanced documentation". + +(If there is such thing, i am sorry but i wasnt +told so by anyone.) + +Otherwise there are gonna be unhappy core hackers +(having to examine each case individually) +and of course bad performing systems on the users side. + +P.S. + +Of course there are newbies in postgresql, +ofcourse there are people who think that +"support" is to be taken for granted, +ofcourse there are people with minimal +programming/hacking skills, +but i think the average "power user" +altho he didnt get the chance to +follow the "hard core" hacking path +in his life, he has a CompScience BSc or MSc, +and can deal with both complicated algoritmic +issues and source code reading, +and morever on the average he likes to +give and receive respect. + +(not to mention that he is the person who can +"spread the word" based on strong arguments +and solid ground) + +Thats my 20 drachmas. + +================================================================== +Achilleus Mantzios +S/W Engineer +IT dept +Dynacom Tankers Mngmt +Nikis 4, Glyfada +Athens 16610 +Greece +tel: +30-210-8981112 +fax: +30-210-8981877 +email: achill@matrix.gatewaynet.com + mantzios@softlab.ece.ntua.gr + + +From pgsql-performance-owner@postgresql.org Thu May 8 10:42:55 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id DC9D14763C2 + for ; + Thu, 8 May 2003 10:42:51 -0400 (EDT) +Received: from sss.pgh.pa.us (unknown [192.204.191.242]) + by postgresql.org (Postfix) with ESMTP id 9BC1E474E4F + for ; + Thu, 8 May 2003 10:42:50 -0400 (EDT) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h48EgtU6020337 + for ; + Thu, 8 May 2003 10:42:55 -0400 (EDT) +To: pgsql-performance@postgresql.org +Subject: Re: An unresolved performance problem. +In-reply-to: <20030508112020.GB3728@libertyrms.info> +References: + + <20030508112020.GB3728@libertyrms.info> +Comments: In-reply-to Andrew Sullivan + message dated "Thu, 08 May 2003 07:20:20 -0400" +Date: Thu, 08 May 2003 10:42:55 -0400 +Message-ID: <20336.1052404975@sss.pgh.pa.us> +From: Tom Lane +X-Spam-Status: No, hits=-32.3 required=5.0 + tests=BAYES_00,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REFERENCES,REPLY_WITH_QUOTES autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/103 +X-Sequence-Number: 1882 + +Andrew Sullivan writes: +> On Thu, May 08, 2003 at 10:48:52AM -0200, Achilleus Mantzios wrote: +>> That is, we have a marginal decrease of the total cost +>> for the index scan when random_page_cost = 1.9, +>> whereas the "real cost" in the means of total runtime +>> ranges from 218 msecs (seq scan) to 19 msecs (index scan). +>> (is it sane?) + +> You're right that the problem is the poor estimate of the cost of +> that selection. + +Are the table and index orders the same? Oliver Elphick pointed out +awhile ago that we're doing a bad job of index order correlation +estimation for multi-column indexes --- the correlation is taken to +be much lower than it should be. But if the correlation is near +zero anyway then this wouldn't explain Achilleus' problem... + + regards, tom lane + + +From pgsql-bugs-owner@postgresql.org Thu May 15 12:06:22 2003 +X-Original-To: pgsql-bugs@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id C4673476560 + for ; Thu, 8 May 2003 10:45:16 -0400 (EDT) +Received: from phaedrusdeinus.org (dsl092-130-239.chi1.dsl.speakeasy.net + [66.92.130.239]) by postgresql.org (Postfix) with SMTP id 3115E476403 + for ; Thu, 8 May 2003 10:45:14 -0400 (EDT) +Received: (qmail 43937 invoked by uid 1001); 8 May 2003 14:47:38 -0000 +Date: Thu, 8 May 2003 09:47:38 -0500 +From: johnnnnnn +To: Sean Chittenden +Cc: pgsql-sql@postgresql.org, pgsql-performance@postgresql.org, + pgsql-bugs@postgresql.org +Subject: Re: [PERFORM] [SQL] Unanswered Questions WAS: An unresolved + performance problem. +Message-ID: <20030508144738.GA18774@performics.com> +References: + <17063.1052367200@sss.pgh.pa.us> + <20030508045749.GV49916@perrin.int.nxad.com> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: <20030508045749.GV49916@perrin.int.nxad.com> +User-Agent: Mutt/1.5.1i +X-Spam-Status: No, hits=-38.0 required=5.0 + tests=BAYES_10,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REFERENCES,REPLY_WITH_QUOTES,USER_AGENT_MUTT version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/42 +X-Sequence-Number: 6003 + +On Wed, May 07, 2003 at 09:57:49PM -0700, Sean Chittenden wrote: +> I hate to point this out, but "TIP 4" is getting a bit old and the 6 +> tips that we throw out to probably about 40K people about 1-200 +> times a day have probably reached saturation. Without looking at +> the archives, I bet anyone a shot of good scotch that, it's probably +> pretty infrequent that people don't kill -9 their postmasters. +> +> Any chance we could flush out the TIPs at the bottom to include, +> "VACUUM ANALYZE your database regularly," or "When reporting a +> problem, include the output from EXPLAIN [query]," or "ANALYZE +> tables before examining the output from an EXPLAIN [query]," or +> "Visit [url] for a tutorial on (schemas|triggers|views)." + +Better yet, have TIPs that are appropriate to the subscribed +list. -performance has different posting guidelines, things to try, +etc. than does -bugs, than does -sql (than does -hackers, than does +-interfaces, ...). + +I don't know how feasible it is to separate them out, but i think it's +worth looking into. + +-johnnnnnnnnnnn + + +From pgsql-performance-owner@postgresql.org Thu May 8 11:36:32 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 3BA01476521 + for ; + Thu, 8 May 2003 11:36:26 -0400 (EDT) +Received: from mail01.stbernard.com (mail01.stbernard.com [64.154.93.162]) + by postgresql.org (Postfix) with ESMTP id 82E2B476513 + for ; + Thu, 8 May 2003 11:36:22 -0400 (EDT) +X-MimeOLE: Produced By Microsoft Exchange V6.0.6249.0 +content-class: urn:content-classes:message +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: quoted-printable +Subject: Type casting and indexes +Date: Thu, 8 May 2003 08:36:27 -0700 +Message-ID: +X-MS-Has-Attach: +X-MS-TNEF-Correlator: +Thread-Topic: Type casting and indexes +Thread-Index: AcMVd5bD0/WPT/qgSwur0MjM9J+9gQ== +From: "David Olbersen" +To: +X-Spam-Status: No, hits=-6.6 required=5.0 + tests=BAYES_01 + version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/105 +X-Sequence-Number: 1884 + +I hope this hasn't been answered before, I've looked at the docs here: + http://www.postgresql.org/docs/view.php?version=3D7.3&idoc=3D1&file=3Dind= +ex.html + +Anyway, I've found a (bug|feature|standard?) with type casting and index us= +age. + +I've got a table with a column that's a timestamp with time zone. This colu= +mn is indexed. If I issue the "normal" query of:=20 + + SELECT count(*) FROM foo WHERE bar > '2003-05-05':;timestamp + +I get the following EXPLAIN ANALYZE output: + +urldb=3D> explain select count(*) from foo where bar > '2003-05-05'::timest= +amp; + QUERY PLAN=20=20=20=20=20=20=20=20=20=20=20=20= +=20=20=20=20=20=20=20=20=20 +------------------------------------------------------------------------ + Aggregate (cost=3D89960.75..89960.75 rows=3D1 width=3D0) (actual time=3D + 56706.58..56706.58 rows=3D1 loops=3D1) + -> Seq Scan on urlinfo (cost=3D0.00..87229.45 rows=3D1092521 width=3D0= +) (actual=20 + time=3D25.37..56537.86 rows=3D27490 loops=3D1) + Filter: (ratedon > ('2003-05-05 00:00:00'::timestamp without time= +=20 + zone)::timestamp with time zone) + Total runtime: 56706.67 msec + +So it seems that the type conversion is killing the use of the index, even = +though the type conversion has to happen for the condition to be tested. + +If I change this query slightly, by casting to timestamptz, I get the follo= +wing EXPLAIN ANALYZE output: + + QUERY PLAN=20=20=20=20=20=20=20=20=20=20=20= +=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 +------------------------------------------------------------------------- + Aggregate (cost=3D38609.70..38609.70 rows=3D1 width=3D0) (actual time=3D5= +47.58..547.58=20 + rows=3D1 loops=3D1) + -> Index Scan using urlinfo_on on urlinfo (cost=3D0.00..38578.97 rows= +=3D12295=20 + width=3D0) (actual time=3D0.18..381.95 rows=3D27490 loops=3D1) + Index Cond: (ratedon > '2003-05-05 00:00:00-07'::timestamp with ti= +me=20 + zone) + Total runtime: 548.17 msec + +That's much better! Is this the way it's supposed to work? + +-------------------------- +David Olbersen=20 +iGuard Engineer +11415 West Bernardo Court=20 +San Diego, CA 92127=20 +1-858-676-2277 x2152 + + +From pgsql-performance-owner@postgresql.org Thu May 8 12:13:31 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 97221476393 + for ; + Thu, 8 May 2003 12:13:29 -0400 (EDT) +Received: from megazone.bigpanda.com (megazone.bigpanda.com [63.150.15.178]) + by postgresql.org (Postfix) with ESMTP id B9435474E4F + for ; + Thu, 8 May 2003 12:13:24 -0400 (EDT) +Received: by megazone.bigpanda.com (Postfix, from userid 1001) + id B5869D605; Thu, 8 May 2003 09:13:29 -0700 (PDT) +Received: from localhost (localhost [127.0.0.1]) + by megazone.bigpanda.com (Postfix) with ESMTP + id AB36C5C0A; Thu, 8 May 2003 09:13:29 -0700 (PDT) +Date: Thu, 8 May 2003 09:13:29 -0700 (PDT) +From: Stephan Szabo +To: David Olbersen +Cc: +Subject: Re: Type casting and indexes +In-Reply-To: +Message-ID: <20030508090101.K43697-100000@megazone23.bigpanda.com> +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-Spam-Status: No, hits=-26.0 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REPLY_WITH_QUOTES autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/106 +X-Sequence-Number: 1885 + +On Thu, 8 May 2003, David Olbersen wrote: + +> Anyway, I've found a (bug|feature|standard?) with type casting and index usage. +> +> I've got a table with a column that's a timestamp with time zone. This +> column is indexed. If I issue the "normal" query of: +> +> SELECT count(*) FROM foo WHERE bar > '2003-05-05':;timestamp +> +> I get the following EXPLAIN ANALYZE output: +> +> urldb=> explain select count(*) from foo where bar > '2003-05-05'::timestamp; +> QUERY PLAN +> ------------------------------------------------------------------------ +> Aggregate (cost=89960.75..89960.75 rows=1 width=0) (actual time= +> 56706.58..56706.58 rows=1 loops=1) +> -> Seq Scan on urlinfo (cost=0.00..87229.45 rows=1092521 width=0) (actual +> time=25.37..56537.86 rows=27490 loops=1) +> Filter: (ratedon > ('2003-05-05 00:00:00'::timestamp without time +> zone)::timestamp with time zone) +> Total runtime: 56706.67 msec +> +> So it seems that the type conversion is killing the use of the index, +> even though the type conversion has to happen for the condition to be +> tested. + +IIRC, timestamp->timestamptz is not considered to give a constant value +(ie, is not stable) probably since it depends on timezone settings which +could be changed (for example by a function) during the query, so for each +row the conversion from '2003-05-05 00:00:00'::timestamp without time zone +to a timestamp with time zone can potentially give a different answer. + + +From pgsql-bugs-owner@postgresql.org Thu May 15 12:06:19 2003 +X-Original-To: pgsql-bugs@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP + id 44B574765C1; Thu, 8 May 2003 12:30:47 -0400 (EDT) +Received: from mail1.ihs.com (mail1.ihs.com [170.207.70.222]) + by postgresql.org (Postfix) with ESMTP + id 5949D47592C; Thu, 8 May 2003 12:30:45 -0400 (EDT) +Received: from css120.ihs.com (css120.ihs.com [170.207.105.120]) + by mail1.ihs.com (8.12.9/8.12.9) with ESMTP id h48GTv5g026325; + Thu, 8 May 2003 10:29:58 -0600 (MDT) +Date: Thu, 8 May 2003 10:20:19 -0600 (MDT) +From: "scott.marlowe" +To: johnnnnnn +Cc: Sean Chittenden , + , , + +Subject: Re: [PERFORM] [SQL] Unanswered Questions WAS: An unresolved + performance +In-Reply-To: <20030508144738.GA18774@performics.com> +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-MailScanner: Found to be clean +X-MailScanner-SpamCheck: +X-Spam-Status: No, hits=-31.7 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REPLY_WITH_QUOTES,USER_AGENT_PINE autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/41 +X-Sequence-Number: 6002 + +On Thu, 8 May 2003, johnnnnnn wrote: + +> On Wed, May 07, 2003 at 09:57:49PM -0700, Sean Chittenden wrote: +> > I hate to point this out, but "TIP 4" is getting a bit old and the 6 +> > tips that we throw out to probably about 40K people about 1-200 +> > times a day have probably reached saturation. Without looking at +> > the archives, I bet anyone a shot of good scotch that, it's probably +> > pretty infrequent that people don't kill -9 their postmasters. +> > +> > Any chance we could flush out the TIPs at the bottom to include, +> > "VACUUM ANALYZE your database regularly," or "When reporting a +> > problem, include the output from EXPLAIN [query]," or "ANALYZE +> > tables before examining the output from an EXPLAIN [query]," or +> > "Visit [url] for a tutorial on (schemas|triggers|views)." +> +> Better yet, have TIPs that are appropriate to the subscribed +> list. -performance has different posting guidelines, things to try, +> etc. than does -bugs, than does -sql (than does -hackers, than does +> -interfaces, ...). +> +> I don't know how feasible it is to separate them out, but i think it's +> worth looking into. + +Agreed. + +Also, some tips might well cross over, like say, vacuum and analyze +regularly. Hmmm. Sounds like a job for a relational database :-) + + +From pgsql-performance-owner@postgresql.org Thu May 8 12:25:06 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 642B3476141 + for ; + Thu, 8 May 2003 12:25:02 -0400 (EDT) +Received: from sss.pgh.pa.us (unknown [192.204.191.242]) + by postgresql.org (Postfix) with ESMTP id B3CC747592C + for ; + Thu, 8 May 2003 12:25:01 -0400 (EDT) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h48GP7U6020979; + Thu, 8 May 2003 12:25:07 -0400 (EDT) +To: "David Olbersen" +Cc: pgsql-performance@postgresql.org +Subject: Re: Type casting and indexes +In-reply-to: +References: +Comments: In-reply-to "David Olbersen" + message dated "Thu, 08 May 2003 08:36:27 -0700" +Date: Thu, 08 May 2003 12:25:07 -0400 +Message-ID: <20978.1052411107@sss.pgh.pa.us> +From: Tom Lane +X-Spam-Status: No, hits=-29.3 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,REFERENCES, + REPLY_WITH_QUOTES autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/107 +X-Sequence-Number: 1886 + +"David Olbersen" writes: +> So it seems that the type conversion is killing the use of the index, even though the type conversion has to happen for the condition to be tested. + +Seems like I just answered this yesterday ;-) + +Note the difference in the number of estimated rows in the two explains. +The reason is that the timestamptz conversion is not a constant and so +the planner can't get a good estimate of the number of rows that will +satisfy it. (And the reason it's not a constant is that it depends on +SET TIMEZONE.) + +Bottom line: declare the constant correctly. Or at least don't +gratuitously cast it to the wrong thing. + + regards, tom lane + + +From pgsql-performance-owner@postgresql.org Thu May 8 18:35:16 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id CC791476141 + for ; + Thu, 8 May 2003 18:35:15 -0400 (EDT) +Received: from sss.pgh.pa.us (unknown [192.204.191.242]) + by postgresql.org (Postfix) with ESMTP id 1D307474E4F + for ; + Thu, 8 May 2003 18:35:14 -0400 (EDT) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h48MZEU6017014; + Thu, 8 May 2003 18:35:14 -0400 (EDT) +To: Stephan Szabo +Cc: David Olbersen , pgsql-performance@postgresql.org +Subject: Re: Type casting and indexes +In-reply-to: <20030508090101.K43697-100000@megazone23.bigpanda.com> +References: <20030508090101.K43697-100000@megazone23.bigpanda.com> +Comments: In-reply-to Stephan Szabo + message dated "Thu, 08 May 2003 09:13:29 -0700" +Date: Thu, 08 May 2003 18:35:14 -0400 +Message-ID: <17013.1052433314@sss.pgh.pa.us> +From: Tom Lane +X-Spam-Status: No, hits=-32.3 required=5.0 + tests=BAYES_00,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REFERENCES,REPLY_WITH_QUOTES autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/109 +X-Sequence-Number: 1888 + +Stephan Szabo writes: +> On Thu, 8 May 2003, David Olbersen wrote: +>> So it seems that the type conversion is killing the use of the index, +>> even though the type conversion has to happen for the condition to be +>> tested. + +> IIRC, timestamp->timestamptz is not considered to give a constant value +> (ie, is not stable) + +No: it is stable, but not immutable, because it depends on SET TIMEZONE. +(Our policy on those is if you change one mid-query, it's unspecified +whether the query will notice or not.) So the query is potentially +indexable. + +The problem here is that instead of seeing a constant, the planner sees +a nonconstant function invocation on the right side of '>', and so it +has to fall back to a default selectivity estimate instead of being able +to extract a reasonable estimate from pg_statistic. The default +estimate is high enough to discourage an indexscan ... + + regards, tom lane + + +From pgsql-performance-owner@postgresql.org Fri May 9 08:31:53 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 1AFA1475AE5 + for ; + Fri, 9 May 2003 08:31:52 -0400 (EDT) +Received: from sss.pgh.pa.us (unknown [192.204.191.242]) + by postgresql.org (Postfix) with ESMTP id 046C0475A80 + for ; + Fri, 9 May 2003 08:31:51 -0400 (EDT) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h49CVkU6029798; + Fri, 9 May 2003 08:31:46 -0400 (EDT) +To: Achilleus Mantzios +Cc: pgsql-performance@postgresql.org +Subject: Re: An unresolved performance problem. +In-reply-to: +References: +Comments: In-reply-to Achilleus Mantzios + message dated "Fri, 09 May 2003 11:00:30 -0200" +Date: Fri, 09 May 2003 08:31:46 -0400 +Message-ID: <29797.1052483506@sss.pgh.pa.us> +From: Tom Lane +X-Spam-Status: No, hits=-32.3 required=5.0 + tests=BAYES_00,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REFERENCES,REPLY_WITH_QUOTES autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/111 +X-Sequence-Number: 1890 + +Achilleus Mantzios writes: +> If so, how can one find the correlation between the ordering +> of a table and a multicolumn index? + +Well, it is surely no better than the correlation of the index's +first column --- what is that? + + regards, tom lane + + +From pgsql-performance-owner@postgresql.org Fri May 9 03:55:34 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 9F27C475EC9 + for ; + Fri, 9 May 2003 03:55:33 -0400 (EDT) +Received: from matrix.gatewaynet.com (unknown [217.19.69.50]) + by postgresql.org (Postfix) with ESMTP id 52BF0475A80 + for ; + Fri, 9 May 2003 03:55:25 -0400 (EDT) +Received: from matrix.gatewaynet.com (localhost [127.0.0.1]) + by matrix.gatewaynet.com (8.12.5/8.12.5) with ESMTP id h49D0V1s006330; + Fri, 9 May 2003 11:00:31 -0200 +Received: from localhost (achill@localhost) + by matrix.gatewaynet.com (8.12.5/8.12.5/Submit) with ESMTP id + h49D0V9w006326; Fri, 9 May 2003 11:00:31 -0200 +Date: Fri, 9 May 2003 11:00:30 -0200 (GMT+2) +From: Achilleus Mantzios +To: Tom Lane +Cc: pgsql-performance@postgresql.org +Subject: Re: An unresolved performance problem. +In-Reply-To: <20336.1052404975@sss.pgh.pa.us> +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-Spam-Status: No, hits=-38.6 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + QUOTE_TWICE_1,REPLY_WITH_QUOTES,SIGNATURE_LONG_DENSE, + USER_AGENT_PINE autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/110 +X-Sequence-Number: 1889 + +On Thu, 8 May 2003, Tom Lane wrote: + +> Andrew Sullivan writes: +> > On Thu, May 08, 2003 at 10:48:52AM -0200, Achilleus Mantzios wrote: +> >> That is, we have a marginal decrease of the total cost +> >> for the index scan when random_page_cost = 1.9, +> >> whereas the "real cost" in the means of total runtime +> >> ranges from 218 msecs (seq scan) to 19 msecs (index scan). +> >> (is it sane?) +> +> > You're right that the problem is the poor estimate of the cost of +> > that selection. +> +> Are the table and index orders the same? Oliver Elphick pointed out +> awhile ago that we're doing a bad job of index order correlation +> estimation for multi-column indexes --- the correlation is taken to +> be much lower than it should be. But if the correlation is near +> zero anyway then this wouldn't explain Achilleus' problem... + +Please correct me if i am wrong. (i think i probably am) +The correlation value in pg_statistc for a column refers to the +correlation between +the ordering of a table's tuples and the ordering of that column. +(So it plays some role in determining the execution plan +if an index exists on that column. Also CLUSTERing a +single-column index on the table makes reordering +of the table according to that index, that is the ordering of that +column). + +Is that correct?? + + +If so, how can one find the correlation between the ordering +of a table and a multicolumn index? + + + +> +> regards, tom lane +> +> +> ---------------------------(end of broadcast)--------------------------- +> TIP 6: Have you searched our list archives? +> +> http://archives.postgresql.org +> + +-- +================================================================== +Achilleus Mantzios +S/W Engineer +IT dept +Dynacom Tankers Mngmt +Nikis 4, Glyfada +Athens 16610 +Greece +tel: +30-210-8981112 +fax: +30-210-8981877 +email: achill@matrix.gatewaynet.com + mantzios@softlab.ece.ntua.gr + + +From pgsql-performance-owner@postgresql.org Fri May 9 09:08:01 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 3DB48475AE5 + for ; + Fri, 9 May 2003 09:08:00 -0400 (EDT) +Received: from sss.pgh.pa.us (unknown [192.204.191.242]) + by postgresql.org (Postfix) with ESMTP id 0E0A0475A80 + for ; + Fri, 9 May 2003 09:07:59 -0400 (EDT) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h49D81U6000152; + Fri, 9 May 2003 09:08:01 -0400 (EDT) +To: Achilleus Mantzios +Cc: pgsql-performance@postgresql.org +Subject: Re: An unresolved performance problem. +In-reply-to: +References: +Comments: In-reply-to Achilleus Mantzios + message dated "Fri, 09 May 2003 16:11:49 -0200" +Date: Fri, 09 May 2003 09:08:00 -0400 +Message-ID: <151.1052485680@sss.pgh.pa.us> +From: Tom Lane +X-Spam-Status: No, hits=-32.3 required=5.0 + tests=BAYES_00,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REFERENCES,REPLY_WITH_QUOTES autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/113 +X-Sequence-Number: 1892 + +Achilleus Mantzios writes: +> On Fri, 9 May 2003, Tom Lane wrote: +>> Achilleus Mantzios writes: +>>> If so, how can one find the correlation between the ordering +>>> of a table and a multicolumn index? +>> +>> Well, it is surely no better than the correlation of the index's +>> first column --- what is that? + +> it is 1 + +Well, that's suggestive, isn't it? What about the remaining columns? + + regards, tom lane + + +From pgsql-performance-owner@postgresql.org Fri May 9 09:30:11 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 26389475EF0 + for ; + Fri, 9 May 2003 09:30:11 -0400 (EDT) +Received: from sss.pgh.pa.us (unknown [192.204.191.242]) + by postgresql.org (Postfix) with ESMTP id 25524475EC9 + for ; + Fri, 9 May 2003 09:30:10 -0400 (EDT) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h49DUCU6000250; + Fri, 9 May 2003 09:30:12 -0400 (EDT) +To: Achilleus Mantzios +Cc: pgsql-performance@postgresql.org +Subject: Re: An unresolved performance problem. +In-reply-to: +References: +Comments: In-reply-to Achilleus Mantzios + message dated "Fri, 09 May 2003 16:22:23 -0200" +Date: Fri, 09 May 2003 09:30:12 -0400 +Message-ID: <249.1052487012@sss.pgh.pa.us> +From: Tom Lane +X-Spam-Status: No, hits=-32.5 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REFERENCES,REPLY_WITH_QUOTES autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/115 +X-Sequence-Number: 1894 + +Achilleus Mantzios writes: +> On Fri, 9 May 2003, Tom Lane wrote: +>> Well, that's suggestive, isn't it? What about the remaining columns? + +> The index is defined as: + +> status_all btree (assettable, assetidval, appname, apptblname, status, +> isvalid) + +> And correlations are: + +> attname | correlation +> -------------+------------- +> assettable | 1 +> assetidval | 0.125902 +> appname | 0.942771 +> apptblname | 0.928761 +> status | 0.443405 +> isvalid | 0.970531 + +Actually, thinking twice about it, I'm not sure if the correlations of +the righthand columns mean anything. If the table were perfectly +ordered by the index, you'd expect righthand values to cycle through +their range for each lefthand value, and so they'd show low +correlations. + +The fact that most of the columns show high correlation makes me think +that they are not independent --- is that right? + +But anyway, I'd say that yes this table is probably quite well ordered +by the index. You could just visually compare the results of + +select * from tab + +select * from tab + order by assettable, assetidval, appname, apptblname, status, isvalid + +to confirm this. + +And that tells us where the problem is: the code is estimating a low +index correlation where it should be estimating a high one. If you +don't mind running a nonstandard version of Postgres, you could try +making btcostestimate() in src/backend/utils/adt/selfuncs.c estimate +the indexCorrelation as just varCorrelation, instead of +varCorrelation / nKeys. This is doubtless an overcorrection in the +other direction (which is why it hasn't been done in the official +sources) but it's probably better than what's there, at least for +your purposes. + + regards, tom lane + + +From pgsql-performance-owner@postgresql.org Fri May 9 09:06:40 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 7BBB0475AE5 + for ; + Fri, 9 May 2003 09:06:38 -0400 (EDT) +Received: from matrix.gatewaynet.com (unknown [217.19.69.50]) + by postgresql.org (Postfix) with ESMTP id 0E72C475A80 + for ; + Fri, 9 May 2003 09:06:35 -0400 (EDT) +Received: from matrix.gatewaynet.com (localhost [127.0.0.1]) + by matrix.gatewaynet.com (8.12.5/8.12.5) with ESMTP id h49IBn1s007457; + Fri, 9 May 2003 16:11:49 -0200 +Received: from localhost (achill@localhost) + by matrix.gatewaynet.com (8.12.5/8.12.5/Submit) with ESMTP id + h49IBngw007453; Fri, 9 May 2003 16:11:49 -0200 +Date: Fri, 9 May 2003 16:11:49 -0200 (GMT+2) +From: Achilleus Mantzios +To: Tom Lane +Cc: pgsql-performance@postgresql.org +Subject: Re: An unresolved performance problem. +In-Reply-To: <29797.1052483506@sss.pgh.pa.us> +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-Spam-Status: No, hits=-38.4 required=5.0 + tests=BAYES_00,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + QUOTE_TWICE_1,REPLY_WITH_QUOTES,SIGNATURE_LONG_DENSE, + USER_AGENT_PINE autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/112 +X-Sequence-Number: 1891 + +On Fri, 9 May 2003, Tom Lane wrote: + +> Achilleus Mantzios writes: +> > If so, how can one find the correlation between the ordering +> > of a table and a multicolumn index? +> +> Well, it is surely no better than the correlation of the index's +> first column --- what is that? + +it is 1 + +> +> regards, tom lane +> + +-- +================================================================== +Achilleus Mantzios +S/W Engineer +IT dept +Dynacom Tankers Mngmt +Nikis 4, Glyfada +Athens 16610 +Greece +tel: +30-210-8981112 +fax: +30-210-8981877 +email: achill@matrix.gatewaynet.com + mantzios@softlab.ece.ntua.gr + + +From pgsql-performance-owner@postgresql.org Fri May 9 09:17:21 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 03118475AE5 + for ; + Fri, 9 May 2003 09:17:21 -0400 (EDT) +Received: from matrix.gatewaynet.com (unknown [217.19.69.50]) + by postgresql.org (Postfix) with ESMTP id EA72C475A80 + for ; + Fri, 9 May 2003 09:17:09 -0400 (EDT) +Received: from matrix.gatewaynet.com (localhost [127.0.0.1]) + by matrix.gatewaynet.com (8.12.5/8.12.5) with ESMTP id h49IMN1s007506; + Fri, 9 May 2003 16:22:23 -0200 +Received: from localhost (achill@localhost) + by matrix.gatewaynet.com (8.12.5/8.12.5/Submit) with ESMTP id + h49IMNaq007502; Fri, 9 May 2003 16:22:23 -0200 +Date: Fri, 9 May 2003 16:22:23 -0200 (GMT+2) +From: Achilleus Mantzios +To: Tom Lane +Cc: pgsql-performance@postgresql.org +Subject: Re: An unresolved performance problem. +In-Reply-To: <151.1052485680@sss.pgh.pa.us> +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-Spam-Status: No, hits=-38.4 required=5.0 + tests=BAYES_00,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + QUOTE_TWICE_1,REPLY_WITH_QUOTES,SIGNATURE_LONG_DENSE, + USER_AGENT_PINE autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/114 +X-Sequence-Number: 1893 + +On Fri, 9 May 2003, Tom Lane wrote: + +> >> Well, it is surely no better than the correlation of the index's +> >> first column --- what is that? +> +> > it is 1 +> +> Well, that's suggestive, isn't it? What about the remaining columns? + +The index is defined as: + +status_all btree (assettable, assetidval, appname, apptblname, status, +isvalid) + +And correlations are: + + attname | correlation +-------------+------------- + assettable | 1 + assetidval | 0.125902 + appname | 0.942771 + apptblname | 0.928761 + status | 0.443405 + isvalid | 0.970531 + +> +> regards, tom lane +> + +-- +================================================================== +Achilleus Mantzios +S/W Engineer +IT dept +Dynacom Tankers Mngmt +Nikis 4, Glyfada +Athens 16610 +Greece +tel: +30-210-8981112 +fax: +30-210-8981877 +email: achill@matrix.gatewaynet.com + mantzios@softlab.ece.ntua.gr + + +From pgsql-performance-owner@postgresql.org Fri May 9 10:08:49 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id C7D19475B99 + for ; + Fri, 9 May 2003 10:08:46 -0400 (EDT) +Received: from matrix.gatewaynet.com (unknown [217.19.69.50]) + by postgresql.org (Postfix) with ESMTP id 2D467475B85 + for ; + Fri, 9 May 2003 10:08:44 -0400 (EDT) +Received: from matrix.gatewaynet.com (localhost [127.0.0.1]) + by matrix.gatewaynet.com (8.12.5/8.12.5) with ESMTP id h49JE01s007700; + Fri, 9 May 2003 17:14:00 -0200 +Received: from localhost (achill@localhost) + by matrix.gatewaynet.com (8.12.5/8.12.5/Submit) with ESMTP id + h49JDxRD007696; Fri, 9 May 2003 17:14:00 -0200 +Date: Fri, 9 May 2003 17:13:59 -0200 (GMT+2) +From: Achilleus Mantzios +To: Tom Lane +Cc: pgsql-performance@postgresql.org +Subject: Re: An unresolved performance problem. +In-Reply-To: <249.1052487012@sss.pgh.pa.us> +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-Spam-Status: No, hits=-38.6 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + QUOTE_TWICE_1,REPLY_WITH_QUOTES,SIGNATURE_LONG_DENSE, + USER_AGENT_PINE autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/116 +X-Sequence-Number: 1895 + +On Fri, 9 May 2003, Tom Lane wrote: + +> Achilleus Mantzios writes: +> > On Fri, 9 May 2003, Tom Lane wrote: +> >> Well, that's suggestive, isn't it? What about the remaining columns? +> +> > The index is defined as: +> +> > status_all btree (assettable, assetidval, appname, apptblname, status, +> > isvalid) +> +> > And correlations are: +> +> > attname | correlation +> > -------------+------------- +> > assettable | 1 +> > assetidval | 0.125902 +> > appname | 0.942771 +> > apptblname | 0.928761 +> > status | 0.443405 +> > isvalid | 0.970531 +> +> Actually, thinking twice about it, I'm not sure if the correlations of +> the righthand columns mean anything. If the table were perfectly +> ordered by the index, you'd expect righthand values to cycle through +> their range for each lefthand value, and so they'd show low +> correlations. + +When i clustered (on onother system no to spoil the situation) +CLUSTER status_all on status; +i got identical results on the order (see below), +also i got quite high correlations. + + +> +> The fact that most of the columns show high correlation makes me think +> that they are not independent --- is that right? + +Well, assettable,appname,apptblname +have high frequencies on one value, so they can be +regarded as constants. +assetidval, status and isvalid play the most part of the +selectivity. +(i have included the first 3 columns in the status_all index for future +usage) + +> +> But anyway, I'd say that yes this table is probably quite well ordered +> by the index. You could just visually compare the results of +> +> select * from tab +> +> select * from tab +> order by assettable, assetidval, appname, apptblname, status, isvalid +> +> to confirm this. +> + +If the table was ordered by status_all index i would show something like + attname | correlation +-------------+------------- + assettable | 1 + assetidval | 1 + appname | 0.927842 + apptblname | 0.895155 + status | 0.539183 + isvalid | 0.722838 + +In the current (production system) situation, visually, i dont see any +correlation between the two. + +> And that tells us where the problem is: the code is estimating a low +> index correlation where it should be estimating a high one. If you +> don't mind running a nonstandard version of Postgres, you could try +> making btcostestimate() in src/backend/utils/adt/selfuncs.c estimate +> the indexCorrelation as just varCorrelation, instead of +> varCorrelation / nKeys. This is doubtless an overcorrection in the +> other direction (which is why it hasn't been done in the official +> sources) but it's probably better than what's there, at least for +> your purposes. +> + +On the test system, +if i cluster the table according to assetidval the optimiser +uses the index on that column which does a pretty good job. +Even better, if i revert the table to an ordering according +to its id (to spoil the previous effect of the CLUSTER command) +and i set random_page_cost = 2 i get the usage of the better +status_all index. + +This way the correlations seem low, but the expected selectivity +is either way 83 rows. + +Are you suggesting to try the change in src/backend/utils/adt/selfuncs.c +at this exact situation i am on my test system?? (its linux too) + +Thanx a lot! + +> regards, tom lane +> + +-- +================================================================== +Achilleus Mantzios +S/W Engineer +IT dept +Dynacom Tankers Mngmt +Nikis 4, Glyfada +Athens 16610 +Greece +tel: +30-210-8981112 +fax: +30-210-8981877 +email: achill@matrix.gatewaynet.com + mantzios@softlab.ece.ntua.gr + + +From pgsql-performance-owner@postgresql.org Fri May 9 10:19:58 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 8B808475AE5 + for ; + Fri, 9 May 2003 10:19:57 -0400 (EDT) +Received: from matrix.gatewaynet.com (unknown [217.19.69.50]) + by postgresql.org (Postfix) with ESMTP id DE6CC475A80 + for ; + Fri, 9 May 2003 10:19:55 -0400 (EDT) +Received: from matrix.gatewaynet.com (localhost [127.0.0.1]) + by matrix.gatewaynet.com (8.12.5/8.12.5) with ESMTP id h49JPC1s007749; + Fri, 9 May 2003 17:25:12 -0200 +Received: from localhost (achill@localhost) + by matrix.gatewaynet.com (8.12.5/8.12.5/Submit) with ESMTP id + h49JPCOj007745; Fri, 9 May 2003 17:25:12 -0200 +Date: Fri, 9 May 2003 17:25:12 -0200 (GMT+2) +From: Achilleus Mantzios +To: Tom Lane +Cc: pgsql-performance@postgresql.org +Subject: Re: An unresolved performance problem. +In-Reply-To: +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-Spam-Status: No, hits=-21.6 required=5.0 + tests=BAYES_00,IN_REP_TO,SIGNATURE_LONG_DENSE,USER_AGENT_PINE + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/117 +X-Sequence-Number: 1896 + + +I changed +*indexCorrelation = varCorrelation / nKeys; +to +*indexCorrelation = varCorrelation ; + +and i got cost=28.88 +and it beats every other index. + + +-- +================================================================== +Achilleus Mantzios +S/W Engineer +IT dept +Dynacom Tankers Mngmt +Nikis 4, Glyfada +Athens 16610 +Greece +tel: +30-210-8981112 +fax: +30-210-8981877 +email: achill@matrix.gatewaynet.com + mantzios@softlab.ece.ntua.gr + + +From pgsql-general-owner@postgresql.org Sat May 10 11:18:21 2003 +X-Original-To: pgsql-general@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP + id C4DF0475F00; Sat, 10 May 2003 11:18:20 -0400 (EDT) +Received: from news.hub.org (news.hub.org [64.49.215.80]) + by postgresql.org (Postfix) with ESMTP + id 57C114758F1; Sat, 10 May 2003 11:18:15 -0400 (EDT) +Received: by news.hub.org (Postfix, from userid 8) + id 3C38143A89E; Sat, 10 May 2003 11:18:15 -0400 (EDT) +From: "Adam Siegel" +X-Newsgroups: comp.databases.postgresql.hackers, + comp.databases.postgresql.performance, + comp.databases.postgresql.questions +Subject: realtime data inserts +Date: Sat, 10 May 2003 11:25:16 -0400 +Organization: Hub.Org Networking Services (http://www.hub.org) +Lines: 12 +Message-ID: +X-Complaints-To: usenet@news.hub.org +X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 +To: pgsql-hackers@postgresql.org, pgsql-performance@postgresql.org, + pgsql-general@postgresql.org +X-Spam-Status: No, hits=-6.6 required=5.0 + tests=BAYES_01 + version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/320 +X-Sequence-Number: 41975 + +I have realtime data flowing at a rate of 500, 512 byte packets per second. +I want to log the info in a database table with two other columns, one for a +timestamp and one for a name of the packet. The max rate I can achieve is +350 inserts per second on a sun blade 2000. The inserts are grouped in a +transaction and I commit every 1200 records. I am storing the binary data +in a bytea. I am using the libpq conversion function. Not sure if that is +slowing me down. But I think it is the insert not the conversion. + +Any thoughts on how to achive this goal? + + +From pgsql-general-owner@postgresql.org Sat May 10 12:00:15 2003 +X-Original-To: pgsql-general@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP + id ACB16475CE5; Sat, 10 May 2003 12:00:08 -0400 (EDT) +Received: from sss.pgh.pa.us (unknown [192.204.191.242]) + by postgresql.org (Postfix) with ESMTP + id 54EAC4762FE; Sat, 10 May 2003 12:00:03 -0400 (EDT) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h4AG03U6006755; + Sat, 10 May 2003 12:00:03 -0400 (EDT) +To: "Adam Siegel" +Cc: pgsql-hackers@postgresql.org, pgsql-performance@postgresql.org, + pgsql-general@postgresql.org +Subject: Re: realtime data inserts +In-reply-to: +References: +Comments: In-reply-to "Adam Siegel" + message dated "Sat, 10 May 2003 11:25:16 -0400" +Date: Sat, 10 May 2003 12:00:02 -0400 +Message-ID: <6754.1052582402@sss.pgh.pa.us> +From: Tom Lane +X-Spam-Status: No, hits=-29.3 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,REFERENCES, + REPLY_WITH_QUOTES autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/323 +X-Sequence-Number: 41978 + +"Adam Siegel" writes: +> I have realtime data flowing at a rate of 500, 512 byte packets per second. +> I want to log the info in a database table with two other columns, one for a +> timestamp and one for a name of the packet. The max rate I can achieve is +> 350 inserts per second on a sun blade 2000. The inserts are grouped in a +> transaction and I commit every 1200 records. + +Have you thought about using COPY? + + regards, tom lane + + +From pgsql-general-owner@postgresql.org Sat May 10 11:58:53 2003 +X-Original-To: pgsql-general@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id B6DF9476022 + for ; + Sat, 10 May 2003 11:58:50 -0400 (EDT) +Received: from w3matter.com (weightlossfriends.com [66.246.13.45]) + by postgresql.org (Postfix) with SMTP id 0E3804758F1 + for ; + Sat, 10 May 2003 11:58:49 -0400 (EDT) +Received: (qmail 16300 invoked from network); 10 May 2003 15:58:49 -0000 +Received: from pool-162-84-215-56.ny5030.east.verizon.net (HELO did-it.com) + (162.84.215.56) by 0 with SMTP; 10 May 2003 15:58:49 -0000 +Message-ID: <3EBD228A.8000901@did-it.com> +Date: Sat, 10 May 2003 12:02:18 -0400 +From: Ericson Smith +User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; + rv:1.3b) Gecko/20030404 Minotaur/0.1a +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: Adam Siegel +Cc: pgsql-hackers@postgresql.org, pgsql-performance@postgresql.org, + pgsql-general@postgresql.org +Subject: Re: realtime data inserts +References: +In-Reply-To: +Content-Type: text/plain; charset=ISO-8859-1; format=flowed +Content-Transfer-Encoding: 7bit +X-Spam-Status: No, hits=-35.1 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,RCVD_IN_OSIRUSOFT_COM, + REFERENCES,REPLY_WITH_QUOTES,USER_AGENT_MOZILLA_UA version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/322 +X-Sequence-Number: 41977 + +Had the same problem recently... + +Format your data like a pg text dump into a file and then... + +COPY (a,b,c) FROM stdin; +1 2 3 +4 5 6 +\. + +psql I have realtime data flowing at a rate of 500, 512 byte packets per second. +>I want to log the info in a database table with two other columns, one for a +>timestamp and one for a name of the packet. The max rate I can achieve is +>350 inserts per second on a sun blade 2000. The inserts are grouped in a +>transaction and I commit every 1200 records. I am storing the binary data +>in a bytea. I am using the libpq conversion function. Not sure if that is +>slowing me down. But I think it is the insert not the conversion. +> +>Any thoughts on how to achive this goal? +> +> +>---------------------------(end of broadcast)--------------------------- +>TIP 4: Don't 'kill -9' the postmaster +> +> + + +From pgsql-general-owner@postgresql.org Sat May 10 13:08:37 2003 +X-Original-To: pgsql-general@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 2E86C475F0D + for ; + Sat, 10 May 2003 13:08:35 -0400 (EDT) +Received: from flake.decibel.org (flake.decibel.org [66.143.173.58]) + by postgresql.org (Postfix) with SMTP id 4C200475CE5 + for ; + Sat, 10 May 2003 13:08:34 -0400 (EDT) +Received: (qmail 19146 invoked by uid 1001); 10 May 2003 17:08:33 -0000 +Date: Sat, 10 May 2003 12:08:33 -0500 +From: "Jim C. Nasby" +To: Adam Siegel +Cc: pgsql-hackers@postgresql.org, pgsql-performance@postgresql.org, + pgsql-general@postgresql.org +Subject: Re: realtime data inserts +Message-ID: <20030510120833.K66185@flake.decibel.org> +Reply-To: jim@nasby.net +References: +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +User-Agent: Mutt/1.2.5.1i +In-Reply-To: ; + from adam@sycamorehq.com on Sat, May 10, 2003 at 11:25:16AM -0400 +X-Operating-System: FreeBSD 4.8-RELEASE i386 +X-Distributed: Join the Effort! http://www.distributed.net +X-Spam-Status: No, hits=-39.4 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REFERENCES,REPLY_WITH_QUOTES,SIGNATURE_SHORT_SPARSE, + USER_AGENT_MUTT version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/324 +X-Sequence-Number: 41979 + +Are you binding your insert? IE: + +prepare statement INSERT INTO blah VALUES (?, ?, ?); + +execute statement (a, b, c) + +Instead of just "INSERT INTO blah VALUES(a, b, c)" + + +On Sat, May 10, 2003 at 11:25:16AM -0400, Adam Siegel wrote: +> I have realtime data flowing at a rate of 500, 512 byte packets per second. +> I want to log the info in a database table with two other columns, one for a +> timestamp and one for a name of the packet. The max rate I can achieve is +> 350 inserts per second on a sun blade 2000. The inserts are grouped in a +> transaction and I commit every 1200 records. I am storing the binary data +> in a bytea. I am using the libpq conversion function. Not sure if that is +> slowing me down. But I think it is the insert not the conversion. +> +> Any thoughts on how to achive this goal? + + +-- +Jim C. Nasby (aka Decibel!) jim@nasby.net +Member: Triangle Fraternity, Sports Car Club of America +Give your computer some brain candy! www.distributed.net Team #1828 + +Windows: "Where do you want to go today?" +Linux: "Where do you want to go tomorrow?" +FreeBSD: "Are you guys coming, or what?" + + +From pgsql-general-owner@postgresql.org Sat May 10 14:31:33 2003 +X-Original-To: pgsql-general@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id DBB05475CE5 + for ; + Sat, 10 May 2003 14:31:31 -0400 (EDT) +Received: from lakemtao04.cox.net (lakemtao04.cox.net [68.1.17.241]) + by postgresql.org (Postfix) with ESMTP id 252C94758F1 + for ; + Sat, 10 May 2003 14:31:31 -0400 (EDT) +Received: from [192.168.1.1] ([68.11.66.83]) by lakemtao04.cox.net + (InterMail vM.5.01.04.05 201-253-122-122-105-20011231) with ESMTP + id <20030510183132.PNSG13930.lakemtao04.cox.net@[192.168.1.1]> + for ; Sat, 10 May 2003 14:31:32 -0400 +Subject: Re: realtime data inserts +From: Ron Johnson +To: pgsql-general@postgresql.org +In-Reply-To: <6754.1052582402@sss.pgh.pa.us> +References: <6754.1052582402@sss.pgh.pa.us> +Content-Type: text/plain +Organization: +Message-Id: <1052591490.26574.161.camel@haggis> +Mime-Version: 1.0 +X-Mailer: Ximian Evolution 1.2.4 +Date: 10 May 2003 13:31:30 -0500 +Content-Transfer-Encoding: 7bit +X-Spam-Status: No, hits=-41.1 required=5.0 + tests=BAYES_10,EMAIL_ATTRIBUTION,IN_REP_TO,REFERENCES, + REPLY_WITH_QUOTES,SIGNATURE_LONG_DENSE,USER_AGENT_XIMIAN + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/328 +X-Sequence-Number: 41983 + +On Sat, 2003-05-10 at 11:00, Tom Lane wrote: +> "Adam Siegel" writes: +> > I have realtime data flowing at a rate of 500, 512 byte packets per second. +> > I want to log the info in a database table with two other columns, one for a +> > timestamp and one for a name of the packet. The max rate I can achieve is +> > 350 inserts per second on a sun blade 2000. The inserts are grouped in a +> > transaction and I commit every 1200 records. +> +> Have you thought about using COPY? + +Generate a temporary file, and then system("COPY /tmp/foobar ...") ? + +-- ++---------------------------------------------------------------+ +| Ron Johnson, Jr. mailto:ron.l.johnson@cox.net | +| Jefferson, LA USA http://members.cox.net/ron.l.johnson | +| | +| The purpose of the military isn't to pay your college tuition | +| or give you a little extra income; it's to "kill people and | +| break things". Surprisingly, not everyone understands that. | ++---------------------------------------------------------------+ + + +From pgsql-general-owner@postgresql.org Sat May 10 22:46:24 2003 +X-Original-To: pgsql-general@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 0D6A7475F0D + for ; + Sat, 10 May 2003 22:46:23 -0400 (EDT) +Received: from sss.pgh.pa.us (unknown [192.204.191.242]) + by postgresql.org (Postfix) with ESMTP id 4A5BA4758F1 + for ; + Sat, 10 May 2003 22:46:22 -0400 (EDT) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h4B2kPU6010705; + Sat, 10 May 2003 22:46:25 -0400 (EDT) +To: Ron Johnson +Cc: pgsql-general@postgresql.org +Subject: Re: realtime data inserts +In-reply-to: <1052591490.26574.161.camel@haggis> +References: <6754.1052582402@sss.pgh.pa.us> + <1052591490.26574.161.camel@haggis> +Comments: In-reply-to Ron Johnson + message dated "10 May 2003 13:31:30 -0500" +Date: Sat, 10 May 2003 22:46:25 -0400 +Message-ID: <10704.1052621185@sss.pgh.pa.us> +From: Tom Lane +X-Spam-Status: No, hits=-32.5 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REFERENCES,REPLY_WITH_QUOTES autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/334 +X-Sequence-Number: 41989 + +Ron Johnson writes: +> On Sat, 2003-05-10 at 11:00, Tom Lane wrote: +>> Have you thought about using COPY? + +> Generate a temporary file, and then system("COPY /tmp/foobar ...") ? + +No, copy from stdin. No need for a temp file. + + regards, tom lane + + +From pgsql-performance-owner@postgresql.org Sun May 11 09:15:59 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id E60F9476022 + for ; + Sun, 11 May 2003 09:15:57 -0400 (EDT) +Received: from web13001.mail.yahoo.com (web13001.mail.yahoo.com + [216.136.174.11]) + by postgresql.org (Postfix) with SMTP id E23BC4758F1 + for ; + Sun, 11 May 2003 09:15:56 -0400 (EDT) +Message-ID: <20030511131600.47686.qmail@web13001.mail.yahoo.com> +Received: from [80.58.43.235] by web13001.mail.yahoo.com via HTTP; + Sun, 11 May 2003 15:16:00 CEST +Date: Sun, 11 May 2003 15:16:00 +0200 (CEST) +From: =?iso-8859-1?q?Xevi=20Serrats?= +Subject: Yet another question about not use on indexes +To: pgsql-performance@postgresql.org +MIME-Version: 1.0 +Content-Type: text/plain; charset=iso-8859-1 +Content-Transfer-Encoding: quoted-printable +X-Spam-Status: No, hits=-5.8 required=5.0 + tests=BAYES_10 + version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/121 +X-Sequence-Number: 1900 + +Hi, + +I have created a table whit some indexes. I analize +the query of this table and never use index. + +After this, I create a more simplistic table with two +columns and one index and the query uses the index. + +Look at this: + +pfc=3D# \d document + Table +"public.document" + Column | Type |=20=20=20=20=20=20=20=20=20=20=20= +=20=20=20 + Modifiers +------------+--------------------------+-----------------------------------= +----------------- + codi | integer | not null +default nextval('seq_document'::text) + nom | character varying(32) | not null + descripcio | text | + formulari | integer | + fitxer | character varying(32) | + tamany | integer | default -1 + data | timestamp with time zone | default +('now'::text)::timestamp(6) with time zone +Indexes: document_pkey primary key btree (codi), + ind_doc1 btree (codi), + ind_document btree (formulari) +Triggers: RI_ConstraintTrigger_19414, + RI_ConstraintTrigger_19418, + RI_ConstraintTrigger_19419, + actualitzaritemcercadocument, + altaitemcercadocument, + baixaitemcercadocument, + eliminaracldocument, + eliminaravaluaciodocument + +pfc=3D# explain select * from document where codi=3D2; + QUERY PLAN +---------------------------------------------------------- + Seq Scan on document (cost=3D0.00..1.19 rows=3D1 +width=3D120) + Filter: (codi =3D 2) +(2 rows) + +This query must use index document_pkey but explain +tells us that the query does a Sequencial scan on +table document. + +Look at this simplistic case: + +pfc=3D# \d prova + Table "public.prova" + Column | Type | Modifiers +--------+-----------------------+----------- + codi | integer | not null + nom | character varying(30) | +Indexes: prova_pkey primary key btree (codi) + +pfc=3D# explain select * from prova where codi=3D1234; + QUERY PLAN +------------------------------------------------------------------------- + Index Scan using prova_pkey on prova=20 +(cost=3D0.00..5.99 rows=3D1 width=3D37) + Index Cond: (codi =3D 1234) +(2 rows) + +Now the query uses index, explain tell something about +index scan using index prova_pkey. + +What is the diference with two cases? What must I do? +It is a bug? I need do something else?=20 + +Thanks a lot for helping me. + +Regards, + +Xevi. + +_______________________________________________________________ +Yahoo! Messenger +Nueva versi=F3n: Webcam, voz, y mucho m=E1s =A1Gratis!=20 +Desc=E1rgalo ya desde http://messenger.yahoo.es + + +From pgsql-performance-owner@postgresql.org Sun May 11 10:08:32 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id D195A476302 + for ; + Sun, 11 May 2003 10:08:30 -0400 (EDT) +Received: from anchor-post-35.mail.demon.net (anchor-post-35.mail.demon.net + [194.217.242.85]) + by postgresql.org (Postfix) with ESMTP id D1D5A4758F1 + for ; + Sun, 11 May 2003 10:08:29 -0400 (EDT) +Received: from mwynhau.demon.co.uk ([193.237.186.96] + helo=mainbox.archonet.com) + by anchor-post-35.mail.demon.net with esmtp (Exim 3.36 #2) + id 19ErVB-0005pZ-0Z; Sun, 11 May 2003 15:08:33 +0100 +Received: from localhost (localhost.localdomain [127.0.0.1]) + by mainbox.archonet.com (Postfix) with ESMTP + id 3D52916202; Sun, 11 May 2003 15:08:32 +0100 (BST) +Received: from client.archonet.com (client.archonet.com [192.168.1.16]) + by mainbox.archonet.com (Postfix) with ESMTP + id 86C26161F1; Sun, 11 May 2003 15:08:31 +0100 (BST) +Content-Type: text/plain; + charset="iso-8859-1" +From: Richard Huxton +Organization: Archonet Ltd +To: Xevi Serrats , + pgsql-performance@postgresql.org +Subject: Re: Yet another question about not use on indexes +Date: Sun, 11 May 2003 15:08:34 +0100 +User-Agent: KMail/1.4.3 +References: <20030511131600.47686.qmail@web13001.mail.yahoo.com> +In-Reply-To: <20030511131600.47686.qmail@web13001.mail.yahoo.com> +MIME-Version: 1.0 +Content-Transfer-Encoding: quoted-printable +Message-Id: <200305111508.34714.dev@archonet.com> +X-Virus-Scanned: by AMaViS snapshot-20020531 +X-Spam-Status: No, hits=-34.9 required=5.0 + tests=BAYES_10,EMAIL_ATTRIBUTION,IN_REP_TO,REFERENCES, + REPLY_WITH_QUOTES,USER_AGENT_KMAIL autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/122 +X-Sequence-Number: 1901 + +On Sunday 11 May 2003 2:16 pm, Xevi Serrats wrote: +> Hi, +> +> I have created a table whit some indexes. I analize +> the query of this table and never use index. + +> pfc=3D# \d document +> Table +> "public.document" +> Column | Type | +> Modifiers +> ------------+--------------------------+---------------------------------= +-- +>----------------- codi | integer | not null +> default nextval('seq_document'::text) +> nom | character varying(32) | not null +etc... + +> pfc=3D# explain select * from document where codi=3D2; +> QUERY PLAN +> ---------------------------------------------------------- +> Seq Scan on document (cost=3D0.00..1.19 rows=3D1 +> width=3D120) +> Filter: (codi =3D 2) +> (2 rows) + +1. Have you done a VACUUM ANALYSE? +2. How many rows are in this table? +3. Can you post the output of EXPLAIN ANALYSE SELECT... - that actually run= +s=20 +the query. + +--=20 + Richard Huxton + + +From pgsql-performance-owner@postgresql.org Sun May 11 10:15:32 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id C508447634B + for ; + Sun, 11 May 2003 10:15:31 -0400 (EDT) +Received: from sss.pgh.pa.us (unknown [192.204.191.242]) + by postgresql.org (Postfix) with ESMTP id 06EBE47635A + for ; + Sun, 11 May 2003 10:15:29 -0400 (EDT) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h4BEFXU6013083; + Sun, 11 May 2003 10:15:33 -0400 (EDT) +To: =?iso-8859-1?q?Xevi=20Serrats?= +Cc: pgsql-performance@postgresql.org +Subject: Re: Yet another question about not use on indexes +In-reply-to: <20030511131600.47686.qmail@web13001.mail.yahoo.com> +References: <20030511131600.47686.qmail@web13001.mail.yahoo.com> +Comments: In-reply-to =?iso-8859-1?q?Xevi=20Serrats?= + message dated "Sun, 11 May 2003 15:16:00 +0200" +Date: Sun, 11 May 2003 10:15:32 -0400 +Message-ID: <13082.1052662532@sss.pgh.pa.us> +From: Tom Lane +X-Spam-Status: No, hits=-16.1 required=5.0 tests=BAYES_00,IN_REP_TO,REFERENCES + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/123 +X-Sequence-Number: 1902 + +=?iso-8859-1?q?Xevi=20Serrats?= writes: +> pfc=# explain select * from document where codi=2; +> QUERY PLAN +> ---------------------------------------------------------- +> Seq Scan on document (cost=0.00..1.19 rows=1 width=120) +> Filter: (codi = 2) +> (2 rows) + +Judging from the cost estimate, this table is too small to bother with +an indexscan. + + regards, tom lane + + +From pgsql-general-owner@postgresql.org Sun May 11 12:54:46 2003 +X-Original-To: pgsql-general@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id CA6DD476302 + for ; + Sun, 11 May 2003 12:54:45 -0400 (EDT) +Received: from lakemtao01.cox.net (lakemtao01.cox.net [68.1.17.244]) + by postgresql.org (Postfix) with ESMTP id E6AE1476022 + for ; + Sun, 11 May 2003 12:54:44 -0400 (EDT) +Received: from [192.168.1.1] ([68.11.66.83]) by lakemtao01.cox.net + (InterMail vM.5.01.04.05 201-253-122-122-105-20011231) with ESMTP + id <20030511165451.RXJG8337.lakemtao01.cox.net@[192.168.1.1]> + for ; Sun, 11 May 2003 12:54:51 -0400 +Subject: Re: realtime data inserts +From: Ron Johnson +To: pgsql-general@postgresql.org +In-Reply-To: <10704.1052621185@sss.pgh.pa.us> +References: <6754.1052582402@sss.pgh.pa.us> + <1052591490.26574.161.camel@haggis> <10704.1052621185@sss.pgh.pa.us> +Content-Type: text/plain +Organization: +Message-Id: <1052672090.995.13.camel@haggis> +Mime-Version: 1.0 +X-Mailer: Ximian Evolution 1.2.4 +Date: 11 May 2003 11:54:50 -0500 +Content-Transfer-Encoding: 7bit +X-Spam-Status: No, hits=-44.3 required=5.0 + tests=BAYES_10,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REFERENCES,REPLY_WITH_QUOTES,SIGNATURE_LONG_DENSE, + USER_AGENT_XIMIAN autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/337 +X-Sequence-Number: 41992 + +On Sat, 2003-05-10 at 21:46, Tom Lane wrote: +> Ron Johnson writes: +> > On Sat, 2003-05-10 at 11:00, Tom Lane wrote: +> >> Have you thought about using COPY? +> +> > Generate a temporary file, and then system("COPY /tmp/foobar ...") ? +> +> No, copy from stdin. No need for a temp file. + +But wouldn't that only work if the input stream is acceptable to +COPY ? + +-- ++---------------------------------------------------------------+ +| Ron Johnson, Jr. mailto:ron.l.johnson@cox.net | +| Jefferson, LA USA http://members.cox.net/ron.l.johnson | +| | +| The purpose of the military isn't to pay your college tuition | +| or give you a little extra income; it's to "kill people and | +| break things". Surprisingly, not everyone understands that. | ++---------------------------------------------------------------+ + + +From pgsql-general-owner@postgresql.org Sun May 11 12:58:54 2003 +X-Original-To: pgsql-general@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 5FFA7476022 + for ; + Sun, 11 May 2003 12:58:53 -0400 (EDT) +Received: from varsoon.wireboard.com (www.wireboard.com [216.151.155.101]) + by postgresql.org (Postfix) with ESMTP id C79A34758F1 + for ; + Sun, 11 May 2003 12:58:48 -0400 (EDT) +Received: from doug by varsoon.wireboard.com with local (Exim 3.35 #1) + id 19Eu9r-0007WV-00; Sun, 11 May 2003 12:58:43 -0400 +To: Ron Johnson +Cc: pgsql-general@postgresql.org +Subject: Re: realtime data inserts +References: <6754.1052582402@sss.pgh.pa.us> + <1052591490.26574.161.camel@haggis> <10704.1052621185@sss.pgh.pa.us> + <1052672090.995.13.camel@haggis> +From: Doug McNaught +Date: 11 May 2003 12:58:43 -0400 +In-Reply-To: Ron Johnson's message of "11 May 2003 11:54:50 -0500" +Message-ID: +Lines: 18 +User-Agent: Gnus/5.0806 (Gnus v5.8.6) Emacs/20.7 +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Spam-Status: No, hits=-38.8 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REFERENCES,REPLY_WITH_QUOTES,USER_AGENT_GNUS_UA + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/338 +X-Sequence-Number: 41993 + +Ron Johnson writes: + +> On Sat, 2003-05-10 at 21:46, Tom Lane wrote: +> > Ron Johnson writes: +> > > On Sat, 2003-05-10 at 11:00, Tom Lane wrote: +> > >> Have you thought about using COPY? +> > +> > > Generate a temporary file, and then system("COPY /tmp/foobar ...") ? +> > +> > No, copy from stdin. No need for a temp file. +> +> But wouldn't that only work if the input stream is acceptable to +> COPY ? + +Yes, but you could always pipe it through a script or C program to +make it so... + +-Doug + + +From pgsql-performance-owner@postgresql.org Mon May 12 03:31:23 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id D13B9475956 + for ; + Mon, 12 May 2003 03:31:21 -0400 (EDT) +Received: from rwcrmhc53.attbi.com (rwcrmhc53.attbi.com [204.127.198.39]) + by postgresql.org (Postfix) with ESMTP id 9711747580B + for ; + Mon, 12 May 2003 03:31:19 -0400 (EDT) +Received: from ladamski (12-236-245-17.client.attbi.com[12.236.245.17]) + by attbi.com (rwcrmhc53) with SMTP + id <2003051207312005300q4uepe>; Mon, 12 May 2003 07:31:20 +0000 +From: "Lucas Adamski" +To: "'Stephan Szabo'" +Cc: "'Postgresql Performance Mailing list (E-mail)'" + +Subject: Re: Hack around lack of CORRESPONDING BY in EXCEPT? +Date: Mon, 12 May 2003 00:29:50 -0700 +Message-ID: <001c01c31858$46967500$11f5ec0c@LADAMSKI> +MIME-Version: 1.0 +Content-Type: text/plain; + charset="us-ascii" +Content-Transfer-Encoding: 7bit +X-Priority: 3 (Normal) +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook CWS, Build 9.0.2416 (9.0.2911.0) +Importance: Normal +X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4925.2800 +In-Reply-To: <20030507154625.C32502-100000@megazone23.bigpanda.com> +X-Spam-Status: No, hits=-12.2 required=5.0 + tests=BAYES_10,IN_REP_TO,QUOTED_EMAIL_TEXT + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/124 +X-Sequence-Number: 1903 + +Stephan, + +Bingo! That worked perfectly, thank you! I was considering something like +that, but couldn't figure out the syntax offhand to join two events tables +in that fashion. Didn't realize you could alias a table as well! Thanks +again, + Lucas. + +> -----Original Message----- +> From: Stephan Szabo [mailto:sszabo@megazone23.bigpanda.com] +> Sent: Wednesday, May 07, 2003 3:59 PM +> To: Lucas Adamski +> Cc: Postgresql Performance Mailing list (E-mail) +> Subject: Re: [PERFORM] Hack around lack of CORRESPONDING BY in EXCEPT? +> +> +> +> On Wed, 7 May 2003, Lucas Adamski wrote: +> +> > I wrote it originally as: +> > +> > SELECT tracking.pk,events.data1,events.data2 FROM +> tracking,events WHERE +> > tracking.event_fk = event.pk EXCEPT (SELECT +> events.data1,events.data2 FROM +> > events WHERE event.type = 10) +> > +> > because each of these subqueries restricts the dataset +> greatly before doing +> > the join. I've simplified the actual problem (as the real +> code has a bunch +> > of extraneous stuff that makes it even more obtuse), but +> essentially, the +> > tracking table maintains a record of the last record type +> that was entered. +> > The type is incremented for each batch of events that is +> loaded. In this +> > case, I'm assuming that the latest batch is type=10 (or +> 5000, or 100000), +> > and the tracking table references a small subset of previous events +> > (possibly of types 1-9 in this example). This particular +> query is supposed +> > to return all tracking.pk's that are present in the +> previous batches (types) +> > but not in the latest batch (10). I didn't mean to make it +> quite so obtuse, +> > sorry. :) +> +> Maybe something like nominally like (quickly done so possibly wrong +> again): +> +> select tracking.pk, events.data1, events.data2 from +> tracking,events where not exists (select * from events e where +> e.type=10 and e.data1=events.data1 and e.data2=events.data2) +> and tracking.event_fk=event.pk +> +> Get all tracking/event combinations, not including those +> where the data1/2 +> matches that of an event with type 10. +> +> That might give dups if there are multiple events rows with +> that pk for +> different types (but not 10). +> +> + + +From pgsql-general-owner@postgresql.org Fri May 16 13:07:57 2003 +X-Original-To: pgsql-general@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP + id 5289347580B; Mon, 12 May 2003 10:51:50 -0400 (EDT) +Received: from beorn.hq.sai (unknown [63.89.77.233]) + by postgresql.org (Postfix) with ESMTP + id 248A5474E42; Mon, 12 May 2003 10:51:47 -0400 (EDT) +Received: from localhost (adam@localhost) + by beorn.hq.sai (8.11.6/8.11.0) with ESMTP id h4CEpHO24098; + Mon, 12 May 2003 10:51:18 -0400 +X-Authentication-Warning: beorn.hq.sai: adam owned process doing -bs +Date: Mon, 12 May 2003 10:51:17 -0400 (EDT) +From: Adam Siegel +X-X-Sender: adam@beorn.hq.sai +To: "Jim C. Nasby" +Cc: pgsql-hackers@postgresql.org, , + +Subject: Re: realtime data inserts +In-Reply-To: <20030510120833.K66185@flake.decibel.org> +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-Spam-Status: No, hits=-33.1 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REPLY_WITH_QUOTES,USER_AGENT_PINE,X_AUTH_WARNING + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/602 +X-Sequence-Number: 42257 + + +The copy from method (PQputline) allows me to achieve around 1000 inserts +per second. + + +On Sat, 10 May 2003, Jim C. Nasby wrote: + +> Are you binding your insert? IE: +> +> prepare statement INSERT INTO blah VALUES (?, ?, ?); +> +> execute statement (a, b, c) +> +> Instead of just "INSERT INTO blah VALUES(a, b, c)" +> +> +> On Sat, May 10, 2003 at 11:25:16AM -0400, Adam Siegel wrote: +> > I have realtime data flowing at a rate of 500, 512 byte packets per second. +> > I want to log the info in a database table with two other columns, one for a +> > timestamp and one for a name of the packet. The max rate I can achieve is +> > 350 inserts per second on a sun blade 2000. The inserts are grouped in a +> > transaction and I commit every 1200 records. I am storing the binary data +> > in a bytea. I am using the libpq conversion function. Not sure if that is +> > slowing me down. But I think it is the insert not the conversion. +> > +> > Any thoughts on how to achive this goal? +> +> +> + + +From pgsql-performance-owner@postgresql.org Mon May 12 11:49:41 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 4BAAB476315 + for ; + Mon, 12 May 2003 11:49:40 -0400 (EDT) +Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) + by postgresql.org (Postfix) with ESMTP id AD5CE47621C + for ; + Mon, 12 May 2003 11:49:39 -0400 (EDT) +Received: from [63.195.55.98] (HELO spooky) + by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) + with ESMTP id 3027553; Mon, 12 May 2003 08:49:46 -0700 +Content-Type: text/plain; + charset="iso-8859-1" +From: Josh Berkus +Organization: Aglio Database Solutions +To: "Alfranio Junior" , + +Subject: Re: PERFORMANCE and SIZE +Date: Mon, 12 May 2003 08:49:39 -0700 +User-Agent: KMail/1.4.3 +References: <011d01c318be$997217f0$9002a8c0@ialfranio> +In-Reply-To: <011d01c318be$997217f0$9002a8c0@ialfranio> +MIME-Version: 1.0 +Message-Id: <200305120849.39381.josh@agliodbs.com> +Content-Transfer-Encoding: quoted-printable +X-Spam-Status: No, hits=-32.4 required=5.0 + tests=BAYES_01,IN_REP_TO,QUOTED_EMAIL_TEXT,REFERENCES, + REPLY_WITH_QUOTES,USER_AGENT_KMAIL autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/127 +X-Sequence-Number: 1906 + +Alfranio, + +> I'm a new PostgresSql user and I do not know so much about the +> performance mechanisms currently implemented and available. + +> Does anybody know what is happening ? + +90% likely: You haven't run VACUUM FULL ANALYZE in a while. + +--=20 +Josh Berkus +Aglio Database Solutions +San Francisco + + +From pgsql-general-owner@postgresql.org Mon May 12 11:56:06 2003 +X-Original-To: pgsql-general@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP + id B591747580B; Mon, 12 May 2003 11:56:02 -0400 (EDT) +Received: from polaris.pinpointresearch.com (66-7-238-176.cust.telepacific.net + [66.7.238.176]) by postgresql.org (Postfix) with ESMTP + id A16CD474E42; Mon, 12 May 2003 11:55:57 -0400 (EDT) +Received: from there (66-7-238-179.cust.telepacific.net [66.7.238.179]) + by polaris.pinpointresearch.com (Postfix) with SMTP + id 6DD11103C7; Mon, 12 May 2003 08:56:02 -0700 (PDT) +Content-Type: text/plain; + charset="iso-8859-1" +From: Steve Crawford +Organization: Pinpoint Research +To: "Adam Siegel" , + pgsql-hackers@postgresql.org, pgsql-performance@postgresql.org, + pgsql-general@postgresql.org +Subject: Re: realtime data inserts +Date: Mon, 12 May 2003 08:56:02 -0700 +X-Mailer: KMail [version 1.3.1] +References: +In-Reply-To: +MIME-Version: 1.0 +Message-Id: <20030512155602.6DD11103C7@polaris.pinpointresearch.com> +Content-Transfer-Encoding: quoted-printable +X-Spam-Status: No, hits=-32.5 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REFERENCES,REPLY_WITH_QUOTES autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/357 +X-Sequence-Number: 42012 + +Depends - we don't know enough about your needs. Some questions: + +Is this constant data or just capturing a burst? + +Are you feeding it through one connection or several in parallel? + +Did you tune your memory configs in postgresql.conf or are they still at th= +e=20 +minimalized defaults? + +How soon does the data need to be available for query? (Obviously there wil= +l=20 +be up to a 1200 record delay just due to the transaction.) + +What generates the timestamp? Ie. is it an insert into foo values (now(),= +=20 +packetname, data) or is the app providing the timestamp? + +More info about the app will help. + +Cheers, +Steve + + +On Saturday 10 May 2003 8:25 am, Adam Siegel wrote: +> I have realtime data flowing at a rate of 500, 512 byte packets per secon= +d. +> I want to log the info in a database table with two other columns, one for +> a timestamp and one for a name of the packet. The max rate I can achieve +> is 350 inserts per second on a sun blade 2000. The inserts are grouped in +> a transaction and I commit every 1200 records. I am storing the binary +> data in a bytea. I am using the libpq conversion function. Not sure if +> that is slowing me down. But I think it is the insert not the conversion. +> +> Any thoughts on how to achive this goal? +> +> +> ---------------------------(end of broadcast)--------------------------- +> TIP 4: Don't 'kill -9' the postmaster + + +From pgsql-performance-owner@postgresql.org Mon May 12 16:53:10 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 4515C47580B + for ; + Mon, 12 May 2003 16:53:07 -0400 (EDT) +Received: from t-9.net (unknown [64.246.36.43]) + by postgresql.org (Postfix) with SMTP id D6B0F476352 + for ; + Mon, 12 May 2003 16:53:03 -0400 (EDT) +Received: (qmail 29160 invoked by uid 0); 12 May 2003 18:58:03 -0000 +Received: from localhost (HELO seahat.com) (127.0.0.1) + by localhost with SMTP; 12 May 2003 18:58:03 -0000 +Received: from 65.102.128.233 + (SquirrelMail authenticated user snubber@seahat.com) + by fordparts.com with HTTP; Mon, 12 May 2003 13:58:03 -0500 (CDT) +Message-ID: <10995.65.102.128.233.1052765883.squirrel@fordparts.com> +Date: Mon, 12 May 2003 13:58:03 -0500 (CDT) +Subject: Re: How are null's stored? +From: "Ryan" +To: +In-Reply-To: <200305121344.43288.josh@agliodbs.com> +References: <20030512190156.GA40542@flake.decibel.org> + <200305121344.43288.josh@agliodbs.com> +X-Priority: 3 +Importance: Normal +Cc: +X-Mailer: SquirrelMail (version 1.2.8) +MIME-Version: 1.0 +Content-Type: text/plain; charset=iso-8859-1 +Content-Transfer-Encoding: quoted-printable +X-Spam-Status: No, hits=-25.1 required=5.0 + tests=BAYES_01,IN_REP_TO,MSG_ID_ADDED_BY_MTA_3,QUOTED_EMAIL_TEXT, + REFERENCES,REPLY_WITH_QUOTES autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/131 +X-Sequence-Number: 1910 + +> Jim, +> +>> I have a 40M row table I need to import data into, then use to create +>> a bunch of more normalized tables. Right now all fields are varchar, +>> but I'm going to change this so that fields that are less than a +>> certain size are just char. Question is, how much impact is there from +>> char being nullable vs. not nullable? src/include/access/htup.h +>> indicates that nulls are stored in a bitmap, so I'd suspect that I +>> should see a decent space savings from not having to include length +>> information all the time... (most of these small fields are always the +>> same size no matter what...) +> +> This is moot. PostgreSQL stores CHAR(x), VARCHAR, and TEXT in the same +> internal format, which includes length information in the page header. +> So you save no storage space by converting to CHAR(x) ... you might +> even make your tables *larger* because of the space padding. + +So if the internal format is identical, why does the INFERNAL database +ignore indexes when you have a text compared to a varchar? + +Ryan + + +From pgsql-performance-owner@postgresql.org Mon May 12 15:02:02 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 0984B476317 + for ; + Mon, 12 May 2003 15:02:01 -0400 (EDT) +Received: from flake.decibel.org (flake.decibel.org [66.143.173.58]) + by postgresql.org (Postfix) with SMTP id 43FA447622E + for ; + Mon, 12 May 2003 15:01:59 -0400 (EDT) +Received: (qmail 41651 invoked by uid 1001); 12 May 2003 19:01:56 -0000 +Date: Mon, 12 May 2003 14:01:56 -0500 +From: "Jim C. Nasby" +To: pgsql-performance@postgresql.org +Subject: How are null's stored? +Message-ID: <20030512190156.GA40542@flake.decibel.org> +Reply-To: jim@nasby.net +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +User-Agent: Mutt/1.4.1i +X-Operating-System: FreeBSD 4.8-RELEASE i386 +X-Distributed: Join the Effort! http://www.distributed.net +X-Spam-Status: No, hits=-12.7 required=5.0 + tests=BAYES_10,SIGNATURE_SHORT_SPARSE,USER_AGENT_MUTT + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/129 +X-Sequence-Number: 1908 + +I have a 40M row table I need to import data into, then use to create a +bunch of more normalized tables. Right now all fields are varchar, but +I'm going to change this so that fields that are less than a certain +size are just char. Question is, how much impact is there from char +being nullable vs. not nullable? src/include/access/htup.h indicates +that nulls are stored in a bitmap, so I'd suspect that I should see a +decent space savings from not having to include length information all +the time... (most of these small fields are always the same size no +matter what...) +-- +Jim C. Nasby (aka Decibel!) jim@nasby.net +Member: Triangle Fraternity, Sports Car Club of America +Give your computer some brain candy! www.distributed.net Team #1828 + +Windows: "Where do you want to go today?" +Linux: "Where do you want to go tomorrow?" +FreeBSD: "Are you guys coming, or what?" + + +From pgsql-performance-owner@postgresql.org Mon May 12 07:45:18 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 3B1FD4758F1 + for ; + Mon, 12 May 2003 07:45:14 -0400 (EDT) +Received: from homer.lsd.di.uminho.pt (gsd.di.uminho.pt [193.136.20.132]) + by postgresql.org (Postfix) with SMTP id A23A147580B + for ; + Mon, 12 May 2003 07:45:00 -0400 (EDT) +Received: (qmail 17971 invoked from network); 12 May 2003 11:44:50 -0000 +Received: from alfranio.lsd.di.uminho.pt (HELO ialfranio) (192.168.2.144) + by mailer.lsd.di.uminho.pt with SMTP; 12 May 2003 11:44:50 -0000 +Message-ID: <011d01c318be$997217f0$9002a8c0@ialfranio> +From: "Alfranio Junior" +To: +Subject: PERFORMANCE and SIZE +Date: Mon, 12 May 2003 12:35:24 -0700 +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit +X-Priority: 3 +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook Express 6.00.2720.3000 +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 +X-Spam-Status: No, hits=-1.9 required=5.0 tests=BAYES_20,DATE_IN_FUTURE_06_12 + version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/125 +X-Sequence-Number: 1904 + + Hello, + +I'm a new PostgresSql user and I do not know so much about the + performance mechanisms currently implemented and available. + + So, as a dummy user I think that something strange is happening with me. + When I run the following command: + + explain analyze select * from customer + where c_last = 'ROUGHTATION' and + c_w_id = 1 and + c_d_id = 1 + order by c_w_id, c_d_id, c_last, c_first limit 1; + + I receive the following results: + + (Customer table with 60.000 rows) - + QUERY PLAN + --------------------------------------------------------------------------- +----------------------------------------------------------- + Limit (cost=4.84..4.84 rows=1 width=283) (actual time=213.13..213.13 + rows=0 loops=1) + -> Sort (cost=4.84..4.84 rows=1 width=283) (actual + time=213.13..213.13 rows=0 loops=1) + Sort Key: c_w_id, c_d_id, c_last, c_first + -> Index Scan using pk_customer on customer (cost=0.00..4.83 + rows=1 width=283) (actual time=211.93..211.93 rows=0 loops=1) + Index Cond: ((c_w_id = 1) AND (c_d_id = 1)) + Filter: (c_last = 'ROUGHTATION'::bpchar) + Total runtime: 213.29 msec + (7 rows) + + + (Customer table with 360.000 rows) - + QUERY PLAN + --------------------------------------------------------------------------- +------------------------------------------------------------- + Limit (cost=11100.99..11101.00 rows=1 width=638) (actual + time=20.82..20.82 rows=0 loops=1) + -> Sort (cost=11100.99..11101.00 rows=4 width=638) (actual + time=20.81..20.81 rows=0 loops=1) + Sort Key: c_w_id, c_d_id, c_last, c_first + -> Index Scan using pk_customer on customer + (cost=0.00..11100.95 rows=4 width=638) (actual time=20.40..20.40 rows=0 + loops=1) + Index Cond: ((c_w_id = 1) AND (c_d_id = 1)) + Filter: (c_last = 'ROUGHTATION'::bpchar) + Total runtime: 21.11 msec + (7 rows) + + Increasing the number of rows the total runtime decreases. + The customer table has the following structure: + CREATE TABLE customer + ( + c_id int NOT NULL , + c_d_id int4 NOT NULL , + c_w_id int4 NOT NULL , + c_first char (16) NULL , + c_middle char (2) NULL , + c_last char (16) NULL , + c_street_1 char (20) NULL , + c_street_2 char (20) NULL , + c_city char (20) NULL , + c_state char (2) NULL , + c_zip char (9) NULL , + c_phone char (16) NULL , + c_since timestamp NULL , + c_credit char (2) NULL , + c_credit_lim numeric(12, 2) NULL , + c_discount numeric(4, 4) NULL , + c_balance numeric(12, 2) NULL , + c_ytd_payment numeric(12, 2) NULL , + c_payment_cnt int4 NULL , + c_delivery_cnt int4 NULL , + c_data text NULL + ); + + ALTER TABLE customer ADD + CONSTRAINT PK_customer PRIMARY KEY + ( + c_w_id, + c_d_id, + c_id + ); + + Does anybody know what is happening ? + + + Thanks !!!! + + Alfranio Junior + + +From pgsql-performance-owner@postgresql.org Mon May 12 16:45:14 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id BB012476315 + for ; + Mon, 12 May 2003 16:45:12 -0400 (EDT) +Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) + by postgresql.org (Postfix) with ESMTP id D05D84762F6 + for ; + Mon, 12 May 2003 16:45:11 -0400 (EDT) +Received: from [216.135.165.74] (HELO temoku) + by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) + with ESMTP id 3028475; Mon, 12 May 2003 13:45:09 -0700 +Content-Type: text/plain; + charset="iso-8859-1" +From: Josh Berkus +Reply-To: josh@agliodbs.com +Organization: Aglio Database Solutions +To: jim@nasby.net, pgsql-performance@postgresql.org +Subject: Re: How are null's stored? +Date: Mon, 12 May 2003 13:44:43 -0700 +User-Agent: KMail/1.4.3 +References: <20030512190156.GA40542@flake.decibel.org> +In-Reply-To: <20030512190156.GA40542@flake.decibel.org> +MIME-Version: 1.0 +Content-Transfer-Encoding: quoted-printable +Message-Id: <200305121344.43288.josh@agliodbs.com> +X-Spam-Status: No, hits=-32.4 required=5.0 + tests=BAYES_01,IN_REP_TO,QUOTED_EMAIL_TEXT,REFERENCES, + REPLY_WITH_QUOTES,USER_AGENT_KMAIL autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/130 +X-Sequence-Number: 1909 + +Jim, + +> I have a 40M row table I need to import data into, then use to create a +> bunch of more normalized tables. Right now all fields are varchar, but +> I'm going to change this so that fields that are less than a certain +> size are just char. Question is, how much impact is there from char +> being nullable vs. not nullable? src/include/access/htup.h indicates +> that nulls are stored in a bitmap, so I'd suspect that I should see a +> decent space savings from not having to include length information all +> the time... (most of these small fields are always the same size no +> matter what...) + +This is moot. PostgreSQL stores CHAR(x), VARCHAR, and TEXT in the same=20 +internal format, which includes length information in the page header. So= +=20 +you save no storage space by converting to CHAR(x) ... you might even make= +=20 +your tables *larger* because of the space padding. + +--=20 +-Josh Berkus + Aglio Database Solutions + San Francisco + + +From pgsql-performance-owner@postgresql.org Mon May 12 17:04:28 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 244F447580B + for ; + Mon, 12 May 2003 17:04:27 -0400 (EDT) +Received: from mail.libertyrms.com (unknown [209.167.124.227]) + by postgresql.org (Postfix) with ESMTP id 55EAA474E42 + for ; + Mon, 12 May 2003 17:04:22 -0400 (EDT) +Received: from [10.1.2.130] (helo=dba2) + by mail.libertyrms.com with esmtp (Exim 3.22 #3 (Debian)) + id 19FKTA-0008M6-00 + for ; Mon, 12 May 2003 17:04:24 -0400 +Received: by dba2 (Postfix, from userid 1019) + id 10846D087; Mon, 12 May 2003 17:04:24 -0400 (EDT) +Date: Mon, 12 May 2003 17:04:24 -0400 +From: Andrew Sullivan +To: pgsql-performance@postgresql.org +Subject: Re: How are null's stored? +Message-ID: <20030512210423.GN14881@libertyrms.info> +Mail-Followup-To: Andrew Sullivan , + pgsql-performance@postgresql.org +References: <20030512190156.GA40542@flake.decibel.org> + <200305121344.43288.josh@agliodbs.com> + <10995.65.102.128.233.1052765883.squirrel@fordparts.com> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: <10995.65.102.128.233.1052765883.squirrel@fordparts.com> +User-Agent: Mutt/1.5.3i +X-Spam-Status: No, hits=-38.0 required=5.0 + tests=BAYES_10,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REFERENCES,REPLY_WITH_QUOTES,USER_AGENT_MUTT + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/132 +X-Sequence-Number: 1911 + +On Mon, May 12, 2003 at 01:58:03PM -0500, Ryan wrote: +> So if the internal format is identical, why does the INFERNAL database +> ignore indexes when you have a text compared to a varchar? + +Because the rules for handling the two data types are not the same. +Since spaces are significant on char(n) according to the spec, you +have strange rules in their handling. + +Short answer: use text. Varchar(n) if you must, to limit length. +But char(n) is almost always evil. + +A + +-- +---- +Andrew Sullivan 204-4141 Yonge Street +Liberty RMS Toronto, Ontario Canada + M2P 2A8 + +1 416 646 3304 x110 + + +From pgsql-performance-owner@postgresql.org Mon May 12 18:47:03 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 8EC4F476321 + for ; + Mon, 12 May 2003 18:47:02 -0400 (EDT) +Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) + by postgresql.org (Postfix) with ESMTP id EDF634762F6 + for ; + Mon, 12 May 2003 18:47:01 -0400 (EDT) +Received: from [216.135.165.74] (HELO temoku) + by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) + with ESMTP id 3028842; Mon, 12 May 2003 15:47:06 -0700 +Content-Type: text/plain; + charset="iso-8859-1" +From: Josh Berkus +Reply-To: josh@agliodbs.com +Organization: Aglio Database Solutions +To: "Ryan" +Subject: Re: How are null's stored? +Date: Mon, 12 May 2003 15:46:39 -0700 +User-Agent: KMail/1.4.3 +Cc: +References: <20030512190156.GA40542@flake.decibel.org> + <200305121344.43288.josh@agliodbs.com> + <10995.65.102.128.233.1052765883.squirrel@fordparts.com> +In-Reply-To: <10995.65.102.128.233.1052765883.squirrel@fordparts.com> +MIME-Version: 1.0 +Content-Transfer-Encoding: quoted-printable +Message-Id: <200305121546.39544.josh@agliodbs.com> +X-Spam-Status: No, hits=-32.4 required=5.0 + tests=BAYES_01,IN_REP_TO,QUOTED_EMAIL_TEXT,REFERENCES, + REPLY_WITH_QUOTES,USER_AGENT_KMAIL autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/133 +X-Sequence-Number: 1912 + +Ryan, + +> So if the internal format is identical, why does the INFERNAL database +> ignore indexes when you have a text compared to a varchar? + +I don't seem to have this problem; I use TEXT or VARCHAR willy-nilly,=20 +including in LIKE 'string%' and UPPER(field) queries, and the indexes work= +=20 +fine. + +I suspect that either you're talking about TEXT to CHAR(x) comparisons, whi= +ch=20 +are a different ball o' wax, or your query problem is something else. + +--=20 +-Josh Berkus + Aglio Database Solutions + San Francisco + + +From pgsql-performance-owner@postgresql.org Mon May 12 19:19:30 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id C371B476353 + for ; + Mon, 12 May 2003 19:19:25 -0400 (EDT) +Received: from megazone.bigpanda.com (megazone.bigpanda.com [63.150.15.178]) + by postgresql.org (Postfix) with ESMTP id 44115476363 + for ; + Mon, 12 May 2003 19:19:23 -0400 (EDT) +Received: by megazone.bigpanda.com (Postfix, from userid 1001) + id DD628D679; Mon, 12 May 2003 16:19:25 -0700 (PDT) +Received: from localhost (localhost [127.0.0.1]) + by megazone.bigpanda.com (Postfix) with ESMTP + id D31095C0A; Mon, 12 May 2003 16:19:25 -0700 (PDT) +Date: Mon, 12 May 2003 16:19:25 -0700 (PDT) +From: Stephan Szabo +To: Josh Berkus +Cc: Ryan , + +Subject: Re: How are null's stored? +In-Reply-To: <200305121546.39544.josh@agliodbs.com> +Message-ID: <20030512160355.L17085-100000@megazone23.bigpanda.com> +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-Spam-Status: No, hits=-26.6 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + QUOTE_TWICE_1,REPLY_WITH_QUOTES autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/134 +X-Sequence-Number: 1913 + +On Mon, 12 May 2003, Josh Berkus wrote: + +> > So if the internal format is identical, why does the INFERNAL database +> > ignore indexes when you have a text compared to a varchar? +> +> I don't seem to have this problem; I use TEXT or VARCHAR willy-nilly, +> including in LIKE 'string%' and UPPER(field) queries, and the indexes work +> fine. + +I can get the case he's complaining about with some cases I believe. + +With an indexed varchar field, I can get 7.3.1 to give me: +sszabo=# set enable_seqscan=off; +SET +sszabo=# explain select * from aq2 where a=('f' || 'g'); + QUERY PLAN +--------------------------------------------------------------------- + Seq Scan on aq2 (cost=100000000.00..100000022.50 rows=1 width=168) + Filter: ((a)::text = 'fg'::text) + +but + +sszabo=# explain select * from aq2 where a=('f' || 'g')::varchar; + QUERY PLAN +---------------------------------------------------------------------- + Index Scan using aq2_pkey on aq2 (cost=0.00..4.82 rows=1 width=168) + Index Cond: (a = 'fg'::character varying) + +or + +sszabo=# explain select * from aq2 where a=('f' || 'g'::varchar); + QUERY PLAN +---------------------------------------------------------------------- + Index Scan using aq2_pkey on aq2 (cost=0.00..4.82 rows=1 width=168) + Index Cond: (a = 'fg'::character varying) + +All in all, I'm not sure what the semantic differences between a varchar +with no length specified and a text are in PostgreSQL actually and if the +whole thing could be simplified in some way that doesn't break backwards +compatibility. + + +From pgsql-performance-owner@postgresql.org Mon May 12 19:50:25 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id A633547580B + for ; + Mon, 12 May 2003 19:50:24 -0400 (EDT) +Received: from sss.pgh.pa.us (unknown [192.204.191.242]) + by postgresql.org (Postfix) with ESMTP id EC279474E42 + for ; + Mon, 12 May 2003 19:50:23 -0400 (EDT) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h4CNoOU6024827; + Mon, 12 May 2003 19:50:24 -0400 (EDT) +To: Stephan Szabo +Cc: Josh Berkus , + Ryan , pgsql-performance@postgresql.org +Subject: Re: How are null's stored? +In-reply-to: <20030512160355.L17085-100000@megazone23.bigpanda.com> +References: <20030512160355.L17085-100000@megazone23.bigpanda.com> +Comments: In-reply-to Stephan Szabo + message dated "Mon, 12 May 2003 16:19:25 -0700" +Date: Mon, 12 May 2003 19:50:24 -0400 +Message-ID: <24826.1052783424@sss.pgh.pa.us> +From: Tom Lane +X-Spam-Status: No, hits=-32.5 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REFERENCES,REPLY_WITH_QUOTES autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/135 +X-Sequence-Number: 1914 + +Stephan Szabo writes: +> All in all, I'm not sure what the semantic differences between a varchar +> with no length specified and a text are in PostgreSQL actually and if the +> whole thing could be simplified in some way that doesn't break backwards +> compatibility. + +Yeah, I've been wondering about that too. A large part of the problem +is that varchar has its own set of operators, which the planner has no +right to assume behave exactly like the text ones ... but they do. It +might work to rip out the redundant varchar operators and allow indexes +on varchar to become truly textual indexes (ie, they'd be text_ops not +varchar_ops opclass). There might be a few tweaks needed to get the +planner to play nice with indexes that require implicit coercions, but +I think it could be made to work. + +Another idea that has been rattling around is to stop treating bpchar as +binary-equivalent to text, and in fact to make bpchar-to-text promotion +go through rtrim() to eliminate padding spaces. + +I think this stuff got put on hold because we haven't been able to come +up with a good solution for the comparable problems in the numeric +datatype hierarchy. But bpchar/varchar/text is a lot simpler problem, +and maybe could be solved with the tools we have in place already. + + regards, tom lane + + +From pgsql-performance-owner@postgresql.org Mon May 12 19:50:59 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 614FD47622E + for ; + Mon, 12 May 2003 19:50:58 -0400 (EDT) +Received: from web40312.mail.yahoo.com (web40312.mail.yahoo.com + [66.218.78.91]) + by postgresql.org (Postfix) with SMTP id D17E4476182 + for ; + Mon, 12 May 2003 19:50:57 -0400 (EDT) +Message-ID: <20030512235100.49769.qmail@web40312.mail.yahoo.com> +Received: from [216.103.85.15] by web40312.mail.yahoo.com via HTTP; + Mon, 12 May 2003 16:51:00 PDT +Date: Mon, 12 May 2003 16:51:00 -0700 (PDT) +From: csajl +Subject: partial index / funxtional idx or bad sql? +To: pgsql-performance@postgresql.org +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Spam-Status: No, hits=-5.8 required=5.0 + tests=BAYES_10 + version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/136 +X-Sequence-Number: 1915 + + +greetings. + +i have a query that is taking a rather long time to execute and have been +looking into setting up a partial index to help, although i'm not sure if this +is what i want. + +here is the table: + +id serial, +type_id int, +areacode smallint, +content text + +__________________________________ +Do you Yahoo!? +The New Yahoo! Search - Faster. Easier. Bingo. +http://search.yahoo.com + + +From pgsql-performance-owner@postgresql.org Mon May 12 20:07:45 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id EC929475EEE + for ; + Mon, 12 May 2003 20:07:43 -0400 (EDT) +Received: from web40301.mail.yahoo.com (web40301.mail.yahoo.com + [66.218.78.80]) + by postgresql.org (Postfix) with SMTP id 024044758F1 + for ; + Mon, 12 May 2003 20:07:43 -0400 (EDT) +Message-ID: <20030513000746.70481.qmail@web40301.mail.yahoo.com> +Received: from [216.103.85.15] by web40301.mail.yahoo.com via HTTP; + Mon, 12 May 2003 17:07:46 PDT +Date: Mon, 12 May 2003 17:07:46 -0700 (PDT) +From: csajl +Subject: [repost] partial index / funxtional idx or bad sql? +To: pgsql-performance@postgresql.org +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Spam-Status: No, hits=-5.8 required=5.0 + tests=BAYES_10 + version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/137 +X-Sequence-Number: 1916 + + +my apologies - a strange key combination sent the message early. + +---- +greetings. + +i have a query that is taking a rather long time to execute and have been +looking into setting up a partial index to help, although i'm not sure if this +is what i want. + +here is the (simplified) table "posts": + +id serial +type_id int +areacode smallint +content text + +and the other table (areacodes) referenced: + +site_id smallint +areacode smallint + + +the query is: + +SELECT p.id, p.areacode, p.content +FROM posts p +WHERE p.type_id = ? +AND p.areacode in ( + select areacode from areacodes + where site_id = ? + ) + + +the "posts" table has 100,000 rows of varying data, across areacodes and types. +given the type_id and site_id, the query is currently taking ~4 seconds to +return 8500 rows (on a dual proc/ gig ram linux box). + +indexes on table "posts" are: +primary key (id) +and another on both (type_id, areacode) + +index on the table "areacodes" is (site_id, areacode). + +would a parital index help in speeding up this query? +are my current indexes counter productive? +or is it just my sql that need help? + + +thanks much for any help or pointers to information. + +- seth + +__________________________________ +Do you Yahoo!? +The New Yahoo! Search - Faster. Easier. Bingo. +http://search.yahoo.com + + +From pgsql-performance-owner@postgresql.org Mon May 12 20:14:05 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id D292547622E + for ; + Mon, 12 May 2003 20:14:04 -0400 (EDT) +Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) + by postgresql.org (Postfix) with ESMTP id 1E6B7474E42 + for ; + Mon, 12 May 2003 20:14:00 -0400 (EDT) +Received: from [216.135.165.74] (HELO temoku) + by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) + with ESMTP id 3029138; Mon, 12 May 2003 17:14:04 -0700 +Content-Type: text/plain; + charset="iso-8859-1" +From: Josh Berkus +Reply-To: josh@agliodbs.com +Organization: Aglio Database Solutions +To: csajl , pgsql-performance@postgresql.org +Subject: Re: [repost] partial index / funxtional idx or bad sql? +Date: Mon, 12 May 2003 17:13:38 -0700 +User-Agent: KMail/1.4.3 +References: <20030513000746.70481.qmail@web40301.mail.yahoo.com> +In-Reply-To: <20030513000746.70481.qmail@web40301.mail.yahoo.com> +MIME-Version: 1.0 +Content-Transfer-Encoding: quoted-printable +Message-Id: <200305121713.38449.josh@agliodbs.com> +X-Spam-Status: No, hits=-22.7 required=5.0 + tests=BAYES_01,IN_REP_TO,REFERENCES,USER_AGENT_KMAIL + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/138 +X-Sequence-Number: 1917 + +Seth, + +> SELECT p.id, p.areacode, p.content=20 +> FROM posts p +> WHERE p.type_id =3D ? +> AND p.areacode in ( +> select areacode from areacodes +> where site_id =3D ? +> ) + +Unless you're using 7.4 from CVS, you want to get rid of that IN: + + SELECT p.id, p.areacode, p.content=20 + FROM posts p + WHERE p.type_id =3D ? + AND EXISTS ( + select areacode from areacodes + where site_id =3D ? + and p.areacode =3D areacodes.areacode + ); + +See how that works, and if it's still slow, post the EXPLAIN ANALYZE. + + +--=20 +-Josh Berkus + Aglio Database Solutions + San Francisco + + +From pgsql-performance-owner@postgresql.org Mon May 12 20:47:12 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id DCB0A4758F1 + for ; + Mon, 12 May 2003 20:47:10 -0400 (EDT) +Received: from web40312.mail.yahoo.com (web40312.mail.yahoo.com + [66.218.78.91]) + by postgresql.org (Postfix) with SMTP id C6ADE474E42 + for ; + Mon, 12 May 2003 20:47:06 -0400 (EDT) +Message-ID: <20030513004710.58428.qmail@web40312.mail.yahoo.com> +Received: from [216.103.85.15] by web40312.mail.yahoo.com via HTTP; + Mon, 12 May 2003 17:47:10 PDT +Date: Mon, 12 May 2003 17:47:10 -0700 (PDT) +From: csajl +Subject: Re: [repost] partial index / funxtional idx or bad sql? +To: josh@agliodbs.com, pgsql-performance@postgresql.org +In-Reply-To: <200305121713.38449.josh@agliodbs.com> +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Spam-Status: No, hits=-26.0 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REPLY_WITH_QUOTES autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/139 +X-Sequence-Number: 1918 + + +hi josh. + +i'm using 7.3.2. i tried using EXISTS instead of the IN, but the same query +now returns in seven sceonds as opposed to four with the IN. + + +cmdb=# EXPLAIN ANALYZE +cmdb-# select c.class_id, c.areacode, c.title from classifieds c +cmdb-# where c.class_cat_id = '1' +cmdb-# and c.areacode IN ( +cmdb(# select areacode from cm_areacode where site_id = '10') +cmdb-# ; + QUERY PLAN +-------------------------------------------------------------------------------------------------------------------------------------------------- + Index Scan using classifieds_dual_idx on classifieds c (cost=0.00..26622.14 +rows=1837 width=39) (actual time=345.48..2305.04 rows=8460 loops=1) + Index Cond: (class_cat_id = 1) + Filter: (subplan) + SubPlan + -> Materialize (cost=3.46..3.46 rows=4 width=2) (actual time=0.00..0.01 +rows=5 loops=61966) + -> Index Scan using site_cm_areacode_idx on cm_areacode +(cost=0.00..3.46 rows=4 width=2) (actual time=0.14..0.22 rows=5 loops=1) + Index Cond: (site_id = 10) + Total runtime: 2314.14 msec +(8 rows) +---------------------------------- + +classifieds_dual_idx is the btree index on (class_type_id, areacode) +and site_cm_areacode_idx is the btree index on (site_id) only. +there is an index in the areacode table that has both (site_id, areacode) but +it's apparently not being used. would it help the query to use that index +instead? + +thanks for your help. + + + +--- Josh Berkus wrote: +> Seth, +> +> > SELECT p.id, p.areacode, p.content +> > FROM posts p +> > WHERE p.type_id = ? +> > AND p.areacode in ( +> > select areacode from areacodes +> > where site_id = ? +> > ) +> +> Unless you're using 7.4 from CVS, you want to get rid of that IN: +> +> SELECT p.id, p.areacode, p.content +> FROM posts p +> WHERE p.type_id = ? +> AND EXISTS ( +> select areacode from areacodes +> where site_id = ? +> and p.areacode = areacodes.areacode +> ); +> +> See how that works, and if it's still slow, post the EXPLAIN ANALYZE. + + +__________________________________ +Do you Yahoo!? +The New Yahoo! Search - Faster. Easier. Bingo. +http://search.yahoo.com + + +From pgsql-performance-owner@postgresql.org Mon May 12 22:14:33 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 0A1024758F1 + for ; + Mon, 12 May 2003 22:14:32 -0400 (EDT) +Received: from c001.snv.cp.net (h005.c001.snv.cp.net [209.228.32.119]) + by postgresql.org (Postfix) with SMTP id 13786474E42 + for ; + Mon, 12 May 2003 22:14:31 -0400 (EDT) +Received: (cpmta 12475 invoked from network); 12 May 2003 19:14:34 -0700 +Received: from 209.228.32.123 (HELO mail.dilger.cc.criticalpath.net) + by smtp.register-admin.com (209.228.32.119) with SMTP; + 12 May 2003 19:14:34 -0700 +X-Sent: 13 May 2003 02:14:34 GMT +Received: from [216.68.146.219] by mail.dilger.cc with HTTP; + Mon, 12 May 2003 19:14:31 -0700 (PDT) +Content-Type: text/plain; charset=iso-8859-1 +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +MIME-Version: 1.0 +To: alfranio@lsd.di.uminho.pt +Cc: pgsql-performance@postgresql.org +From: "Nikolaus Dilger" +Subject: Re: PERFORMANCE and SIZE +X-Sent-From: nikolaus@dilger.cc +Date: Mon, 12 May 2003 19:14:31 -0700 (PDT) +X-Mailer: Web Mail 5.3.1-0_sol28 +Message-Id: + <20030512191434.26622.h009.c001.wm@mail.dilger.cc.criticalpath.net> +X-Spam-Status: No, hits=-13.7 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,QUOTE_TWICE_1 + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/140 +X-Sequence-Number: 1919 + +Alfranio Junior, + +99% likely: You ran the second query after the first +and the 4 result rows where already stored in memory. +The first execution took longer because the database +had to go to the disk after looking up in the index +what rows to get. I further assume that the index was +already in memory for both queries since you most +likely just build it. + +Of course you also need to vaccuum on a regular basis +in order to have up to date statstics. + +Regards, +Nikolaus Dilger + + +On Mon, 12 May 2003 12:35:24 -0700, "Alfranio Junior" +wrote: + +> +> Hello, +> +> I'm a new PostgresSql user and I do not know so much +> about the +> performance mechanisms currently implemented and +> available. +> +> So, as a dummy user I think that something strange is +> happening with me. +> When I run the following command: +> +> explain analyze select * from customer +> where c_last = 'ROUGHTATION' and +> c_w_id = 1 and +> c_d_id = 1 +> order by c_w_id, c_d_id, c_last, c_first limit +1; +> +> I receive the following results: +> +> (Customer table with 60.000 rows) - +> + +> QUERY PLAN +> +--------------------------------------------------------------------------- +> +----------------------------------------------------------- +> Limit (cost=4.84..4.84 rows=1 width=283) (actual +> time=213.13..213.13 +> rows=0 loops=1) +> -> Sort (cost=4.84..4.84 rows=1 width=283) +> (actual +> time=213.13..213.13 rows=0 loops=1) +> Sort Key: c_w_id, c_d_id, c_last, c_first +> -> Index Scan using pk_customer on +customer +> (cost=0.00..4.83 +> rows=1 width=283) (actual time=211.93..211.93 rows=0 +> loops=1) +> Index Cond: ((c_w_id = 1) AND (c_d_id +> = 1)) +> Filter: (c_last = +> 'ROUGHTATION'::bpchar) +> Total runtime: 213.29 msec +> (7 rows) +> +> +> (Customer table with 360.000 rows) - +> + +> QUERY PLAN +> +--------------------------------------------------------------------------- +> +------------------------------------------------------------- +> Limit (cost=11100.99..11101.00 rows=1 width=638) +> (actual +> time=20.82..20.82 rows=0 loops=1) +> -> Sort (cost=11100.99..11101.00 rows=4 +> width=638) (actual +> time=20.81..20.81 rows=0 loops=1) +> Sort Key: c_w_id, c_d_id, c_last, c_first +> -> Index Scan using pk_customer on +customer +> (cost=0.00..11100.95 rows=4 width=638) (actual +> time=20.40..20.40 rows=0 +> loops=1) +> Index Cond: ((c_w_id = 1) AND (c_d_id +> = 1)) +> Filter: (c_last = +> 'ROUGHTATION'::bpchar) +> Total runtime: 21.11 msec +> (7 rows) +> +> Increasing the number of rows the total runtime +> decreases. +> The customer table has the following structure: +> CREATE TABLE customer +> ( +> c_id int NOT NULL , +> c_d_id int4 NOT NULL , +> c_w_id int4 NOT NULL , +> c_first char (16) NULL , +> c_middle char (2) NULL , +> c_last char (16) NULL , +> c_street_1 char (20) NULL , +> c_street_2 char (20) NULL , +> c_city char (20) NULL , +> c_state char (2) NULL , +> c_zip char (9) NULL , +> c_phone char (16) NULL , +> c_since timestamp NULL , +> c_credit char (2) NULL , +> c_credit_lim numeric(12, 2) NULL , +> c_discount numeric(4, 4) NULL , +> c_balance numeric(12, 2) NULL , +> c_ytd_payment numeric(12, 2) NULL , +> c_payment_cnt int4 NULL , +> c_delivery_cnt int4 NULL , +> c_data text NULL +> ); +> +> ALTER TABLE customer ADD +> CONSTRAINT PK_customer PRIMARY KEY +> ( +> c_w_id, +> c_d_id, +> c_id +> ); +> +> Does anybody know what is happening ? +> +> +> Thanks !!!! +> +> Alfranio Junior +> +> +> ---------------------------(end of +> broadcast)--------------------------- +> TIP 5: Have you checked our extensive FAQ? +> +> http://www.postgresql.org/docs/faqs/FAQ.html + + +From pgsql-performance-owner@postgresql.org Mon May 12 23:32:17 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 27A0647621C + for ; + Mon, 12 May 2003 23:32:16 -0400 (EDT) +Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) + by postgresql.org (Postfix) with ESMTP id 622434758F1 + for ; + Mon, 12 May 2003 23:32:15 -0400 (EDT) +Received: from [63.195.55.98] (HELO spooky) + by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) + with ESMTP id 3029486; Mon, 12 May 2003 20:32:21 -0700 +Content-Type: text/plain; + charset="iso-8859-1" +From: Josh Berkus +Organization: Aglio Database Solutions +To: csajl , pgsql-performance@postgresql.org +Subject: Re: [repost] partial index / funxtional idx or bad sql? +Date: Mon, 12 May 2003 20:32:10 -0700 +User-Agent: KMail/1.4.3 +References: <20030513004710.58428.qmail@web40312.mail.yahoo.com> +In-Reply-To: <20030513004710.58428.qmail@web40312.mail.yahoo.com> +MIME-Version: 1.0 +Message-Id: <200305122032.10928.josh@agliodbs.com> +Content-Transfer-Encoding: quoted-printable +X-Spam-Status: No, hits=-32.4 required=5.0 + tests=BAYES_01,IN_REP_TO,QUOTED_EMAIL_TEXT,REFERENCES, + REPLY_WITH_QUOTES,USER_AGENT_KMAIL autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/141 +X-Sequence-Number: 1920 + +Csajl, + +> i'm using 7.3.2. i tried using EXISTS instead of the IN, but the same +> query now returns in seven sceonds as opposed to four with the IN. + +> classifieds_dual_idx is the btree index on (class_type_id, areacode) +> and site_cm_areacode_idx is the btree index on (site_id) only. +> there is an index in the areacode table that has both (site_id, areacode) +> but it's apparently not being used. would it help the query to use that +> index instead? + +No.=20=20 +>From the look of things, it's not the index scan that's taking time ... it'= +s=20 +the subplan, which is doing 61,000 loops. Which is normal for IN, but not= +=20 +for EXISTS. You run VACUUM ANALYZE? + +--=20 +Josh Berkus +Aglio Database Solutions +San Francisco + + +From pgsql-performance-owner@postgresql.org Mon May 12 23:47:55 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 0AD604758F1 + for ; + Mon, 12 May 2003 23:47:54 -0400 (EDT) +Received: from megazone.bigpanda.com (megazone.bigpanda.com [63.150.15.178]) + by postgresql.org (Postfix) with ESMTP id 6F0DC474E42 + for ; + Mon, 12 May 2003 23:47:50 -0400 (EDT) +Received: by megazone.bigpanda.com (Postfix, from userid 1001) + id 6EC4DD62B; Mon, 12 May 2003 20:47:55 -0700 (PDT) +Received: from localhost (localhost [127.0.0.1]) + by megazone.bigpanda.com (Postfix) with ESMTP + id 4A6615C0A; Mon, 12 May 2003 20:47:55 -0700 (PDT) +Date: Mon, 12 May 2003 20:47:55 -0700 (PDT) +From: Stephan Szabo +To: csajl +Cc: , +Subject: Re: [repost] partial index / funxtional idx or bad sql? +In-Reply-To: <20030513004710.58428.qmail@web40312.mail.yahoo.com> +Message-ID: <20030512204533.I20042-100000@megazone23.bigpanda.com> +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-Spam-Status: No, hits=-26.0 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REPLY_WITH_QUOTES autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/142 +X-Sequence-Number: 1921 + + +On Mon, 12 May 2003, csajl wrote: + +> i'm using 7.3.2. i tried using EXISTS instead of the IN, but the same query +> now returns in seven sceonds as opposed to four with the IN. +> +> +> cmdb=# EXPLAIN ANALYZE +> cmdb-# select c.class_id, c.areacode, c.title from classifieds c +> cmdb-# where c.class_cat_id = '1' +> cmdb-# and c.areacode IN ( +> cmdb(# select areacode from cm_areacode where site_id = '10') +> cmdb-# ; + +How about something like: + +select c.class_id, c.areacode, c.title from + classifieds c, + (select distinct areacode from cm_areacode where site_id='10') a + where c.class_cat_id='1' and c.areacode=a.areacode; + + +From pgsql-performance-owner@postgresql.org Mon May 12 23:58:51 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 3A67C4758F1 + for ; + Mon, 12 May 2003 23:58:50 -0400 (EDT) +Received: from web40310.mail.yahoo.com (web40310.mail.yahoo.com + [66.218.78.89]) + by postgresql.org (Postfix) with SMTP id 2C38A474E42 + for ; + Mon, 12 May 2003 23:58:49 -0400 (EDT) +Message-ID: <20030513035854.78339.qmail@web40310.mail.yahoo.com> +Received: from [216.103.85.15] by web40310.mail.yahoo.com via HTTP; + Mon, 12 May 2003 20:58:54 PDT +Date: Mon, 12 May 2003 20:58:54 -0700 (PDT) +From: csajl +Subject: Re: [repost] partial index / funxtional idx or bad sql? +To: Josh Berkus , pgsql-performance@postgresql.org +In-Reply-To: <200305122032.10928.josh@agliodbs.com> +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Spam-Status: No, hits=-26.0 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REPLY_WITH_QUOTES autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/143 +X-Sequence-Number: 1922 + + +hi josh. + +thanks for your help and time with this. + +ran vacuum analyze, still timed in around 3seconds. +i dropped the site_id only index on the areacodes table in favor of the dual +site_id and areacode index and seemingly gained 1/2 second. + +by using the IN, i gain another .3 of a second. (i thought EXISTS was supposed +to be more efficient?) + +the loop on the subplan (~62k) is killing me. any alternatives to what i +thought would be a seemingly innocuous lookup? the cm_Areacode table is +nothing more than two columns, associating each areacode into a site_id. (292 +rows if i remember correctly) + + +cmdb=# EXPLAIN ANALYZE +cmdb-# select c.class_id, c.areacode, c.title from classifieds c +cmdb-# where c.class_cat_id = '1' +cmdb-# and EXISTS ( +cmdb(# select areacode from cm_areacode cm where site_id = '10' and c.areacode += cm.areacode) +cmdb-# ; + QUERY +PLAN +-------------------------------------------------------------------------------------------------------------------------------------------------------- + Index Scan using classifieds_dual_idx on classifieds c (cost=0.00..493277.77 +rows=28413 width=39) (actual time=360.23..2523.08 rows=8460 loops=1) + Index Cond: (class_cat_id = 1) + Filter: (subplan) + SubPlan + -> Index Scan using areacode_site_dual_cmareacode on cm_areacode cm +(cost=0.00..4.96 rows=1 width=2) (actual time=0.01..0.01 rows=0 loops=61966) + Index Cond: ((site_id = 10) AND ($0 = areacode)) + Total runtime: 2533.93 msec +(7 rows) + +cmdb=# +------------------------------------ + +cmdb=# EXPLAIN ANALYZE +cmdb-# select c.class_id, c.areacode, c.title from classifieds c +cmdb-# where c.class_cat_id = '1' +cmdb-# and c.areacode IN ( +cmdb(# select areacode from cm_areacode where site_id = '10') +cmdb-# ; + QUERY PLAN +---------------------------------------------------------------------------------------------------------------------------------------------------- + Index Scan using classifieds_dual_idx on classifieds c (cost=0.00..632183.80 +rows=28413 width=39) (actual time=344.70..2287.93 rows=8460 loops=1) + Index Cond: (class_cat_id = 1) + Filter: (subplan) + SubPlan + -> Materialize (cost=7.40..7.40 rows=4 width=2) (actual time=0.00..0.00 +rows=5 loops=61966) + -> Seq Scan on cm_areacode (cost=0.00..7.40 rows=4 width=2) +(actual time=0.20..0.73 rows=5 loops=1) + Filter: (site_id = 10) + Total runtime: 2296.83 msec +(8 rows) + + + +--- Josh Berkus wrote: +> Csajl, +> +> > i'm using 7.3.2. i tried using EXISTS instead of the IN, but the same +> > query now returns in seven sceonds as opposed to four with the IN. +> +> > classifieds_dual_idx is the btree index on (class_type_id, areacode) +> > and site_cm_areacode_idx is the btree index on (site_id) only. +> > there is an index in the areacode table that has both (site_id, areacode) +> > but it's apparently not being used. would it help the query to use that +> > index instead? +> +> No. +> From the look of things, it's not the index scan that's taking time ... it's +> the subplan, which is doing 61,000 loops. Which is normal for IN, but not +> for EXISTS. You run VACUUM ANALYZE? + + +__________________________________ +Do you Yahoo!? +The New Yahoo! Search - Faster. Easier. Bingo. +http://search.yahoo.com + + +From pgsql-performance-owner@postgresql.org Tue May 13 00:03:36 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 962244758F1 + for ; + Tue, 13 May 2003 00:03:34 -0400 (EDT) +Received: from web40305.mail.yahoo.com (web40305.mail.yahoo.com + [66.218.78.84]) + by postgresql.org (Postfix) with SMTP id DD4C9474E42 + for ; + Tue, 13 May 2003 00:03:32 -0400 (EDT) +Message-ID: <20030513040338.3925.qmail@web40305.mail.yahoo.com> +Received: from [216.103.85.15] by web40305.mail.yahoo.com via HTTP; + Mon, 12 May 2003 21:03:38 PDT +Date: Mon, 12 May 2003 21:03:38 -0700 (PDT) +From: csajl +Subject: Re: [repost] partial index / funxtional idx or bad sql? +To: Stephan Szabo +Cc: josh@agliodbs.com, pgsql-performance@postgresql.org +In-Reply-To: <20030512204533.I20042-100000@megazone23.bigpanda.com> +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Spam-Status: No, hits=-26.0 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REPLY_WITH_QUOTES autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/144 +X-Sequence-Number: 1923 + + +wow. + +that did it. so much for my knowing SQL... + +unbelievable - thanks much. + + +cmdb=# EXPLAIN ANALYZE +cmdb-# select c.class_id, c.areacode, c.title from classifieds c +cmdb-# , (select distinct areacode from cm_areacode where site_id='10') a +cmdb-# where c.class_cat_id='1' and c.areacode=a.areacode; + QUERY PLAN +-------------------------------------------------------------------------------------------------------------------------------------------------- + Nested Loop (cost=7.44..1107.53 rows=279 width=41) (actual time=1.13..258.11 +rows=8460 loops=1) + -> Subquery Scan a (cost=7.44..7.46 rows=1 width=2) (actual +time=0.86..0.92 rows=5 loops=1) + -> Unique (cost=7.44..7.46 rows=1 width=2) (actual time=0.85..0.88 +rows=5 loops=1) + -> Sort (cost=7.44..7.45 rows=4 width=2) (actual +time=0.85..0.86 rows=5 loops=1) + Sort Key: areacode + -> Seq Scan on cm_areacode (cost=0.00..7.40 rows=4 +width=2) (actual time=0.20..0.73 rows=5 loops=1) + Filter: (site_id = 10) + -> Index Scan using classifieds_dual_idx on classifieds c +(cost=0.00..1096.59 rows=279 width=39) (actual time=0.22..44.28 rows=1692 +loops=5) + Index Cond: ((c.class_cat_id = 1) AND (c.areacode = "outer".areacode)) + Total runtime: 267.71 msec +(10 rows) + + + + + +--- Stephan Szabo wrote: +> +> On Mon, 12 May 2003, csajl wrote: +> +> > i'm using 7.3.2. i tried using EXISTS instead of the IN, but the same +> query +> > now returns in seven sceonds as opposed to four with the IN. +> > +> > +> > cmdb=# EXPLAIN ANALYZE +> > cmdb-# select c.class_id, c.areacode, c.title from classifieds c +> > cmdb-# where c.class_cat_id = '1' +> > cmdb-# and c.areacode IN ( +> > cmdb(# select areacode from cm_areacode where site_id = '10') +> > cmdb-# ; +> +> How about something like: +> +> select c.class_id, c.areacode, c.title from +> classifieds c, +> (select distinct areacode from cm_areacode where site_id='10') a +> where c.class_cat_id='1' and c.areacode=a.areacode; +> + + +__________________________________ +Do you Yahoo!? +The New Yahoo! Search - Faster. Easier. Bingo. +http://search.yahoo.com + + +From pgsql-performance-owner@postgresql.org Tue May 13 06:58:21 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 4A5654762CF + for ; + Tue, 13 May 2003 06:58:19 -0400 (EDT) +Received: from flake.decibel.org (unknown [66.143.173.58]) + by postgresql.org (Postfix) with SMTP id 31694474E42 + for ; + Tue, 13 May 2003 06:58:15 -0400 (EDT) +Received: (qmail 83013 invoked by uid 1001); 13 May 2003 10:58:17 -0000 +Date: Tue, 13 May 2003 05:58:17 -0500 +From: "Jim C. Nasby" +To: csajl +Cc: Stephan Szabo , + josh@agliodbs.com, pgsql-performance@postgresql.org +Subject: Re: [repost] partial index / funxtional idx or bad sql? +Message-ID: <20030513055817.N66185@flake.decibel.org> +Reply-To: jim@nasby.net +References: <20030512204533.I20042-100000@megazone23.bigpanda.com> + <20030513040338.3925.qmail@web40305.mail.yahoo.com> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +User-Agent: Mutt/1.2.5.1i +In-Reply-To: <20030513040338.3925.qmail@web40305.mail.yahoo.com>; + from csajl@yahoo.com on Mon, May 12, 2003 at 09:03:38PM -0700 +X-Operating-System: FreeBSD 4.8-RELEASE i386 +X-Distributed: Join the Effort! http://www.distributed.net +X-Spam-Status: No, hits=-39.4 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REFERENCES,REPLY_WITH_QUOTES,SIGNATURE_SHORT_SPARSE, + USER_AGENT_MUTT autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/145 +X-Sequence-Number: 1924 + +On Mon, May 12, 2003 at 09:03:38PM -0700, csajl wrote: +> +> wow. +> +> that did it. so much for my knowing SQL... +> > +> > How about something like: +> > +> > select c.class_id, c.areacode, c.title from +> > classifieds c, +> > (select distinct areacode from cm_areacode where site_id='10') a +> > where c.class_cat_id='1' and c.areacode=a.areacode; +> > + +Wow, I'll have to keep that in mind. Shouldn't the optimizer be able to +handle that? Could this get added to the TODO? +-- +Jim C. Nasby (aka Decibel!) jim@nasby.net +Member: Triangle Fraternity, Sports Car Club of America +Give your computer some brain candy! www.distributed.net Team #1828 + +Windows: "Where do you want to go today?" +Linux: "Where do you want to go tomorrow?" +FreeBSD: "Are you guys coming, or what?" + + +From pgsql-performance-owner@postgresql.org Tue May 13 10:46:17 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 1C7624762CF + for ; + Tue, 13 May 2003 10:46:15 -0400 (EDT) +Received: from sss.pgh.pa.us (unknown [192.204.191.242]) + by postgresql.org (Postfix) with ESMTP id 8A2FB474E42 + for ; + Tue, 13 May 2003 10:46:12 -0400 (EDT) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h4DEkCU6008276; + Tue, 13 May 2003 10:46:12 -0400 (EDT) +To: jim@nasby.net +Cc: csajl , + Stephan Szabo , josh@agliodbs.com, + pgsql-performance@postgresql.org +Subject: Re: [repost] partial index / funxtional idx or bad sql? +In-reply-to: <20030513055817.N66185@flake.decibel.org> +References: <20030512204533.I20042-100000@megazone23.bigpanda.com> + <20030513040338.3925.qmail@web40305.mail.yahoo.com> + <20030513055817.N66185@flake.decibel.org> +Comments: In-reply-to "Jim C. Nasby" + message dated "Tue, 13 May 2003 05:58:17 -0500" +Date: Tue, 13 May 2003 10:46:12 -0400 +Message-ID: <8275.1052837172@sss.pgh.pa.us> +From: Tom Lane +X-Spam-Status: No, hits=-32.5 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REFERENCES,REPLY_WITH_QUOTES autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/147 +X-Sequence-Number: 1926 + +"Jim C. Nasby" writes: +> Wow, I'll have to keep that in mind. Shouldn't the optimizer be able to +> handle that? Could this get added to the TODO? + +No, 'cause it's done (in CVS tip). + +I'm actually a bit hesitant now to recommend that people do such things, +because the 7.4 optimizer is likely to produce a better plan from the +unmodified IN query than it will from any explicitly "improved" version. +The 7.4 code knows several ways to do IN efficiently, but when you +hand-transform the query you are forcing the choice; perhaps wrongly. + +An example from CVS tip and the regression database in which hand +transformation forces a less efficient plan choice: + +regression=# explain analyze select * from tenk1 a where unique1 in (select ten from tenk1); + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------------------- + Merge Join (cost=483.17..484.91 rows=10 width=248) (actual time=407.14..409.16 rows=10 loops=1) + Merge Cond: ("outer".unique1 = "inner".ten) + -> Index Scan using tenk1_unique1 on tenk1 a (cost=0.00..1571.97 rows=10000 width=244) (actual time=0.41..1.60 rows=11 loops=1) + -> Sort (cost=483.17..483.19 rows=10 width=4) (actual time=406.57..406.65 rows=10 loops=1) + Sort Key: tenk1.ten + -> HashAggregate (cost=483.00..483.00 rows=10 width=4) (actual time=406.08..406.26 rows=10 loops=1) + -> Seq Scan on tenk1 (cost=0.00..458.00 rows=10000 width=4) (actual time=0.19..261.84 rows=10000 loops=1) + Total runtime: 410.74 msec +(8 rows) + +regression=# explain analyze select * from tenk1 a, (select distinct ten from tenk1) b +regression-# where a.unique1 = b.ten; + QUERY PLAN +--------------------------------------------------------------------------------------------------------------------------------- + Nested Loop (cost=1122.39..1232.59 rows=10 width=248) (actual time=476.67..666.02 rows=10 loops=1) + -> Subquery Scan b (cost=1122.39..1172.39 rows=10 width=4) (actual time=475.94..662.00 rows=10 loops=1) + -> Unique (cost=1122.39..1172.39 rows=10 width=4) (actual time=475.89..661.65 rows=10 loops=1) + -> Sort (cost=1122.39..1147.39 rows=10000 width=4) (actual time=475.85..559.27 rows=10000 loops=1) + Sort Key: ten + -> Seq Scan on tenk1 (cost=0.00..458.00 rows=10000 width=4) (actual time=0.37..274.87 rows=10000 loops=1) + -> Index Scan using tenk1_unique1 on tenk1 a (cost=0.00..6.01 rows=1 width=244) (actual time=0.27..0.31 rows=1 loops=10) + Index Cond: (a.unique1 = "outer".ten) + Total runtime: 687.53 msec +(9 rows) + +So, for now, make the transformation ... but keep a note about the IN +version to try whenever you update to 7.4. + + regards, tom lane + + +From pgsql-performance-owner@postgresql.org Tue May 13 12:15:46 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 04BD547636B + for ; + Tue, 13 May 2003 12:15:44 -0400 (EDT) +Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) + by postgresql.org (Postfix) with ESMTP id 48252474E42 + for ; + Tue, 13 May 2003 12:15:43 -0400 (EDT) +Received: from [63.195.55.98] (HELO spooky) + by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) + with ESMTP id 3030574; Tue, 13 May 2003 09:15:49 -0700 +Content-Type: text/plain; + charset="iso-8859-1" +From: Josh Berkus +Organization: Aglio Database Solutions +To: "Alfranio Junior" , + +Subject: Re: PERFORMANCE and SIZE +Date: Tue, 13 May 2003 09:15:34 -0700 +User-Agent: KMail/1.4.3 +References: <011d01c318be$997217f0$9002a8c0@ialfranio> + <200305120849.39381.josh@agliodbs.com> + <012a01c3198e$48957270$9002a8c0@ialfranio> +In-Reply-To: <012a01c3198e$48957270$9002a8c0@ialfranio> +MIME-Version: 1.0 +Message-Id: <200305130915.34850.josh@agliodbs.com> +Content-Transfer-Encoding: quoted-printable +X-Spam-Status: No, hits=-22.7 required=5.0 + tests=BAYES_01,IN_REP_TO,REFERENCES,USER_AGENT_KMAIL + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/148 +X-Sequence-Number: 1927 + +Alfranio, + +> And now, the optimizer started to use a table scan and in consequence giv= +es +> me: + +What appears to me to be happening is that the planner has incorrect estima= +tes=20 +of the cost of an index lookup. The base estimate is contained in the=20 +postgresql.conf parameter: +cpu_index_tuple_cost =3D 0.001 + + From the look of things, your disk/array has much better random seek times= +=20 +than the standard, or you have enough RAM to cache most of your tables.=20= +=20 +Either way, I would experiment with lowering the index_tuple_cost to, say,= +=20 +0.0003 and see if you get better use of indexes. + +If that does work for you, make sure to check some other queries unrelated = +to=20 +the "customers" table to make sure that the new setting doesn't mess them u= +p=20 +in some way. + +--=20 +Josh Berkus +Aglio Database Solutions +San Francisco + + +From pgsql-performance-owner@postgresql.org Tue May 13 15:45:33 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 673DB47636B + for ; + Tue, 13 May 2003 15:45:31 -0400 (EDT) +Received: from megazone.bigpanda.com (megazone.bigpanda.com [63.150.15.178]) + by postgresql.org (Postfix) with ESMTP id 8BA75476348 + for ; + Tue, 13 May 2003 15:45:26 -0400 (EDT) +Received: by megazone.bigpanda.com (Postfix, from userid 1001) + id 5DDC0D61B; Tue, 13 May 2003 12:45:27 -0700 (PDT) +Received: from localhost (localhost [127.0.0.1]) + by megazone.bigpanda.com (Postfix) with ESMTP + id 5396A5C03; Tue, 13 May 2003 12:45:27 -0700 (PDT) +Date: Tue, 13 May 2003 12:45:27 -0700 (PDT) +From: Stephan Szabo +To: Tom Lane +Cc: Josh Berkus , Ryan , + +Subject: Re: How are null's stored? +In-Reply-To: <24826.1052783424@sss.pgh.pa.us> +Message-ID: <20030513123355.B29586-100000@megazone23.bigpanda.com> +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-Spam-Status: No, hits=-26.0 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REPLY_WITH_QUOTES autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/149 +X-Sequence-Number: 1928 + + +On Mon, 12 May 2003, Tom Lane wrote: + +> Stephan Szabo writes: +> > All in all, I'm not sure what the semantic differences between a varchar +> > with no length specified and a text are in PostgreSQL actually and if the +> > whole thing could be simplified in some way that doesn't break backwards +> > compatibility. +> +> Yeah, I've been wondering about that too. A large part of the problem +> is that varchar has its own set of operators, which the planner has no +> right to assume behave exactly like the text ones ... but they do. It +> might work to rip out the redundant varchar operators and allow indexes +> on varchar to become truly textual indexes (ie, they'd be text_ops not +> varchar_ops opclass). There might be a few tweaks needed to get the +> planner to play nice with indexes that require implicit coercions, but +> I think it could be made to work. + +This seems to possibly work on 7.4. I took my system and removed the +varchar comparison operators and directly made a text_ops index on a +varchar(30). +That gave me indexscans for + col = 'a' + col = 'a'::varchar + col = 'a'::text + col = 'a' || 'b' + +but I don't know if it has other bad effects yet. + + +> Another idea that has been rattling around is to stop treating bpchar as +> binary-equivalent to text, and in fact to make bpchar-to-text promotion +> go through rtrim() to eliminate padding spaces. + +I guess this depends on how we read the comparisons/conversions from PAD +SPACE to NO PAD are supposed to work, but I think this would be good and +make things easier for alot of people since most people don't expect it, +especially when using functions like upper and lower that return text. + + +From pgsql-performance-owner@postgresql.org Tue May 13 16:16:13 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 5A3F0475EE2 + for ; + Tue, 13 May 2003 16:16:12 -0400 (EDT) +Received: from sss.pgh.pa.us (unknown [192.204.191.242]) + by postgresql.org (Postfix) with ESMTP id 96BA9475AA9 + for ; + Tue, 13 May 2003 16:16:11 -0400 (EDT) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h4DKGAU6028559; + Tue, 13 May 2003 16:16:10 -0400 (EDT) +To: Stephan Szabo +Cc: Josh Berkus , + Ryan , pgsql-performance@postgresql.org +Subject: Re: How are null's stored? +In-reply-to: <20030513123355.B29586-100000@megazone23.bigpanda.com> +References: <20030513123355.B29586-100000@megazone23.bigpanda.com> +Comments: In-reply-to Stephan Szabo + message dated "Tue, 13 May 2003 12:45:27 -0700" +Date: Tue, 13 May 2003 16:16:10 -0400 +Message-ID: <28558.1052856970@sss.pgh.pa.us> +From: Tom Lane +X-Spam-Status: No, hits=-32.5 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REFERENCES,REPLY_WITH_QUOTES autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/150 +X-Sequence-Number: 1929 + +Stephan Szabo writes: +> On Mon, 12 May 2003, Tom Lane wrote: +>> It might work to rip out the redundant varchar operators and allow indexes +>> on varchar to become truly textual indexes (ie, they'd be text_ops not +>> varchar_ops opclass). + +> This seems to possibly work on 7.4. I took my system and removed the +> varchar comparison operators and directly made a text_ops index on a +> varchar(30). + +Yeah, I fooled with it a little bit last night too. It seems that we'd +need to still have a varchar_ops entry in pg_opclass (else you get +complaints about unable to select a default opclass, not to mention that +old pg_dump files specifying varchar_ops would fail to load). But this +entry could point to the textual comparison operators. AFAICT the +planner doesn't have any problem dealing with the implicit coercions +that it's faced with in such cases. + +>> Another idea that has been rattling around is to stop treating bpchar as +>> binary-equivalent to text, and in fact to make bpchar-to-text promotion +>> go through rtrim() to eliminate padding spaces. + +> I guess this depends on how we read the comparisons/conversions from PAD +> SPACE to NO PAD are supposed to work, but I think this would be good and +> make things easier for alot of people since most people don't expect it, +> especially when using functions like upper and lower that return text. + +I tried that too, and it seemed to work as expected. Whether it's +arguably more spec-compliant than our current behavior I dunno; haven't +looked at that part of the spec closely... + + regards, tom lane + + +From pgsql-performance-owner@postgresql.org Tue May 13 08:31:45 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id B78E34763A9 + for ; + Tue, 13 May 2003 08:31:44 -0400 (EDT) +Received: from homer.lsd.di.uminho.pt (gsd.di.uminho.pt [193.136.20.132]) + by postgresql.org (Postfix) with SMTP id C9F724763A1 + for ; + Tue, 13 May 2003 08:31:36 -0400 (EDT) +Received: (qmail 8419 invoked from network); 13 May 2003 12:31:30 -0000 +Received: from alfranio.lsd.di.uminho.pt (HELO ialfranio) (192.168.2.144) + by mailer.lsd.di.uminho.pt with SMTP; 13 May 2003 12:31:30 -0000 +Message-ID: <012a01c3198e$48957270$9002a8c0@ialfranio> +From: "Alfranio Junior" +To: +References: <011d01c318be$997217f0$9002a8c0@ialfranio> + <200305120849.39381.josh@agliodbs.com> +Subject: Re: PERFORMANCE and SIZE +Date: Tue, 13 May 2003 13:28:58 -0700 +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit +X-Priority: 3 +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook Express 6.00.2720.3000 +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 +X-Spam-Status: No, hits=-11.6 required=5.0 + tests=BAYES_20,DATE_IN_FUTURE_06_12,QUOTED_EMAIL_TEXT,REFERENCES + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/146 +X-Sequence-Number: 1925 + +Josh, + +I ran the vacuumdb as follows: +vacuumdb -f -v -e -a + +and after that, + +vacuumdb -z -v -e -a. + +And now, the optimizer started to use a table scan and in consequence gives +me: + +explain analyze select * from customer + +where c_last = 'ROUGHTATION' and + +c_w_id = 1 and + +c_d_id = 1 + +order by c_w_id, c_d_id, c_last, c_first limit 1; + +QUERY PLAN + +---------------------------------------------------------------------------- +----------------------------------------- + +Limit (cost=6302.03..6302.03 rows=1 width=639) (actual time=208.33..208.33 +rows=0 loops=1) + +-> Sort (cost=6302.03..6302.04 rows=3 width=639) (actual time=208.32..208.32 +rows=0 loops=1) + +Sort Key: c_w_id, c_d_id, c_last, c_first + +-> Seq Scan on customer (cost=0.00..6302.00 rows=3 width=639) (actual +time=207.99..207.99 rows=0 loops=1) + +Filter: ((c_last = 'ROUGHTATION'::bpchar) AND (c_w_id = 1) AND (c_d_id = 1)) + +Total runtime: 208.54 msec + +(6 rows) + + + + +When I force the index use a receive a better result: + +set enable_seqscan to off; + +explain analyze select * from customer + +where c_last = 'ROUGHTATION' and + +c_w_id = 1 and + +c_d_id = 1 + +order by c_w_id, c_d_id, c_last, c_first limit 1; + + +QUERY PLAN + +---------------------------------------------------------------------------- +----------------------------------------------------------- + +Limit (cost=9860.03..9860.03 rows=1 width=639) (actual time=13.98..13.98 +rows=0 loops=1) + +-> Sort (cost=9860.03..9860.04 rows=3 width=639) (actual time=13.98..13.98 +rows=0 loops=1) + +Sort Key: c_w_id, c_d_id, c_last, c_first + +-> Index Scan using pk_customer on customer (cost=0.00..9860.00 rows=3 +width=639) (actual time=13.86..13.86 rows=0 loops=1) + +Index Cond: ((c_w_id = 1) AND (c_d_id = 1)) + +Filter: (c_last = 'ROUGHTATION'::bpchar) + +Total runtime: 14.11 msec + +(7 rows) + +Is this the only way to force the index ? +What are the reasons to the optimizer to decide for a worse plan ? + +> Alfranio, +> +> > I'm a new PostgresSql user and I do not know so much about the +> > performance mechanisms currently implemented and available. +> +> > Does anybody know what is happening ? +> +> 90% likely: You haven't run VACUUM FULL ANALYZE in a while. +> +> -- +> Josh Berkus +> Aglio Database Solutions +> San Francisco +> + + +From pgsql-performance-owner@postgresql.org Tue May 13 17:05:36 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 9C0CA475AA9 + for ; + Tue, 13 May 2003 17:05:34 -0400 (EDT) +Received: from mail1.ihs.com (mail1.ihs.com [170.207.70.222]) + by postgresql.org (Postfix) with ESMTP id CA86D475EE2 + for ; + Tue, 13 May 2003 17:05:29 -0400 (EDT) +Received: from css120.ihs.com (css120.ihs.com [170.207.105.120]) + by mail1.ihs.com (8.12.9/8.12.9) with ESMTP id h4DL3wb0013206; + Tue, 13 May 2003 15:03:58 -0600 (MDT) +Date: Tue, 13 May 2003 14:51:37 -0600 (MDT) +From: "scott.marlowe" +To: Josh Berkus +Cc: Alfranio Junior , + +Subject: Re: PERFORMANCE and SIZE +In-Reply-To: <200305130915.34850.josh@agliodbs.com> +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-MailScanner: Found to be clean +X-MailScanner-SpamCheck: +X-Spam-Status: No, hits=-31.7 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REPLY_WITH_QUOTES,USER_AGENT_PINE autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/151 +X-Sequence-Number: 1930 + +On Tue, 13 May 2003, Josh Berkus wrote: + +> Alfranio, +> +> > And now, the optimizer started to use a table scan and in consequence gives +> > me: +> +> What appears to me to be happening is that the planner has incorrect estimates +> of the cost of an index lookup. The base estimate is contained in the +> postgresql.conf parameter: +> cpu_index_tuple_cost = 0.001 +> +> >From the look of things, your disk/array has much better random seek times +> than the standard, or you have enough RAM to cache most of your tables. +> Either way, I would experiment with lowering the index_tuple_cost to, say, +> 0.0003 and see if you get better use of indexes. +> +> If that does work for you, make sure to check some other queries unrelated to +> the "customers" table to make sure that the new setting doesn't mess them up +> in some way. + +Also, you can lower random page cost. And make sure the query planner has +some idea how much effective cache you have, as it can kind of take that +into account too. i.e. a machine wiht 800 Meg cache is far more likely to +have data in memory than one 100 MEg cache. This is kernel cache I'm +talking about, by the way. effective cache size is set in 8k blocks. + + +From pgsql-performance-owner@postgresql.org Tue May 13 17:52:37 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 5E31C4763D2 + for ; + Tue, 13 May 2003 17:52:36 -0400 (EDT) +Received: from smtp.web.de (smtp02.web.de [217.72.192.151]) + by postgresql.org (Postfix) with ESMTP id 7C5FF4763C2 + for ; + Tue, 13 May 2003 17:52:31 -0400 (EDT) +Received: from p50818a51.dip0.t-ipconnect.de ([80.129.138.81] helo=web.de) + by smtp.web.de with asmtp (TLSv1:RC4-MD5:128) (WEB.DE 4.98 #232) + id 19FhhI-0008Kq-00; Tue, 13 May 2003 23:52:32 +0200 +Message-ID: <3EC1691D.4050604@web.de> +Date: Tue, 13 May 2003 23:52:29 +0200 +From: Andreas Pflug +User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3) Gecko/20030312 +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: Jamie Lawrence , pgsql-performance@postgresql.org +Subject: Re: Finding filenames for tables +References: <20030513223055.GZ4093@jal.clueinc.net> +In-Reply-To: <20030513223055.GZ4093@jal.clueinc.net> +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit +X-Spam-Status: No, hits=-34.4 required=5.0 + tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,RCVD_IN_NJABL, + REFERENCES,REPLY_WITH_QUOTES,USER_AGENT_MOZILLA_UA + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/153 +X-Sequence-Number: 1932 + +Jamie Lawrence wrote: + +>How do I join pg_class and pg_database to determine OID/tablename +>pairs for a given database? I can't find anything to join on in those +>tables. I'm just grepping output right now, but I'd like to do more +>complicated things in the future, thus my question. +> +> +Jamie, + +you don't need to join since pg_class is specific for a database. You +cannot see any classes from a different database in pg_class. In +contrast, pg_database is server-wide mirrored. + +Regards, +Andreas + + +From pgsql-performance-owner@postgresql.org Tue May 13 17:55:41 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 35AEF4763B1 + for ; + Tue, 13 May 2003 17:55:40 -0400 (EDT) +Received: from flake.decibel.org (flake.decibel.org [66.143.173.58]) + by postgresql.org (Postfix) with SMTP id 2E5EB4763AF + for ; + Tue, 13 May 2003 17:55:39 -0400 (EDT) +Received: (qmail 10158 invoked by uid 1001); 13 May 2003 21:55:41 -0000 +Date: Tue, 13 May 2003 16:55:41 -0500 +From: "Jim C. Nasby" +To: pgsql-performance@postgresql.org +Subject: Re: How are null's stored? -- Some numbers +Message-ID: <20030513215541.GC40542@flake.decibel.org> +Reply-To: jim@nasby.net +References: <20030512190156.GA40542@flake.decibel.org> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: <20030512190156.GA40542@flake.decibel.org> +User-Agent: Mutt/1.4.1i +X-Operating-System: FreeBSD 4.8-RELEASE i386 +X-Distributed: Join the Effort! http://www.distributed.net +X-Spam-Status: No, hits=-23.2 required=5.0 + tests=BAYES_01,IN_REP_TO,REFERENCES,SIGNATURE_SHORT_SPARSE, + USER_AGENT_MUTT autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/154 +X-Sequence-Number: 1933 + +I did two experiments. First, as someone mentioned, changing between +char and varchar made absolutely no difference size-wise. In some other +RDBMSes, performance wise char might still win out because the database +wouldn't have to do the math to figure out where in the tuple the fields +are. I know it's splitting hairs, but on what will be a 40M row table... + +Second, I modified the table (see below; all fields were originally +nullable): + +Before: +usps=# vacuum full analyze verbose zip4_detail; +INFO: --Relation public.zip4_detail-- +INFO: Pages 12728: Changed 0, reaped 1, Empty 0, New 0; Tup 467140: Vac +0, Keep/VTL 0/0, UnUsed 19, MinLen 154, MaxLen 302; Re-using: +Free/Avail. Space 1009820/264028; EndEmpty/Avail. Pages 0/1521. + CPU 0.65s/0.86u sec elapsed 1.51 sec. +INFO: Rel zip4_detail: Pages: 12728 --> 12728; Tuple(s) moved: 0. + CPU 0.00s/0.00u sec elapsed 0.00 sec. +INFO: Analyzing public.zip4_detail + + +After: +INFO: --Relation public.zip4_detail-- +INFO: Pages 13102: Changed 0, reaped 6961, Empty 0, New 0; Tup 467140: +Vac 0, Keep/VTL 0/0, UnUsed 31795, MinLen 166, MaxLen 306; Re-using: +Free/Avail. Space 1136364/190188; EndEmpty/Avail. Pages 0/1056. + CPU 0.41s/0.79u sec elapsed 1.20 sec. +INFO: Rel zip4_detail: Pages: 13102 --> 13102; Tuple(s) moved: 0. + CPU 0.59s/10.02u sec elapsed 18.17 sec. +INFO: Analyzing public.zip4_detail + +As you can see, space useage actually went up, by 2.9% (pages). In other +words, it appears to be more efficient to store a null than to store an +empty string in a varchar. + +usps=# select count(*) from zip4_detail where street_pre_drctn_abbrev='' +and street_suffix_abbrev='' and street_post_drctn_abbrev=''; +------- + 9599 + +usps=# select count(*) from zip4_detail where street_pre_drctn_abbrev='' +or street_suffix_abbrev=''; +-------- + 128434 + +(all rows have at least one of the 3 fields empty) + +Hope someone finds this info useful... :) + + Table "public.zip4_detail" + Column | Type | Modifiers +---------------------------+-----------------------+----------- + zip_code | character varying(5) | + update_key_no | character varying(10) | + action_code | character varying(1) | + record_type_code | character varying(1) | + carrier_route_id | character varying(4) | + street_pre_drctn_abbrev | character varying(2) | not null + street_name | character varying(28) | + street_suffix_abbrev | character varying(4) | not null + street_post_drctn_abbrev | character varying(2) | not null + addr_primary_low_no | character varying(10) | + addr_primary_high_no | character varying(10) | + addr_prmry_odd_even_code | character varying(1) | + building_or_firm_name | character varying(40) | + addr_secondary_abbrev | character varying(4) | + addr_secondary_low_no | character varying(8) | + addr_secondary_high_no | character varying(8) | + addr_secny_odd_even_code | character varying(1) | + zip_add_on_low_no | character varying(4) | + zip_add_on_high_no | character varying(4) | + base_alt_code | character varying(1) | + lacs_status_ind | character varying(1) | + govt_bldg_ind | character varying(1) | + finance_no | character varying(6) | + state_abbrev | character varying(2) | + county_no | character varying(3) | + congressional_dist_no | character varying(2) | + muncipality_ctyst_key | character varying(6) | + urbanization_ctyst_key | character varying(6) | + prefd_last_line_ctyst_key | character varying(6) | + +-- +Jim C. Nasby (aka Decibel!) jim@nasby.net +Member: Triangle Fraternity, Sports Car Club of America +Give your computer some brain candy! www.distributed.net Team #1828 + +Windows: "Where do you want to go today?" +Linux: "Where do you want to go tomorrow?" +FreeBSD: "Are you guys coming, or what?" + + +From pgsql-performance-owner@postgresql.org Tue May 13 17:31:15 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 0FD05475EE2 + for ; + Tue, 13 May 2003 17:31:15 -0400 (EDT) +Received: from jal.clueinc.net (xd84b436b.ip.e-nt.net [216.75.67.107]) + by postgresql.org (Postfix) with ESMTP id 0C9D1475AA9 + for ; + Tue, 13 May 2003 17:31:14 -0400 (EDT) +Received: from jal.clueinc.net (localhost [127.0.0.1]) + by jal.clueinc.net (8.12.9/8.12.9/Debian-3) with ESMTP id + h4DMUuIE023655 + (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) + for ; Tue, 13 May 2003 17:30:56 -0500 +Received: (from jal@localhost) + by jal.clueinc.net (8.12.9/8.12.9/Debian-3) id h4DMUuXi023653 + for pgsql-performance@postgresql.org; Tue, 13 May 2003 17:30:56 -0500 +Date: Tue, 13 May 2003 17:30:56 -0500 +From: Jamie Lawrence +To: pgsql-performance@postgresql.org +Subject: Finding filenames for tables +Message-ID: <20030513223055.GZ4093@jal.clueinc.net> +Mail-Followup-To: pgsql-performance@postgresql.org +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +Organization: clue inc +X-URL: http://www.clueinc.net/ +User-Agent: Mutt/1.5.4i +X-Spam-Status: No, hits=-12.1 required=5.0 tests=BAYES_10,USER_AGENT_MUTT + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/152 +X-Sequence-Number: 1931 + + +I must be having a bad search-engine day. + +How do I join pg_class and pg_database to determine OID/tablename +pairs for a given database? I can't find anything to join on in those +tables. I'm just grepping output right now, but I'd like to do more +complicated things in the future, thus my question. + +-j + +-- +Jamie Lawrence jal@jal.org + + +From pgsql-performance-owner@postgresql.org Tue May 13 19:11:37 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from spampd.localdomain (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 115AA4763B1 + for ; + Tue, 13 May 2003 19:11:36 -0400 (EDT) +Received: from jal.clueinc.net (xd84b436b.ip.e-nt.net [216.75.67.107]) + by postgresql.org (Postfix) with ESMTP id BD6CD4763BD + for ; + Tue, 13 May 2003 19:11:34 -0400 (EDT) +Received: from jal.clueinc.net (localhost [127.0.0.1]) + by jal.clueinc.net (8.12.9/8.12.9/Debian-3) with ESMTP id + h4E0BHIE024386 + (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) + for ; Tue, 13 May 2003 19:11:17 -0500 +Received: (from jal@localhost) + by jal.clueinc.net (8.12.9/8.12.9/Debian-3) id h4E0BHPw024384 + for pgsql-performance@postgresql.org; Tue, 13 May 2003 19:11:17 -0500 +Date: Tue, 13 May 2003 19:11:17 -0500 +From: Jamie Lawrence +To: pgsql-performance@postgresql.org +Subject: Re: Finding filenames for tables +Message-ID: <20030514001117.GC4093@jal.clueinc.net> +Mail-Followup-To: pgsql-performance@postgresql.org +References: <20030513223055.GZ4093@jal.clueinc.net> <3EC1691D.4050604@web.de> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: <3EC1691D.4050604@web.de> +Organization: clue inc +X-URL: http://www.clueinc.net/ +User-Agent: Mutt/1.5.4i +X-Spam-Status: No, hits=-38.0 required=5.0 + tests=BAYES_10,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, + REFERENCES,REPLY_WITH_QUOTES,USER_AGENT_MUTT + autolearn=ham version=2.50 +X-Spam-Level: +X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) +X-Archive-Number: 200305/155 +X-Sequence-Number: 1934 + + +On Tue, 13 May 2003, Andreas Pflug wrote: + +> you don't need to join since pg_class is specific for a database. You +> cannot see any classes from a different database in pg_class. In +> contrast, pg_database is server-wide mirrored. + +Thank you! I had sufficiently confused myself that I didn't even think +to wonder if this was the case or not. + +Thanks again. + +-j + +-- +Jamie Lawrence jal@jal.org +"It only takes 20 years for a liberal to become a conservative +without changing a single idea." + - Robert Anton Wilson + + +From pgsql-performance-owner@postgresql.org Wed May 14 19:09:36 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 4A193475B47 + for ; + Wed, 14 May 2003 19:09:34 -0400 (EDT) +Received: from postgresql.org ([64.49.215.8]) + by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with + ESMTP id 67748-05 for ; + Wed, 14 May 2003 19:09:03 -0400 (EDT) +Received: from shield.nordlb.lv (shield.pirmabanka.lv [195.114.57.4]) + by postgresql.org (Postfix) with ESMTP id 7B5D74764AD + for ; + Wed, 14 May 2003 19:09:02 -0400 (EDT) +Received: from wall2.pirmabanka.lv (wall2-pub.nordlb.lv [195.114.57.14]) + by shield.nordlb.lv (8.12.9/8.12.9) with SMTP id h4EN8rbg018418 + for ; Thu, 15 May 2003 02:08:53 +0300 +Received: from share.nordlb.lv ([10.0.0.10]) by wall2.pirmabanka.lv; + Thu, 15 May 2003 02:08:52 +0300 (EET DST) +Received: from pc311x1.nordlb.lv (localhost.localdomain [127.0.0.1]) + by nordlb.lv (8.11.6/8.11.6) with SMTP id h4EN8qG18205 + for ; Thu, 15 May 2003 02:08:52 +0300 +Received: (qmail 2182 invoked by uid 100); 14 May 2003 23:11:33 -0000 +Date: Thu, 15 May 2003 02:11:33 +0300 +From: "Victor Yegorov" +To: "Postgres Performance" +Subject: constraint with reference to the same table +Message-ID: <20030514231133.GB1549@nordlb.lv> +Mime-Version: 1.0 +Content-Type: text/plain; charset=koi8-r +Content-Disposition: inline +User-Agent: Mutt/1.4.1i +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/156 +X-Sequence-Number: 1935 + +Hello. + +I'm using PostgreSQL 7.3.1 on i686-pc-linux-gnu, compiled by GCC egcs-2.91.66. + +Here is topic. Table transactions: + +=> \d transactions + Table "public.transactions" + Column | Type | Modifiers +-------------+--------------+----------- + trxn_id | integer | not null + trxn_ret | integer | + trxn_for | integer | + status | numeric(2,0) | not null + auth_status | numeric(2,0) | not null +Indexes: transactions_pkey primary key btree (trxn_id) +Foreign Key constraints: trxns_id FOREIGN KEY (trxn_id) REFERENCES connections(conn_id) ON UPDATE NO ACTION ON DELETE NO ACTION, + trxns_ret FOREIGN KEY (trxn_ret) REFERENCES transactions(trxn_id) ON UPDATE NO ACTION ON DELETE NO ACTION, + trxns_for FOREIGN KEY (trxn_for) REFERENCES transactions(trxn_id) ON UPDATE NO ACTION ON DELETE NO ACTION + +As you can see, trxns_ret and trxns_for constraints references to the same table they come from. + +Maintenance of system includes the following step: +delete from transactions where transactions.trxn_id = uneeded_trxns.trxn_id; +transactions volume is about 10K-20K rows. +uneeded_trxns volume is about 3K-5K rows. + + +Problem: It takes to MUCH time. EXPLAIN says: +=> explain delete from transactions where transactions.trxn_id = balance_delete_data.conn_id; + QUERY PLAN +----------------------------------------------------------------------------------- + Hash Join (cost=86.47..966.66 rows=5238 width=14) + Hash Cond: ("outer".trxn_id = "inner".conn_id) + -> Seq Scan on transactions (cost=0.00..503.76 rows=24876 width=10) + -> Hash (cost=73.38..73.38 rows=5238 width=4) + -> Seq Scan on balance_delete_data (cost=0.00..73.38 rows=5238 width=4) +(5 rows) + +I was waiting for about 30 minutes and then hit ^C. + +After some time spent dropping indexes and constraints, I've found out, that problem was in +those 2 "cyclic" constraints. After drop, query passed in some seconds (that is suitable). + +Question: why so? +Thanks in advance. + +-- + +Victor Yegorov + +From pgsql-performance-owner@postgresql.org Wed May 14 19:28:59 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 349FD4764D7 + for ; + Wed, 14 May 2003 19:28:58 -0400 (EDT) +Received: from postgresql.org ([64.49.215.8]) + by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with + ESMTP id 69032-04 for ; + Wed, 14 May 2003 19:28:52 -0400 (EDT) +Received: from megazone.bigpanda.com (megazone.bigpanda.com [63.150.15.178]) + by postgresql.org (Postfix) with ESMTP id 808824764D6 + for ; + Wed, 14 May 2003 19:28:52 -0400 (EDT) +Received: by megazone.bigpanda.com (Postfix, from userid 1001) + id 33F5FD613; Wed, 14 May 2003 16:28:55 -0700 (PDT) +Received: from localhost (localhost [127.0.0.1]) + by megazone.bigpanda.com (Postfix) with ESMTP + id 29A775C0A; Wed, 14 May 2003 16:28:55 -0700 (PDT) +Date: Wed, 14 May 2003 16:28:55 -0700 (PDT) +From: Stephan Szabo +To: Victor Yegorov +Cc: Postgres Performance +Subject: Re: constraint with reference to the same table +In-Reply-To: <20030514231133.GB1549@nordlb.lv> +Message-ID: <20030514162559.O51040-100000@megazone23.bigpanda.com> +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/157 +X-Sequence-Number: 1936 + +On Thu, 15 May 2003, Victor Yegorov wrote: + +> I'm using PostgreSQL 7.3.1 on i686-pc-linux-gnu, compiled by GCC egcs-2.91.66. +> +> Here is topic. Table transactions: +> +> => \d transactions +> Table "public.transactions" +> Column | Type | Modifiers +> -------------+--------------+----------- +> trxn_id | integer | not null +> trxn_ret | integer | +> trxn_for | integer | +> status | numeric(2,0) | not null +> auth_status | numeric(2,0) | not null +> Indexes: transactions_pkey primary key btree (trxn_id) +> Foreign Key constraints: trxns_id FOREIGN KEY (trxn_id) REFERENCES connections(conn_id) ON UPDATE NO ACTION ON DELETE NO ACTION, +> trxns_ret FOREIGN KEY (trxn_ret) REFERENCES transactions(trxn_id) ON UPDATE NO ACTION ON DELETE NO ACTION, +> trxns_for FOREIGN KEY (trxn_for) REFERENCES transactions(trxn_id) ON UPDATE NO ACTION ON DELETE NO ACTION +> +> As you can see, trxns_ret and trxns_for constraints references to the same table they come from. +> +> Maintenance of system includes the following step: +> delete from transactions where transactions.trxn_id = uneeded_trxns.trxn_id; +> transactions volume is about 10K-20K rows. +> uneeded_trxns volume is about 3K-5K rows. +> +> +> Problem: It takes to MUCH time. EXPLAIN says: +> +> I was waiting for about 30 minutes and then hit ^C. +> +> After some time spent dropping indexes and constraints, I've found out, that problem was in +> those 2 "cyclic" constraints. After drop, query passed in some seconds (that is suitable). +> +> Question: why so? + +For each row dropped it's making sure that no row has either a trxn_ret or +trxn_for that pointed to that row. If those columns aren't indexed it's +going to be amazingly slow (if they are indexed it'll probably only be +normally slow ;) ). + + + +From pgsql-performance-owner@postgresql.org Wed May 14 19:51:41 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 6D75A4764D7 + for ; + Wed, 14 May 2003 19:51:39 -0400 (EDT) +Received: from postgresql.org ([64.49.215.8]) + by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with + ESMTP id 71037-05 for ; + Wed, 14 May 2003 19:51:37 -0400 (EDT) +Received: from water.oasis.net.au (water.oasis.net.au [210.8.139.2]) + by postgresql.org (Postfix) with ESMTP id 8B38C4764AD + for ; + Wed, 14 May 2003 19:51:36 -0400 (EDT) +Received: from oasis.net.au (guardian [210.8.139.5]) + by water.oasis.net.au (8.9.3/8.9.3/Debian 8.9.3-21) with ESMTP id + KAA15851 + for ; Thu, 15 May 2003 10:01:03 +1000 +X-Authentication-Warning: water.oasis.net.au: Host guardian [210.8.139.5] + claimed to be oasis.net.au +Message-ID: <3EC2D7D5.1010404@oasis.net.au> +Date: Thu, 15 May 2003 09:57:09 +1000 +From: Rudi Starcevic +User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; + rv:1.3) Gecko/20030312 +X-Accept-Language: en-us, en +MIME-Version: 1.0 +Cc: Postgres Performance +Subject: Re: constraint with reference to the same table +References: <20030514162559.O51040-100000@megazone23.bigpanda.com> +In-Reply-To: <20030514162559.O51040-100000@megazone23.bigpanda.com> +Content-Type: multipart/alternative; + boundary="------------030507030600090204060106" +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/158 +X-Sequence-Number: 1937 + +This is a multi-part message in MIME format. +--------------030507030600090204060106 +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit + +Hi, + +Can I confirm what this means then .. + +For large table's each column with ref. inegritry I should create an +index on those columns ? + +So if I create a table like this : +CREATE TABLE business_businesstype +( +b_bt_id serial PRIMARY KEY, +b_id integer REFERENCES business ON UPDATE CASCADE ON DELETE CASCADE NOT +NULL, +bt_id integer REFERENCES businesstype ON UPDATE CASCADE ON DELETE +CASCADE NOT NULL +); + +I should then create 2 index's + +CREATE INDEX business_idx ON business_businesstype (business); +CREATE INDEX businesstype_idx ON business_businesstype (businesstype); + +Thanks +Regards +Rudi. + + + +Stephan Szabo wrote: + +>On Thu, 15 May 2003, Victor Yegorov wrote: +> +> +> +>>I'm using PostgreSQL 7.3.1 on i686-pc-linux-gnu, compiled by GCC egcs-2.91.66. +>> +>>Here is topic. Table transactions: +>> +>>=> \d transactions +>> Table "public.transactions" +>> Column | Type | Modifiers +>>-------------+--------------+----------- +>> trxn_id | integer | not null +>> trxn_ret | integer | +>> trxn_for | integer | +>> status | numeric(2,0) | not null +>> auth_status | numeric(2,0) | not null +>>Indexes: transactions_pkey primary key btree (trxn_id) +>>Foreign Key constraints: trxns_id FOREIGN KEY (trxn_id) REFERENCES connections(conn_id) ON UPDATE NO ACTION ON DELETE NO ACTION, +>> trxns_ret FOREIGN KEY (trxn_ret) REFERENCES transactions(trxn_id) ON UPDATE NO ACTION ON DELETE NO ACTION, +>> trxns_for FOREIGN KEY (trxn_for) REFERENCES transactions(trxn_id) ON UPDATE NO ACTION ON DELETE NO ACTION +>> +>>As you can see, trxns_ret and trxns_for constraints references to the same table they come from. +>> +>>Maintenance of system includes the following step: +>>delete from transactions where transactions.trxn_id = uneeded_trxns.trxn_id; +>>transactions volume is about 10K-20K rows. +>>uneeded_trxns volume is about 3K-5K rows. +>> +>> +>>Problem: It takes to MUCH time. EXPLAIN says: +>> +>>I was waiting for about 30 minutes and then hit ^C. +>> +>>After some time spent dropping indexes and constraints, I've found out, that problem was in +>>those 2 "cyclic" constraints. After drop, query passed in some seconds (that is suitable). +>> +>>Question: why so? +>> +>> +> +>For each row dropped it's making sure that no row has either a trxn_ret or +>trxn_for that pointed to that row. If those columns aren't indexed it's +>going to be amazingly slow (if they are indexed it'll probably only be +>normally slow ;) ). +> +> +> +>---------------------------(end of broadcast)--------------------------- +>TIP 6: Have you searched our list archives? +> +>http://archives.postgresql.org +> +> +> + + +--------------030507030600090204060106 +Content-Type: text/html; charset=us-ascii +Content-Transfer-Encoding: 7bit + + + + + + + + +Hi,
+
+Can I confirm what this means then ..
+
+For large table's each column with ref. inegritry I should create an +index on those columns ?
+
+So if I create a table like this :
+CREATE TABLE business_businesstype
+(
+b_bt_id serial PRIMARY KEY,
+b_id integer REFERENCES business ON UPDATE CASCADE ON DELETE CASCADE +NOT NULL,
+bt_id integer REFERENCES businesstype ON UPDATE CASCADE ON DELETE +CASCADE NOT NULL
+);
+
+I should then create 2 index's
+
+CREATE  INDEX business_idx ON  business_businesstype (business);
+CREATE  INDEX businesstype_idx ON  business_businesstype (businesstype);
+
+Thanks
+Regards
+Rudi.
+
+
+
+Stephan Szabo wrote:
+
+
On Thu, 15 May 2003, Victor Yegorov wrote:
+
+  
+
+
I'm using PostgreSQL 7.3.1 on i686-pc-linux-gnu, compiled by GCC egcs-2.91.66.
+
+Here is topic. Table transactions:
+
+=> \d transactions
+      Table "public.transactions"
+   Column    |     Type     | Modifiers
+-------------+--------------+-----------
+ trxn_id     | integer      | not null
+ trxn_ret    | integer      |
+ trxn_for    | integer      |
+ status      | numeric(2,0) | not null
+ auth_status | numeric(2,0) | not null
+Indexes: transactions_pkey primary key btree (trxn_id)
+Foreign Key constraints: trxns_id FOREIGN KEY (trxn_id) REFERENCES connections(conn_id) ON UPDATE NO ACTION ON DELETE NO ACTION,
+                         trxns_ret FOREIGN KEY (trxn_ret) REFERENCES transactions(trxn_id) ON UPDATE NO ACTION ON DELETE NO ACTION,
+                         trxns_for FOREIGN KEY (trxn_for) REFERENCES transactions(trxn_id) ON UPDATE NO ACTION ON DELETE NO ACTION
+
+As you can see, trxns_ret and trxns_for constraints references to the same table they come from.
+
+Maintenance of system includes the following step:
+delete from transactions where transactions.trxn_id = uneeded_trxns.trxn_id;
+transactions volume is about 10K-20K rows.
+uneeded_trxns volume is about 3K-5K rows.
+
+
+Problem: It takes to MUCH time. EXPLAIN says:
+
+I was waiting for about 30 minutes and then hit ^C.
+
+After some time spent dropping indexes and constraints, I've found out, that problem was in
+those 2 "cyclic" constraints. After drop, query passed in some seconds (that is suitable).
+
+Question: why so?
+    
+
+

+For each row dropped it's making sure that no row has either a trxn_ret or
+trxn_for that pointed to that row.  If those columns aren't indexed it's
+going to be amazingly slow (if they are indexed it'll probably only be
+normally slow ;) ).
+
+
+
+---------------------------(end of broadcast)---------------------------
+TIP 6: Have you searched our list archives?
+
+http://archives.postgresql.org
+
+  
+
+
+ + + +--------------030507030600090204060106-- + + +From pgsql-performance-owner@postgresql.org Wed May 14 20:02:07 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 150134764D7 + for ; + Wed, 14 May 2003 20:02:05 -0400 (EDT) +Received: from postgresql.org ([64.49.215.8]) + by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with + ESMTP id 71252-07 for ; + Wed, 14 May 2003 20:02:03 -0400 (EDT) +Received: from water.oasis.net.au (water.oasis.net.au [210.8.139.2]) + by postgresql.org (Postfix) with ESMTP id 5B28E4764AD + for ; + Wed, 14 May 2003 20:02:02 -0400 (EDT) +Received: from oasis.net.au (guardian [210.8.139.5]) + by water.oasis.net.au (8.9.3/8.9.3/Debian 8.9.3-21) with ESMTP id + KAA16022 + for ; Thu, 15 May 2003 10:11:30 +1000 +X-Authentication-Warning: water.oasis.net.au: Host guardian [210.8.139.5] + claimed to be oasis.net.au +Message-ID: <3EC2DA46.4070105@oasis.net.au> +Date: Thu, 15 May 2003 10:07:34 +1000 +From: Rudi Starcevic +User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; + rv:1.3) Gecko/20030312 +X-Accept-Language: en-us, en +MIME-Version: 1.0 +Cc: Postgres Performance +Subject: Re: constraint with reference to the same table +References: <20030514162559.O51040-100000@megazone23.bigpanda.com> + <3EC2D7D5.1010404@oasis.net.au> +In-Reply-To: <3EC2D7D5.1010404@oasis.net.au> +Content-Type: text/plain; charset=ISO-8859-1; format=flowed +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/159 +X-Sequence-Number: 1938 + + Hi, + +Oops - sorry I made a typo on those 2 index's. + +Wrong: +CREATE INDEX business_idx ON business_businesstype (business); +CREATE INDEX businesstype_idx ON business_businesstype (businesstype); + +Right: +CREATE INDEX business_idx ON business_businesstype (b_id); +CREATE INDEX businesstype_idx ON business_businesstype (bt_id); + +The table: +CREATE TABLE business_businesstype +( +b_bt_id serial PRIMARY KEY, +b_id integer REFERENCES business ON UPDATE CASCADE ON DELETE CASCADE NOT +NULL, +bt_id integer REFERENCES businesstype ON UPDATE CASCADE ON DELETE +CASCADE NOT NULL +); + +Thanks +Regards +Rudi. + + + +From pgsql-performance-owner@postgresql.org Wed May 14 20:10:11 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 326254764E2 + for ; + Wed, 14 May 2003 20:10:10 -0400 (EDT) +Received: from postgresql.org ([64.49.215.8]) + by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with + ESMTP id 74492-02 for ; + Wed, 14 May 2003 20:09:59 -0400 (EDT) +Received: from shield.nordlb.lv (shield.pirmabanka.lv [195.114.57.4]) + by postgresql.org (Postfix) with ESMTP id 51A59475B99 + for ; + Wed, 14 May 2003 20:09:58 -0400 (EDT) +Received: from wall2.pirmabanka.lv (wall2-pub.nordlb.lv [195.114.57.14]) + by shield.nordlb.lv (8.12.9/8.12.9) with SMTP id h4F0A0bg018665 + for ; Thu, 15 May 2003 03:10:00 +0300 +Received: from share.nordlb.lv ([10.0.0.10]) by wall2.pirmabanka.lv; + Thu, 15 May 2003 03:09:58 +0300 (EET DST) +Received: from pc311x1.nordlb.lv (localhost.localdomain [127.0.0.1]) + by nordlb.lv (8.11.6/8.11.6) with SMTP id h4F09w719898 + for ; Thu, 15 May 2003 03:09:58 +0300 +Received: (qmail 2359 invoked by uid 100); 15 May 2003 00:12:39 -0000 +Date: Thu, 15 May 2003 03:12:39 +0300 +From: "Victor Yegorov" +To: Rudi Starcevic +Cc: Postgres Performance +Subject: Re: constraint with reference to the same table +Message-ID: <20030515001239.GC1549@nordlb.lv> +References: <20030514162559.O51040-100000@megazone23.bigpanda.com> + <3EC2D7D5.1010404@oasis.net.au> +Mime-Version: 1.0 +Content-Type: text/plain; charset=koi8-r +Content-Disposition: inline +In-Reply-To: <3EC2D7D5.1010404@oasis.net.au> +User-Agent: Mutt/1.4.1i +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/160 +X-Sequence-Number: 1939 + +* Rudi Starcevic [15.05.2003 02:59]: +> Hi, +> +> Can I confirm what this means then .. +> +> For large table's each column with ref. inegritry I should create an +> index on those columns ? + +I think, that indicies are needed only at delete stage to decrease search +time of possible referencing rows. +Not only, of course, but when we speak about +INSERT/UPDATE/DELETE data it is so. + +On the other side, indicies increases total query runtime, because for +each row deleted/updated/inserted it'll be necessary to update each index. + +In my case, I at first drop "cyclic" constraints, do the job and then +restore them. + + +-- + +Victor Yegorov + +From pgsql-performance-owner@postgresql.org Wed May 14 20:46:51 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 75FE44764E7 + for ; + Wed, 14 May 2003 20:46:49 -0400 (EDT) +Received: from postgresql.org ([64.49.215.8]) + by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with + ESMTP id 75841-06 for ; + Wed, 14 May 2003 20:46:44 -0400 (EDT) +Received: from megazone.bigpanda.com (megazone.bigpanda.com [63.150.15.178]) + by postgresql.org (Postfix) with ESMTP id C6387474E4F + for ; + Wed, 14 May 2003 20:46:44 -0400 (EDT) +Received: by megazone.bigpanda.com (Postfix, from userid 1001) + id EDFC7D628; Wed, 14 May 2003 17:46:47 -0700 (PDT) +Received: from localhost (localhost [127.0.0.1]) + by megazone.bigpanda.com (Postfix) with ESMTP + id DBA3D5C03; Wed, 14 May 2003 17:46:47 -0700 (PDT) +Date: Wed, 14 May 2003 17:46:47 -0700 (PDT) +From: Stephan Szabo +To: Rudi Starcevic +Cc: Postgres Performance +Subject: Re: constraint with reference to the same table +In-Reply-To: <3EC2D7D5.1010404@oasis.net.au> +Message-ID: <20030514174416.K52132-100000@megazone23.bigpanda.com> +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/161 +X-Sequence-Number: 1940 + +On Thu, 15 May 2003, Rudi Starcevic wrote: + +> Can I confirm what this means then .. +> +> For large table's each column with ref. inegritry I should create an +> index on those columns ? + +In general, yes. There's always an additional cost with having additional +indexes to modifications to the table, so you need to balance the costs by +what sorts of queries you're doing. For example, if you're doing a +references constraint to a table that is mostly there for say providing a +nice name for something and those values aren't likely to change (and it's +okay if a change were expensive) then you wouldn't necessarily want the +additional index. + + + +From pgsql-performance-owner@postgresql.org Wed May 14 20:49:41 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 4BAAD4764E7 + for ; + Wed, 14 May 2003 20:49:40 -0400 (EDT) +Received: from postgresql.org ([64.49.215.8]) + by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with + ESMTP id 77781-01 for ; + Wed, 14 May 2003 20:49:38 -0400 (EDT) +Received: from megazone.bigpanda.com (megazone.bigpanda.com [63.150.15.178]) + by postgresql.org (Postfix) with ESMTP id AED64474E4F + for ; + Wed, 14 May 2003 20:49:38 -0400 (EDT) +Received: by megazone.bigpanda.com (Postfix, from userid 1001) + id 5C640D612; Wed, 14 May 2003 17:49:42 -0700 (PDT) +Received: from localhost (localhost [127.0.0.1]) + by megazone.bigpanda.com (Postfix) with ESMTP + id 51DAA5C03; Wed, 14 May 2003 17:49:42 -0700 (PDT) +Date: Wed, 14 May 2003 17:49:42 -0700 (PDT) +From: Stephan Szabo +To: Victor Yegorov +Cc: Rudi Starcevic , + Postgres Performance +Subject: Re: constraint with reference to the same table +In-Reply-To: <20030515001239.GC1549@nordlb.lv> +Message-ID: <20030514174656.B52132-100000@megazone23.bigpanda.com> +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/163 +X-Sequence-Number: 1942 + +On Thu, 15 May 2003, Victor Yegorov wrote: + +> * Rudi Starcevic [15.05.2003 02:59]: +> > Hi, +> > +> > Can I confirm what this means then .. +> > +> > For large table's each column with ref. inegritry I should create an +> > index on those columns ? +> +> I think, that indicies are needed only at delete stage to decrease search +> time of possible referencing rows. +> Not only, of course, but when we speak about +> INSERT/UPDATE/DELETE data it is so. +> +> On the other side, indicies increases total query runtime, because for +> each row deleted/updated/inserted it'll be necessary to update each index. +> +> In my case, I at first drop "cyclic" constraints, do the job and then +> restore them. + +That can be a win, but if you're actually dropping and adding the +constraint again it may not be on large tables since it'll still do a +whole bunch of index lookups to check the existing rows when the alter +table add constraint happens. Disabling triggers and re-enabling them is +faster but breaks the guarantee of the constraint. + + +From pgsql-performance-owner@postgresql.org Wed May 14 20:47:49 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 8BB4E4764E7 + for ; + Wed, 14 May 2003 20:47:48 -0400 (EDT) +Received: from postgresql.org ([64.49.215.8]) + by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with + ESMTP id 75841-10 for ; + Wed, 14 May 2003 20:47:47 -0400 (EDT) +Received: from water.oasis.net.au (water.oasis.net.au [210.8.139.2]) + by postgresql.org (Postfix) with ESMTP id 361E3474E4F + for ; + Wed, 14 May 2003 20:47:46 -0400 (EDT) +Received: from oasis.net.au (guardian [210.8.139.5]) + by water.oasis.net.au (8.9.3/8.9.3/Debian 8.9.3-21) with ESMTP id + KAA16672 + for ; Thu, 15 May 2003 10:57:16 +1000 +X-Authentication-Warning: water.oasis.net.au: Host guardian [210.8.139.5] + claimed to be oasis.net.au +Message-ID: <3EC2E4F5.5020704@oasis.net.au> +Date: Thu, 15 May 2003 10:53:09 +1000 +From: Rudi Starcevic +User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; + rv:1.3) Gecko/20030312 +X-Accept-Language: en-us, en +MIME-Version: 1.0 +Cc: Postgres Performance +Subject: Re: constraint with reference to the same table +References: <20030514162559.O51040-100000@megazone23.bigpanda.com> + <3EC2D7D5.1010404@oasis.net.au> <20030515001239.GC1549@nordlb.lv> +In-Reply-To: <20030515001239.GC1549@nordlb.lv> +Content-Type: multipart/alternative; + boundary="------------020406090500050303030907" +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/162 +X-Sequence-Number: 1941 + +This is a multi-part message in MIME format. +--------------020406090500050303030907 +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit + +Victor, + +I see. +Good point. + +Thank you kindly. +Regards +Rudi. + + +Victor Yegorov wrote: + +>* Rudi Starcevic [15.05.2003 02:59]: +> +> +>>Hi, +>> +>>Can I confirm what this means then .. +>> +>>For large table's each column with ref. inegritry I should create an +>>index on those columns ? +>> +>> +> +>I think, that indicies are needed only at delete stage to decrease search +>time of possible referencing rows. +>Not only, of course, but when we speak about +>INSERT/UPDATE/DELETE data it is so. +> +>On the other side, indicies increases total query runtime, because for +>each row deleted/updated/inserted it'll be necessary to update each index. +> +>In my case, I at first drop "cyclic" constraints, do the job and then +>restore them. +> +> +> +> + + +--------------020406090500050303030907 +Content-Type: text/html; charset=us-ascii +Content-Transfer-Encoding: 7bit + + + + + + + + +Victor,
+
+I see.
+Good point.
+
+Thank you kindly.
+Regards
+Rudi.
+
+
+Victor Yegorov wrote:
+
+
* Rudi Starcevic <rudi@oasis.net.au> [15.05.2003 02:59]:
+  
+
+
Hi,
+
+Can I confirm what this means then ..
+
+For large table's each column with ref. inegritry I should create an 
+index on those columns ?
+    
+
+

+I think, that indicies are needed only at delete stage to decrease search
+time of possible referencing rows.
+Not only, of course, but when we speak about
+INSERT/UPDATE/DELETE data it is so.
+
+On the other side, indicies increases total query runtime, because for
+each row deleted/updated/inserted it'll be necessary to update each index.
+
+In my case, I at first drop "cyclic" constraints, do the job and then
+restore them.
+
+
+  
+
+
+ + + +--------------020406090500050303030907-- + + +From pgsql-performance-owner@postgresql.org Wed May 14 21:01:02 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id B02D74764C8 + for ; + Wed, 14 May 2003 21:01:01 -0400 (EDT) +Received: from postgresql.org ([64.49.215.8]) + by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with + ESMTP id 79101-03 for ; + Wed, 14 May 2003 21:01:00 -0400 (EDT) +Received: from shield.nordlb.lv (shield.pirmabanka.lv [195.114.57.4]) + by postgresql.org (Postfix) with ESMTP id A39754764FA + for ; + Wed, 14 May 2003 21:00:59 -0400 (EDT) +Received: from wall2.pirmabanka.lv (wall2-pub.nordlb.lv [195.114.57.14]) + by shield.nordlb.lv (8.12.9/8.12.9) with SMTP id h4F112bg018902 + for ; Thu, 15 May 2003 04:01:02 +0300 +Received: from share.nordlb.lv ([10.0.0.10]) by wall2.pirmabanka.lv; + Thu, 15 May 2003 04:01:01 +0300 (EET DST) +Received: from pc311x1.nordlb.lv (localhost.localdomain [127.0.0.1]) + by nordlb.lv (8.11.6/8.11.6) with SMTP id h4F111W21057 + for ; Thu, 15 May 2003 04:01:01 +0300 +Received: (qmail 2426 invoked by uid 100); 15 May 2003 01:03:41 -0000 +Date: Thu, 15 May 2003 04:03:41 +0300 +From: Victor Yegorov +To: Stephan Szabo +Cc: Rudi Starcevic , + Postgres Performance +Subject: Re: constraint with reference to the same table +Message-ID: <20030515010341.GD1549@nordlb.lv> +References: <20030515001239.GC1549@nordlb.lv> + <20030514174656.B52132-100000@megazone23.bigpanda.com> +Mime-Version: 1.0 +Content-Type: text/plain; charset=koi8-r +Content-Disposition: inline +In-Reply-To: <20030514174656.B52132-100000@megazone23.bigpanda.com> +User-Agent: Mutt/1.4.1i +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/164 +X-Sequence-Number: 1943 + +* Stephan Szabo [15.05.2003 03:54]: +> +> That can be a win, but if you're actually dropping and adding the +> constraint again it may not be on large tables since it'll still do a +> whole bunch of index lookups to check the existing rows when the alter +> table add constraint happens. Disabling triggers and re-enabling them is +> faster but breaks the guarantee of the constraint. + +You're right. I thought of big tables after posting the reply. My solution +is suitable for my case, i.e. not so big tables. + +Returning to the very first question I asked. +May be it is usefull to implicitly create index on foreign key columns? +Actually, untill you had pointed on seq. scans, I thought Postgres is +using internal indicies - don't ask me why. + + +-- + +Victor Yegorov + +From pgsql-performance-owner@postgresql.org Wed May 14 21:04:09 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id CED62475EFD + for ; + Wed, 14 May 2003 21:04:08 -0400 (EDT) +Received: from postgresql.org ([64.49.215.8]) + by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with + ESMTP id 79101-05 for ; + Wed, 14 May 2003 21:04:06 -0400 (EDT) +Received: from water.oasis.net.au (water.oasis.net.au [210.8.139.2]) + by postgresql.org (Postfix) with ESMTP id C80D8474E4F + for ; + Wed, 14 May 2003 21:04:05 -0400 (EDT) +Received: from oasis.net.au (guardian [210.8.139.5]) + by water.oasis.net.au (8.9.3/8.9.3/Debian 8.9.3-21) with ESMTP id + LAA16944; Thu, 15 May 2003 11:13:25 +1000 +X-Authentication-Warning: water.oasis.net.au: Host guardian [210.8.139.5] + claimed to be oasis.net.au +Message-ID: <3EC2E8B8.8070805@oasis.net.au> +Date: Thu, 15 May 2003 11:09:12 +1000 +From: Rudi Starcevic +User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; + rv:1.3) Gecko/20030312 +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: Stephan Szabo +Cc: Postgres Performance +Subject: Re: constraint with reference to the same table +References: <20030514174416.K52132-100000@megazone23.bigpanda.com> +In-Reply-To: <20030514174416.K52132-100000@megazone23.bigpanda.com> +Content-Type: multipart/alternative; + boundary="------------040108050600040709090607" +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/165 +X-Sequence-Number: 1944 + +This is a multi-part message in MIME format. +--------------040108050600040709090607 +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit + +Stephan, + +Thanks also - I'm actually building a new database as I write this so +this topic is perfect timing for me. + +I'm using ref. integrity right now mostly for many-to-many type situations. + +For example. +I create a table of People, +then a table of Business's, +then I need to relate many people to many business's. + +So I create a business_people table *with* index's to the referred to tables +Eg: +CREATE TABLE business_people +( +b_p_id serial PRIMARY KEY, +b_id integer REFERENCES business ON UPDATE CASCADE ON DELETE CASCADE NOT +NULL, +p_id integer REFERENCES people ON UPDATE CASCADE ON DELETE CASCADE NOT +NULL +); +CREATE INDEX b_p_b_id_idx ON business_people (b_id); +CREATE INDEX b_p_p_id_idx ON business_people (p_id); + +The b_id and p_id are primary key's in other table's so they have an +index too. + +So far I think I've done every thing right. +Can I ask if you'd agree or not ? + +As a side note when I build my PG database's I do it 100% by hand in text. +That is I write Create table statements, save them to file then +cut'n'paste them into phpPgAdmin or use PSQL. +So the code I have below is the same code I use build the DB. +I wonder if this is OK or would make other PG user's gasp. +I'm sure most database people out there, not sure about PG people, would +use some sort of GUI. + +Thanks kindly +I appreciate your time guy's. +Regards +Rudi. + + + + + + + + +Stephan Szabo wrote: + +>On Thu, 15 May 2003, Rudi Starcevic wrote: +> +> +> +>>Can I confirm what this means then .. +>> +>>For large table's each column with ref. inegritry I should create an +>>index on those columns ? +>> +>> +> +>In general, yes. There's always an additional cost with having additional +>indexes to modifications to the table, so you need to balance the costs by +>what sorts of queries you're doing. For example, if you're doing a +>references constraint to a table that is mostly there for say providing a +>nice name for something and those values aren't likely to change (and it's +>okay if a change were expensive) then you wouldn't necessarily want the +>additional index. +> +> +> +>---------------------------(end of broadcast)--------------------------- +>TIP 3: if posting/reading through Usenet, please send an appropriate +>subscribe-nomail command to majordomo@postgresql.org so that your +>message can get through to the mailing list cleanly +> +> +> + + +--------------040108050600040709090607 +Content-Type: text/html; charset=us-ascii +Content-Transfer-Encoding: 7bit + + + + + + + + +Stephan,
+
+Thanks also - I'm actually building a new database as I write this so +this topic is perfect timing for me.
+
+I'm using ref. integrity right now mostly for many-to-many type +situations.
+
+For example.
+I create a table of People,
+then a table of Business's,
+then I need to relate many people to many business's.
+
+So I create a business_people table *with* index's to the referred to +tables
+Eg:
+CREATE TABLE business_people
+(
+b_p_id serial PRIMARY KEY,
+b_id integer REFERENCES business ON UPDATE CASCADE ON DELETE CASCADE +NOT NULL,
+p_id integer REFERENCES people   ON UPDATE CASCADE ON DELETE CASCADE +NOT NULL
+);
+CREATE  INDEX b_p_b_id_idx ON  business_people (b_id);
+CREATE  INDEX b_p_p_id_idx ON  business_people (p_id);
+
+The b_id and p_id are primary key's in other table's so they have an +index too.
+
+So far I think I've done every thing right.
+Can I ask if you'd agree or not ?
+
+As a side note when I build my PG database's I do it 100% by hand in +text.
+That is I write Create table statements, save them to file then +cut'n'paste them into phpPgAdmin or use PSQL.
+So the code I have below is the same code I use build the DB.
+I wonder if this is OK or would make other PG user's gasp.
+I'm sure most database people out there, not sure about PG people, +would use some sort of GUI.
+
+Thanks kindly
+I appreciate your time guy's.
+Regards
+Rudi.
+
+
+
+
+
+
+
+
+Stephan Szabo wrote:
+
+
On Thu, 15 May 2003, Rudi Starcevic wrote:
+
+  
+
+
Can I confirm what this means then ..
+
+For large table's each column with ref. inegritry I should create an
+index on those columns ?
+    
+
+

+In general, yes.  There's always an additional cost with having additional
+indexes to modifications to the table, so you need to balance the costs by
+what sorts of queries you're doing.  For example, if you're doing a
+references constraint to a table that is mostly there for say providing a
+nice name for something and those values aren't likely to change (and it's
+okay if a change were expensive) then you wouldn't necessarily want the
+additional index.
+
+
+
+---------------------------(end of broadcast)---------------------------
+TIP 3: if posting/reading through Usenet, please send an appropriate
+subscribe-nomail command to majordomo@postgresql.org so that your
+message can get through to the mailing list cleanly
+
+  
+
+
+ + + +--------------040108050600040709090607-- + + +From pgsql-performance-owner@postgresql.org Wed May 14 21:23:30 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 99D72475F26 + for ; + Wed, 14 May 2003 21:23:28 -0400 (EDT) +Received: from postgresql.org ([64.49.215.8]) + by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with + ESMTP id 84626-06 for ; + Wed, 14 May 2003 21:23:23 -0400 (EDT) +Received: from megazone.bigpanda.com (megazone.bigpanda.com [63.150.15.178]) + by postgresql.org (Postfix) with ESMTP id 8B38B475B85 + for ; + Wed, 14 May 2003 21:23:23 -0400 (EDT) +Received: by megazone.bigpanda.com (Postfix, from userid 1001) + id 49F24D612; Wed, 14 May 2003 18:23:27 -0700 (PDT) +Received: from localhost (localhost [127.0.0.1]) + by megazone.bigpanda.com (Postfix) with ESMTP + id 279AF5C04; Wed, 14 May 2003 18:23:27 -0700 (PDT) +Date: Wed, 14 May 2003 18:23:27 -0700 (PDT) +From: Stephan Szabo +To: Rudi Starcevic +Cc: Postgres Performance +Subject: Re: constraint with reference to the same table +In-Reply-To: <3EC2E8B8.8070805@oasis.net.au> +Message-ID: <20030514181136.S52444-100000@megazone23.bigpanda.com> +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/166 +X-Sequence-Number: 1945 + + +On Thu, 15 May 2003, Rudi Starcevic wrote: + +> I'm using ref. integrity right now mostly for many-to-many type situations. +> +> For example. +> I create a table of People, +> then a table of Business's, +> then I need to relate many people to many business's. +> +> So I create a business_people table *with* index's to the referred to tables +> Eg: +> CREATE TABLE business_people +> ( +> b_p_id serial PRIMARY KEY, +> b_id integer REFERENCES business ON UPDATE CASCADE ON DELETE CASCADE NOT +> NULL, +> p_id integer REFERENCES people ON UPDATE CASCADE ON DELETE CASCADE NOT +> NULL +> ); +> CREATE INDEX b_p_b_id_idx ON business_people (b_id); +> CREATE INDEX b_p_p_id_idx ON business_people (p_id); +> +> The b_id and p_id are primary key's in other table's so they have an +> index too. +> +> So far I think I've done every thing right. +> Can I ask if you'd agree or not ? + +Generally, yes, I'd agree with something like that, although I might not +have given a separate serial and instead made the primary key the two id +integers (since I'm not sure having the same reference twice makes sense +and I'm not sure that you'll need to reference the relationship itself +separately). If you weren't likely to be doing your own lookups on b_id +and p_id I'd have to consider the indexes more carefully, since I'd expect +that inserts/updates to business_people are much much more likely than +deletes or key updates to business or people. + +> As a side note when I build my PG database's I do it 100% by hand in text. +> That is I write Create table statements, save them to file then +> cut'n'paste them into phpPgAdmin or use PSQL. +> So the code I have below is the same code I use build the DB. +> I wonder if this is OK or would make other PG user's gasp. +> I'm sure most database people out there, not sure about PG people, would +> use some sort of GUI. + +I generally do something like the above, or make the tables, get them to +what I want and schema dump them. + + +From pgsql-performance-owner@postgresql.org Wed May 14 21:24:32 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 35BE4475F26 + for ; + Wed, 14 May 2003 21:24:31 -0400 (EDT) +Received: from postgresql.org ([64.49.215.8]) + by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with + ESMTP id 85263-07 for ; + Wed, 14 May 2003 21:24:29 -0400 (EDT) +Received: from megazone.bigpanda.com (megazone.bigpanda.com [63.150.15.178]) + by postgresql.org (Postfix) with ESMTP id 4F081475B85 + for ; + Wed, 14 May 2003 21:24:28 -0400 (EDT) +Received: by megazone.bigpanda.com (Postfix, from userid 1001) + id 3CF83D612; Wed, 14 May 2003 18:24:32 -0700 (PDT) +Received: from localhost (localhost [127.0.0.1]) + by megazone.bigpanda.com (Postfix) with ESMTP + id 327DC5C04; Wed, 14 May 2003 18:24:32 -0700 (PDT) +Date: Wed, 14 May 2003 18:24:32 -0700 (PDT) +From: Stephan Szabo +To: Victor Yegorov +Cc: Rudi Starcevic , + Postgres Performance +Subject: Re: constraint with reference to the same table +In-Reply-To: <20030515010341.GD1549@nordlb.lv> +Message-ID: <20030514180750.L52444-100000@megazone23.bigpanda.com> +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/167 +X-Sequence-Number: 1946 + + +On Thu, 15 May 2003, Victor Yegorov wrote: + +> * Stephan Szabo [15.05.2003 03:54]: +> > +> > That can be a win, but if you're actually dropping and adding the +> > constraint again it may not be on large tables since it'll still do a +> > whole bunch of index lookups to check the existing rows when the alter +> > table add constraint happens. Disabling triggers and re-enabling them is +> > faster but breaks the guarantee of the constraint. +> +> You're right. I thought of big tables after posting the reply. My solution +> is suitable for my case, i.e. not so big tables. + +This may become slightly a higher point of balance if we change the alter +table time check to a single query rather than repeated checks as well. + +> Returning to the very first question I asked. +> May be it is usefull to implicitly create index on foreign key columns? + +Maybe, it seems to me that we've been trying to move away from such +implicit behavior (such as serial columns no longer implicitly being +unique) in general. I don't personally have a strong feeling on the +subject. + + +From pgsql-performance-owner@postgresql.org Wed May 14 21:46:48 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id A0319475F26 + for ; + Wed, 14 May 2003 21:46:46 -0400 (EDT) +Received: from postgresql.org ([64.49.215.8]) + by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with + ESMTP id 87188-06 for ; + Wed, 14 May 2003 21:46:45 -0400 (EDT) +Received: from tomts19-srv.bellnexxia.net (tomts19.bellnexxia.net + [209.226.175.73]) + by postgresql.org (Postfix) with ESMTP id 93968475F16 + for ; + Wed, 14 May 2003 21:46:44 -0400 (EDT) +Received: from p433 ([64.229.65.191]) by tomts19-srv.bellnexxia.net + (InterMail vM.5.01.06.01 201-253-122-130-101-20030228) with ESMTP + id <20030515014648.NRXV26559.tomts19-srv.bellnexxia.net@p433> + for ; + Wed, 14 May 2003 21:46:48 -0400 +From: "T. Alex Beamish" +To: "Postgresql-Performance" +Date: Wed, 14 May 2003 21:45:04 -0400 +X-Mailer: PMMail 2000 Standard (2.20.2657) For Windows 98 (4.10.2222) +MIME-Version: 1.0 +Content-Type: text/plain; charset="us-ascii" +Content-Transfer-Encoding: 7bit +Subject: INNER JOIN vs WHERE +Message-Id: <20030515014648.NRXV26559.tomts19-srv.bellnexxia.net@p433> +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/169 +X-Sequence-Number: 1948 + +Hello, + +I've just had a quick search through the archives but couldn't find +what I wanted, so I've joined this list to continue my search for an +answer. + +Is there any rule of thumb about how much more efficient an INNER JOIN +is compare to a regular WHERE statement? + +I have a couple of queries in PostgreSQL that use a variety of tables +(four or five) linked together by key/foreign key conditions all ANDed +together. My co-worker re-wrote one of them using the INNER JOIN +approach and I wanted to find out if this would empirically improve the +performance. + +I have not tried to do an EXPLAIN ANALYZE yet but I will try that. +Thanks for your responses. + +Alex + + + + +From pgsql-performance-owner@postgresql.org Wed May 14 21:43:20 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 86169475F26 + for ; + Wed, 14 May 2003 21:43:18 -0400 (EDT) +Received: from postgresql.org ([64.49.215.8]) + by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with + ESMTP id 87188-04 for ; + Wed, 14 May 2003 21:43:16 -0400 (EDT) +Received: from water.oasis.net.au (water.oasis.net.au [210.8.139.2]) + by postgresql.org (Postfix) with ESMTP id C05CB475F16 + for ; + Wed, 14 May 2003 21:43:15 -0400 (EDT) +Received: from oasis.net.au (guardian [210.8.139.5]) + by water.oasis.net.au (8.9.3/8.9.3/Debian 8.9.3-21) with ESMTP id + LAA17521; Thu, 15 May 2003 11:52:42 +1000 +X-Authentication-Warning: water.oasis.net.au: Host guardian [210.8.139.5] + claimed to be oasis.net.au +Message-ID: <3EC2F1E4.8080706@oasis.net.au> +Date: Thu, 15 May 2003 11:48:20 +1000 +From: Rudi Starcevic +User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; + rv:1.3) Gecko/20030312 +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: Stephan Szabo +Cc: Postgres Performance +Subject: Re: constraint with reference to the same table +References: <20030514181136.S52444-100000@megazone23.bigpanda.com> +In-Reply-To: <20030514181136.S52444-100000@megazone23.bigpanda.com> +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/168 +X-Sequence-Number: 1947 + +Stephen, + + +>> although I might not +>> have given a separate serial and instead made the primary key the two id +>> integers (since I'm not sure having the same reference twice makes sense +>> and I'm not sure that you'll need to reference the relationship itself +>> separately). + +Yes I see. +That's a very good point. +If I make the primary key across both the business and person instead of using +a new primary key/serial then that will prevent the same business to person +relationship being entered twice. + +If I did it that way would this be OK: + +New: +CREATE TABLE business_person +( +b_id integer REFERENCES business ON UPDATE CASCADE ON DELETE CASCADE NOT NULL, +pn_id integer REFERENCES person ON UPDATE CASCADE ON DELETE CASCADE NOT NULL +PRIMARY KEY(b_id,pn_id); +); +CREATE INDEX b_pn_b_id_idx ON business_person (b_id); +CREATE INDEX b_pn_pn_id_idx ON business_person (pn_id); + + +Old: +CREATE TABLE business_person +( +b_pn_id serial PRIMARY KEY, +b_id integer REFERENCES business ON UPDATE CASCADE ON DELETE CASCADE NOT NULL, +pn_id integer REFERENCES person ON UPDATE CASCADE ON DELETE CASCADE NOT NULL +); +CREATE INDEX b_pn_b_id_idx ON business_person (b_id); +CREATE INDEX b_pn_pn_id_idx ON business_person (pn_id); + +As I'd like to sometime's look up business's, sometime's look up people and sometimes +look up both I think I should keep the Index's. + +Cheers +Rudi. + + + +From pgsql-performance-owner@postgresql.org Wed May 14 21:55:32 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 2D358475F26 + for ; + Wed, 14 May 2003 21:55:31 -0400 (EDT) +Received: from postgresql.org ([64.49.215.8]) + by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with + ESMTP id 88576-01 for ; + Wed, 14 May 2003 21:55:29 -0400 (EDT) +Received: from shield.nordlb.lv (shield.pirmabanka.lv [195.114.57.4]) + by postgresql.org (Postfix) with ESMTP id 1A179475F16 + for ; + Wed, 14 May 2003 21:55:29 -0400 (EDT) +Received: from wall2.pirmabanka.lv (wall2-pub.nordlb.lv [195.114.57.14]) + by shield.nordlb.lv (8.12.9/8.12.9) with SMTP id h4F1tWbg019213 + for ; Thu, 15 May 2003 04:55:32 +0300 +Received: from share.nordlb.lv ([10.0.0.10]) by wall2.pirmabanka.lv; + Thu, 15 May 2003 04:55:31 +0300 (EET DST) +Received: from pc311x1.nordlb.lv (localhost.localdomain [127.0.0.1]) + by nordlb.lv (8.11.6/8.11.6) with SMTP id h4F1tUE22956 + for ; Thu, 15 May 2003 04:55:30 +0300 +Received: (qmail 2590 invoked by uid 100); 15 May 2003 01:58:11 -0000 +Date: Thu, 15 May 2003 04:58:11 +0300 +From: "Victor Yegorov" +To: Rudi Starcevic +Cc: Stephan Szabo , + Postgres Performance +Subject: Re: constraint with reference to the same table +Message-ID: <20030515015811.GE1549@nordlb.lv> +References: <20030514181136.S52444-100000@megazone23.bigpanda.com> + <3EC2F1E4.8080706@oasis.net.au> +Mime-Version: 1.0 +Content-Type: text/plain; charset=koi8-r +Content-Disposition: inline +In-Reply-To: <3EC2F1E4.8080706@oasis.net.au> +User-Agent: Mutt/1.4.1i +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/170 +X-Sequence-Number: 1949 + +* Rudi Starcevic [15.05.2003 04:46]: +> Stephen, +> +> +> New: +> CREATE TABLE business_person +> ( +> b_id integer REFERENCES business ON UPDATE CASCADE ON DELETE CASCADE NOT +> NULL, +> pn_id integer REFERENCES person ON UPDATE CASCADE ON DELETE CASCADE NOT NULL +> PRIMARY KEY(b_id,pn_id); +> ); +> CREATE INDEX b_pn_b_id_idx ON business_person (b_id); +> CREATE INDEX b_pn_pn_id_idx ON business_person (pn_id); + +May be it's better to name indexes a bit more clearer? No impact on overall +performance, but you'll ease your life, if you project will grow to hundreds +of tables and thousands of indicies. + +> As I'd like to sometime's look up business's, sometime's look up people and +> sometimes +> look up both I think I should keep the Index's. + +If your lookups are part of business logic, than it's ok. Also, if your +system generates reports using several table joins that may speed up the +things. + +Otherwise, for curiosity cases, it's better to wait some time for the result +of one-time queries. + +-- + +Victor Yegorov + +From pgsql-performance-owner@postgresql.org Wed May 14 22:02:40 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 0F00047652B + for ; + Wed, 14 May 2003 22:02:39 -0400 (EDT) +Received: from postgresql.org ([64.49.215.8]) + by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with + ESMTP id 88873-05 for ; + Wed, 14 May 2003 22:02:37 -0400 (EDT) +Received: from water.oasis.net.au (water.oasis.net.au [210.8.139.2]) + by postgresql.org (Postfix) with ESMTP id 993D3476528 + for ; + Wed, 14 May 2003 22:02:36 -0400 (EDT) +Received: from oasis.net.au (guardian [210.8.139.5]) + by water.oasis.net.au (8.9.3/8.9.3/Debian 8.9.3-21) with ESMTP id + MAA17859; Thu, 15 May 2003 12:11:58 +1000 +X-Authentication-Warning: water.oasis.net.au: Host guardian [210.8.139.5] + claimed to be oasis.net.au +Message-ID: <3EC2F65F.2050004@oasis.net.au> +Date: Thu, 15 May 2003 12:07:27 +1000 +From: Rudi Starcevic +User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; + rv:1.3) Gecko/20030312 +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: Victor Yegorov +Cc: Stephan Szabo , + Postgres Performance +Subject: Re: constraint with reference to the same table +References: <20030514181136.S52444-100000@megazone23.bigpanda.com> + <3EC2F1E4.8080706@oasis.net.au> <20030515015811.GE1549@nordlb.lv> +In-Reply-To: <20030515015811.GE1549@nordlb.lv> +Content-Type: multipart/alternative; + boundary="------------030903040507010607030403" +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/171 +X-Sequence-Number: 1950 + +This is a multi-part message in MIME format. +--------------030903040507010607030403 +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit + +Victor, + +>> May be it's better to name indexes a bit more clearer? No impact on overall +>> performance, but you'll ease your life, if you project will grow to hundreds +>> of tables and thousands of indicies. + +Very true. +Instead of: b_pn_b_id_idx, +I think better would be: busines_person_b_id_idx + +Thanks +Rudi. + + + + +Victor Yegorov wrote: + +>* Rudi Starcevic [15.05.2003 04:46]: +> +> +>>Stephen, +>> +>> +>>New: +>>CREATE TABLE business_person +>>( +>>b_id integer REFERENCES business ON UPDATE CASCADE ON DELETE CASCADE NOT +>>NULL, +>>pn_id integer REFERENCES person ON UPDATE CASCADE ON DELETE CASCADE NOT NULL +>>PRIMARY KEY(b_id,pn_id); +>>); +>>CREATE INDEX b_pn_b_id_idx ON business_person (b_id); +>>CREATE INDEX b_pn_pn_id_idx ON business_person (pn_id); +>> +>> +> +>May be it's better to name indexes a bit more clearer? No impact on overall +>performance, but you'll ease your life, if you project will grow to hundreds +>of tables and thousands of indicies. +> +> +> +>>As I'd like to sometime's look up business's, sometime's look up people and +>>sometimes +>>look up both I think I should keep the Index's. +>> +>> +> +>If your lookups are part of business logic, than it's ok. Also, if your +>system generates reports using several table joins that may speed up the +>things. +> +>Otherwise, for curiosity cases, it's better to wait some time for the result +>of one-time queries. +> +> +> + + +--------------030903040507010607030403 +Content-Type: text/html; charset=us-ascii +Content-Transfer-Encoding: 7bit + + + + + + + + +
Victor,
+
+>> May be it's better to name indexes a bit more clearer? No impact on overall
+>> performance, but you'll ease your life, if you project will grow to hundreds
+>> of tables and thousands of indicies.
+
+Very true.
+Instead of: b_pn_b_id_idx,
+I think better would be: busines_person_b_id_idx
+
+Thanks
+Rudi.
+
+
+
+
+Victor Yegorov wrote:
+
+
* Rudi Starcevic <rudi@oasis.net.au> [15.05.2003 04:46]:
+  
+
+
Stephen,
+
+
+New:
+CREATE TABLE business_person
+(
+b_id integer REFERENCES business ON UPDATE CASCADE ON DELETE CASCADE NOT 
+NULL,
+pn_id integer REFERENCES person ON UPDATE CASCADE ON DELETE CASCADE NOT NULL
+PRIMARY KEY(b_id,pn_id);
+);
+CREATE INDEX b_pn_b_id_idx  ON business_person (b_id);
+CREATE INDEX b_pn_pn_id_idx ON business_person (pn_id);
+    
+
+

+May be it's better to name indexes a bit more clearer? No impact on overall
+performance, but you'll ease your life, if you project will grow to hundreds
+of tables and thousands of indicies.
+
+  
+
+
As I'd like to sometime's look up business's, sometime's look up people and 
+sometimes
+look up both I think I should keep the Index's.
+    
+
+

+If your lookups are part of business logic, than it's ok. Also, if your
+system generates reports using several table joins that may speed up the
+things.
+
+Otherwise, for curiosity cases, it's better to wait some time for the result
+of one-time queries.
+
+  
+
+
+ + + +--------------030903040507010607030403-- + + +From pgsql-performance-owner@postgresql.org Wed May 14 22:10:04 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 80A6F47644F + for ; + Wed, 14 May 2003 22:10:03 -0400 (EDT) +Received: from postgresql.org ([64.49.215.8]) + by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with + ESMTP id 89838-09 for ; + Wed, 14 May 2003 22:10:02 -0400 (EDT) +Received: from water.oasis.net.au (water.oasis.net.au [210.8.139.2]) + by postgresql.org (Postfix) with ESMTP id 39BE8475F16 + for ; + Wed, 14 May 2003 22:10:01 -0400 (EDT) +Received: from oasis.net.au (guardian [210.8.139.5]) + by water.oasis.net.au (8.9.3/8.9.3/Debian 8.9.3-21) with ESMTP id + MAA17960; Thu, 15 May 2003 12:19:23 +1000 +X-Authentication-Warning: water.oasis.net.au: Host guardian [210.8.139.5] + claimed to be oasis.net.au +Message-ID: <3EC2F81B.10001@oasis.net.au> +Date: Thu, 15 May 2003 12:14:51 +1000 +From: Rudi Starcevic +User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; + rv:1.3) Gecko/20030312 +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: Rudi Starcevic +Cc: Victor Yegorov , + Stephan Szabo , + Postgres Performance +Subject: Re: constraint with reference to the same table +References: <20030514181136.S52444-100000@megazone23.bigpanda.com> + <3EC2F1E4.8080706@oasis.net.au> <20030515015811.GE1549@nordlb.lv> + <3EC2F65F.2050004@oasis.net.au> +In-Reply-To: <3EC2F65F.2050004@oasis.net.au> +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/172 +X-Sequence-Number: 1951 + +Perhaps I also need a 3rd Index ? + +One for Business's +One for People and +One for Business_People. + +I think I may need the 3rd Index for query's like + +Select b_id + From business_people +where b_id = 1 and pn_id = 2; + +I think this way I have an Index for 3 type's of queries. + +When I looking for data on just the business, +when I'm looking for data on just people and +when I'm looking for data on business people relationships. + +Cheers +Rudi. + + +From pgsql-performance-owner@postgresql.org Wed May 14 22:18:56 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id B1FFE47644F + for ; + Wed, 14 May 2003 22:18:54 -0400 (EDT) +Received: from postgresql.org ([64.49.215.8]) + by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with + ESMTP id 90738-04 for ; + Wed, 14 May 2003 22:18:53 -0400 (EDT) +Received: from shield.nordlb.lv (shield.pirmabanka.lv [195.114.57.4]) + by postgresql.org (Postfix) with ESMTP id 7A64B475F16 + for ; + Wed, 14 May 2003 22:18:52 -0400 (EDT) +Received: from wall2.pirmabanka.lv (wall2-pub.nordlb.lv [195.114.57.14]) + by shield.nordlb.lv (8.12.9/8.12.9) with SMTP id h4F2Itbg019348 + for ; Thu, 15 May 2003 05:18:55 +0300 +Received: from share.nordlb.lv ([10.0.0.10]) by wall2.pirmabanka.lv; + Thu, 15 May 2003 05:18:54 +0300 (EET DST) +Received: from pc311x1.nordlb.lv (localhost.localdomain [127.0.0.1]) + by nordlb.lv (8.11.6/8.11.6) with SMTP id h4F2Is523609 + for ; Thu, 15 May 2003 05:18:54 +0300 +Received: (qmail 2708 invoked by uid 100); 15 May 2003 02:21:35 -0000 +Date: Thu, 15 May 2003 05:21:35 +0300 +From: Victor Yegorov +To: Rudi Starcevic +Cc: Stephan Szabo , + Postgres Performance +Subject: Re: constraint with reference to the same table +Message-ID: <20030515022135.GF1549@nordlb.lv> +References: <20030514181136.S52444-100000@megazone23.bigpanda.com> + <3EC2F1E4.8080706@oasis.net.au> <20030515015811.GE1549@nordlb.lv> + <3EC2F65F.2050004@oasis.net.au> <3EC2F81B.10001@oasis.net.au> +Mime-Version: 1.0 +Content-Type: text/plain; charset=koi8-r +Content-Disposition: inline +In-Reply-To: <3EC2F81B.10001@oasis.net.au> +User-Agent: Mutt/1.4.1i +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/173 +X-Sequence-Number: 1952 + +* Rudi Starcevic [15.05.2003 05:15]: +> Perhaps I also need a 3rd Index ? +> +> One for Business's +> One for People and +> One for Business_People. +> +> I think I may need the 3rd Index for query's like + +You don't need it. Primary key on that 2 columns will create a unique index +on them. Of course, if you left things unchanged - you'll need to create +business_people index yourself. + +execute: + +=> \d business_people + +and take a glance on a line, describing primary key. + +-- + +Victor Yegorov + +From pgsql-performance-owner@postgresql.org Wed May 14 22:25:54 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id CB4CF47653B + for ; + Wed, 14 May 2003 22:25:53 -0400 (EDT) +Received: from postgresql.org ([64.49.215.8]) + by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with + ESMTP id 91984-07 for ; + Wed, 14 May 2003 22:25:52 -0400 (EDT) +Received: from sss.pgh.pa.us (unknown [192.204.191.242]) + by postgresql.org (Postfix) with ESMTP id 22ABA476539 + for ; + Wed, 14 May 2003 22:25:52 -0400 (EDT) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h4F2PuU6004922; + Wed, 14 May 2003 22:25:56 -0400 (EDT) +To: "T. Alex Beamish" +Cc: "Postgresql-Performance" +Subject: Re: INNER JOIN vs WHERE +In-reply-to: <20030515014648.NRXV26559.tomts19-srv.bellnexxia.net@p433> +References: <20030515014648.NRXV26559.tomts19-srv.bellnexxia.net@p433> +Comments: In-reply-to "T. Alex Beamish" + message dated "Wed, 14 May 2003 21:45:04 -0400" +Date: Wed, 14 May 2003 22:25:55 -0400 +Message-ID: <4921.1052965555@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/175 +X-Sequence-Number: 1954 + +"T. Alex Beamish" writes: +> Is there any rule of thumb about how much more efficient an INNER JOIN +> is compare to a regular WHERE statement? + +Ideally there is no difference. If there are only two tables involved, +there definitely is no difference. + +If there is a difference, it's because there are more than two tables, +and the JOIN syntax forced a particular join order. Read +http://www.postgresql.org/docs/view.php?version=7.3&idoc=0&file=explicit-joins.html + +Typically I'd expect JOIN syntax to be a loss because the odds are good +that you're forcing an inefficient join order. It could be a win only +if the planner chooses a poor join order when given a free hand, or if +you have so many tables that you need to suppress the planner's search +for a good join order. + +> I have not tried to do an EXPLAIN ANALYZE yet but I will try that. + +If you have not bothered to do any EXPLAINs yet then you are really +wasting people's time on this list. + + regards, tom lane + +From pgsql-performance-owner@postgresql.org Wed May 14 22:24:30 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 3C8C147644F + for ; + Wed, 14 May 2003 22:24:29 -0400 (EDT) +Received: from postgresql.org ([64.49.215.8]) + by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with + ESMTP id 91984-02 for ; + Wed, 14 May 2003 22:24:27 -0400 (EDT) +Received: from water.oasis.net.au (water.oasis.net.au [210.8.139.2]) + by postgresql.org (Postfix) with ESMTP id D1914475F16 + for ; + Wed, 14 May 2003 22:24:26 -0400 (EDT) +Received: from oasis.net.au (guardian [210.8.139.5]) + by water.oasis.net.au (8.9.3/8.9.3/Debian 8.9.3-21) with ESMTP id + MAA18229 + for ; Thu, 15 May 2003 12:33:57 +1000 +X-Authentication-Warning: water.oasis.net.au: Host guardian [210.8.139.5] + claimed to be oasis.net.au +Message-ID: <3EC2FB82.8070507@oasis.net.au> +Date: Thu, 15 May 2003 12:29:22 +1000 +From: Rudi Starcevic +User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; + rv:1.3) Gecko/20030312 +X-Accept-Language: en-us, en +MIME-Version: 1.0 +Cc: Postgres Performance +Subject: Re: constraint with reference to the same table +References: <20030514181136.S52444-100000@megazone23.bigpanda.com> + <3EC2F1E4.8080706@oasis.net.au> <20030515015811.GE1549@nordlb.lv> + <3EC2F65F.2050004@oasis.net.au> <3EC2F81B.10001@oasis.net.au> + <20030515022135.GF1549@nordlb.lv> +In-Reply-To: <20030515022135.GF1549@nordlb.lv> +Content-Type: multipart/alternative; + boundary="------------060707030407080409010707" +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/174 +X-Sequence-Number: 1953 + +This is a multi-part message in MIME format. +--------------060707030407080409010707 +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit + +Victor, + +>> You don't need it. Primary key on that 2 columns will create a unique index +>> on them. Of course, if you left things unchanged - you'll need to create +>> business_people index yourself. + +Ahh of course .. + +"I see said the blind man !" .. + +Thanks heaps. +I think now it's pretty clear to me. +I feel I have pretty much optimised my code / sql schema. + +Thank you both, +it's a tremendous help - one learns something every day with this list. + +Kind regards +Rudi. + +Victor Yegorov wrote: + +>* Rudi Starcevic [15.05.2003 05:15]: +> +> +>>Perhaps I also need a 3rd Index ? +>> +>>One for Business's +>>One for People and +>>One for Business_People. +>> +>>I think I may need the 3rd Index for query's like +>> +>> +> +>You don't need it. Primary key on that 2 columns will create a unique index +>on them. Of course, if you left things unchanged - you'll need to create +>business_people index yourself. +> +>execute: +> +>=> \d business_people +> +>and take a glance on a line, describing primary key. +> +> +> + + +--------------060707030407080409010707 +Content-Type: text/html; charset=us-ascii +Content-Transfer-Encoding: 7bit + + + + + + + + +Victor,
+
+
>> You don't need it. Primary key on that 2 columns will create a unique index
+>> on them. Of course, if you left things unchanged - you'll need to create
+>> business_people index yourself.
+
+Ahh of course ..
+
+"I see said the blind man !" ..
+
+Thanks heaps.
+I think now it's pretty clear to me.
+I feel I have pretty much optimised my code / sql schema.
+
+Thank you both,
+it's a tremendous help - one learns something every day with this list.
+
+Kind regards
+Rudi.
+
+Victor Yegorov wrote:
+
+
* Rudi Starcevic <rudi@oasis.net.au> [15.05.2003 05:15]:
+  
+
+
Perhaps I also need a 3rd Index ?
+
+One for Business's
+One for People and
+One for Business_People.
+
+I think I may need the 3rd Index for query's like
+    
+
+

+You don't need it. Primary key on that 2 columns will create a unique index
+on them. Of course, if you left things unchanged - you'll need to create
+business_people index yourself.
+
+execute:
+
+=> \d business_people
+
+and take a glance on a line, describing primary key.
+
+  
+
+
+ + + +--------------060707030407080409010707-- + + +From pgsql-performance-owner@postgresql.org Wed May 14 23:30:34 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 24EBB475ED4 + for ; + Wed, 14 May 2003 23:30:34 -0400 (EDT) +Received: from postgresql.org ([64.49.215.8]) + by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with + ESMTP id 99927-02 for ; + Wed, 14 May 2003 23:30:32 -0400 (EDT) +Received: from candle.pha.pa.us (momjian.navpoint.com [207.106.42.251]) + by postgresql.org (Postfix) with ESMTP id 912E4475CBC + for ; + Wed, 14 May 2003 23:30:31 -0400 (EDT) +Received: (from pgman@localhost) + by candle.pha.pa.us (8.11.6/8.10.1) id h4F3UHV03141; + Wed, 14 May 2003 23:30:17 -0400 (EDT) +From: Bruce Momjian +Message-Id: <200305150330.h4F3UHV03141@candle.pha.pa.us> +Subject: Re: PERFORMANCE and SIZE +In-Reply-To: <011d01c318be$997217f0$9002a8c0@ialfranio> +To: Alfranio Junior +Date: Wed, 14 May 2003 23:30:17 -0400 (EDT) +Cc: pgsql-performance@postgresql.org +X-Mailer: ELM [version 2.4ME+ PL99 (25)] +MIME-Version: 1.0 +Content-Transfer-Encoding: 7bit +Content-Type: text/plain; charset=US-ASCII +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/176 +X-Sequence-Number: 1955 + + +I have gotten so much spam, this subject line struck me as spam until I +looked closer. Did it catch anyone else? + +--------------------------------------------------------------------------- + +Alfranio Junior wrote: +> Hello, +> +> I'm a new PostgresSql user and I do not know so much about the +> performance mechanisms currently implemented and available. +> +> So, as a dummy user I think that something strange is happening with me. +> When I run the following command: +> +> explain analyze select * from customer +> where c_last = 'ROUGHTATION' and +> c_w_id = 1 and +> c_d_id = 1 +> order by c_w_id, c_d_id, c_last, c_first limit 1; +> +> I receive the following results: +> +> (Customer table with 60.000 rows) - +> QUERY PLAN +> --------------------------------------------------------------------------- +> ----------------------------------------------------------- +> Limit (cost=4.84..4.84 rows=1 width=283) (actual time=213.13..213.13 +> rows=0 loops=1) +> -> Sort (cost=4.84..4.84 rows=1 width=283) (actual +> time=213.13..213.13 rows=0 loops=1) +> Sort Key: c_w_id, c_d_id, c_last, c_first +> -> Index Scan using pk_customer on customer (cost=0.00..4.83 +> rows=1 width=283) (actual time=211.93..211.93 rows=0 loops=1) +> Index Cond: ((c_w_id = 1) AND (c_d_id = 1)) +> Filter: (c_last = 'ROUGHTATION'::bpchar) +> Total runtime: 213.29 msec +> (7 rows) +> +> +> (Customer table with 360.000 rows) - +> QUERY PLAN +> --------------------------------------------------------------------------- +> ------------------------------------------------------------- +> Limit (cost=11100.99..11101.00 rows=1 width=638) (actual +> time=20.82..20.82 rows=0 loops=1) +> -> Sort (cost=11100.99..11101.00 rows=4 width=638) (actual +> time=20.81..20.81 rows=0 loops=1) +> Sort Key: c_w_id, c_d_id, c_last, c_first +> -> Index Scan using pk_customer on customer +> (cost=0.00..11100.95 rows=4 width=638) (actual time=20.40..20.40 rows=0 +> loops=1) +> Index Cond: ((c_w_id = 1) AND (c_d_id = 1)) +> Filter: (c_last = 'ROUGHTATION'::bpchar) +> Total runtime: 21.11 msec +> (7 rows) +> +> Increasing the number of rows the total runtime decreases. +> The customer table has the following structure: +> CREATE TABLE customer +> ( +> c_id int NOT NULL , +> c_d_id int4 NOT NULL , +> c_w_id int4 NOT NULL , +> c_first char (16) NULL , +> c_middle char (2) NULL , +> c_last char (16) NULL , +> c_street_1 char (20) NULL , +> c_street_2 char (20) NULL , +> c_city char (20) NULL , +> c_state char (2) NULL , +> c_zip char (9) NULL , +> c_phone char (16) NULL , +> c_since timestamp NULL , +> c_credit char (2) NULL , +> c_credit_lim numeric(12, 2) NULL , +> c_discount numeric(4, 4) NULL , +> c_balance numeric(12, 2) NULL , +> c_ytd_payment numeric(12, 2) NULL , +> c_payment_cnt int4 NULL , +> c_delivery_cnt int4 NULL , +> c_data text NULL +> ); +> +> ALTER TABLE customer ADD +> CONSTRAINT PK_customer PRIMARY KEY +> ( +> c_w_id, +> c_d_id, +> c_id +> ); +> +> Does anybody know what is happening ? +> +> +> Thanks !!!! +> +> Alfranio Junior +> +> +> ---------------------------(end of broadcast)--------------------------- +> TIP 5: Have you checked our extensive FAQ? +> +> http://www.postgresql.org/docs/faqs/FAQ.html +> + +-- + Bruce Momjian | http://candle.pha.pa.us + pgman@candle.pha.pa.us | (610) 359-1001 + + If your life is a hard drive, | 13 Roberts Road + + Christ can be your backup. | Newtown Square, Pennsylvania 19073 + +From pgsql-performance-owner@postgresql.org Wed May 14 23:40:17 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 7E53247655C + for ; + Wed, 14 May 2003 23:40:16 -0400 (EDT) +Received: from postgresql.org ([64.49.215.8]) + by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with + ESMTP id 00291-10 for ; + Wed, 14 May 2003 23:40:14 -0400 (EDT) +Received: from water.oasis.net.au (water.oasis.net.au [210.8.139.2]) + by postgresql.org (Postfix) with ESMTP id A1069476555 + for ; + Wed, 14 May 2003 23:40:13 -0400 (EDT) +Received: from oasis.net.au (guardian [210.8.139.5]) + by water.oasis.net.au (8.9.3/8.9.3/Debian 8.9.3-21) with ESMTP id + NAA19692 + for ; Thu, 15 May 2003 13:49:45 +1000 +X-Authentication-Warning: water.oasis.net.au: Host guardian [210.8.139.5] + claimed to be oasis.net.au +Message-ID: <3EC30D7D.4070107@oasis.net.au> +Date: Thu, 15 May 2003 13:46:05 +1000 +From: Rudi Starcevic +User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; + rv:1.3) Gecko/20030312 +X-Accept-Language: en-us, en +MIME-Version: 1.0 +Cc: pgsql-performance@postgresql.org +Subject: Re: PERFORMANCE and SIZE +References: <200305150330.h4F3UHV03141@candle.pha.pa.us> +In-Reply-To: <200305150330.h4F3UHV03141@candle.pha.pa.us> +Content-Type: multipart/alternative; + boundary="------------030102000703030609060504" +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/177 +X-Sequence-Number: 1956 + +This is a multi-part message in MIME format. +--------------030102000703030609060504 +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit + +Ha ! + +No - it didn't catch me -- but Yes my spam has been going through the +roof lately. +Over here in Australia it's in the Media alot of late - Spam increases. +Seems like everyone is suffering. + +Cheers +RS. + + + + +Bruce Momjian wrote: + +>I have gotten so much spam, this subject line struck me as spam until I +>looked closer. Did it catch anyone else? +> +>--------------------------------------------------------------------------- +> +>Alfranio Junior wrote: +> +> +>> Hello, +>> +>>I'm a new PostgresSql user and I do not know so much about the +>> performance mechanisms currently implemented and available. +>> +>> So, as a dummy user I think that something strange is happening with me. +>> When I run the following command: +>> +>> explain analyze select * from customer +>> where c_last = 'ROUGHTATION' and +>> c_w_id = 1 and +>> c_d_id = 1 +>> order by c_w_id, c_d_id, c_last, c_first limit 1; +>> +>> I receive the following results: +>> +>> (Customer table with 60.000 rows) - +>> QUERY PLAN +>> --------------------------------------------------------------------------- +>>----------------------------------------------------------- +>> Limit (cost=4.84..4.84 rows=1 width=283) (actual time=213.13..213.13 +>> rows=0 loops=1) +>> -> Sort (cost=4.84..4.84 rows=1 width=283) (actual +>> time=213.13..213.13 rows=0 loops=1) +>> Sort Key: c_w_id, c_d_id, c_last, c_first +>> -> Index Scan using pk_customer on customer (cost=0.00..4.83 +>> rows=1 width=283) (actual time=211.93..211.93 rows=0 loops=1) +>> Index Cond: ((c_w_id = 1) AND (c_d_id = 1)) +>> Filter: (c_last = 'ROUGHTATION'::bpchar) +>> Total runtime: 213.29 msec +>> (7 rows) +>> +>> +>> (Customer table with 360.000 rows) - +>> QUERY PLAN +>> --------------------------------------------------------------------------- +>>------------------------------------------------------------- +>> Limit (cost=11100.99..11101.00 rows=1 width=638) (actual +>> time=20.82..20.82 rows=0 loops=1) +>> -> Sort (cost=11100.99..11101.00 rows=4 width=638) (actual +>> time=20.81..20.81 rows=0 loops=1) +>> Sort Key: c_w_id, c_d_id, c_last, c_first +>> -> Index Scan using pk_customer on customer +>> (cost=0.00..11100.95 rows=4 width=638) (actual time=20.40..20.40 rows=0 +>> loops=1) +>> Index Cond: ((c_w_id = 1) AND (c_d_id = 1)) +>> Filter: (c_last = 'ROUGHTATION'::bpchar) +>> Total runtime: 21.11 msec +>> (7 rows) +>> +>> Increasing the number of rows the total runtime decreases. +>> The customer table has the following structure: +>> CREATE TABLE customer +>> ( +>> c_id int NOT NULL , +>> c_d_id int4 NOT NULL , +>> c_w_id int4 NOT NULL , +>> c_first char (16) NULL , +>> c_middle char (2) NULL , +>> c_last char (16) NULL , +>> c_street_1 char (20) NULL , +>> c_street_2 char (20) NULL , +>> c_city char (20) NULL , +>> c_state char (2) NULL , +>> c_zip char (9) NULL , +>> c_phone char (16) NULL , +>> c_since timestamp NULL , +>> c_credit char (2) NULL , +>> c_credit_lim numeric(12, 2) NULL , +>> c_discount numeric(4, 4) NULL , +>> c_balance numeric(12, 2) NULL , +>> c_ytd_payment numeric(12, 2) NULL , +>> c_payment_cnt int4 NULL , +>> c_delivery_cnt int4 NULL , +>> c_data text NULL +>> ); +>> +>> ALTER TABLE customer ADD +>> CONSTRAINT PK_customer PRIMARY KEY +>> ( +>> c_w_id, +>> c_d_id, +>> c_id +>> ); +>> +>> Does anybody know what is happening ? +>> +>> +>> Thanks !!!! +>> +>> Alfranio Junior +>> +>> +>>---------------------------(end of broadcast)--------------------------- +>>TIP 5: Have you checked our extensive FAQ? +>> +>>http://www.postgresql.org/docs/faqs/FAQ.html +>> +>> +>> +> +> +> + + +--------------030102000703030609060504 +Content-Type: text/html; charset=us-ascii +Content-Transfer-Encoding: 7bit + + + + + + + + +Ha !
+
+No - it didn't catch me -- but Yes my spam has been going through the +roof lately.
+Over here in Australia it's in the Media alot of late - Spam increases.
+Seems like everyone is suffering.
+
+Cheers
+RS.
+
+
+
+
+Bruce Momjian wrote:
+
+
I have gotten so much spam, this subject line struck me as spam until I
+looked closer.  Did it catch anyone else?
+
+---------------------------------------------------------------------------
+
+Alfranio Junior wrote:
+  
+
+
 Hello,
+
+I'm a new PostgresSql user and I do not know so much about the
+ performance mechanisms currently implemented and available.
+
+ So, as a dummy user I think that something strange is happening with me.
+ When I run the following command:
+
+ explain analyze select * from customer
+       where c_last = 'ROUGHTATION' and
+       c_w_id = 1 and
+       c_d_id = 1
+       order by c_w_id, c_d_id, c_last, c_first limit 1;
+
+ I receive the following results:
+
+ (Customer table with 60.000 rows) -
+                                                                QUERY PLAN
+ ---------------------------------------------------------------------------
+-----------------------------------------------------------
+   Limit  (cost=4.84..4.84 rows=1 width=283) (actual time=213.13..213.13
+ rows=0 loops=1)
+     ->  Sort  (cost=4.84..4.84 rows=1 width=283) (actual
+ time=213.13..213.13 rows=0 loops=1)
+           Sort Key: c_w_id, c_d_id, c_last, c_first
+           ->  Index Scan using pk_customer on customer  (cost=0.00..4.83
+ rows=1 width=283) (actual time=211.93..211.93 rows=0 loops=1)
+                 Index Cond: ((c_w_id = 1) AND (c_d_id = 1))
+                 Filter: (c_last = 'ROUGHTATION'::bpchar)
+   Total runtime: 213.29 msec
+ (7 rows)
+
+
+ (Customer table with 360.000 rows) -
+                                                                 QUERY PLAN
+ ---------------------------------------------------------------------------
+-------------------------------------------------------------
+   Limit  (cost=11100.99..11101.00 rows=1 width=638) (actual
+ time=20.82..20.82 rows=0 loops=1)
+     ->  Sort  (cost=11100.99..11101.00 rows=4 width=638) (actual
+ time=20.81..20.81 rows=0 loops=1)
+           Sort Key: c_w_id, c_d_id, c_last, c_first
+           ->  Index Scan using pk_customer on customer
+ (cost=0.00..11100.95 rows=4 width=638) (actual time=20.40..20.40 rows=0
+ loops=1)
+                 Index Cond: ((c_w_id = 1) AND (c_d_id = 1))
+                 Filter: (c_last = 'ROUGHTATION'::bpchar)
+   Total runtime: 21.11 msec
+ (7 rows)
+
+ Increasing the number of rows the total runtime decreases.
+ The customer table has the following structure:
+ CREATE TABLE customer
+ (
+      c_id int NOT NULL ,
+      c_d_id int4 NOT NULL ,
+      c_w_id int4 NOT NULL ,
+      c_first char (16) NULL ,
+      c_middle char (2) NULL ,
+      c_last char (16) NULL ,
+      c_street_1 char (20) NULL ,
+      c_street_2 char (20) NULL ,
+      c_city char (20) NULL ,
+      c_state char (2) NULL ,
+      c_zip char (9) NULL ,
+      c_phone char (16) NULL ,
+      c_since timestamp NULL ,
+      c_credit char (2) NULL ,
+      c_credit_lim numeric(12, 2) NULL ,
+      c_discount numeric(4, 4) NULL ,
+      c_balance numeric(12, 2) NULL ,
+      c_ytd_payment numeric(12, 2) NULL ,
+      c_payment_cnt int4 NULL ,
+      c_delivery_cnt int4 NULL ,
+      c_data text NULL
+ );
+
+ ALTER TABLE customer  ADD
+      CONSTRAINT PK_customer PRIMARY KEY
+      (
+          c_w_id,
+          c_d_id,
+          c_id
+      );
+
+ Does anybody know what is happening ?
+
+
+ Thanks !!!!
+
+ Alfranio Junior
+
+
+---------------------------(end of broadcast)---------------------------
+TIP 5: Have you checked our extensive FAQ?
+
+http://www.postgresql.org/docs/faqs/FAQ.html
+
+    
+
+

+  
+
+
+ + + +--------------030102000703030609060504-- + + +From pgsql-performance-owner@postgresql.org Wed May 14 23:49:06 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 88539476549 + for ; + Wed, 14 May 2003 23:49:05 -0400 (EDT) +Received: from postgresql.org ([64.49.215.8]) + by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with + ESMTP id 01928-05 for ; + Wed, 14 May 2003 23:49:04 -0400 (EDT) +Received: from shield.nordlb.lv (shield.pirmabanka.lv [195.114.57.4]) + by postgresql.org (Postfix) with ESMTP id 62FD8475CBC + for ; + Wed, 14 May 2003 23:49:03 -0400 (EDT) +Received: from wall2.pirmabanka.lv (wall2-pub.nordlb.lv [195.114.57.14]) + by shield.nordlb.lv (8.12.9/8.12.9) with SMTP id h4F3n7bg019654 + for ; Thu, 15 May 2003 06:49:07 +0300 +Received: from share.nordlb.lv ([10.0.0.10]) by wall2.pirmabanka.lv; + Thu, 15 May 2003 06:49:06 +0300 (EET DST) +Received: from pc311x1.nordlb.lv (localhost.localdomain [127.0.0.1]) + by nordlb.lv (8.11.6/8.11.6) with SMTP id h4F3n6Y25243 + for ; Thu, 15 May 2003 06:49:06 +0300 +Received: (qmail 3216 invoked by uid 100); 15 May 2003 03:51:46 -0000 +Date: Thu, 15 May 2003 06:51:46 +0300 +From: "Victor Yegorov" +To: "amol" +Cc: +Subject: Re: nested select query failing +Message-ID: <20030515035146.GH1549@nordlb.lv> +References: <003c01c31a96$1d1703d0$2e00a8c0@amol> +Mime-Version: 1.0 +Content-Type: text/plain; charset=koi8-r +Content-Disposition: inline +In-Reply-To: <003c01c31a96$1d1703d0$2e00a8c0@amol> +User-Agent: Mutt/1.4.1i +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/179 +X-Sequence-Number: 1958 + +* amol [15.05.2003 06:47]: +> Hi everybody, +> I am new to this mailing list, so please let me know if I am not posting +> queries the way you are expecting. +> +> - We are porting a web based application from MSSQL to postgres as a +> backend. +> This is a database intensive application. I am facing a problem in some +> queries like this : +> +> select distinct attached_info.id, ownerid ,attached_info.modified_date from +> attached_info where attached_info.id in ( select distinct +> attached_tag_list.id from attached_tag_list where attached_tag_list.id in +> select attached_info.id from attached_info where +> ttached_info.deleted='0' ) and attached_tag_list.id in ( select id from +> attached_tag_list where attached_tag = 262 ) and +> attached_tag_list.attached_tag in ( select tags.id from tags where tags.id +> in ( select tag_id from tag_classifier, tag_classifier_association where +> classifier_tag_id in ( 261, 4467, 1894, 1045, 1087, 1355, 72, 1786, 1179, +> 3090, 871, 3571, 3565, 3569, 3567, 1043, 2535, 1080, 3315, 87, 1041, 2343, +> 2345, 1869, 3088, 3872, 2651, 2923, 2302, 1681, 3636, 3964, 2778, 2694, +> 1371, 2532, 2527, 3742, 3740, 1761, 4530, 4671, 4503, 4512, 3700 ) and +> association_id='1566' and +> tag_classifier.uid=tag_classifier_association.uid ) and +> tags.isdeleted='0' ) ) order by attached_info.modified_date desc, +> attached_info.id desc; + +IN () constructs isn't a good part of postgres (from the performance point +of view). Try to rewrite your query using joins or EXISTS/NOT EXISTS +constructs. + +Search archives for more details, there were a discussion of this topic +lately. + +-- + +Victor Yegorov + +From pgsql-performance-owner@postgresql.org Wed May 14 23:41:55 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 4E7FF476549 + for ; + Wed, 14 May 2003 23:41:54 -0400 (EDT) +Received: from postgresql.org ([64.49.215.8]) + by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with + ESMTP id 01167-10 for ; + Wed, 14 May 2003 23:41:52 -0400 (EDT) +Received: from mithi.com (unknown [219.65.91.97]) + by postgresql.org (Postfix) with SMTP id E816F476555 + for ; + Wed, 14 May 2003 23:41:50 -0400 (EDT) +Received: (qmail 29272 invoked by uid 0); 15 May 2003 03:38:45 -0000 +Received: from unknown (HELO amol) (192.168.0.46) + by 0 with SMTP; 15 May 2003 03:38:45 -0000 +Message-ID: <003c01c31a96$1d1703d0$2e00a8c0@amol> +From: "amol" +To: +Subject: nested select query failing +Date: Thu, 15 May 2003 09:27:33 +0530 +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit +X-Priority: 3 +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook Express 5.00.2919.6700 +X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6700 +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/178 +X-Sequence-Number: 1957 + +Hi everybody, +I am new to this mailing list, so please let me know if I am not posting +queries the way you are expecting. + +- We are porting a web based application from MSSQL to postgres as a +backend. +This is a database intensive application. I am facing a problem in some +queries like this : + +select distinct attached_info.id, ownerid ,attached_info.modified_date from +attached_info where attached_info.id in ( select distinct +attached_tag_list.id from attached_tag_list where attached_tag_list.id in + select attached_info.id from attached_info where +ttached_info.deleted='0' ) and attached_tag_list.id in ( select id from +attached_tag_list where attached_tag = 262 ) and +attached_tag_list.attached_tag in ( select tags.id from tags where tags.id +in ( select tag_id from tag_classifier, tag_classifier_association where +classifier_tag_id in ( 261, 4467, 1894, 1045, 1087, 1355, 72, 1786, 1179, +3090, 871, 3571, 3565, 3569, 3567, 1043, 2535, 1080, 3315, 87, 1041, 2343, +2345, 1869, 3088, 3872, 2651, 2923, 2302, 1681, 3636, 3964, 2778, 2694, +1371, 2532, 2527, 3742, 3740, 1761, 4530, 4671, 4503, 4512, 3700 ) and +association_id='1566' and +tag_classifier.uid=tag_classifier_association.uid ) and +tags.isdeleted='0' ) ) order by attached_info.modified_date desc, +attached_info.id desc; + +When I fire this query in psql, it does not return back. + +- top command shows postgres above 95+% cpu usage consistantly + PID USER PRI NI SIZE RSS SHARE STAT %CPU %MEM TIME COMMAND + 1550 postgres 25 0 20268 19M 18904 R 95.3 5.2 6:31 postmaster + +- I am using RedHat 8 with following postgres rpms +postgresql-libs-7.2.2-1 +postgresql-7.2.2-1 +postgresql-server-7.2.2-1 + +- RAM size is 384 MB, SWAP size is 384 MB, but top shows that memory is free + +- I have done following changes after searching for performance realted +information on the internet and postgres site + - in /etc/rc.d/rc.local added following lines + echo "32768" >/proc/sys/fs/file-max + echo "98304" >/proc/sys/fs/inode-max + - in /etc/init.d/postgresql file a pg_ctl call is changed to : + su -l postgres -s /bin/sh -c "/usr/bin/pg_ctl -D $PGDATA -o +'-i -N 1024 -B 2048 -d 5' -p /usr/bin/postmaster start >> +/var/log/pgsql.log 2>&1" < /dev/null + +- pgsql log shows : +...... +}) :lefttree <> :righttree <> :extprm () :locprm () :initplan <> :nprm 0 +:scanrelid 1 } :righttree <> :extprm () :locprm () :initplan <> :nprm 0 +:keycount 3 } :righttree <> :extprm () :locprm () :initplan <> :nprm 0 +:numCols 3 :uniqColIdx 3 1 2 } +DEBUG: ProcessQuery +********* +log stops here for 5/6 minuts +********* +DEBUG: proc_exit(0) +DEBUG: shmem_exit(0) +DEBUG: exit(0) +DEBUG: reaping dead processes +DEBUG: child process (pid 1595) exited with exit code 0 +DEBUG: proc_exit(0) +DEBUG: shmem_exit(0) +DEBUG: exit(0) +DEBUG: reaping dead processes +DEBUG: child process (pid 1598) exited with exit code 0 +DEBUG: proc_exit(0) +DEBUG: shmem_exit(0) +DEBUG: exit(0) +DEBUG: reaping dead processes +DEBUG: child process (pid 1599) exited with exit code 0 +DEBUG: proc_exit(0) +DEBUG: shmem_exit(0) +DEBUG: exit(0) +DEBUG: reaping dead processes +DEBUG: child process (pid 1600) exited with exit code 0 + + +- What should I do to get such queries working? +- Is there any limit on query size? +- Is there anything left in tuning postgres which is causing this problem ? + +If you want me to try anything, please let me know. + +thanks +Amol + + + + + + +From pgsql-performance-owner@postgresql.org Thu May 15 00:24:16 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id B008D4761C0 + for ; + Thu, 15 May 2003 00:24:09 -0400 (EDT) +Received: from postgresql.org ([64.49.215.8]) + by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with + ESMTP id 03212-10 for ; + Thu, 15 May 2003 00:23:57 -0400 (EDT) +Received: from houston.familyhealth.com.au (unknown [203.59.48.253]) + by postgresql.org (Postfix) with ESMTP id 21903476085 + for ; + Thu, 15 May 2003 00:23:56 -0400 (EDT) +Received: (from root@localhost) + by houston.familyhealth.com.au (8.11.6p2/8.11.6) id h4F4NxD12730 + for pgsql-performance@postgresql.org; + Thu, 15 May 2003 12:23:59 +0800 (WST) + (envelope-from chriskl@familyhealth.com.au) +Received: from mariner (mariner.internal [192.168.0.101]) + by houston.familyhealth.com.au (8.11.6p2/8.9.3) with SMTP id + h4F4NrJ12640; Thu, 15 May 2003 12:23:53 +0800 (WST) +Message-ID: <063501c31a99$d4425020$6500a8c0@fhp.internal> +From: "Christopher Kings-Lynne" +To: "amol" , +References: <003c01c31a96$1d1703d0$2e00a8c0@amol> +Subject: Re: nested select query failing +Date: Thu, 15 May 2003 12:24:08 +0800 +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit +X-Priority: 3 +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook Express 6.00.2800.1158 +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 +X-scanner: scanned by Inflex 0.1.5c - (http://www.inflex.co.za/) +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/180 +X-Sequence-Number: 1959 + +Please post the EXPLAIN ANALYZE of that query... + +Chris + +----- Original Message ----- +From: "amol" +To: +Sent: Thursday, May 15, 2003 11:57 AM +Subject: [PERFORM] nested select query failing + + +> Hi everybody, +> I am new to this mailing list, so please let me know if I am not posting +> queries the way you are expecting. +> +> - We are porting a web based application from MSSQL to postgres as a +> backend. +> This is a database intensive application. I am facing a problem in some +> queries like this : +> +> select distinct attached_info.id, ownerid ,attached_info.modified_date +from +> attached_info where attached_info.id in ( select distinct +> attached_tag_list.id from attached_tag_list where attached_tag_list.id in +> select attached_info.id from attached_info where +> ttached_info.deleted='0' ) and attached_tag_list.id in ( select id from +> attached_tag_list where attached_tag = 262 ) and +> attached_tag_list.attached_tag in ( select tags.id from tags where tags.id +> in ( select tag_id from tag_classifier, tag_classifier_association where +> classifier_tag_id in ( 261, 4467, 1894, 1045, 1087, 1355, 72, 1786, 1179, +> 3090, 871, 3571, 3565, 3569, 3567, 1043, 2535, 1080, 3315, 87, 1041, 2343, +> 2345, 1869, 3088, 3872, 2651, 2923, 2302, 1681, 3636, 3964, 2778, 2694, +> 1371, 2532, 2527, 3742, 3740, 1761, 4530, 4671, 4503, 4512, 3700 ) and +> association_id='1566' and +> tag_classifier.uid=tag_classifier_association.uid ) and +> tags.isdeleted='0' ) ) order by attached_info.modified_date desc, +> attached_info.id desc; +> +> When I fire this query in psql, it does not return back. +> +> - top command shows postgres above 95+% cpu usage consistantly +> PID USER PRI NI SIZE RSS SHARE STAT %CPU %MEM TIME COMMAND +> 1550 postgres 25 0 20268 19M 18904 R 95.3 5.2 6:31 postmaster +> +> - I am using RedHat 8 with following postgres rpms +> postgresql-libs-7.2.2-1 +> postgresql-7.2.2-1 +> postgresql-server-7.2.2-1 +> +> - RAM size is 384 MB, SWAP size is 384 MB, but top shows that memory is +free +> +> - I have done following changes after searching for performance realted +> information on the internet and postgres site +> - in /etc/rc.d/rc.local added following lines +> echo "32768" >/proc/sys/fs/file-max +> echo "98304" >/proc/sys/fs/inode-max +> - in /etc/init.d/postgresql file a pg_ctl call is changed to : +> su -l postgres -s /bin/sh -c "/usr/bin/pg_ctl -D +$PGDATA -o +> '-i -N 1024 -B 2048 -d 5' -p /usr/bin/postmaster start >> +> /var/log/pgsql.log 2>&1" < /dev/null +> +> - pgsql log shows : +> ...... +> }) :lefttree <> :righttree <> :extprm () :locprm () :initplan <> :nprm 0 +> :scanrelid 1 } :righttree <> :extprm () :locprm () :initplan <> :nprm 0 +> :keycount 3 } :righttree <> :extprm () :locprm () :initplan <> :nprm 0 +> :numCols 3 :uniqColIdx 3 1 2 } +> DEBUG: ProcessQuery +> ********* +> log stops here for 5/6 minuts +> ********* +> DEBUG: proc_exit(0) +> DEBUG: shmem_exit(0) +> DEBUG: exit(0) +> DEBUG: reaping dead processes +> DEBUG: child process (pid 1595) exited with exit code 0 +> DEBUG: proc_exit(0) +> DEBUG: shmem_exit(0) +> DEBUG: exit(0) +> DEBUG: reaping dead processes +> DEBUG: child process (pid 1598) exited with exit code 0 +> DEBUG: proc_exit(0) +> DEBUG: shmem_exit(0) +> DEBUG: exit(0) +> DEBUG: reaping dead processes +> DEBUG: child process (pid 1599) exited with exit code 0 +> DEBUG: proc_exit(0) +> DEBUG: shmem_exit(0) +> DEBUG: exit(0) +> DEBUG: reaping dead processes +> DEBUG: child process (pid 1600) exited with exit code 0 +> +> +> - What should I do to get such queries working? +> - Is there any limit on query size? +> - Is there anything left in tuning postgres which is causing this problem +? +> +> If you want me to try anything, please let me know. +> +> thanks +> Amol +> +> +> +> +> +> +> ---------------------------(end of broadcast)--------------------------- +> TIP 6: Have you searched our list archives? +> +> http://archives.postgresql.org +> + + +From pgsql-performance-owner@postgresql.org Thu May 15 06:39:54 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 3337F47665D + for ; + Thu, 15 May 2003 06:39:53 -0400 (EDT) +Received: from postgresql.org ([64.49.215.8]) + by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with + ESMTP id 75297-05 for ; + Thu, 15 May 2003 06:39:51 -0400 (EDT) +Received: from TactiCom-MA1.TactiCom.com (unknown [216.235.244.20]) + by postgresql.org (Postfix) with SMTP id 4223A47665A + for ; + Thu, 15 May 2003 06:39:51 -0400 (EDT) +Received: from [203.124.133.194] by TactiCom-MA1.Nulinkinc.com (NTMail + 4.30.0013/NU4135.00.d4f82e0c) with ESMTP id nsrbiaaa for + ; Thu, 15 May 2003 06:39:47 -0400 +content-class: urn:content-classes:message +MIME-Version: 1.0 +Content-Type: multipart/alternative; + boundary="----_=_NextPart_001_01C31ACE.4CB11F40" +Subject: FW: [ADMIN] Out of disk space- error code +X-MimeOLE: Produced By Microsoft Exchange V6.0.6249.0 +Date: Thu, 15 May 2003 16:09:44 +0530 +Message-ID: +X-MS-Has-Attach: +X-MS-TNEF-Correlator: +Thread-Topic: [ADMIN] Out of disk space- error code +Thread-Index: AcMUgyJIr8aJ6oB0EdedgABABabtaAGStoFQ +From: "Anagha Joshi" +To: +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/181 +X-Sequence-Number: 1960 + +This is a multi-part message in MIME format. + +------_=_NextPart_001_01C31ACE.4CB11F40 +Content-Type: text/plain; + charset="US-ASCII" +Content-Transfer-Encoding: quoted-printable + +=20 +=20 +-----Original Message----- +From: Anagha Joshi=20 +Sent: Wednesday, May 07, 2003 3:58 PM +To: pgsql-admin@postgresql.org +Subject: [ADMIN] Out of disk space- error code +=20 +Hi, +=20 +I'm using PostgreSQL 7.1.2 on Sun Solaries 8. +=20 +My Server was kept for overnight test and I observed that on my server +hostmachine I could not switch user (su) to 'postgres' to see the +postgres pid. It looked as if the postgres process was tied up some how. + +=20 +The server pids were available but postgress was not. This looked like a +potential database crash although there are no postgres core files or +logs that give clues as to what may have happned=20 +The zipped server logs display lots of error trying to locate the +postgres PID +=20 +The snapshot of the Postgres log is like this: +ERROR: cannot extend trap: No space left on device. + Check free disk space. +ERROR: cannot extend trap: No space left on device. + Check free disk space. +ERROR: cannot extend trap: No space left on device. + Check free disk space. +ERROR: cannot extend trap: No space left on device. +=20 +That was clear from the logs that disk is full. But is there anyway that +I can check this programatically? i.e. when I call 'PgDatabase::Exec()' +to execute query from C++ API, I get error code reflecting 'low on the +disk'? I know I can get corresponding error message in C++ from Postgres +by +'errorMessage()' method. I want specific error code for this. +=20 +Pls. help ASAP. +Thanks in advance, +=20 +Anagha Joshi +=20 +=20 + +------_=_NextPart_001_01C31ACE.4CB11F40 +Content-Type: text/html; + charset="US-ASCII" +Content-Transfer-Encoding: quoted-printable + + + + + + + + + + + + + + + + + + + + + + + +
+ +

 

+ +

 

+ +

-----Original Message-----
+From:
Anagha Joshi= +
+Sent:
Wednesday, May 07, 2003= + 3:58 PM
+To: pgsql-admin@postgresql.o= +rg
+Subject: [ADMIN] Out of disk +space- error code

+ +

 

+ +

Hi,

+ +

 

+ +
I=92m using PostgreSQL 7.1.2 on Sun Solaries 8.<=
+/o:p>
 <=
+/o:p>
My Server wa=
+s kept for overnight test and I observed that on my server hostmachine I could not switch user (su) t=
+o 'postgres' to see the postgres pid. It looked as if the postgres process =
+was tied up some how. 
<=
+font
+size=3D2 face=3D"Courier New"> <=
+/o:p>
The server p=
+ids were available but postgress was not. This looked like a potential data=
+base crash although there are no postgres core files or logs that give clue=
+s as to what may have happned 
=
+The zipped s=
+erver logs display lots of error trying to locate the postgres PID
 <=
+/o:p>
+ +

The snapshot of the Postgres log is like this:

+ +

ERROR:=A0 cannot= + extend +trap: No space left on device.

+ +

=A0=A0=A0=A0=A0=A0=A0=A0= +=A0=A0=A0 Check free +disk space.

+ +

ERROR:=A0 cannot= + extend +trap: No space left on device.

+ +

=A0=A0=A0=A0=A0=A0=A0=A0= +=A0=A0=A0 Check free +disk space.

+ +

ERROR:=A0 cannot= + extend +trap: No space left on device.

+ +

=A0=A0=A0=A0=A0=A0=A0=A0= +=A0=A0=A0 Check free +disk space.

+ +

ERROR:=A0 cannot= + extend +trap: No space left on device.

+ +
 
That was cle=
+ar from the logs that disk is full. But is there anyway that I can check th=
+is programatically? i.e. when I call =91PgDatabase::Exec()=92 to execute qu=
+ery from C++ API, I get error code reflecting =91low on the disk=92? I know=
+ I can get corresponding error message in C++ from Postgres by
=91errorMess=
+age()=92 method. I want specific error code for this.
 <=
+/o:p>
Pls. help AS=
+AP.
Thanks in ad=
+vance,
 <=
+/o:p>
Anagha J=
+oshi
 
+ +

 

+ +
+ + + + +=00 +------_=_NextPart_001_01C31ACE.4CB11F40-- + +From pgsql-performance-owner@postgresql.org Thu May 15 07:57:30 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 3475A47668A + for ; + Thu, 15 May 2003 07:57:29 -0400 (EDT) +Received: from postgresql.org ([64.49.215.8]) + by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with + ESMTP id 88323-09 for ; + Thu, 15 May 2003 07:57:27 -0400 (EDT) +Received: from mail.deltav.hu (mail.deltav.hu [213.163.0.192]) + by postgresql.org (Postfix) with ESMTP id 33E4B4766A1 + for ; + Thu, 15 May 2003 07:57:27 -0400 (EDT) +Received: from fejleszt2 ([213.163.10.103]) by mail.deltav.hu + (Netscape Messaging Server 3.6) with SMTP id AAA1A06 + for ; + Thu, 15 May 2003 13:56:11 +0200 +Message-ID: <00a401c31ad8$fa234760$0a03a8c0@fejleszt2> +From: =?iso-8859-1?Q?SZUCS_G=E1bor?= +To: +References: <003c01c31a96$1d1703d0$2e00a8c0@amol> +Subject: Re: nested select query failing +Date: Thu, 15 May 2003 13:56:10 +0200 +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit +X-Priority: 3 +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook Express 6.00.2800.1106 +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/182 +X-Sequence-Number: 1961 + +It's a rather nasty query format, but wrapped it to readable form. +Looks like you could make a good join from all these IN's. + +Another question: does EXPLAIN (without ANALYZE) work for this query? +Could you send its output, and table defs? maybe a minimal dump in private +email? + + +QUESTION TO PRO'S: + +Basically, is it true that IN's can be converted to RIGHT JOIN's quite +simply? Is it always worth? + +G. +-- +while (!asleep()) sheep++; + +---------------------------- cut here ------------------------------ +----- Original Message ----- +From: "amol" +Sent: Thursday, May 15, 2003 5:57 AM + + +> Hi everybody, +> I am new to this mailing list, so please let me know if I am not posting +> queries the way you are expecting. +> +> - We are porting a web based application from MSSQL to postgres as a +> backend. +> This is a database intensive application. I am facing a problem in some +> queries like this : +> +> select distinct +> attached_info.id, ownerid ,attached_info.modified_date +> from attached_info +> where +> attached_info.id in +> (select distinct attached_tag_list.id from attached_tag_list +> where +> attached_tag_list.id in +> (select attached_info.id from attached_info +> where attached_info.deleted='0') and +> attached_tag_list.id in +> (select id from attached_tag_list +> where attached_tag = 262) and +> attached_tag_list.attached_tag in +> (select tags.id from tags +> where +> tags.id in +> (select tag_id +> from tag_classifier, tag_classifier_association +> where +> classifier_tag_id in +> (261, 4467, 1894, 1045, 1087, 1355, 72, 1786, 1179, +> 3090, 871, 3571, 3565, 3569, 3567, 1043, 2535, 1080, +> 3315, 87, 1041, 2343, 2345, 1869, 3088, 3872, 2651, +> 2923, 2302, 1681, 3636, 3964, 2778, 2694, 1371, 2532, +> 2527, 3742, 3740, 1761, 4530, 4671, 4503, 4512, 3700) +> and +> association_id='1566' and +> tag_classifier.uid=tag_classifier_association.uid +> ) and +> tags.isdeleted='0' +> ) +> ) +> order by attached_info.modified_date desc, attached_info.id desc; + + +From pgsql-performance-owner@postgresql.org Thu May 15 08:38:22 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 9968E4766DE + for ; + Thu, 15 May 2003 08:38:21 -0400 (EDT) +Received: from postgresql.org ([64.49.215.8]) + by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with + ESMTP id 94375-08 for ; + Thu, 15 May 2003 08:38:19 -0400 (EDT) +Received: from mail.libertyrms.com (unknown [209.167.124.227]) + by postgresql.org (Postfix) with ESMTP id B5ADB4766E7 + for ; + Thu, 15 May 2003 08:38:19 -0400 (EDT) +Received: from [10.1.2.130] (helo=dba2) + by mail.libertyrms.com with esmtp (Exim 3.22 #3 (Debian)) + id 19GI07-0000ZD-00 + for ; Thu, 15 May 2003 08:38:23 -0400 +Received: by dba2 (Postfix, from userid 1019) + id F0F18D087; Thu, 15 May 2003 08:38:22 -0400 (EDT) +Date: Thu, 15 May 2003 08:38:22 -0400 +From: Andrew Sullivan +To: pgsql-performance@postgresql.org +Subject: Re: FW: [ADMIN] Out of disk space- error code +Message-ID: <20030515123822.GC23812@libertyrms.info> +Mail-Followup-To: Andrew Sullivan , + pgsql-performance@postgresql.org +References: +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: +User-Agent: Mutt/1.5.3i +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/183 +X-Sequence-Number: 1962 + +On Thu, May 15, 2003 at 04:09:44PM +0530, Anagha Joshi wrote: +> The snapshot of the Postgres log is like this: +> ERROR: cannot extend trap: No space left on device. +> Check free disk space. + +[. . .] + +> +> That was clear from the logs that disk is full. But is there anyway that +> I can check this programatically? i.e. when I call 'PgDatabase::Exec()' +> to execute query from C++ API, I get error code reflecting 'low on the +> disk'? I know I can get corresponding error message in C++ from Postgres +> by +> 'errorMessage()' method. I want specific error code for this. + +Postgres relies on your filesystem and OS. It doesn't know you're +low on disk until it gets the error from the OS. Use your OS to warn +you if you're going to run out of space. + +A + +-- +---- +Andrew Sullivan 204-4141 Yonge Street +Liberty RMS Toronto, Ontario Canada + M2P 2A8 + +1 416 646 3304 x110 + + +From pgsql-admin-owner@postgresql.org Thu May 15 09:22:54 2003 +X-Original-To: pgsql-admin@postgresql.org +Received: from localhost (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id A6E574766FE + for ; Thu, 15 May 2003 09:22:53 -0400 (EDT) +Received: from postgresql.org ([64.49.215.8]) + by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with + ESMTP id 06776-10 for ; + Thu, 15 May 2003 09:22:21 -0400 (EDT) +Received: from smtp2.arnet.com.ar (smtp2.arnet.com.ar [200.45.191.5]) + by postgresql.org (Postfix) with SMTP id 161524766E2 + for ; Thu, 15 May 2003 09:22:21 -0400 (EDT) +Received: (qmail 23230 invoked from network); 15 May 2003 13:14:14 -0000 +Received: from unknown (HELO 219) (200.45.224.75) + by smtp2.arnet.com.ar with SMTP; 15 May 2003 13:14:12 -0000 +Message-ID: <003f01c31ae4$b15a59e0$db00a8c0@219> +From: =?Windows-1252?Q?Sub_Director_-_Sistemas_Inform=E1ticos?= + +To: +Subject: nested query too expensive +Date: Thu, 15 May 2003 10:20:01 -0300 +MIME-Version: 1.0 +Content-Type: multipart/alternative; + boundary="----=_NextPart_000_003C_01C31ACB.8BA1B5E0" +X-Priority: 3 +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook Express 6.00.2720.3000 +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2727.1300 +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/207 +X-Sequence-Number: 8769 + +This is a multi-part message in MIME format. + +------=_NextPart_000_003C_01C31ACB.8BA1B5E0 +Content-Type: text/plain; + charset="Windows-1252" +Content-Transfer-Encoding: quoted-printable + +This a relatively simple nested query that we try to use, but it finish in = +a "seq scan" with a=20 +too high cost, so we had to use a little orthodox solution creating a tempo= +ral table into the=20 +terminal and scanning this table row's one by one making individual querys = +for each one. + +Any body knows how to make the query work in "index scan" mode ? +=20 +________________________________________________________ +=20 +explain select w.*,b.nombre from (select nro_insc,cod_estab,cuitempre,impue= +sto,sum(monto_impo) + as totret,sum(monto_rete) as suma_rete,tipodoc,documento from detadj where= + nro_insc=3D390009 + and cod_estab=3D0 and ano=3D2003 and mes=3D4 and per=3D2 and sec=3D0 group= + by nro_insc,cod_estab, + cuitempre,impuesto,tipodoc,documento) w LEFT OUTER JOIN retper b on (w.tip= +odoc=3Db.tipodoc=20 + and btrim(w.documento) like btrim(b.documento) and btrim(w.cuitempre) like= + btrim(b.cuitempre)=20 + and w.nro_insc=3Db.nro_insc and w.cod_estab=3Db.cod_estab)=20 +=20 +_______________________________________________ +=20 +TABLES STRUCTURE: +=20 + Table "retper" ( 180.000 rows ) + + Column | Type | Modifiers +-----------+---------------+----------- + tipodoc | integer | + documento | character(20) | + nombre | character(40) | + domicilio | character(40) | + puerta | integer | + localidad | character(15) | + provincia | character(15) | + ningbru | character(20) | + c_postal | character(8) | + cuitempre | character(20) | + nro_insc | integer | + cod_estab | integer | + graba | date | + hora | character(4) | + opera | integer | + puesto | integer | + crc | character(4) | +Indexes:=20 + cuitemp_btrim, + docu_btrim, + retper_cod_estab, + retper_cuitempre, + retper_documento, + retper_nombre, + retper_nro_insc, + retper_tipodoc +=20 +________________________________________________ + +Table "detadj" ( 18.500.000 rows ) + + Column | Type | Modifiers +------------+-----------------------+----------- + cuitempre | character varying(20) | + sec | numeric(10,0) | + per | numeric(10,0) | + mes | numeric(10,0) | + ano | numeric(10,0) | + nro_insc | numeric(10,0) | + cod_estab | numeric(10,0) | + nobli | character varying(20) | + cod_act | character varying(20) | + tipo_agen | character varying(1) | + monto_impo | double precision | + alicuota | double precision | + monto_rete | double precision | + tipodoc | numeric(10,0) | + documento | character varying(20) | + impuesto | numeric(10,0) | + tipo_dato | numeric(10,0) | + id | character varying(11) | + tipo_comp | numeric(10,0) | + letra | character varying(1) | + terminal | numeric(10,0) | + numero | character varying(20) | + fecha | date | + ningbru | character varying(20) | + graba | date | + hora | character varying(4) | + opera | numeric(10,0) | + puesto | numeric(10,0) | +Indexes:=20 + ano_detadj, + ano_mes_per, + cod_estab, + cuitempre, + cuitempre_btrim, + documento_btrim, + impue, + mes_detadj, + nro_insc_detadj, + per_detadj, + sec +=20 +________________________________________ +=20 +QUERY: +=20 +# explain select w.*,b.nombre from (select nro_insc,cod_estab,cuitempre,imp= +uesto,sum(monto_impo) as totret,sum(monto_rete) as suma_rete,tipodoc,docume= +nto from detadj where nro_insc=3D390009 and cod_estab=3D0 and ano=3D2003 an= +d mes=3D4 and per=3D2 and sec=3D0 group by nro_insc,cod_estab,cuitempre,imp= +uesto,tipodoc,documento) w LEFT OUTER JOIN retper b on (w.tipodoc=3Db.tipod= +oc and btrim(w.documento) like btrim(b.documento) and btrim(w.cuitempre) li= +ke btrim(b.cuitempre) ); + + +RESULTS: +=20 +NOTICE: QUERY PLAN: +=20 +Nested Loop (cost=3D4999.30..21256.26 rows=3D1 width=3D220) + -> Subquery Scan w (cost=3D4999.30..4999.34 rows=3D1 width=3D106) + -> Aggregate (cost=3D4999.30..4999.34 rows=3D1 width=3D106) + -> Group (cost=3D4999.30..4999.33 rows=3D2 width=3D106) + -> Sort (cost=3D4999.30..4999.30 rows=3D2 width=3D106) + -> Index Scan using ano_mes_per on detadj (cost= +=3D0.00..4999.29 rows=3D2 width=3D106) +-> Seq Scan on retper b (cost=3D0.00..9821.23 rows=3D214523 width=3D96) +=20 +________________________________________ +=20 +E. Caillava + +------=_NextPart_000_003C_01C31ACB.8BA1B5E0 +Content-Type: text/html; + charset="Windows-1252" +Content-Transfer-Encoding: quoted-printable + + + + + + + + +
This a relatively simple nested query that= + we try=20 +to use, but it finish in a "seq scan" with a
too high cost, so we had t= +o use=20 +a little orthodox solution creating a temporal table into the
terminal = +and=20 +scanning this table row's one by one making individual querys for each= +=20 +one.
+
 
+
Any body knows how to make the query&= +nbsp;work=20 +in "index scan" mode=20 +?
 
________________________________________________________
= + 
explain=20 +select w.*,b.nombre from (select=20 +nro_insc,cod_estab,cuitempre,impuesto,sum(monto_impo)
 as=20 +totret,sum(monto_rete) as suma_rete,tipodoc,documento from detadj where=20 +nro_insc=3D390009
 and cod_estab=3D0 and ano=3D2003 and mes=3D4 and= + per=3D2 and=20 +sec=3D0 group by=20 +nro_insc,cod_estab,
 cuitempre,impuesto,tipodoc,documento) w LEFT O= +UTER=20 +JOIN retper b on (w.tipodoc=3Db.tipodoc
 and btrim(w.documento) li= +ke=20 +btrim(b.documento) and btrim(w.cuitempre) like btrim(b.cuitempre)
 = +;and=20 +w.nro_insc=3Db.nro_insc and w.cod_estab=3Db.cod_estab)=20 +
 
_______________________________________________
 
= +TABLES=20 +STRUCTURE:
 
 Table "retper"  ( 180.000 rows )
<= +/DIV> +
 
+
  Column   |  &nb= +sp; =20 +Type      |=20 +Modifiers
-----------+---------------+-----------
 tipodoc = + =20 +| integer       |
 documento |=20 +character(20) |
 nombre    | character(40)=20 +|
 domicilio | character(40) |
 puerta    |= +=20 +integer       |
 localidad | characte= +r(15)=20 +|
 provincia | character(15) |
 ningbru   |=20 +character(20) |
 c_postal  | character(8) =20 +|
 cuitempre | character(20) |
 nro_insc  |=20 +integer       |
 cod_estab |=20 +integer      =20 +|
 graba     |=20 +date         =20 +|
 hora      | character(4) =20 +|
 opera     |=20 +integer       |
 puesto  &n= +bsp;=20 +| integer      =20 +|
 crc       | character(4) =20 +|
Indexes:
+
       = + =20 +cuitemp_btrim,
        =20 +docu_btrim,
        =20 +retper_cod_estab,
        =20 +retper_cuitempre,
        =20 +retper_documento,
        =20 +retper_nombre,
        =20 +retper_nro_insc,
        =20 +retper_tipodoc
 
________________________________________________
+
 
+
Table "detadj"  ( 18.500.000 rows )
+
 
+
   Column  =20 +|        =20 +Type          |=20 +Modifiers
------------+-----------------------+-----------
 cuit= +empre =20 +| character varying(20) |
 sec      &= +nbsp;=20 +| numeric(10,0)        =20 +|
 per        |=20 +numeric(10,0)        =20 +|
 mes        |=20 +numeric(10,0)        =20 +|
 ano        |=20 +numeric(10,0)        =20 +|
 nro_insc   |=20 +numeric(10,0)        =20 +|
 cod_estab  |=20 +numeric(10,0)        =20 +|
 nobli      | character varying(20)=20 +|
 cod_act    | character varying(20)=20 +|
 tipo_agen  | character varying(1)  |
 monto_im= +po |=20 +double precision      |
 alicuota &nb= +sp; |=20 +double precision      |
 monto_rete | doub= +le=20 +precision      |
 tipodoc   = +; |=20 +numeric(10,0)        =20 +|
 documento  | character varying(20)=20 +|
 impuesto   |=20 +numeric(10,0)        =20 +|
 tipo_dato  |=20 +numeric(10,0)        =20 +|
 id         | character= +=20 +varying(11) |
 tipo_comp  |=20 +numeric(10,0)        =20 +|
 letra      | character varying(1) = +=20 +|
 terminal   |=20 +numeric(10,0)        =20 +|
 numero     | character varying(20)=20 +|
 fecha      |=20 +date            = +;     =20 +|
 ningbru    | character varying(20)=20 +|
 graba      |=20 +date            = +;     =20 +|
 hora       | character varying(4)&= +nbsp;=20 +|
 opera      |=20 +numeric(10,0)        =20 +|
 puesto     |=20 +numeric(10,0)         |
Indexes:= +=20 +
+
       = + =20 +ano_detadj,
        =20 +ano_mes_per,
        =20 +cod_estab,
        =20 +cuitempre,
        =20 +cuitempre_btrim,
        =20 +documento_btrim,
        =20 +impue,
        =20 +mes_detadj,
        =20 +nro_insc_detadj,
        =20 +per_detadj,
        =20 +sec
 
+
________________________________________
 
QUERY:
 
# exp= +lain=20 +select w.*,b.nombre from (select=20 +nro_insc,cod_estab,cuitempre,impuesto,sum(monto_impo) as totret,sum(monto_r= +ete)=20 +as suma_rete,tipodoc,documento from detadj where nro_insc=3D390009 and cod_= +estab=3D0=20 +and ano=3D2003 and mes=3D4 and per=3D2 and sec=3D0 group by=20 +nro_insc,cod_estab,cuitempre,impuesto,tipodoc,documento) w LEFT OUTER JOIN= +=20 +retper b on (w.tipodoc=3Db.tipodoc and btrim(w.documento) like btrim(b.docu= +mento)=20 +and btrim(w.cuitempre) like btrim(b.cuitempre) );
+
 
+

RESULTS:
 
NOTICE:  QU= +ERY=20 +PLAN:
 
Nested Loop  (cost=3D4999.30..21256.26 rows=3D1=20 +width=3D220)
  ->  Subquery Scan w  (cost=3D4999.30..4= +999.34=20 +rows=3D1 width=3D106)
        ->&n= +bsp;=20 +Aggregate  (cost=3D4999.30..4999.34 rows=3D1=20 +width=3D106)
          = +;   =20 +->  Group  (cost=3D4999.30..4999.33 rows=3D2=20 +width=3D106)
          = +;         =20 +->  Sort  (cost=3D4999.30..4999.30 rows=3D2=20 +width=3D106)
          = +;            &n= +bsp;  =20 +->  Index Scan using ano_mes_per on detadj  (cost=3D0.00..4999= +.29=20 +rows=3D2 width=3D106)
->  Seq Scan on retper b  (cost=3D0.0= +0..9821.23=20 +rows=3D214523=20 +width=3D96)
 
________________________________________
 = +
E.=20 +Caillava
+ +------=_NextPart_000_003C_01C31ACB.8BA1B5E0-- + + +From pgsql-performance-owner@postgresql.org Thu May 15 10:57:26 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 92BBD476721 + for ; + Thu, 15 May 2003 10:57:24 -0400 (EDT) +Received: from postgresql.org ([64.49.215.8]) + by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with + ESMTP id 21753-08 for ; + Thu, 15 May 2003 10:56:52 -0400 (EDT) +Received: from megazone.bigpanda.com (megazone.bigpanda.com [63.150.15.178]) + by postgresql.org (Postfix) with ESMTP id 361B747671E + for ; + Thu, 15 May 2003 10:56:45 -0400 (EDT) +Received: by megazone.bigpanda.com (Postfix, from userid 1001) + id DAAFBD618; Thu, 15 May 2003 07:56:49 -0700 (PDT) +Received: from localhost (localhost [127.0.0.1]) + by megazone.bigpanda.com (Postfix) with ESMTP + id C43725C04; Thu, 15 May 2003 07:56:49 -0700 (PDT) +Date: Thu, 15 May 2003 07:56:49 -0700 (PDT) +From: Stephan Szabo +To: =?iso-8859-1?Q?SZUCS_G=E1bor?= +Cc: +Subject: Re: nested select query failing +In-Reply-To: <00a401c31ad8$fa234760$0a03a8c0@fejleszt2> +Message-ID: <20030515075032.B60859-100000@megazone23.bigpanda.com> +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=X-UNKNOWN +Content-Transfer-Encoding: QUOTED-PRINTABLE +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/184 +X-Sequence-Number: 1963 + +On Thu, 15 May 2003, [iso-8859-1] SZUCS G=E1bor wrote: + +> Basically, is it true that IN's can be converted to RIGHT JOIN's quite +> simply? Is it always worth? + +I'm not sure you want to convert to an outer join (since you want to throw +away the rows on either side that don't match in an IN). You also have to +be careful not to get duplicate entries from what was the subquery. + +As for whether it's worth doing, in 7.3 and earlier, almost +certainly, in 7.4 almost certainly not. :) + + + + +From pgsql-performance-owner@postgresql.org Thu May 15 11:09:23 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 3A514476711 + for ; + Thu, 15 May 2003 11:09:19 -0400 (EDT) +Received: from postgresql.org ([64.49.215.8]) + by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with + ESMTP id 22806-10 for ; + Thu, 15 May 2003 11:08:48 -0400 (EDT) +Received: from megazone.bigpanda.com (megazone.bigpanda.com [63.150.15.178]) + by postgresql.org (Postfix) with ESMTP id E9F3D476546 + for ; + Thu, 15 May 2003 11:08:47 -0400 (EDT) +Received: by megazone.bigpanda.com (Postfix, from userid 1001) + id 8BE73D622; Thu, 15 May 2003 08:08:52 -0700 (PDT) +Received: from localhost (localhost [127.0.0.1]) + by megazone.bigpanda.com (Postfix) with ESMTP + id 81A245C04; Thu, 15 May 2003 08:08:52 -0700 (PDT) +Date: Thu, 15 May 2003 08:08:52 -0700 (PDT) +From: Stephan Szabo +To: =?Windows-1252?Q?Sub_Director_-_Sistemas_Inform=E1ticos?= + +Cc: +Subject: Re: [ADMIN] nested query too expensive +In-Reply-To: <003f01c31ae4$b15a59e0$db00a8c0@219> +Message-ID: <20030515080135.M60859-100000@megazone23.bigpanda.com> +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=X-UNKNOWN +Content-Transfer-Encoding: QUOTED-PRINTABLE +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/185 +X-Sequence-Number: 1964 + + +[Moving to -performance, since it's more on topic there] + +On Thu, 15 May 2003, [Windows-1252] Sub Director - Sistemas Inform=E1ticos = +wrote: + +> This a relatively simple nested query that we try to use, but it finish i= +n a "seq scan" with a +> too high cost, so we had to use a little orthodox solution creating a tem= +poral table into the +> terminal and scanning this table row's one by one making individual query= +s for each one. +> +> Any body knows how to make the query work in "index scan" mode ? + +> explain select w.*,b.nombre from (select nro_insc,cod_estab,cuitempre,imp= +uesto,sum(monto_impo) +> as totret,sum(monto_rete) as suma_rete,tipodoc,documento from detadj whe= +re nro_insc=3D390009 +> and cod_estab=3D0 and ano=3D2003 and mes=3D4 and per=3D2 and sec=3D0 gro= +up by nro_insc,cod_estab, +> cuitempre,impuesto,tipodoc,documento) w LEFT OUTER JOIN retper b on (w.t= +ipodoc=3Db.tipodoc +> and btrim(w.documento) like btrim(b.documento) and btrim(w.cuitempre) li= +ke btrim(b.cuitempre) +> and w.nro_insc=3Db.nro_insc and w.cod_estab=3Db.cod_estab) + +If you're doing a condition on a bunch of columns, you might want a +multi-column index, since postgres is only going to use one of the +indexes below I believe and it may not be considered selective enough +on just one of those conditions. And you're doing cross datatype +comparisons, which is likely to screw it up as well (why is tipodoc an +integer in one and a numeric in the other for example?) I'd also say you +might want to consider upgrading to 7.3.x since the explain format looks +like that from 7.2 or earlier. Also explain analyze output would tell us +what is actually taking the time and could be useful as well. + + +> Indexes: +> cuitemp_btrim, +> docu_btrim, +> retper_cod_estab, +> retper_cuitempre, +> retper_documento, +> retper_nombre, +> retper_nro_insc, +> retper_tipodoc +> +> ________________________________________________ +> +> Table "detadj" ( 18.500.000 rows ) +> +> Column | Type | Modifiers +> ------------+-----------------------+----------- +> cuitempre | character varying(20) | +> sec | numeric(10,0) | +> per | numeric(10,0) | +> mes | numeric(10,0) | +> ano | numeric(10,0) | +> nro_insc | numeric(10,0) | +> cod_estab | numeric(10,0) | +> nobli | character varying(20) | +> cod_act | character varying(20) | +> tipo_agen | character varying(1) | +> monto_impo | double precision | +> alicuota | double precision | +> monto_rete | double precision | +> tipodoc | numeric(10,0) | +> documento | character varying(20) | +> impuesto | numeric(10,0) | +> tipo_dato | numeric(10,0) | +> id | character varying(11) | +> tipo_comp | numeric(10,0) | +> letra | character varying(1) | +> terminal | numeric(10,0) | +> numero | character varying(20) | +> fecha | date | +> ningbru | character varying(20) | +> graba | date | +> hora | character varying(4) | +> opera | numeric(10,0) | +> puesto | numeric(10,0) | +> Indexes: +> ano_detadj, +> ano_mes_per, +> cod_estab, +> cuitempre, +> cuitempre_btrim, +> documento_btrim, +> impue, +> mes_detadj, +> nro_insc_detadj, +> per_detadj, +> sec + + +From pgsql-general-owner@postgresql.org Fri May 16 16:27:49 2003 +X-Original-To: pgsql-general@postgresql.org +Received: from localhost (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id F3BB6476D11 + for ; + Fri, 16 May 2003 16:27:46 -0400 (EDT) +Received: from postgresql.org ([64.49.215.8]) + by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with + ESMTP id 53413-08 for ; + Fri, 16 May 2003 16:27:45 -0400 (EDT) +Received: from mail.gmx.net (mail.gmx.net [213.165.65.60]) + by postgresql.org (Postfix) with SMTP id DBECE476D01 + for ; + Fri, 16 May 2003 16:27:44 -0400 (EDT) +Received: (qmail 14917 invoked by uid 65534); 16 May 2003 20:27:45 -0000 +Received: from pD9E6D095.dip.t-dialin.net (EHLO gmx.de) (217.230.208.149) + by mail.gmx.net (mp011-rz3) with SMTP; 16 May 2003 22:27:45 +0200 +Message-ID: <3EC549BE.5040403@gmx.de> +Date: Fri, 16 May 2003 22:27:42 +0200 +From: "alex b." +User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3) Gecko/20030312 +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: Postgresql General +Subject: Re: realtime data inserts +References: + <6754.1052582402@sss.pgh.pa.us> <1052591490.26574.161.camel@haggis> + <10704.1052621185@sss.pgh.pa.us> <1052672090.995.13.camel@haggis> + +In-Reply-To: +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/627 +X-Sequence-Number: 42282 + +Doug McNaught wrote: +> Ron Johnson writes: +> +> +>>On Sat, 2003-05-10 at 21:46, Tom Lane wrote: +>> +>>>Ron Johnson writes: +>>> +>>>>On Sat, 2003-05-10 at 11:00, Tom Lane wrote: +>>>> +>>>>>Have you thought about using COPY? +>>> +>>>>Generate a temporary file, and then system("COPY /tmp/foobar ...") ? +>>> +>>>No, copy from stdin. No need for a temp file. +>> +>>But wouldn't that only work if the input stream is acceptable to +>>COPY ? +> +> +> Yes, but you could always pipe it through a script or C program to +> make it so... + +lets say I have an about 1kb/s continuus datastream comming in for many +hours and I'd like to store this data in my db using COPY table FROM stdin. + +At what time should I COMMIT or close the stream to feed the database +and COPY FROM again? + + + + +From pgsql-general-owner@postgresql.org Fri May 16 16:33:57 2003 +X-Original-To: pgsql-general@postgresql.org +Received: from localhost (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 9EBFE476BCA + for ; + Fri, 16 May 2003 16:33:52 -0400 (EDT) +Received: from postgresql.org ([64.49.215.8]) + by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with + ESMTP id 55913-03 for ; + Fri, 16 May 2003 16:33:47 -0400 (EDT) +Received: from pop.e-it.com (pop.e-it.com [216.187.113.81]) + by postgresql.org (Postfix) with SMTP id 66581476967 + for ; + Fri, 16 May 2003 16:33:47 -0400 (EDT) +Received: (qmail 2578 invoked from network); 16 May 2003 20:33:47 -0000 +Received: from unknown (HELO ?151.191.181.108?) (216.187.113.13) + by 0 with SMTP; 16 May 2003 20:33:47 -0000 +Subject: Re: realtime data inserts +From: Ericson Smith +To: "alex b." +Cc: Postgresql General +In-Reply-To: <3EC549BE.5040403@gmx.de> +References: <6754.1052582402@sss.pgh.pa.us> + <1052591490.26574.161.camel@haggis> <10704.1052621185@sss.pgh.pa.us> + <1052672090.995.13.camel@haggis> + <3EC549BE.5040403@gmx.de> +Content-Type: text/plain +Organization: +Message-Id: <1053117234.15138.23.camel@localhost.localdomain> +Mime-Version: 1.0 +X-Mailer: Ximian Evolution 1.2.2 +Date: 16 May 2003 16:33:55 -0400 +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/628 +X-Sequence-Number: 42283 + +You probably want to have a process that constantly stores the data in a +text file. Every "n" minutes, you will cause the logger to rotate the +text file, then process that batch. + +Over here, we are able to dump around 5,000 records per second in one of +our tables using that methodology. + +- Ericson Smith +eric@did-it.com + +On Fri, 2003-05-16 at 16:27, alex b. wrote: +> Doug McNaught wrote: +> > Ron Johnson writes: +> > +> > +> >>On Sat, 2003-05-10 at 21:46, Tom Lane wrote: +> >> +> >>>Ron Johnson writes: +> >>> +> >>>>On Sat, 2003-05-10 at 11:00, Tom Lane wrote: +> >>>> +> >>>>>Have you thought about using COPY? +> >>> +> >>>>Generate a temporary file, and then system("COPY /tmp/foobar ...") ? +> >>> +> >>>No, copy from stdin. No need for a temp file. +> >> +> >>But wouldn't that only work if the input stream is acceptable to +> >>COPY ? +> > +> > +> > Yes, but you could always pipe it through a script or C program to +> > make it so... +> +> lets say I have an about 1kb/s continuus datastream comming in for many +> hours and I'd like to store this data in my db using COPY table FROM stdin. +> +> At what time should I COMMIT or close the stream to feed the database +> and COPY FROM again? +> +> +> +> +> ---------------------------(end of broadcast)--------------------------- +> TIP 5: Have you checked our extensive FAQ? +> +> http://www.postgresql.org/docs/faqs/FAQ.html +-- +Ericson Smith + + +From pgsql-general-owner@postgresql.org Fri May 16 18:29:09 2003 +X-Original-To: pgsql-general@postgresql.org +Received: from localhost (postgresql.org [64.49.215.8]) + by postgresql.org (Postfix) with ESMTP id 788B5476903 + for ; + Fri, 16 May 2003 18:29:07 -0400 (EDT) +Received: from postgresql.org ([64.49.215.8]) + by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with + ESMTP id 70216-05 for ; + Fri, 16 May 2003 18:29:05 -0400 (EDT) +Received: from lakemtao01.cox.net (lakemtao01.cox.net [68.1.17.244]) + by postgresql.org (Postfix) with ESMTP id B9D7147689E + for ; + Fri, 16 May 2003 18:29:05 -0400 (EDT) +Received: from [192.168.1.1] ([68.11.66.83]) by lakemtao01.cox.net + (InterMail vM.5.01.04.05 201-253-122-122-105-20011231) with ESMTP + id <20030516222908.UFC8337.lakemtao01.cox.net@[192.168.1.1]> + for ; Fri, 16 May 2003 18:29:08 -0400 +Subject: Re: realtime data inserts +From: Ron Johnson +To: Postgresql General +In-Reply-To: <1053117234.15138.23.camel@localhost.localdomain> +References: <6754.1052582402@sss.pgh.pa.us> + <1052591490.26574.161.camel@haggis> <10704.1052621185@sss.pgh.pa.us> + <1052672090.995.13.camel@haggis> + <3EC549BE.5040403@gmx.de> + <1053117234.15138.23.camel@localhost.localdomain> +Content-Type: text/plain +Organization: +Message-Id: <1053124145.11845.17.camel@haggis> +Mime-Version: 1.0 +X-Mailer: Ximian Evolution 1.2.4 +Date: 16 May 2003 17:29:05 -0500 +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/631 +X-Sequence-Number: 42286 + +On Fri, 2003-05-16 at 15:33, Ericson Smith wrote: +> You probably want to have a process that constantly stores the data in a +> text file. Every "n" minutes, you will cause the logger to rotate the +> text file, then process that batch. + +Does the logger spawn the DB writer? + +> Over here, we are able to dump around 5,000 records per second in one of +> our tables using that methodology. +> +> - Ericson Smith +> eric@did-it.com +> +> On Fri, 2003-05-16 at 16:27, alex b. wrote: +> > Doug McNaught wrote: +> > > Ron Johnson writes: +> > > +> > > +> > >>On Sat, 2003-05-10 at 21:46, Tom Lane wrote: +> > >> +> > >>>Ron Johnson writes: +> > >>> +> > >>>>On Sat, 2003-05-10 at 11:00, Tom Lane wrote: +> > >>>> +> > >>>>>Have you thought about using COPY? +> > >>> +> > >>>>Generate a temporary file, and then system("COPY /tmp/foobar ...") ? +> > >>> +> > >>>No, copy from stdin. No need for a temp file. +> > >> +> > >>But wouldn't that only work if the input stream is acceptable to +> > >>COPY ? +> > > +> > > +> > > Yes, but you could always pipe it through a script or C program to +> > > make it so... +> > +> > lets say I have an about 1kb/s continuus datastream comming in for many +> > hours and I'd like to store this data in my db using COPY table FROM stdin. +> > +> > At what time should I COMMIT or close the stream to feed the database +> > and COPY FROM again? +> > +> > +> > +> > +> > ---------------------------(end of broadcast)--------------------------- +> > TIP 5: Have you checked our extensive FAQ? +> > +> > http://www.postgresql.org/docs/faqs/FAQ.html +-- ++---------------------------------------------------------------+ +| Ron Johnson, Jr. mailto:ron.l.johnson@cox.net | +| Jefferson, LA USA http://members.cox.net/ron.l.johnson | +| | +| The purpose of the military isn't to pay your college tuition | +| or give you a little extra income; it's to "kill people and | +| break things". Surprisingly, not everyone understands that. | ++---------------------------------------------------------------+ + + +From pgsql-performance-owner@postgresql.org Mon May 19 18:12:44 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (unknown [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id DE2A5925986 + for ; + Mon, 19 May 2003 18:12:40 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 35800-05 for ; + Mon, 19 May 2003 18:12:37 -0400 (EDT) +Received: from ll.mit.edu (LLMAIL.LL.MIT.EDU [129.55.12.40]) + by developer.postgresql.org (Postfix) with ESMTP id 833EF9259A2 + for ; + Mon, 19 May 2003 13:28:50 -0400 (EDT) +Received: (from smtp@localhost) by ll.mit.edu (8.12.9/8.8.8) id h4JHScAm002525 + for ; + Mon, 19 May 2003 13:28:38 -0400 (EDT) +Received: from sty.llan.ll.mit.edu( ), claiming to be "sty.llan" + via SMTP by llpost, id smtpdAAAqYaWYe; Mon May 19 13:28:32 2003 +Date: Mon, 19 May 2003 13:28:32 -0400 +From: george young +To: pgsql-performance@postgresql.org +Subject: postgres on a beowulf? (AMD)opteron? +Message-Id: <20030519132832.6733dd56.gry@ll.mit.edu> +Reply-To: gry@ll.mit.edu +Organization: MIT Lincoln Laboratory +X-Mailer: Sylpheed version 0.9.0 (GTK+ 1.2.10; i686-pc-linux-gnu) +Mime-Version: 1.0 +Content-Type: text/plain; charset=US-ASCII +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/186 +X-Sequence-Number: 1965 + +Has anyone run postgres on a beowulf system? + +I'm shopping for a new server. One candidate would be a +quad opteron (64-bit AMD "hammer") machine. Another approach might +be a beowulf of single or dual opterons. I imagine the beowulf +would be a bit cheaper, and much more expandable, but what about +the shared memory used by the postgres backends? I gather that +postgres uses shared memory to coordinate (locks?) between backends? + +I have a smallish DB (pgdump|bzip2 -> 10MB), with ~45 users logged in +using local X(python/gtk) postgres client apps. + +Will the much slower shared memory access between beowulf nodes be +a performance bottleneck? + +[Next question is: has anyone used postgres on an opteron at all??] + +-- George +-- + I cannot think why the whole bed of the ocean is + not one solid mass of oysters, so prolific they seem. Ah, + I am wandering! Strange how the brain controls the brain! + -- Sherlock Holmes in "The Dying Detective" + +From pgsql-performance-owner@postgresql.org Fri May 23 10:38:55 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 4CA86925676 + for ; + Fri, 23 May 2003 10:38:50 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 12335-04 for ; + Fri, 23 May 2003 10:38:36 -0400 (EDT) +Received: from www.pspl.co.in (www.pspl.co.in [202.54.11.65]) + by developer.postgresql.org (Postfix) with ESMTP id 6FE6A92584C + for ; + Fri, 23 May 2003 09:55:26 -0400 (EDT) +Received: (from root@localhost) + by www.pspl.co.in (8.11.6/8.11.6) id h4NDtPs21017 + for ; Fri, 23 May 2003 19:25:25 +0530 +Received: from daithan.intranet.pspl.co.in (daithan.intranet.pspl.co.in + [192.168.7.161]) + by www.pspl.co.in (8.11.6/8.11.0) with ESMTP id h4NDtN221012 + for ; Fri, 23 May 2003 19:25:24 +0530 +From: Shridhar Daithankar +To: pgsql-performance@postgresql.org +Subject: Re: postgres on a beowulf? (AMD)opteron? +Date: Tue, 20 May 2003 12:14:03 +0530 +User-Agent: KMail/1.5.1 +References: <20030519132832.6733dd56.gry@ll.mit.edu> +In-Reply-To: <20030519132832.6733dd56.gry@ll.mit.edu> +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit +Content-Disposition: inline +Message-Id: <200305201214.03432.shridhar_daithankar@nospam.persistent.co.in> +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/221 +X-Sequence-Number: 2000 + +On Monday 19 May 2003 22:58, george young wrote: +> Has anyone run postgres on a beowulf system? +> +> I'm shopping for a new server. One candidate would be a +> quad opteron (64-bit AMD "hammer") machine. Another approach might +> be a beowulf of single or dual opterons. I imagine the beowulf +> would be a bit cheaper, and much more expandable, but what about +> the shared memory used by the postgres backends? I gather that +> postgres uses shared memory to coordinate (locks?) between backends? + +Postgresql will not run on beowulf at all since it is an MPI system and +postgresql can no span a single database across machines (yet). Further it +won't even run on mosix because mosix does not support shared memory across +machines. + +> +> I have a smallish DB (pgdump|bzip2 -> 10MB), with ~45 users logged in +> using local X(python/gtk) postgres client apps. + +Well, you haven't put how many transactions you do, but in general for that +sort of DB, a P-IV/512MB RAM and SCSI disk would be more than enough unless +you are doing really exotic things with data.. + +> [Next question is: has anyone used postgres on an opteron at all??] + +Well, if it runs linux as good as anything else, postgresql will run as good +as anything else..:-) + +HTH + + Shridhar + +From pgsql-performance-owner@postgresql.org Tue May 20 06:05:51 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (unknown [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id BC2A7924C87 + for ; + Tue, 20 May 2003 05:57:57 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 53409-02 for ; + Tue, 20 May 2003 05:57:50 -0400 (EDT) +Received: from mithi.com (unknown [219.65.91.97]) + by developer.postgresql.org (Postfix) with SMTP id 89297924C89 + for ; + Tue, 20 May 2003 05:57:00 -0400 (EDT) +Received: (qmail 9907 invoked by uid 0); 20 May 2003 07:07:58 -0000 +Received: from unknown (HELO amol) (192.168.0.46) + by 0 with SMTP; 20 May 2003 07:07:58 -0000 +Message-ID: <00a101c31ea1$19e03d80$2e00a8c0@amol> +From: "amol" +To: +References: <20030515075032.B60859-100000@megazone23.bigpanda.com> +Subject: Re: nested select query failing +Date: Tue, 20 May 2003 12:56:16 +0530 +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 8bit +X-Priority: 3 +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook Express 5.00.2919.6700 +X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6700 +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/188 +X-Sequence-Number: 1967 + +thanks allot everybody for your mails, + +- It helped and now I have got down the query execution time allot. But I am +facing problem in following query +----------- +explain analyze select attached_info.id from attached_tag_list, +attached_info +where + attached_tag_list.attached_tag = 265 + and + attached_tag_list.id = attached_info.id +---------- + +- it's result is +---------- +NOTICE: QUERY PLAN: + +Nested Loop (cost=0.00..165349.50 rows=114 width=16) (actual +time=117.14..8994.60 rows=15 loops=1) + -> Index Scan using ix_attached_tag_list_id on attached_tag_list +(cost=0.00..111.13 rows=96 width=12) (actual time=0.12..0.66 rows=15 +loops=1) + -> Seq Scan on attached_info (cost=0.00..1211.53 rows=33553 width=4) +(actual time=3.67..197.98 rows=33553 loops=15) +Total runtime: 8994.92 msec + +EXPLAIN +--------- + +- I have already indexed attached_info on id using following query +------ +CREATE INDEX attached_info_Index_1 ON attached_info(id) ; +------ + +- But I am wondering why there is "->Seq Scan on attached_info." + After reading various documentation on the internet I am assuming it +should have been an index scan. BTW I have done vaccume analyze also. + +Am I right? + +thanks, +Amol + + + +----- Original Message ----- +From: "Stephan Szabo" +To: "SZUCS G�bor" +Cc: +Sent: Thursday, May 15, 2003 8:26 PM +Subject: Re: [PERFORM] nested select query failing + + +On Thu, 15 May 2003, [iso-8859-1] SZUCS G�bor wrote: + +> Basically, is it true that IN's can be converted to RIGHT JOIN's quite +> simply? Is it always worth? + +I'm not sure you want to convert to an outer join (since you want to throw +away the rows on either side that don't match in an IN). You also have to +be careful not to get duplicate entries from what was the subquery. + +As for whether it's worth doing, in 7.3 and earlier, almost +certainly, in 7.4 almost certainly not. :) + + + + +---------------------------(end of broadcast)--------------------------- +TIP 4: Don't 'kill -9' the postmaster + + + + +From pgsql-performance-owner@postgresql.org Tue May 20 05:26:24 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (unknown [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 1516B923230 + for ; + Tue, 20 May 2003 05:26:21 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 37750-10 for ; + Tue, 20 May 2003 05:26:14 -0400 (EDT) +Received: from fuji.krosing.net (sein.itera.ee [194.126.109.126]) + by developer.postgresql.org (Postfix) with ESMTP id 19A889232C6 + for ; + Tue, 20 May 2003 05:15:33 -0400 (EDT) +Received: from fuji.krosing.net (lo [127.0.0.1]) + by fuji.krosing.net (8.12.8/8.12.8) with ESMTP id h4K9FLlQ001759 + for ; Tue, 20 May 2003 12:15:21 +0300 +Received: (from hannu@localhost) + by fuji.krosing.net (8.12.8/8.12.8/Submit) id h4K8TYUn001517; + Tue, 20 May 2003 11:29:34 +0300 +X-Authentication-Warning: fuji.krosing.net: hannu set sender to hannu@tm.ee + using -f +Subject: Re: postgres on a beowulf? (AMD)opteron? +From: Hannu Krosing +To: gry@ll.mit.edu +Cc: pgsql-performance@postgresql.org +In-Reply-To: <20030519132832.6733dd56.gry@ll.mit.edu> +References: <20030519132832.6733dd56.gry@ll.mit.edu> +Content-Type: text/plain +Content-Transfer-Encoding: 7bit +Organization: +Message-Id: <1053419374.1435.4.camel@fuji.krosing.net> +Mime-Version: 1.0 +X-Mailer: Ximian Evolution 1.2.4 +Date: 20 May 2003 11:29:34 +0300 +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/187 +X-Sequence-Number: 1966 + +george young kirjutas E, 19.05.2003 kell 20:28: +> Has anyone run postgres on a beowulf system? + +I don't think that postgresql will easyly port to beowulf clusters. + +> I'm shopping for a new server. One candidate would be a +> quad opteron (64-bit AMD "hammer") machine. Another approach might +> be a beowulf of single or dual opterons. I imagine the beowulf +> would be a bit cheaper, and much more expandable, but what about +> the shared memory used by the postgres backends? I gather that +> postgres uses shared memory to coordinate (locks?) between backends? +> +> I have a smallish DB (pgdump|bzip2 -> 10MB), with ~45 users logged in +> using local X(python/gtk) postgres client apps. + +Why do you want such a monster machine for this smallish DB ? + +Are there any special performance requirements you are not telling us +about ? + +> Will the much slower shared memory access between beowulf nodes be +> a performance bottleneck? + +I guess that it will not run at all ;( + +-------------- +Hannu + + +From pgsql-performance-owner@postgresql.org Tue May 20 07:28:07 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (unknown [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 2F53E924F12 + for ; + Tue, 20 May 2003 07:28:04 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 94684-09 for ; + Tue, 20 May 2003 07:27:41 -0400 (EDT) +Received: from mail.libertyrms.com (unknown [209.167.124.227]) + by developer.postgresql.org (Postfix) with ESMTP id F0F09924EED + for ; + Tue, 20 May 2003 07:27:39 -0400 (EDT) +Received: from [10.1.2.130] (helo=dba2) + by mail.libertyrms.com with esmtp (Exim 3.22 #3 (Debian)) + id 19I5HQ-0003gn-00 + for ; Tue, 20 May 2003 07:27:40 -0400 +Received: by dba2 (Postfix, from userid 1019) + id EE2E9D087; Tue, 20 May 2003 07:27:39 -0400 (EDT) +Date: Tue, 20 May 2003 07:27:39 -0400 +From: Andrew Sullivan +To: pgsql-performance@postgresql.org +Subject: Re: postgres on a beowulf? (AMD)opteron? +Message-ID: <20030520112739.GB11943@libertyrms.info> +Mail-Followup-To: Andrew Sullivan , + pgsql-performance@postgresql.org +References: <20030519132832.6733dd56.gry@ll.mit.edu> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: <20030519132832.6733dd56.gry@ll.mit.edu> +User-Agent: Mutt/1.5.3i +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/189 +X-Sequence-Number: 1968 + +On Mon, May 19, 2003 at 01:28:32PM -0400, george young wrote: +> Has anyone run postgres on a beowulf system? + +Can't be done. None of the cluster systems support cross-machne +shared memory (this is actually a problem for Postgres and NUMA, as +well, BTW). + +> I have a smallish DB (pgdump|bzip2 -> 10MB), with ~45 users logged in +> using local X(python/gtk) postgres client apps. + +Seems like you want a sledgehammer to kill a fly here. That's tiny. +Why do you want the complications of a cluster for this? + +A + +-- +---- +Andrew Sullivan 204-4141 Yonge Street +Liberty RMS Toronto, Ontario Canada + M2P 2A8 + +1 416 646 3304 x110 + + +From pgsql-performance-owner@postgresql.org Tue May 20 08:28:49 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (unknown [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 135AA924ECA + for ; + Tue, 20 May 2003 08:28:47 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 11894-03 for ; + Tue, 20 May 2003 08:28:43 -0400 (EDT) +Received: from gate.solvo.ru (gate.solvo.ru [195.201.44.1]) + by developer.postgresql.org (Postfix) with ESMTP id 6EBB0924E23 + for ; + Tue, 20 May 2003 08:28:42 -0400 (EDT) +Received: from grace.solvo.ru (grace.solvo.ru [195.201.44.100]) + by gate.solvo.ru (8.8.8/8.8.8) with ESMTP id QAA07402 + for ; Tue, 20 May 2003 16:28:38 +0400 +Received: from grace.solvo.ru (localhost [127.0.0.1]) + by grace.solvo.ru (8.12.8/8.12.8) with ESMTP id h4KCScpD028664 + for ; Tue, 20 May 2003 16:28:38 +0400 +Received: (from elf@localhost) + by grace.solvo.ru (8.12.8/8.12.8/Submit) id h4KCScJx028662 + for pgsql-performance@postgresql.org; Tue, 20 May 2003 16:28:38 +0400 +Date: Tue, 20 May 2003 16:28:38 +0400 +From: Eugene Fokin +To: pgsql-performance@postgresql.org +Subject: 7.3.2 vs 7.1.2 +Message-ID: <20030520122838.GA28654@solvo.ru> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +User-Agent: Mutt/1.4i +X-Operating-System: Linux 2.4.19-1pe i686 +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/190 +X-Sequence-Number: 1969 + +Hello. +I'm just going to upgrade from 7.1.2 to 7.3.2 and found that some +of my queries performing on 7.3.2 much slower than on 7.1.2. +For example, pretty complex query that takes 3-4 seconds on 7.1.2 +now takes about 1 minute on 7.3.2. +EXPLAIN shows the pretty same total query cost (49000 on 7.1.2 vs +56000 vs 7.3.2, but 7.1.2 didn't calculate some subqueries). +What I did: make the dump from 7.1.2, load dump into 7.3.2, +tune postgresql.conf parameters like in 7.1.2, vacuum analyze. +Why is it take so long ? +P.S. Of course, I can show the query. +-- +Eugene Fokin +SOLVO Ltd. Company + +From pgsql-performance-owner@postgresql.org Tue May 20 09:09:04 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (unknown [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id DC475924F68 + for ; + Tue, 20 May 2003 09:09:01 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 40397-02 for ; + Tue, 20 May 2003 09:08:58 -0400 (EDT) +Received: from tomts21-srv.bellnexxia.net (tomts21.bellnexxia.net + [209.226.175.183]) + by developer.postgresql.org (Postfix) with ESMTP id 6A1BA924F67 + for ; + Tue, 20 May 2003 09:08:57 -0400 (EDT) +Received: from [10.0.2.7] ([216.208.117.7]) by tomts21-srv.bellnexxia.net + (InterMail vM.5.01.05.32 201-253-122-126-132-20030307) with ESMTP + id <20030520130855.BGPM2574.tomts21-srv.bellnexxia.net@[10.0.2.7]>; + Tue, 20 May 2003 09:08:55 -0400 +Subject: Re: 7.3.2 vs 7.1.2 +From: Rod Taylor +To: Eugene Fokin +Cc: Postgresql Performance +In-Reply-To: <20030520122838.GA28654@solvo.ru> +References: <20030520122838.GA28654@solvo.ru> +Content-Type: multipart/signed; micalg=pgp-sha1; + protocol="application/pgp-signature"; + boundary="=-ll38YrWA8b2aqyQIhAcC" +Organization: +Message-Id: <1053436138.21079.1.camel@jester> +Mime-Version: 1.0 +X-Mailer: Ximian Evolution 1.2.4 +Date: 20 May 2003 09:08:59 -0400 +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/192 +X-Sequence-Number: 1971 + +--=-ll38YrWA8b2aqyQIhAcC +Content-Type: text/plain +Content-Transfer-Encoding: quoted-printable + +On Tue, 2003-05-20 at 08:28, Eugene Fokin wrote: +> Hello. +> I'm just going to upgrade from 7.1.2 to 7.3.2 and found that some +> of my queries performing on 7.3.2 much slower than on 7.1.2. + +This generally indicates misconfiguration of some kind or required +tweaking. + +> P.S. Of course, I can show the query. + +Please show EXPLAIN ANALYZE output along with the query. +--=20 +Rod Taylor + +PGP Key: http://www.rbt.ca/rbtpub.asc + +--=-ll38YrWA8b2aqyQIhAcC +Content-Type: application/pgp-signature; name=signature.asc +Content-Description: This is a digitally signed message part + +-----BEGIN PGP SIGNATURE----- +Version: GnuPG v1.2.2 (FreeBSD) + +iD8DBQA+yijq6DETLow6vwwRAtVZAJ94phAj19PKfQr3yAmgzCpr3MWDagCeLUt6 +EI0CxGAOGIUH0ZQ2knrrYsc= +=jxvg +-----END PGP SIGNATURE----- + +--=-ll38YrWA8b2aqyQIhAcC-- + + +From pgsql-performance-owner@postgresql.org Tue May 20 09:06:37 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (unknown [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 66E46924F65 + for ; + Tue, 20 May 2003 09:06:36 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 40154-04 for ; + Tue, 20 May 2003 09:06:23 -0400 (EDT) +Received: from shield.nordlb.lv (shield.pirmabanka.lv [195.114.57.4]) + by developer.postgresql.org (Postfix) with ESMTP id 53020924F68 + for ; + Tue, 20 May 2003 09:06:22 -0400 (EDT) +Received: from wall2.pirmabanka.lv (wall2-pub.nordlb.lv [195.114.57.14]) + by shield.nordlb.lv (8.12.9/8.12.9) with SMTP id h4KD6Kbg022465 + for ; Tue, 20 May 2003 16:06:20 +0300 +Received: from share.nordlb.lv ([10.0.0.10]) by wall2.pirmabanka.lv; + Tue, 20 May 2003 16:06:18 +0300 (EET DST) +Received: from pc311x1.nordlb.lv (localhost.localdomain [127.0.0.1]) + by nordlb.lv (8.11.6/8.11.6) with SMTP id h4KD6Ib10470 + for ; Tue, 20 May 2003 16:06:18 +0300 +Received: (qmail 4070 invoked by uid 100); 20 May 2003 13:09:13 -0000 +Date: Tue, 20 May 2003 16:09:13 +0300 +From: "Victor Yegorov" +To: Eugene Fokin +Cc: pgsql-performance@postgresql.org +Subject: Re: 7.3.2 vs 7.1.2 +Message-ID: <20030520130913.GM1976@nordlb.lv> +References: <20030520122838.GA28654@solvo.ru> +Mime-Version: 1.0 +Content-Type: text/plain; charset=koi8-r +Content-Disposition: inline +In-Reply-To: <20030520122838.GA28654@solvo.ru> +User-Agent: Mutt/1.4.1i +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/191 +X-Sequence-Number: 1970 + +* Eugene Fokin [20.05.2003 15:52]: +> Why is it take so long ? +> P.S. Of course, I can show the query. + +Please, attach both: query and explain analyze results. +Results of: + +=> select version(); + +are welcomed too. + +-- + +Victor Yegorov + +From pgsql-performance-owner@postgresql.org Tue May 20 09:28:59 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (unknown [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 8B5E4924E30 + for ; + Tue, 20 May 2003 09:28:58 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 43492-10 for ; + Tue, 20 May 2003 09:28:54 -0400 (EDT) +Received: from gate.solvo.ru (gate.solvo.ru [195.201.44.1]) + by developer.postgresql.org (Postfix) with ESMTP id 143E0924CA9 + for ; + Tue, 20 May 2003 09:28:52 -0400 (EDT) +Received: from grace.solvo.ru (grace.solvo.ru [195.201.44.100]) + by gate.solvo.ru (8.8.8/8.8.8) with ESMTP id RAA08256; + Tue, 20 May 2003 17:28:43 +0400 +Received: from grace.solvo.ru (localhost [127.0.0.1]) + by grace.solvo.ru (8.12.8/8.12.8) with ESMTP id h4KDShpD029388; + Tue, 20 May 2003 17:28:43 +0400 +Received: (from elf@localhost) + by grace.solvo.ru (8.12.8/8.12.8/Submit) id h4KDSgNu029386; + Tue, 20 May 2003 17:28:42 +0400 +Date: Tue, 20 May 2003 17:28:42 +0400 +From: Eugene Fokin +To: Victor Yegorov +Cc: pgsql-performance@postgresql.org +Subject: Re: 7.3.2 vs 7.1.2 +Message-ID: <20030520132842.GA29262@solvo.ru> +References: <20030520122838.GA28654@solvo.ru> + <20030520130913.GM1976@nordlb.lv> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +Content-Transfer-Encoding: quoted-printable +In-Reply-To: <20030520130913.GM1976@nordlb.lv> +User-Agent: Mutt/1.4i +X-Operating-System: Linux 2.4.19-1pe i686 +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/193 +X-Sequence-Number: 1972 + +On Tue, May 20, 2003 at 04:09:13PM +0300, Victor Yegorov wrote: +=20 +> Please, attach both: query and explain analyze results. +> Results of: +>=20 +> =3D> select version(); +>=20 +> are welcomed too. + +Ok. +btw, it works on 7.2.1 fine to me too (as 7.1.2). + +\d loadview: + + View "public.loadview" + Column | Type | Modifiers=20 +-------------------+--------------------------+----------- + id | integer |=20 + parent_load_id | integer |=20 + name | character varying(10) |=20 + code_id | integer |=20 + rcn_id | integer |=20 + loc_id | integer |=20 + real_loc_id | integer |=20 + dest_id | integer |=20 + order_id | integer |=20 + last_comment | character varying |=20 + label | character varying(20) |=20 + type | character varying(1) |=20 + qty | integer |=20 + qty_type | character varying(1) |=20 + units | integer |=20 + assigned | integer |=20 + visible | boolean |=20 + status | character varying(1) |=20 + sort | integer |=20 + dest_status | character varying(1) |=20 + date_pour | date |=20 + akciz_name | text |=20 + is_ub | boolean |=20 + is_toll | boolean |=20 + has_receiving | boolean |=20 + has_ub | boolean |=20 + has_custom | boolean |=20 + has_akciz | boolean |=20 + owner_id | integer |=20 + receive_type | character varying(1) |=20 + region_units | integer |=20 + msk_units | integer |=20 + town_units | integer |=20 + date_last_counted | timestamp with time zone |=20 + counted_by | character varying(32) |=20 + date_last_access | timestamp with time zone |=20 + accessed_by | character varying(32) |=20 + created | timestamp with time zone |=20 + created_by | character varying(32) |=20 + sku_name | character varying |=20 + real_loc | integer |=20 + loc_type | character varying |=20 +View definition: SELECT l.id, l.parent_load_id, l.name, l.code_id, l.rcn_id= +, l.loc_id, l.real_loc_id, l.dest_id, CASE WHEN (EXISTS (SELECT orders.id F= +ROM orders WHERE (orders.id =3D l.order_id))) THEN l.order_id ELSE 0 END AS= + order_id, (SELECT lc."comment" FROM load_comments lc WHERE (lc.id =3D l.la= +st_comment_id)) AS last_comment, l.label, l."type", l.qty, l.qty_type, l.un= +its, l.assigned, l.visible, l.status, l.sort, l.dest_status, r.date_pour, a= +d.name AS akciz_name, l.is_ub, l.is_toll, l.has_receiving, l.has_ub, l.has_= +custom, l.has_akciz, l.owner_id, l.receive_type, l.region_units, l.msk_unit= +s, l.town_units, l.date_last_counted, l.counted_by, l.date_last_access, l.a= +ccessed_by, l.created, l.created_by, (SELECT s.name FROM sku s, code_info c= + WHERE ((s.id =3D c.sku_id) AND (c.id =3D l.code_id))) AS sku_name, l.real_= +loc_id AS real_loc, (SELECT loc."type" FROM "location" loc WHERE (loc.id = +=3D l.real_loc_id)) AS loc_type FROM (((loads l JOIN (SELECT rcn_details.id= +, rcn_details.date_pour FROM rcn_details) r ON ((r.id =3D l.rcn_id))) LEFT = +JOIN (SELECT min(akciz.id) AS id, akciz.rcn_id FROM akciz GROUP BY akciz.rc= +n_id) ah ON ((ah.rcn_id =3D l.rcn_id))) LEFT JOIN (SELECT max((akciz_detail= +s.name)::text) AS name, akciz_details.akciz_id FROM akciz_details GROUP BY = +akciz_details.akciz_id) ad ON ((ad.akciz_id =3D ah.id))); + +7.2.1: +select version (): + "PostgreSQL 7.2.1 on i686-pc-linux-gnu, compiled by GCC 2.96" + +explain analyze select count(*) from loadview: + +NOTICE: QUERY PLAN: + +Aggregate (cost=3D49464.29..49464.29 rows=3D1 width=3D20) (actual time=3D4= +823.05..4823.05 rows=3D1 loops=3D1) + -> Merge Join (cost=3D36149.36..47306.99 rows=3D862919 width=3D20) (act= +ual time=3D4081.67..4699.48 rows=3D147281 loops=3D1) + -> Sort (cost=3D35013.94..35013.94 rows=3D147281 width=3D16) (act= +ual time=3D3851.65..3919.07 rows=3D147281 loops=3D1) + -> Merge Join (cost=3D1098.11..22371.18 rows=3D147281 width= +=3D16) (actual time=3D196.80..3001.89 rows=3D147281 loops=3D1) + -> Merge Join (cost=3D0.00..19885.60 rows=3D147281 wi= +dth=3D8) (actual time=3D0.08..2059.89 rows=3D147281 loops=3D1) + -> Index Scan using load_rcn_id_idx on loads l = +(cost=3D0.00..17026.36 rows=3D147281 width=3D4) (actual time=3D0.04..786.13= + rows=3D147281 loops=3D1) + -> Index Scan using rcn_detail_idx on rcn_detail= +s (cost=3D0.00..618.30 rows=3D12692 width=3D4) (actual time=3D0.03..510.13= + rows=3D151332 loops=3D1) + -> Sort (cost=3D1098.11..1098.11 rows=3D1161 width=3D= +8) (actual time=3D196.68..273.26 rows=3D140535 loops=3D1) + -> Subquery Scan ah (cost=3D980.95..1039.00 row= +s=3D1161 width=3D8) (actual time=3D73.79..167.89 rows=3D11497 loops=3D1) + -> Aggregate (cost=3D980.95..1039.00 rows= +=3D1161 width=3D8) (actual time=3D73.78..145.90 rows=3D11497 loops=3D1) + -> Group (cost=3D980.95..1009.98 ro= +ws=3D11610 width=3D8) (actual time=3D73.76..115.53 rows=3D11610 loops=3D1) + -> Sort (cost=3D980.95..980.9= +5 rows=3D11610 width=3D8) (actual time=3D73.75..78.99 rows=3D11610 loops=3D= +1) + -> Seq Scan on akciz (c= +ost=3D0.00..197.10 rows=3D11610 width=3D8) (actual time=3D0.01..26.24 rows= +=3D11610 loops=3D1) + -> Sort (cost=3D1135.43..1135.43 rows=3D1172 width=3D15) (actual = +time=3D229.97..308.41 rows=3D140648 loops=3D1) + -> Subquery Scan ad (cost=3D1017.11..1075.70 rows=3D1172 wi= +dth=3D15) (actual time=3D94.52..200.64 rows=3D11610 loops=3D1) + -> Aggregate (cost=3D1017.11..1075.70 rows=3D1172 wid= +th=3D15) (actual time=3D94.51..179.57 rows=3D11610 loops=3D1) + -> Group (cost=3D1017.11..1046.40 rows=3D11718 = +width=3D15) (actual time=3D94.49..135.00 rows=3D11718 loops=3D1) + -> Sort (cost=3D1017.11..1017.11 rows=3D1= +1718 width=3D15) (actual time=3D94.47..101.80 rows=3D11718 loops=3D1) + -> Seq Scan on akciz_details (cost= +=3D0.00..225.18 rows=3D11718 width=3D15) (actual time=3D0.03..30.11 rows=3D= +11718 loops=3D1) +Total runtime: 4878.56 msec + +7.3.2: +select version(): + "PostgreSQL 7.3.2 on i386-redhat-linux-gnu, compiled by GCC i386-red= +hat-linux-gcc (GCC) 3.2.2 20030213 (Red Hat Linux 8.0 3.2.2-1)" + + Also, I've tried 7.3.2 version binaries from PostgreSQL site for RH7= +3. + And I've got the same result. + +explain analyze select count(*) from loadview: + + = + QUERY PLAN=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= +=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= +=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= +=20=20=20=20=20=20=20=20=20=20=20=20=20 +---------------------------------------------------------------------------= +---------------------------------------------------------------------------= +------------------------ + Aggregate (cost=3D57642.48..57642.48 rows=3D1 width=3D233) (actual time= +=3D43799.03..43799.03 rows=3D1 loops=3D1) + -> Subquery Scan loadview (cost=3D43956.42..55485.18 rows=3D862919 wid= +th=3D233) (actual time=3D28013.35..43638.75 rows=3D147281 loops=3D1) + -> Merge Join (cost=3D43956.42..55485.18 rows=3D862919 width=3D2= +33) (actual time=3D28013.35..43409.03 rows=3D147281 loops=3D1) + Merge Cond: ("outer".id =3D "inner".akciz_id) + -> Sort (cost=3D42797.70..43165.90 rows=3D147281 width=3D1= +97) (actual time=3D27785.80..28126.86 rows=3D147281 loops=3D1) + Sort Key: ah.id + -> Merge Join (cost=3D1115.13..22038.07 rows=3D14728= +1 width=3D197) (actual time=3D133.98..14205.66 rows=3D147281 loops=3D1) + Merge Cond: ("outer".rcn_id =3D "inner".rcn_id) + -> Merge Join (cost=3D0.00..19524.78 rows=3D14= +7281 width=3D189) (actual time=3D0.14..9419.68 rows=3D147281 loops=3D1) + Merge Cond: ("outer".rcn_id =3D "inner".id) + -> Index Scan using load_rcn_id_idx on lo= +ads l (cost=3D0.00..16659.18 rows=3D147281 width=3D181) (actual time=3D0.0= +7..4486.76 rows=3D147281 loops=3D1) + -> Index Scan using rcn_detail_idx on rcn= +_details (cost=3D0.00..624.96 rows=3D12692 width=3D8) (actual time=3D0.02.= +.587.84 rows=3D151332 loops=3D1) + -> Sort (cost=3D1115.13..1118.03 rows=3D1161 w= +idth=3D8) (actual time=3D133.74..214.17 rows=3D140535 loops=3D1) + Sort Key: ah.rcn_id + -> Subquery Scan ah (cost=3D968.95..1056= +.03 rows=3D1161 width=3D8) (actual time=3D46.03..115.21 rows=3D11497 loops= +=3D1) + -> Aggregate (cost=3D968.95..1056.= +03 rows=3D1161 width=3D8) (actual time=3D46.02..100.01 rows=3D11497 loops= +=3D1) + -> Group (cost=3D968.95..102= +7.00 rows=3D11610 width=3D8) (actual time=3D46.00..76.80 rows=3D11610 loops= +=3D1) + -> Sort (cost=3D968.95= +..997.98 rows=3D11610 width=3D8) (actual time=3D45.99..50.45 rows=3D11610 l= +oops=3D1) + Sort Key: rcn_id + -> Seq Scan on ak= +ciz (cost=3D0.00..185.10 rows=3D11610 width=3D8) (actual time=3D0.01..19.0= +9 rows=3D11610 loops=3D1) + -> Sort (cost=3D1158.72..1161.65 rows=3D1172 width=3D15) (= +actual time=3D227.16..332.79 rows=3D140648 loops=3D1) + Sort Key: ad.akciz_id + -> Subquery Scan ad (cost=3D1011.11..1098.99 rows=3D= +1172 width=3D15) (actual time=3D80.77..188.32 rows=3D11610 loops=3D1) + -> Aggregate (cost=3D1011.11..1098.99 rows=3D1= +172 width=3D15) (actual time=3D80.76..158.60 rows=3D11610 loops=3D1) + -> Group (cost=3D1011.11..1069.70 rows= +=3D11718 width=3D15) (actual time=3D80.73..124.73 rows=3D11718 loops=3D1) + -> Sort (cost=3D1011.11..1040.40 r= +ows=3D11718 width=3D15) (actual time=3D80.71..88.88 rows=3D11718 loops=3D1) + Sort Key: akciz_id + -> Seq Scan on akciz_details = + (cost=3D0.00..219.18 rows=3D11718 width=3D15) (actual time=3D0.03..28.57 r= +ows=3D11718 loops=3D1) + SubPlan + -> Index Scan using orders_id_idx on orders (cost=3D0.00= +..5.92 rows=3D1 width=3D4) (actual time=3D0.01..0.01 rows=3D1 loops=3D14728= +1) + Index Cond: (id =3D $0) + -> Index Scan using load_comments_id_idx on load_comments= + lc (cost=3D0.00..5.90 rows=3D1 width=3D10) (actual time=3D0.01..0.01 rows= +=3D0 loops=3D147281) + Index Cond: (id =3D $1) + -> Nested Loop (cost=3D0.00..11.08 rows=3D1 width=3D59) = +(actual time=3D0.02..0.03 rows=3D1 loops=3D147281) + -> Index Scan using code_id_idx on code_info c (co= +st=3D0.00..5.07 rows=3D1 width=3D4) (actual time=3D0.01..0.01 rows=3D1 loop= +s=3D147281) + Index Cond: (id =3D $2) + -> Index Scan using sku_id_idx on sku s (cost=3D0.= +00..6.00 rows=3D1 width=3D55) (actual time=3D0.01..0.01 rows=3D1 loops=3D14= +7281) + Index Cond: (s.id =3D "outer".sku_id) + -> Index Scan using loc_g_id_idx on "location" loc (cost= +=3D0.00..5.98 rows=3D1 width=3D5) (actual time=3D0.01..0.01 rows=3D1 loops= +=3D147281) + Index Cond: (id =3D $3) + Total runtime: 43825.44 msec +(41 rows) + +--=20 +Eugene Fokin +SOLVO Ltd. Company + +From pgsql-performance-owner@postgresql.org Tue May 20 10:04:32 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (unknown [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 1AF1A924F3C + for ; + Tue, 20 May 2003 10:04:32 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 61900-03 for ; + Tue, 20 May 2003 10:04:25 -0400 (EDT) +Received: from shield.nordlb.lv (shield.pirmabanka.lv [195.114.57.4]) + by developer.postgresql.org (Postfix) with ESMTP id C92C0924F44 + for ; + Tue, 20 May 2003 10:04:22 -0400 (EDT) +Received: from wall2.pirmabanka.lv (wall2-pub.nordlb.lv [195.114.57.14]) + by shield.nordlb.lv (8.12.9/8.12.9) with SMTP id h4KE4Kbg023360 + for ; Tue, 20 May 2003 17:04:20 +0300 +Received: from share.nordlb.lv ([10.0.0.10]) by wall2.pirmabanka.lv; + Tue, 20 May 2003 17:04:19 +0300 (EET DST) +Received: from pc311x1.nordlb.lv (localhost.localdomain [127.0.0.1]) + by nordlb.lv (8.11.6/8.11.6) with SMTP id h4KE4HN18112 + for ; Tue, 20 May 2003 17:04:19 +0300 +Received: (qmail 4269 invoked by uid 100); 20 May 2003 14:07:13 -0000 +Date: Tue, 20 May 2003 17:07:13 +0300 +From: Victor Yegorov +To: Eugene Fokin +Cc: pgsql-performance@postgresql.org +Subject: Re: 7.3.2 vs 7.1.2 +Message-ID: <20030520140713.GN1976@nordlb.lv> +References: <20030520122838.GA28654@solvo.ru> + <20030520130913.GM1976@nordlb.lv> + <20030520132842.GA29262@solvo.ru> +Mime-Version: 1.0 +Content-Type: text/plain; charset=koi8-r +Content-Disposition: inline +In-Reply-To: <20030520132842.GA29262@solvo.ru> +User-Agent: Mutt/1.4.1i +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/194 +X-Sequence-Number: 1973 + +* Eugene Fokin [20.05.2003 16:33]: +> 7.2.1: +> -> Merge Join (cost=0.00..19885.60 rows=147281 width=8) (actual time=0.08..2059.89 rows=147281 loops=1) +> -> Index Scan using load_rcn_id_idx on loads l (cost=0.00..17026.36 rows=147281 width=4) (actual time=0.04..786.13 rows=147281 loops=1) +> -> Index Scan using rcn_detail_idx on rcn_details (cost=0.00..618.30 rows=12692 width=4) (actual time=0.03..510.13 rows=151332 loops=1) + +snip + +> 7.3.2: +> -> Merge Join (cost=0.00..19524.78 rows=147281 width=189) (actual time=0.14..9419.68 rows=147281 loops=1) +> Merge Cond: ("outer".rcn_id = "inner".id) +> -> Index Scan using load_rcn_id_idx on loads l (cost=0.00..16659.18 rows=147281 width=181) (actual time=0.07..4486.76 rows=147281 loops=1) +> -> Index Scan using rcn_detail_idx on rcn_details (cost=0.00..624.96 rows=12692 width=8) (actual time=0.02..587.84 rows=151332 loops=1) + +As you can see, in 7.2.1 index scan on loads (load_rcn_id_idx) takes 0.04..786.13, +but in 7.3.2 - 0.07..4486.76. + +Also, note the difference in the: + +7.2.1 "... rows=147281 width=4) ..." +7.3.2 "... rows=147281 width=181) ..." + +My guesses: + +1. Check your index. +2. Do vacuum analyze again. +3. This part: +(loads l JOIN (SELECT rcn_details.id, rcn_details.date_pour FROM rcn_details) r ON ((r.id = l.rcn_id))) + +Why do you use subselect here? It seems to me, that you can simply join +whole table, can't you? + +May be somebody else will point to some other details. +Good luck! + +-- + +Victor Yegorov + +From pgsql-performance-owner@postgresql.org Tue May 20 11:18:37 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (unknown [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 43AA2924FEA + for ; + Tue, 20 May 2003 11:18:36 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 84718-01 for ; + Tue, 20 May 2003 11:18:33 -0400 (EDT) +Received: from sss.pgh.pa.us (unknown [192.204.191.242]) + by developer.postgresql.org (Postfix) with ESMTP id 67C1B924FF8 + for ; + Tue, 20 May 2003 11:18:32 -0400 (EDT) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h4KFIRU6029059; + Tue, 20 May 2003 11:18:28 -0400 (EDT) +To: "amol" +Cc: pgsql-performance@postgresql.org +Subject: Re: nested select query failing +In-reply-to: <00a101c31ea1$19e03d80$2e00a8c0@amol> +References: <20030515075032.B60859-100000@megazone23.bigpanda.com> + <00a101c31ea1$19e03d80$2e00a8c0@amol> +Comments: In-reply-to "amol" + message dated "Tue, 20 May 2003 12:56:16 +0530" +Date: Tue, 20 May 2003 11:18:26 -0400 +Message-ID: <29058.1053443906@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/195 +X-Sequence-Number: 1974 + +"amol" writes: +> explain analyze select attached_info.id from attached_tag_list, +> attached_info +> where +> attached_tag_list.attached_tag = 265 +> and +> attached_tag_list.id = attached_info.id + +> NOTICE: QUERY PLAN: + +> Nested Loop (cost=0.00..165349.50 rows=114 width=16) (actual +> time=117.14..8994.60 rows=15 loops=1) +> -> Index Scan using ix_attached_tag_list_id on attached_tag_list +> (cost=0.00..111.13 rows=96 width=12) (actual time=0.12..0.66 rows=15 +> loops=1) +> -> Seq Scan on attached_info (cost=0.00..1211.53 rows=33553 width=4) +> (actual time=3.67..197.98 rows=33553 loops=15) +> Total runtime: 8994.92 msec + +> - I have already indexed attached_info on id using following query +> CREATE INDEX attached_info_Index_1 ON attached_info(id) ; + +Hm. I'd have expected an index scan too. Maybe the two id columns are +not of the same datatype? + + regards, tom lane + +From pgsql-performance-owner@postgresql.org Tue May 20 11:34:10 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (unknown [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 5B8C3925015 + for ; + Tue, 20 May 2003 11:34:07 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 89372-07 for ; + Tue, 20 May 2003 11:34:02 -0400 (EDT) +Received: from gate.solvo.ru (gate.solvo.ru [195.201.44.1]) + by developer.postgresql.org (Postfix) with ESMTP id CA9D0925016 + for ; + Tue, 20 May 2003 11:34:00 -0400 (EDT) +Received: from grace.solvo.ru (grace.solvo.ru [195.201.44.100]) + by gate.solvo.ru (8.8.8/8.8.8) with ESMTP id TAA09303; + Tue, 20 May 2003 19:33:49 +0400 +Received: from grace.solvo.ru (localhost [127.0.0.1]) + by grace.solvo.ru (8.12.8/8.12.8) with ESMTP id h4KFXnpD030585; + Tue, 20 May 2003 19:33:49 +0400 +Received: (from elf@localhost) + by grace.solvo.ru (8.12.8/8.12.8/Submit) id h4KFXnto030583; + Tue, 20 May 2003 19:33:49 +0400 +Date: Tue, 20 May 2003 19:33:48 +0400 +From: Eugene Fokin +To: Victor Yegorov +Cc: pgsql-performance@postgresql.org +Subject: Re: 7.3.2 vs 7.1.2 +Message-ID: <20030520153348.GA30541@solvo.ru> +References: <20030520122838.GA28654@solvo.ru> + <20030520130913.GM1976@nordlb.lv> + <20030520132842.GA29262@solvo.ru> <20030520140713.GN1976@nordlb.lv> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: <20030520140713.GN1976@nordlb.lv> +User-Agent: Mutt/1.4i +X-Operating-System: Linux 2.4.19-1pe i686 +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/196 +X-Sequence-Number: 1975 + +On Tue, May 20, 2003 at 05:07:13PM +0300, Victor Yegorov wrote: +> +> As you can see, in 7.2.1 index scan on loads (load_rcn_id_idx) takes 0.04..786.13, +> but in 7.3.2 - 0.07..4486.76. +> +> Also, note the difference in the: +> +> 7.2.1 "... rows=147281 width=4) ..." +> 7.3.2 "... rows=147281 width=181) ..." +> +> My guesses: +> +> 1. Check your index. +> 2. Do vacuum analyze again. +> 3. This part: +> (loads l JOIN (SELECT rcn_details.id, rcn_details.date_pour FROM rcn_details) r ON ((r.id = l.rcn_id))) +> + +I've tried to simplify it, nothing happens -- the same effect ! +The question is -- why it scans my indexes so long ? +I've created "clean" experiment: the same machine, the same dump. +And perform the same procedure for each DB (btw, now it's 7.2.4 vs 7.3.1 :-)): + +1. Install DB. +2. Init DB. +3. Fix postgresql.conf +4. Load dump. +5. vacuum analyze. +6. query ! + +Difference is the same like 5 seconds vs 50 seconds... + +-- +Eugene Fokin +SOLVO Ltd. Company + +From pgsql-performance-owner@postgresql.org Tue May 20 11:49:54 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (unknown [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id E396892504E + for ; + Tue, 20 May 2003 11:49:53 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 94241-02 for ; + Tue, 20 May 2003 11:49:46 -0400 (EDT) +Received: from mail1.ihs.com (mail1.ihs.com [170.207.70.222]) + by developer.postgresql.org (Postfix) with ESMTP id 4DF05925047 + for ; + Tue, 20 May 2003 11:49:46 -0400 (EDT) +Received: from css120.ihs.com (css120.ihs.com [170.207.105.120]) + by mail1.ihs.com (8.12.9/8.12.9) with ESMTP id h4KFmeMv006870; + Tue, 20 May 2003 09:48:40 -0600 (MDT) +Date: Tue, 20 May 2003 09:37:03 -0600 (MDT) +From: "scott.marlowe" +To: george young +Cc: +Subject: Re: postgres on a beowulf? (AMD)opteron? +In-Reply-To: <20030519132832.6733dd56.gry@ll.mit.edu> +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-MailScanner: Found to be clean +X-MailScanner-SpamCheck: +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/197 +X-Sequence-Number: 1976 + +On Mon, 19 May 2003, george young wrote: + +> Has anyone run postgres on a beowulf system? +> +> I'm shopping for a new server. One candidate would be a +> quad opteron (64-bit AMD "hammer") machine. Another approach might +> be a beowulf of single or dual opterons. I imagine the beowulf +> would be a bit cheaper, and much more expandable, but what about +> the shared memory used by the postgres backends? I gather that +> postgres uses shared memory to coordinate (locks?) between backends? +> +> I have a smallish DB (pgdump|bzip2 -> 10MB), with ~45 users logged in +> using local X(python/gtk) postgres client apps. +> +> Will the much slower shared memory access between beowulf nodes be +> a performance bottleneck? + +Save yourself some money on the big boxes and get a fast drive subsystem +and lots of memory, those are more important than raw horsepower, and any +dual Opteron / Itanium2 / USparc III / PPC / Xeon machine has plenty of +CPU ponies to handle the load. + +We use dual PIII's for most of our serving, and while our front end web +servers need to grow a bit to handle all the PHP we're throwing at them, +the postgresql database on the dual PIII-750 is still plenty fast. I.e. +our bottlenecks are elsewhere than pgsql. + +I don't know anyone off the top of my head that's running postgresql on an +Opteron, by the way, but I expect it should work fine. You're more likely +to have problems finding a distribution that works well on top of an +Opteron than to have problems with pgsql. + + +From pgsql-performance-owner@postgresql.org Tue May 20 11:55:16 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (unknown [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id CB33F925069 + for ; + Tue, 20 May 2003 11:55:14 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 95759-04 for ; + Tue, 20 May 2003 11:55:11 -0400 (EDT) +Received: from shield.nordlb.lv (shield.pirmabanka.lv [195.114.57.4]) + by developer.postgresql.org (Postfix) with ESMTP id 99663925063 + for ; + Tue, 20 May 2003 11:55:10 -0400 (EDT) +Received: from wall2.pirmabanka.lv (wall2-pub.nordlb.lv [195.114.57.14]) + by shield.nordlb.lv (8.12.9/8.12.9) with SMTP id h4KFt8bg024735 + for ; Tue, 20 May 2003 18:55:08 +0300 +Received: from share.nordlb.lv ([10.0.0.10]) by wall2.pirmabanka.lv; + Tue, 20 May 2003 18:55:06 +0300 (EET DST) +Received: from pc311x1.nordlb.lv (localhost.localdomain [127.0.0.1]) + by nordlb.lv (8.11.6/8.11.6) with SMTP id h4KFt5j28391 + for ; Tue, 20 May 2003 18:55:05 +0300 +Received: (qmail 4687 invoked by uid 100); 20 May 2003 15:58:01 -0000 +Date: Tue, 20 May 2003 18:58:01 +0300 +From: Victor Yegorov +To: Eugene Fokin +Cc: pgsql-performance@postgresql.org +Subject: Re: 7.3.2 vs 7.1.2 +Message-ID: <20030520155801.GC4580@nordlb.lv> +References: <20030520122838.GA28654@solvo.ru> + <20030520130913.GM1976@nordlb.lv> + <20030520132842.GA29262@solvo.ru> <20030520140713.GN1976@nordlb.lv> + <20030520153348.GA30541@solvo.ru> +Mime-Version: 1.0 +Content-Type: text/plain; charset=koi8-r +Content-Disposition: inline +In-Reply-To: <20030520153348.GA30541@solvo.ru> +User-Agent: Mutt/1.4.1i +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/198 +X-Sequence-Number: 1977 + +* Eugene Fokin [20.05.2003 18:38]: +> > (loads l JOIN (SELECT rcn_details.id, rcn_details.date_pour FROM rcn_details) r ON ((r.id = l.rcn_id))) +> > + +Try changing the join above to: + +loads l JOIN rcn_details r ON r.id = l.rcn_id + +Also, give the full description of fields, involved in your +load_rcn_id_idx and rcn_detail_idx indicies. + +-- + +Victor Yegorov + +From pgsql-performance-owner@postgresql.org Tue May 20 12:31:40 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (unknown [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 7DA80924E57 + for ; + Tue, 20 May 2003 12:31:39 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 12807-09 for ; + Tue, 20 May 2003 12:31:28 -0400 (EDT) +Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) + by developer.postgresql.org (Postfix) with ESMTP id D6A40924E66 + for ; + Tue, 20 May 2003 12:31:27 -0400 (EDT) +Received: from [63.195.55.98] (HELO spooky) + by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) + with ESMTP id 3049776; Tue, 20 May 2003 09:31:29 -0700 +Content-Type: text/plain; + charset="koi8-r" +From: Josh Berkus +Organization: Aglio Database Solutions +To: Victor Yegorov , + Eugene Fokin +Subject: Re: 7.3.2 vs 7.1.2 +Date: Tue, 20 May 2003 09:30:20 -0700 +User-Agent: KMail/1.4.3 +Cc: pgsql-performance@postgresql.org +References: <20030520122838.GA28654@solvo.ru> + <20030520132842.GA29262@solvo.ru> + <20030520140713.GN1976@nordlb.lv> +In-Reply-To: <20030520140713.GN1976@nordlb.lv> +MIME-Version: 1.0 +Content-Transfer-Encoding: 8bit +Message-Id: <200305200930.20233.josh@agliodbs.com> +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/199 +X-Sequence-Number: 1978 + +Eugene, + +> 7.2.1 "... rows=147281 width=4) ..." +> 7.3.2 "... rows=147281 width=181) ..." + +Unless we have a serious bug here, Victor changed the definition of his index, +or of his table, between versions. Or mabye type casting during upgade +changed it? + +Please post the definition of "loads" and " load_rcn_id_idx" in each system, +Victor. Intentionally or not, you changed it between systems. + +-- +Josh Berkus +Aglio Database Solutions +San Francisco + +From pgsql-performance-owner@postgresql.org Tue May 20 12:32:56 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (unknown [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 2332B924E57 + for ; + Tue, 20 May 2003 12:32:53 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 13740-01 for ; + Tue, 20 May 2003 12:32:39 -0400 (EDT) +Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) + by developer.postgresql.org (Postfix) with ESMTP id 5C69A924E66 + for ; + Tue, 20 May 2003 12:32:39 -0400 (EDT) +Received: from [63.195.55.98] (HELO spooky) + by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) + with ESMTP id 3049781; Tue, 20 May 2003 09:32:41 -0700 +Content-Type: text/plain; + charset="koi8-r" +From: Josh Berkus +Organization: Aglio Database Solutions +To: "Victor Yegorov" , Eugene Fokin +Subject: Re: 7.3.2 vs 7.1.2 -- Ooops +Date: Tue, 20 May 2003 09:31:32 -0700 +User-Agent: KMail/1.4.3 +Cc: pgsql-performance@postgresql.org +References: <20030520122838.GA28654@solvo.ru> + <20030520130913.GM1976@nordlb.lv> +In-Reply-To: <20030520130913.GM1976@nordlb.lv> +MIME-Version: 1.0 +Content-Transfer-Encoding: 8bit +Message-Id: <200305200931.32267.josh@agliodbs.com> +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/200 +X-Sequence-Number: 1979 + +Eugene, Victor, + +Sorry! I got the two of you mixed up ... who was asking, who was answering. +Please transpose your two names in my last post! + +-- +Josh Berkus +Aglio Database Solutions +San Francisco + +From pgsql-performance-owner@postgresql.org Tue May 20 12:36:40 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (unknown [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id EEE2C925069 + for ; + Tue, 20 May 2003 12:36:36 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 13741-09 for ; + Tue, 20 May 2003 12:36:33 -0400 (EDT) +Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) + by developer.postgresql.org (Postfix) with ESMTP id 292FE924F55 + for ; + Tue, 20 May 2003 12:36:33 -0400 (EDT) +Received: from [63.195.55.98] (HELO spooky) + by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) + with ESMTP id 3049796; Tue, 20 May 2003 09:36:34 -0700 +Content-Type: text/plain; + charset="iso-8859-1" +From: Josh Berkus +Organization: Aglio Database Solutions +To: Eugene Fokin , + Victor Yegorov +Subject: Re: 7.3.2 vs 7.1.2 +Date: Tue, 20 May 2003 09:35:25 -0700 +User-Agent: KMail/1.4.3 +Cc: pgsql-performance@postgresql.org +References: <20030520122838.GA28654@solvo.ru> + <20030520130913.GM1976@nordlb.lv> + <20030520132842.GA29262@solvo.ru> +In-Reply-To: <20030520132842.GA29262@solvo.ru> +MIME-Version: 1.0 +Content-Transfer-Encoding: 8bit +Message-Id: <200305200935.25766.josh@agliodbs.com> +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/201 +X-Sequence-Number: 1980 + +Eugene, + +Another question ... given that 7.3.2's estimates are very similar to 7.2.1's +estimates, but the real execution time is much slower, is it possible that +the 7.3.2 copy of the database is being loaded on a much slower disk? + +-- +Josh Berkus +Aglio Database Solutions +San Francisco + +From pgsql-performance-owner@postgresql.org Tue May 20 12:40:43 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (unknown [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 57A03925098 + for ; + Tue, 20 May 2003 12:40:42 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 15310-10 for ; + Tue, 20 May 2003 12:40:35 -0400 (EDT) +Received: from sss.pgh.pa.us (unknown [192.204.191.242]) + by developer.postgresql.org (Postfix) with ESMTP id 2C16592508E + for ; + Tue, 20 May 2003 12:40:35 -0400 (EDT) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h4KGeMU6029700; + Tue, 20 May 2003 12:40:22 -0400 (EDT) +To: Victor Yegorov +Cc: Eugene Fokin , pgsql-performance@postgresql.org +Subject: Re: 7.3.2 vs 7.1.2 +In-reply-to: <20030520140713.GN1976@nordlb.lv> +References: <20030520122838.GA28654@solvo.ru> + <20030520130913.GM1976@nordlb.lv> + <20030520132842.GA29262@solvo.ru> <20030520140713.GN1976@nordlb.lv> +Comments: In-reply-to Victor Yegorov + message dated "Tue, 20 May 2003 17:07:13 +0300" +Date: Tue, 20 May 2003 12:40:21 -0400 +Message-ID: <29699.1053448821@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/202 +X-Sequence-Number: 1981 + +Victor Yegorov writes: +> As you can see, in 7.2.1 index scan on loads (load_rcn_id_idx) takes +> 0.04..786.13, but in 7.3.2 - 0.07..4486.76. + +That seems very odd, doesn't it? Is it reproducible? I'm wondering if +the 7.2 table was clustered on the index while the 7.3 wasn't. + +Most of the cost differential, however, is coming from the fact that 7.3 +doesn't flatten the view and thus fails to realize that it doesn't need +to evaluate any of the view's targetlist expressions. Note the lack of +any "SubPlans" in the 7.2 plan, whereas they're accounting for a good +deal of time in the 7.3 plan. + +The reason that the view isn't flattened is that pulling up targetlists +containing sub-selects turned out to break some obscure cases involving +join alias variables, and by the time we discovered this (after 7.3 +release) there was no practical way to fix it except to disable the +optimization. It's fixed properly in CVS tip (7.4 branch) but 7.3.* is +just going to be slow on such cases; the fix is much too complex to risk +back-porting. + +I'm not sure whether selecting the count from this view is really all +that important to Eugene, but if it is he could make an alternate view +that has the same FROM clause and nothing interesting in its select +list, and then count that. + + regards, tom lane + +From pgsql-performance-owner@postgresql.org Tue May 20 13:34:04 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (unknown [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 93BF2925142 + for ; + Tue, 20 May 2003 13:34:01 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 34638-03 for ; + Tue, 20 May 2003 13:33:56 -0400 (EDT) +Received: from sss.pgh.pa.us (unknown [192.204.191.242]) + by developer.postgresql.org (Postfix) with ESMTP id A094992514B + for ; + Tue, 20 May 2003 13:33:54 -0400 (EDT) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h4KHXeU6000194; + Tue, 20 May 2003 13:33:40 -0400 (EDT) +To: Josh Berkus +Cc: Eugene Fokin , Victor Yegorov , + pgsql-performance@postgresql.org +Subject: Re: 7.3.2 vs 7.1.2 +In-reply-to: <200305200935.25766.josh@agliodbs.com> +References: <20030520122838.GA28654@solvo.ru> + <20030520130913.GM1976@nordlb.lv> + <20030520132842.GA29262@solvo.ru> + <200305200935.25766.josh@agliodbs.com> +Comments: In-reply-to Josh Berkus + message dated "Tue, 20 May 2003 09:35:25 -0700" +Date: Tue, 20 May 2003 13:33:40 -0400 +Message-ID: <193.1053452020@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/203 +X-Sequence-Number: 1982 + +Josh Berkus writes: +> Another question ... given that 7.3.2's estimates are very similar to 7.2.1's +> estimates, but the real execution time is much slower, is it possible that +> the 7.3.2 copy of the database is being loaded on a much slower disk? + +Nah, the big reason for the discrepancy is that 7.3 is unable to prune +away evaluation of all those sub-selects in the view's target list, per +my previous response. + +Up till just recently (post-7.3) the planner didn't bother to charge any +evaluation cost for targetlist expressions, and so the estimated costs +don't reflect the difference. + +(The reasoning behind that behavior was that the planner couldn't affect +the evaluation costs of targetlist expressions by choosing a different +plan, since the number of rows they'll be computed for will be the same +in every correct plan. But now that we allow arbitrarily complex stuff +in sub-selects, that reasoning doesn't hold water anymore --- it's +important to propagate a good estimate of the cost up to the enclosing +plan. So as of 7.4 we expend the cycles to add in tlist execution time +estimates.) + +I am still interested in the apparent difference in the time taken for +that bottom indexscan, though. The width difference that you noticed is +because the unflattened view needs to fetch many more columns of the +table than the flattened query needs. But the same number of rows get +fetched, and approximately the same number of disk blocks ought to get +read, so it's hard to see why there'd be such a large difference. + + regards, tom lane + +From pgsql-performance-owner@postgresql.org Wed May 21 03:09:39 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (unknown [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 551A69250B8 + for ; + Wed, 21 May 2003 03:09:38 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 19825-02 for ; + Wed, 21 May 2003 03:09:05 -0400 (EDT) +Received: from gate.solvo.ru (gate.solvo.ru [195.201.44.1]) + by developer.postgresql.org (Postfix) with ESMTP id 7F6B19250EC + for ; + Wed, 21 May 2003 03:08:56 -0400 (EDT) +Received: from grace.solvo.ru (grace.solvo.ru [195.201.44.100]) + by gate.solvo.ru (8.8.8/8.8.8) with ESMTP id LAA14925; + Wed, 21 May 2003 11:08:26 +0400 +Received: from grace.solvo.ru (localhost [127.0.0.1]) + by grace.solvo.ru (8.12.8/8.12.8) with ESMTP id h4L78QpD004879; + Wed, 21 May 2003 11:08:26 +0400 +Received: (from elf@localhost) + by grace.solvo.ru (8.12.8/8.12.8/Submit) id h4L78Gj6004876; + Wed, 21 May 2003 11:08:16 +0400 +Date: Wed, 21 May 2003 11:08:16 +0400 +From: Eugene Fokin +To: Victor Yegorov +Cc: pgsql-performance@postgresql.org +Subject: Re: 7.3.2 vs 7.1.2 +Message-ID: <20030521070816.GA4664@solvo.ru> +References: <20030520122838.GA28654@solvo.ru> + <20030520130913.GM1976@nordlb.lv> + <20030520132842.GA29262@solvo.ru> <20030520140713.GN1976@nordlb.lv> + <20030520153348.GA30541@solvo.ru> <20030520155801.GC4580@nordlb.lv> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: <20030520155801.GC4580@nordlb.lv> +User-Agent: Mutt/1.4i +X-Operating-System: Linux 2.4.19-1pe i686 +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/204 +X-Sequence-Number: 1983 + +On Tue, May 20, 2003 at 06:58:01PM +0300, Victor Yegorov wrote: +> +> Try changing the join above to: +> +> loads l JOIN rcn_details r ON r.id = l.rcn_id +> + +Nothing, I mean - the same result. + +> +> Also, give the full description of fields, involved in your +> load_rcn_id_idx and rcn_detail_idx indicies. +> + +\d load_rcn_id_idx: + + Index "public.load_rcn_id_idx" + Column | Type + --------+--------- + rcn_id | integer + btree, for table "public.loads" + +\d loads: + + ... + rcn_id | integer | not null default 0 + ... + +\d rcn_detail_idx: + + Index "public.rcn_detail_idx" + Column | Type + --------+--------- + id | integer + unique, btree, for table "public.rcn_details" + +\d rcn_details: + + ... + id | integer | default nextval('rcn_details_id'::text) + ... + +\d rcn_details_id + + Sequence "public.rcn_details_id" + Column | Type + ---------------+--------- + sequence_name | name + last_value | bigint + increment_by | bigint + max_value | bigint + min_value | bigint + cache_value | bigint + log_cnt | bigint + is_cycled | boolean + is_called | boolean + +-- +Eugene Fokin +SOLVO Ltd. Company + +From pgsql-performance-owner@postgresql.org Wed May 21 03:13:20 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (unknown [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id CB2AC924EEB + for ; + Wed, 21 May 2003 03:13:17 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 20797-03 for ; + Wed, 21 May 2003 03:12:45 -0400 (EDT) +Received: from gate.solvo.ru (gate.solvo.ru [195.201.44.1]) + by developer.postgresql.org (Postfix) with ESMTP id 19E889250B8 + for ; + Wed, 21 May 2003 03:12:34 -0400 (EDT) +Received: from grace.solvo.ru (grace.solvo.ru [195.201.44.100]) + by gate.solvo.ru (8.8.8/8.8.8) with ESMTP id LAA14948; + Wed, 21 May 2003 11:11:29 +0400 +Received: from grace.solvo.ru (localhost [127.0.0.1]) + by grace.solvo.ru (8.12.8/8.12.8) with ESMTP id h4L7BTpD004901; + Wed, 21 May 2003 11:11:29 +0400 +Received: (from elf@localhost) + by grace.solvo.ru (8.12.8/8.12.8/Submit) id h4L7BQ53004899; + Wed, 21 May 2003 11:11:26 +0400 +Date: Wed, 21 May 2003 11:11:25 +0400 +From: Eugene Fokin +To: Josh Berkus +Cc: Victor Yegorov , + pgsql-performance@postgresql.org +Subject: Re: 7.3.2 vs 7.1.2 +Message-ID: <20030521071125.GB4664@solvo.ru> +References: <20030520122838.GA28654@solvo.ru> + <20030520132842.GA29262@solvo.ru> + <20030520140713.GN1976@nordlb.lv> + <200305200930.20233.josh@agliodbs.com> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: <200305200930.20233.josh@agliodbs.com> +User-Agent: Mutt/1.4i +X-Operating-System: Linux 2.4.19-1pe i686 +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/205 +X-Sequence-Number: 1984 + +On Tue, May 20, 2003 at 09:30:20AM -0700, Josh Berkus wrote: +> +> > 7.2.1 "... rows=147281 width=4) ..." +> > 7.3.2 "... rows=147281 width=181) ..." +> +> Unless we have a serious bug here, Victor changed the definition of his index, +> or of his table, between versions. Or mabye type casting during upgade +> changed it? +> +> Please post the definition of "loads" and " load_rcn_id_idx" in each system, +> Victor. Intentionally or not, you changed it between systems. + +Nothing changed ! Believe me :-) +Same dump file, same platform, even the same machine. +I've post already necessary definitions. + +-- +Eugene Fokin +SOLVO Ltd. Company + +From pgsql-performance-owner@postgresql.org Wed May 21 03:25:19 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (unknown [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 20B449250F1 + for ; + Wed, 21 May 2003 03:25:10 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 23843-05 for ; + Wed, 21 May 2003 03:24:59 -0400 (EDT) +Received: from gate.solvo.ru (gate.solvo.ru [195.201.44.1]) + by developer.postgresql.org (Postfix) with ESMTP id 21F969250CE + for ; + Wed, 21 May 2003 03:24:53 -0400 (EDT) +Received: from grace.solvo.ru (grace.solvo.ru [195.201.44.100]) + by gate.solvo.ru (8.8.8/8.8.8) with ESMTP id LAA14980; + Wed, 21 May 2003 11:19:12 +0400 +Received: from grace.solvo.ru (localhost [127.0.0.1]) + by grace.solvo.ru (8.12.8/8.12.8) with ESMTP id h4L7JCpD004938; + Wed, 21 May 2003 11:19:12 +0400 +Received: (from elf@localhost) + by grace.solvo.ru (8.12.8/8.12.8/Submit) id h4L7J36q004936; + Wed, 21 May 2003 11:19:03 +0400 +Date: Wed, 21 May 2003 11:19:03 +0400 +From: Eugene Fokin +To: Tom Lane +Cc: Victor Yegorov , + pgsql-performance@postgresql.org +Subject: Re: 7.3.2 vs 7.1.2 +Message-ID: <20030521071903.GC4664@solvo.ru> +References: <20030520122838.GA28654@solvo.ru> + <20030520130913.GM1976@nordlb.lv> + <20030520132842.GA29262@solvo.ru> <20030520140713.GN1976@nordlb.lv> + <29699.1053448821@sss.pgh.pa.us> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: <29699.1053448821@sss.pgh.pa.us> +User-Agent: Mutt/1.4i +X-Operating-System: Linux 2.4.19-1pe i686 +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/206 +X-Sequence-Number: 1985 + +On Tue, May 20, 2003 at 12:40:21PM -0400, Tom Lane wrote: +> +> [...skipped...] +> +> I'm not sure whether selecting the count from this view is really all +> that important to Eugene, but if it is he could make an alternate view +> that has the same FROM clause and nothing interesting in its select +> list, and then count that. +> + +This is the one sample from the working system for which I'm trying +to upgrade the database. + +And you're right. I've removed all subqueries from select list and I've +got original 5 seconds ! After that I tried to add one subquery back (the +simpliest one) and got the same 40-50 seconds again ! + +-- +Eugene Fokin +SOLVO Ltd. Company + +From pgsql-performance-owner@postgresql.org Wed May 21 06:00:28 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (unknown [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 7A3499234EE + for ; + Wed, 21 May 2003 06:00:26 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 82276-01 for ; + Wed, 21 May 2003 06:00:20 -0400 (EDT) +Received: from mithi.com (unknown [219.65.91.97]) + by developer.postgresql.org (Postfix) with SMTP id 9402E92335B + for ; + Wed, 21 May 2003 06:00:10 -0400 (EDT) +Received: (qmail 31784 invoked by uid 0); 21 May 2003 09:57:48 -0000 +Received: from unknown (HELO amol) (192.168.0.46) + by 0 with SMTP; 21 May 2003 09:57:48 -0000 +Message-ID: <000a01c31f81$fa45da70$2e00a8c0@amol> +From: "amol" +To: +References: <20030515075032.B60859-100000@megazone23.bigpanda.com> + <00a101c31ea1$19e03d80$2e00a8c0@amol> + <29058.1053443906@sss.pgh.pa.us> +Subject: Re: nested select query failing +Date: Wed, 21 May 2003 15:46:00 +0530 +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit +X-Priority: 3 +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook Express 5.00.2919.6700 +X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6700 +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/207 +X-Sequence-Number: 1986 + +Hi Tom, +U are great. As you have said, one item was numeric and another serial + integer ) so it was applying seq scan. Thank you very much for your help +everybody. + +regards, +Amol + +----- Original Message ----- +From: "Tom Lane" +To: "amol" +Cc: +Sent: Tuesday, May 20, 2003 8:48 PM +Subject: Re: [PERFORM] nested select query failing + + +> "amol" writes: +> > explain analyze select attached_info.id from attached_tag_list, +> > attached_info +> > where +> > attached_tag_list.attached_tag = 265 +> > and +> > attached_tag_list.id = attached_info.id +> +> > NOTICE: QUERY PLAN: +> +> > Nested Loop (cost=0.00..165349.50 rows=114 width=16) (actual +> > time=117.14..8994.60 rows=15 loops=1) +> > -> Index Scan using ix_attached_tag_list_id on attached_tag_list +> > (cost=0.00..111.13 rows=96 width=12) (actual time=0.12..0.66 rows=15 +> > loops=1) +> > -> Seq Scan on attached_info (cost=0.00..1211.53 rows=33553 width=4) +> > (actual time=3.67..197.98 rows=33553 loops=15) +> > Total runtime: 8994.92 msec +> +> > - I have already indexed attached_info on id using following query +> > CREATE INDEX attached_info_Index_1 ON attached_info(id) ; +> +> Hm. I'd have expected an index scan too. Maybe the two id columns are +> not of the same datatype? +> +> regards, tom lane +> +> ---------------------------(end of broadcast)--------------------------- +> TIP 6: Have you searched our list archives? +> +> http://archives.postgresql.org +> +> + + +From pgsql-performance-owner@postgresql.org Wed May 21 11:02:09 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (unknown [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id E815C9253DD + for ; + Wed, 21 May 2003 11:02:05 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 29642-01 for ; + Wed, 21 May 2003 11:01:33 -0400 (EDT) +Received: from lakemtao03.cox.net (lakemtao03.cox.net [68.1.17.242]) + by developer.postgresql.org (Postfix) with ESMTP id 2C678923313 + for ; + Wed, 21 May 2003 10:54:36 -0400 (EDT) +Received: from [192.168.1.1] ([68.11.66.83]) by lakemtao03.cox.net + (InterMail vM.5.01.04.05 201-253-122-122-105-20011231) with ESMTP + id <20030521145435.GPSU23518.lakemtao03.cox.net@[192.168.1.1]> + for ; + Wed, 21 May 2003 10:54:35 -0400 +Subject: Re: postgres on a beowulf? (AMD)opteron? +From: Ron Johnson +To: PgSQL Performance ML +In-Reply-To: <20030520112739.GB11943@libertyrms.info> +References: <20030519132832.6733dd56.gry@ll.mit.edu> + <20030520112739.GB11943@libertyrms.info> +Content-Type: text/plain +Organization: +Message-Id: <1053528874.688.118.camel@haggis> +Mime-Version: 1.0 +X-Mailer: Ximian Evolution 1.2.4 +Date: 21 May 2003 09:54:34 -0500 +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/208 +X-Sequence-Number: 1987 + +On Tue, 2003-05-20 at 06:27, Andrew Sullivan wrote: +> On Mon, May 19, 2003 at 01:28:32PM -0400, george young wrote: +> > Has anyone run postgres on a beowulf system? +> +> Can't be done. None of the cluster systems support cross-machne +> shared memory (this is actually a problem for Postgres and NUMA, as +> well, BTW). + +VMSclusters and Tru64 clusters do, but, of course, it has to be +programmed for. + +And the licensing costs are pretty steep... + +-- ++-----------------------------------------------------------+ +| Ron Johnson, Jr. Home: ron.l.johnson@cox.net | +| Jefferson, LA USA http://members.cox.net/ron.l.johnson | +| | +| Regarding war zones: "There's nothing sacrosanct about a | +| hotel with a bunch of journalists in it." | +| Marine Lt. Gen. Bernard E. Trainor (Retired) | ++-----------------------------------------------------------+ + + +From pgsql-performance-owner@postgresql.org Wed May 21 12:24:26 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (unknown [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 4FC98924FC6 + for ; + Wed, 21 May 2003 12:24:21 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 55162-08 for ; + Wed, 21 May 2003 12:23:49 -0400 (EDT) +Received: from mail1.ihs.com (mail1.ihs.com [170.207.70.222]) + by developer.postgresql.org (Postfix) with ESMTP id F216D92542D + for ; + Wed, 21 May 2003 11:59:11 -0400 (EDT) +Received: from css120.ihs.com (css120.ihs.com [170.207.105.120]) + by mail1.ihs.com (8.12.9/8.12.9) with ESMTP id h4LFvZ1v021812; + Wed, 21 May 2003 09:57:35 -0600 (MDT) +Date: Wed, 21 May 2003 09:45:50 -0600 (MDT) +From: "scott.marlowe" +To: Ron Johnson +Cc: PgSQL Performance ML +Subject: Re: postgres on a beowulf? (AMD)opteron? +In-Reply-To: <1053528874.688.118.camel@haggis> +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-MailScanner: Found to be clean +X-MailScanner-SpamCheck: +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/209 +X-Sequence-Number: 1988 + +On 21 May 2003, Ron Johnson wrote: + +> On Tue, 2003-05-20 at 06:27, Andrew Sullivan wrote: +> > On Mon, May 19, 2003 at 01:28:32PM -0400, george young wrote: +> > > Has anyone run postgres on a beowulf system? +> > +> > Can't be done. None of the cluster systems support cross-machne +> > shared memory (this is actually a problem for Postgres and NUMA, as +> > well, BTW). +> +> VMSclusters and Tru64 clusters do, but, of course, it has to be +> programmed for. +> +> And the licensing costs are pretty steep... + +someone was on the list last year and had gotten postgresql (sorta) +working on mosix clusters. The performance, I recall, was less than +stellar. + + +From pgsql-performance-owner@postgresql.org Thu May 22 11:30:57 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (unknown [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 5CAD7925379 + for ; + Thu, 22 May 2003 11:29:25 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 76349-05 for ; + Thu, 22 May 2003 11:28:53 -0400 (EDT) +Received: from mail.deltav.hu (unknown [213.163.0.192]) + by developer.postgresql.org (Postfix) with ESMTP id C6C9A926198 + for ; + Thu, 22 May 2003 10:27:07 -0400 (EDT) +Received: from fejleszt4 ([213.163.10.103]) by mail.deltav.hu + (Netscape Messaging Server 3.6) with SMTP id AAA28C4; + Thu, 22 May 2003 16:27:06 +0200 +Message-ID: <008101c3206e$0dc8a310$0403a8c0@fejleszt4> +From: "=?iso-8859-2?B?U1rbQ1MgR+Fib3I=?=" +To: +Cc: +Subject: ugly query slower in 7.3, even slower after vacuum full analyze +Date: Thu, 22 May 2003 16:25:54 +0200 +MIME-Version: 1.0 +Content-Type: multipart/mixed; + boundary="----=_NextPart_000_007E_01C3207E.D11CF590" +X-Priority: 3 +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook Express 6.00.2800.1158 +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/210 +X-Sequence-Number: 1989 + +This is a multi-part message in MIME format. + +------=_NextPart_000_007E_01C3207E.D11CF590 +Content-Type: text/plain; + charset="iso-8859-2" +Content-Transfer-Encoding: 7bit + +Dear Gurus, + +This is a rather nasty query, built up from several parameters, and it +proved to be 7--15 times slower in 7.3 than in 7.2. This particular query +takes more than 3.5 minutes (4 after vacuum full analyze! (henceforth VFA)) +that is unacceptable in an interactive client application. + +If you have courage and will to please have a look at the query and/or the +explains, you might point out something I can't see at this level of +complexity. + +As for trivial questions: + +* The databases were identical a couple of weeks ago, deviated slightly + since then, but I don't think it may be a cause. +* The 5% difference in the result set doesn't seem to explain this huge + diff in performance either. +* The query has been run on the same server (Linux RedHat 6.1 -- + historical, isn't it?) with the same load (this one postmaster took >90% + CPU all the time, in all three cases) +* Since this query involves quite a large part of the database, I'm not + willing to post a dump on the list. If a schema-only dump helps, I may + be able to send it in private email; I approximate it to be ~500k, + zipped. +* Also checked a "lighter" version of this query (at least, fewer rows). It + took 223msec on 7.2 and 3658 on 7.3 (VFA). (15x slower) However, it got + down to 400-500msec (still double of 7.2) when re-queried + +Files are zipped, since 7.3 exp-ana's are over 40k each. + +slow.sql: the query. +72.ana: explain analyze in 7.2 +73.ana: explain analyze in 7.3, before VFA +73.ana2: explain analyze in 7.3, after VFA + +I just hope someone helps me; any little help may prove really useful! +TIA, +G. +------------------------------- cut here ------------------------------- + +------=_NextPart_000_007E_01C3207E.D11CF590 +Content-Type: application/octet-stream; + name="slow_and_ugly.zip" +Content-Transfer-Encoding: base64 +Content-Disposition: attachment; + filename="slow_and_ugly.zip" + +UEsDBBQAAgAIAAR+ti7RaeV35AgAAANOAAAGAAAANzIuYW5hzVxbj+O2FX5u +gPwHPSZAS/B+CbAF+tQL2qLA9n3g7AgTJ57xxtZsuvn1PTy6kLpalmRJxGDM +wcjD7yMPz4UfPR/PlyxJvvt0vmYfNFeGE2cJKXvJ5fzb9QOTVCe/HZ+znz5w +Kb9Pvjt8yt4PpyQ7vqYfuFGSEaEJ8T1OGMvfJC1PTufzZ3j7999+kyR/+nOS +/Cu9vKTJP87HtzCkdIo47YeUzhE5akihLCdc+SGF1MS67iHz5gf+GLFkQIwS +gi/FYMVIhjYGYjAAPAnf8wdpx5+PBnn/8df39PI1+fjp8Ja8Xp5eoyGtwSFL +qL1DUmJh/v33W0OGgf/y8nJJXw5ZOm08g+PdpNgc9a+X8/vnjhHt7RE1jqjv +GbF3Lcthze1hFQ6r7h82DP7v9Jqlz8k/4a0lBkpobk4loQEIsFOI/z4Vwggg +lmhWx6Ga+wcQUMRB5+EIaP7+9pz+L7f79+vx7SV5fbm8PZ+uT1l2espOP1+z +a3KGPZGCocKjpxR+k2bwmmR19IIIUUcvO2bx4egjnK/n5/P1mB2uh6fPv6Rf +mzTCr5PXOhVFuKxTYXLCQg+C60CU/FiHIQlvzCjTA94R3LAVhBp0yNhrOWQh +dMshc1gT5WMA9DjRunTI5g6PmbEIBNWEKgRBHfzlcSDgTVogCPDbSt0GEaB0 +hqapIJRDEMzBW8eC6F4OZsGFg3extz05hCmBwUpM9Ku1xfhyjMKXJUblIEY4 +9wW8bDug3YVAIgI538nWQ1zAUPxpO4BBIIYJS9GzOHWbKIAYtSqQAKc/DEL4 +uT07EldIzlyhe6FR+Kobj+iAhvMlF5yvJsCWQ7/+fjplpy9xoLz+fjidjtn5 +lH5JT02PLoh0LY/e4sGRB1+VRwS6K272PdCMnODF6czIOQly/adO0N1Zi+nK +Wu5x85oLyGMZlkF5r10G2XYZxCE68TzW+FDl7os1EZR6HOYRLL9rJMJigmg1 +ChYzlBiExRyfCCuA64rM02FJhAXloxyRo4yYuWmxmhKHVZe7q+oav4TgUiaG +b4W1mZpQmw2hmxfQl8cUkE0P8QoTHTU50bmNbXLQVxhf1eLxtQlwZhpAcQ+U +FQZ9BMoxWEflBQ2sD5nSJuR1MgWKu4suvrvuZLbn3GESidHZxNxkohtdPb3g +juGBadlrB0zatHkIk9oRwzBgmuB/pwfMCFw94dARUIjn/pTM9wyE61FAqZPF +6QODF2WXARrgdqUg04FyBMopETMyo8HZjZbeCQU4LSFFJx9R8NIt69YJBgOA +1J+i+A4rCgjFHhHfalbw9jV9er1UuLmjsJU9bgFWeBs3M0YQk+MGjy4ehDug +b+U0EyH7DcakezTkALyW8sSgWbV1BDeuF7WE3FX6RFf5Q+8CtZBd2svy4Gu2 +XWHPO2Oxg6dgKDap9bAHBn87XH+q+RJLlSUOnLOjAKrUz4ZoOHAj/mCHSasr +2WE9FoHLx/TXfPOOOtxXIgo9itsq3WonJZBAEgEZtiv9qoYVW50eLlVYJYUO +v+iU/p7pvqTRr5Lwy4qva6VXA0xiozOOWjwkGk3Hgoly7emIylcxZzcgFGj1 +2V9/fuj86XwRdoVyIUdsWaA/XlBE2+jhLanGtgiLpwn3uWLeKSot6/qyfAsm +6HX9/HU7U2yS6tUNsdK5oWyNJc8IJGhAXVS6FIPSeFvyeYME6D+nw9uWENr7 +6Jf0kmbVnNdL5SpkVqVJu5x0vpxk1XP5PHPt1KZTvTxP28lTSb54Dg+hUjlI +0CCCFr1WscG0bebxUGtwjD++JyoxesliI4JbL+hMgG6Mg0LHQzeQrJSCxA3o +FvI5wRA6F5Uaszz0QKBd4s2Azi1CZxp81GOhBwKxwXCmjSTUn3UXvRb0Vk4J +uPPjceiw6uxQ6kfijtC3SsEvx8BGWAe+G9kASNU2f2BTIyMlhG6vMlprVaiz +VyATKLXqw3E8kg4iPk2zRkNZvjaRQKdWNcZUlA4zDFRUb7kLXBjezwBOsDPK +4yTBtgjG7S0TGOW9sYz8ZQ8pLQ9mtg2jwKuV7DMDBkc0OlQGu5uNWS5wZZBe +gelJDotG6Q7IBYpxIB+j0DJ/n5WVTs04bvprT46igL9hWl3e0eKRhzJjSccl +ACwp1G0ItejlWMG1qL4KDlZU5ddm884+6oAGv5rdauuV2rtIMuscSmWcGhPU +RQEbeg88A9t+E+6vXpmy1QGRoYwNlK/+4EFBlho9vC/+NWvWFhbLH4WWvWLZ +rBG9ZZ1faGG92IidPVlz3IaVvNPpc/bHwR9vqnx3TBnufpgv6JQhgMntjnCG +2y6q43ZbuI5keJm5uvBTrIXSQuxsOR5VQTeYS+nulTtHY4/yPcEYVfixlbLX +ru5oEzNjznrZAPgx50vUO2/3ziZQr7JtIEP9hWfuyVCom21b3+0kA0x0TgaK +CzH6vvSSlNp19xwyHMloWwmd65EJlGbKr8zgGRp2mFlBExzkUrO44zyFVlNB +BB5KQHZSnpxtQi0QHK/iDrJCEZfJ6ibRhqwCt7lCrz+k0NInGEzDhtxGZhwi +OFMMRn6Yc1JefcZvL/wCywUEY8aYxRsyUEC46nLjvqjm7aGqMofFFtofLW+l +Ko9p85VnXG6GkR07ey2N8raQPg1JAcsvYDNwV+XN6i0V6jFtBRXbH5zo6OG9 +T8cspRutwB/jFp19m37cVtTDKcf5oVVQrwvif2i3HGJVkfc+sVJ5XMjJK8LA +D25X5+ZLqr1jbWOuwOcstyhnQseFs+2VpaSIT7O0uFfxa2gx2liMks6CeSuz +Jb1AchkR0FPDlTMuUsM3pBYILiALegOGkp1IB8VGGbd3oDMFksNC4ViK0iuf +LrqfvheKgehCyiGHRNsfLEkJG9LtRzlst0driczno1S56FOQ22uJ7baIush5 +/s9kis6+M6/F9EZOBdQnSJtFNwz3pTe220oKpKw+NrQzBbLdltAk0Rgo3v4S +QXzd6x6I265USorxhpvqklBDpdxVgYL/MILZemVQ6HfrwRgU0/57zuDJy/ub +f/iHhBuA56/4vV7TT99+839QSwMEFAACAAgAN7i1LgBXFvsODwAA+bsAAAYA +AAA3My5hbmHtHWtv20bye34FURSIhUuIfXDJpREXCJrctb2c22taHO6Todo8 +RzElpRTtxv71ty+Sy13KovhOzIFhig9xZ2ZnZ3fnJceZYYYq+Pfvb3/9r/PL +u9fnY2Myw1Th2csZZphhhkbwzHm/TVLHObnc7tIzCgMX+K4rjoGTbP/anUHn +r9VV+uEMU7BwTpaX6e0ydtLVOjpD0EM4dCFxXfUxxPI7BIROvN1+Yt9ePGNK +SrTxz+j+1LnZbu6iJF3GJ5erm5uL5cN2s92t0q04feGso+sk2lxF8XaxYGcr +djO6fuHsHu52DxfJ9m51dbGJ7k60x144379+/9b5zw9vz52TmyiJUnkn2rGX +X3yM4pObZOH8+N45//k35/z3d+8Wzm/82b2Pyjc9f17xnefPT08vPywTxoQo +ce6Wyf1qc+28fcfa509V3jx/wxnw8jvH+VeUXEfOT9vVpsRuT7GbHGQ3CKCP +3AALdoMwcFFQzW4Jsr3vt5urU+fk5JvtLcPrG3f3sIxjxnDnzPlmtdnolxbO +6/M3Tv5kwWTtWY3z5advEu0pzsfyu2RP6i+SV4znuBRoD/HThUbS31cxe0wn +Z51crJ1X3zng9HRzu46S1eXC+flX9kL1hrvV4/eZWD16f3PPGHMRXd9Hm5jh +X35Sw4x3sD6SIMBuSF1XHstdi1BodG1AiRuyYSSP8mlQ0aUSitHEqc+774U8 +LXpIXbhJsjvZcBJnnLfmmwUVt3/8eRsl9877y+VGPFqiyVM0BXVo4rIqj4do +Ktp/fc3wv16mUYtmoWoW1mu2aPwfyfb2U2XDfq2GgWoYHNPwIxKUtU7qtO6H +snU/PL51U7KUOs4lRhOqQt5MHVq3mQoxy97P3pNGKTteRMldtLmPdhk/PN9F +SLED12EHppIdmDZlR4HtebRLoyvnHXtBc3wChU/QDh8JYh7R9KGpnxnjmB5V +WnL5kOlZ9dgyufywuuOaLleky89x9LBM7pZC//GZz761UK/RmkvTbcxaOjEf +TpmYrJ2/OXCxaNyMja38Qunyohd8GzZ0HH/Lr++Ftx018cjL6pKcXc041i21 +1W+vL0BdYVf3/Y3GPNdEPyx3H0qLSKWH2FQbKEVHlBpiqslUQ77rs2UGxn4+ +k3oYoFaKSIJAS601rQWk1EUZUx5aNCNmjuhPOWlsy/PGenvFtxLL3dLJlyzA +BWxKRvygVDRgnxR7PIM7wIVsBqVhvvXxcNAFb/JuK3oMsrlJHBRWnsKJWhMH +612+MOSHLqYNE68fGfM+S3be7viGZX2dbK7i3cXuIY5Tg8XOH2W+1qIAMLl0 +XbZxYY+IR1EAYGc0SJBUKPHTdjist7tqIp9q2cuXn7Yp3wrQxqPYZnt5AXSh +n99E96asyzWSk5b7w3fZWC6tRCDyre4ATMj5/7I4cT3QglWlHtijAVL93Nj4 +7baJUKTiqWwgN9OSEoqlkaH8y7PXcwQAfgnISxiyzf0V33a8YjhE8ceIoZCj +WVxwXjn5d5CvvqOe+t/yY7pkJHjNEGdL4l/i5aYZzZVSVV6gf1KCVLpqjGiX +GhKEuJbcRHdR4kSfo0vWW1etRlRJUJYPjFvfQvDIRjqAWJik5NGwkSBThSPg +I7bOptwkxT+GOT0Ekhobam0vre14xA462wrt2zfb5h2BMlaom+adKtS5eSeE +AnXIjiQ8jLqEr9DUY7K3tDVGbDpkWowfMTDk1acGYyFnP9t7yWP2dJ0JqJAL +bkbSDC3iVJcQcYGLibyTyYo4qxIYi7rSblgYrXRafUkrMg1JFbQiMd3K4zG0 +FrjYBpjjUfAUCt7xKBSIlI0xRyERhG7At9vsEDZFQesdU/YyPEyjUCUensSD +tMNDwkAGGosBJfHM3h+zWSHeZ66R84ngkmm8srlEmZoWXPIayOxjiFfYbY5E +jI8mjlhjSd4Heww4JebOJpzZhDObcL4mE059BQVDa20DoekT9D3hQGQHv3MF +VSBp7SvKM0B2lm1UyyrMsBlAgFxoeHFCc5PqYxexhTM7UNgPWRIGsBtIKPR8 +pxvO3Bhx5vhSdosLgXmBCU97mZVQQygKa1y+79z3gGmu04IPyH5bHfctgo6W +VfugJB/rx+bmXmxx1cNMnlXydJ9ZKISGIiHmSge41OP8pC2Xy7U4ae1QM4am +5St924h0qGkvamni0aGVuUeHXk0/hu0QCtvhUX71Y+CQdagpcBa9W61X+cjg +ptJqg6lplpEehJzm7hWNucOsjRp0Q24EYf+VYb0XHahvOldX20/bTdrt6/eo +vjhO4zuu9dbxg3JHsHNb53GVEC8f+Dyysszhpt4zWQhErAj7r+Yb3BMLJZSV +oKn8voVQKZlKpc4fQHUtZIT6wvAgjuY2F1SYHoEXCtcg/0iAS0hd06OE1hZU +kxjbmipIQYokM+CigiQSEMg9f4IkSF2IjyNJwlduWX1MhjwfuB7mXj5+NCNc +7OhE4tPA9YX5mn2kLoFNGG7KU+prdld2oksVO+WCxa9mssU+HxIvi+aScSv1 +S/QDRb85NVbSz572fEU/csManofD2NkDoRleWOIVENdvjZeEJzQ0qrtGHyyY ++K7HFK48GrOObSMPMQGBi9hgER9pviVu2ykSOlXHhxlhy6hgA1TswDXY4XGv +HRLs8NjOjoAu2SHhScur2WWWSwMqm7ipUKzOooSHqxPWV/wTdbGSdi/sev1Z +SPHmPrq4W2kTgbqgy7S6xEU7u5tJuDpvJ+g62NOGbELnKA/xERw96KCk0Gcc +xYBzNGBL+mwP3j1HC+wrnXzHooyoQJmGRTRZTygXiFtOweOQZqpF5LdQtpPN +HKQeUzm9rvsz3M1Bl6EOw5qo80EHfcy26mBA1CWM4HqsD62dlKZJusKvjYnY +UlHohTyMcvAOkJDbqZRR2HsJqWZI1pKhTna3f3yKl5uq7Kfinkp34i9zAeER +kJWZT7bVWkt7kufnbwZhwEG37uGuDGRiCkGIu09URwYAdm/POgyzG3h2A89u +4KfsBq4PBx3G5urddhgDl/BQOG7jQ8o+42PU3SarCUldu5eBsZyy3MtA2AUx +m9Bhts/0vaoU2iFhMF90fSimpWp3dL4YGNkdXR+m4Ljm0czsvxHpxiVwCpLX +q5e7PozvD4fCMURUN1HVTVxZDt5Nk3ee14fh3ez1oTOHfH0Y0nUv4mWAESYm +tj0j6J0KR78/KBrNIwKAsHux/+E0WNk4foCREAhCgmkQIqHnaIP6MG5cglol +TKprJByIYggOBDHQYVT6oMq8LzVeocW9aWjxCv091LpoQGbLKRMbzEY+/QqY +bU4bCMttsTia+smKr4Eg8NnTUBSoYR9hrtO6dNlK0IJBqB4MQsvBIFQGg1At +GIT26vNLqc477swRx7AG7wiFLsGSdxDnmUjd867A3XbSN8MaSKwBcYnXL9YS +Zrf9XqgsGeXXrZRFKMIuhjyijn3wsuHr924H01Z40cU60Ya0PNdHtbzCB7a6 +l41tedrd8LbBHvCizRKzcd36XMQLgcv+OLOhS73BmF3QUl1Y7TgKaCAoAHmF +s8EoKOiwa7QdQQOlol4lIWyPhNTEjskYjr/KwZtR4tWjhIfDejR0qT8mJRIm +HR9gQ+sadFbkpVW6J+QOdd5BMI/THLODJDz5+AEbahT4O9zZgYjJxSHRAhA8 +6tGRu1vCXCxwDjGYQwzmEIMm0EXRQaEafZAXcOqo6GBXMFDxwq6g7yKI1GUT +nhYd20kRxC6Jb1FMEVBRTBG0rAncHwxVlJGHQftsJ0p7K8rYFUwwMGYfdFck +sivotdik5cXaV2wSZUG23RSb7AomV7SyK6gZZaFHdZ1pVUZIp2Utu4IRwjNs +GD1gQ2wqJyBi1bUaRkJsZNEY2yM5BZmokAZvNJTG7xAChg1nsmGgDmmXTAoB +DAgVUQ3iY5gvKryw31ocHEqOqFJ+6cpKL13l2aWrcnLpquPcUhsqHVFNk01D +zA2a0vcMA14gORiO4QU9LfNPFRVQUoFC18dDU1HQ0iIlNcQgDEU2Woh5PgIo +UlLHsBy3S1KVxPBfIWLdg7xCssYhRsIX75bqIZGVim1ZiAKeAQMn0EkSZteU +BR0ku1LxQ1iUEFD8PiOPF5yGuWdOf519U7NvavZNNYMOEmKhi/la2OdryCIh +dtiopsNEjpAiy2vt8R8K8/JIr9FjV2z4InwD1Wm0jxhcp59Ha8MkMmtFXhYE +ZWMMF9wJMEjCFHNtbZhA9q2nV/fWsm/HNqtx+IrycW2YcoauDU/OKbQ3/2sa +892EnEIZtMn0xaIIAIZTZXeb3N9wXxLzNEiTMJlsYBummh88pe6TcCBjGB3I +GMZjTTFPx61MhDCR6QlTxXwy3mJ+bLfy8JnHNnTWIe2SFyGCGCsrOP8Eu0xf +LBceLmUoqgtm4WGVo5jd1QsPt85SrC423DQREULPU0XgGONgH3mfHSQbKiw9 +iSXIf/Gz83TDlgmFDM+scDn0CMpLN/eV59UuaVBiG4QCW8xdtUNkpU3OAztI +6p+ojMC4XBRGGCL370m6UDvK3xPVtQM2pYQj5O/NGXqzF3T2gs5e0GroIgeP +B8v5oKj0MngO3uSy7AbIo0MQumH+Ww0DJ9K1TJXjxaCCIohxrBoZgyXDIRdP +IRluUi7tMRLaxk5Z40qViQQaKWXtC05Ka5B2tr+Y+GAOxoGsvEM6CUVZV2D+ +lPOAWUKDlvftvQMHtPuGVREsw/RcRZ/1WZF+bGP6MDlaDZlamVUVypBvfDCr +xJc/FSYOTRdv+k9IxhdrzQQuz8vGO36FG8DVvczCJ0/b/SCreEeJD77KrqE1 ++MDdpOLQbhG7N2XpOGSIRIZ0saKuzDw6Dh0s0cHdLfAr5TbDyR8HJwkjW6Fb +5/Ug0xdhcw/x7ZorDv1s2Q5mo9RDkkgkOxkF+2DOK5ktqrNFdbaoSjiYJ2Ku +qew8Ea6xPKm4vP4NYn3kfJipglbOx7AkShjF2lXMCxWey1dnTmGgeNRigfy9 +aRuemaVBzAthL1kb42RhbNj3Eif6HF2yMXw1jKwMljsxRi5E7wz9ojIYxs1I +6MW61KsxcIDhWBXm33Vk4nFx+wMQfVSw/UA6cdAI+aEj3gfjoYQDYeoQHohT +ZzgzHH/bpmxBldxu+Jrq1EHQQ37Af1FnvYsun50glXGxePbs/1BLAwQUAAIA +CACYAbYuaAdiENYQAABPvAAABwAAADczLmFuYTLtXWlv20Ya/p5fQRQFYmOT +wdwcBnGBYJvddjfrdpsWi/1kKDbXUSxLriS7sX/9vjPDY3iKong10RsgPEST +7zHX+zzDoecd5Shl8u/f3v7yX+/nd2/Ox9bkKJOVZy+PcpSjHKWdPPPer9Zb +zzu5XG22Z4xx5SMmEYK9wEdKeOvVH5szTgLh/TG/2n48Ywqfeiezy+39bOFt +57fhGRWYM4FogJDZlQj79s8EDrzFanW3OSOnz6CxMo/6Z/j4yrtZLR/C9Xa2 +OLmc39xczJ5Wy9Vmvl2ZwxfebXi9DpdX4WJ1egpHc/gxvH7hbZ4eNk8X69XD +/OpiGT6cOJe98P765v1b7z8/vD33Tm7Cdbi1v4QbuPnFp3BxcrM+9X58753/ +9Kt3/tu7d6fer/raykvtnZ4/L/mb589fvbr8OFuDE8K19zBbP86X197bd/B8 +fVXpj+ffawe8/M7z/hWur0PvH6v5MvE69QMCTgOvU0UowrKJ17ng4HJlvc58 +DgEo97oV+9i/rpZXr7yTk29W96DeN2jzNFsswO/emffNfLl0T516b86/95Ir +U1871zoByF59s3au0u7M3ssG1L2RPZO7ThcG5yJ9eOqY9Lf5Ai5zzbldX9x6 +r7/z8KtXy/vbcD2/PPV++gVuGN3hYV7/O5Su2t+Xj+CYi/D6MVwuQP/slY5m +Os5uvYKg+gohvYmCRKLAEubnAst9JClCZmOvxSXhtJJWKG15EroX9jCNTnTi +Zh3/Etcoc6T9mr+zseD+w+/34frRe385W5pLXXuEtcdvYA8LjD0s2GVP+uw3 +16D79Wwbtn2kso9UzR6ZPvjv69X9XduH+vah/j4PrS4x0ZNFkydL+2S5/5Pz +JSlqgZMS4hSitHzlm82mjykpVvH94T7bcAvbi3D9EC4fw03sC4wwtq7gDVyB +beTxXpEv1/Q83GzDK+8d3KClLrZA4BYFoiimy0javEK7DP5Km8rZU6tH1Bqt +kMA5m3GZzbYo4tZFcZfliemz9eXH+YNuoJNuZPZ5ET7N1g8z02zrfrv402nU +yzgu3G5XC/DeSf7iLZT4W+8vHjk9bf2Yorb2DzKnT3vRt+WD9vNv9va9+Laj +R9TcrKnJ8dnYY91aW3735gWoK+2a3v+AKq1bmh+h2fpse4H7jR4l316vl1cL +6Ae2i4vt4tNmu/FWZT2Et822TAxRmm2ZAlbSMAnbMInuGiYr1o54aP2cYsxe +YvGSBJAnXOkhzOszD9T+FEKGE26iqKQnvNde8jdURn9ziG+tpO1lruBkS/7/ +Zp+2MygTvPtoOnG7XV3p/G62mV3c3YSP+bCmP3u32dBCXpnvaDmEFrI/yK7C +z+ElFNKrjiN4m+9Ui11t5DwYcq/Wpu44V8W2tHPoTleW+M/7kHUaL9QHhrt0 +WsZd5QORD22HIFbSwutkqARjEjkezs3uVludgal2foZR6M+L2bKdimYYG/5u +QwSxyAyHc0NFxPMpX6excHw1ewInfQu3r05EGfUhEdVQDewpBVlpEWqgvAA1 +cCokYgQhs6uQJBHUQESD3NRJS51kwiSjcZZRlYKWgSWEE0SYtoBAokxoMwuI +H6BAWQsITlqVOgusfIHASaEoZ0oIwRxJA0YRIhApQoAUl/gXEx8FtoRgopBq +UEI6LS0NSg5RUIQpB8uIEhRR1sgyFkAizkzJYYGSCSba1LKvohTVliiiQU0p +jd8pKy1RtAhvsoD6SDDrd6oQ37NElZeurXRQMjhwyxgc6mKmz8YlDfZ3FbaC +6Rl4YytTNwjGwXjtBiFx0kXvcoOCBtv3IzdQpFh7N6RKltWOA9TjVj34a9a4 +Xa2Xr6i+lEcoU4M4Y0jq0Gh2hcYoDCZBJfhEOJXcpDx2j8RxkR2kPWl1Wj6G +F7drp0pFJ9xqFZ3SVSv+Na5e0fE+VazCW5lKZ2+b9mjQoQmdJjJFkS+beA/q +ADa1TnuPIuF36L1U6wLI3U5VrkBBo6oIEFWdq5oqnAHHHWXh8TH7BMoqWa0t +DMN8JKFVJ6ZXCKJWhonu0vG80tnRTawzhUFwIJvrDK5Fei9AHPers5WBAPnm +0gq6pyowjRAMKjVX2cTdAlorwa2zoQ6yIZxtJUmkIjiGvyTKgXAcgvlkc//h +DrLHMkY5/S2ikPXNtBNIgErZ5CJe5FDJ9vj8+96M1mH9Ybb5mBkMtAwb9FKQ +OcCAgMVdFFdc9R43K8aIWkziQHKkueT5inioUoMVtUHej8zGkdk4MhtTYzaa +SB4/3E1xCCIRj/pCyNQgC6wgOmBQBUNHpPwAetHoegn/BmqFrTTkHso5kKQf +7JKhaCJJVxj3gr5GHaAX9FP0QSOhket5HisSOksD39tt1yzTXha4nbkvkOLN +rSC+hFGXpsoIUvFMNIbpoIZYmVCX7kpd7a1msgKO/BhTYbDnsFkZSAWSIp3M +sSDBUszlw3s/Xx1kgKARQmZjFaPSzxBMmWIkGBJwud2OURnytlSELE+eNbSP +Cj0LyMQpriXUx8M2s0XpnzdrLgcxbM3lcC7ODStcCIk+TopAElCdyQwU1Byh +J3t7bO8ROig2+ZYRm6l9OOEPhg1NLihBjw/sx2uFAi1wfyUrlk68lgfxqIIW +zaB4sEcwCookNpGq0K8GknAYR8Nf6V2RDI8PpSqsdEpg7vZHkcCB8R2WiNjx +KldlbxGUekUwyCyE8YqAIR9tRW/Wy1dN5uQjl5nlLXwJJVm/GiB8nyQThd2Y +FShpQikzNKqehwy7HGHafcysOMSpcolTlSVOlSVOlUOcqgNZHVdKaFWVupBD +vqsnWhMhoKkrYZdLXUghJwoC60IY1rKDadXdJhTr7EHKS6s8/JnE/Spv5ViL +K6ULwpb4nJh5N3bP755yrJK0ks9zbO68QObOEy53nqVy5x0wufVSbAXmh9K8 +hEczU7TPYYzUF3daZ1InJLA1xLJmkJFiMrAhqTkdUMRck05E28Khn4sHJEMw +gOUmHU4ga4vMC4AQJxiy90x6N5HJ0cv1MhT5zKAOSVv0DGk7fqCsfJXUdL10 +RVzrkGuUX2Ilkok+QxLX9TJRDLwoR9L7SHofSe8j6d1SeqTEMYwhoX2HEbKI +e4TBGfF6acGXnzkvDYqRCPN6OZROZ5Ihrt9UMtuxGcQa+w4h2ylHVL/LBI4R +Cd07CtleL3+aYYgrvRL1GBEf6ZkSeFyavl4OJPGhbCqDM7KE5Z5SFXSle4of +m5fFNMMUV+UJMPz1MiX+v14Gmh1QLz3NHUjWChp+7kC95F8VHkmpkWPfNb/u +jzcroV5y4eajqdPPjIZCNRtiRkO9DODx4kphmMNgU89Fo1goFMTDTodDFKIA +SWPBIw5Z73KE47ehAzYs4fQwzxJOcJwjnOBMRDjp3xzCCQ4HJ5we5onjCZYE +KWZfVRKl01CKjoe/UZAjKOt4SEzjmcJDOD61q7i+3iHWSGuNnlRDhrYmtSm7 +dJ9jjwwI/J/aQ+sNoojqhghLDQ0nUzLYKIBwobY7ZhEpkb+PWaa6Y0kxc5LN +EXHuPz0JFeu2CB/CRRUNJTEx9V1Q/W5G0Chemr7Qb9NBtLAQ6VIVY0bLypGJ +KkgpENQm6pjayUBKUWiBgriKQtI5jayzDATKVIHpwEBHNurIRh3ZqCMb1VLy +CWtZR5/nowh33nyH/SAFimh+NUqk9Io+0llKjSufTgk+HnL5yMMlD3MLyEqk +7n3N1npY8oQiFHmKUK+spFNou50e0F0+2YXb+f5NjWS+MGSTUhyGJdH1jA47 +R7CJ/InGGa7UNxrVhBMRNJmx6RNMqhgnPTrU69BBYqB85/Kpha9A/GJp7LTb +aGaqEPF0Vhbkyyn4w9dTLM12epXRldqY53mnpg4gkApBvWaYJ4sNCTn6HMR6 +2cU8NZy7kDBUZ560w4X0hJ8/QfDpkcTqnMQiuOx9QZOFTqLkTYTEikW7/938 +dp6MBqGT9c3C1Srn6vwoEJvPduDkqx3Tc3UefdzHNG5ME1M1zYrDRFyt7lbL +7XRUK10IfPO0WGwXD4uLzdPt4mlzER8Xhxs66VrMnvRwY56bNweJx87w6bUN +4H827fBZya7enh8ofkujrqU0h4Pf2Vh9yJdFg0fdhj+9EpPrMPAXRoPnew8q +1XgmWunc42WktzCrQ2vSWybpEycBq8HXfQpDa6InddndhOQMuoZeskvkZjju +6ER+idyI5Y5/dZfI7ZTnLl8uN0NriwA6bksEM0SbuZZhqlBgKCufBCLFtTp3 +bWpGGYndXndsdVfp9yv70j21IE9ZJ9pLpZLvyGnt6zh4UN8CO7ALeVUy6OKM ++73njCUEdWIE0QtPB3sYQQJjBOZ+AlANYoSVSdPRB5DPfmBoSGc5t9pYCEXM +Z0UJpoGeKeAPHggrXz3TXMkr7xtQKc0bMEpohiJ+n1qPzMaAlCYL7h4p4yNl +fKSMj5RxI+mZIIZBnOELfImCuL0elSCeMh1cRv7qzzXYbcKL4ipeVEQDVrsd +m2+qpHr1ugZNTSKKIyr1KIEnSa5ktM/loZrIZPt+V/qmcXE0vdhHnE+GxW3I +2fqVlKViyNfvIJjt2HUob1lbhrbS3OjVQMERDmKClgeTsNfKPnRs9dLrU2Zj +R0DPh1lq2CRmIxShwZYdLpODWFTDPCTfnBnZjQdwptSUh2SZtJENsTIZhnRc +PtS+5InVlEJjZQf76e9gPwd6DXzQ1nowZnPY2OcaaDHQw79Q1rKFNwtch7Kf +BVTpwkKVICz3zfckzabt8NhdYxwyEYdTtMdZnkKf0Yxi9FtMZtjDw75qa+7h +eMG8fQxeyHdxZV7g5tsyycpNbZOEcv5vT1WoVaWTfKVI56XKRHmeqlWGWGVI +d8lTSXmNNOKNNMJWo86n4I5MtLWk0qImTiFGGjiP2GJODizmdTach5tteOW9 +gxtPUkcrVbRKHvaJ4d2nGGaOcaAUAo9x42pIvoylSFYaT9Dm3MV5LLzNY4ra +ZkiNAtnRob4tH7Sff7O378W3HT2i5mZNTY7P5nmLbqwtv3vzAtSVdk3v3/m0 +nep2K12mgVQh27q9st02GQBmrE86t4tPm+1mJ6jIk8lQpApP1ObY/p902P/X +SzZxLJn38PrMS2HCWtyQyhg37P/jzBWApgNE8jwyKfIngl6QyorCUs4eXNzd +hI/70AsS8fyYVidXS/iztRd+Di+h1l4NU1hu63rvrluLHR7NHpX6tJyNlYjw +PEJLh3Bott5V0WDb7Jkc955OStk601F6UHZc3rcX1OhwFH+AOpd/yalrbGQ/ +vH0Ag/eCzQdq9AZFv4fGtwfzoZUdMDUhO3Bq0LlCx8InWqCnlHrZaBhORcu2 +Vs871otp6bnKZptbT7DWJ2nJeJhnoDhz6AIZ5oQG4uwvMdZhjnbBcEWoQv+Z +Y6keNZoP+DWxVK+mrbcC72NpqknxU0X7KhC5mu/l6rwa2U8MJSrE0+WJX62D +CAyqZba0rQ5OaLLFLlIkWQq0XhHmW0WYOkwRKyNgagfhaEykn7aq85MyS6Vo +P+XJt0OR0co0dA/VWKQa7041K0fU7IiaHVGzrxk1q0fK0m6jcrkfhc0qInrT +efOUqtghOkarZ9sRu8Z2hz1AUaaPh+2BgQ06XW8U4MstIH5gyHW9Ga6I9IqC +jYF8ZTxKTeMBm74q3eRhsOGhr87grs6XBLITVXv7CFMfaNchM0qFmaMkemtL +DpgjKkxPKBJkox+WqGfca9y5nNQsTUST8VOfRFs3sNevqy2ov75fagteeVRg +rvQ7vd7tJrx8dkKj2R6nz579H1BLAwQUAAIACABPu7UufSgHXC0DAAAAEgAA +CAAAAHNsb3cuc3Fs3VhZb9swDH7fr+BbnM0z7DTpgcUFsjXdlTWD22DYk+G2 +aqrEx2CrBuJfP8qSbSlNj2Hu+SSREmny4ydK8PF4Mv50Amd0uYTRcTn6QWFC +ROMkI3NTaOgyiQ0+6/JNpehz0awMEtxNWWICruQkZUFo6CtdxbtUfZfWEZnH +JCcFyUobE+WUxOckTLoYRy2YkBVBGJZfabTc7Z8gZTFJ+YY8K/w0yem5jy4N +xZOyjy/hp5MgJNkZMZYkJUxsIxlG5y9IaCzTrtnplFbaOiaY1mE3iETEBBqz +fpIacqjdXzqm3TUbsYeiKm9xmfu4pKdBxgJ2lSH8OfUjrsxphlnTOYIW5gHP +UOgrKEIELiQxIpKKBREow+jieEXLCuLIEp/MVyQOuUzPEzRfKpo6GtRHoc8/ +jlHBu/UF/nW+IAKIwqDgMdWbYhL5N3poFhUvtZJ7gkNv+gOMY8HIt+vcEuQA +taa6gS7K3TWNbyq3jISXFW5gmyypUiBRMAc3XUWGZIPPqW+gE0niCv96Rjni +XFMZoF9BIUGAsoRlDnUYGCEjDEefpDmJVyQD+PVl7I3BcR2A0dFBHabr2LZU +dXq2vWXZA8vZszpDF+0XBBFEY77aiMN6Y2/b6gjbi2DBArdfztFx8Cdhw/1d +gM/edPYTPv5ex3UzYusgQ5Pg0ehk5o0mcDibTGA6Oxl78G369egJy9hrt4wl +99Hetuz6oIgDUan0cwIiYe1EP2XVDVl2dxumXsUBd0cVHAS7FUaU+T8/Rmy1 +y4iy4a0zQiivMaJs8M+VEX2VBANV2GuJEFkR3oMRzaWyItVd815T8lZT3TH6 +9ff/bFLzASWja5S5ky+SUxsoU+UArVwIm0rNOXFrx1cY1LecXQsAOVTjU+F3 +Si7Igr/dRKAabDKyoHDX0cSHnc7OlugjYHuEjvJYHGjzgrgXC/7pCnipFMnp +nRRpWEA3tBiqdZjrD+qXQTD6QD3Gbe6TwStsMvRePeb51vyBesotVX/NTQWg +wbWcsV0x7IhhWww9MThiGMgQ+fEb7tscA14VOeVvQDnVHy+oFPZKZabeAVJP +hq/9XKkz0f57aAl8ePMXUEsBAhQAFAACAAgABH62LtFp5XfkCAAAA04AAAYA +AAAAAAAAAAAgAAAAAAAAADcyLmFuYVBLAQIUABQAAgAIADe4tS4AVxb7Dg8A +APm7AAAGAAAAAAAAAAAAIAAAAAgJAAA3My5hbmFQSwECFAAUAAIACACYAbYu +aAdiENYQAABPvAAABwAAAAAAAAAAACAAAAA6GAAANzMuYW5hMlBLAQIUABQA +AgAIAE+7tS59KAdcLQMAAAASAAAIAAAAAAAAAAAAIAAAADUpAABzbG93LnNx +bFBLBQYAAAAABAAEANMAAACILAAAAAA= + +------=_NextPart_000_007E_01C3207E.D11CF590-- + + +From pgsql-performance-owner@postgresql.org Thu May 22 13:17:12 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (unknown [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id ACBB2925BAA + for ; + Thu, 22 May 2003 13:17:07 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 45615-07 for ; + Thu, 22 May 2003 13:17:05 -0400 (EDT) +Received: from sss.pgh.pa.us (unknown [192.204.191.242]) + by developer.postgresql.org (Postfix) with ESMTP id 884E1925BCD + for ; + Thu, 22 May 2003 12:02:40 -0400 (EDT) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h4MG2cU6019627; + Thu, 22 May 2003 12:02:38 -0400 (EDT) +To: "=?iso-8859-2?B?U1rbQ1MgR+Fib3I=?=" +Cc: pgsql-performance@postgresql.org, TIR@yahoogroups.com +Subject: Re: ugly query slower in 7.3, even slower after vacuum full analyze +In-reply-to: <008101c3206e$0dc8a310$0403a8c0@fejleszt4> +References: <008101c3206e$0dc8a310$0403a8c0@fejleszt4> +Comments: In-reply-to "=?iso-8859-2?B?U1rbQ1MgR+Fib3I=?=" + message dated "Thu, 22 May 2003 16:25:54 +0200" +Date: Thu, 22 May 2003 12:02:37 -0400 +Message-ID: <19626.1053619357@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/211 +X-Sequence-Number: 1990 + +"=?iso-8859-2?B?U1rbQ1MgR+Fib3I=?=" writes: +> This is a rather nasty query, built up from several parameters, and it +> proved to be 7--15 times slower in 7.3 than in 7.2. + +I think you are running into the same subselect-in-targetlist +shortcoming as Eugene Fokin did: +http://archives.postgresql.org/pgsql-performance/2003-05/msg00204.php + + regards, tom lane + +From pgsql-performance-owner@postgresql.org Thu May 22 14:06:41 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (unknown [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 6814E925CAA + for ; + Thu, 22 May 2003 14:06:39 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 67984-01 for ; + Thu, 22 May 2003 14:06:06 -0400 (EDT) +Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) + by developer.postgresql.org (Postfix) with ESMTP id 9F017925923 + for ; + Thu, 22 May 2003 12:32:30 -0400 (EDT) +Received: from [63.195.55.98] (HELO spooky) + by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) + with ESMTP id 3056055; Thu, 22 May 2003 09:32:32 -0700 +Content-Type: text/plain; + charset="iso-8859-2" +From: Josh Berkus +Organization: Aglio Database Solutions +To: "=?iso-8859-2?q?SZ=DBCS?= =?iso-8859-2?q?=20G=E1bor?=" + , +Subject: Re: ugly query slower in 7.3, even slower after vacuum full analyze +Date: Thu, 22 May 2003 09:31:06 -0700 +User-Agent: KMail/1.4.3 +Cc: +References: <008101c3206e$0dc8a310$0403a8c0@fejleszt4> +In-Reply-To: <008101c3206e$0dc8a310$0403a8c0@fejleszt4> +MIME-Version: 1.0 +Content-Transfer-Encoding: 8bit +Message-Id: <200305220931.06110.josh@agliodbs.com> +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/212 +X-Sequence-Number: 1991 + +Szucs, + +> This is a rather nasty query, built up from several parameters, and it +> proved to be 7--15 times slower in 7.3 than in 7.2. This particular query +> takes more than 3.5 minutes (4 after vacuum full analyze! (henceforth VFA)) +> that is unacceptable in an interactive client application. + +Please read the list archives for the last 3-4 days. Another user reported a +"slow query" problem with 7.3.2; please see if it sounds like yours. + +-- +Josh Berkus +Aglio Database Solutions +San Francisco + +From pgsql-performance-owner@postgresql.org Thu May 22 14:14:03 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (unknown [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 1E263925727 + for ; + Thu, 22 May 2003 14:13:48 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 69047-07 for ; + Thu, 22 May 2003 14:13:08 -0400 (EDT) +Received: from mail.deltav.hu (unknown [213.163.0.192]) + by developer.postgresql.org (Postfix) with ESMTP id 353D3925872 + for ; + Thu, 22 May 2003 12:34:02 -0400 (EDT) +Received: from fejleszt4 ([213.163.10.103]) by mail.deltav.hu + (Netscape Messaging Server 3.6) with SMTP id AAAA01 + for ; + Thu, 22 May 2003 18:34:00 +0200 +Message-ID: <012e01c3207f$c80b3920$0403a8c0@fejleszt4> +From: "=?iso-8859-2?B?U1rbQ1MgR+Fib3I=?=" +To: +References: <008101c3206e$0dc8a310$0403a8c0@fejleszt4> + <19626.1053619357@sss.pgh.pa.us> +Subject: Re: ugly query slower in 7.3, even slower after vacuum full analyze +Date: Thu, 22 May 2003 18:32:48 +0200 +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-2" +Content-Transfer-Encoding: 7bit +X-Priority: 3 +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook Express 6.00.2800.1158 +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/213 +X-Sequence-Number: 1992 + +Dear Tom, (or anyone who followed the belowmentioned thread) + +I read that thread (more-or-less), but couldn't have noticed the same +symptoms in my analyze output. So, to summarize my reading on this (please +confirm or fix): + +* The symptom is the differing width in 7.2 and 7.3 + +* This causes more hdd work, that takes lots of time (indeed, the hdd was +going crazy) + +* The query is probably good as it is; it's 7.3 that's slow (but more +reliable than 7.2) and 7.4 will most likely fix the problem. + +If all these are correct, that's enough info to me. Hopefully it'll move +from a Cel333 (the developers' server) to an IBM 2x2.4 Xeon with 5-HDD SCSI +Raid (the business server). + +G. +------------------------------- cut here ------------------------------- +----- Original Message ----- +From: "Tom Lane" +Sent: Thursday, May 22, 2003 6:02 PM +Subject: Re: [PERFORM] ugly query slower in 7.3, even slower after vacuum +full analyze + + +> "=?iso-8859-2?B?U1rbQ1MgR+Fib3I=?=" writes: +> > This is a rather nasty query, built up from several parameters, and it +> > proved to be 7--15 times slower in 7.3 than in 7.2. +> +> I think you are running into the same subselect-in-targetlist +> shortcoming as Eugene Fokin did: +> http://archives.postgresql.org/pgsql-performance/2003-05/msg00204.php +> +> regards, tom lane +> + + +From pgsql-admin-owner@postgresql.org Thu May 22 18:17:39 2003 +X-Original-To: pgsql-admin@postgresql.org +Received: from localhost (unknown [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP + id 3AB9D9259C6; Thu, 22 May 2003 18:17:37 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 64571-10; Thu, 22 May 2003 18:17:06 -0400 (EDT) +Received: from relay11.austria.eu.net (relay11.Austria.eu.net + [193.154.160.115]) by developer.postgresql.org (Postfix) with ESMTP + id 006F8925E78; Thu, 22 May 2003 16:40:47 -0400 (EDT) +Received: from sisyphus.vogelsinger.at (vogelsinger.at [193.154.189.26]) + by relay11.austria.eu.net (8.12.9/8.12.0.Beta10) with ESMTP id + h4MKekc8011660; Thu, 22 May 2003 22:40:47 +0200 +Message-Id: <5.1.1.6.2.20030522223909.05929600@mail.vogelsinger.at> +X-Sender: homebird@mail.vogelsinger.at +X-Mailer: QUALCOMM Windows Eudora Version 5.1.1 +Date: Thu, 22 May 2003 22:41:22 +0200 +To: "pgsql-admin" , + "pgsql-general" , + "pgsql-performance" +From: Ernest E Vogelsinger +Subject: Q: Structured index - which one runs faster? +Mime-Version: 1.0 +Content-Type: text/plain; charset="us-ascii" +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/316 +X-Sequence-Number: 8878 + +Hi all, + +sorry for reposting this to the lists, but I feel I posted this at the +wrong time of day, since now a lot more of you gurus are reading, and I +really need some knowledgeable input... thanks for consideration :) + + +I have a question concerning table/key layout. + +I need to store an ID value that consists of three numerical elements: + - ident1 char(5) + - ident2 char(5) + - nodeid int4 + +I need an index on these columns. Insert, delete, and lookup operations +this in this need to be as fast as possible. Now I have two options: + +(a) creating an index on all three columns, or +(b) create a single varchar column combining all three components into a +single string, like "ident1:ident2:nodeid" and indexing this column only. + +There will be a couple of million rows in this table, the values in +question are not unique. + +Which would be faster in your opinion? (a) or (b)? + +Thanks for any insight, + + +-- + >O Ernest E. Vogelsinger + (\) ICQ #13394035 + ^ http://www.vogelsinger.at/ + + + +---------------------------(end of broadcast)--------------------------- +TIP 3: if posting/reading through Usenet, please send an appropriate +subscribe-nomail command to majordomo@postgresql.org so that your +message can get through to the mailing list cleanly + +-- + >O Ernest E. Vogelsinger + (\) ICQ #13394035 + ^ http://www.vogelsinger.at/ + + + +From pgsql-performance-owner@postgresql.org Thu May 22 19:31:56 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (unknown [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 70A12925658 + for ; + Thu, 22 May 2003 19:31:55 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 83826-08 for ; + Thu, 22 May 2003 19:31:24 -0400 (EDT) +Received: from candle.pha.pa.us (momjian.navpoint.com [207.106.42.251]) + by developer.postgresql.org (Postfix) with ESMTP id B9B28923395 + for ; + Thu, 22 May 2003 17:24:17 -0400 (EDT) +Received: (from pgman@localhost) + by candle.pha.pa.us (8.11.6/8.11.6) id h4MLNf708403; + Thu, 22 May 2003 17:23:41 -0400 (EDT) +From: Bruce Momjian +Message-Id: <200305222123.h4MLNf708403@candle.pha.pa.us> +Subject: Re: postgres on a beowulf? (AMD)opteron? +In-Reply-To: +To: "scott.marlowe" +Date: Thu, 22 May 2003 17:23:41 -0400 (EDT) +Cc: Ron Johnson , + PgSQL Performance ML +X-Mailer: ELM [version 2.4ME+ PL99 (25)] +MIME-Version: 1.0 +Content-Transfer-Encoding: 7bit +Content-Type: text/plain; charset=US-ASCII +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/215 +X-Sequence-Number: 1994 + +scott.marlowe wrote: +> On 21 May 2003, Ron Johnson wrote: +> +> > On Tue, 2003-05-20 at 06:27, Andrew Sullivan wrote: +> > > On Mon, May 19, 2003 at 01:28:32PM -0400, george young wrote: +> > > > Has anyone run postgres on a beowulf system? +> > > +> > > Can't be done. None of the cluster systems support cross-machne +> > > shared memory (this is actually a problem for Postgres and NUMA, as +> > > well, BTW). +> > +> > VMSclusters and Tru64 clusters do, but, of course, it has to be +> > programmed for. +> > +> > And the licensing costs are pretty steep... +> +> someone was on the list last year and had gotten postgresql (sorta) +> working on mosix clusters. The performance, I recall, was less than +> stellar. + +I think they copied and locked the shared memory for each machine that +needed it. + +-- + Bruce Momjian | http://candle.pha.pa.us + pgman@candle.pha.pa.us | (610) 359-1001 + + If your life is a hard drive, | 13 Roberts Road + + Christ can be your backup. | Newtown Square, Pennsylvania 19073 + +From pgsql-admin-owner@postgresql.org Sat May 24 18:36:00 2003 +X-Original-To: pgsql-admin@postgresql.org +Received: from localhost (unknown [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP + id 37415924DEE; Thu, 22 May 2003 20:45:11 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 05120-03; Thu, 22 May 2003 20:44:40 -0400 (EDT) +Received: from mail1.ihs.com (mail1.ihs.com [170.207.70.222]) + by developer.postgresql.org (Postfix) with ESMTP + id 6852E924E2D; Thu, 22 May 2003 18:36:11 -0400 (EDT) +Received: from css120.ihs.com (css120.ihs.com [170.207.105.120]) + by mail1.ihs.com (8.12.9/8.12.9) with ESMTP id h4MMZc62002357; + Thu, 22 May 2003 16:35:38 -0600 (MDT) +Date: Thu, 22 May 2003 16:23:44 -0600 (MDT) +From: "scott.marlowe" +To: Ernest E Vogelsinger +Cc: pgsql-admin , + pgsql-general , + pgsql-performance +Subject: Re: [GENERAL] Q: Structured index - which one runs faster? +In-Reply-To: <5.1.1.6.2.20030522223909.05929600@mail.vogelsinger.at> +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-MailScanner: Found to be clean +X-MailScanner-SpamCheck: +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/351 +X-Sequence-Number: 8913 + +On Thu, 22 May 2003, Ernest E Vogelsinger wrote: + +> Hi all, +> +> sorry for reposting this to the lists, but I feel I posted this at the +> wrong time of day, since now a lot more of you gurus are reading, and I +> really need some knowledgeable input... thanks for consideration :) +> +> +> I have a question concerning table/key layout. +> +> I need to store an ID value that consists of three numerical elements: +> - ident1 char(5) +> - ident2 char(5) +> - nodeid int4 +> +> I need an index on these columns. Insert, delete, and lookup operations +> this in this need to be as fast as possible. Now I have two options: +> +> (a) creating an index on all three columns, or +> (b) create a single varchar column combining all three components into a +> single string, like "ident1:ident2:nodeid" and indexing this column only. +> +> There will be a couple of million rows in this table, the values in +> question are not unique. +> +> Which would be faster in your opinion? (a) or (b)? + +Generally speaking, b should be faster, but a should be more versatile. + + +From pgsql-admin-owner@postgresql.org Thu May 22 21:03:14 2003 +X-Original-To: pgsql-admin@postgresql.org +Received: from localhost (unknown [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP + id CBDEA925E73; Thu, 22 May 2003 21:03:07 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 17333-08; Thu, 22 May 2003 21:02:36 -0400 (EDT) +Received: from sss.pgh.pa.us (unknown [192.204.191.242]) + by developer.postgresql.org (Postfix) with ESMTP + id 428D7925E71; Thu, 22 May 2003 18:53:01 -0400 (EDT) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h4MMr1U6011952; + Thu, 22 May 2003 18:53:01 -0400 (EDT) +To: Ernest E Vogelsinger +Cc: "pgsql-admin" , + "pgsql-general" , + "pgsql-performance" +Subject: Re: Q: Structured index - which one runs faster? +In-reply-to: <5.1.1.6.2.20030522223909.05929600@mail.vogelsinger.at> +References: <5.1.1.6.2.20030522223909.05929600@mail.vogelsinger.at> +Comments: In-reply-to Ernest E Vogelsinger + message dated "Thu, 22 May 2003 22:41:22 +0200" +Date: Thu, 22 May 2003 18:53:00 -0400 +Message-ID: <11951.1053643980@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/324 +X-Sequence-Number: 8886 + +Ernest E Vogelsinger writes: +> (a) creating an index on all three columns, or +> (b) create a single varchar column combining all three components into a +> single string, like "ident1:ident2:nodeid" and indexing this column only. + +I can't imagine that (b) is a good idea ... it's dubious that you are +saving anything on the indexing, and you're sure adding a lot of space +to the table, not to mention maintenance effort, potential for bugs, +etc. + +It might be worth creating the index so that the "least non-unique" +column is mentioned first, if there's a clear winner in those terms. +That would minimize the number of times that comparisons have to look at +the additional columns. + + regards, tom lane + +From pgsql-performance-owner@postgresql.org Thu May 22 21:12:48 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (unknown [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id F3493925ECA + for ; + Thu, 22 May 2003 21:11:37 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 47847-01 for ; + Thu, 22 May 2003 21:11:05 -0400 (EDT) +Received: from megazone.bigpanda.com (megazone.bigpanda.com [63.150.15.178]) + by developer.postgresql.org (Postfix) with ESMTP id 6B703924AF6 + for ; + Thu, 22 May 2003 19:00:55 -0400 (EDT) +Received: by megazone.bigpanda.com (Postfix, from userid 1001) + id AE0A0D610; Thu, 22 May 2003 16:00:54 -0700 (PDT) +Received: from localhost (localhost [127.0.0.1]) + by megazone.bigpanda.com (Postfix) with ESMTP + id A3C355C11; Thu, 22 May 2003 16:00:54 -0700 (PDT) +Date: Thu, 22 May 2003 16:00:54 -0700 (PDT) +From: Stephan Szabo +To: Ernest E Vogelsinger +Cc: pgsql-performance +Subject: Re: [ADMIN] Q: Structured index - which one runs faster? +In-Reply-To: <5.1.1.6.2.20030522223909.05929600@mail.vogelsinger.at> +Message-ID: <20030522155056.R47562-100000@megazone23.bigpanda.com> +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/217 +X-Sequence-Number: 1996 + +On Thu, 22 May 2003, Ernest E Vogelsinger wrote: + +[response only to -performance] + +> sorry for reposting this to the lists, but I feel I posted this at the +> wrong time of day, since now a lot more of you gurus are reading, and I +> really need some knowledgeable input... thanks for consideration :) + +It just takes time. :) + +> I have a question concerning table/key layout. +> +> I need to store an ID value that consists of three numerical elements: +> - ident1 char(5) +> - ident2 char(5) +> - nodeid int4 + +This seems like a somewhat odd key layout, why char(5) for the first +two parts if they're numeric as well? + +> I need an index on these columns. Insert, delete, and lookup operations +> this in this need to be as fast as possible. Now I have two options: +> +> (a) creating an index on all three columns, or +> (b) create a single varchar column combining all three components into a +> single string, like "ident1:ident2:nodeid" and indexing this column only. +> +> There will be a couple of million rows in this table, the values in +> question are not unique. +> +> Which would be faster in your opinion? (a) or (b)? + +Generally, you're probably better off with an index on the three columns. +Otherwise either your clients need to composite the value for the varchar +column or the system does in triggers for insert/update. + +Also, what kinds of lookups are you going to be doing? Only lookups based +on all three parts of the key or will you ever be searching based on parts +of the keys? + + +From pgsql-performance-owner@postgresql.org Thu May 22 21:47:19 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (unknown [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 2AD00925926 + for ; + Thu, 22 May 2003 21:47:16 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 46243-06 for ; + Thu, 22 May 2003 21:46:45 -0400 (EDT) +Received: from relay11.austria.eu.net (relay11.Austria.eu.net + [193.154.160.115]) + by developer.postgresql.org (Postfix) with ESMTP id BCF61925FE1 + for ; + Thu, 22 May 2003 19:35:47 -0400 (EDT) +Received: from sisyphus.vogelsinger.at (vogelsinger.at [193.154.189.26]) + by relay11.austria.eu.net (8.12.9/8.12.0.Beta10) with ESMTP id + h4MNZbc8027968; Fri, 23 May 2003 01:35:42 +0200 +Message-Id: <5.1.1.6.2.20030523012954.0400a730@mail.vogelsinger.at> +X-Sender: homebird@mail.vogelsinger.at +X-Mailer: QUALCOMM Windows Eudora Version 5.1.1 +Date: Fri, 23 May 2003 01:36:14 +0200 +To: Stephan Szabo +From: Ernest E Vogelsinger +Subject: Re: [ADMIN] Q: Structured index - which one runs faster? +Cc: pgsql-performance +In-Reply-To: <20030522155056.R47562-100000@megazone23.bigpanda.com> +References: <5.1.1.6.2.20030522223909.05929600@mail.vogelsinger.at> +Mime-Version: 1.0 +Content-Type: text/plain; charset="us-ascii" +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/219 +X-Sequence-Number: 1998 + +Thanks for replying :) + +At 01:00 23.05.2003, Stephan Szabo said: +--------------------[snip]-------------------- +>On Thu, 22 May 2003, Ernest E Vogelsinger wrote: +> +>> I need to store an ID value that consists of three numerical elements: +>> - ident1 char(5) +>> - ident2 char(5) +>> - nodeid int4 +> +>This seems like a somewhat odd key layout, why char(5) for the first +>two parts if they're numeric as well? + +It's not odd - ident1 and ident2 are in fact logical identifiers that _are_ +character values, no numbers. + +>Generally, you're probably better off with an index on the three columns. +>Otherwise either your clients need to composite the value for the varchar +>column or the system does in triggers for insert/update. + +This table will be used by a PHP library accessing it - no direct client +intervention (except the developers and they should know what they're doing ;-) + +>Also, what kinds of lookups are you going to be doing? Only lookups based +>on all three parts of the key or will you ever be searching based on parts +>of the keys? + +Hmm. Yes, lookups on parts of the keys will be possible, but only from left +to right, ident1 having the highest precedence, followed by ident2 and +finally by nodeid. + +These columns will never be modified once inserted. The only operations +these columns will be affected are insert and delete, and lookup of course. +I'm not so concerned with delete since this will not happen too often, but +inserts will, and lookups of course permanently, and both operations must +be as fast as possible, even with gazillions of rows... + + + +-- + >O Ernest E. Vogelsinger + (\) ICQ #13394035 + ^ http://www.vogelsinger.at/ + + + +From pgsql-admin-owner@postgresql.org Thu May 22 21:51:24 2003 +X-Original-To: pgsql-admin@postgresql.org +Received: from localhost (unknown [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 8B5C1925FA9 + for ; Thu, 22 May 2003 21:51:22 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 56042-01 for ; + Thu, 22 May 2003 21:50:51 -0400 (EDT) +Received: from relay11.austria.eu.net (relay11.Austria.eu.net + [193.154.160.115]) + by developer.postgresql.org (Postfix) with ESMTP id A4F3192595E + for ; Thu, 22 May 2003 19:42:31 -0400 (EDT) +Received: from sisyphus.vogelsinger.at (vogelsinger.at [193.154.189.26]) + by relay11.austria.eu.net (8.12.9/8.12.0.Beta10) with ESMTP id + h4MNgUc8028539; Fri, 23 May 2003 01:42:30 +0200 +Message-Id: <5.1.1.6.2.20030523013910.03095bb8@mail.vogelsinger.at> +X-Sender: homebird@mail.vogelsinger.at +X-Mailer: QUALCOMM Windows Eudora Version 5.1.1 +Date: Fri, 23 May 2003 01:43:06 +0200 +To: Tom Lane +From: Ernest E Vogelsinger +Subject: Re: Q: Structured index - which one runs faster? +Cc: "pgsql-admin" +In-Reply-To: <11951.1053643980@sss.pgh.pa.us> +References: <5.1.1.6.2.20030522223909.05929600@mail.vogelsinger.at> + <5.1.1.6.2.20030522223909.05929600@mail.vogelsinger.at> +Mime-Version: 1.0 +Content-Type: text/plain; charset="us-ascii" +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/325 +X-Sequence-Number: 8887 + +At 00:53 23.05.2003, Tom Lane said: +--------------------[snip]-------------------- +>Ernest E Vogelsinger writes: +>> (a) creating an index on all three columns, or +>> (b) create a single varchar column combining all three components into a +>> single string, like "ident1:ident2:nodeid" and indexing this column only. +> +>I can't imagine that (b) is a good idea ... it's dubious that you are +>saving anything on the indexing, and you're sure adding a lot of space +>to the table, not to mention maintenance effort, potential for bugs, +>etc. +> +>It might be worth creating the index so that the "least non-unique" +>column is mentioned first, if there's a clear winner in those terms. +>That would minimize the number of times that comparisons have to look at +>the additional columns. +--------------------[snip]-------------------- + +Thanks for replying :) + +Do you know if there's a general performance difference between numeric +(int4) and character (fixed-size char[5]) columns? The ident1 and ident2 +columns are planned to be char[5], only the third column (with least +precedence) will be numeric. + +The application is still in the design phase, so I still could fiddle +around that and make that char[5] numeric with an additional mapping +(@runtime, not in the DB) if this will increase performance. + +Thanks, + +-- + >O Ernest E. Vogelsinger + (\) ICQ #13394035 + ^ http://www.vogelsinger.at/ + + + +From pgsql-admin-owner@postgresql.org Thu May 22 22:08:19 2003 +X-Original-To: pgsql-admin@postgresql.org +Received: from localhost (unknown [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 3DC549251D9 + for ; Thu, 22 May 2003 22:08:18 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 72058-04 for ; + Thu, 22 May 2003 22:07:47 -0400 (EDT) +Received: from sss.pgh.pa.us (unknown [192.204.191.242]) + by developer.postgresql.org (Postfix) with ESMTP id BB34D925747 + for ; Thu, 22 May 2003 20:00:14 -0400 (EDT) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h4N00EU6012260; + Thu, 22 May 2003 20:00:14 -0400 (EDT) +To: Ernest E Vogelsinger +Cc: "pgsql-admin" +Subject: Re: Q: Structured index - which one runs faster? +In-reply-to: <5.1.1.6.2.20030523013910.03095bb8@mail.vogelsinger.at> +References: <5.1.1.6.2.20030522223909.05929600@mail.vogelsinger.at> + <5.1.1.6.2.20030522223909.05929600@mail.vogelsinger.at> + <5.1.1.6.2.20030523013910.03095bb8@mail.vogelsinger.at> +Comments: In-reply-to Ernest E Vogelsinger + message dated "Fri, 23 May 2003 01:43:06 +0200" +Date: Thu, 22 May 2003 20:00:14 -0400 +Message-ID: <12259.1053648014@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/326 +X-Sequence-Number: 8888 + +Ernest E Vogelsinger writes: +> Do you know if there's a general performance difference between numeric +> (int4) and character (fixed-size char[5]) columns? The ident1 and ident2 +> columns are planned to be char[5], only the third column (with least +> precedence) will be numeric. + +int4 is certainly faster to compare than char(n), but I wouldn't contort +your database design on that basis... if the idents aren't naturally +integers, don't force them to be. + + regards, tom lane + +From pgsql-performance-owner@postgresql.org Fri May 23 05:12:52 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (unknown [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 19A2C923380 + for ; + Fri, 23 May 2003 05:12:51 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 73560-10 for ; + Fri, 23 May 2003 05:12:18 -0400 (EDT) +Received: from megazone.bigpanda.com (megazone.bigpanda.com [63.150.15.178]) + by developer.postgresql.org (Postfix) with ESMTP id B047B925533 + for ; + Fri, 23 May 2003 02:42:37 -0400 (EDT) +Received: by megazone.bigpanda.com (Postfix, from userid 1001) + id 81772D60C; Thu, 22 May 2003 23:42:36 -0700 (PDT) +Received: from localhost (localhost [127.0.0.1]) + by megazone.bigpanda.com (Postfix) with ESMTP + id 772555C11; Thu, 22 May 2003 23:42:36 -0700 (PDT) +Date: Thu, 22 May 2003 23:42:36 -0700 (PDT) +From: Stephan Szabo +To: Ernest E Vogelsinger +Cc: pgsql-performance +Subject: Re: [ADMIN] Q: Structured index - which one runs faster? +In-Reply-To: <5.1.1.6.2.20030523012954.0400a730@mail.vogelsinger.at> +Message-ID: <20030522233646.Y58014-100000@megazone23.bigpanda.com> +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/220 +X-Sequence-Number: 1999 + + +On Fri, 23 May 2003, Ernest E Vogelsinger wrote: + +> Thanks for replying :) +> +> At 01:00 23.05.2003, Stephan Szabo said: +> --------------------[snip]-------------------- +> >On Thu, 22 May 2003, Ernest E Vogelsinger wrote: +> > +> >> I need to store an ID value that consists of three numerical elements: +> >> - ident1 char(5) +> >> - ident2 char(5) +> >> - nodeid int4 +> > +> >This seems like a somewhat odd key layout, why char(5) for the first +> >two parts if they're numeric as well? +> +> It's not odd - ident1 and ident2 are in fact logical identifiers that _are_ +> character values, no numbers. + +The reason I mentioned it is that the original said, "three numerical +elements" ;) + +> >Also, what kinds of lookups are you going to be doing? Only lookups based +> >on all three parts of the key or will you ever be searching based on parts +> >of the keys? +> +> Hmm. Yes, lookups on parts of the keys will be possible, but only from left +> to right, ident1 having the highest precedence, followed by ident2 and +> finally by nodeid. + +The multi-column index helps for those as well, as long as you put the +columns in the precedence order. If they're ordered ident1,ident2,nodeid +then it'll potentially use it for searches on ident1 or ident1 and ident2 +if it thinks that the condition is selective enough. + + +From pgsql-general-owner@postgresql.org Fri May 23 11:45:53 2003 +X-Original-To: pgsql-general@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 961E792356A + for ; + Fri, 23 May 2003 11:45:50 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 68116-10 for ; + Fri, 23 May 2003 11:45:41 -0400 (EDT) +Received: from lorax.kciLink.com (lorax.kciLink.com [206.112.95.1]) + by developer.postgresql.org (Postfix) with ESMTP id 406EA924F62 + for ; + Fri, 23 May 2003 11:09:12 -0400 (EDT) +Received: from localhost (localhost [127.0.0.1]) + by lorax.kciLink.com (Postfix) with ESMTP id 03E7F3E37 + for ; + Fri, 23 May 2003 11:09:11 -0400 (EDT) +Received: from lorax.kciLink.com ([127.0.0.1]) + by localhost (lorax.kciLink.com [127.0.0.1]) (amavisd-new, port 10024) + with SMTP id 07972-09 for ; + Fri, 23 May 2003 11:09:00 -0400 (EDT) +Received: by lorax.kciLink.com (Postfix, from userid 8) + id A90CD3E8E; Fri, 23 May 2003 11:09:00 -0400 (EDT) +To: pgsql-general@postgresql.org +Path: not-for-mail +From: Vivek Khera +Newsgroups: ml.postgres.general +Subject: Re: [ADMIN] Q: Structured index - which one runs faster? +Date: 23 May 2003 11:09:00 -0400 +Organization: Khera Communications, Inc., Rockville, MD +Lines: 27 +Message-ID: +References: <5.1.1.6.2.20030522223909.05929600@mail.vogelsinger.at> + <11951.1053643980@sss.pgh.pa.us> +NNTP-Posting-Host: yertle.kcilink.com +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Trace: lorax.kciLink.com 1053702540 30602 216.194.193.105 (23 May 2003 + 15:09:00 GMT) +X-Complaints-To: daemon@kciLink.com +NNTP-Posting-Date: Fri, 23 May 2003 15:09:00 +0000 (UTC) +User-Agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Portable Code) +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/915 +X-Sequence-Number: 42570 + +A related question: + +Are any of these indexes redundant: + + CREATE UNIQUE INDEX user_list_id_email ON user_list (owner_id,user_email); + CREATE INDEX user_list_owner_id ON user_list (owner_id); + CREATE INDEX user_list_oid_created ON user_list (owner_id,user_created); + +In particular, is user_list_owner_id redundant to +user_list_oid_created? Will the latter be used for queries such as + + SELECT user_fname from user_list where owner_id=34 + +If so, I can drop the owner_id index. the _id columns are integers, +created is a datetime, and email is a string. owner_id is also a +foreign key into the owners table (via REFERENCES), if that matters. + +I'd try it out by dropping the index, but reindexing it takes a *LONG* +time which I cannot afford to be unavailable. + +Thanks. + +-- +=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +Vivek Khera, Ph.D. Khera Communications, Inc. +Internet: khera@kciLink.com Rockville, MD +1-240-453-8497 +AIM: vivekkhera Y!: vivek_khera http://www.khera.org/~vivek/ + +From pgsql-performance-owner@postgresql.org Fri May 23 12:50:58 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id AEA35923531 + for ; + Fri, 23 May 2003 12:50:52 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 07790-08 for ; + Fri, 23 May 2003 12:50:43 -0400 (EDT) +Received: from mail1.ihs.com (mail1.ihs.com [170.207.70.222]) + by developer.postgresql.org (Postfix) with ESMTP id D8453924E1B + for ; + Fri, 23 May 2003 12:26:51 -0400 (EDT) +Received: from css120.ihs.com (css120.ihs.com [170.207.105.120]) + by mail1.ihs.com (8.12.9/8.12.9) with ESMTP id h4NGPl62007594; + Fri, 23 May 2003 10:25:47 -0600 (MDT) +Date: Fri, 23 May 2003 10:13:47 -0600 (MDT) +From: "scott.marlowe" +To: Shridhar Daithankar +Cc: +Subject: Re: postgres on a beowulf? (AMD)opteron? +In-Reply-To: <200305201214.03432.shridhar_daithankar@nospam.persistent.co.in> +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-MailScanner: Found to be clean +X-MailScanner-SpamCheck: +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/222 +X-Sequence-Number: 2001 + +On Tue, 20 May 2003, Shridhar Daithankar wrote: + +> On Monday 19 May 2003 22:58, george young wrote: +> > Has anyone run postgres on a beowulf system? +> > +> > I'm shopping for a new server. One candidate would be a +> > quad opteron (64-bit AMD "hammer") machine. Another approach might +> > be a beowulf of single or dual opterons. I imagine the beowulf +> > would be a bit cheaper, and much more expandable, but what about +> > the shared memory used by the postgres backends? I gather that +> > postgres uses shared memory to coordinate (locks?) between backends? +> +> Postgresql will not run on beowulf at all since it is an MPI system and +> postgresql can no span a single database across machines (yet). Further it +> won't even run on mosix because mosix does not support shared memory across +> machines. +> +> > +> > I have a smallish DB (pgdump|bzip2 -> 10MB), with ~45 users logged in +> > using local X(python/gtk) postgres client apps. +> +> Well, you haven't put how many transactions you do, but in general for that +> sort of DB, a P-IV/512MB RAM and SCSI disk would be more than enough unless +> you are doing really exotic things with data.. +> +> > [Next question is: has anyone used postgres on an opteron at all??] +> +> Well, if it runs linux as good as anything else, postgresql will run as good +> as anything else..:-) + +Keep in mind, if what you're doing is very memory intensive, then the PIV +with it's faster memory bandwidth may be the best bet. If it's CPU +processing intensive (GIS calculations) or I/O intensive the AMD's should +be competitive, but for memory I/O speed bound apps, the P IV is still +faster. + +You'll not know which is faster until you've benchmarked it yourself under +your own load though. :-) + + +From pgsql-admin-owner@postgresql.org Sat May 24 18:35:54 2003 +X-Original-To: pgsql-admin@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP + id 36BE192506C; Fri, 23 May 2003 12:59:12 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 18064-07; Fri, 23 May 2003 12:59:03 -0400 (EDT) +Received: from djinn.gene.com (socks-open.gene.com [192.12.78.2]) + by developer.postgresql.org (Postfix) with ESMTP + id C1D069234FB; Fri, 23 May 2003 12:46:33 -0400 (EDT) +Received: from faraday.gene.com (faraday.gene.com [128.137.49.205]) + by djinn.gene.com (8.12.9/8.12.4) with ESMTP id h4NGkQuk374098; + Fri, 23 May 2003 09:46:26 -0700 (PDT) +Received: from tallac.gene.com (meitner.gene.com [128.137.49.207]) + by faraday.gene.com (Switch-3.0.4/Switch-3.0.0) with ESMTP id + h4NGkPqV023852; Fri, 23 May 2003 09:46:25 -0700 (PDT) +Subject: Re: [GENERAL] Q: Structured index - which one runs faster? +From: Reece Hart +To: Ernest E Vogelsinger +Cc: pgsql-admin , + pgsql-general , + pgsql-performance +In-Reply-To: <5.1.1.6.2.20030522223909.05929600@mail.vogelsinger.at> +References: <5.1.1.6.2.20030522223909.05929600@mail.vogelsinger.at> +Content-Type: text/plain +Organization: Genentech, Inc. +Message-Id: <1053708385.29339.26.camel@tallac> +Mime-Version: 1.0 +X-Mailer: Ximian Evolution 1.2.2 (1.2.2-5) +Date: 23 May 2003 09:46:25 -0700 +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/350 +X-Sequence-Number: 8912 + +Ernest- + +> (a) creating an index on all three columns, or +> (b) create a single varchar column combining all three components into a +> single string, like "ident1:ident2:nodeid" and indexing this column only. +> +> There will be a couple of million rows in this table, the values in +> question are not unique. + +I'd go with (a). (b) is not very flexible (e.g., lookup by ident2 +only), and any speed advantage will require knowing in advance the +optimal key order (i1:i2:n v. n:i2:i1 v. ...). I'd expect it would be +comparable to a multi-column index for speed. + +(a) can really be implemented in 3 ways: +(a1) an index of all 3 columns +(a2) an index on /each/ of 3 columns +(a3) a multi-column index AND separate indices on the others. + e.g., index (i1,i2,n), and index (i2) and index (n) + +The choice of which is fastest depends a lot on the distribution of keys +in each column and whether you need to do lookups on only one or two +columns. Again, once you choose (b), you're kinda stuck with treating +the compound key as a single entity (without incurring a big performance +hit); (a) will allow you to experiment with optimal indexing without +affecting code. + +Since it sounds like you've already got the data loaded, I (probably +others) would be interested in any timing runs you do. + +-Reece + +-- +Reece Hart, Ph.D. rkh@gene.com, http://www.gene.com/ +Genentech, Inc. 650/225-6133 (voice), -5389 (fax) +Bioinformatics and Protein Engineering +1 DNA Way, MS-93 http://www.in-machina.com/~reece/ +South San Francisco, CA 94080-4990 reece@in-machina.com, GPG: 0x25EC91A0 + + +From pgsql-general-owner@postgresql.org Fri May 23 12:59:54 2003 +X-Original-To: pgsql-general@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 18FCF9251B7 + for ; + Fri, 23 May 2003 12:59:49 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 18064-10 for ; + Fri, 23 May 2003 12:59:40 -0400 (EDT) +Received: from wolff.to (wolff.to [66.93.249.74]) + by developer.postgresql.org (Postfix) with SMTP id CE4BC925217 + for ; + Fri, 23 May 2003 12:48:21 -0400 (EDT) +Received: (qmail 11475 invoked by uid 500); 23 May 2003 16:50:20 -0000 +Date: Fri, 23 May 2003 11:50:20 -0500 +From: Bruno Wolff III +To: Vivek Khera +Cc: pgsql-general@postgresql.org +Subject: Re: [ADMIN] Q: Structured index - which one runs faster? +Message-ID: <20030523165020.GA11094@wolff.to> +Mail-Followup-To: Vivek Khera , + pgsql-general@postgresql.org +References: <5.1.1.6.2.20030522223909.05929600@mail.vogelsinger.at> + <11951.1053643980@sss.pgh.pa.us> + +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: +User-Agent: Mutt/1.5.4i +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/923 +X-Sequence-Number: 42578 + +On Fri, May 23, 2003 at 11:09:00 -0400, + Vivek Khera wrote: +> A related question: +> +> Are any of these indexes redundant: +> +> CREATE UNIQUE INDEX user_list_id_email ON user_list (owner_id,user_email); +> CREATE INDEX user_list_owner_id ON user_list (owner_id); +> CREATE INDEX user_list_oid_created ON user_list (owner_id,user_created); +> +> In particular, is user_list_owner_id redundant to +> user_list_oid_created? Will the latter be used for queries such as + +Yes. Any prefix of a multicolumn index can be used for queries. They +(prefixes) won't be usable by foreign key references because even if the +index as a whole is unique, the prefixes won't necessarily be. + +From pgsql-general-owner@postgresql.org Fri May 23 13:52:42 2003 +X-Original-To: pgsql-general@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id F009B9235DE + for ; + Fri, 23 May 2003 13:52:36 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 38612-10 for ; + Fri, 23 May 2003 13:52:15 -0400 (EDT) +Received: from sss.pgh.pa.us (unknown [192.204.191.242]) + by developer.postgresql.org (Postfix) with ESMTP id DB5B992322A + for ; + Fri, 23 May 2003 13:38:40 -0400 (EDT) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h4NHccU6017189; + Fri, 23 May 2003 13:38:38 -0400 (EDT) +To: Vivek Khera +Cc: pgsql-general@postgresql.org +Subject: Re: [ADMIN] Q: Structured index - which one runs faster? +In-reply-to: +References: <5.1.1.6.2.20030522223909.05929600@mail.vogelsinger.at> + <11951.1053643980@sss.pgh.pa.us> + +Comments: In-reply-to Vivek Khera + message dated "23 May 2003 11:09:00 -0400" +Date: Fri, 23 May 2003 13:38:37 -0400 +Message-ID: <17188.1053711517@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/925 +X-Sequence-Number: 42580 + +Vivek Khera writes: +> Are any of these indexes redundant: + +> CREATE UNIQUE INDEX user_list_id_email ON user_list (owner_id,user_email); +> CREATE INDEX user_list_owner_id ON user_list (owner_id); +> CREATE INDEX user_list_oid_created ON user_list (owner_id,user_created); + +> In particular, is user_list_owner_id redundant to +> user_list_oid_created? + +Any of the three indexes can be used for a search on owner_id alone, so +yeah, user_list_owner_id is redundant. It would be marginally faster to +use user_list_owner_id for such a search, just because it's physically +smaller than the other two indexes, but against that you have to balance +the extra update cost of maintaining the additional index. + +Also, I can imagine scenarios where even a pure SELECT query load could +find the extra index to be a net loss: if you have a mix of queries that +use two or all three indexes, and the indexes don't fit in kernel disk +cache but just one or two would, then you'll lose on extra I/O as the +indexes compete for cache space. Not sure how likely that scenario is, +but it's something to think about. + + regards, tom lane + +From pgsql-general-owner@postgresql.org Fri May 23 14:17:40 2003 +X-Original-To: pgsql-general@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 7E0E89250E8 + for ; + Fri, 23 May 2003 14:17:28 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 50078-04 for ; + Fri, 23 May 2003 14:17:19 -0400 (EDT) +Received: from yertle.kcilink.com (yertle.kcilink.com [216.194.193.105]) + by developer.postgresql.org (Postfix) with ESMTP id 81968924FFD + for ; + Fri, 23 May 2003 14:04:44 -0400 (EDT) +Received: by yertle.kcilink.com (Postfix, from userid 100) + id 998632178C; Fri, 23 May 2003 14:04:28 -0400 (EDT) +From: Vivek Khera +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Transfer-Encoding: 7bit +Message-ID: <16078.25260.512996.337914@yertle.int.kciLink.com> +Date: Fri, 23 May 2003 14:04:28 -0400 +To: pgsql-general@postgresql.org +Subject: Re: [ADMIN] Q: Structured index - which one runs faster? +In-Reply-To: <17188.1053711517@sss.pgh.pa.us> +References: <5.1.1.6.2.20030522223909.05929600@mail.vogelsinger.at> + <11951.1053643980@sss.pgh.pa.us> + + <17188.1053711517@sss.pgh.pa.us> +X-Mailer: VM 7.14 under 21.4 (patch 12) "Portable Code" XEmacs Lucid +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/926 +X-Sequence-Number: 42581 + +>>>>> "TL" == Tom Lane writes: + +>> In particular, is user_list_owner_id redundant to +>> user_list_oid_created? + +TL> Any of the three indexes can be used for a search on owner_id alone, so +TL> yeah, user_list_owner_id is redundant. It would be marginally faster to +TL> use user_list_owner_id for such a search, just because it's physically +TL> smaller than the other two indexes, but against that you have to balance +TL> the extra update cost of maintaining the additional index. + +This is great info. That extra index is gonna be nuked in about 37.23 +seconds... It takes up a lot of space and is wasting time with +updates and inserts, which happen a *lot* on that table (nearly 10 +million rows). + +Thanks! + + +From pgsql-general-owner@postgresql.org Fri May 23 14:32:45 2003 +X-Original-To: pgsql-general@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id EDEA6924FCF + for ; + Fri, 23 May 2003 14:32:41 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 68262-06 for ; + Fri, 23 May 2003 14:32:39 -0400 (EDT) +Received: from email02.aon.at (WARSL402PIP7.highway.telekom.at [195.3.96.94]) + by developer.postgresql.org (Postfix) with SMTP id 93D66925324 + for ; + Fri, 23 May 2003 14:30:39 -0400 (EDT) +Received: (qmail 415092 invoked from network); 23 May 2003 18:30:37 -0000 +Received: from m170p012.dipool.highway.telekom.at (HELO cantor) + ([62.46.11.44]) (envelope-sender ) + by qmail2rs.highway.telekom.at (qmail-ldap-1.03) with SMTP + for ; 23 May 2003 18:30:37 -0000 +From: Manfred Koizar +To: Vivek Khera +Cc: pgsql-general@postgresql.org +Subject: Re: [ADMIN] Q: Structured index - which one runs faster? +Date: Fri, 23 May 2003 20:30:03 +0200 +Message-ID: +References: <5.1.1.6.2.20030522223909.05929600@mail.vogelsinger.at> + <11951.1053643980@sss.pgh.pa.us> + +In-Reply-To: +X-Mailer: Forte Agent 1.93/32.576 English (American) +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/927 +X-Sequence-Number: 42582 + +On 23 May 2003 11:09:00 -0400, Vivek Khera wrote: +> CREATE UNIQUE INDEX user_list_id_email ON user_list (owner_id,user_email); +> CREATE INDEX user_list_owner_id ON user_list (owner_id); +> CREATE INDEX user_list_oid_created ON user_list (owner_id,user_created); +> +>In particular, is user_list_owner_id redundant to +>user_list_oid_created? + +In theory yes, but in practice it depends ... + +> Will the latter be used for queries such as +> +> SELECT user_fname from user_list where owner_id=34 + +All other things being equal, the planner tends to estimate higher +costs for the multi column index. This has to do with its attempt to +adjust correlation for the additional index columns. So unless the +physical order of tuples is totally unrelated to owner_id, I'd expect +it to choose the single column index. + +>If so, I can drop the owner_id index. + +If the planner estimates the cost for an user_list_id_email or +user_list_oid_created index scan lower than for a seq scan, you will +notice no difference. + +But under unfortunate circumstances it might choose a seq scan ... + +Servus + Manfred + +From pgsql-hackers-owner@postgresql.org Fri May 23 16:34:55 2003 +X-Original-To: pgsql-hackers@postgreSQL.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id DB6EA925435 + for ; + Fri, 23 May 2003 16:34:53 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 17776-08 for ; + Fri, 23 May 2003 16:34:53 -0400 (EDT) +Received: from sss.pgh.pa.us (unknown [192.204.191.242]) + by developer.postgresql.org (Postfix) with ESMTP id B4F4C92542E + for ; + Fri, 23 May 2003 16:34:52 -0400 (EDT) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h4NKYnU6018327; + Fri, 23 May 2003 16:34:49 -0400 (EDT) +To: Stephan Szabo +Cc: pgsql-hackers@postgreSQL.org +Subject: Simplifying varchar and bpchar behavior +In-reply-to: <20030513123355.B29586-100000@megazone23.bigpanda.com> +References: <20030513123355.B29586-100000@megazone23.bigpanda.com> +Comments: In-reply-to Stephan Szabo + message dated "Tue, 13 May 2003 12:45:27 -0700" +Date: Fri, 23 May 2003 16:34:48 -0400 +Message-ID: <18326.1053722088@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/605 +X-Sequence-Number: 39111 + +We have had a couple of threads recently on improving +bpchar/varchar/text behavior by making bpchar-to-text promotion +go through rtrim() (instead of being a straight binary-compatible +conversion) and getting rid of redundant operators: + +http://archives.postgresql.org/pgsql-hackers/2002-11/msg00703.php +http://archives.postgresql.org/pgsql-performance/2003-05/msg00151.php + +I'm going to go ahead and make these changes for 7.4, as they will +clearly improve the intuitiveness of the behavior. I don't think they +move us any closer to spec compliance --- the spec appears to require +a notion of a collation sequence that can be specified independently +of the character datatype, which is something we don't have and aren't +likely to have very soon. (It's not clear to me that it's actually +*useful* to specify NO PAD collation with fixed-width character data, +or PAD SPACE with varchar data, but the spec lets you do it.) In the +meantime though these changes seem to be a win, and they will not leave +us any worse off when we do get around to implementing collations. + +We speculated about a couple of alternative solutions in the first of +the above-mentioned threads, but they didn't look nearly as practical +to implement as this way. + +Last call for objections ... + + regards, tom lane + +From pgsql-performance-owner@postgresql.org Tue May 27 15:09:16 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 2856C924D41 + for ; + Tue, 27 May 2003 15:09:15 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 68561-07 for ; + Tue, 27 May 2003 15:09:10 -0400 (EDT) +Received: from elbereth.noviforum.si (unknown [193.189.169.66]) + by developer.postgresql.org (Postfix) with ESMTP id 99BDD924D50 + for ; + Tue, 27 May 2003 15:09:09 -0400 (EDT) +Received: (from gregab@localhost) + by elbereth.noviforum.si (8.11.4/8.11.4) id h4RJ98x01054 + for pgsql-performance@postgresql.org; Tue, 27 May 2003 21:09:08 +0200 +Date: Tue, 27 May 2003 21:09:08 +0200 +From: Grega Bremec +To: pgsql-performance@postgresql.org +Subject: Wildcard searches & performance question +Message-ID: <20030527210908.A571@elbereth.noviforum.si> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +User-Agent: Mutt/1.2.5i +Organization: Noviforum, Ltd., Software & Media +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/224 +X-Sequence-Number: 2003 + +Hello, + +I have a database with the following layout: + + searchterms=# \d+ searches_2002 + Table "public.searches_2002" + Column | Type | Modifiers | Description + -----------+------------------------+-----------+------------- + srchdate | date | not null | + srchtime | time without time zone | not null | + client_ip | inet | not null | + srchquery | character varying(50) | not null | + fhvalue | smallint | | + Indexes: searches_2002_client_ip btree (client_ip), + searches_2002_srchdate btree (srchdate), + searches_2002_srchdatetime btree (srchdate, srchtime), + searches_2002_srchquery btree (srchquery), + searches_2002_srchquery_lcase btree (lower(srchquery)), + searches_2002_srchquery_withfh btree (srchquery, fhvalue), + searches_2002_srchtime btree (srchtime) + +There are no uniqueness properties that would make it possible for this table +to have a primary key, as it is a list of searches performed on a search +engine and the users' behaviour is, well... umm, odd, to be mild. :) + +Also, do note that this is a test table, so nevermind the excessive amount of +indexes - performance is not an issue here, I am still evaluating the need and +benefits of having various indexes on those columns. + +The particular case I am interested is this: when executing queries involving +pattern searches using various operators on srchquery, none of the indexes are +used in certain cases, namely those LIKE and regexp filters that start with +a wildcard. + +This makes perfect sense, because wildcard pattern searches that start with a +wildcard, can not really benefit from an index scan, because a sequential scan +is probably going to be faster: we are only going to benefit from scanning an +index in those special cases where the wildcard evaluates to a zero-length +string. + +One example of a query plan: + + searchterms=# explain select count(*) + from searches_2002 + where srchquery like '%curriculum%'; + QUERY PLAN + -------------------------------------------------------------------------- + Aggregate (cost=4583.26..4583.26 rows=1 width=0) + -> Seq Scan on searches_2002 (cost=0.00..4583.26 rows=1 width=0) + Filter: (srchquery ~~ '%curriculum%'::text) + +There is 211061 records in this test table, but the real-life tables would +contain a much much larger amount of data, more like 50+ million rows. + +This promise of a hell on earth trying to optimize performance makes me wonder: +would there be a sensible way/reason for avoiding sequential scans on queries +that start with a wildcard, and would avoiding sequential scans even be +feasible in such cases? Or in other words, can I somehow optimize LIKE and +regexp queries that start with a wildcard? + +TIA, +-- + Grega Bremec + System Administration & Development Support + grega.bremec-at-noviforum.si + http://najdi.si/ + http://www.noviforum.si/ + +From pgsql-performance-owner@postgresql.org Tue May 27 15:37:06 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 6C85A924C3A + for ; + Tue, 27 May 2003 15:37:02 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 74886-09 for ; + Tue, 27 May 2003 15:37:00 -0400 (EDT) +Received: from mail.libertyrms.com (unknown [209.167.124.227]) + by developer.postgresql.org (Postfix) with ESMTP id A55A5923605 + for ; + Tue, 27 May 2003 15:37:00 -0400 (EDT) +Received: from [10.1.2.130] (helo=dba2) + by mail.libertyrms.com with esmtp (Exim 3.22 #3 (Debian)) + id 19KkFo-0007fB-00 + for ; Tue, 27 May 2003 15:37:00 -0400 +Received: by dba2 (Postfix, from userid 1019) + id 4FD5FD24A; Tue, 27 May 2003 15:37:00 -0400 (EDT) +Date: Tue, 27 May 2003 15:37:00 -0400 +From: Andrew Sullivan +To: pgsql-performance@postgresql.org +Subject: Re: Wildcard searches & performance question +Message-ID: <20030527193700.GB4459@libertyrms.info> +Mail-Followup-To: Andrew Sullivan , + pgsql-performance@postgresql.org +References: <20030527210908.A571@elbereth.noviforum.si> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: <20030527210908.A571@elbereth.noviforum.si> +User-Agent: Mutt/1.5.4i +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/225 +X-Sequence-Number: 2004 + +On Tue, May 27, 2003 at 09:09:08PM +0200, Grega Bremec wrote: +> that start with a wildcard, and would avoiding sequential scans even be +> feasible in such cases? Or in other words, can I somehow optimize LIKE and +> regexp queries that start with a wildcard? + +Not really. But it sounds like you might be a candidate for full +text indexing. See contrib/tsearch for one implementation. + +A + +-- +---- +Andrew Sullivan 204-4141 Yonge Street +Liberty RMS Toronto, Ontario Canada + M2P 2A8 + +1 416 646 3304 x110 + + +From pgsql-performance-owner@postgresql.org Tue May 27 16:03:09 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id DA76A924C55 + for ; + Tue, 27 May 2003 16:03:08 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 82794-10 for ; + Tue, 27 May 2003 16:03:07 -0400 (EDT) +Received: from mail1.ihs.com (mail1.ihs.com [170.207.70.222]) + by developer.postgresql.org (Postfix) with ESMTP id CEC32924C26 + for ; + Tue, 27 May 2003 16:03:06 -0400 (EDT) +Received: from css120.ihs.com (css120.ihs.com [170.207.105.120]) + by mail1.ihs.com (8.12.9/8.12.9) with ESMTP id h4RK1AQB008827; + Tue, 27 May 2003 14:01:10 -0600 (MDT) +Date: Tue, 27 May 2003 13:48:39 -0600 (MDT) +From: "scott.marlowe" +To: Grega Bremec +Cc: +Subject: Re: Wildcard searches & performance question +In-Reply-To: <20030527210908.A571@elbereth.noviforum.si> +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-MailScanner: Found to be clean +X-MailScanner-SpamCheck: +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/227 +X-Sequence-Number: 2006 + +What you want is full text searching. To see it in action go here: + +fts.postgresql.org + +To download it go here: + +http://openfts.sourceforge.net/ + +There is also the older, and slightly slower full text indexing engine, +included in the /contrib/fulltextindex directory. It's a little more +wrung out, but also not as likely to get maintenance in the future. + +Basically, full text indexing does exactly what you're asking for by +indexing each row inserted by each word in it (that isn't a noise word +like "the" or "a") and then uses the indexes created for its searches. + +On Tue, 27 May 2003, Grega Bremec wrote: + +> Hello, +> +> I have a database with the following layout: +> +> searchterms=# \d+ searches_2002 +> Table "public.searches_2002" +> Column | Type | Modifiers | Description +> -----------+------------------------+-----------+------------- +> srchdate | date | not null | +> srchtime | time without time zone | not null | +> client_ip | inet | not null | +> srchquery | character varying(50) | not null | +> fhvalue | smallint | | +> Indexes: searches_2002_client_ip btree (client_ip), +> searches_2002_srchdate btree (srchdate), +> searches_2002_srchdatetime btree (srchdate, srchtime), +> searches_2002_srchquery btree (srchquery), +> searches_2002_srchquery_lcase btree (lower(srchquery)), +> searches_2002_srchquery_withfh btree (srchquery, fhvalue), +> searches_2002_srchtime btree (srchtime) +> +> There are no uniqueness properties that would make it possible for this table +> to have a primary key, as it is a list of searches performed on a search +> engine and the users' behaviour is, well... umm, odd, to be mild. :) +> +> Also, do note that this is a test table, so nevermind the excessive amount of +> indexes - performance is not an issue here, I am still evaluating the need and +> benefits of having various indexes on those columns. +> +> The particular case I am interested is this: when executing queries involving +> pattern searches using various operators on srchquery, none of the indexes are +> used in certain cases, namely those LIKE and regexp filters that start with +> a wildcard. +> +> This makes perfect sense, because wildcard pattern searches that start with a +> wildcard, can not really benefit from an index scan, because a sequential scan +> is probably going to be faster: we are only going to benefit from scanning an +> index in those special cases where the wildcard evaluates to a zero-length +> string. +> +> One example of a query plan: +> +> searchterms=# explain select count(*) +> from searches_2002 +> where srchquery like '%curriculum%'; +> QUERY PLAN +> -------------------------------------------------------------------------- +> Aggregate (cost=4583.26..4583.26 rows=1 width=0) +> -> Seq Scan on searches_2002 (cost=0.00..4583.26 rows=1 width=0) +> Filter: (srchquery ~~ '%curriculum%'::text) +> +> There is 211061 records in this test table, but the real-life tables would +> contain a much much larger amount of data, more like 50+ million rows. +> +> This promise of a hell on earth trying to optimize performance makes me wonder: +> would there be a sensible way/reason for avoiding sequential scans on queries +> that start with a wildcard, and would avoiding sequential scans even be +> feasible in such cases? Or in other words, can I somehow optimize LIKE and +> regexp queries that start with a wildcard? +> +> TIA, +> + + +From pgsql-performance-owner@postgresql.org Tue May 27 15:56:26 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id E7BF7924EF7 + for ; + Tue, 27 May 2003 15:56:21 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 79639-10 for ; + Tue, 27 May 2003 15:56:20 -0400 (EDT) +Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) + by developer.postgresql.org (Postfix) with ESMTP id 0CBBA924C26 + for ; + Tue, 27 May 2003 15:56:19 -0400 (EDT) +Received: from [66.219.92.2] (HELO temoku) + by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) + with ESMTP id 3071725; Tue, 27 May 2003 12:56:24 -0700 +Content-Type: text/plain; + charset="iso-8859-1" +From: Josh Berkus +Reply-To: josh@agliodbs.com +Organization: Aglio Database Solutions +To: Grega Bremec , pgsql-performance@postgresql.org +Subject: Re: Wildcard searches & performance question +Date: Tue, 27 May 2003 12:55:46 -0700 +User-Agent: KMail/1.4.3 +References: <20030527210908.A571@elbereth.noviforum.si> +In-Reply-To: <20030527210908.A571@elbereth.noviforum.si> +MIME-Version: 1.0 +Content-Transfer-Encoding: quoted-printable +Message-Id: <200305271255.46668.josh@agliodbs.com> +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/226 +X-Sequence-Number: 2005 + +Grega, + +See www.openfts.org for a tool to do what you need. There's also a simpler= +=20 +one in /contrib, as Andrew mentioned. + +--=20 +-Josh Berkus + Aglio Database Solutions + San Francisco + + +From pgsql-performance-owner@postgresql.org Tue May 27 16:06:35 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 7B708924B4C + for ; + Tue, 27 May 2003 16:06:33 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 84136-04 for ; + Tue, 27 May 2003 16:06:29 -0400 (EDT) +Received: from tomts26-srv.bellnexxia.net (tomts26.bellnexxia.net + [209.226.175.189]) + by developer.postgresql.org (Postfix) with ESMTP id 1066D921AAD + for ; + Tue, 27 May 2003 16:06:28 -0400 (EDT) +Received: from [10.0.2.5] ([216.208.117.7]) by tomts26-srv.bellnexxia.net + (InterMail vM.5.01.05.32 201-253-122-126-132-20030307) with ESMTP + id <20030527200626.FJNN11703.tomts26-srv.bellnexxia.net@[10.0.2.5]>; + Tue, 27 May 2003 16:06:26 -0400 +Subject: Re: Wildcard searches & performance question +From: Rod Taylor +To: Grega Bremec +Cc: Postgresql Performance +In-Reply-To: <20030527210908.A571@elbereth.noviforum.si> +References: <20030527210908.A571@elbereth.noviforum.si> +Content-Type: multipart/signed; micalg=pgp-sha1; + protocol="application/pgp-signature"; + boundary="=-+omd7A7+aRlPXDgIrJnu" +Organization: +Message-Id: <1054065986.93507.43.camel@jester> +Mime-Version: 1.0 +X-Mailer: Ximian Evolution 1.2.4 +Date: 27 May 2003 16:06:26 -0400 +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/228 +X-Sequence-Number: 2007 + +--=-+omd7A7+aRlPXDgIrJnu +Content-Type: text/plain +Content-Transfer-Encoding: quoted-printable + +> feasible in such cases? Or in other words, can I somehow optimize LIKE and +> regexp queries that start with a wildcard? + +If they start with a wildcard, but end in character data you could +reverse the string and index that... + +If they start and end with a wildcard, your best bet is a full text +indexing solution (various contrib modules). + +--=20 +Rod Taylor + +PGP Key: http://www.rbt.ca/rbtpub.asc + +--=-+omd7A7+aRlPXDgIrJnu +Content-Type: application/pgp-signature; name=signature.asc +Content-Description: This is a digitally signed message part + +-----BEGIN PGP SIGNATURE----- +Version: GnuPG v1.2.2 (FreeBSD) + +iD8DBQA+08VC6DETLow6vwwRAumSAJ9OQj3YzdOs961ihgCtJ14FlBBL/gCfSrGI ++pfft8Hn4xMYi/DIh3bx+eM= +=U2fP +-----END PGP SIGNATURE----- + +--=-+omd7A7+aRlPXDgIrJnu-- + + +From pgsql-performance-owner@postgresql.org Wed May 28 07:28:56 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP + id 8E76D9250E4; Wed, 28 May 2003 07:28:52 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 05562-05; Wed, 28 May 2003 07:28:51 -0400 (EDT) +Received: from mta06bw.bigpond.com (mta06bw.bigpond.com [139.134.6.96]) + by developer.postgresql.org (Postfix) with ESMTP + id 874A89250F7; Wed, 28 May 2003 07:28:49 -0400 (EDT) +Received: from rabbit.sspl.net.au ([144.135.24.69]) by + mta06bw.bigpond.com (Netscape Messaging Server 4.15 mta06bw Jul + 16 2002 22:47:55) with SMTP id HFLH7600.785; Wed, 28 May 2003 + 21:28:18 +1000 +Received: from cpe-203-51-24-209.nsw.bigpond.net.au ([203.51.24.209]) by + bwmam01bpa.bigpond.com(MAM $Name: REL_3_3_2a $ 8/1553876); + 28 May 2003 21:28:18 +Received: by rabbit.sspl.net.au (Postfix, from userid 1000) + id A2FC72EC76; Wed, 28 May 2003 21:28:15 +1000 +Date: Wed, 28 May 2003 21:28:15 +1000 +From: Peter Lavender +To: pgsql-sql@postgresql.org, pgsql-performance@postgresql.org +Message-ID: <20030528112815.GD816@piglet2> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +User-Agent: Mutt/1.3.28i +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/229 +X-Sequence-Number: 2008 + +pgsql-bugs@postgresql.org +Cc: +Bcc: +Subject: Re: [PERFORM] [SQL] Unanswered Questions WAS: An unresolved performance +Reply-To: plaven@bigpond.net.au +In-Reply-To: +X-Operating-System: Linux/2.4.18-686-smp (i686) +X-Uptime: 21:03:03 up 8 days, 22:55, 8 users, load average: 1.00, 1.00, 1.00 + +* scott.marlowe (scott.marlowe@ihs.com) wrote: + + +> On Thu, 8 May 2003, johnnnnnn wrote: +> +> > > I hate to point this out, but "TIP 4" is getting a bit old and the 6 +> +> Also, some tips might well cross over, like say, vacuum and analyze +> regularly. Hmmm. Sounds like a job for a relational database :-) + +Did this get carried any further? + +I'd love to see something come out of it. But I'd really like to see more +of the kind of tricks and tips, like how to dump all databases using a +script of 3 lines(?) I'm sure I've seen it before. The extra lines I +don't think would be a major pain given the added value. + +Even if it's too much, how about somewhere on techdocs for the script and +a link in the tips 'n tricks line? + + +Pete +:wq + +From pgsql-performance-owner@postgresql.org Wed May 28 08:51:55 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 8DAA79252A0 + for ; + Wed, 28 May 2003 08:51:53 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 23511-09 for ; + Wed, 28 May 2003 08:51:51 -0400 (EDT) +Received: from sccrmhc02.attbi.com (sccrmhc02.attbi.com [204.127.202.62]) + by developer.postgresql.org (Postfix) with ESMTP id 2248F925297 + for ; + Wed, 28 May 2003 08:51:51 -0400 (EDT) +Received: from attbi.com (dtenny.ne.client2.attbi.com[24.60.113.221]) + by attbi.com (sccrmhc02) with SMTP + id <2003052812515000200ktucle>; Wed, 28 May 2003 12:51:50 +0000 +Message-ID: <3ED4B0E5.3050703@attbi.com> +Date: Wed, 28 May 2003 08:51:49 -0400 +From: Dave Tenny +User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3.1) Gecko/20030425 +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: pgsql-performance@postgresql.org +Subject: IN list processing performance (yet again) +Content-Type: multipart/mixed; boundary="------------030505060105040101090109" +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/230 +X-Sequence-Number: 2009 + +This is a multi-part message in MIME format. +--------------030505060105040101090109 +Content-Type: text/plain; charset=ISO-8859-1; format=flowed +Content-Transfer-Encoding: 7bit + +Having grepped the web, it's clear that this isn't the first or last +time this issue will be raised. + +My application relies heavily on IN lists. The lists are primarily +constant integers, so queries look like: + +SELECT val FROM table WHERE id IN (43, 49, 1001, 100002, ...) + +Performance is critical, and the size of these lists depends a lot on +how the larger 3-tier applicaiton is used, +but it wouldn't be out of the question to retrieve 3000-10000 items. + +PostgreSQL 7.3.2 seems to have a lot of trouble with large lists. + +I ran an experiment that ran queries on a table of two integers (ID, +VAL), where ID is a primary key and the subject +of IN list predicates. The test used a table with one million rows ID +is appropriately indexed, +and I have VACUUMED/analyzed the database after table load. + +I ran tests on in-lists from about 100 to 100,000 entries. + +I also ran tests where I picked the rows out one-by-one using +parameterized statements, e.g. + +SELECT val FROM table WHERE id = ? + +I'm trying to decide how much I should use parameterized statements and +when to work around buffer size limitations +in JDBC transport, general query processing, etc. + +So here are my questions as a prelude to the data noted below: + +1) What is the acceptable limit of jdbc Statement buffer sizes for +executeQuery()? + (Presumably it's not really a JDBC question, but a PostgreSQL +query/buffering/transport question). + +2) What is the expected acceptable limit for the number of items in an +IN list predicate such as + those used here. (List of constants, not subselects). + +3) What should I expect for performance capabilities/limitations from +PostgreSQL on this type of problem? + (Set my expectations, perhaps they're unrealistic). + +4) What are my alternatives for picking specific rows for thousands of +elements with sub-second response times + if not IN lists? (This is crucial!) + +--------------------------------------------- + +Here is a summary of my observations of query times, and I've attached +the test program (more on that below). + +1) PostgreSQL exhibits worse-than-linear performance behavior with +respect to IN list size. + This is bad. + +2) Parameterized statements exhibit the expected linear performance +characteristics. + +3) The break-even point for using IN lists vs. parameterized statements +in my environment + + (RedHat Linux 9.0, PostgreSQL 7.3.2, 512MB memory, 7200RPM 100UDMA +IDE disks, AMD1600Mhz) + + is about 700 items in the IN list. Beyond that, IN the IN list +scalability curve makes it impractical. + +4) God help you if you haven't vacuum/analyzed that the newly loaded +table. Without this, + IN list processing is even worse! + + For just 10 elements in the IN list: + + *Without* VACUUMDB, IN lists suck beyond measure: + Elapsed time for 10 IN list elements: 2638 ms + Elapsed time for 10 parameterized elements: 9 ms + + *With* VACUUMDB: IN lists recover a bit: + Elapsed time for 10 IN list elements: 10 ms + Elapsed time for 10 parameterized elements: 24 ms + + However it's VERY interesting to note that parameterized statements +worked well. That implies + probable disparity in plan generation. It's worth noting that it +didn't *feel* like I was getting the same + delay when I ran the query from the 'psql' client, but since it +doesn't report times I can't be sure. + +5) Rest of my results are vacuumed, (and listed in the attached program +in detail). + + The interesting points are: + + For an IN list of 700 elements: + + MySQL 3.23.56 (with INNODB tables) takes 19ms, 73ms with +parameterized statements. + PostgreSQL takes 269ms, 263ms with parameterized statements. + + For larger lists, MySQL happily processed a 90,000 element IN list +in 1449ms, + 9283 ms using parameterized statements. + + PostgreSQL craps out trying to process 8000 elements with the error: + out of free buffers: time to abort! + + PostgreSQL takes 45,566ms for 7000 elements in an IN list (ouch!) +, and 2027ms for a parameterized statement. + MySQL easily beats that with 10 times the data. + +6) Using a remote client on the lan (10/100) to run the client piece on +a separate machine from the database + server yielded little change int he results. Prepared statements +worked pretty well even with actual wire latency, + surprise! (Of course it's very little latency on my lan, not like, +say, the database server running in a different city + which customers have been known to do). + +The MySQL and PostgreSQL installations are the default RedHat 9.0 +distribution packages, +I haven't tweaked either's installation parameters. (though MySQL was +updated by RedHat from 3.23.54a to 3.23.56 +as part of an automatic upgrade). + +My goal here isn't to say "why aren't you like MySQL". I've been using +PostgreSQL for a year as the development database of choice +with satisfactory results. But I won't be able to support customers who +want to use PostgreSQL on large deployments of my products +if I can't selectively retrieve data for several thousand elements in +sub-second times. + +(PostgreSQL devos, if you want a feel good bullet, note that I don't +support MySQL at all since lack of MVCC transactions +is a showstopper from a multi-user performance standpoint). + +So I'm looking for (a) solutions, answers to my questions above, and (b) +a statement of "we're on this" or "you're stuck with it" from +PostgreSQL devos who know. + +---------------------------------------------------------------- +On the attached program. (a Java JDBC program) Sorry, you can't just run +it "as is". Search for formfeeds (^L) if you want +to skip all the result data I logged. Compilation is straightforward, +simply supply the location of your JDBC jar file for compiling and running +(mine is noted in the program). + +First, move the "if (false)" element below the table creation statements +and run the program to create the table. +Then VACUUM/analyze your database (suuuuure would be nice not to have to +vacuum). +Then move the "if (false)" element above the table creation so you won't +have to do it every time. +Then move past the formfeed and adjust the 'tryAmount' for loop to test +the amounts you're interested. +100 to 1000 by 100's is a good starting point. + +Ignore the section (part of the if (false) logic) that attempts to +figure out what the largest query size is. +Unless you want to reproduce a hung postmaster in a CPU loop, which is +what I got when I tried to run that logic, +though whan I ran it I was missing the closing ')' in my IN list, which +I've since added to that code. + +Thanks for any help! + +Dave + +--------------030505060105040101090109 +Content-Type: text/plain; + name="INList.java" +Content-Transfer-Encoding: 7bit +Content-Disposition: inline; + filename="INList.java" + +import java.sql.* ; + +/* +Query huge inlists, test for buffer overflow and performance using in-lists vs. +parameterized statements, and perhaps batched statements (not yet) + +Results: +MySQL blows PostgreSQL away here, and that's AFTER doing a VACUUMDB in PostgreSQL +PostgreSQL does ok with VACUUMDB to 700 entries, the prepared statements are better. +MySQL: IN lists are always superior to any practical limit (tested to 100,000 elements) + +Local-to-local on AMD1600Mhz, MySQL 3.23.56 with JDBC driver 3.0.8 +[MYSQL was much better here...] + +Table update time: 109927 ms + +For 10,000 -> 100,000 by 10,000 +Elapsed time for 90000 IN list elements: 1449 ms +62 elements/ms +Elapsed time for 90000 parameterized elements: 9283 ms +9 elements/ms + +For 100 -> 10,000 by 100 +Last received via IN list: 99 +Elapsed time for 100 IN list elements: 6 ms +16 elements/ms +Elapsed time for 100 parameterized elements: 20 ms +5 elements/ms +Last received via parameterized elements: 99 +Last received via IN list: 199 +Elapsed time for 200 IN list elements: 7 ms +28 elements/ms +Elapsed time for 200 parameterized elements: 45 ms +4 elements/ms +Last received via parameterized elements: 199 +Last received via IN list: 299 +Elapsed time for 300 IN list elements: 22 ms +13 elements/ms +Elapsed time for 300 parameterized elements: 64 ms +4 elements/ms +Last received via parameterized elements: 299 +Last received via IN list: 399 +Elapsed time for 400 IN list elements: 39 ms +10 elements/ms +Elapsed time for 400 parameterized elements: 63 ms +6 elements/ms +Last received via parameterized elements: 399 +Last received via IN list: 499 +Elapsed time for 500 IN list elements: 12 ms +41 elements/ms +Elapsed time for 500 parameterized elements: 116 ms +4 elements/ms +Last received via parameterized elements: 499 +Last received via IN list: 599 +Elapsed time for 600 IN list elements: 8 ms +75 elements/ms +Elapsed time for 600 parameterized elements: 65 ms +9 elements/ms +Last received via parameterized elements: 599 +Last received via IN list: 699 +Elapsed time for 700 IN list elements: 19 ms +36 elements/ms +Elapsed time for 700 parameterized elements: 73 ms +9 elements/ms +Last received via parameterized elements: 699 +Last received via IN list: 799 +Elapsed time for 800 IN list elements: 12 ms +66 elements/ms +Elapsed time for 800 parameterized elements: 84 ms +9 elements/ms +Last received via parameterized elements: 799 +Last received via IN list: 899 +Elapsed time for 900 IN list elements: 12 ms +75 elements/ms +Elapsed time for 900 parameterized elements: 97 ms +9 elements/ms +Last received via parameterized elements: 899 +Last received via IN list: 999 +Elapsed time for 1000 IN list elements: 15 ms +66 elements/ms +Elapsed time for 1000 parameterized elements: 109 ms +9 elements/ms +Last received via parameterized elements: 999 +Last received via IN list: 1099 +Elapsed time for 1100 IN list elements: 16 ms +68 elements/ms +Elapsed time for 1100 parameterized elements: 115 ms +9 elements/ms +Last received via parameterized elements: 1099 +Last received via IN list: 1199 +Elapsed time for 1200 IN list elements: 16 ms +75 elements/ms +Elapsed time for 1200 parameterized elements: 138 ms +8 elements/ms +Last received via parameterized elements: 1199 +Last received via IN list: 1299 +Elapsed time for 1300 IN list elements: 19 ms +68 elements/ms +Elapsed time for 1300 parameterized elements: 136 ms +9 elements/ms +Last received via parameterized elements: 1299 +Last received via IN list: 1399 +Elapsed time for 1400 IN list elements: 21 ms +66 elements/ms +Elapsed time for 1400 parameterized elements: 150 ms +9 elements/ms +Last received via parameterized elements: 1399 +Last received via IN list: 1499 +Elapsed time for 1500 IN list elements: 21 ms +71 elements/ms +Elapsed time for 1500 parameterized elements: 158 ms +9 elements/ms +Last received via parameterized elements: 1499 +Last received via IN list: 1599 +Elapsed time for 1600 IN list elements: 22 ms +72 elements/ms +Elapsed time for 1600 parameterized elements: 178 ms +8 elements/ms +Last received via parameterized elements: 1599 +Last received via IN list: 1699 +Elapsed time for 1700 IN list elements: 22 ms +77 elements/ms +Elapsed time for 1700 parameterized elements: 180 ms +9 elements/ms +Last received via parameterized elements: 1699 +Last received via IN list: 1799 +Elapsed time for 1800 IN list elements: 26 ms +69 elements/ms +Elapsed time for 1800 parameterized elements: 205 ms +8 elements/ms +Last received via parameterized elements: 1799 +Last received via IN list: 1899 +Elapsed time for 1900 IN list elements: 57 ms +33 elements/ms +Elapsed time for 1900 parameterized elements: 198 ms +9 elements/ms +Last received via parameterized elements: 1899 +Last received via IN list: 1999 +Elapsed time for 2000 IN list elements: 29 ms +68 elements/ms +Elapsed time for 2000 parameterized elements: 215 ms +9 elements/ms +Last received via parameterized elements: 1999 +Last received via IN list: 2099 +Elapsed time for 2100 IN list elements: 30 ms +70 elements/ms +Elapsed time for 2100 parameterized elements: 222 ms +9 elements/ms +Last received via parameterized elements: 2099 +Last received via IN list: 2199 +Elapsed time for 2200 IN list elements: 32 ms +68 elements/ms +Elapsed time for 2200 parameterized elements: 243 ms +9 elements/ms +Last received via parameterized elements: 2199 +Last received via IN list: 2299 +Elapsed time for 2300 IN list elements: 32 ms +71 elements/ms +Elapsed time for 2300 parameterized elements: 241 ms +9 elements/ms +Last received via parameterized elements: 2299 +Last received via IN list: 2399 +Elapsed time for 2400 IN list elements: 33 ms +72 elements/ms +Elapsed time for 2400 parameterized elements: 260 ms +9 elements/ms +Last received via parameterized elements: 2399 +Last received via IN list: 2499 +Elapsed time for 2500 IN list elements: 64 ms +39 elements/ms +Elapsed time for 2500 parameterized elements: 275 ms +9 elements/ms +Last received via parameterized elements: 2499 +Last received via IN list: 2599 +Elapsed time for 2600 IN list elements: 35 ms +74 elements/ms +Elapsed time for 2600 parameterized elements: 275 ms +9 elements/ms +Last received via parameterized elements: 2599 +Last received via IN list: 2699 +Elapsed time for 2700 IN list elements: 36 ms +75 elements/ms +Elapsed time for 2700 parameterized elements: 292 ms +9 elements/ms +Last received via parameterized elements: 2699 +Last received via IN list: 2799 +Elapsed time for 2800 IN list elements: 41 ms +68 elements/ms +Elapsed time for 2800 parameterized elements: 308 ms +9 elements/ms +Last received via parameterized elements: 2799 +Last received via IN list: 2899 +Elapsed time for 2900 IN list elements: 40 ms +72 elements/ms +Elapsed time for 2900 parameterized elements: 341 ms +8 elements/ms +Last received via parameterized elements: 2899 +Last received via IN list: 2999 +Elapsed time for 3000 IN list elements: 42 ms +71 elements/ms +Elapsed time for 3000 parameterized elements: 356 ms +8 elements/ms +Last received via parameterized elements: 2999 +Last received via IN list: 3099 +Elapsed time for 3100 IN list elements: 42 ms +73 elements/ms +Elapsed time for 3100 parameterized elements: 342 ms +9 elements/ms +Last received via parameterized elements: 3099 +Last received via IN list: 3199 +Elapsed time for 3200 IN list elements: 43 ms +74 elements/ms +Elapsed time for 3200 parameterized elements: 345 ms +9 elements/ms +Last received via parameterized elements: 3199 +Last received via IN list: 3299 +Elapsed time for 3300 IN list elements: 43 ms +76 elements/ms +Elapsed time for 3300 parameterized elements: 359 ms +9 elements/ms +Last received via parameterized elements: 3299 +Last received via IN list: 3399 +Elapsed time for 3400 IN list elements: 77 ms +44 elements/ms +Elapsed time for 3400 parameterized elements: 356 ms +9 elements/ms +Last received via parameterized elements: 3399 +Last received via IN list: 3499 +Elapsed time for 3500 IN list elements: 50 ms +70 elements/ms +Elapsed time for 3500 parameterized elements: 370 ms +9 elements/ms +Last received via parameterized elements: 3499 +Last received via IN list: 3599 +Elapsed time for 3600 IN list elements: 84 ms +42 elements/ms +Elapsed time for 3600 parameterized elements: 387 ms +9 elements/ms +Last received via parameterized elements: 3599 +Last received via IN list: 3699 +Elapsed time for 3700 IN list elements: 52 ms +71 elements/ms +Elapsed time for 3700 parameterized elements: 390 ms +9 elements/ms +Last received via parameterized elements: 3699 +Last received via IN list: 3799 +Elapsed time for 3800 IN list elements: 54 ms +70 elements/ms +Elapsed time for 3800 parameterized elements: 407 ms +9 elements/ms +Last received via parameterized elements: 3799 +Last received via IN list: 3899 +Elapsed time for 3900 IN list elements: 84 ms +46 elements/ms +Elapsed time for 3900 parameterized elements: 422 ms +9 elements/ms +Last received via parameterized elements: 3899 +Last received via IN list: 3999 +Elapsed time for 4000 IN list elements: 58 ms +68 elements/ms +Elapsed time for 4000 parameterized elements: 434 ms +9 elements/ms +Last received via parameterized elements: 3999 +Last received via IN list: 4099 +Elapsed time for 4100 IN list elements: 58 ms +70 elements/ms +Elapsed time for 4100 parameterized elements: 446 ms +9 elements/ms +Last received via parameterized elements: 4099 +Last received via IN list: 4199 +Elapsed time for 4200 IN list elements: 61 ms +68 elements/ms +Elapsed time for 4200 parameterized elements: 453 ms +9 elements/ms +Last received via parameterized elements: 4199 +Last received via IN list: 4299 +Elapsed time for 4300 IN list elements: 63 ms +68 elements/ms +Elapsed time for 4300 parameterized elements: 457 ms +9 elements/ms +Last received via parameterized elements: 4299 +Last received via IN list: 4399 +Elapsed time for 4400 IN list elements: 94 ms +46 elements/ms +Elapsed time for 4400 parameterized elements: 473 ms +9 elements/ms +Last received via parameterized elements: 4399 +Last received via IN list: 4499 +Elapsed time for 4500 IN list elements: 64 ms +70 elements/ms +Elapsed time for 4500 parameterized elements: 506 ms +8 elements/ms +Last received via parameterized elements: 4499 +Last received via IN list: 4599 +Elapsed time for 4600 IN list elements: 72 ms +63 elements/ms +Elapsed time for 4600 parameterized elements: 527 ms +8 elements/ms +Last received via parameterized elements: 4599 +Last received via IN list: 4699 +Elapsed time for 4700 IN list elements: 68 ms +69 elements/ms +Elapsed time for 4700 parameterized elements: 499 ms +9 elements/ms +Last received via parameterized elements: 4699 +Last received via IN list: 4799 +Elapsed time for 4800 IN list elements: 70 ms +68 elements/ms +Elapsed time for 4800 parameterized elements: 539 ms +8 elements/ms +Last received via parameterized elements: 4799 +Last received via IN list: 4899 +Elapsed time for 4900 IN list elements: 100 ms +49 elements/ms +Elapsed time for 4900 parameterized elements: 590 ms +8 elements/ms +Last received via parameterized elements: 4899 +Last received via IN list: 4999 +Elapsed time for 5000 IN list elements: 111 ms +45 elements/ms +Elapsed time for 5000 parameterized elements: 531 ms +9 elements/ms +Last received via parameterized elements: 4999 +Last received via IN list: 5099 +Elapsed time for 5100 IN list elements: 79 ms +64 elements/ms +Elapsed time for 5100 parameterized elements: 542 ms +9 elements/ms +Last received via parameterized elements: 5099 +Last received via IN list: 5199 +Elapsed time for 5200 IN list elements: 108 ms +48 elements/ms +Elapsed time for 5200 parameterized elements: 560 ms +9 elements/ms +Last received via parameterized elements: 5199 +Last received via IN list: 5299 +Elapsed time for 5300 IN list elements: 78 ms +67 elements/ms +Elapsed time for 5300 parameterized elements: 560 ms +9 elements/ms +Last received via parameterized elements: 5299 +Last received via IN list: 5399 +Elapsed time for 5400 IN list elements: 81 ms +66 elements/ms +Elapsed time for 5400 parameterized elements: 572 ms +9 elements/ms +Last received via parameterized elements: 5399 +Last received via IN list: 5499 +Elapsed time for 5500 IN list elements: 80 ms +68 elements/ms +Elapsed time for 5500 parameterized elements: 627 ms +8 elements/ms +Last received via parameterized elements: 5499 +Last received via IN list: 5599 +Elapsed time for 5600 IN list elements: 81 ms +69 elements/ms +Elapsed time for 5600 parameterized elements: 590 ms +9 elements/ms +Last received via parameterized elements: 5599 +Last received via IN list: 5699 +Elapsed time for 5700 IN list elements: 86 ms +66 elements/ms +Elapsed time for 5700 parameterized elements: 606 ms +9 elements/ms +Last received via parameterized elements: 5699 +Last received via IN list: 5799 +Elapsed time for 5800 IN list elements: 85 ms +68 elements/ms +Elapsed time for 5800 parameterized elements: 663 ms +8 elements/ms +Last received via parameterized elements: 5799 +Last received via IN list: 5899 +Elapsed time for 5900 IN list elements: 83 ms +71 elements/ms +Elapsed time for 5900 parameterized elements: 629 ms +9 elements/ms +Last received via parameterized elements: 5899 +Last received via IN list: 5999 +Elapsed time for 6000 IN list elements: 91 ms +65 elements/ms +Elapsed time for 6000 parameterized elements: 658 ms +9 elements/ms +Last received via parameterized elements: 5999 +Last received via IN list: 6099 +Elapsed time for 6100 IN list elements: 87 ms +70 elements/ms +Elapsed time for 6100 parameterized elements: 702 ms +8 elements/ms +Last received via parameterized elements: 6099 +Last received via IN list: 6199 +Elapsed time for 6200 IN list elements: 88 ms +70 elements/ms +Elapsed time for 6200 parameterized elements: 667 ms +9 elements/ms +Last received via parameterized elements: 6199 +Last received via IN list: 6299 +Elapsed time for 6300 IN list elements: 91 ms +69 elements/ms +Elapsed time for 6300 parameterized elements: 670 ms +9 elements/ms +Last received via parameterized elements: 6299 +Last received via IN list: 6399 +Elapsed time for 6400 IN list elements: 91 ms +70 elements/ms +Elapsed time for 6400 parameterized elements: 708 ms +9 elements/ms +Last received via parameterized elements: 6399 +Last received via IN list: 6499 +Elapsed time for 6500 IN list elements: 96 ms +67 elements/ms +Elapsed time for 6500 parameterized elements: 687 ms +9 elements/ms +Last received via parameterized elements: 6499 +Last received via IN list: 6599 +Elapsed time for 6600 IN list elements: 95 ms +69 elements/ms +Elapsed time for 6600 parameterized elements: 701 ms +9 elements/ms +Last received via parameterized elements: 6599 +Last received via IN list: 6699 +Elapsed time for 6700 IN list elements: 134 ms +50 elements/ms +Elapsed time for 6700 parameterized elements: 711 ms +9 elements/ms +Last received via parameterized elements: 6699 +Last received via IN list: 6799 +Elapsed time for 6800 IN list elements: 98 ms +69 elements/ms +Elapsed time for 6800 parameterized elements: 723 ms +9 elements/ms +Last received via parameterized elements: 6799 +Last received via IN list: 6899 +Elapsed time for 6900 IN list elements: 99 ms +69 elements/ms +Elapsed time for 6900 parameterized elements: 728 ms +9 elements/ms +Last received via parameterized elements: 6899 +Last received via IN list: 6999 +Elapsed time for 7000 IN list elements: 141 ms +49 elements/ms +Elapsed time for 7000 parameterized elements: 733 ms +9 elements/ms +Last received via parameterized elements: 6999 +Last received via IN list: 7099 +Elapsed time for 7100 IN list elements: 108 ms +65 elements/ms +Elapsed time for 7100 parameterized elements: 752 ms +9 elements/ms +Last received via parameterized elements: 7099 +Last received via IN list: 7199 +Elapsed time for 7200 IN list elements: 104 ms +69 elements/ms +Elapsed time for 7200 parameterized elements: 769 ms +9 elements/ms +Last received via parameterized elements: 7199 +Last received via IN list: 7299 +Elapsed time for 7300 IN list elements: 142 ms +51 elements/ms +Elapsed time for 7300 parameterized elements: 778 ms +9 elements/ms +Last received via parameterized elements: 7299 +Last received via IN list: 7399 +Elapsed time for 7400 IN list elements: 127 ms +58 elements/ms +Elapsed time for 7400 parameterized elements: 796 ms +9 elements/ms +Last received via parameterized elements: 7399 +Last received via IN list: 7499 +Elapsed time for 7500 IN list elements: 110 ms +68 elements/ms +Elapsed time for 7500 parameterized elements: 796 ms +9 elements/ms +Last received via parameterized elements: 7499 +Last received via IN list: 7599 +Elapsed time for 7600 IN list elements: 144 ms +52 elements/ms +Elapsed time for 7600 parameterized elements: 994 ms +7 elements/ms +Last received via parameterized elements: 7599 +Last received via IN list: 7699 +Elapsed time for 7700 IN list elements: 122 ms +63 elements/ms +Elapsed time for 7700 parameterized elements: 819 ms +9 elements/ms +Last received via parameterized elements: 7699 +Last received via IN list: 7799 +Elapsed time for 7800 IN list elements: 114 ms +68 elements/ms +Elapsed time for 7800 parameterized elements: 893 ms +8 elements/ms +Last received via parameterized elements: 7799 +Last received via IN list: 7899 +Elapsed time for 7900 IN list elements: 152 ms +51 elements/ms +Elapsed time for 7900 parameterized elements: 841 ms +9 elements/ms +Last received via parameterized elements: 7899 +Last received via IN list: 7999 +Elapsed time for 8000 IN list elements: 119 ms +67 elements/ms +Elapsed time for 8000 parameterized elements: 853 ms +9 elements/ms +Last received via parameterized elements: 7999 +Last received via IN list: 8099 +Elapsed time for 8100 IN list elements: 121 ms +66 elements/ms +Elapsed time for 8100 parameterized elements: 858 ms +9 elements/ms +Last received via parameterized elements: 8099 +Last received via IN list: 8199 +Elapsed time for 8200 IN list elements: 157 ms +52 elements/ms +Elapsed time for 8200 parameterized elements: 871 ms +9 elements/ms +Last received via parameterized elements: 8199 +Last received via IN list: 8299 +Elapsed time for 8300 IN list elements: 131 ms +63 elements/ms +Elapsed time for 8300 parameterized elements: 879 ms +9 elements/ms +Last received via parameterized elements: 8299 +Last received via IN list: 8399 +Elapsed time for 8400 IN list elements: 124 ms +67 elements/ms +Elapsed time for 8400 parameterized elements: 890 ms +9 elements/ms +Last received via parameterized elements: 8399 +Last received via IN list: 8499 +Elapsed time for 8500 IN list elements: 163 ms +52 elements/ms +Elapsed time for 8500 parameterized elements: 904 ms +9 elements/ms +Last received via parameterized elements: 8499 +Last received via IN list: 8599 +Elapsed time for 8600 IN list elements: 131 ms +65 elements/ms +Elapsed time for 8600 parameterized elements: 907 ms +9 elements/ms +Last received via parameterized elements: 8599 +Last received via IN list: 8699 +Elapsed time for 8700 IN list elements: 127 ms +68 elements/ms +Elapsed time for 8700 parameterized elements: 947 ms +9 elements/ms +Last received via parameterized elements: 8699 +Last received via IN list: 8799 +Elapsed time for 8800 IN list elements: 166 ms +53 elements/ms +Elapsed time for 8800 parameterized elements: 933 ms +9 elements/ms +Last received via parameterized elements: 8799 +Last received via IN list: 8899 +Elapsed time for 8900 IN list elements: 133 ms +66 elements/ms +Elapsed time for 8900 parameterized elements: 947 ms +9 elements/ms +Last received via parameterized elements: 8899 +Last received via IN list: 8999 +Elapsed time for 9000 IN list elements: 142 ms +63 elements/ms +Elapsed time for 9000 parameterized elements: 951 ms +9 elements/ms +Last received via parameterized elements: 8999 +Last received via IN list: 9099 +Elapsed time for 9100 IN list elements: 173 ms +52 elements/ms +Elapsed time for 9100 parameterized elements: 961 ms +9 elements/ms +Last received via parameterized elements: 9099 +Last received via IN list: 9199 +Elapsed time for 9200 IN list elements: 138 ms +66 elements/ms +Elapsed time for 9200 parameterized elements: 979 ms +9 elements/ms +Last received via parameterized elements: 9199 +Last received via IN list: 9299 +Elapsed time for 9300 IN list elements: 135 ms +68 elements/ms +Elapsed time for 9300 parameterized elements: 985 ms +9 elements/ms +Last received via parameterized elements: 9299 +Last received via IN list: 9399 +Elapsed time for 9400 IN list elements: 175 ms +53 elements/ms +Elapsed time for 9400 parameterized elements: 1000 ms +9 elements/ms +Last received via parameterized elements: 9399 +Last received via IN list: 9499 +Elapsed time for 9500 IN list elements: 136 ms +69 elements/ms +Elapsed time for 9500 parameterized elements: 1010 ms +9 elements/ms +Last received via parameterized elements: 9499 +Last received via IN list: 9599 +Elapsed time for 9600 IN list elements: 144 ms +66 elements/ms +Elapsed time for 9600 parameterized elements: 1017 ms +9 elements/ms +Last received via parameterized elements: 9599 +Last received via IN list: 9699 +Elapsed time for 9700 IN list elements: 186 ms +52 elements/ms +Elapsed time for 9700 parameterized elements: 1021 ms +9 elements/ms +Last received via parameterized elements: 9699 +Last received via IN list: 9799 +Elapsed time for 9800 IN list elements: 142 ms +69 elements/ms +Elapsed time for 9800 parameterized elements: 1048 ms +9 elements/ms +Last received via parameterized elements: 9799 +Last received via IN list: 9899 +Elapsed time for 9900 IN list elements: 145 ms +68 elements/ms +Elapsed time for 9900 parameterized elements: 1054 ms +9 elements/ms +Last received via parameterized elements: 9899 + + +Local-to-local on AMD 1600Mhz, PGSQL7.3.2, RH9.0 +Table update time: 169xxx ms + +*Without* VACUUMDB, IN lists suck beyond measure: +For just 10 elements in the IN list: +Elapsed time for 10 IN list elements: 2638 ms +0 elements/ms +Elapsed time for 10 parameterized elements: 9 ms +1 elements/ms + +*With* VACUUMDB: IN lists recover a bit: +Elapsed time for 10 IN list elements: 10 ms +1 elements/ms +Elapsed time for 10 parameterized elements: 24 ms +0 elements/ms +[...] +Elapsed time for 99 IN list elements: 16 ms +6 elements/ms +Elapsed time for 99 parameterized elements: 36 ms +2 elements/ms +Last received via parameterized elements: 98 + + +Testing for some larger numbers of elements, however, reveals another story. +Elapsed time for 1000 IN list elements: 676 ms +1 elements/ms +Elapsed time for 1000 parameterized elements: 351 ms +2 elements/ms +Elapsed time for 2000 IN list elements: 3197 ms +0 elements/ms +Elapsed time for 2000 parameterized elements: 713 ms +2 elements/ms +Elapsed time for 3000 IN list elements: 7266 ms +0 elements/ms +Elapsed time for 3000 parameterized elements: 1080 ms +2 elements/ms +Elapsed time for 4000 IN list elements: 13341 ms +0 elements/ms +Elapsed time for 4000 parameterized elements: 1449 ms +2 elements/ms + +Based on the 'by-the-1000's approach, IN lists are on a seriously bad curve, +while parameterized statements are linear. + +The cutoff on my AMD 1600 Mhz machine is at about 700 elements: +Elapsed time for 600 IN list elements: 157 ms +3 elements/ms +Elapsed time for 600 parameterized elements: 246 ms +2 elements/ms +Elapsed time for 700 IN list elements: 269 ms +2 elements/ms +Elapsed time for 700 parameterized elements: 263 ms +2 elements/ms + +Local(Intel PIII-M 1Ghz)-to-REMOTE(AMD1600Mhz), PostgreSQL 7.3.2 + +100 -> 1000 by 100's. + +IN List Query string length is 637 +Last received via IN list: 99 +Elapsed time for 100 IN list elements: 22 ms +4 elements/ms +Elapsed time for 100 parameterized elements: 117 ms +0 elements/ms +Last received via parameterized elements: 99 +IN List Query string length is 1237 +Last received via IN list: 199 +Elapsed time for 200 IN list elements: 39 ms +5 elements/ms +Elapsed time for 200 parameterized elements: 169 ms +1 elements/ms +Last received via parameterized elements: 199 +IN List Query string length is 1837 +Last received via IN list: 299 +Elapsed time for 300 IN list elements: 81 ms +3 elements/ms +Elapsed time for 300 parameterized elements: 136 ms +2 elements/ms +Last received via parameterized elements: 299 +IN List Query string length is 2437 +Last received via IN list: 399 +Elapsed time for 400 IN list elements: 108 ms +3 elements/ms +Elapsed time for 400 parameterized elements: 157 ms +2 elements/ms +Last received via parameterized elements: 399 +IN List Query string length is 3037 +Last received via IN list: 499 +Elapsed time for 500 IN list elements: 99 ms +5 elements/ms +Elapsed time for 500 parameterized elements: 232 ms +2 elements/ms +Last received via parameterized elements: 499 +IN List Query string length is 3637 +Last received via IN list: 599 +Elapsed time for 600 IN list elements: 150 ms +4 elements/ms +Elapsed time for 600 parameterized elements: 182 ms +3 elements/ms +Last received via parameterized elements: 599 +IN List Query string length is 4237 +Last received via IN list: 699 +Elapsed time for 700 IN list elements: 256 ms +2 elements/ms +Elapsed time for 700 parameterized elements: 219 ms +3 elements/ms +Last received via parameterized elements: 699 +IN List Query string length is 4837 +Last received via IN list: 799 +Elapsed time for 800 IN list elements: 370 ms +2 elements/ms +Elapsed time for 800 parameterized elements: 245 ms +3 elements/ms +Last received via parameterized elements: 799 +IN List Query string length is 5437 +Last received via IN list: 899 +Elapsed time for 900 IN list elements: 511 ms +1 elements/ms +Elapsed time for 900 parameterized elements: 265 ms +3 elements/ms +Last received via parameterized elements: 899 + +Curiously, the difference between local->local and local->remote here is +small. The breakeven point was about 650 elements, versus slightly closer +to 700 in local->local. + + +Local(Intel PIII-M 1Ghz)-to-REMOTE(AMD1600Mhz), PostgreSQL 7.3.2 + +1000 -> 10000 by 1000's. + +IN List Query string length is 6037 +Last received via IN list: 999 +Elapsed time for 1000 IN list elements: 772 ms +1 elements/ms +Elapsed time for 1000 parameterized elements: 495 ms +2 elements/ms +Last received via parameterized elements: 999 +IN List Query string length is 12037 +Last received via IN list: 1999 +Elapsed time for 2000 IN list elements: 3055 ms +0 elements/ms +Elapsed time for 2000 parameterized elements: 681 ms +2 elements/ms +Last received via parameterized elements: 1999 +IN List Query string length is 18037 +Last received via IN list: 2999 +Elapsed time for 3000 IN list elements: 7205 ms +0 elements/ms +Elapsed time for 3000 parameterized elements: 888 ms +3 elements/ms +Last received via parameterized elements: 2999 +IN List Query string length is 24037 +Last received via IN list: 3999 +Elapsed time for 4000 IN list elements: 12912 ms +0 elements/ms +Elapsed time for 4000 parameterized elements: 1162 ms +3 elements/ms +Last received via parameterized elements: 3999 +IN List Query string length is 30037 +Last received via IN list: 4999 +Elapsed time for 5000 IN list elements: 21844 ms +0 elements/ms +Elapsed time for 5000 parameterized elements: 1461 ms +3 elements/ms +Last received via parameterized elements: 4999 +IN List Query string length is 36037 +Last received via IN list: 5999 +Elapsed time for 6000 IN list elements: 32595 ms +0 elements/ms +Elapsed time for 6000 parameterized elements: 1780 ms +3 elements/ms +Last received via parameterized elements: 5999 +IN List Query string length is 42037 +Last received via IN list: 6999 +Elapsed time for 7000 IN list elements: 46566 ms +0 elements/ms +Elapsed time for 7000 parameterized elements: 2027 ms +3 elements/ms +Last received via parameterized elements: 6999 +IN List Query string length is 48037 +java.sql.SQLException: ERROR: out of free buffers: time to abort! + + at org.postgresql.core.QueryExecutor.execute(QueryExecutor.java:126) + at org.postgresql.jdbc1.AbstractJdbc1Connection.ExecSQL(AbstractJdbc1Connection.java:451) + at org.postgresql.jdbc1.AbstractJdbc1Statement.execute(AbstractJdbc1Statement.java:281) + at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:48) + at org.postgresql.jdbc1.AbstractJdbc1Statement.executeQuery(AbstractJdbc1Statement.java:144) + at org.postgresql.jdbc1.AbstractJdbc1Statement.executeQuery(AbstractJdbc1Statement.java:132) + at INList.main(INList.java:775) +*/ + + +class INList +{ + public static void main(String[] args) { + try { + final int NROWS = 1000000 ; // one million + final int IDSTART = 10000 ; // first ID value + + // ---------------- MySql driver ----------------- + // -classpath .:/usr/java/mysql-connector-java-2.0.14/mysql-connector-java-2.0.14-bin.jar + // RH9: -classpath .:/home/dave/mysql-connector-java-3.0.8-stable/mysql-connector-java-3.0.8-stable-bin.jar + //Class.forName("com.mysql.jdbc.Driver") ; + //Connection conn = DriverManager.getConnection("jdbc:mysql:///test", "dave", "") ; + //String innodb = " TYPE=INNODB" ; + + // --------------- postgres 7.3.2 distribution JDBC2 driver linked as /usr/java/postgresql-jdbc.jar + // -classpath .:/usr/java/postgresql-jdbc.jar + Class.forName("org.postgresql.Driver") ; + Connection conn = DriverManager.getConnection("jdbc:postgresql:test", "dave", "") ; + String innodb = "" ; + + conn.setAutoCommit(false) ; + + long oldmillis, newmillis, elapsed ; + Statement statement = conn.createStatement() ; + PreparedStatement pstatement ; + ResultSet rs ; + int lastReceived ; + + if (false) { + statement.executeUpdate("CREATE TABLE MILLION (ID INTEGER PRIMARY KEY, VAL INTEGER)" + innodb) ; + conn.commit() ; + + // Read that "all statements of a connection commit/rollback as a group, API certainly implies this + // conn.commit() ; pstatement should potentially fail because table isn't there without this! + + // Create the rows + pstatement = conn.prepareStatement("INSERT INTO MILLION (ID, VAL) VALUES(?, ?)") ; + oldmillis = System.currentTimeMillis() ; + for (int i = 0 ; i < NROWS ; i++) { + pstatement.setInt(1, IDSTART+i) ; + pstatement.setInt(2, i) ; + pstatement.executeUpdate() ; + } + conn.commit() ; + newmillis = System.currentTimeMillis() ; + pstatement.close() ; + System.out.println("Table update time: " + (newmillis-oldmillis) + " ms") ; + rs = statement.executeQuery("SELECT COUNT(*) FROM MILLION") ; + rs.first() ; + if (rs.getInt(1) != NROWS) + System.out.println("**** Expected " + (NROWS) + " rows, got " + rs.getInt(1)) ; + conn.commit() ; + + // Determine largest IN LIST + StringBuffer sb = new StringBuffer(8000*1024) ; + boolean successful = false ; + int tryAmount = NROWS ; + while (!successful) { + sb.setLength(0) ; + sb.append("SELECT MAX(VAL) FROM MILLION WHERE ID IN (") ; + for (int i = 0 ; i < tryAmount ; i++) { + sb.append(i+IDSTART) ; + if (i < tryAmount-1) + sb.append(',') ; + } + sb.append(')') ; + try { + rs = statement.executeQuery(sb.toString()) ; + successful = true ; + } + catch (SQLException e) { + System.out.println("IN list failed for " + tryAmount + " entries, buffer size was " + + sb.length()) ; + tryAmount -= 10000 ; + if (tryAmount <= 0) + break ; // be done with the while loop + } + } // while (!successful) + conn.commit() ; // more for the next txn than this one, eliminate txn caching + System.out.println("Largest IN list: " + tryAmount + " elements.") ; + } // if (false) + + else { + for (int tryAmount = 100 ; tryAmount < 1000 ; tryAmount+= 100) { + StringBuffer sb = new StringBuffer(tryAmount*20) ; + sb.append("SELECT VAL FROM MILLION WHERE ID IN (") ; + for (int i = 0 ; i < tryAmount ; i++) { + sb.append(i+IDSTART) ; + if (i+1 < tryAmount) + sb.append(',') ; + } + sb.append(')') ; + + // Try query with largest inlist, getting resultset with all values + String query = sb.toString() ; + System.out.println("IN List Query string length is " + query.length()) ; + //query = query.replaceFirst("MAX(VAL)", "VAL") ; + oldmillis = System.currentTimeMillis() ; + rs = statement.executeQuery(query) ; + lastReceived = -1 ; + while (rs.next()) + lastReceived = rs.getInt(1) ; + System.out.println("Last received via IN list: " + lastReceived) ; + conn.commit() ; + newmillis = System.currentTimeMillis() ; + elapsed = newmillis - oldmillis ; + System.out.println("Elapsed time for " + tryAmount + " IN list elements: " + elapsed + " ms") ; + System.out.println((tryAmount/elapsed) + " elements/ms") ; + + // Try the query with prepared statements + lastReceived = -1 ; + pstatement = conn.prepareStatement("SELECT VAL FROM MILLION WHERE ID = ?") ; + oldmillis = System.currentTimeMillis() ; + for (int i = 0 ; i < tryAmount ; i++) { + pstatement.setInt(1, i+IDSTART) ; + rs = pstatement.executeQuery() ; + if (!rs.first()) + System.out.println("Pstatement query failed") ; + else + lastReceived = rs.getInt(1) ; + } + conn.commit() ; + newmillis = System.currentTimeMillis() ; + pstatement.close() ; + elapsed = newmillis - oldmillis ; + System.out.println("Elapsed time for " + tryAmount + " parameterized elements: " + elapsed + " ms") ; + System.out.println((tryAmount/elapsed) + " elements/ms") ; + System.out.println("Last received via parameterized elements: " + lastReceived) ; + } // for (tryAmount ...) + } // else (if (false)) + + // Done, delete our table + // statement.executeUpdate("DROP TABLE MILLION") ; + conn.commit() ; + } + catch (Exception e) { + e.printStackTrace() ; + } + } // main() +} // class INList + +--------------030505060105040101090109-- + + +From pgsql-performance-owner@postgresql.org Wed May 28 09:17:44 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 13BCA925424 + for ; + Wed, 28 May 2003 09:17:43 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 33175-04 for ; + Wed, 28 May 2003 09:17:41 -0400 (EDT) +Received: from www.pspl.co.in (www.pspl.co.in [202.54.11.65]) + by developer.postgresql.org (Postfix) with ESMTP id EBB3C925422 + for ; + Wed, 28 May 2003 09:17:39 -0400 (EDT) +Received: (from root@localhost) + by www.pspl.co.in (8.11.6/8.11.6) id h4SDHaa21106 + for ; Wed, 28 May 2003 18:47:36 +0530 +Received: from daithan.intranet.pspl.co.in (daithan.intranet.pspl.co.in + [192.168.7.161]) + by www.pspl.co.in (8.11.6/8.11.0) with ESMTP id h4SDHa221101 + for ; Wed, 28 May 2003 18:47:36 +0530 +From: Shridhar Daithankar +To: pgsql-performance@postgresql.org +Subject: Re: IN list processing performance (yet again) +Date: Wed, 28 May 2003 18:46:38 +0530 +User-Agent: KMail/1.5.2 +References: <3ED4B0E5.3050703@attbi.com> +In-Reply-To: <3ED4B0E5.3050703@attbi.com> +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit +Content-Disposition: inline +Message-Id: <200305281846.38928.shridhar_daithankar@nospam.persistent.co.in> +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/231 +X-Sequence-Number: 2010 + +On Wednesday 28 May 2003 18:21, Dave Tenny wrote: +> Having grepped the web, it's clear that this isn't the first or last +> time this issue will be raised. +> +> My application relies heavily on IN lists. The lists are primarily +> constant integers, so queries look like: +> +> SELECT val FROM table WHERE id IN (43, 49, 1001, 100002, ...) + +How do you derive this list of number? If it is from same database, can you +rewrite the query using a join statement? + +HTH + + Shridhar + + +From pgsql-performance-owner@postgresql.org Wed May 28 09:19:21 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id BA370925227 + for ; + Wed, 28 May 2003 09:19:19 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 34058-01 for ; + Wed, 28 May 2003 09:19:18 -0400 (EDT) +Received: from smtp.web.de (smtp03.web.de [217.72.192.158]) + by developer.postgresql.org (Postfix) with ESMTP id 0A9AE9251F7 + for ; + Wed, 28 May 2003 09:19:18 -0400 (EDT) +Received: from p508187dc.dip0.t-ipconnect.de ([80.129.135.220] helo=web.de) + by smtp.web.de with asmtp (TLSv1:RC4-MD5:128) (WEB.DE 4.98 #232) + id 19L0po-0003yV-00; Wed, 28 May 2003 15:19:17 +0200 +Message-ID: <3ED4B75A.2050106@web.de> +Date: Wed, 28 May 2003 15:19:22 +0200 +From: Andreas Pflug +User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3) Gecko/20030312 +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: Dave Tenny , pgsql-performance@postgresql.org +Subject: Re: IN list processing performance (yet again) +References: <3ED4B0E5.3050703@attbi.com> +In-Reply-To: <3ED4B0E5.3050703@attbi.com> +Content-Type: text/plain; charset=ISO-8859-1; format=flowed +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/232 +X-Sequence-Number: 2011 + +Dave Tenny wrote: + +> Having grepped the web, it's clear that this isn't the first or last +> time this issue will be raised. +> +> My application relies heavily on IN lists. The lists are primarily +> constant integers, so queries look like: +> +> SELECT val FROM table WHERE id IN (43, 49, 1001, 100002, ...) +> +> Performance is critical, and the size of these lists depends a lot on +> how the larger 3-tier applicaiton is used, +> but it wouldn't be out of the question to retrieve 3000-10000 items. +> +> PostgreSQL 7.3.2 seems to have a lot of trouble with large lists. +> I ran an experiment that ran queries on a table of two integers (ID, +> VAL), where ID is a primary key and the subject +> of IN list predicates. The test used a table with one million rows +> ID is appropriately indexed, +> and I have VACUUMED/analyzed the database after table load. +> +> I ran tests on in-lists from about 100 to 100,000 entries. + +Hi Dave, + +it sounds as if that IN-list is created by the application. I wonder if +there are really so many variances and combinations of it or whether you +could invent an additional column, which groups all those individual +values. If possible, you could reduce your IN list to much fewer values, +and probably would get better performance (using an index on that col, +of course). + +Regards, + +Andreas + + + + +From pgsql-performance-owner@postgresql.org Wed May 28 10:31:47 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 567DB925174 + for ; + Wed, 28 May 2003 10:31:45 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 48577-06 for ; + Wed, 28 May 2003 10:31:41 -0400 (EDT) +Received: from relay12.austria.eu.net (relay12.Austria.eu.net + [193.154.160.116]) + by developer.postgresql.org (Postfix) with ESMTP id EF45A925124 + for ; + Wed, 28 May 2003 10:31:40 -0400 (EDT) +Received: from relay2.austria.eu.net (endjinn.austria.eu.net [193.81.13.2]) + by relay12.austria.eu.net (Postfix) with ESMTP + id 0571DC5611; Wed, 28 May 2003 16:31:40 +0200 (CEST) +Received: from ICOMWE (office.icomedias.com [62.99.232.80] (may be forged)) + by relay2.austria.eu.net (8.12.9/8.12.6) with SMTP id h4SEVbUg010347; + Wed, 28 May 2003 16:31:39 +0200 (MET DST) +Message-ID: <002401c32525$d92368e0$1e01c00a@icomedias.com> +From: "Mario Weilguni" +To: "Dave Tenny" , + +References: <3ED4B0E5.3050703@attbi.com> +Subject: Re: IN list processing performance (yet again) +Date: Wed, 28 May 2003 16:31:37 +0200 +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit +X-Priority: 3 +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook Express 6.00.2800.1158 +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 +X-Spam-Status: NO ; -10 +X-Spam-Level: +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/233 +X-Sequence-Number: 2012 + +> +> My application relies heavily on IN lists. The lists are primarily +> constant integers, so queries look like: +> +> SELECT val FROM table WHERE id IN (43, 49, 1001, 100002, ...) +> +> Performance is critical, and the size of these lists depends a lot on +> how the larger 3-tier applicaiton is used, +> but it wouldn't be out of the question to retrieve 3000-10000 items. +> +> PostgreSQL 7.3.2 seems to have a lot of trouble with large lists. + +you should rewrite your query if the query is created from an applition: + +SELECT val + FROM table + WHERE id between 43 and 100002 + AND id IN (43, 49, 1001, 100002, ...) + +where 43 is the min and 100002 the max of all values. + +I had this case with postgresql 7.2 and the planner made much smarter +choices in my case. + +Regards, + Mario Weilguni + + + +From pgsql-performance-owner@postgresql.org Wed May 28 10:54:36 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 4540B925550 + for ; + Wed, 28 May 2003 10:54:33 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 52388-10 for ; + Wed, 28 May 2003 10:54:27 -0400 (EDT) +Received: from megazone.bigpanda.com (megazone.bigpanda.com [63.150.15.178]) + by developer.postgresql.org (Postfix) with ESMTP id BC654925571 + for ; + Wed, 28 May 2003 10:54:27 -0400 (EDT) +Received: by megazone.bigpanda.com (Postfix, from userid 1001) + id 12855D665; Wed, 28 May 2003 07:54:27 -0700 (PDT) +Received: from localhost (localhost [127.0.0.1]) + by megazone.bigpanda.com (Postfix) with ESMTP + id 083875C12; Wed, 28 May 2003 07:54:27 -0700 (PDT) +Date: Wed, 28 May 2003 07:54:26 -0700 (PDT) +From: Stephan Szabo +To: Dave Tenny +Cc: +Subject: Re: IN list processing performance (yet again) +In-Reply-To: <3ED4B0E5.3050703@attbi.com> +Message-ID: <20030528074020.G33203-100000@megazone23.bigpanda.com> +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/234 +X-Sequence-Number: 2013 + + +On Wed, 28 May 2003, Dave Tenny wrote: + +> Having grepped the web, it's clear that this isn't the first or last +> time this issue will be raised. +> +> My application relies heavily on IN lists. The lists are primarily +> constant integers, so queries look like: +> +> SELECT val FROM table WHERE id IN (43, 49, 1001, 100002, ...) +> +> Performance is critical, and the size of these lists depends a lot on +> how the larger 3-tier applicaiton is used, +> but it wouldn't be out of the question to retrieve 3000-10000 items. +> +> PostgreSQL 7.3.2 seems to have a lot of trouble with large lists. + +It gets converted into a sequence like col=list[0] or col=list[1] and it +seems the planner/optimizer is taking at least a large amount of time for +me given that explain takes just over 80 seconds for a 9900 item list on +my machine (I don't have a data filled table to run the actual query +against). + +The best plan may be generated right now from making a temporary +table, copying the values into it, and joining. + +> 2) What is the expected acceptable limit for the number of items in an +> IN list predicate such as +> those used here. (List of constants, not subselects). + +As a note, 7.4 by default seems to limit it to 10000 unless you up +max_expr_depth afaics. + + + + +From pgsql-performance-owner@postgresql.org Wed May 28 11:46:07 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id D60F192584F + for ; + Wed, 28 May 2003 11:46:06 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 64115-09 for ; + Wed, 28 May 2003 11:46:06 -0400 (EDT) +Received: from utahisp.com (mail.cyberwires.com [66.239.12.3]) + by developer.postgresql.org (Postfix) with ESMTP id 9620892583D + for ; + Wed, 28 May 2003 11:46:05 -0400 (EDT) +Received: from chad [63.230.8.76] by utahisp.com + (SMTPD32-8.00) id A9E0BBC02E4; Wed, 28 May 2003 09:46:40 -0600 +Message-ID: <027901c32530$273839c0$32021aac@chad> +From: "Chad Thompson" +To: "pgsql-performance" +Subject: >24 hour restore +Date: Wed, 28 May 2003 09:12:23 -0600 +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit +X-Priority: 3 +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook Express 6.00.2720.3000 +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 +X-Declude-Sender: chad@weblinkservices.com [63.230.8.76] +X-Declude-Spoolname: Dd9e00bbc02e4ff35.SMD +X-Note: This E-mail was scanned by Declude JunkMail (www.declude.com) for + spam. +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/235 +X-Sequence-Number: 2014 + +I have, what appears to be a big problem. + +Machine specs +AMD 2100+, +1 GIG SDRam, +3 WD HD's + 1 - 20 Gig -15 Gig system and 5 Gig Swap + mounted as / + 2 - 80 Gig (8 M Cache) in Redhat software RAID 1 (mirror) using Adaptec +1200 as an IDE Controller + mounted as /usr/local/pgsql +Redhat 8 w/ latest kernel and all updates. + +I have a much slower machine that has been running my database. We are +trying to upgrade to the above machine to make things a bit faster. + +I followed "Tips for upgrading PostgreSQL from 6.5.3 to 7.0.3" by Mark +Stosberg with only a few changes + +[postgres@sqlsrv root]# pg_dump -cs mydbtable >sqlschema.sql +[postgres@sqlsrv root]# pg_dump -a mydbtable > sqldump.sql + +sqlschema.sql = 900K +sqldump.sql = 2.4G + +[sftp files to aforementioned machine] + +[postgres@newsqlsrv root]# psql -e mydbtable &1 | tee +schema-full-results.txt; grep ERROR schema-full-results.txt +>schema-err-results.txt + +All this works perfectly, quite fast but when I ran.... + +[postgres@newsqlsrv root]# psql -e &1 | tee +inserts-full-results.txt; grep ERROR inserts-full-results.txt +>inserts-err-results.txt + +It started off quick, but it got to the first table w/ any real data in it +(only about 30k records) and acted like it was frozen. I left it running +all night, it finished that table and started on others but it hasnt even +gotten to the big tables (2 @ about 9 million records). At this pace it +will take several days to finish the restore. + +I hope this is something easy/stupid that I have missed. I know that w/ +mirroring my write times are not improved, but they are DEFINATLY not this +bad. + +I hope that I havent missed any information. +Thank you in advance for any direction. + +Chad + + +From pgsql-performance-owner@postgresql.org Wed May 28 12:12:01 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id CDF4992581C + for ; + Wed, 28 May 2003 12:12:00 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 70951-10 for ; + Wed, 28 May 2003 12:11:59 -0400 (EDT) +Received: from mail1.ihs.com (mail1.ihs.com [170.207.70.222]) + by developer.postgresql.org (Postfix) with ESMTP id E2B919257F3 + for ; + Wed, 28 May 2003 12:11:58 -0400 (EDT) +Received: from css120.ihs.com (css120.ihs.com [170.207.105.120]) + by mail1.ihs.com (8.12.9/8.12.9) with ESMTP id h4SGAbQB020795; + Wed, 28 May 2003 10:10:37 -0600 (MDT) +Date: Wed, 28 May 2003 09:55:51 -0600 (MDT) +From: "scott.marlowe" +To: Chad Thompson +Cc: pgsql-performance +Subject: Re: >24 hour restore +In-Reply-To: <027901c32530$273839c0$32021aac@chad> +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-MailScanner: Found to be clean +X-MailScanner-SpamCheck: +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/236 +X-Sequence-Number: 2015 + +Have a look through the log files for both postgresql and the kernel. + +You could be having issues like SCSI time outs, or a failed disk in a +RAID, or there could be some hints in the postgresql logs about what's +happening. + +What does top show? high CPU load, low? + +iostat ? + +vmstat ? + +On Wed, 28 May 2003, Chad Thompson wrote: + +> I have, what appears to be a big problem. +> +> Machine specs +> AMD 2100+, +> 1 GIG SDRam, +> 3 WD HD's +> 1 - 20 Gig -15 Gig system and 5 Gig Swap +> mounted as / +> 2 - 80 Gig (8 M Cache) in Redhat software RAID 1 (mirror) using Adaptec +> 1200 as an IDE Controller +> mounted as /usr/local/pgsql +> Redhat 8 w/ latest kernel and all updates. +> +> I have a much slower machine that has been running my database. We are +> trying to upgrade to the above machine to make things a bit faster. +> +> I followed "Tips for upgrading PostgreSQL from 6.5.3 to 7.0.3" by Mark +> Stosberg with only a few changes +> +> [postgres@sqlsrv root]# pg_dump -cs mydbtable >sqlschema.sql +> [postgres@sqlsrv root]# pg_dump -a mydbtable > sqldump.sql +> +> sqlschema.sql = 900K +> sqldump.sql = 2.4G +> +> [sftp files to aforementioned machine] +> +> [postgres@newsqlsrv root]# psql -e mydbtable &1 | tee +> schema-full-results.txt; grep ERROR schema-full-results.txt +> >schema-err-results.txt +> +> All this works perfectly, quite fast but when I ran.... +> +> [postgres@newsqlsrv root]# psql -e &1 | tee +> inserts-full-results.txt; grep ERROR inserts-full-results.txt +> >inserts-err-results.txt +> +> It started off quick, but it got to the first table w/ any real data in it +> (only about 30k records) and acted like it was frozen. I left it running +> all night, it finished that table and started on others but it hasnt even +> gotten to the big tables (2 @ about 9 million records). At this pace it +> will take several days to finish the restore. +> +> I hope this is something easy/stupid that I have missed. I know that w/ +> mirroring my write times are not improved, but they are DEFINATLY not this +> bad. +> +> I hope that I havent missed any information. +> Thank you in advance for any direction. +> +> Chad +> +> +> ---------------------------(end of broadcast)--------------------------- +> TIP 6: Have you searched our list archives? +> +> http://archives.postgresql.org +> + + +From pgsql-performance-owner@postgresql.org Wed May 28 12:24:59 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 4D7F2925383 + for ; + Wed, 28 May 2003 12:24:57 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 72855-05 for ; + Wed, 28 May 2003 12:24:56 -0400 (EDT) +Received: from mail.libertyrms.com (unknown [209.167.124.227]) + by developer.postgresql.org (Postfix) with ESMTP id 51003925355 + for ; + Wed, 28 May 2003 12:24:56 -0400 (EDT) +Received: from [10.1.2.130] (helo=dba2) + by mail.libertyrms.com with esmtp (Exim 3.22 #3 (Debian)) + id 19L3jT-0004f1-00 + for ; Wed, 28 May 2003 12:24:55 -0400 +Received: by dba2 (Postfix, from userid 1019) + id 6FE40CB51; Wed, 28 May 2003 12:24:55 -0400 (EDT) +Date: Wed, 28 May 2003 12:24:55 -0400 +From: Andrew Sullivan +To: pgsql-performance +Subject: Re: >24 hour restore +Message-ID: <20030528162455.GG6637@libertyrms.info> +Mail-Followup-To: Andrew Sullivan , + pgsql-performance +References: <027901c32530$273839c0$32021aac@chad> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: <027901c32530$273839c0$32021aac@chad> +User-Agent: Mutt/1.5.4i +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/237 +X-Sequence-Number: 2016 + +On Wed, May 28, 2003 at 09:12:23AM -0600, Chad Thompson wrote: +> +> It started off quick, but it got to the first table w/ any real data in it +> (only about 30k records) and acted like it was frozen. I left it running +> all night, it finished that table and started on others but it hasnt even +> gotten to the big tables (2 @ about 9 million records). At this pace it +> will take several days to finish the restore. + +This makes me think you have a trigger problem. You don't say what +version you're running, but my guess is that you need to disable all +your triggers, and remove all your indices, before you start loading +the data. Re-enable them afterwards. + +By building the schema first, then loading the data, you're spending +cycles running triggers &c. + +A + +-- +---- +Andrew Sullivan 204-4141 Yonge Street +Liberty RMS Toronto, Ontario Canada + M2P 2A8 + +1 416 646 3304 x110 + + +From pgsql-performance-owner@postgresql.org Wed May 28 13:58:18 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id B89379259AA + for ; + Wed, 28 May 2003 13:58:17 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 95164-02 for ; + Wed, 28 May 2003 13:58:16 -0400 (EDT) +Received: from sccrmhc02.attbi.com (sccrmhc02.attbi.com [204.127.202.62]) + by developer.postgresql.org (Postfix) with ESMTP id E75989259A6 + for ; + Wed, 28 May 2003 13:58:15 -0400 (EDT) +Received: from attbi.com (dtenny.ne.client2.attbi.com[24.60.113.221]) + by attbi.com (sccrmhc02) with SMTP + id <2003052817581500200r93g8e>; Wed, 28 May 2003 17:58:15 +0000 +Message-ID: <3ED4F8B6.7030905@attbi.com> +Date: Wed, 28 May 2003 13:58:14 -0400 +From: Dave Tenny +User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3.1) Gecko/20030425 +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: Shridhar Daithankar +Cc: pgsql-performance@postgresql.org +Subject: Re: IN list processing performance (yet again) +References: <3ED4B0E5.3050703@attbi.com> + <200305281846.38928.shridhar_daithankar@nospam.persistent.co.in> +In-Reply-To: <200305281846.38928.shridhar_daithankar@nospam.persistent.co.in> +Content-Type: multipart/alternative; + boundary="------------040509090107020304090108" +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/238 +X-Sequence-Number: 2017 + +This is a multi-part message in MIME format. +--------------040509090107020304090108 +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit + +A join isn't an option, these elements come a a selection of entity ID's +that are specific to some client context. +Some other people suggested joins too. + +Consider it something like this, say there's a database that represents +the entire file system content +of a set of machines, hundreds of thousands of files. A single user +wants to do something +related to the ID's of 3000 files. The requests for those 3000 files +can be built up in a number of ways, +not all of which rely on data in the database. So I need to retrieve +data on those 3000 files using IN lists or some alternative. + +Dave + +Shridhar Daithankar wrote: + +>On Wednesday 28 May 2003 18:21, Dave Tenny wrote: +> +> +>>Having grepped the web, it's clear that this isn't the first or last +>>time this issue will be raised. +>> +>>My application relies heavily on IN lists. The lists are primarily +>>constant integers, so queries look like: +>> +>>SELECT val FROM table WHERE id IN (43, 49, 1001, 100002, ...) +>> +>> +> +>How do you derive this list of number? If it is from same database, can you +>rewrite the query using a join statement? +> +>HTH +> +> Shridhar +> +> +>---------------------------(end of broadcast)--------------------------- +>TIP 4: Don't 'kill -9' the postmaster +> +> +> + +--------------040509090107020304090108 +Content-Type: text/html; charset=us-ascii +Content-Transfer-Encoding: 7bit + + + + + + + + +A join isn't an option, these elements come a a selection of entity +ID's that are specific to some client context.
+Some other people suggested joins too. 
+
+Consider it something like this, say there's a database that represents +the entire file system content
+of a set of machines, hundreds of thousands of files.  A single user +wants to do something
+related to the ID's of 3000 files.  The requests for those 3000 files +can be built up in a number of ways,
+not all of which rely on data in the database.  So I need to retrieve +data on those 3000 files using IN lists or some alternative.
+
+Dave
+
+Shridhar Daithankar wrote:
+
+
On Wednesday 28 May 2003 18:21, Dave Tenny wrote:
+  
+
+
Having grepped the web, it's clear that this isn't the first or last
+time this issue will be raised.
+
+My application relies heavily on IN lists.  The lists are primarily
+constant integers, so queries look like:
+
+SELECT val FROM table WHERE id IN (43, 49, 1001, 100002, ...)
+    
+
+

+How do you derive this list of number? If it is from same database, can you 
+rewrite the query using a join statement?
+
+HTH
+
+ Shridhar
+
+
+---------------------------(end of broadcast)---------------------------
+TIP 4: Don't 'kill -9' the postmaster
+
+  
+
+ + + +--------------040509090107020304090108-- + + +From pgsql-performance-owner@postgresql.org Wed May 28 14:00:36 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id AC6239259B3 + for ; + Wed, 28 May 2003 14:00:34 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 95072-08 for ; + Wed, 28 May 2003 14:00:33 -0400 (EDT) +Received: from utahisp.com (utahisp.com [66.239.12.3]) + by developer.postgresql.org (Postfix) with ESMTP id 99D759259AA + for ; + Wed, 28 May 2003 14:00:31 -0400 (EDT) +Received: from chad [63.230.8.76] by utahisp.com + (SMTPD32-8.00) id A962132E0108; Wed, 28 May 2003 12:01:06 -0600 +Message-ID: <02aa01c32542$ef61f730$32021aac@chad> +From: "Chad Thompson" +To: "Andrew Sullivan" , + "pgsql-performance" +References: <027901c32530$273839c0$32021aac@chad> + <20030528162455.GG6637@libertyrms.info> +Subject: Re: >24 hour restore +Date: Wed, 28 May 2003 11:59:49 -0600 +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit +X-Priority: 3 +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook Express 6.00.2720.3000 +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 +X-Declude-Sender: chad@weblinkservices.com [63.230.8.76] +X-Declude-Spoolname: Df962132e01081036.SMD +X-Note: This E-mail was scanned by Declude JunkMail (www.declude.com) for + spam. +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/239 +X-Sequence-Number: 2018 + + + +> On Wed, May 28, 2003 at 09:12:23AM -0600, Chad Thompson wrote: +> > +> > It started off quick, but it got to the first table w/ any real data in +it +> > (only about 30k records) and acted like it was frozen. I left it +running +> > all night, it finished that table and started on others but it hasnt +even +> > gotten to the big tables (2 @ about 9 million records). At this pace it +> > will take several days to finish the restore. +> +> This makes me think you have a trigger problem. You don't say what +> version you're running, but my guess is that you need to disable all +> your triggers, and remove all your indices, before you start loading +> the data. Re-enable them afterwards. +> +> By building the schema first, then loading the data, you're spending +> cycles running triggers &c. +> + +This was my first thought. After about an hour of running, I stopped the +process, edited the schema file to remove all the foreign keys and triggers. +I then started it again. So there SHOULD be no triggers right now. + +UPDATE: I stopped the restore, before it was stopped, top showed postmaster +using 17% CPU. After stopping I noticed that it DID fill my largest table +(1.16 M tuples) over night. So I am editing the dump file to continue where +it left off. ( vi is the only thing that is not choking on the 2.4 gig file) +That is good news because that means it wont take 7-10 days to import, just +1-2. + +As for version (oops) my old version was 7.3.1 and I am moving to 7.3.2 + +Any other ideas? + +TIA +Chad + +Oh, a bit off topic... I remember that I wanted to move the WAL files off of +the raid but forgot to do it on start up. Can I do that now that the system +is setup? Where would I find docs to tell me about that? + + +From pgsql-performance-owner@postgresql.org Wed May 28 14:08:06 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 6939392588C + for ; + Wed, 28 May 2003 14:08:05 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 97830-07 for ; + Wed, 28 May 2003 14:08:03 -0400 (EDT) +Received: from sccrmhc01.attbi.com (sccrmhc01.attbi.com [204.127.202.61]) + by developer.postgresql.org (Postfix) with ESMTP id 9F955925729 + for ; + Wed, 28 May 2003 14:08:03 -0400 (EDT) +Received: from attbi.com (dtenny.ne.client2.attbi.com[24.60.113.221]) + by attbi.com (sccrmhc01) with SMTP + id <20030528180803001004bmc3e>; Wed, 28 May 2003 18:08:03 +0000 +Message-ID: <3ED4FB02.1010908@attbi.com> +Date: Wed, 28 May 2003 14:08:02 -0400 +From: Dave Tenny +User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3.1) Gecko/20030425 +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: Andreas Pflug +Cc: pgsql-performance@postgresql.org +Subject: Re: IN list processing performance (yet again) +References: <3ED4B0E5.3050703@attbi.com> <3ED4B75A.2050106@web.de> +In-Reply-To: <3ED4B75A.2050106@web.de> +Content-Type: text/plain; charset=ISO-8859-1; format=flowed +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/240 +X-Sequence-Number: 2019 + +Andreas Pflug wrote: + +> Dave Tenny wrote: +> +>> Having grepped the web, it's clear that this isn't the first or last +>> time this issue will be raised. +>> +>> My application relies heavily on IN lists. The lists are primarily +>> constant integers, so queries look like: +>> +>> SELECT val FROM table WHERE id IN (43, 49, 1001, 100002, ...) +>> +>> Performance is critical, and the size of these lists depends a lot on +>> how the larger 3-tier applicaiton is used, +>> but it wouldn't be out of the question to retrieve 3000-10000 items. +>> +>> PostgreSQL 7.3.2 seems to have a lot of trouble with large lists. +>> I ran an experiment that ran queries on a table of two integers (ID, +>> VAL), where ID is a primary key and the subject +>> of IN list predicates. The test used a table with one million rows +>> ID is appropriately indexed, +>> and I have VACUUMED/analyzed the database after table load. +>> +>> I ran tests on in-lists from about 100 to 100,000 entries. +> +> +> Hi Dave, +> +> it sounds as if that IN-list is created by the application. I wonder +> if there are really so many variances and combinations of it or +> whether you could invent an additional column, which groups all those +> individual values. If possible, you could reduce your IN list to much +> fewer values, and probably would get better performance (using an +> index on that col, of course). + + +There are over 50 tables in the schema, +and dozens of client commands that manipulate the schema in a +persistent-checkout kind of way over time, as well as spurious reporting +requests +that require incredibly complex filtering and combination of data from +many tables. +I'm pretty much up to my keister data (and am resisting impulses for +denormalization), so this approach +probably isn't viable for me. Now I *could* create a temporary table +with the group of values, but I suspect the cost of that +substantially outweighs the negative performance of current IN lists or +parameterized statements. + +I'm reminded to relay to the PostgreSQL devos that I might be able to do +more in the join or subquery department if +PostgreSQL had better performing MAX functions and a FIRST function for +selecting rows from groups. +("Performing" being the operative word here, since the extensible +architecture of PostgreSQL currently makes for poorly +performing MAX capabilities and presumably similar user defined +aggregate functions). + +> +> Regards, +> +> Andreas +> +> +> +> +> ---------------------------(end of broadcast)--------------------------- +> TIP 3: if posting/reading through Usenet, please send an appropriate +> subscribe-nomail command to majordomo@postgresql.org so that your +> message can get through to the mailing list cleanly +> + + +From pgsql-performance-owner@postgresql.org Wed May 28 14:14:07 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 9CDCD9259B8 + for ; + Wed, 28 May 2003 14:14:04 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 99761-01 for ; + Wed, 28 May 2003 14:14:03 -0400 (EDT) +Received: from mail.libertyrms.com (unknown [209.167.124.227]) + by developer.postgresql.org (Postfix) with ESMTP id B680592588C + for ; + Wed, 28 May 2003 14:14:03 -0400 (EDT) +Received: from [10.1.2.130] (helo=dba2) + by mail.libertyrms.com with esmtp (Exim 3.22 #3 (Debian)) + id 19L5R5-0005Kb-00 + for ; Wed, 28 May 2003 14:14:03 -0400 +Received: by dba2 (Postfix, from userid 1019) + id 10FC8CB4D; Wed, 28 May 2003 14:14:03 -0400 (EDT) +Date: Wed, 28 May 2003 14:14:03 -0400 +From: Andrew Sullivan +To: pgsql-performance +Subject: Re: >24 hour restore +Message-ID: <20030528181402.GK6637@libertyrms.info> +Mail-Followup-To: Andrew Sullivan , + pgsql-performance +References: <027901c32530$273839c0$32021aac@chad> + <20030528162455.GG6637@libertyrms.info> + <02aa01c32542$ef61f730$32021aac@chad> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: <02aa01c32542$ef61f730$32021aac@chad> +User-Agent: Mutt/1.5.4i +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/241 +X-Sequence-Number: 2020 + +On Wed, May 28, 2003 at 11:59:49AM -0600, Chad Thompson wrote: + +> This was my first thought. After about an hour of running, I stopped the +> process, edited the schema file to remove all the foreign keys and triggers. +> I then started it again. So there SHOULD be no triggers right now. + +Hmm. + +> UPDATE: I stopped the restore, before it was stopped, top showed postmaster +> using 17% CPU. After stopping I noticed that it DID fill my largest table +> (1.16 M tuples) over night. So I am editing the dump file to continue where +> it left off. ( vi is the only thing that is not choking on the 2.4 gig file) +> That is good news because that means it wont take 7-10 days to import, just +> 1-2. + +Sounds like you have an I/O problem. + +> As for version (oops) my old version was 7.3.1 and I am moving to 7.3.2 + +Why don't you just shut down your 7.3.1 postmaster and start 7.3.2? +This requires no initdb. If you're changing machines (ISTR you are), +then copy the tree, assuming the same OS. + +> Oh, a bit off topic... I remember that I wanted to move the WAL files off of +> the raid but forgot to do it on start up. Can I do that now that the system +> is setup? Where would I find docs to tell me about that? + +Sure. Stop the postmaster, copy the pg_xlog directory to the target +location, then make a soft link. (I usually use cp and move the old +dir out of the way temporarily to start with, just in case.) + +A + +-- +---- +Andrew Sullivan 204-4141 Yonge Street +Liberty RMS Toronto, Ontario Canada + M2P 2A8 + +1 416 646 3304 x110 + + +From pgsql-performance-owner@postgresql.org Wed May 28 14:17:30 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 52F089259B5 + for ; + Wed, 28 May 2003 14:17:27 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 00212-08 for ; + Wed, 28 May 2003 14:17:23 -0400 (EDT) +Received: from sccrmhc03.attbi.com (sccrmhc03.attbi.com [204.127.202.63]) + by developer.postgresql.org (Postfix) with ESMTP id 4BBE49259D9 + for ; + Wed, 28 May 2003 14:17:23 -0400 (EDT) +Received: from attbi.com (dtenny.ne.client2.attbi.com[24.60.113.221]) + by attbi.com (sccrmhc03) with SMTP + id <2003052818172200300e9v7ae>; Wed, 28 May 2003 18:17:22 +0000 +Message-ID: <3ED4FD31.5090804@attbi.com> +Date: Wed, 28 May 2003 14:17:21 -0400 +From: Dave Tenny +User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3.1) Gecko/20030425 +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: Mario Weilguni +Cc: pgsql-performance@postgresql.org +Subject: Re: IN list processing performance (yet again) +References: <3ED4B0E5.3050703@attbi.com> + <002401c32525$d92368e0$1e01c00a@icomedias.com> +In-Reply-To: <002401c32525$d92368e0$1e01c00a@icomedias.com> +Content-Type: multipart/alternative; + boundary="------------050507090400080101010005" +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/242 +X-Sequence-Number: 2021 + +This is a multi-part message in MIME format. +--------------050507090400080101010005 +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit + +Mario Weilguni wrote: + +>>My application relies heavily on IN lists. The lists are primarily +>>constant integers, so queries look like: +>> +>>SELECT val FROM table WHERE id IN (43, 49, 1001, 100002, ...) +>> +>>Performance is critical, and the size of these lists depends a lot on +>>how the larger 3-tier applicaiton is used, +>>but it wouldn't be out of the question to retrieve 3000-10000 items. +>> +>>PostgreSQL 7.3.2 seems to have a lot of trouble with large lists. +>> +>> +> +>you should rewrite your query if the query is created from an applition: +> +>SELECT val +> FROM table +> WHERE id between 43 and 100002 +> AND id IN (43, 49, 1001, 100002, ...) +> +>where 43 is the min and 100002 the max of all values. +> +>I had this case with postgresql 7.2 and the planner made much smarter +>choices in my case. +> +>Regards, +> Mario Weilguni +> +> +Very interesting! I tried it out, but it didn't appreciably change the +thresholds in my results for going by for IN list +sizes 100 - 1000. It's also likely to be of use only if the range for +the between is fairly restricted, +which isn't necessarily characteristic of my data. + +Dave + +--------------050507090400080101010005 +Content-Type: text/html; charset=us-ascii +Content-Transfer-Encoding: 7bit + + + + + + + + +Mario Weilguni wrote:
+
+
+
My application relies heavily on IN lists.  The lists are primarily
+constant integers, so queries look like:
+
+SELECT val FROM table WHERE id IN (43, 49, 1001, 100002, ...)
+
+Performance is critical, and the size of these lists depends a lot on
+how the larger 3-tier applicaiton is used,
+but it wouldn't be out of the question to retrieve 3000-10000 items.
+
+PostgreSQL 7.3.2 seems to have a lot of trouble with large lists.
+    
+
+

+you should rewrite your query if the query is created from an applition:
+
+SELECT val
+   FROM table
+ WHERE id between 43 and 100002
+       AND id IN (43, 49, 1001, 100002, ...)
+
+where 43 is the min and 100002 the max of all values.
+
+I had this case with postgresql 7.2 and the planner made much smarter
+choices in my case.
+
+Regards,
+    Mario Weilguni
+  
+
+Very interesting!  I tried it out, but it didn't appreciably change the +thresholds in my results for going by for IN list
+sizes 100 - 1000.  It's also likely to be of use only if the range for +the between is fairly restricted,
+which isn't necessarily characteristic of my data.
+
+Dave
+ + + +--------------050507090400080101010005-- + + +From pgsql-performance-owner@postgresql.org Wed May 28 14:30:05 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id AA8179259EE + for ; + Wed, 28 May 2003 14:30:02 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 04507-05 for ; + Wed, 28 May 2003 14:29:58 -0400 (EDT) +Received: from relay.icomedias.com (relay.icomedias.com [62.99.232.66]) + by developer.postgresql.org (Postfix) with ESMTP id E4B03925A4C + for ; + Wed, 28 May 2003 14:29:50 -0400 (EDT) +Received: from loki.icomedias.com ([10.192.17.128]) + by relay.icomedias.com (8.12.9/8.12.9) with ESMTP id h4SITigB004194; + Wed, 28 May 2003 20:29:46 +0200 +From: Mario Weilguni +To: Dave Tenny , + Andreas Pflug +Subject: Re: IN list processing performance (yet again) +Date: Wed, 28 May 2003 20:29:43 +0200 +User-Agent: KMail/1.5.2 +Cc: pgsql-performance@postgresql.org +References: <3ED4B0E5.3050703@attbi.com> <3ED4B75A.2050106@web.de> + <3ED4FB02.1010908@attbi.com> +In-Reply-To: <3ED4FB02.1010908@attbi.com> +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit +Content-Disposition: inline +Message-Id: <200305282029.44152.mweilguni@sime.com> +avpresult: 0, ok, ok, +X-Scanned-By: MIMEDefang 2.16 (www . roaringpenguin . com / mimedefang) +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/243 +X-Sequence-Number: 2022 + +> I'm reminded to relay to the PostgreSQL devos that I might be able to do +> more in the join or subquery department if +> PostgreSQL had better performing MAX functions and a FIRST function for +> selecting rows from groups. +> ("Performing" being the operative word here, since the extensible +> architecture of PostgreSQL currently makes for poorly +> performing MAX capabilities and presumably similar user defined +> aggregate functions). + +MIN/MAX is almost in every case replaceable: +select bar + from foo + order by bar limit 1; + +instead of +select max(bar) from foo; + + + +From pgsql-performance-owner@postgresql.org Wed May 28 14:37:05 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 347C89233A2 + for ; + Wed, 28 May 2003 14:37:05 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 07115-02 for ; + Wed, 28 May 2003 14:37:03 -0400 (EDT) +Received: from wolff.to (wolff.to [66.93.249.74]) + by developer.postgresql.org (Postfix) with SMTP id 0D3B292334A + for ; + Wed, 28 May 2003 14:37:03 -0400 (EDT) +Received: (qmail 6140 invoked by uid 500); 28 May 2003 18:39:14 -0000 +Date: Wed, 28 May 2003 13:39:14 -0500 +From: Bruno Wolff III +To: Dave Tenny +Cc: Andreas Pflug , + pgsql-performance@postgresql.org +Subject: Re: IN list processing performance (yet again) +Message-ID: <20030528183914.GA6118@wolff.to> +Mail-Followup-To: Dave Tenny , + Andreas Pflug , + pgsql-performance@postgresql.org +References: <3ED4B0E5.3050703@attbi.com> <3ED4B75A.2050106@web.de> + <3ED4FB02.1010908@attbi.com> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: <3ED4FB02.1010908@attbi.com> +User-Agent: Mutt/1.5.4i +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/244 +X-Sequence-Number: 2023 + +On Wed, May 28, 2003 at 14:08:02 -0400, + Dave Tenny wrote: +> Andreas Pflug wrote: +> +> I'm reminded to relay to the PostgreSQL devos that I might be able to do +> more in the join or subquery department if +> PostgreSQL had better performing MAX functions and a FIRST function for +> selecting rows from groups. +> ("Performing" being the operative word here, since the extensible +> architecture of PostgreSQL currently makes for poorly +> performing MAX capabilities and presumably similar user defined +> aggregate functions). + +Have you tried replacing max with a subselect that uses order by and limit? + +From pgsql-performance-owner@postgresql.org Wed May 28 14:39:43 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id BAEF59235B3 + for ; + Wed, 28 May 2003 14:39:40 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 07634-01 for ; + Wed, 28 May 2003 14:39:39 -0400 (EDT) +Received: from wolff.to (wolff.to [66.93.249.74]) + by developer.postgresql.org (Postfix) with SMTP id 53B389235B0 + for ; + Wed, 28 May 2003 14:39:38 -0400 (EDT) +Received: (qmail 6158 invoked by uid 500); 28 May 2003 18:41:50 -0000 +Date: Wed, 28 May 2003 13:41:50 -0500 +From: Bruno Wolff III +To: Dave Tenny +Cc: Shridhar Daithankar , + pgsql-performance@postgresql.org +Subject: Re: IN list processing performance (yet again) +Message-ID: <20030528184150.GB6118@wolff.to> +Mail-Followup-To: Dave Tenny , + Shridhar Daithankar , + pgsql-performance@postgresql.org +References: <3ED4B0E5.3050703@attbi.com> + <200305281846.38928.shridhar_daithankar@nospam.persistent.co.in> + <3ED4F8B6.7030905@attbi.com> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: <3ED4F8B6.7030905@attbi.com> +User-Agent: Mutt/1.5.4i +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/245 +X-Sequence-Number: 2024 + +On Wed, May 28, 2003 at 13:58:14 -0400, + Dave Tenny wrote: +> A join isn't an option, these elements come a a selection of entity ID's +> that are specific to some client context. +> Some other people suggested joins too. + +You can union the values together and then join (or use where exists) with the +result. This may not be faster and you may not be able to union several +thousand selects together in a single statement. But it shouldn't be too +much work to test it out. + +From pgsql-performance-owner@postgresql.org Wed May 28 15:57:29 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 0F81B925AF6 + for ; + Wed, 28 May 2003 15:57:28 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 24866-04 for ; + Wed, 28 May 2003 15:57:23 -0400 (EDT) +Received: from sccrmhc03.attbi.com (sccrmhc03.attbi.com [204.127.202.63]) + by developer.postgresql.org (Postfix) with ESMTP id 68FFC925AB7 + for ; + Wed, 28 May 2003 15:57:23 -0400 (EDT) +Received: from attbi.com (dtenny.ne.client2.attbi.com[24.60.113.221]) + by attbi.com (sccrmhc03) with SMTP + id <2003052819572300300jc3sre>; Wed, 28 May 2003 19:57:23 +0000 +Message-ID: <3ED514A2.8060107@attbi.com> +Date: Wed, 28 May 2003 15:57:22 -0400 +From: Dave Tenny +User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3.1) Gecko/20030425 +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: Mario Weilguni +Cc: Andreas Pflug , + pgsql-performance@postgresql.org +Subject: Re: IN list processing performance (yet again) +References: <3ED4B0E5.3050703@attbi.com> <3ED4B75A.2050106@web.de> + <3ED4FB02.1010908@attbi.com> + <200305282029.44152.mweilguni@sime.com> +In-Reply-To: <200305282029.44152.mweilguni@sime.com> +Content-Type: multipart/alternative; + boundary="------------000003050904030903060308" +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/246 +X-Sequence-Number: 2025 + +This is a multi-part message in MIME format. +--------------000003050904030903060308 +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit + +Mario Weilguni wrote: + +>>I'm reminded to relay to the PostgreSQL devos that I might be able to do +>>more in the join or subquery department if +>>PostgreSQL had better performing MAX functions and a FIRST function for +>>selecting rows from groups. +>>("Performing" being the operative word here, since the extensible +>>architecture of PostgreSQL currently makes for poorly +>>performing MAX capabilities and presumably similar user defined +>>aggregate functions). +>> +>> +> +>MIN/MAX is almost in every case replaceable: +>select bar +> from foo +> order by bar limit 1; +> +>instead of +>select max(bar) from foo; +> +> +Yup, been there, done that, but thanks, it's a good tidbit for the +postgresql unaware. + +There are some places however where it doesn't work well in query logic, +though I don't have an example off the top of my head +since I've worked around it in all my queries. + + + +--------------000003050904030903060308 +Content-Type: text/html; charset=us-ascii +Content-Transfer-Encoding: 7bit + + + + + + + + +Mario Weilguni wrote:
+
+
+
I'm reminded to relay to the PostgreSQL devos that I might be able to do
+more in the  join or subquery department if
+PostgreSQL had better performing MAX functions and a FIRST function for
+selecting rows from groups.
+("Performing" being the operative word here, since the extensible
+architecture of PostgreSQL currently makes for poorly
+performing MAX capabilities and presumably similar user defined
+aggregate functions).
+    
+
+

+MIN/MAX is almost in every case replaceable:
+select bar
+   from foo
+ order by bar limit 1;
+
+instead of
+select max(bar) from foo;
+  
+
+Yup, been there, done that, but thanks, it's a good tidbit for the +postgresql unaware.
+
+There are some places however where it doesn't work well in query +logic, though I don't have an example off the top of my head
+since I've worked around it in all my queries.
+
+
+ + + +--------------000003050904030903060308-- + + +From pgsql-performance-owner@postgresql.org Wed May 28 16:01:40 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id AA331925304 + for ; + Wed, 28 May 2003 16:01:38 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 24942-09 for ; + Wed, 28 May 2003 16:01:36 -0400 (EDT) +Received: from sccrmhc01.attbi.com (sccrmhc01.attbi.com [204.127.202.61]) + by developer.postgresql.org (Postfix) with ESMTP id 6CAF59251A5 + for ; + Wed, 28 May 2003 16:01:35 -0400 (EDT) +Received: from attbi.com (dtenny.ne.client2.attbi.com[24.60.113.221]) + by attbi.com (sccrmhc01) with SMTP + id <20030528200135001004j3ske>; Wed, 28 May 2003 20:01:35 +0000 +Message-ID: <3ED5159E.2050407@attbi.com> +Date: Wed, 28 May 2003 16:01:34 -0400 +From: Dave Tenny +User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3.1) Gecko/20030425 +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: Bruno Wolff III +Cc: Andreas Pflug , + pgsql-performance@postgresql.org +Subject: Re: IN list processing performance (yet again) +References: <3ED4B0E5.3050703@attbi.com> <3ED4B75A.2050106@web.de> + <3ED4FB02.1010908@attbi.com> <20030528183914.GA6118@wolff.to> +In-Reply-To: <20030528183914.GA6118@wolff.to> +Content-Type: multipart/alternative; + boundary="------------000401040609080703080200" +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/247 +X-Sequence-Number: 2026 + +This is a multi-part message in MIME format. +--------------000401040609080703080200 +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit + +Bruno Wolff III wrote: + +>On Wed, May 28, 2003 at 14:08:02 -0400, +> Dave Tenny wrote: +> +> +>>Andreas Pflug wrote: +>> +>>I'm reminded to relay to the PostgreSQL devos that I might be able to do +>>more in the join or subquery department if +>>PostgreSQL had better performing MAX functions and a FIRST function for +>>selecting rows from groups. +>>("Performing" being the operative word here, since the extensible +>>architecture of PostgreSQL currently makes for poorly +>>performing MAX capabilities and presumably similar user defined +>>aggregate functions). +>> +>> +> +>Have you tried replacing max with a subselect that uses order by and limit? +> +> + +I'm uncertain how that would work, since somewhere in there I still need +to elaborate on the +1000 items I want, and they're not necessarily in any particular range, +nor do they bear any +contiguous group nature. + +Also, IN (subquery) is a known performance problem in PGSQL, at least if +the subquery is going to return many rows. +It's too bad, since I'm rather fond of subqueries, but I avoid them like +the plague in PostgreSQL. + +Perhaps I don't understand what you had in mind. + + +--------------000401040609080703080200 +Content-Type: text/html; charset=us-ascii +Content-Transfer-Encoding: 7bit + + + + + + + + +Bruno Wolff III wrote:
+
+
On Wed, May 28, 2003 at 14:08:02 -0400,
+  Dave Tenny <tenny@attbi.com> wrote:
+  
+
+
Andreas Pflug wrote:
+
+I'm reminded to relay to the PostgreSQL devos that I might be able to do 
+more in the  join or subquery department if
+PostgreSQL had better performing MAX functions and a FIRST function for 
+selecting rows from groups.
+("Performing" being the operative word here, since the extensible 
+architecture of PostgreSQL currently makes for poorly
+performing MAX capabilities and presumably similar user defined 
+aggregate functions).
+    
+
+

+Have you tried replacing max with a subselect that uses order by and limit?
+  
+
+
+I'm uncertain how that would work, since somewhere in there I still +need to elaborate on the
+1000 items I want, and they're not necessarily in any particular range, +nor do they bear any
+contiguous group nature.
+
+Also, IN (subquery) is a known performance problem in PGSQL, at least +if the subquery is going to return many rows.
+It's too bad, since I'm rather fond of subqueries, but I avoid them +like the plague in PostgreSQL.
+
+Perhaps I don't understand what you had in mind.
+
+ + + +--------------000401040609080703080200-- + + +From pgsql-performance-owner@postgresql.org Wed May 28 16:13:22 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 578E69259DA + for ; + Wed, 28 May 2003 16:13:19 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 28975-03 for ; + Wed, 28 May 2003 16:13:18 -0400 (EDT) +Received: from sccrmhc03.attbi.com (sccrmhc03.attbi.com [204.127.202.63]) + by developer.postgresql.org (Postfix) with ESMTP id 7CAF69258F9 + for ; + Wed, 28 May 2003 16:13:18 -0400 (EDT) +Received: from attbi.com (dtenny.ne.client2.attbi.com[24.60.113.221]) + by attbi.com (sccrmhc03) with SMTP + id <2003052820131800300ant5ie>; Wed, 28 May 2003 20:13:18 +0000 +Message-ID: <3ED5185D.2000102@attbi.com> +Date: Wed, 28 May 2003 16:13:17 -0400 +From: Dave Tenny +User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3.1) Gecko/20030425 +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: Bruno Wolff III +Cc: Shridhar Daithankar , + pgsql-performance@postgresql.org +Subject: Re: IN list processing performance (yet again) +References: <3ED4B0E5.3050703@attbi.com> + <200305281846.38928.shridhar_daithankar@nospam.persistent.co.in> + <3ED4F8B6.7030905@attbi.com> <20030528184150.GB6118@wolff.to> +In-Reply-To: <20030528184150.GB6118@wolff.to> +Content-Type: multipart/alternative; + boundary="------------010307030702020301050308" +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/248 +X-Sequence-Number: 2027 + +This is a multi-part message in MIME format. +--------------010307030702020301050308 +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit + +Bruno Wolff III wrote: + +>On Wed, May 28, 2003 at 13:58:14 -0400, +> Dave Tenny wrote: +> +> +>>A join isn't an option, these elements come a a selection of entity ID's +>>that are specific to some client context. +>>Some other people suggested joins too. +>> +>> +> +>You can union the values together and then join (or use where exists) with the +>result. This may not be faster and you may not be able to union several +>thousand selects together in a single statement. But it shouldn't be too +>much work to test it out. +> +> +I assume you mean something like: + +test=# select million.id, million.val from million, (select 10000 as a +union select 20000 as a) t2 where million.id = t2.a; + id | val +-------+------- + 10000 | 0 + 20000 | 10000 +(2 rows) + +Ouch! That's deviant. Haven't tried it yet and I cringe at the +thought of it, but I might take a run at it. However that's going to +run up the buffer space quickly. That was one of my as yet unsnaswered +questions, what is the pragmatic buffer size limit +for queries? + +I'm /really/ hoping we'll come up with something better, like an +understanding of why IN lists are non-linear in the first +place when the column is indexed, and whether it's fixable through some +other means or whether it's a bug that should be fixed. + +After all, I'm trying to support multiple databases, and other databases +kick butt on this. It's just postgresql that's +having difficulty. + +(Btw, I've also tried statement batching, but that's a lose for now, at +least with the current JDBC drivers and 7.3.2). + + +--------------010307030702020301050308 +Content-Type: text/html; charset=us-ascii +Content-Transfer-Encoding: 7bit + + + + + + + + +Bruno Wolff III wrote:
+
+
On Wed, May 28, 2003 at 13:58:14 -0400,
+  Dave Tenny <tenny@attbi.com> wrote:
+  
+
+
A join isn't an option, these elements come a a selection of entity ID's 
+that are specific to some client context.
+Some other people suggested joins too. 
+    
+
+

+You can union the values together and then join (or use where exists) with the
+result. This may not be faster and you may not be able to union several
+thousand selects together in a single statement. But it shouldn't be too
+much work to test it out.
+  
+
+I assume you mean something like:
+
+test=# select million.id, million.val from million, (select 10000 as a +union select 20000 as a) t2 where million.id = t2.a;
+  id   |  val
+-------+-------
+ 10000 |     0
+ 20000 | 10000
+(2 rows)
+
+Ouch!  That's deviant.   Haven't tried it yet and I cringe at the +thought of it, but I might take a run at it.  However that's going to
+run up the buffer space quickly.  That was one of my as yet unsnaswered +questions, what is the pragmatic buffer size limit
+for queries?
+
+I'm really hoping we'll come up with something better, like an +understanding of why IN lists are non-linear in the first
+place when the column is indexed, and whether it's fixable through some +other means or whether it's a bug that should be fixed.
+
+After all, I'm trying to support multiple databases, and other +databases kick butt on this.  It's just postgresql that's
+having difficulty.
+
+(Btw, I've also tried statement batching, but that's a lose for now, at +least with the current JDBC drivers and 7.3.2).
+
+ + + +--------------010307030702020301050308-- + + +From pgsql-performance-owner@postgresql.org Wed May 28 16:22:10 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 28E1C925A68 + for ; + Wed, 28 May 2003 16:22:07 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 30420-05 for ; + Wed, 28 May 2003 16:22:06 -0400 (EDT) +Received: from wolff.to (wolff.to [66.93.249.74]) + by developer.postgresql.org (Postfix) with SMTP id 3DF5B925A65 + for ; + Wed, 28 May 2003 16:22:06 -0400 (EDT) +Received: (qmail 6702 invoked by uid 500); 28 May 2003 20:24:18 -0000 +Date: Wed, 28 May 2003 15:24:18 -0500 +From: Bruno Wolff III +To: Dave Tenny +Cc: Andreas Pflug , + pgsql-performance@postgresql.org +Subject: Re: IN list processing performance (yet again) +Message-ID: <20030528202418.GB6655@wolff.to> +Mail-Followup-To: Dave Tenny , + Andreas Pflug , + pgsql-performance@postgresql.org +References: <3ED4B0E5.3050703@attbi.com> <3ED4B75A.2050106@web.de> + <3ED4FB02.1010908@attbi.com> <20030528183914.GA6118@wolff.to> + <3ED5159E.2050407@attbi.com> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: <3ED5159E.2050407@attbi.com> +User-Agent: Mutt/1.5.4i +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/249 +X-Sequence-Number: 2028 + +On Wed, May 28, 2003 at 16:01:34 -0400, + Dave Tenny wrote: +> +> Perhaps I don't understand what you had in mind. +> + +I was refering to your comment about max causing problems. But it seems +you are aware of the standard work around. + +From pgsql-performance-owner@postgresql.org Wed May 28 16:26:57 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 467D5925B13 + for ; + Wed, 28 May 2003 16:26:55 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 31738-01 for ; + Wed, 28 May 2003 16:26:54 -0400 (EDT) +Received: from wolff.to (wolff.to [66.93.249.74]) + by developer.postgresql.org (Postfix) with SMTP id 62793925B0E + for ; + Wed, 28 May 2003 16:26:54 -0400 (EDT) +Received: (qmail 6717 invoked by uid 500); 28 May 2003 20:29:05 -0000 +Date: Wed, 28 May 2003 15:29:05 -0500 +From: Bruno Wolff III +To: Dave Tenny +Cc: Shridhar Daithankar , + pgsql-performance@postgresql.org +Subject: Re: IN list processing performance (yet again) +Message-ID: <20030528202905.GC6655@wolff.to> +Mail-Followup-To: Dave Tenny , + Shridhar Daithankar , + pgsql-performance@postgresql.org +References: <3ED4B0E5.3050703@attbi.com> + <200305281846.38928.shridhar_daithankar@nospam.persistent.co.in> + <3ED4F8B6.7030905@attbi.com> <20030528184150.GB6118@wolff.to> + <3ED5185D.2000102@attbi.com> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: <3ED5185D.2000102@attbi.com> +User-Agent: Mutt/1.5.4i +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/250 +X-Sequence-Number: 2029 + +On Wed, May 28, 2003 at 16:13:17 -0400, + Dave Tenny wrote: +> Bruno Wolff III wrote: +> +> I assume you mean something like: +> +> test=# select million.id, million.val from million, (select 10000 as a +> union select 20000 as a) t2 where million.id = t2.a; +> id | val +> -------+------- +> 10000 | 0 +> 20000 | 10000 +> (2 rows) +> +> Ouch! That's deviant. Haven't tried it yet and I cringe at the +> thought of it, but I might take a run at it. However that's going to +> run up the buffer space quickly. That was one of my as yet unsnaswered +> questions, what is the pragmatic buffer size limit +> for queries? + +That is what I was referring to. I have used this in some cases where +I knew the list was small and I wanted to do a set difference without +loading a temporary table. Or to do an insert of multiple rows with +one insert statement. + +> I'm /really/ hoping we'll come up with something better, like an +> understanding of why IN lists are non-linear in the first +> place when the column is indexed, and whether it's fixable through some +> other means or whether it's a bug that should be fixed. + +It also might be worth seeing if the development version is going to +speed things up for you. Beta is one month away. My guess is that the +production release will be in September. + +From pgsql-performance-owner@postgresql.org Wed May 28 16:53:01 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id C7B32925B2B + for ; + Wed, 28 May 2003 16:52:58 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 37298-02 for ; + Wed, 28 May 2003 16:52:57 -0400 (EDT) +Received: from elbereth.noviforum.si (unknown [193.189.169.66]) + by developer.postgresql.org (Postfix) with ESMTP id C4054925B0E + for ; + Wed, 28 May 2003 16:52:56 -0400 (EDT) +Received: (from gregab@localhost) + by elbereth.noviforum.si (8.11.4/8.11.4) id h4SKquo25416 + for pgsql-performance@postgresql.org; Wed, 28 May 2003 22:52:56 +0200 +Date: Wed, 28 May 2003 22:52:56 +0200 +From: Grega Bremec +To: pgsql-performance@postgresql.org +Subject: Re: Wildcard searches & performance question +Message-ID: <20030528225256.A24693@elbereth.noviforum.si> +References: <20030527210908.A571@elbereth.noviforum.si> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +User-Agent: Mutt/1.2.5i +In-Reply-To: <20030527210908.A571@elbereth.noviforum.si>; + from grega.bremec@noviforum.si on Tue, May 27, 2003 at 09:09:08PM + +0200 +Organization: Noviforum, Ltd., Software & Media +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/251 +X-Sequence-Number: 2030 + +Thank you very much for all your suggestions. + +I am planning on investing some time into trying out a couple FT indexes. Not +minding the fact most of the queries are going to be exact phrase substring +searches, performance will most probably benefit from it, so at least some of +what I'm after is achieved that way. + +I shall be getting back with reports, in case anyone is interested. + +Cheers, +-- + Grega Bremec + System Administration & Development Support + grega.bremec-at-noviforum.si + http://najdi.si/ + http://www.noviforum.si/ + +From pgsql-performance-owner@postgresql.org Wed May 28 17:30:41 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP + id D4516925A1C; Wed, 28 May 2003 17:30:39 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 51018-06; Wed, 28 May 2003 17:30:34 -0400 (EDT) +Received: from ms-smtp-01.tampabay.rr.com (ms-smtp-01.tampabay.rr.com + [65.32.1.43]) by developer.postgresql.org (Postfix) with ESMTP + id EADAA925A19; Wed, 28 May 2003 17:30:33 -0400 (EDT) +Received: from mattspc (169-52.34-65.tampabay.rr.com [65.34.52.169]) + by ms-smtp-01.tampabay.rr.com (8.12.5/8.12.5) with ESMTP id + h4SLUOCO021347; Wed, 28 May 2003 17:30:24 -0400 (EDT) +From: "Matthew Nuzum" +To: , + "'Pgsql-Performance'" +Cc: "'Matthew Nuzum'" +Subject: recursive srf +Date: Wed, 28 May 2003 17:30:01 -0400 +Organization: Bearfruit.org +Message-ID: <002601c32560$4c8468e0$a322fea9@mattspc> +MIME-Version: 1.0 +Content-Type: text/plain; + charset="us-ascii" +Content-Transfer-Encoding: quoted-printable +X-Priority: 3 (Normal) +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook, Build 10.0.4510 +Importance: Normal +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/252 +X-Sequence-Number: 2031 + +Working on my first set returning function... So far the examples from +http://techdocs.postgresql.org/guides/SetReturningFunctions have worked well +for me... + +I'd like to see what kind of performance I get from a particularly slow +piece of code by replacing it with a recursive srf (right now, I do the +recursion in php). + +So, here's my working example, I haven't bench marked it yet, but if someone +would look at it and tell me if there's any improvements that can be made, +I'd appreciate it. My first impression is that it's fast, because it +appeared to have returned instantaneously. I really don't understand the +"explain analyze" output, but I'm including it as well. + +I'd love to get some feedback on this (did I say that already?). + +Imagine this: +CREATE TYPE nav_list AS (id int8, accountid varchar(12),=20 + ...snip... , parent int8, subfolders int8); + +subfolders is the count() of records that have their parent set to this +record's id. I want to take a list of something like this: +home + - item 1 + - item 2 + - sub item 1 + - item 3 +and return it so that it comes out in this order +home +item1 +item2 +sub item 1 +item 3 + +create or replace function nav_srf(varchar(12), int8) returns setof nav_list +as ' +DECLARE=20 + r nav_list%rowtype; + depth int8; + last_id int8; + records RECORD; +BEGIN + FOR r IN SELECT * FROM navigation WHERE accountid =3D $1 AND parent =3D +$2 ORDER BY dsply_order LOOP + depth :=3D r.subfolders; + last_id :=3D r.id; + RETURN NEXT r; + IF depth > 0 THEN + FOR records IN SELECT * FROM nav_srf($1, last_id) +LOOOP + RETURN NEXT records; + END LOOP; + END IF; + END LOOP; + RETURN; +END +' LANGUAGE 'plpgsql'; + + +# EXPLAIN ANALYZE SELECT * FROM nav_srf('GOTDNS000000', 0); +QUERY PLAN +Function Scan on nav_srf (cost=3D0.00..12.50 rows=3D1000 width=3D134) (act= +ual +time=3D85.78..86.19 rows=3D22 loops=3D1) +Total runtime: 86.37 msec +(2 rows) + +I then ran it again a moment later and got: +# EXPLAIN ANALYZE SELECT * FROM nav_srf('GOTDNS000000', 0); +QUERY PLAN +Function Scan on nav_srf (cost=3D0.00..12.50 rows=3D1000 width=3D134) (act= +ual +time=3D23.54..23.97 rows=3D22 loops=3D1) +Total runtime: 24.15 msec +(2 rows) + +BTW, this started out as a question about how to do it, but in the process +of thinking my question out, the answer came to me. ;-) + +Matthew Nuzum +www.bearfruit.org +cobalt@bearfruit.org + + + +From pgsql-performance-owner@postgresql.org Wed May 28 19:02:52 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 6801892541D + for ; + Wed, 28 May 2003 19:02:51 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 65855-01 for ; + Wed, 28 May 2003 19:02:50 -0400 (EDT) +Received: from mail1.ihs.com (mail1.ihs.com [170.207.70.222]) + by developer.postgresql.org (Postfix) with ESMTP id 7267F924F10 + for ; + Wed, 28 May 2003 19:02:49 -0400 (EDT) +Received: from css120.ihs.com (css120.ihs.com [170.207.105.120]) + by mail1.ihs.com (8.12.9/8.12.9) with ESMTP id h4SN2BQB024153; + Wed, 28 May 2003 17:02:11 -0600 (MDT) +Date: Wed, 28 May 2003 16:46:26 -0600 (MDT) +From: "scott.marlowe" +To: Grega Bremec +Cc: +Subject: Re: Wildcard searches & performance question +In-Reply-To: <20030528225256.A24693@elbereth.noviforum.si> +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-MailScanner: Found to be clean +X-MailScanner-SpamCheck: +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/253 +X-Sequence-Number: 2032 + +On Wed, 28 May 2003, Grega Bremec wrote: + +> Thank you very much for all your suggestions. +> +> I am planning on investing some time into trying out a couple FT indexes. Not +> minding the fact most of the queries are going to be exact phrase substring +> searches, performance will most probably benefit from it, so at least some of +> what I'm after is achieved that way. +> +> I shall be getting back with reports, in case anyone is interested. + +Be sure to look at OpenFTS http://sourceforge.net/projects/openfts/ + + +From pgsql-performance-owner@postgresql.org Wed May 28 19:44:06 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 3945D925A10 + for ; + Wed, 28 May 2003 19:44:05 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 70096-05 for ; + Wed, 28 May 2003 19:44:03 -0400 (EDT) +Received: from sss.pgh.pa.us (unknown [192.204.191.242]) + by developer.postgresql.org (Postfix) with ESMTP id 776789259E8 + for ; + Wed, 28 May 2003 19:44:03 -0400 (EDT) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h4SNi2U6009208; + Wed, 28 May 2003 19:44:02 -0400 (EDT) +To: Dave Tenny +Cc: pgsql-performance@postgresql.org +Subject: Re: IN list processing performance (yet again) +In-reply-to: <3ED4B0E5.3050703@attbi.com> +References: <3ED4B0E5.3050703@attbi.com> +Comments: In-reply-to Dave Tenny + message dated "Wed, 28 May 2003 08:51:49 -0400" +Date: Wed, 28 May 2003 19:44:01 -0400 +Message-ID: <9207.1054165441@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/254 +X-Sequence-Number: 2033 + +Dave Tenny writes: +> My application relies heavily on IN lists. The lists are primarily +> constant integers, so queries look like: +> SELECT val FROM table WHERE id IN (43, 49, 1001, 100002, ...) + +> 1) PostgreSQL exhibits worse-than-linear performance behavior with +> respect to IN list size. + +Yeah. There are a couple of places in the planner that have O(N^2) +behavior on sufficiently large WHERE clauses, due to building lists +in a naive way (repeated lappend() operations). The inner loop is +very tight, but nonetheless when you do it tens of millions of times +it adds up :-( + +I have just committed some fixes into CVS tip for this --- I see about +a 10x speedup in planning time on test cases involving 10000-OR-item +WHERE clauses. We looked at this once before; the test cases I'm using +actually date back to Jan 2000. But it seems some slowness has crept +in due to subsequent planning improvements. + + +> 4) God help you if you haven't vacuum/analyzed that the newly loaded +> table. + +Without knowledge that the id field is unique, the planner is likely to +tilt away from an indexscan with not too many IN items. I don't +consider this a bug. + + +> PostgreSQL craps out trying to process 8000 elements with the error: +> out of free buffers: time to abort! + +This is a known bug in 7.3.2; it's fixed in 7.3.3. + + regards, tom lane + +From pgsql-performance-owner@postgresql.org Wed May 28 21:19:59 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 7091692544F + for ; + Wed, 28 May 2003 21:19:58 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 90682-03 for ; + Wed, 28 May 2003 21:19:57 -0400 (EDT) +Received: from sccrmhc03.attbi.com (sccrmhc03.attbi.com [204.127.202.63]) + by developer.postgresql.org (Postfix) with ESMTP id 8095C925441 + for ; + Wed, 28 May 2003 21:19:57 -0400 (EDT) +Received: from attbi.com (dtenny.ne.client2.attbi.com[24.60.113.221]) + by attbi.com (sccrmhc03) with SMTP + id <2003052901195700300pf617e>; Thu, 29 May 2003 01:19:57 +0000 +Message-ID: <3ED5603C.2020800@attbi.com> +Date: Wed, 28 May 2003 21:19:56 -0400 +From: Dave Tenny +User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3.1) Gecko/20030425 +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: Tom Lane +Cc: pgsql-performance@postgresql.org +Subject: Re: IN list processing performance (yet again) +References: <3ED4B0E5.3050703@attbi.com> <9207.1054165441@sss.pgh.pa.us> +In-Reply-To: <9207.1054165441@sss.pgh.pa.us> +Content-Type: multipart/alternative; + boundary="------------050408010506090807030801" +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/255 +X-Sequence-Number: 2034 + +This is a multi-part message in MIME format. +--------------050408010506090807030801 +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit + +Tom Lane wrote: + +>Dave Tenny writes: +> +> +>>My application relies heavily on IN lists. The lists are primarily +>>constant integers, so queries look like: +>>SELECT val FROM table WHERE id IN (43, 49, 1001, 100002, ...) +>> +>> +> +> +> +>>1) PostgreSQL exhibits worse-than-linear performance behavior with +>>respect to IN list size. +>> +>> +> +>Yeah. There are a couple of places in the planner that have O(N^2) +>behavior on sufficiently large WHERE clauses, due to building lists +>in a naive way (repeated lappend() operations). The inner loop is +>very tight, but nonetheless when you do it tens of millions of times +>it adds up :-( +> +> +> +It was also showing up very clearly in the timings I attached for just a +couple hundred IN list entries too. +Does that mean that the time for the O(1) portions of the logic are +perhaps also in need of a tuneup? +(I would think O(N^2) for trivial operations on a fast machine wouldn't +manifest quite so much +for smallish N). + +>I have just committed some fixes into CVS tip for this --- I see about +>a 10x speedup in planning time on test cases involving 10000-OR-item +>WHERE clauses. We looked at this once before; the test cases I'm using +>actually date back to Jan 2000. But it seems some slowness has crept +>in due to subsequent planning improvements. +> +> +> +So what version might that equate to down the road, so I can be sure to +check it out? +I'm afraid I'm not up to testing CVS tips. + +> +> +>>4) God help you if you haven't vacuum/analyzed that the newly loaded +>>table. +>> +>> +> +>Without knowledge that the id field is unique, the planner is likely to +>tilt away from an indexscan with not too many IN items. I don't +>consider this a bug. +> +> +> +There is one very interesting thing in my test case though. It +certainly /seemed/ as if the +parameterized statements were successfully using the index of the +freshly-created-but-unanalyzed table, +or else the times on those queries would have been terrible too. It was +only the IN list form +of query that wasn't making correct use of the index. How can the +planner recognize uniqueness for +one case but not the other? (Since I ran both forms of query on the same +table with and without vacuuming). + +> +> +>> PostgreSQL craps out trying to process 8000 elements with the error: +>> out of free buffers: time to abort! +>> +>> +> +>This is a known bug in 7.3.2; it's fixed in 7.3.3. +> +> +Thanks, that's good to know. + +Dave + +--------------050408010506090807030801 +Content-Type: text/html; charset=us-ascii +Content-Transfer-Encoding: 7bit + + + + + + + + +Tom Lane wrote:
+
+
Dave Tenny <tenny@attbi.com> writes:
+  
+
+
My application relies heavily on IN lists.  The lists are primarily 
+constant integers, so queries look like:
+SELECT val FROM table WHERE id IN (43, 49, 1001, 100002, ...)
+    
+
+

+  
+
+
1) PostgreSQL exhibits worse-than-linear performance behavior with 
+respect to IN list size.
+    
+
+

+Yeah.  There are a couple of places in the planner that have O(N^2)
+behavior on sufficiently large WHERE clauses, due to building lists
+in a naive way (repeated lappend() operations).  The inner loop is
+very tight, but nonetheless when you do it tens of millions of times
+it adds up :-(
+
+  
+
+It was also showing up very clearly in the timings I attached for just +a couple hundred IN list entries too.
+Does that mean that the time for the O(1) portions of the logic are +perhaps also in need of a tuneup?
+(I would think O(N^2) for trivial operations on a fast machine wouldn't +manifest quite so much
+for smallish N).
+
+
I have just committed some fixes into CVS tip for this --- I see about
+a 10x speedup in planning time on test cases involving 10000-OR-item
+WHERE clauses.  We looked at this once before; the test cases I'm using
+actually date back to Jan 2000.  But it seems some slowness has crept
+in due to subsequent planning improvements.
+
+  
+
+So what version might that equate to down the road, so I can be sure to +check it out?
+I'm afraid I'm not up to testing CVS tips.
+
+
+  
+
+
4)  God help you if you haven't vacuum/analyzed that the newly loaded 
+table.
+    
+
+

+Without knowledge that the id field is unique, the planner is likely to
+tilt away from an indexscan with not too many IN items.  I don't
+consider this a bug.
+
+  
+
+There is one very interesting thing in my test case though.  It +certainly seemed as if the
+parameterized statements were successfully using the index of the +freshly-created-but-unanalyzed table,
+or else the times on those queries would have been terrible too.  It +was only the IN list form
+of query that wasn't making correct use of the index.  How can the +planner recognize uniqueness for
+one case but not the other? (Since I ran both forms of query on the +same table with and without vacuuming).
+
+
+  
+
+
      PostgreSQL  craps out trying to process 8000 elements with the error:
+      out of free buffers: time to abort!    
+    
+
+

+This is a known bug in 7.3.2; it's fixed in 7.3.3.
+  
+
+Thanks, that's good to know.
+
+Dave
+ + + +--------------050408010506090807030801-- + + +From pgsql-performance-owner@postgresql.org Wed May 28 21:46:21 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id F22FD924F51 + for ; + Wed, 28 May 2003 21:46:17 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 93578-09 for ; + Wed, 28 May 2003 21:46:14 -0400 (EDT) +Received: from sss.pgh.pa.us (unknown [192.204.191.242]) + by developer.postgresql.org (Postfix) with ESMTP id ADE36924EFC + for ; + Wed, 28 May 2003 21:46:13 -0400 (EDT) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h4T1kDU6013454; + Wed, 28 May 2003 21:46:13 -0400 (EDT) +To: Dave Tenny +Cc: pgsql-performance@postgresql.org +Subject: Re: IN list processing performance (yet again) +In-reply-to: <3ED5603C.2020800@attbi.com> +References: <3ED4B0E5.3050703@attbi.com> <9207.1054165441@sss.pgh.pa.us> + <3ED5603C.2020800@attbi.com> +Comments: In-reply-to Dave Tenny + message dated "Wed, 28 May 2003 21:19:56 -0400" +Date: Wed, 28 May 2003 21:46:13 -0400 +Message-ID: <13453.1054172773@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/256 +X-Sequence-Number: 2035 + +Dave Tenny writes: +> +> There is one very interesting thing in my test case though.  It +> certainly seemed as if the
+> parameterized statements were successfully using the index of the +> freshly-created-but-unanalyzed table,
+> or else the times on those queries would have been terrible too.  It +> was only the IN list form
+> of query that wasn't making correct use of the index.  How can the +> planner recognize uniqueness for
+> one case but not the other? + +The question is whether a seqscan will be faster than an indexscan; at +some point there's less I/O involved to just scan the table once. If +the planner doesn't know the index is unique then it's going to estimate +a higher cost for the indexscan (due to more rows fetched) and there is +some number of rows at which it will flip over to a seqscan. The same +will happen even if it *does* know the index is unique, it's just that +it will take more IN elements to make it happen. This is reasonable +behavior IMHO, although whether the flip-over point is anywhere near +the actual breakeven point on your hardware is anyone's guess. The cost +estimates are often far enough off that it's not very close. + + regards, tom lane + +From pgsql-performance-owner@postgresql.org Wed May 28 21:47:50 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 6FF23925001 + for ; + Wed, 28 May 2003 21:47:48 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 94279-02 for ; + Wed, 28 May 2003 21:47:47 -0400 (EDT) +Received: from houston.familyhealth.com.au (unknown [203.59.48.253]) + by developer.postgresql.org (Postfix) with ESMTP id 8C971924FE9 + for ; + Wed, 28 May 2003 21:47:45 -0400 (EDT) +Received: (from root@localhost) + by houston.familyhealth.com.au (8.11.6p2/8.11.6) id h4T1lii55474 + for pgsql-performance@postgresql.org; + Thu, 29 May 2003 09:47:44 +0800 (WST) + (envelope-from chriskl@familyhealth.com.au) +Received: from mariner (mariner.internal [192.168.0.101]) + by houston.familyhealth.com.au (8.11.6p2/8.9.3) with SMTP id + h4T1ldV55338; Thu, 29 May 2003 09:47:39 +0800 (WST) +Message-ID: <0b2901c32584$528dee90$6500a8c0@fhp.internal> +From: "Christopher Kings-Lynne" +To: "Dave Tenny" , + "Shridhar Daithankar" +Cc: +References: <3ED4B0E5.3050703@attbi.com> + <200305281846.38928.shridhar_daithankar@nospam.persistent.co.in> + <3ED4F8B6.7030905@attbi.com> +Subject: Re: IN list processing performance (yet again) +Date: Thu, 29 May 2003 09:47:53 +0800 +MIME-Version: 1.0 +Content-Type: multipart/alternative; + boundary="----=_NextPart_000_0B26_01C325C7.5FF9EC80" +X-Priority: 3 +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook Express 6.00.2800.1158 +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 +X-scanner: scanned by Inflex 0.1.5c - (http://www.inflex.co.za/) +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/257 +X-Sequence-Number: 2036 + +This is a multi-part message in MIME format. + +------=_NextPart_000_0B26_01C325C7.5FF9EC80 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: quoted-printable + +The IN list processing has been fixed in 7.4CVS. It now uses a hash based = +lookup rather than a list, so it's vastly faster. + +Chris + ----- Original Message -----=20 + From: Dave Tenny=20 + To: Shridhar Daithankar=20 + Cc: pgsql-performance@postgresql.org=20 + Sent: Thursday, May 29, 2003 1:58 AM + Subject: Re: [PERFORM] IN list processing performance (yet again) + + + A join isn't an option, these elements come a a selection of entity ID's = +that are specific to some client context. + Some other people suggested joins too.=20=20 + + Consider it something like this, say there's a database that represents t= +he entire file system content + of a set of machines, hundreds of thousands of files. A single user want= +s to do something + related to the ID's of 3000 files. The requests for those 3000 files can= + be built up in a number of ways, + not all of which rely on data in the database. So I need to retrieve dat= +a on those 3000 files using IN lists or some alternative. + + Dave + + Shridhar Daithankar wrote: + +On Wednesday 28 May 2003 18:21, Dave Tenny wrote: + Having grepped the web, it's clear that this isn't the first or last +time this issue will be raised. + +My application relies heavily on IN lists. The lists are primarily +constant integers, so queries look like: + +SELECT val FROM table WHERE id IN (43, 49, 1001, 100002, ...) +=20=20=20=20 +How do you derive this list of number? If it is from same database, can you= +=20 +rewrite the query using a join statement? + +HTH + + Shridhar + + +---------------------------(end of broadcast)--------------------------- +TIP 4: Don't 'kill -9' the postmaster + +=20=20 +------=_NextPart_000_0B26_01C325C7.5FF9EC80 +Content-Type: text/html; + charset="iso-8859-1" +Content-Transfer-Encoding: quoted-printable + + + + + + + + +
The IN list processing has been fixed in= +=20 +7.4CVS.  It now uses a hash based lookup rather than a list, so it's v= +astly=20 +faster.
+
 
+
Chris
+
+
----- Original Message -----
+ Fro= +m:=20 + Dave Tenny= +
+
To: Shridhar Daithankar<= +/A>=20 +
+
Cc: pgsql-performance@postgr= +esql.org=20 +
+
Sent: Thursday, May 29, 2003 1:58= +=20 +AM
+
Subject: Re: [PERFORM] IN list pro= +cessing=20 + performance (yet again)
+

A join isn't an option, these elements come a a selection = +of=20 + entity ID's that are specific to some client context.
Some other peopl= +e=20 + suggested joins too. 

Consider it something like this, say= +=20 + there's a database that represents the entire file system content
of a= + set=20 + of machines, hundreds of thousands of files.  A single user wants to= + do=20 + something
related to the ID's of 3000 files.  The requests for th= +ose=20 + 3000 files can be built up in a number of ways,
not all of which rely = +on=20 + data in the database.  So I need to retrieve data on those 3000 file= +s=20 + using IN lists or some alternative.

Dave

Shridhar Daithanka= +r=20 + wrote:
+
On Wednesday 28 May 2003 18:21, Dave Tenny w=
+rote:
+  
+
Having grepped the web, it's c=
+lear that this isn't the first or last
+time this issue will be raised.
+
+My application relies heavily on IN lists.  The lists are primarily
+constant integers, so queries look like:
+
+SELECT val FROM table WHERE id IN (43, 49, 1001, 100002, ...)
+    

+How do you derive this list of number? If it is from same database, can you=
+=20
+rewrite the query using a join statement?
+
+HTH
+
+ Shridhar
+
+
+---------------------------(end of broadcast)---------------------------
+TIP 4: Don't 'kill -9' the postmaster
+
+  
+ +------=_NextPart_000_0B26_01C325C7.5FF9EC80-- + + +From pgsql-performance-owner@postgresql.org Wed May 28 21:53:54 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 09AE4925263 + for ; + Wed, 28 May 2003 21:53:52 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 93900-09 for ; + Wed, 28 May 2003 21:53:51 -0400 (EDT) +Received: from houston.familyhealth.com.au (unknown [203.59.48.253]) + by developer.postgresql.org (Postfix) with ESMTP id D944092511F + for ; + Wed, 28 May 2003 21:53:49 -0400 (EDT) +Received: (from root@localhost) + by houston.familyhealth.com.au (8.11.6p2/8.11.6) id h4T1rnW57234 + for pgsql-performance@postgresql.org; + Thu, 29 May 2003 09:53:49 +0800 (WST) + (envelope-from chriskl@familyhealth.com.au) +Received: from mariner (mariner.internal [192.168.0.101]) + by houston.familyhealth.com.au (8.11.6p2/8.9.3) with SMTP id + h4T1rfV57052; Thu, 29 May 2003 09:53:41 +0800 (WST) +Message-ID: <0b9a01c32585$2a8e6900$6500a8c0@fhp.internal> +From: "Christopher Kings-Lynne" +To: "Dave Tenny" , + "Bruno Wolff III" +Cc: "Andreas Pflug" , +References: <3ED4B0E5.3050703@attbi.com> <3ED4B75A.2050106@web.de> + <3ED4FB02.1010908@attbi.com> <20030528183914.GA6118@wolff.to> + <3ED5159E.2050407@attbi.com> +Subject: Re: IN list processing performance (yet again) +Date: Thu, 29 May 2003 09:53:55 +0800 +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit +X-Priority: 3 +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook Express 6.00.2800.1158 +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 +X-scanner: scanned by Inflex 0.1.5c - (http://www.inflex.co.za/) +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/258 +X-Sequence-Number: 2037 + + + +> Also, IN (subquery) is a known performance problem in PGSQL, at least if +the subquery is going to return > many rows. +> It's too bad, since I'm rather fond of subqueries, but I avoid them like +the plague in PostgreSQL. + +You're not really using a subquery - really just a long list of integers. +Subqueries are lightning fast, so long as you conver to the EXISTS form: + +SELECT * FROM tab WHERE id IN (SELECT id2 FROM tab2); + +converts to: + +SELECT * FROM tab WHERE EXISTS (SELECT id2 FROM tab2 WHERE id2=id); + +Chris + + + + +From pgsql-performance-owner@postgresql.org Thu May 29 02:15:35 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 8ABB5924D42 + for ; + Thu, 29 May 2003 02:15:33 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 56287-05 for ; + Thu, 29 May 2003 02:15:32 -0400 (EDT) +Received: from shield.nordlb.lv (shield.pirmabanka.lv [195.114.57.4]) + by developer.postgresql.org (Postfix) with ESMTP id 97A06924CCF + for ; + Thu, 29 May 2003 02:15:31 -0400 (EDT) +Received: from wall2.pirmabanka.lv (wall2-pub.nordlb.lv [195.114.57.14]) + by shield.nordlb.lv (8.12.9/8.12.9) with SMTP id h4T6FSGZ021927 + for ; Thu, 29 May 2003 09:15:29 +0300 +Received: from share.nordlb.lv ([10.0.0.10]) by wall2.pirmabanka.lv; + Thu, 29 May 2003 09:15:27 +0300 (EET DST) +Received: from pc311x1.nordlb.lv (localhost.localdomain [127.0.0.1]) + by nordlb.lv (8.11.6/8.11.6) with SMTP id h4T6FQA00659 + for ; Thu, 29 May 2003 09:15:27 +0300 +Received: (qmail 26137 invoked by uid 100); 29 May 2003 06:18:18 -0000 +Date: Thu, 29 May 2003 09:18:18 +0300 +From: "Victor Yegorov" +To: "Chad Thompson" +Cc: "pgsql-performance" +Subject: Re: >24 hour restore +Message-ID: <20030529061818.GA23596@nordlb.lv> +References: <027901c32530$273839c0$32021aac@chad> +Mime-Version: 1.0 +Content-Type: text/plain; charset=koi8-r +Content-Disposition: inline +In-Reply-To: <027901c32530$273839c0$32021aac@chad> +User-Agent: Mutt/1.4.1i +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/259 +X-Sequence-Number: 2038 + +* Chad Thompson [28.05.2003 19:08]: +> I hope this is something easy/stupid that I have missed. I know that w/ +> mirroring my write times are not improved, but they are DEFINATLY not this +> bad. + +Well, I have had something similar to your case, except for size - it's was +about 1 Gb. + +I've dropped all foreign keys, triggers and, also, all indexes. As I've +found, each index takes additional time for inserts/updates/deletes, +so it's recommended to create indexes after data manipulations. + +If this will not help, I don't know. May be hardware problems... + +-- + +Victor Yegorov + +From pgsql-performance-owner@postgresql.org Thu May 29 06:53:24 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id BD198925C17 + for ; + Thu, 29 May 2003 06:53:22 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 22149-04 for ; + Thu, 29 May 2003 06:53:18 -0400 (EDT) +Received: from wolff.to (wolff.to [66.93.249.74]) + by developer.postgresql.org (Postfix) with SMTP id B8332925C0A + for ; + Thu, 29 May 2003 06:53:17 -0400 (EDT) +Received: (qmail 11108 invoked by uid 500); 29 May 2003 10:55:31 -0000 +Date: Thu, 29 May 2003 05:55:31 -0500 +From: Bruno Wolff III +To: Dave Tenny +Cc: Tom Lane , pgsql-performance@postgresql.org +Subject: Re: IN list processing performance (yet again) +Message-ID: <20030529105531.GA11002@wolff.to> +Mail-Followup-To: Dave Tenny , + Tom Lane , pgsql-performance@postgresql.org +References: <3ED4B0E5.3050703@attbi.com> <9207.1054165441@sss.pgh.pa.us> + <3ED5603C.2020800@attbi.com> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: <3ED5603C.2020800@attbi.com> +User-Agent: Mutt/1.5.4i +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/260 +X-Sequence-Number: 2039 + +On Wed, May 28, 2003 at 21:19:56 -0400, + Dave Tenny wrote: +> So what version might that equate to down the road, so I can be sure to +> check it out? +> I'm afraid I'm not up to testing CVS tips. + +7.4 + +7.4 is suppsoed to go into beta July 1. + +If you are used to installing from source tarballs, you can grab a +development snapshot tarball. There is probably a day or two delay +depending on if you get it from a mirror or the primary site. + +From pgsql-performance-owner@postgresql.org Thu May 29 08:48:46 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id C9A9A925C47 + for ; + Thu, 29 May 2003 08:48:44 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 42685-01 for ; + Thu, 29 May 2003 08:48:43 -0400 (EDT) +Received: from rwcrmhc51.attbi.com (rwcrmhc51.attbi.com [204.127.198.38]) + by developer.postgresql.org (Postfix) with ESMTP id D5D28925C41 + for ; + Thu, 29 May 2003 08:48:42 -0400 (EDT) +Received: from attbi.com (dtenny.ne.client2.attbi.com[24.60.113.221]) + by attbi.com (rwcrmhc51) with SMTP + id <2003052912484105100k6c39e>; Thu, 29 May 2003 12:48:42 +0000 +Message-ID: <3ED601A9.50209@attbi.com> +Date: Thu, 29 May 2003 08:48:41 -0400 +From: Dave Tenny +User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3.1) Gecko/20030425 +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: Christopher Kings-Lynne +Cc: Bruno Wolff III , Andreas Pflug , + pgsql-performance@postgresql.org +Subject: Re: IN list processing performance (yet again) +References: <3ED4B0E5.3050703@attbi.com> <3ED4B75A.2050106@web.de> + <3ED4FB02.1010908@attbi.com> <20030528183914.GA6118@wolff.to> + <3ED5159E.2050407@attbi.com> + <0b9a01c32585$2a8e6900$6500a8c0@fhp.internal> +In-Reply-To: <0b9a01c32585$2a8e6900$6500a8c0@fhp.internal> +Content-Type: multipart/alternative; + boundary="------------070300060608000803080604" +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/261 +X-Sequence-Number: 2040 + +This is a multi-part message in MIME format. +--------------070300060608000803080604 +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit + +Christopher Kings-Lynne wrote: + +> +> +>>Also, IN (subquery) is a known performance problem in PGSQL, at least if +>> +>> +>the subquery is going to return > many rows. +> +> +>>It's too bad, since I'm rather fond of subqueries, but I avoid them like +>> +>> +>the plague in PostgreSQL. +> +>You're not really using a subquery - really just a long list of integers. +> + +Oops, you got that out of context, it was a different piece of +conversation about subqueries in IN predicate, +not the scalar forms that was my overall discussion point. You're +right, I'm using lists of integers, +someone else was suggesting using subqueries in some context and I was +responding to that. + +>Subqueries are lightning fast, so long as you conver to the EXISTS form: +> +>SELECT * FROM tab WHERE id IN (SELECT id2 FROM tab2); +> +>converts to: +> +>SELECT * FROM tab WHERE EXISTS (SELECT id2 FROM tab2 WHERE id2=id); +> +>Chris +> +> +I hadn't thought of that, it's an excellent tip. I'll have to remember +it next time I want to use subqueries. +(Again, it's a side topic, my primary concern is scalar-form IN lists.) + +Thanks, + +Dave + +--------------070300060608000803080604 +Content-Type: text/html; charset=us-ascii +Content-Transfer-Encoding: 7bit + + + + + + + + +Christopher Kings-Lynne wrote:
+
+
+  
+
+
Also, IN (subquery) is a known performance problem in PGSQL, at least if
+    
+
+
the subquery is going to return > many rows.
+  
+
+
It's too bad, since I'm rather fond of subqueries, but I avoid them like
+    
+
+
the plague in PostgreSQL.
+
+You're not really using a subquery - really just a long list of integers.
+
+
+Oops, you got that out of context, it was a different piece of +conversation about subqueries in IN predicate,
+not the scalar forms that was my overall discussion point.  You're +right, I'm using lists of integers,
+someone else was suggesting using subqueries in some context and I was +responding to that.
+
+
+
+Subqueries are lightning fast, so long as you conver to the EXISTS form:
+
+SELECT * FROM tab WHERE id IN (SELECT id2 FROM tab2);
+
+converts to:
+
+SELECT * FROM tab WHERE EXISTS (SELECT id2 FROM tab2 WHERE id2=id);
+
+Chris
+  
+
+I hadn't thought of that, it's an excellent tip.  I'll have to remember +it next time I want to use subqueries.
+(Again, it's a side topic, my primary concern is scalar-form IN lists.)
+
+Thanks,
+
+Dave
+ + + +--------------070300060608000803080604-- + + +From pgsql-performance-owner@postgresql.org Thu May 29 09:58:15 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 2AE019258FF + for ; + Thu, 29 May 2003 09:58:13 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 60858-03 for ; + Thu, 29 May 2003 09:58:11 -0400 (EDT) +Received: from relay.netcetra.com (unknown [198.65.147.132]) + by developer.postgresql.org (Postfix) with ESMTP id 4C1EE92586F + for ; + Thu, 29 May 2003 09:58:11 -0400 (EDT) +Received: from WORKSTATION (frsc-dsldyna-66-228-147-1.advantexcom.net + [66.228.147.1]) + by relay.netcetra.com (8.11.6/8.11.6) with SMTP id h4TDoVZ19921 + for ; + Thu, 29 May 2003 09:50:32 -0400 (EDT) +Message-ID: <005501c325ea$5879ad10$0200a8c0@WORKSTATION> +From: "Kevin Schroeder" +To: +Subject: Select query takes long to execute +Date: Thu, 29 May 2003 08:58:07 -0500 +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit +X-Priority: 3 +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook Express 6.00.2800.1158 +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/262 +X-Sequence-Number: 2041 + +Hello, + I'm running a simple query on a table and I'm getting a very long +response time. The table has 56,000 rows in it. It has a full text field, +but it is not being referenced in this query. The query I'm running is + +select row_key, column1, column2, column3, column4, column5 from table1 +where column6 = 1 order by column3 desc limit 21; + +There is an index on the table + +message_index btree (column6, column3, column7) + +Column 3 is a date type, column 6 is an integer and column 7 is unused in +this query. + +The total query time is 6 seconds, but I can bring that down to 4.5 if I +append "offset 0" to the end of the query. By checking query using "explain +analyze" it shows that it is using the index. + +If anyone has any ideas as to why the query is taking so long and what I can +do to make it more efficient I would love to know. + +Thanks +Kevin + + +From pgsql-performance-owner@postgresql.org Thu May 29 10:09:31 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 53F0B925B12 + for ; + Thu, 29 May 2003 10:09:28 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 63737-04 for ; + Thu, 29 May 2003 10:09:27 -0400 (EDT) +Received: from relay.netcetra.com (unknown [198.65.147.132]) + by developer.postgresql.org (Postfix) with ESMTP id 2E8109258D8 + for ; + Thu, 29 May 2003 10:09:27 -0400 (EDT) +Received: from WORKSTATION (frsc-dsldyna-66-228-147-1.advantexcom.net + [66.228.147.1]) + by relay.netcetra.com (8.11.6/8.11.6) with SMTP id h4TE1lZ21473 + for ; + Thu, 29 May 2003 10:01:47 -0400 (EDT) +Message-ID: <006d01c325eb$eb72fdf0$0200a8c0@WORKSTATION> +From: "Kevin Schroeder" +To: +Subject: Query problem fixed +Date: Thu, 29 May 2003 09:09:23 -0500 +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit +X-Priority: 3 +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook Express 6.00.2800.1158 +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/263 +X-Sequence-Number: 2042 + +I figured out how to make the query faster. There should be a mailing list +set up for wasted questions since I always seem to figure out the problem +after I've bugged everyone for help. + +In the query + +select row_key, column1, column2, column3, column4, column5 from table1 +where column6 = 1 order by column3 desc limit 21; + +I changed the index to + +message_index btree (column3, column6) + +rather than + +message_index btree (column6, column3, column7) + +Since the data was being ordered by column3 it seems to have sped the query +up to 1 ms from 6000ms by making column 3 the first part of the index rather +than the second. + +Kevin + + +From pgsql-performance-owner@postgresql.org Thu May 29 10:25:44 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 95CC2925C48 + for ; + Thu, 29 May 2003 10:25:42 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 68735-02 for ; + Thu, 29 May 2003 10:25:42 -0400 (EDT) +Received: from www.pspl.co.in (www.pspl.co.in [202.54.11.65]) + by developer.postgresql.org (Postfix) with ESMTP id 62C9F925BCA + for ; + Thu, 29 May 2003 10:25:40 -0400 (EDT) +Received: (from root@localhost) + by www.pspl.co.in (8.11.6/8.11.6) id h4TEPex14249 + for ; Thu, 29 May 2003 19:55:40 +0530 +Received: from daithan (daithan.intranet.pspl.co.in [192.168.7.161]) + by www.pspl.co.in (8.11.6/8.11.0) with ESMTP id h4TEPd614244 + for ; Thu, 29 May 2003 19:55:40 +0530 +From: "Shridhar Daithankar" +To: +Date: Thu, 29 May 2003 19:54:43 +0530 +MIME-Version: 1.0 +Subject: Re: Select query takes long to execute +Reply-To: shridhar_daithankar@persistent.co.in +Message-ID: <3ED66583.20384.551042A@localhost> +In-reply-to: <005501c325ea$5879ad10$0200a8c0@WORKSTATION> +X-mailer: Pegasus Mail for Windows (v4.11) +Content-type: text/plain; charset=US-ASCII +Content-transfer-encoding: 7BIT +Content-description: Mail message body +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/264 +X-Sequence-Number: 2043 + +On 29 May 2003 at 8:58, Kevin Schroeder wrote: +> If anyone has any ideas as to why the query is taking so long and what I can +> do to make it more efficient I would love to know. + +Check yor shared buffers setting and effective OS cache setting. If these are +appropriately tuned, then it should be fast enough. + +Is the table vacuumed? Is index taking too much space? Then try reindexing. It +might help as vacuum does not reclaim wasted space in index. + +HTH + +Bye + Shridhar + +-- +Wait! You have not been prepared! -- Mr. Atoz, "Tomorrow is Yesterday", +stardate 3113.2 + + +From pgsql-performance-owner@postgresql.org Thu May 29 10:28:39 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 9078B925C61 + for ; + Thu, 29 May 2003 10:28:37 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 69385-02 for ; + Thu, 29 May 2003 10:28:36 -0400 (EDT) +Received: from mail.deltav.hu (unknown [213.163.0.192]) + by developer.postgresql.org (Postfix) with ESMTP id 8CF21925C55 + for ; + Thu, 29 May 2003 10:28:35 -0400 (EDT) +Received: from fejleszt4 ([213.163.10.103]) by mail.deltav.hu + (Netscape Messaging Server 3.6) with SMTP id AAA12FB + for ; + Thu, 29 May 2003 16:28:33 +0200 +Message-ID: <009f01c325ee$63fbdb00$0403a8c0@fejleszt4> +From: =?ISO-8859-1?Q?SZUCS_G=E1bor?= +To: +References: <006d01c325eb$eb72fdf0$0200a8c0@WORKSTATION> +Subject: Re: Query problem fixed +Date: Thu, 29 May 2003 16:27:10 +0200 +MIME-Version: 1.0 +Content-Type: text/plain; + charset="ISO-8859-1" +Content-Transfer-Encoding: 7bit +X-Priority: 3 +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook Express 6.00.2800.1158 +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/265 +X-Sequence-Number: 2044 + +The thing I can't really understand why can't the planner find out something +like this: + +1. Index scan using column6 +2. Backward search on subset using column3 + +Any guru to explain? + +G. +------------------------------- cut here ------------------------------- +----- Original Message ----- +From: "Kevin Schroeder" +Sent: Thursday, May 29, 2003 4:09 PM + + +> I figured out how to make the query faster. There should be a mailing +list +> set up for wasted questions since I always seem to figure out the problem +> after I've bugged everyone for help. +> +> In the query +> +> select row_key, column1, column2, column3, column4, column5 from table1 +> where column6 = 1 order by column3 desc limit 21; +> +> I changed the index to +> +> message_index btree (column3, column6) +> +> rather than +> +> message_index btree (column6, column3, column7) +> +> Since the data was being ordered by column3 it seems to have sped the +query +> up to 1 ms from 6000ms by making column 3 the first part of the index +rather +> than the second. +> +> Kevin + + +From pgsql-performance-owner@postgresql.org Thu May 29 10:49:54 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 829D0925CA3 + for ; + Thu, 29 May 2003 10:49:53 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 74886-06 for ; + Thu, 29 May 2003 10:49:53 -0400 (EDT) +Received: from sss.pgh.pa.us (unknown [192.204.191.242]) + by developer.postgresql.org (Postfix) with ESMTP id BFF89925CA2 + for ; + Thu, 29 May 2003 10:49:52 -0400 (EDT) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h4TEnhU6017681; + Thu, 29 May 2003 10:49:43 -0400 (EDT) +To: "Kevin Schroeder" +Cc: pgsql-performance@postgresql.org +Subject: Re: Query problem fixed +In-reply-to: <006d01c325eb$eb72fdf0$0200a8c0@WORKSTATION> +References: <006d01c325eb$eb72fdf0$0200a8c0@WORKSTATION> +Comments: In-reply-to "Kevin Schroeder" + message dated "Thu, 29 May 2003 09:09:23 -0500" +Date: Thu, 29 May 2003 10:49:43 -0400 +Message-ID: <17680.1054219783@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/266 +X-Sequence-Number: 2045 + +"Kevin Schroeder" writes: +> select row_key, column1, column2, column3, column4, column5 from table1 +> where column6 = 1 order by column3 desc limit 21; + +> I changed the index to + +> message_index btree (column3, column6) + +> rather than + +> message_index btree (column6, column3, column7) + +That's probably not the best solution. It would be better to leave the +index with column6 first and write the query as + +... where column6 = 1 order by column6 desc, column3 desc limit 21 + +This doesn't change the results (since there's only one value of column6 +in the output), but it does cause the planner to realize that a +backwards scan of the index would produce what you want with no sort +step. The results should be essentially instantaneous if you can get +the query plan down to Index Scan Backward + Limit. + + regards, tom lane + +From pgsql-performance-owner@postgresql.org Thu May 29 12:18:32 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id E6B02925D19 + for ; + Thu, 29 May 2003 12:18:26 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 98697-06 for ; + Thu, 29 May 2003 12:18:26 -0400 (EDT) +Received: from mail1.ihs.com (mail1.ihs.com [170.207.70.222]) + by developer.postgresql.org (Postfix) with ESMTP id CF6CC925D11 + for ; + Thu, 29 May 2003 12:18:25 -0400 (EDT) +Received: from css120.ihs.com (css120.ihs.com [170.207.105.120]) + by mail1.ihs.com (8.12.9/8.12.9) with ESMTP id h4TGH7QB025706; + Thu, 29 May 2003 10:17:07 -0600 (MDT) +Date: Thu, 29 May 2003 10:01:16 -0600 (MDT) +From: "scott.marlowe" +To: Kevin Schroeder +Cc: +Subject: Re: Select query takes long to execute +In-Reply-To: <005501c325ea$5879ad10$0200a8c0@WORKSTATION> +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-MailScanner: Found to be clean +X-MailScanner-SpamCheck: +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/267 +X-Sequence-Number: 2046 + +See if lowering random_page_cost to 1.5 or so helps here. + +That and effective_cache_size are two of the more important values the +planner uses to decide between seq scans and index scans. + +On Thu, 29 May 2003, Kevin Schroeder wrote: + +> Hello, +> I'm running a simple query on a table and I'm getting a very long +> response time. The table has 56,000 rows in it. It has a full text field, +> but it is not being referenced in this query. The query I'm running is +> +> select row_key, column1, column2, column3, column4, column5 from table1 +> where column6 = 1 order by column3 desc limit 21; +> +> There is an index on the table +> +> message_index btree (column6, column3, column7) +> +> Column 3 is a date type, column 6 is an integer and column 7 is unused in +> this query. +> +> The total query time is 6 seconds, but I can bring that down to 4.5 if I +> append "offset 0" to the end of the query. By checking query using "explain +> analyze" it shows that it is using the index. +> +> If anyone has any ideas as to why the query is taking so long and what I can +> do to make it more efficient I would love to know. +> +> Thanks +> Kevin +> +> +> ---------------------------(end of broadcast)--------------------------- +> TIP 6: Have you searched our list archives? +> +> http://archives.postgresql.org +> + + +From pgsql-bugs-owner@postgresql.org Thu May 29 12:32:48 2003 +X-Original-To: pgsql-bugs@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 0D60E925C70 + for ; Thu, 29 May 2003 12:32:45 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) with ESMTP id 04409-10 for ; + Thu, 29 May 2003 12:32:43 -0400 (EDT) +Received: from louise.pinerecords.com (louise.pinerecords.com + [213.168.176.16]) + by developer.postgresql.org (Postfix) with ESMTP id 3552A925BFF + for ; Thu, 29 May 2003 12:32:41 -0400 (EDT) +Received: from louise.pinerecords.com (kala@localhost [127.0.0.1]) + by louise.pinerecords.com with ESMTP id h4TGWdvI011310 + (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) + for ; Thu, 29 May 2003 18:32:39 +0200 +Received: (from kala@localhost) + by louise.pinerecords.com (submit) id h4TGWdwC011309 + for pgsql-bugs@postgresql.org; Thu, 29 May 2003 18:32:39 +0200 +Date: Thu, 29 May 2003 18:32:39 +0200 +From: Tomas Szepe +To: pgsql-bugs@postgresql.org +Subject: db growing out of proportion +Message-ID: <20030529163239.GA11101@louise.pinerecords.com> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +User-Agent: Mutt/1.4.1i +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/109 +X-Sequence-Number: 6070 + +Hello everybody, + +I'm facing a simple yet gravely problem with postgresql 7.3.2 on x86 Linux. +My db is used to store IP accounting statistics for about 30 C's. There are +a couple truly trivial tables such as the one below: + +CREATE TABLE stats_min +( + ip inet NOT NULL, + start timestamp NOT NULL default CURRENT_TIMESTAMP(0), + intlen int4 NOT NULL default 60, + d_in int8 NOT NULL, + d_out int8 NOT NULL, + + constraint "stats_min_pkey" PRIMARY KEY ("ip", "start") +); +CREATE INDEX stats_min_start ON stats_min (start); + +A typical transaction committed on these tables looks like this: + +BEGIN WORK + DELETE ... + UPDATE/INSERT ... +COMMIT WORK + +Trouble is, as the rows in the tables get deleted/inserted/updated +(the frequency being a couple thousand rows per minute), the database +is growing out of proportion in size. After about a week, I have +to redump the db by hand so as to get query times back to sensible +figures. A transaction that takes ~50 seconds before the redump will +then complete in under 5 seconds (the corresponding data/base/ dir having +shrunk from ~2 GB to ~0.6GB). + +A nightly VACCUM ANALYZE is no use. + +A VACUUM FULL is no use. + +A VACUUM FULL followed by REINDEX is no use. + +It seems that only a full redump involving "pg_dump olddb | \ +psql newdb" is capable of restoring the system to its working +glory. + +Please accept my apologies if I've overlooked a relevant piece of +information in the docs. I'm in an urgent need of getting this +problem resolved. + +-- +Tomas Szepe + +From pgsql-bugs-owner@postgresql.org Thu May 29 13:37:51 2003 +X-Original-To: pgsql-bugs@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 2FAF9925DBC + for ; Thu, 29 May 2003 13:37:49 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) with ESMTP id 29109-02 for ; + Thu, 29 May 2003 13:37:40 -0400 (EDT) +Received: from megazone.bigpanda.com (megazone.bigpanda.com [63.150.15.178]) + by developer.postgresql.org (Postfix) with ESMTP id 3CBD4925DA8 + for ; Thu, 29 May 2003 13:37:40 -0400 (EDT) +Received: by megazone.bigpanda.com (Postfix, from userid 1001) + id 99ED2D61C; Thu, 29 May 2003 10:37:38 -0700 (PDT) +Received: from localhost (localhost [127.0.0.1]) + by megazone.bigpanda.com (Postfix) with ESMTP + id 8FA845C0D; Thu, 29 May 2003 10:37:38 -0700 (PDT) +Date: Thu, 29 May 2003 10:37:38 -0700 (PDT) +From: Stephan Szabo +To: Tomas Szepe +Cc: +Subject: Re: db growing out of proportion +In-Reply-To: <20030529163239.GA11101@louise.pinerecords.com> +Message-ID: <20030529103316.K60582-100000@megazone23.bigpanda.com> +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/110 +X-Sequence-Number: 6071 + +On Thu, 29 May 2003, Tomas Szepe wrote: + +> Hello everybody, +> +> I'm facing a simple yet gravely problem with postgresql 7.3.2 on x86 Linux. +> My db is used to store IP accounting statistics for about 30 C's. There are +> a couple truly trivial tables such as the one below: +> +> CREATE TABLE stats_min +> ( +> ip inet NOT NULL, +> start timestamp NOT NULL default CURRENT_TIMESTAMP(0), +> intlen int4 NOT NULL default 60, +> d_in int8 NOT NULL, +> d_out int8 NOT NULL, +> +> constraint "stats_min_pkey" PRIMARY KEY ("ip", "start") +> ); +> CREATE INDEX stats_min_start ON stats_min (start); +> +> A typical transaction committed on these tables looks like this: +> +> BEGIN WORK +> DELETE ... +> UPDATE/INSERT ... +> COMMIT WORK +> +> Trouble is, as the rows in the tables get deleted/inserted/updated +> (the frequency being a couple thousand rows per minute), the database +> is growing out of proportion in size. After about a week, I have +> to redump the db by hand so as to get query times back to sensible +> figures. A transaction that takes ~50 seconds before the redump will +> then complete in under 5 seconds (the corresponding data/base/ dir having +> shrunk from ~2 GB to ~0.6GB). +> +> A nightly VACCUM ANALYZE is no use. +> +> A VACUUM FULL is no use. +> +> A VACUUM FULL followed by REINDEX is no use. + +Is the space being taken up by stats_min, this index, some other object? +I'm not 100% sure, but after vacuums maybe +select * from pg_class order by relpages desc limit 10; +will give a good idea. + +What does VACUUM FULL VERBOSE stats_min; give you? + + +From pgsql-performance-owner@postgresql.org Thu May 29 22:44:55 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 27CC5923292 + for ; + Thu, 29 May 2003 22:44:54 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 50921-06 for ; + Thu, 29 May 2003 22:44:53 -0400 (EDT) +Received: from c001.snv.cp.net (h021.c001.snv.cp.net [209.228.32.135]) + by developer.postgresql.org (Postfix) with SMTP id 56A3B92328B + for ; + Thu, 29 May 2003 22:44:51 -0400 (EDT) +Received: (cpmta 12815 invoked from network); 29 May 2003 19:44:51 -0700 +Received: from 209.228.32.120 (HELO mail.dilger.cc.criticalpath.net) + by smtp.register-admin.com (209.228.32.135) with SMTP; + 29 May 2003 19:44:51 -0700 +X-Sent: 30 May 2003 02:44:51 GMT +Received: from [216.68.146.219] by mail.dilger.cc with HTTP; + Thu, 29 May 2003 19:44:50 -0700 (PDT) +Content-Type: text/plain; charset=iso-8859-1 +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +MIME-Version: 1.0 +To: mirage@mirageworks.com +Cc: pgsql-performance@postgresql.org +From: "Nikolaus Dilger" +Subject: Re: Select query takes long to execute +X-Sent-From: nikolaus@dilger.cc +Date: Thu, 29 May 2003 19:44:50 -0700 (PDT) +X-Mailer: Web Mail 5.4.0-4_sol28 +Message-Id: + <20030529194451.24416.h006.c001.wm@mail.dilger.cc.criticalpath.net> +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/268 +X-Sequence-Number: 2047 + +Kevin, + +How about creating a new index just on column6? +That should be much more effective than the multicolumn +index. + +Regards, +Nikolaus + +On Thu, 29 May 2003 08:58:07 -0500, "Kevin Schroeder" +wrote: + +> +> Hello, +> I'm running a simple query on a table and I'm +> getting a very long +> response time. The table has 56,000 rows in it. It +> has a full text field, +> but it is not being referenced in this query. The +> query I'm running is +> +> select row_key, column1, column2, column3, column4, +> column5 from table1 +> where column6 = 1 order by column3 desc limit 21; +> +> There is an index on the table +> +> message_index btree (column6, column3, column7) +> +> Column 3 is a date type, column 6 is an integer and +> column 7 is unused in +> this query. +> +> The total query time is 6 seconds, but I can bring +that +> down to 4.5 if I +> append "offset 0" to the end of the query. By +checking +> query using "explain +> analyze" it shows that it is using the index. +> +> If anyone has any ideas as to why the query is taking +> so long and what I can +> do to make it more efficient I would love to know. +> +> Thanks +> Kevin +> +> +> ---------------------------(end of +> broadcast)--------------------------- +> TIP 6: Have you searched our list archives? +> +> http://archives.postgresql.org + +From pgsql-bugs-owner@postgresql.org Fri May 30 03:24:53 2003 +X-Original-To: pgsql-bugs@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 3C619924DF8 + for ; Fri, 30 May 2003 03:24:52 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) with ESMTP id 16838-06 for ; + Fri, 30 May 2003 03:24:51 -0400 (EDT) +Received: from louise.pinerecords.com (louise.pinerecords.com + [213.168.176.16]) + by developer.postgresql.org (Postfix) with ESMTP id 85C9D924CE8 + for ; Fri, 30 May 2003 03:24:50 -0400 (EDT) +Received: from louise.pinerecords.com (kala@localhost [127.0.0.1]) + by louise.pinerecords.com with ESMTP id h4U7OhvI017941 + (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); + Fri, 30 May 2003 09:24:43 +0200 +Received: (from kala@localhost) + by louise.pinerecords.com (submit) id h4U7Ogit017940; + Fri, 30 May 2003 09:24:42 +0200 +Date: Fri, 30 May 2003 09:24:42 +0200 +From: Tomas Szepe +To: Stephan Szabo +Cc: pgsql-bugs@postgresql.org +Subject: Re: db growing out of proportion +Message-ID: <20030530072442.GD14159@louise.pinerecords.com> +References: <20030529163239.GA11101@louise.pinerecords.com> + <20030529103316.K60582-100000@megazone23.bigpanda.com> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: <20030529103316.K60582-100000@megazone23.bigpanda.com> +User-Agent: Mutt/1.4.1i +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/112 +X-Sequence-Number: 6073 + +> [sszabo@megazone23.bigpanda.com] +> +> > Trouble is, as the rows in the tables get deleted/inserted/updated +> > (the frequency being a couple thousand rows per minute), the database +> > is growing out of proportion in size. After about a week, I have +> > to redump the db by hand so as to get query times back to sensible +> > figures. A transaction that takes ~50 seconds before the redump will +> > then complete in under 5 seconds (the corresponding data/base/ dir having +> > shrunk from ~2 GB to ~0.6GB). +> > +> > A nightly VACCUM ANALYZE is no use. +> > +> > A VACUUM FULL is no use. +> > +> > A VACUUM FULL followed by REINDEX is no use. +> +> Is the space being taken up by stats_min, this index, some other object? + + relname | relkind | relpages | reltuples +---------------------------------+---------+----------+------------- + stats_hr | r | 61221 | 3.01881e+06 + stats_hr_pkey | i | 26414 | 3.02239e+06 + stats_min_pkey | i | 20849 | 953635 + stats_hr_start | i | 17218 | 3.02142e+06 + stats_min_start | i | 15284 | 949788 + stats_min | r | 10885 | 948792 + authinfo_pkey | i | 1630 | 1342 + authinfo | r | 1004 | 1342 + contract_ips | r | 865 | 565 + contract_ips_pkey | i | 605 | 565 + +> What does VACUUM FULL VERBOSE stats_min; give you? + +Sorry, I can't run a VACUUM FULL at this time. +We're in production use. + +-- +Tomas Szepe + +From pgsql-performance-owner@postgresql.org Fri May 30 04:59:07 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id C0AFB9232C1 + for ; + Fri, 30 May 2003 04:59:06 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 45550-08 for ; + Fri, 30 May 2003 04:59:01 -0400 (EDT) +Received: from mail.deltav.hu (unknown [213.163.0.192]) + by developer.postgresql.org (Postfix) with ESMTP id 37999925149 + for ; + Fri, 30 May 2003 04:59:01 -0400 (EDT) +Received: from fejleszt4 ([213.163.10.103]) by mail.deltav.hu + (Netscape Messaging Server 3.6) with SMTP id AAA2646 + for ; + Fri, 30 May 2003 10:58:58 +0200 +Message-ID: <001c01c32689$82da1050$0403a8c0@fejleszt4> +From: =?iso-8859-1?Q?SZUCS_G=E1bor?= +To: +References: + <20030529194451.24416.h006.c001.wm@mail.dilger.cc.criticalpath.net> +Subject: Re: Select query takes long to execute +Date: Fri, 30 May 2003 10:57:33 +0200 +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit +X-Priority: 3 +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook Express 6.00.2800.1158 +X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/269 +X-Sequence-Number: 2048 + +Nikolaus, + +I think that shouldn't be any more effective. As I experienced, it's +irrelevant how many cols an index has as long as you only use the first +column. And, after that, if you use another column, how could a missing +second column be any better? + +G. +------------------------------- cut here ------------------------------- +----- Original Message ----- +From: "Nikolaus Dilger" +Sent: Friday, May 30, 2003 4:44 AM + + +> Kevin, +> +> How about creating a new index just on column6? +> That should be much more effective than the multicolumn +> index. +> +> Regards, +> Nikolaus + + + +From pgsql-bugs-owner@postgresql.org Fri May 30 05:21:29 2003 +X-Original-To: pgsql-bugs@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 22DF5925B1C + for ; Fri, 30 May 2003 05:21:28 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) with ESMTP id 54768-03 for ; + Fri, 30 May 2003 05:21:26 -0400 (EDT) +Received: from smtp.blueyonder.co.uk (pc-80-195-188-198-gl.blueyonder.co.uk + [80.195.188.198]) + by developer.postgresql.org (Postfix) with ESMTP id 3DADC925B12 + for ; Fri, 30 May 2003 05:21:26 -0400 (EDT) +Received: from reddragon.localdomain ([127.0.0.1] helo=localhost) + by smtp.blueyonder.co.uk with esmtp (Exim 4.10) id 19Lg59-0005lb-00 + for pgsql-bugs@postgresql.org; Fri, 30 May 2003 10:21:51 +0100 +Date: Fri, 30 May 2003 10:21:51 +0100 (BST) +From: Peter Childs +X-X-Sender: peter@RedDragon.Childs +Cc: pgsql-bugs@postgresql.org +Subject: Re: db growing out of proportion +In-Reply-To: <20030530072442.GD14159@louise.pinerecords.com> +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/113 +X-Sequence-Number: 6074 + +On Fri, 30 May 2003, Tomas Szepe wrote: + +> > [sszabo@megazone23.bigpanda.com] +> > +> > > Trouble is, as the rows in the tables get deleted/inserted/updated +> > > (the frequency being a couple thousand rows per minute), the database +> > > is growing out of proportion in size. After about a week, I have +> > > to redump the db by hand so as to get query times back to sensible +> > > figures. A transaction that takes ~50 seconds before the redump will +> > > then complete in under 5 seconds (the corresponding data/base/ dir having +> > > shrunk from ~2 GB to ~0.6GB). +> > > +> > > A nightly VACCUM ANALYZE is no use. +> > > +> > > A VACUUM FULL is no use. +> > > +> > > A VACUUM FULL followed by REINDEX is no use. +> > +> > Is the space being taken up by stats_min, this index, some other object? +> +> relname | relkind | relpages | reltuples +> ---------------------------------+---------+----------+------------- +> stats_hr | r | 61221 | 3.01881e+06 +> stats_hr_pkey | i | 26414 | 3.02239e+06 +> stats_min_pkey | i | 20849 | 953635 +> stats_hr_start | i | 17218 | 3.02142e+06 +> stats_min_start | i | 15284 | 949788 +> stats_min | r | 10885 | 948792 +> authinfo_pkey | i | 1630 | 1342 +> authinfo | r | 1004 | 1342 +> contract_ips | r | 865 | 565 +> contract_ips_pkey | i | 605 | 565 +> +> > What does VACUUM FULL VERBOSE stats_min; give you? +> +> Sorry, I can't run a VACUUM FULL at this time. +> We're in production use. +> +> + + Would more regular vacuum help. I think a vaccum every hour may do +the job. perhaps with an analyse every day. (I presume the statistics +don't change too much) + While I don't surgest doing a vacuum more than twice an hour as +this would slow down the system with little gain more than once a day may +improve the speed and space usage. + Just an idea. + +Peter + + +From pgsql-performance-owner@postgresql.org Fri May 30 05:37:24 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id A9FDF925B28 + for ; + Fri, 30 May 2003 05:37:22 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 56229-04 for ; + Fri, 30 May 2003 05:37:21 -0400 (EDT) +Received: from etna.obsidian.co.za (etna.obsidian.co.za [196.36.119.67]) + by developer.postgresql.org (Postfix) with ESMTP id 0E04E925B1C + for ; + Fri, 30 May 2003 05:37:19 -0400 (EDT) +Received: from etna.obsidian.co.za (localhost [127.0.0.1]) + by etna.obsidian.co.za (8.12.9/8.12.9) with ESMTP id h4U9bE9S008753 + for ; Fri, 30 May 2003 11:37:16 +0200 +Received: (from uucp@localhost) + by etna.obsidian.co.za (8.12.9/8.12.9/Submit) with UUCP id + h4U9bEtL008751 + for pgsql-performance@postgresql.org; Fri, 30 May 2003 11:37:14 +0200 +Received: from tarcil (tarcil [172.16.1.14]) + by flash.itvs.co.za (8.9.3/8.9.3) with ESMTP id MAA17411 + for ; Fri, 30 May 2003 12:04:59 +0200 +Date: Fri, 30 May 2003 11:23:10 +0200 (SAST) +From: Jeandre du Toit +X-X-Sender: jeandre@localhost.localdomain +To: pgsql-performance@postgresql.org +Subject: Table Relationships +In-Reply-To: <001c01c32689$82da1050$0403a8c0@fejleszt4> +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/270 +X-Sequence-Number: 2049 + + +What are the advantages to having a database relational? I am currently +discussing the design of a database with some people at work and they +reckon it is best to create one table with and index and all the data +instead of normalizing the database. I think that they think that joining +tables will slow down retrieval, is this true? + +Thanks +Jeandre + + +From pgsql-performance-owner@postgresql.org Fri May 30 06:08:49 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id EAEF9923407 + for ; + Fri, 30 May 2003 06:08:46 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 59102-07 for ; + Fri, 30 May 2003 06:07:50 -0400 (EDT) +Received: from shield.nordlb.lv (shield.pirmabanka.lv [195.114.57.4]) + by developer.postgresql.org (Postfix) with ESMTP id 0CFED9233FE + for ; + Fri, 30 May 2003 06:07:39 -0400 (EDT) +Received: from wall2.pirmabanka.lv (wall2-pub.nordlb.lv [195.114.57.14]) + by shield.nordlb.lv (8.12.9/8.12.9) with SMTP id h4UA7MGZ009440 + for ; Fri, 30 May 2003 13:07:22 +0300 +Received: from share.nordlb.lv ([10.0.0.10]) by wall2.pirmabanka.lv; + Fri, 30 May 2003 13:07:21 +0300 (EET DST) +Received: from pc311x1.nordlb.lv (localhost.localdomain [127.0.0.1]) + by nordlb.lv (8.11.6/8.11.6) with SMTP id h4UA7HL14568 + for ; Fri, 30 May 2003 13:07:21 +0300 +Received: (qmail 6220 invoked by uid 100); 30 May 2003 10:10:09 -0000 +Date: Fri, 30 May 2003 13:10:09 +0300 +From: "Victor Yegorov" +To: Jeandre du Toit +Cc: pgsql-performance@postgresql.org +Subject: Re: Table Relationships +Message-ID: <20030530101009.GD23596@nordlb.lv> +References: <001c01c32689$82da1050$0403a8c0@fejleszt4> + +Mime-Version: 1.0 +Content-Type: text/plain; charset=koi8-r +Content-Disposition: inline +In-Reply-To: +User-Agent: Mutt/1.4.1i +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/271 +X-Sequence-Number: 2050 + +* Jeandre du Toit [30.05.2003 12:57]: +> +> What are the advantages to having a database relational? I am currently +> discussing the design of a database with some people at work and they +> reckon it is best to create one table with and index and all the data +> instead of normalizing the database. I think that they think that joining +> tables will slow down retrieval, is this true? +> + +Take a look at situation from another side. + +Let's say: You own a store and have 3 customers and 5 products on your +store. All you going to keep in DB is track of all purchases. + +So, each time a customer will by a product, an new record will be added. +What this means: + +1. Customer's name will be repeated as many times, as many purchases he had + made. The same for each of products. In real world, you'll have about + 10,000 customers and about 100,000 products. Do you have enoght space on + your disks to store all that stuff? + +2. Some of your customers decided to change it's name. What you're going to + do? If you're going to insert new purchases of that customer with he's new + name, then in all turnover reports you'll have to specify both: + old name and new one. If he will hange his name again - again, all + reports are to be updated. + +There is much more stuff to read about Relational Data Model in books. + +About slowing down retrieval of data: all efforts today are put to speed up +things. You should think about your convenience in data manipulation. + + +I suggest you should try both: one huge table, and a set of normalized +tables and compare, what is quicker and what is easier to use. + +-- + +Victor Yegorov + +From pgsql-performance-owner@postgresql.org Fri May 30 08:10:04 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id AFCBC924C1B + for ; + Fri, 30 May 2003 08:10:03 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 75671-09 for ; + Fri, 30 May 2003 08:09:08 -0400 (EDT) +Received: from wolff.to (wolff.to [66.93.249.74]) + by developer.postgresql.org (Postfix) with SMTP id AA92B924B30 + for ; + Fri, 30 May 2003 08:08:56 -0400 (EDT) +Received: (qmail 8953 invoked by uid 500); 30 May 2003 12:11:01 -0000 +Date: Fri, 30 May 2003 07:11:01 -0500 +From: Bruno Wolff III +To: Jeandre du Toit +Cc: pgsql-performance@postgresql.org +Subject: Re: Table Relationships +Message-ID: <20030530121101.GA8920@wolff.to> +Mail-Followup-To: Jeandre du Toit , + pgsql-performance@postgresql.org +References: <001c01c32689$82da1050$0403a8c0@fejleszt4> + +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: +User-Agent: Mutt/1.5.4i +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/272 +X-Sequence-Number: 2051 + +On Fri, May 30, 2003 at 11:23:10 +0200, + Jeandre du Toit wrote: +> + +Don't reply to existing threads to start a new thread. + +> What are the advantages to having a database relational? I am currently +> discussing the design of a database with some people at work and they +> reckon it is best to create one table with and index and all the data +> instead of normalizing the database. I think that they think that joining +> tables will slow down retrieval, is this true? + +You might want to read some books on relational database theory. + +Date and Pascal are two noted authors of books on relational database theory. + +> +> Thanks +> Jeandre +> +> +> ---------------------------(end of broadcast)--------------------------- +> TIP 3: if posting/reading through Usenet, please send an appropriate +> subscribe-nomail command to majordomo@postgresql.org so that your +> message can get through to the mailing list cleanly + +From pgsql-performance-owner@postgresql.org Fri May 30 08:12:13 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 6F9DA924C1F + for ; + Fri, 30 May 2003 08:12:12 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 78020-05 for ; + Fri, 30 May 2003 08:11:16 -0400 (EDT) +Received: from wolff.to (wolff.to [66.93.249.74]) + by developer.postgresql.org (Postfix) with SMTP id 3B530924B30 + for ; + Fri, 30 May 2003 08:11:05 -0400 (EDT) +Received: (qmail 8968 invoked by uid 500); 30 May 2003 12:13:11 -0000 +Date: Fri, 30 May 2003 07:13:11 -0500 +From: Bruno Wolff III +To: SZUCS =?iso-8859-1?Q?G=E1bor?= +Cc: pgsql-performance@postgresql.org +Subject: Re: Select query takes long to execute +Message-ID: <20030530121311.GB8920@wolff.to> +Mail-Followup-To: SZUCS =?iso-8859-1?Q?G=E1bor?= , + pgsql-performance@postgresql.org +References: + <20030529194451.24416.h006.c001.wm@mail.dilger.cc.criticalpath.net> + <001c01c32689$82da1050$0403a8c0@fejleszt4> +Mime-Version: 1.0 +Content-Type: text/plain; charset=iso-8859-1 +Content-Disposition: inline +Content-Transfer-Encoding: 8bit +In-Reply-To: <001c01c32689$82da1050$0403a8c0@fejleszt4> +User-Agent: Mutt/1.5.4i +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/273 +X-Sequence-Number: 2052 + +On Fri, May 30, 2003 at 10:57:33 +0200, + SZUCS G�bor wrote: +> Nikolaus, +> +> I think that shouldn't be any more effective. As I experienced, it's +> irrelevant how many cols an index has as long as you only use the first +> column. And, after that, if you use another column, how could a missing +> second column be any better? + +Because the index will be more compact and reside on less disk blocks. +The planner also makes different guesses for the selectivity whne using +the first column of a multicolumn index as opposed to a single column +index. + +From pgsql-bugs-owner@postgresql.org Fri May 30 09:13:37 2003 +X-Original-To: pgsql-bugs@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id F2573923577 + for ; Fri, 30 May 2003 09:13:35 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) with ESMTP id 93316-02 for ; + Fri, 30 May 2003 09:12:37 -0400 (EDT) +Received: from sss.pgh.pa.us (unknown [192.204.191.242]) + by developer.postgresql.org (Postfix) with ESMTP id A98669235BA + for ; Fri, 30 May 2003 09:11:44 -0400 (EDT) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h4UDBdU6008939 + for ; Fri, 30 May 2003 09:11:39 -0400 (EDT) +To: pgsql-bugs@postgresql.org +Subject: Re: db growing out of proportion +In-reply-to: +References: +Comments: In-reply-to Peter Childs + message dated "Fri, 30 May 2003 10:21:51 +0100" +Date: Fri, 30 May 2003 09:11:39 -0400 +Message-ID: <8938.1054300299@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/114 +X-Sequence-Number: 6075 + +Peter Childs writes: +> On Fri, 30 May 2003, Tomas Szepe wrote: +>> Trouble is, as the rows in the tables get deleted/inserted/updated +>> (the frequency being a couple thousand rows per minute), the database +>> is growing out of proportion in size. + +> Would more regular vacuum help. I think a vaccum every hour may do +> the job. + +Also note that no amount of vacuuming will save you if the FSM is not +large enough to keep track of all the free space. The default FSM +settings, like all the other default settings in Postgres, are set up +for a small installation. You'd probably need to raise them by at least +a factor of 10 for this installation. + + regards, tom lane + +From pgsql-performance-owner@postgresql.org Fri May 30 10:31:15 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 867C8923384 + for ; + Fri, 30 May 2003 10:31:13 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 08831-02 for ; + Fri, 30 May 2003 10:31:12 -0400 (EDT) +Received: from etna.obsidian.co.za (etna.obsidian.co.za [196.36.119.67]) + by developer.postgresql.org (Postfix) with ESMTP id 3BFBD923380 + for ; + Fri, 30 May 2003 10:31:11 -0400 (EDT) +Received: from etna.obsidian.co.za (localhost [127.0.0.1]) + by etna.obsidian.co.za (8.12.9/8.12.9) with ESMTP id h4UEV89S016788; + Fri, 30 May 2003 16:31:09 +0200 +Received: (from uucp@localhost) + by etna.obsidian.co.za (8.12.9/8.12.9/Submit) with UUCP id + h4UEV80H016786; Fri, 30 May 2003 16:31:08 +0200 +Received: from tarcil (tarcil [172.16.1.14]) + by flash.itvs.co.za (8.9.3/8.9.3) with ESMTP id QAA18714; + Fri, 30 May 2003 16:04:49 +0200 +Date: Fri, 30 May 2003 15:34:36 +0200 (SAST) +From: Jeandre du Toit +X-X-Sender: jeandre@localhost.localdomain +To: Bruno Wolff III +Cc: pgsql-performance@postgresql.org +Subject: Re: Table Relationships +In-Reply-To: <20030530121101.GA8920@wolff.to> +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/275 +X-Sequence-Number: 2054 + +On Fri, 30 May 2003, Bruno Wolff III wrote: + +> On Fri, May 30, 2003 at 11:23:10 +0200, +> Jeandre du Toit wrote: +> > +> +> Don't reply to existing threads to start a new thread. + +Sorry about that, I did something screwy in Pine. I thought that it would +create a new mail. + +> +> > What are the advantages to having a database relational? I am currently +> > discussing the design of a database with some people at work and they +> > reckon it is best to create one table with and index and all the data +> > instead of normalizing the database. I think that they think that joining +> > tables will slow down retrieval, is this true? +> +> You might want to read some books on relational database theory. +> +> Date and Pascal are two noted authors of books on relational database theory. + +Thanks, I will look at these books. + +> +> > +> > Thanks +> > Jeandre +> > +> > + + +From pgsql-performance-owner@postgresql.org Fri May 30 10:25:28 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 4E6F9925415 + for ; + Fri, 30 May 2003 10:25:26 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 06998-06 for ; + Fri, 30 May 2003 10:25:24 -0400 (EDT) +Received: from mailhub1.sghms.ac.uk (firewall.sghms.ac.uk [194.82.50.2]) + by developer.postgresql.org (Postfix) with ESMTP id 65551925253 + for ; + Fri, 30 May 2003 10:25:23 -0400 (EDT) +Received: from [194.82.51.24] (helo=imail) + by mailhub1.sghms.ac.uk with esmtp (Exim 4.12) id 19Lkr7-0000Ki-00 + for pgsql-performance@postgresql.org; Fri, 30 May 2003 15:27:41 +0100 +Received: from [172.16.20.3] (mrc1-003.sghms.ac.uk [172.16.20.3]) + by imail.sghms.ac.uk + (iPlanet Messaging Server 5.1 HotFix 0.7 (built May 7 2002)) + with ESMTPA id <0HFP000BLENFEZ@imail.sghms.ac.uk> for + pgsql-performance@postgresql.org; Fri, 30 May 2003 15:23:39 +0100 (BST) +Date: Fri, 30 May 2003 15:23:28 +0100 +From: Adam Witney +Subject: Hardware advice +To: pgsql-performance +Message-id: +MIME-version: 1.0 +Content-type: text/plain; charset=ISO-8859-1 +Content-transfer-encoding: quoted-printable +User-Agent: Microsoft-Entourage/10.1.1.2418 +X-MailScanner-Information: Please contact sysadmin at sghms.ac.uk for more + information +X-MailScanner-MH1: Found to be clean +X-MailScanner-SpamCheck: not spam, SpamAssassin (score=-100, required 5, + USER_AGENT_ENTOURAGE, USER_IN_WHITELIST) +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/274 +X-Sequence-Number: 2053 + +Hi, + +I am in the process of pricing up boxes for our database, and I was +wondering if anyone had any recommendations or comments. + +The database itself will have around 100-150 users mostly accessing through +a PHP/apache interface. I don't expect lots of simultaneous activity, +however users will often be doing multiple table joins (can be up to 10-15 +tables in one query). Also they will often be pulling out on the order of +250,000 rows (5-10 numeric fields per row), processing the data (I may split +this to a second box) and then writing back ~20,000 rows of data (2-3 +numeric fields per row). + +Estimating total amount of data is quite tricky, but it could grow to +100-250Gb over the next 3 years. + +I have priced one box from the Dell web site as follows + +Single Intel Xeon 2.8GHz with 512kb L2 cache +2GB RAM + +36Gb 10,000rpm Ultra 3 160 SCSI +36Gb 10,000rpm Ultra 3 160 SCSI +146Gb 10,000rpm U320 SCSI +146Gb 10,000rpm U320 SCSI +146Gb 10,000rpm U320 SCSI + +PERC 3/DC RAID Controller (128MB Cache) + +RAID1 for 2x 36Gb drives +RAID5 for 3x 146Gb drives + +Running RedHat Linux 8.0 + +This configuration would be pretty much the top of our budget (~ =A35k). + +I was planning on having the RAID1 setup for the OS and then the RAID5 for +the db files. + +Would it be better to have a dual 2.4GHz setup rather than a single 2.8GHz +or would it not make much difference? + +Does the RAID setup look ok, or would anyone forsee problems in this +context? (This machine can take a maximum of 5 internal drives). + +Am I overdoing any particular component at the expense of another? + +Any other comments would be most welcome. + +Thanks for any help + +Adam + + +--=20 +This message has been scanned for viruses and +dangerous content by MailScanner, and is +believed to be clean. + + +From pgsql-bugs-owner@postgresql.org Fri May 30 10:27:35 2003 +X-Original-To: pgsql-bugs@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 96987925415 + for ; Fri, 30 May 2003 10:27:33 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) with ESMTP id 07001-05 for ; + Fri, 30 May 2003 10:27:32 -0400 (EDT) +Received: from wh1.baymountain.net (unknown [12.155.117.17]) + by developer.postgresql.org (Postfix) with ESMTP id 8D33F925253 + for ; Fri, 30 May 2003 10:27:32 -0400 (EDT) +Received: from twopunks.org (rdu26-242-078.nc.rr.com [66.26.242.78]) + (authenticated) + by wh1.baymountain.net (8.10.0/8.10.0) with ESMTP id h4UERWr26457 + for ; Fri, 30 May 2003 10:27:33 -0400 +X-Authentication-Warning: wh1.baymountain.net: cyrus owned process doing -bs +Message-ID: <3ED769E6.3050300@twopunks.org> +Date: Fri, 30 May 2003 10:25:42 -0400 +From: Todd Nemanich +User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20030225 +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: pgsql-bugs@postgresql.org +Subject: Re: db growing out of proportion +References: <20030529163239.GA11101@louise.pinerecords.com> +In-Reply-To: <20030529163239.GA11101@louise.pinerecords.com> +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/115 +X-Sequence-Number: 6076 + +I have a database with similar performance constraints. Our best +estimates put the turnover on our most active table at 350k tuples/day. +The hardware is a 4x1.4GHz Xeon w/ a RAID 1 disk setup, and the DB +floats around 500MB of disk space taken. Here is what we do to maintain +operations: + +1) Cron job @ 4:00AM that runs a full vacuum analyze on the DB, and +reindex on the major tables. (Reindex is to maintain index files in SHM) +An alerting feature pages the administrator if the job does not complete +within a reasonable amount of time. + +2) Every 15 minutes, a cron job runs a vacuum analyze on our five +largest tables. An alert is emailed to the administrator if a second +vacuum attempts to start before the previous completes. + +3) Every week, we review the disk usage numbers from daily peaks. This +determines if we need to increase our shmmax & shared buffers. + +Additionally, you may want to take a look at your query performance. Are +most of your queries doing sequential scans? In my system, the crucial +columns of the primary tables are int8 and float8 fields. I have those +indexed, and I get a serious performance boost by making sure all +SELECT/UPDATE/DELETE queries that use those columns in the WHERE have an +explicit ::int8 or ::float8 (Explain analyze is your friend). During +peak usage, there is an order of magnitude difference (usually 10 to +15x) between queries doing sequential scans on the table, and queries +doing index scans. Might be worth investigating if your queries are +taking 5 seconds when your DB is fresh. HTH. + + + +Tomas Szepe wrote: +> Hello everybody, +> +> I'm facing a simple yet gravely problem with postgresql 7.3.2 on x86 Linux. +> My db is used to store IP accounting statistics for about 30 C's. There are +> a couple truly trivial tables such as the one below: +> +> CREATE TABLE stats_min +> ( +> ip inet NOT NULL, +> start timestamp NOT NULL default CURRENT_TIMESTAMP(0), +> intlen int4 NOT NULL default 60, +> d_in int8 NOT NULL, +> d_out int8 NOT NULL, +> +> constraint "stats_min_pkey" PRIMARY KEY ("ip", "start") +> ); +> CREATE INDEX stats_min_start ON stats_min (start); +> +> A typical transaction committed on these tables looks like this: +> +> BEGIN WORK +> DELETE ... +> UPDATE/INSERT ... +> COMMIT WORK +> +> Trouble is, as the rows in the tables get deleted/inserted/updated +> (the frequency being a couple thousand rows per minute), the database +> is growing out of proportion in size. After about a week, I have +> to redump the db by hand so as to get query times back to sensible +> figures. A transaction that takes ~50 seconds before the redump will +> then complete in under 5 seconds (the corresponding data/base/ dir having +> shrunk from ~2 GB to ~0.6GB). +> +> A nightly VACCUM ANALYZE is no use. +> +> A VACUUM FULL is no use. +> +> A VACUUM FULL followed by REINDEX is no use. +> +> It seems that only a full redump involving "pg_dump olddb | \ +> psql newdb" is capable of restoring the system to its working +> glory. +> +> Please accept my apologies if I've overlooked a relevant piece of +> information in the docs. I'm in an urgent need of getting this +> problem resolved. +> + + +From pgsql-performance-owner@postgresql.org Fri May 30 10:44:33 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 62B6D9256BC + for ; + Fri, 30 May 2003 10:44:32 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 10707-05 for ; + Fri, 30 May 2003 10:44:31 -0400 (EDT) +Received: from mail.libertyrms.com (unknown [209.167.124.227]) + by developer.postgresql.org (Postfix) with ESMTP id CF15F925608 + for ; + Fri, 30 May 2003 10:44:30 -0400 (EDT) +Received: from [10.1.2.130] (helo=dba2) + by mail.libertyrms.com with esmtp (Exim 3.22 #3 (Debian)) + id 19Ll7P-0002Cr-00 + for ; Fri, 30 May 2003 10:44:31 -0400 +Received: by dba2 (Postfix, from userid 1019) + id D3C27D0E0; Fri, 30 May 2003 10:44:30 -0400 (EDT) +Date: Fri, 30 May 2003 10:44:30 -0400 +From: Andrew Sullivan +To: pgsql-performance +Subject: Re: Hardware advice +Message-ID: <20030530144430.GD17867@libertyrms.info> +Mail-Followup-To: Andrew Sullivan , + pgsql-performance +References: +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: +User-Agent: Mutt/1.5.4i +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/276 +X-Sequence-Number: 2055 + +On Fri, May 30, 2003 at 03:23:28PM +0100, Adam Witney wrote: +> RAID5 for 3x 146Gb drives + +I find the RAID5 on the PERC to be painfully slow. It's _really_ bad +if you don't put WAL on its own drive. + +Also, you don't mention it, but check to make sure you're getting ECC +memory on these boxes. Random memory errors which go undetected will +make you very unhappy. ECC lowers (but doesn't eliminate, +apparently) your chances. + +A + +-- +---- +Andrew Sullivan 204-4141 Yonge Street +Liberty RMS Toronto, Ontario Canada + M2P 2A8 + +1 416 646 3304 x110 + + +From pgsql-performance-owner@postgresql.org Fri May 30 11:42:12 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id F3EE9925BE1 + for ; + Fri, 30 May 2003 11:42:10 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 24118-10 for ; + Fri, 30 May 2003 11:42:09 -0400 (EDT) +Received: from mail1.ihs.com (mail1.ihs.com [170.207.70.222]) + by developer.postgresql.org (Postfix) with ESMTP id DB8A2925B2B + for ; + Fri, 30 May 2003 11:42:08 -0400 (EDT) +Received: from css120.ihs.com (css120.ihs.com [170.207.105.120]) + by mail1.ihs.com (8.12.9/8.12.9) with ESMTP id h4UFfbQB028126; + Fri, 30 May 2003 09:41:37 -0600 (MDT) +Date: Fri, 30 May 2003 09:25:38 -0600 (MDT) +From: "scott.marlowe" +To: Adam Witney +Cc: pgsql-performance +Subject: Re: Hardware advice +In-Reply-To: +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-MailScanner: Found to be clean +X-MailScanner-SpamCheck: +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/277 +X-Sequence-Number: 2056 + +On Fri, 30 May 2003, Adam Witney wrote: + +> 250,000 rows (5-10 numeric fields per row), processing the data (I may split +> this to a second box) and then writing back ~20,000 rows of data (2-3 +> numeric fields per row). + +Make sure and vacuum often and crank up your fsm values to be able to +reclaim lost disk space. + +> 36Gb 10,000rpm Ultra 3 160 SCSI +> 36Gb 10,000rpm Ultra 3 160 SCSI +> 146Gb 10,000rpm U320 SCSI +> 146Gb 10,000rpm U320 SCSI +> 146Gb 10,000rpm U320 SCSI +> +> PERC 3/DC RAID Controller (128MB Cache) + +If that box has a built in U320 controller or you can bypass the Perc, +give the Linux kernel level RAID1 and RAID5 drivers a try. On a dual CPU +box of that speed, they may well outrun many hardware controllers. +Contrary to popular opinion, software RAID is not slow in Linux. + +> RAID1 for 2x 36Gb drives +> RAID5 for 3x 146Gb drives + +You might wanna do something like go to all 146 gig drives, put a mirror +set on the first 20 or so gigs for the OS, and then use the remainder +(5x120gig or so ) to make your RAID5. The more drives in a RAID5 the +better, generally, up to about 8 or 12 as the optimal for most setups. + +But that setup of a RAID1 and RAID5 set is fine as is. + +By running software RAID you may be able to afford to upgrade the 36 gig +drives... + +> Would it be better to have a dual 2.4GHz setup rather than a single 2.8GHz +> or would it not make much difference? + +Yes it would. Linux servers running databases are much more responsive +with dual CPUs. + +> Am I overdoing any particular component at the expense of another? + +Maybe the RAID controller cost versus having more big hard drives. + + + +From pgsql-bugs-owner@postgresql.org Fri May 30 11:40:56 2003 +X-Original-To: pgsql-bugs@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 798B5925BE1 + for ; Fri, 30 May 2003 11:40:55 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) with ESMTP id 23894-07 for ; + Fri, 30 May 2003 11:40:50 -0400 (EDT) +Received: from megazone.bigpanda.com (megazone.bigpanda.com [63.150.15.178]) + by developer.postgresql.org (Postfix) with ESMTP id 77588925B2B + for ; Fri, 30 May 2003 11:40:50 -0400 (EDT) +Received: by megazone.bigpanda.com (Postfix, from userid 1001) + id BE5B1D632; Fri, 30 May 2003 08:40:43 -0700 (PDT) +Received: from localhost (localhost [127.0.0.1]) + by megazone.bigpanda.com (Postfix) with ESMTP + id B41475C0E; Fri, 30 May 2003 08:40:43 -0700 (PDT) +Date: Fri, 30 May 2003 08:40:43 -0700 (PDT) +From: Stephan Szabo +To: Tomas Szepe +Cc: +Subject: Re: db growing out of proportion +In-Reply-To: <20030530072442.GD14159@louise.pinerecords.com> +Message-ID: <20030530083944.N91707-100000@megazone23.bigpanda.com> +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/116 +X-Sequence-Number: 6077 + + +On Fri, 30 May 2003, Tomas Szepe wrote: + +> > [sszabo@megazone23.bigpanda.com] +> > +> > > Trouble is, as the rows in the tables get deleted/inserted/updated +> > > (the frequency being a couple thousand rows per minute), the database +> > > is growing out of proportion in size. After about a week, I have +> > > to redump the db by hand so as to get query times back to sensible +> > > figures. A transaction that takes ~50 seconds before the redump will +> > > then complete in under 5 seconds (the corresponding data/base/ dir having +> > > shrunk from ~2 GB to ~0.6GB). +> > > +> > > A nightly VACCUM ANALYZE is no use. +> > > +> > > A VACUUM FULL is no use. +> > > +> > > A VACUUM FULL followed by REINDEX is no use. +> > +> > Is the space being taken up by stats_min, this index, some other object? +> +> relname | relkind | relpages | reltuples +> ---------------------------------+---------+----------+------------- +> stats_hr | r | 61221 | 3.01881e+06 +> stats_hr_pkey | i | 26414 | 3.02239e+06 +> stats_min_pkey | i | 20849 | 953635 +> stats_hr_start | i | 17218 | 3.02142e+06 +> stats_min_start | i | 15284 | 949788 +> stats_min | r | 10885 | 948792 +> authinfo_pkey | i | 1630 | 1342 +> authinfo | r | 1004 | 1342 +> contract_ips | r | 865 | 565 +> contract_ips_pkey | i | 605 | 565 +> +> > What does VACUUM FULL VERBOSE stats_min; give you? +> +> Sorry, I can't run a VACUUM FULL at this time. +> We're in production use. + +As Tom said, you probably need higher FSM settings, but also, do you have +any long lived transactions (say from some kind of persistent connection +system) that might be preventing vacuum from removing rows? + + + +From pgsql-performance-owner@postgresql.org Fri May 30 12:07:17 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id C12D0925C40 + for ; + Fri, 30 May 2003 12:07:13 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 30333-06 for ; + Fri, 30 May 2003 12:07:12 -0400 (EDT) +Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) + by developer.postgresql.org (Postfix) with ESMTP id C98F2925C1A + for ; + Fri, 30 May 2003 12:07:11 -0400 (EDT) +Received: from [63.195.55.98] (HELO spooky) + by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) + with ESMTP id 3078866; Fri, 30 May 2003 09:07:16 -0700 +Content-Type: text/plain; + charset="iso-8859-1" +From: Josh Berkus +Organization: Aglio Database Solutions +To: Jeandre du Toit , + pgsql-performance@postgresql.org +Subject: Re: Table Relationships +Date: Fri, 30 May 2003 09:06:43 -0700 +User-Agent: KMail/1.4.3 +References: +In-Reply-To: +MIME-Version: 1.0 +Content-Transfer-Encoding: 8bit +Message-Id: <200305300906.43044.josh@agliodbs.com> +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/278 +X-Sequence-Number: 2057 + +Jeandre, + +> instead of normalizing the database. I think that they think that joining +> tables will slow down retrieval, is this true? + +No, it's not. I'm afraid that your co-workers learned their computer +knowledge 10 years ago and have not kept up to date. They may need +retraining. + +Modern database systems, especially PostgreSQL, are much faster with a proper +relational schema than with an inadequate flat-file table, due to the +efficient storage of data ... i.e., no redundancy. + +I highly suggest that you take a look at the book "Database Design for Mere +Mortals"; if you're asking the question you posted, you are nowhere near +ready to build a production database application. + +-- +Josh Berkus +Aglio Database Solutions +San Francisco + +From pgsql-performance-owner@postgresql.org Fri May 30 12:22:06 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 3DB95925C7A + for ; + Fri, 30 May 2003 12:22:06 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 34145-05 for ; + Fri, 30 May 2003 12:22:04 -0400 (EDT) +Received: from etna.obsidian.co.za (etna.obsidian.co.za [196.36.119.67]) + by developer.postgresql.org (Postfix) with ESMTP id BD34D925C22 + for ; + Fri, 30 May 2003 12:22:03 -0400 (EDT) +Received: from etna.obsidian.co.za (localhost [127.0.0.1]) + by etna.obsidian.co.za (8.12.9/8.12.9) with ESMTP id h4UGLu9S025699; + Fri, 30 May 2003 18:21:56 +0200 +Received: (from uucp@localhost) + by etna.obsidian.co.za (8.12.9/8.12.9/Submit) with UUCP id + h4UGLuwC025697; Fri, 30 May 2003 18:21:56 +0200 +Received: from tarcil (tarcil [172.16.1.14]) + by flash.itvs.co.za (8.9.3/8.9.3) with ESMTP id SAA01999; + Fri, 30 May 2003 18:49:21 +0200 +Date: Fri, 30 May 2003 18:19:48 +0200 (SAST) +From: Jeandre du Toit +X-X-Sender: jeandre@localhost.localdomain +To: Josh Berkus +Cc: pgsql-performance@postgresql.org +Subject: Re: Table Relationships +In-Reply-To: <200305300906.43044.josh@agliodbs.com> +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/279 +X-Sequence-Number: 2058 + +On Fri, 30 May 2003, Josh Berkus wrote: + +> Jeandre, +> +> > instead of normalizing the database. I think that they think that joining +> > tables will slow down retrieval, is this true? +> +> No, it's not. I'm afraid that your co-workers learned their computer +> knowledge 10 years ago and have not kept up to date. They may need +> retraining. + +Thought as much + +> +> Modern database systems, especially PostgreSQL, are much faster with a proper +> relational schema than with an inadequate flat-file table, due to the +> efficient storage of data ... i.e., no redundancy. + +That is what I thought, but since they out rank me at work I needed the +extra conformation. Now at least I can show them that I am not the only +person that thinks a flat table structure is stone age design. I know for a +fact it is better on Sybase, but I wasn't to sure about postgres and since +they have been working on it for longer than I have, I am expected to +follow their lead. + +> +> I highly suggest that you take a look at the book "Database Design for Mere +> Mortals"; if you're asking the question you posted, you are nowhere near +> ready to build a production database application. +> + +Thanks, I will have a look at that book. You are right, I am only first +year Bsc, but I had a feeling that the facts they are giving me can't be +right, it just didn't make any sense. They way I figured it, is that +having a relational database, makes the database smaller because there is +no duplicate data, which should make it faster. + +Thanks for your help. I will approach my managers. +Jeandre + + + +From pgsql-performance-owner@postgresql.org Fri May 30 12:30:26 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 67D80924F52 + for ; + Fri, 30 May 2003 12:30:23 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 36145-08 for ; + Fri, 30 May 2003 12:30:21 -0400 (EDT) +Received: from martin.sysdetect.com (martin.sysdetect.com [65.209.102.1]) + by developer.postgresql.org (Postfix) with ESMTP id 641AD924E31 + for ; + Fri, 30 May 2003 12:30:21 -0400 (EDT) +Received: (from mail@localhost) + by martin.sysdetect.com (8.11.4/8.11.3) id h4UGUKY22092 + for ; Fri, 30 May 2003 16:30:20 GMT +Received: from winwood.sysdetect.com(172.16.1.1) + via SMTP by mail.sysdetect.com, id smtpdqg6978; Fri May 30 16:30:11 2003 +Received: from startide.sysdetect.com (startide.sysdetect.com [172.16.1.34]) + by winwood.sysdetect.com (8.11.6/8.11.6) with ESMTP id h4UGUB905244 + for ; Fri, 30 May 2003 12:30:11 -0400 +Received: from startide.sysdetect.com (seth@localhost) + by startide.sysdetect.com (8.12.8/8.12.8/Submit) with ESMTP id + h4UGUBB5009655 + for ; Fri, 30 May 2003 12:30:11 -0400 +Message-Id: <200305301630.h4UGUBB5009655@startide.sysdetect.com> +To: pgsql-performance +From: pgsql-performance@sysd.com +Subject: Spam sent to addresses subscribed to psql-performance +Date: Fri, 30 May 2003 12:30:11 -0400 +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/280 +X-Sequence-Number: 2059 + + +I was unable to find the address of a human who manages these lists, +so I apologize for the off-topic email (email about abuse of the +psql-performance mailing list instead of email about psql +performance). + +I received, today, spam sent to addresses subscribed to +psql-performance. One address was ONLY used for this specific mailing +list mail, so there are only two ways the address could have been +discovered: + +* Someone found a way to retrieve the list of email addresses subscribed + to this mailing list. + +* Someone harvested the email addresses from the archive. + +The evidence supports the latter assertion, since other single-use +email addresses subscribed to other psql lists received no spam. + +Thus, I suggest that the archives be munged to translate all email +addresses to human (but not simple machine) readable form. + + -Seth Robertson + pgsql-performance@sysd.com + +Offsending (and offensive) spam included below +---------------------------------------------------------------------- +Return-Path: 6zw1krmhrk5l@netoneplus.com +Delivery-Date: Fri May 30 05:41:09 2003 +Delivery-Date: Fri, 30 May 2003 05:41:09 -0400 +Received: from martin.sysdetect.com (martin.sysdetect.com [172.16.1.254]) + by winwood.sysdetect.com (8.11.6/8.11.6) with ESMTP id h4U9f9927804; + Fri, 30 May 2003 05:41:09 -0400 +Received: (from mail@localhost) + by martin.sysdetect.com (8.11.4/8.11.3) id h4U9f7B02542; + Fri, 30 May 2003 09:41:07 GMT +Received: from user-0cal2q3.cable.mindspring.com(24.170.139.67) + via SMTP by mail.sysdetect.com, id smtpdgM8099; Fri May 30 09:40:57 2003 +Received: from zfd.8ot39.net [195.6.117.117] by user-0cal2q3.cable.mindspring.com with SMTP for ; Fri, 30 May 2003 06:40:57 -0400 +Message-ID: +From: "Adele Dickson" <6zw1krmhrk5l@netoneplus.com> +To: , +Subject: KARMEN'S pics x iroiaqypverhm tud +Date: Fri, 30 May 03 06:40:57 GMT +X-Priority: 3 +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook, Build 10.0.2616 +MIME-Version: 1.0 +Content-Type: multipart/alternative; + boundary="C_FC_.F69E_" + +This is a multi-part message in MIME format. + +--C_FC_.F69E_ +Content-Type: text/html +Content-Transfer-Encoding: quoted-printable + +

I hope this is apgsql-performance@sysd.com ... Here are the snapshot from my c@m last ni= +ght +

+

+
+
+
This will piss off my dink BF!! +
I hope I got your address right +
XOXOXOXOXOXOXOX +
+beam me off scotty= +
+ + +ieawib fh tahy +amt +q + +i akfrfddmhafjk hvyvcc +prz qzmuaz +--C_FC_.F69E_-- + +---------------------------------------------------------------------- + +From pgsql-performance-owner@postgresql.org Fri May 30 12:39:04 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id EBB56925C5D + for ; + Fri, 30 May 2003 12:39:02 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 37704-06 for ; + Fri, 30 May 2003 12:39:02 -0400 (EDT) +Received: from mail.libertyrms.com (unknown [209.167.124.227]) + by developer.postgresql.org (Postfix) with ESMTP id ED1F6925C54 + for ; + Fri, 30 May 2003 12:39:01 -0400 (EDT) +Received: from [10.1.2.130] (helo=dba2) + by mail.libertyrms.com with esmtp (Exim 3.22 #3 (Debian)) + id 19LmuD-0002sa-00 + for ; Fri, 30 May 2003 12:39:01 -0400 +Received: by dba2 (Postfix, from userid 1019) + id D4526D1BB; Fri, 30 May 2003 12:39:00 -0400 (EDT) +Date: Fri, 30 May 2003 12:39:00 -0400 +From: Andrew Sullivan +To: pgsql-performance@postgresql.org +Subject: Re: Table Relationships +Message-ID: <20030530163900.GF18140@libertyrms.info> +Mail-Followup-To: Andrew Sullivan , + pgsql-performance@postgresql.org +References: + <200305300906.43044.josh@agliodbs.com> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: <200305300906.43044.josh@agliodbs.com> +User-Agent: Mutt/1.5.4i +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/281 +X-Sequence-Number: 2060 + +On Fri, May 30, 2003 at 09:06:43AM -0700, Josh Berkus wrote: +> Modern database systems, especially PostgreSQL, are much faster with a proper +> relational schema than with an inadequate flat-file table, due to the +> efficient storage of data ... i.e., no redundancy. + +Are you sure you want to say it that strongly? After all, if you +have a data set which needs always to be returned in the same static +format, why not just denormalise it? It's sure faster that way in +every system I've ever encountered. + +It's only when you actually have relations to cope with that it +ceases to be an advantage. So, as usual, it depends on what you're +trying to do. + +A + +-- +---- +Andrew Sullivan 204-4141 Yonge Street +Liberty RMS Toronto, Ontario Canada + M2P 2A8 + +1 416 646 3304 x110 + + +From pgsql-performance-owner@postgresql.org Fri May 30 12:57:27 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 988D3925CAA + for ; + Fri, 30 May 2003 12:57:26 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 43218-05 for ; + Fri, 30 May 2003 12:57:25 -0400 (EDT) +Received: from mailhub1.sghms.ac.uk (firewall.sghms.ac.uk [194.82.50.2]) + by developer.postgresql.org (Postfix) with ESMTP id ED140925C73 + for ; + Fri, 30 May 2003 12:57:24 -0400 (EDT) +Received: from [194.82.51.24] (helo=imail) + by mailhub1.sghms.ac.uk with esmtp (Exim 4.12) + id 19Ln83-0004Xa-00; Fri, 30 May 2003 17:53:19 +0100 +Received: from [172.16.20.3] (mrc1-003.sghms.ac.uk [172.16.20.3]) + by imail.sghms.ac.uk + (iPlanet Messaging Server 5.1 HotFix 0.7 (built May 7 2002)) + with ESMTPA id <0HFP000GRLP2SO@imail.sghms.ac.uk>; Fri, + 30 May 2003 17:55:50 +0100 (BST) +Date: Fri, 30 May 2003 17:55:40 +0100 +From: Adam Witney +Subject: Re: Hardware advice +In-reply-to: +To: "scott.marlowe" , Adam Witney +Cc: pgsql-performance +Message-id: +MIME-version: 1.0 +Content-type: text/plain; charset=US-ASCII +Content-transfer-encoding: 7BIT +User-Agent: Microsoft-Entourage/10.1.1.2418 +X-MailScanner-Information: Please contact sysadmin at sghms.ac.uk for more + information +X-MailScanner-MH1: Found to be clean +X-MailScanner-SpamCheck: not spam, SpamAssassin (score=-106.2, required 5, + BAYES_01, IN_REP_TO, QUOTED_EMAIL_TEXT, USER_AGENT_ENTOURAGE, + USER_IN_WHITELIST) +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/282 +X-Sequence-Number: 2061 + +Hi scott, + +Thanks for the info + +> You might wanna do something like go to all 146 gig drives, put a mirror +> set on the first 20 or so gigs for the OS, and then use the remainder +> (5x120gig or so ) to make your RAID5. The more drives in a RAID5 the +> better, generally, up to about 8 or 12 as the optimal for most setups. + +I am not quite sure I understand what you mean here... Do you mean take 20Gb +from each of the 5 drives to setup a 20Gb RAID 1 device? Or just from the +first 2 drives? + +Thanks again for your help + +adam + + +-- +This message has been scanned for viruses and +dangerous content by MailScanner, and is +believed to be clean. + + +From pgsql-performance-owner@postgresql.org Fri May 30 13:03:53 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 7C330921DD8 + for ; + Fri, 30 May 2003 13:03:49 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 50167-03 for ; + Fri, 30 May 2003 13:03:49 -0400 (EDT) +Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) + by developer.postgresql.org (Postfix) with ESMTP id 9D691921BD9 + for ; + Fri, 30 May 2003 13:03:48 -0400 (EDT) +Received: from [63.195.55.98] (HELO spooky) + by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) + with ESMTP id 3079050; Fri, 30 May 2003 10:03:53 -0700 +Content-Type: text/plain; + charset="iso-8859-1" +From: Josh Berkus +Organization: Aglio Database Solutions +To: Andrew Sullivan , pgsql-performance@postgresql.org +Subject: Re: Table Relationships +Date: Fri, 30 May 2003 10:03:19 -0700 +User-Agent: KMail/1.4.3 +References: + <200305300906.43044.josh@agliodbs.com> + <20030530163900.GF18140@libertyrms.info> +In-Reply-To: <20030530163900.GF18140@libertyrms.info> +MIME-Version: 1.0 +Content-Transfer-Encoding: 8bit +Message-Id: <200305301003.19829.josh@agliodbs.com> +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/283 +X-Sequence-Number: 2062 + +Andrew, + +> Are you sure you want to say it that strongly? After all, if you +> have a data set which needs always to be returned in the same static +> format, why not just denormalise it? It's sure faster that way in +> every system I've ever encountered. +> +> It's only when you actually have relations to cope with that it +> ceases to be an advantage. So, as usual, it depends on what you're +> trying to do. + +Yeah, I suppose so ... if all they're doing is reporting on a static set of +data which is not transactional ... sure. If it's a disposable, +limited-time-use application. + +However, I have yet to see in my professional experience any application that +was really this way and stayed this way once it was in use ... relations have +a way of creeping in, and planning for them is less messy than refactoring. + +-- +Josh Berkus +Aglio Database Solutions +San Francisco + +From pgsql-performance-owner@postgresql.org Fri May 30 13:34:34 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 0D69D925533 + for ; + Fri, 30 May 2003 13:34:32 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 55633-08 for ; + Fri, 30 May 2003 13:34:30 -0400 (EDT) +Received: from mail1.ihs.com (mail1.ihs.com [170.207.70.222]) + by developer.postgresql.org (Postfix) with ESMTP id BC4DB924D89 + for ; + Fri, 30 May 2003 13:34:29 -0400 (EDT) +Received: from css120.ihs.com (css120.ihs.com [170.207.105.120]) + by mail1.ihs.com (8.12.9/8.12.9) with ESMTP id h4UHXdQB008791; + Fri, 30 May 2003 11:33:39 -0600 (MDT) +Date: Fri, 30 May 2003 11:17:39 -0600 (MDT) +From: "scott.marlowe" +To: Adam Witney +Cc: pgsql-performance +Subject: Re: Hardware advice +In-Reply-To: +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-MailScanner: Found to be clean +X-MailScanner-SpamCheck: +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/284 +X-Sequence-Number: 2063 + +On Fri, 30 May 2003, Adam Witney wrote: + +> Hi scott, +> +> Thanks for the info +> +> > You might wanna do something like go to all 146 gig drives, put a mirror +> > set on the first 20 or so gigs for the OS, and then use the remainder +> > (5x120gig or so ) to make your RAID5. The more drives in a RAID5 the +> > better, generally, up to about 8 or 12 as the optimal for most setups. +> +> I am not quite sure I understand what you mean here... Do you mean take 20Gb +> from each of the 5 drives to setup a 20Gb RAID 1 device? Or just from the +> first 2 drives? + +You could do it either way, since the linux kernel supports more than 2 +drives in a mirror. But, this costs on writes, so don't do it for things +like /var or the pg_xlog directory. + +There are a few ways you could arrange 5 146 gig drives. + +One might be to make the first 20 gig on each drive part of a mirror set +where the first two drives are the live mirror, and the next three are hot +spares. Then you could setup your RAID5 to have 4 live drives and 1 hot +spare. + +Hot spares are nice to have because they provide for the shortest period +of time during which your machine is running with a degraded RAID array. + +note that in linux you can set the kernel parameter +dev.raid.speed_limit_max and dev.raid.speed_limit_min to control the +rebuild bandwidth used so that when a disk dies you can set a compromise +between fast rebuilds, and lowering the demands on the I/O subsystem +during a rebuild. The max limit default is 100k / second, which is quite +slow. On a machine with Ultra320 gear, you could set that to 10 ot 20 +megs a second and still not saturate your SCSI buss. + +Now that I think of it, you could probably set it up so that you have a +mirror set for the OS, one for pg_xlog, and then use the rest of the +drives as RAID5. Then grab space on the fifth drive to make a hot spare +for both the pg_xlog and the OS drive. + +Drive 0 +[OS RAID1 20 Gig D0][big data drive RAID5 106 Gig D0] +Drive 1 +[OS RAID1 20 Gig D1][big data drive RAID5 106 Gig D1] +Drive 2 +[pg_xlog RAID1 20 gig D0][big data drive RAID5 106 Gig D2] +Drive 3 +[pg_xlog RAID1 20 gig D1][big data drive RAID5 106 Gig D3] +Drive 4 +[OS hot spare 20 gig][g_clog hot spare 20 gig][big data drive RAID5 106 +Gig hot spare] + +That would give you ~ 300 gigs storage. + +Of course, there will likely be slightly less performance than you might +get from dedicated RAID arrays for each RAID1/RAID5 set, but my guess is +that by having 4 (or 5 if you don't want a hot spare) drives in the RAID5 +it'll still be faster than a dedicated 3 drive RAID array. + + +From pgsql-performance-owner@postgresql.org Fri May 30 13:37:20 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 6D2FA9254EE + for ; + Fri, 30 May 2003 13:37:18 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 57589-05 for ; + Fri, 30 May 2003 13:37:17 -0400 (EDT) +Received: from mail1.ihs.com (mail1.ihs.com [170.207.70.222]) + by developer.postgresql.org (Postfix) with ESMTP id 5C6E8924E17 + for ; + Fri, 30 May 2003 13:37:17 -0400 (EDT) +Received: from css120.ihs.com (css120.ihs.com [170.207.105.120]) + by mail1.ihs.com (8.12.9/8.12.9) with ESMTP id h4UHaWQB009219; + Fri, 30 May 2003 11:36:32 -0600 (MDT) +Date: Fri, 30 May 2003 11:20:33 -0600 (MDT) +From: "scott.marlowe" +To: Josh Berkus +Cc: Andrew Sullivan , + +Subject: Re: Table Relationships +In-Reply-To: <200305301003.19829.josh@agliodbs.com> +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-MailScanner: Found to be clean +X-MailScanner-SpamCheck: +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/285 +X-Sequence-Number: 2064 + +On Fri, 30 May 2003, Josh Berkus wrote: + +> Andrew, +> +> > Are you sure you want to say it that strongly? After all, if you +> > have a data set which needs always to be returned in the same static +> > format, why not just denormalise it? It's sure faster that way in +> > every system I've ever encountered. +> > +> > It's only when you actually have relations to cope with that it +> > ceases to be an advantage. So, as usual, it depends on what you're +> > trying to do. +> +> Yeah, I suppose so ... if all they're doing is reporting on a static set of +> data which is not transactional ... sure. If it's a disposable, +> limited-time-use application. +> +> However, I have yet to see in my professional experience any application that +> was really this way and stayed this way once it was in use ... relations have +> a way of creeping in, and planning for them is less messy than refactoring. + +My philosophy has been you store the data normalized, and denormalize it +for performance down the line. + +but denormalizing for storage is usually a bad idea, as it allows your +data to get filled with inconsistencies. + +It's funny how people start worrying about performance of flat versus +normalized before really looking at the difference between the two first. +On Postgresql and most other databases, there are far more important +concerns to worry about when it comes to performance than whether or not +you're joining a couple tables. + + +From pgsql-performance-owner@postgresql.org Fri May 30 14:00:06 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 25777925B15 + for ; + Fri, 30 May 2003 13:59:59 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 64352-01 for ; + Fri, 30 May 2003 13:59:57 -0400 (EDT) +Received: from pos_pdc.posportal.com (unknown [12.158.169.100]) + by developer.postgresql.org (Postfix) with ESMTP id 452D59255E8 + for ; + Fri, 30 May 2003 13:59:57 -0400 (EDT) +Content-Class: urn:content-classes:message +MIME-Version: 1.0 +Content-Type: text/plain; + charset="utf-8" +Content-Transfer-Encoding: base64 +Subject: Re: Hardware advice +X-MimeOLE: Produced By Microsoft Exchange V6.0.6249.0 +Date: Fri, 30 May 2003 10:59:51 -0700 +Message-ID: <9B1C77393DED0D4B9DAA1AA1742942DA3BCBDC@pos_pdc.posportal.com> +X-MS-Has-Attach: +X-MS-TNEF-Correlator: +Thread-Topic: [PERFORM] Hardware advice +Thread-Index: AcMmzstT08Iepwh9Rwe+tNcXvet3BAABIARv +From: "Roman Fail" +To: "Adam Witney" , + "scott.marlowe" , + "Adam Witney" +Cc: "pgsql-performance" +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/286 +X-Sequence-Number: 2065 + +QmFzZWQgb24gd2hhdCB5b3UndmUgc2FpZCwgSSB3b3VsZCBndWVzcyB5b3Ug +YXJlIGNvbnNpZGVyaW5nIHRoZSBEZWxsIFBvd2VyRWRnZSAyNjUwIHNpbmNl +IGl0IGhhcyA1IGRyaXZlIGJheXMuICBJZiB5b3UgY291bGQgYWZmb3JkIHRo +ZSByYWNrc3BhY2UgYW5kIGp1c3QgYSBiaXQgbW9yZSBtb25leSwgSSdkIGdl +dCB0aGUgdG93ZXIgY29uZmlndXJhdGlvbiAyNjAwIHdpdGggNiBkcml2ZSBi +YXlzIChhbmQgcmFjayByYWlscyBpZiBuZWVkZWQgLSBEZWxsIGV2ZW4gZ2l2 +ZXMgeW91IGEgc3BlY2lhbCByYWNrbW91bnQgZmFjZXBsYXRlIGlmIHlvdSBv +cmRlciBhIHRvd2VyIHdpdGggcmFjayByYWlscykuICBUaGlzIHdvdWxkIGFs +bG93IHlvdSB0byBoYXZlIHRoaXMgY29uZmlndXJhdGlvbiwgd2hpY2ggSSB0 +aGluayB3b3VsZCBiZSBhYm91dCBpZGVhbCBmb3IgdGhlIHByaWNlIHJhbmdl +IHlvdSBhcmUgbG9va2luZyBhdDoNCiANCiogTGludXgga2VybmVsIFJBSUQN +CiogRHVhbCBwcm9jZXNzb3JzIC0gYmV0dGVyIHRoYW4gYSBzaW5nbGUgZmFz +dGVyIHByb2Nlc3NvciwgZXNwZWNpYWxseSB3aXRoIGNvbmN1cnJlbnQgdXNl +ciBsb2FkIGFuZCBzb2Z0d2FyZSBSQUlEIG9uIHRvcCBvZiB0aGF0DQoqIDJ4 +MzZHQiBpbiBSQUlELTEgKGZvciBPUyBhbmQgV0FMKQ0KKiA0eDE0NkdCIGlu +IFJBSUQtMTAgKGZvciBkYXRhKSAoYWx0ZXJuYXRpdmU6IDQtZGlzayBSQUlE +LTUpDQogDQpUaGUgUkFJRC0xMCBhcnJheSBnaXZlcyB5b3UgdGhlIHNhbWUg +YW1vdW50IG9mIHNwYWNlIHlvdSB3b3VsZCBoYXZlIHdpdGggYSAzLWRpc2sg +UkFJRC01IGFuZCBpbXByb3ZlZCBmYXVsdCB0b2xlcmFuY2UuICBBbHRob3Vn +aCBJJ20gcHJldHR5IHN1cmUgeW91ciBkcml2ZXMgd29uJ3QgYmUgaG90LXN3 +YXBwYWJsZSB3aXRoIHRoZSBzb2Z0d2FyZSBSQUlEIC0gSSd2ZSBuZXZlciBh +Y3R1YWxseSBoYWQgdG8gZG8gaXQuDQogDQpJIGNhbid0IHNheSBJIGxpa2Ug +U2NvdHQncyBpZGVhIG11Y2ggYmVjYXVzZSB0aGUgV0FMIGFuZCBPUyBhcmUg +Y29tcGV0aW5nIGZvciBkaXNrIHRpbWUgd2l0aCB0aGUgZGF0YSBzaW5jZSB0 +aGV5IGFyZSBvbiB0aGUgc2FtZSBwaHlzaWNhbCBkaXNrLiAgSW4gYSBkYXRh +YmFzZSB0aGF0IGlzIG1haW5seSByZWFkcyB3aXRoIGZldyB3cml0ZXMsIHRo +aXMgd291bGRuJ3QgYmUgc3VjaCBhIHByb2JsZW0gdGhvdWdoLg0KIA0KSnVz +dCBteSBpbmV4cGVydCBvcGluaW9uLA0KIA0KUm9tYW4NCiANCg0KCS0tLS0t +T3JpZ2luYWwgTWVzc2FnZS0tLS0tIA0KCUZyb206IEFkYW0gV2l0bmV5IFtt +YWlsdG86YXdpdG5leUBzZ2htcy5hYy51a10gDQoJU2VudDogRnJpIDUvMzAv +MjAwMyA5OjU1IEFNIA0KCVRvOiBzY290dC5tYXJsb3dlOyBBZGFtIFdpdG5l +eSANCglDYzogcGdzcWwtcGVyZm9ybWFuY2UgDQoJU3ViamVjdDogUmU6IFtQ +RVJGT1JNXSBIYXJkd2FyZSBhZHZpY2UNCgkNCgkNCg0KCUhpIHNjb3R0LA0K +CQ0KCVRoYW5rcyBmb3IgdGhlIGluZm8NCgkNCgk+IFlvdSBtaWdodCB3YW5u +YSBkbyBzb21ldGhpbmcgbGlrZSBnbyB0byBhbGwgMTQ2IGdpZyBkcml2ZXMs +IHB1dCBhIG1pcnJvcg0KCT4gc2V0IG9uIHRoZSBmaXJzdCAyMCBvciBzbyBn +aWdzIGZvciB0aGUgT1MsIGFuZCB0aGVuIHVzZSB0aGUgcmVtYWluZGVyDQoJ +PiAoNXgxMjBnaWcgb3Igc28gKSB0byBtYWtlIHlvdXIgUkFJRDUuICBUaGUg +bW9yZSBkcml2ZXMgaW4gYSBSQUlENSB0aGUNCgk+IGJldHRlciwgZ2VuZXJh +bGx5LCB1cCB0byBhYm91dCA4IG9yIDEyIGFzIHRoZSBvcHRpbWFsIGZvciBt +b3N0IHNldHVwcy4NCgkNCglJIGFtIG5vdCBxdWl0ZSBzdXJlIEkgdW5kZXJz +dGFuZCB3aGF0IHlvdSBtZWFuIGhlcmUuLi4gRG8geW91IG1lYW4gdGFrZSAy +MEdiDQoJZnJvbSBlYWNoIG9mIHRoZSA1IGRyaXZlcyB0byBzZXR1cCBhIDIw +R2IgUkFJRCAxIGRldmljZT8gT3IganVzdCBmcm9tIHRoZQ0KCWZpcnN0IDIg +ZHJpdmVzPw0KCQ0KCVRoYW5rcyBhZ2FpbiBmb3IgeW91ciBoZWxwDQoJDQoJ +YWRhbQ0KCQ0KCQ0KCS0tDQoJVGhpcyBtZXNzYWdlIGhhcyBiZWVuIHNjYW5u +ZWQgZm9yIHZpcnVzZXMgYW5kDQoJZGFuZ2Vyb3VzIGNvbnRlbnQgYnkgTWFp +bFNjYW5uZXIsIGFuZCBpcw0KCWJlbGlldmVkIHRvIGJlIGNsZWFuLg0KCQ0K +CQ0KCS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLShlbmQgb2YgYnJvYWRj +YXN0KS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLQ0KCVRJUCAxOiBzdWJz +Y3JpYmUgYW5kIHVuc3Vic2NyaWJlIGNvbW1hbmRzIGdvIHRvIG1ham9yZG9t +b0Bwb3N0Z3Jlc3FsLm9yZw0KCQ0KDQo= + +From pgsql-performance-owner@postgresql.org Fri May 30 14:18:59 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 6592C925CB5 + for ; + Fri, 30 May 2003 14:18:56 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 69547-02 for ; + Fri, 30 May 2003 14:18:55 -0400 (EDT) +Received: from mail.libertyrms.com (unknown [209.167.124.227]) + by developer.postgresql.org (Postfix) with ESMTP id 73339925CAA + for ; + Fri, 30 May 2003 14:18:55 -0400 (EDT) +Received: from [10.1.2.130] (helo=dba2) + by mail.libertyrms.com with esmtp (Exim 3.22 #3 (Debian)) + id 19LoSt-0003UC-00 + for ; Fri, 30 May 2003 14:18:55 -0400 +Received: by dba2 (Postfix, from userid 1019) + id ABEF4D1BB; Fri, 30 May 2003 14:18:54 -0400 (EDT) +Date: Fri, 30 May 2003 14:18:54 -0400 +From: Andrew Sullivan +To: pgsql-performance@postgresql.org +Subject: Re: Table Relationships +Message-ID: <20030530181854.GA19077@libertyrms.info> +Mail-Followup-To: Andrew Sullivan , + pgsql-performance@postgresql.org +References: <200305301003.19829.josh@agliodbs.com> + +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: +User-Agent: Mutt/1.5.4i +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/287 +X-Sequence-Number: 2066 + +On Fri, May 30, 2003 at 11:20:33AM -0600, scott.marlowe wrote: + +> but denormalizing for storage is usually a bad idea, as it allows your +> data to get filled with inconsistencies. + +Sure, but if performance is an important goal for certain kinds of +SELECTs, using a trigger at insert or update to do denormalising is +perhaps an acceptable approach. It's obvious that in most cases, +denormalising instead of optimising your normalisation is silly. But +if you need something to return in, say, 2ms most of the time, and it +requires a wide variety of data, denormalising is a good idea. + +It is, of course, contrary to the RDBMS-y mind to denormalise. But +there are (rare) times when it's a good idea, and I hate to see it +rejected out of hand in such cases. + +A +-- +---- +Andrew Sullivan 204-4141 Yonge Street +Liberty RMS Toronto, Ontario Canada + M2P 2A8 + +1 416 646 3304 x110 + + +From pgsql-performance-owner@postgresql.org Fri May 30 15:15:17 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id BC736921BE0 + for ; + Fri, 30 May 2003 15:15:15 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 84242-03 for ; + Fri, 30 May 2003 15:15:14 -0400 (EDT) +Received: from isis.pcis.net (cr.pcis.net [207.18.226.3]) + by developer.postgresql.org (Postfix) with ESMTP id 39CB8921B98 + for ; + Fri, 30 May 2003 15:15:14 -0400 (EDT) +Received: from lyric.ofsloans.com (unverified [209.180.142.225]) by + isis.pcis.net + (Rockliffe SMTPRA 4.5.6) with ESMTP id ; + Fri, 30 May 2003 14:15:12 -0500 +Subject: Re: Hardware advice +From: Will LaShell +To: Andrew Sullivan +Cc: pgsql-performance +In-Reply-To: <20030530144430.GD17867@libertyrms.info> +References: + <20030530144430.GD17867@libertyrms.info> +Content-Type: multipart/signed; micalg=pgp-sha1; + protocol="application/pgp-signature"; + boundary="=-FTHg+X4CjVgbqFsT5gSt" +X-Mailer: Ximian Evolution 1.0.8 (1.0.8-10) +Date: 30 May 2003 12:14:57 -0700 +Message-Id: <1054322103.15469.8.camel@lyric.ofsloans.com> +Mime-Version: 1.0 +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/288 +X-Sequence-Number: 2067 + +--=-FTHg+X4CjVgbqFsT5gSt +Content-Type: text/plain +Content-Transfer-Encoding: quoted-printable + +On Fri, 2003-05-30 at 07:44, Andrew Sullivan wrote: +> On Fri, May 30, 2003 at 03:23:28PM +0100, Adam Witney wrote: +> > RAID5 for 3x 146Gb drives +>=20 +> I find the RAID5 on the PERC to be painfully slow. It's _really_ bad +> if you don't put WAL on its own drive. + +This seems to be an issue with the dell firmware. The megaraid devel +list has been tracking this issue on and off for some time now. People +have had good luck with a couple of different fixes. The PERC cards +-can- be made not to suck and the LSI cards simply don't have the +problem. ( Since they are effectively the same card its the opinion that +its the firmware ) + + + +> Also, you don't mention it, but check to make sure you're getting ECC +> memory on these boxes. Random memory errors which go undetected will +> make you very unhappy. ECC lowers (but doesn't eliminate, +> apparently) your chances. + +100% agree with this note. + +> A +>=20 +> --=20 +> ---- +> Andrew Sullivan 204-4141 Yonge Street +> Liberty RMS Toronto, Ontario Canada +> M2P 2A8 +> +1 416 646 3304 x110 +>=20 +>=20 +> ---------------------------(end of broadcast)--------------------------- +> TIP 2: you can get off all lists at once with the unregister command +> (send "unregister YourEmailAddressHere" to majordomo@postgresql.org) + + +--=-FTHg+X4CjVgbqFsT5gSt +Content-Type: application/pgp-signature; name=signature.asc +Content-Description: This is a digitally signed message part + +-----BEGIN PGP SIGNATURE----- +Version: GnuPG v1.0.7 (GNU/Linux) + +iD8DBQA+162xZr3R5kgOZd0RAllLAJ93qxXFS2L1klz/lpBokaNFIlCY9ACeNOSu +Hh171+G9yapGHSKQYW9VyPw= +=2xsh +-----END PGP SIGNATURE----- + +--=-FTHg+X4CjVgbqFsT5gSt-- + + +From pgsql-performance-owner@postgresql.org Fri May 30 15:43:23 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 24A1B925D44 + for ; + Fri, 30 May 2003 15:43:20 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 94139-01 for ; + Fri, 30 May 2003 15:43:19 -0400 (EDT) +Received: from mail1.ihs.com (mail1.ihs.com [170.207.70.222]) + by developer.postgresql.org (Postfix) with ESMTP id D1BB8925D3F + for ; + Fri, 30 May 2003 15:43:17 -0400 (EDT) +Received: from css120.ihs.com (css120.ihs.com [170.207.105.120]) + by mail1.ihs.com (8.12.9/8.12.9) with ESMTP id h4UJgVWf022347; + Fri, 30 May 2003 13:42:31 -0600 (MDT) +Date: Fri, 30 May 2003 13:26:31 -0600 (MDT) +From: "scott.marlowe" +To: Roman Fail +Cc: Adam Witney , + pgsql-performance +Subject: Re: Hardware advice +In-Reply-To: <9B1C77393DED0D4B9DAA1AA1742942DA3BCBDC@pos_pdc.posportal.com> +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-MailScanner: Found to be clean +X-MailScanner-SpamCheck: +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/289 +X-Sequence-Number: 2068 + +On Fri, 30 May 2003, Roman Fail wrote: + +> Based on what you've said, I would guess you are considering the Dell PowerEdge 2650 since it has 5 drive bays. If you could afford the rackspace and just a bit more money, I'd get the tower configuration 2600 with 6 drive bays (and rack rails if needed - Dell even gives you a special rackmount faceplate if you order a tower with rack rails). This would allow you to have this configuration, which I think would be about ideal for the price range you are looking at: +> +> * Linux kernel RAID + +Actually, I think he was looking at hardware RAID, but I was recommending +software RAID as at least an option. I've found that on modern hardware +with late model kernels, Linux is pretty fast with straight RAID, but not +as good with layering it, fyi. I haven't tested since 2.4.9 though, so +things may well have changed, and hopefully for the better, in relation to +running fast in layered RAID. + +they both would likely work well, but going with a sub par HW raid card +will make the system slower than the kernel sw RAID. + +> * Dual processors - better than a single faster processor, especially +> with concurrent user load and software RAID on top of that +> * 2x36GB in RAID-1 (for OS and WAL) +> * 4x146GB in RAID-10 (for data) (alternative: 4-disk RAID-5) +> +> The RAID-10 array gives you the same amount of space you would have +> with a 3-disk RAID-5 and improved fault tolerance. Although I'm pretty +> sure your drives won't be hot-swappable with the software RAID - I've +> never actually had to do it. + +I agree that 6 drives makes this a much better option. + +Actually, the hot swappable issue can only be accomplished in linux kernel +sw raid by using multiple controllers. It's not really "hot swap" because +you have to basically reset that card and it's information about which +drives are on it. Using two controllers, where one runs one RAID0 set, +and the other runs another RAID0 set, and you run a RAID1 on top, you can +then use hot swap shoes and replace failed drives. + +The improved fault tolerance of the RAID 1+0 is minimal over the RAID5 if +the RAID5 has a hot spare, but it is there. + +I've removed and added drives to running arrays, and the raidhotadd +program to do it is quite easy to drive. It all seemed to work quite +well. The biggest problem you'll note when a drive fails is that the +kernel / scsi driver will keep resetting the bus and timing out the +device, so with a failed device, linux kernel RAID can be a bit doggish +until you restart the SCSI driver so it KNOWs the drive's not there and +quits asking for it over and over. + +> I can't say I like Scott's idea much because the WAL and OS are +> competing for disk time with the data since they are on the same +> physical disk. In a database that is mainly reads with few writes, +> this wouldn't be such a problem though. + +You'd be surprised how often this is a non-issue. If you're writing +20,000 records every 10 minutes or so, the location of the WAL file is not +that important. The machine will lug for a few seconds, insert, and be +done. The speed increase averaged out over time is almost nothing. + +Now, transactional systems are a whole nother enchilada. I got the +feeling from the original post this was more a batch processing kinda +thing. + +I knew the solution I was giving was suboptimal on performance (I might +have even alluded to that...). I was going more for maximizing use of +rack space and getting the most storage. I think the user said that this +project might well grow to 250 or 300 gig, so size is probably more or as +important as speed for this system. + +RAID5 is pretty much the compromise RAID set. It's not necessarily the +fastest, it certainly isn't the sexiest, but it provides a lot of storage +for very little redundancy cost, and with a hot spare it's pretty much +24/7 with a couple days off a year for scheduled maintenance. Combine +that with having n-1 number of platters for each read to be spread across +make it a nice choice for data warehousing or report serving. + +Whatever he does, he should make sure he turns off atime on the data +partition. That can utterly kill a postgresql / linux box by a factor of +right at two for someone doing small reads. + + + +From pgsql-performance-owner@postgresql.org Fri May 30 15:50:23 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 34662921BC5 + for ; + Fri, 30 May 2003 15:50:21 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 96628-10 for ; + Fri, 30 May 2003 15:50:20 -0400 (EDT) +Received: from mail1.ihs.com (mail1.ihs.com [170.207.70.222]) + by developer.postgresql.org (Postfix) with ESMTP id 8891C921BBE + for ; + Fri, 30 May 2003 15:50:19 -0400 (EDT) +Received: from css120.ihs.com (css120.ihs.com [170.207.105.120]) + by mail1.ihs.com (8.12.9/8.12.9) with ESMTP id h4UJnJWf022824; + Fri, 30 May 2003 13:49:19 -0600 (MDT) +Date: Fri, 30 May 2003 13:33:19 -0600 (MDT) +From: "scott.marlowe" +To: Will LaShell +Cc: Andrew Sullivan , + pgsql-performance +Subject: Re: Hardware advice +In-Reply-To: <1054322103.15469.8.camel@lyric.ofsloans.com> +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-MailScanner: Found to be clean +X-MailScanner-SpamCheck: +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/290 +X-Sequence-Number: 2069 + +On 30 May 2003, Will LaShell wrote: + +> On Fri, 2003-05-30 at 07:44, Andrew Sullivan wrote: +> > On Fri, May 30, 2003 at 03:23:28PM +0100, Adam Witney wrote: +> > > RAID5 for 3x 146Gb drives +> > +> > I find the RAID5 on the PERC to be painfully slow. It's _really_ bad +> > if you don't put WAL on its own drive. +> +> This seems to be an issue with the dell firmware. The megaraid devel +> list has been tracking this issue on and off for some time now. People +> have had good luck with a couple of different fixes. The PERC cards +> -can- be made not to suck and the LSI cards simply don't have the +> problem. ( Since they are effectively the same card its the opinion that +> its the firmware ) + +I've used the LSI/MegaRAID cards in the past. They're not super fast, but +they're not slow either. Very solid operation. Sometimes the firmware +makes you feel like you're wearing handcuffs compared to the relative +freedom in the kernel sw drivers (i.e. you can force the kernel to take +back a failed drive, the megaraid just won't take it back until it's been +formatted, that kind of thing). + +The LSI plain scsi cards in general are great cards, I got an UWSCSI card +by them with gigabit ethernet thrown in off ebay a couple years back and +it's VERY fast and stable. + +Also, if you're getting cache memory on the megaraid/perc card, make sure +you get the battery backup module. + + +From pgsql-performance-owner@postgresql.org Fri May 30 15:55:04 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 4CB7F921BBC + for ; + Fri, 30 May 2003 15:55:03 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 96780-10 for ; + Fri, 30 May 2003 15:55:01 -0400 (EDT) +Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) + by developer.postgresql.org (Postfix) with ESMTP id 67974921BC5 + for ; + Fri, 30 May 2003 15:55:01 -0400 (EDT) +Received: from [66.219.92.2] (HELO temoku) + by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) + with ESMTP id 3079517; Fri, 30 May 2003 12:55:06 -0700 +Content-Type: text/plain; + charset="iso-8859-1" +From: Josh Berkus +Reply-To: josh@agliodbs.com +Organization: Aglio Database Solutions +To: Andrew Sullivan , pgsql-performance@postgresql.org +Subject: Re: Table Relationships +Date: Fri, 30 May 2003 12:54:26 -0700 +User-Agent: KMail/1.4.3 +References: <200305301003.19829.josh@agliodbs.com> + + <20030530181854.GA19077@libertyrms.info> +In-Reply-To: <20030530181854.GA19077@libertyrms.info> +MIME-Version: 1.0 +Content-Transfer-Encoding: quoted-printable +Message-Id: <200305301254.26283.josh@agliodbs.com> +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/291 +X-Sequence-Number: 2070 + +Andrew, + +> Sure, but if performance is an important goal for certain kinds of +> SELECTs, using a trigger at insert or update to do denormalising is +> perhaps an acceptable approach. It's obvious that in most cases, +> denormalising instead of optimising your normalisation is silly. But +> if you need something to return in, say, 2ms most of the time, and it +> requires a wide variety of data, denormalising is a good idea. + +I've done this plenty of times ... but what you're talking about is more of= + a=20 +"materialized view" than denormalized data. The data is still stored in= +=20 +normal form; it is just distilled for a particular view and saved on disk f= +or=20 +quick reference. This is often a good approach with performance-sensitive,= +=20 +complex databases. + +> It is, of course, contrary to the RDBMS-y mind to denormalise. But +> there are (rare) times when it's a good idea, and I hate to see it +> rejected out of hand in such cases. + +There is a big difference between denormalizing normalized data and storing= +=20 +your data in denormalized (basically flat file) form in the first place. + +--=20 +-Josh Berkus + Aglio Database Solutions + San Francisco + + +From pgsql-performance-owner@postgresql.org Fri May 30 16:33:15 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 29CAF925DC2 + for ; + Fri, 30 May 2003 16:33:14 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 05541-05 for ; + Fri, 30 May 2003 16:33:13 -0400 (EDT) +Received: from imo-d01.mx.aol.com (imo-d01.mx.aol.com [205.188.157.33]) + by developer.postgresql.org (Postfix) with ESMTP id BC8EA925DB9 + for ; + Fri, 30 May 2003 16:33:12 -0400 (EDT) +Received: from yusuf0478@netscape.net + by imo-d01.mx.aol.com (mail_out_v36.3.) id k.7.8cea604 (22681) + for ; + Fri, 30 May 2003 16:33:07 -0400 (EDT) +Received: from netscape.net (66-163-11-108.ip.tor.radiant.net [66.163.11.108]) + by air-in04.mx.aol.com (v93.12) with ESMTP id + MAILININ42-58993ed7c003366; Fri, 30 May 2003 16:33:07 -0400 +Message-ID: <3ED7C003.1090303@netscape.net> +Date: Fri, 30 May 2003 16:33:07 -0400 +From: Yusuf +User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; + rv:1.0.2) Gecko/20030208 Netscape/7.02 +X-Accept-Language: en-us, en +MIME-Version: 1.0 +To: pgsql-performance +Subject: Enabling and Disabling Sequencial Scan +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit +X-Mailer: Unknown (No Version) +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/292 +X-Sequence-Number: 2071 + +In the application, that I'm working on, I have a query that'll be a lot +60% faster if I disable sequential scan forcing it to you my index. + +Is it bad practice to disable sequential scan ( set +enable_seqscan=false), run my query then enable sequential scan, +whenever I'm running this query? Why? + +Thanks in advance + +- David Wendy + + +From pgsql-performance-owner@postgresql.org Fri May 30 17:03:29 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id E0095925D9D + for ; + Fri, 30 May 2003 17:03:22 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 11012-05 for ; + Fri, 30 May 2003 17:03:22 -0400 (EDT) +Received: from mail1.ihs.com (mail1.ihs.com [170.207.70.222]) + by developer.postgresql.org (Postfix) with ESMTP id B852C925D93 + for ; + Fri, 30 May 2003 17:03:21 -0400 (EDT) +Received: from css120.ihs.com (css120.ihs.com [170.207.105.120]) + by mail1.ihs.com (8.12.9/8.12.9) with ESMTP id h4UL2CWf029337; + Fri, 30 May 2003 15:02:12 -0600 (MDT) +Date: Fri, 30 May 2003 14:46:12 -0600 (MDT) +From: "scott.marlowe" +To: Yusuf +Cc: pgsql-performance +Subject: Re: Enabling and Disabling Sequencial Scan +In-Reply-To: <3ED7C003.1090303@netscape.net> +Message-ID: +MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; charset=US-ASCII +X-MailScanner: Found to be clean +X-MailScanner-SpamCheck: +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/293 +X-Sequence-Number: 2072 + +On Fri, 30 May 2003, Yusuf wrote: + +> In the application, that I'm working on, I have a query that'll be a lot +> 60% faster if I disable sequential scan forcing it to you my index. +> +> Is it bad practice to disable sequential scan ( set +> enable_seqscan=false), run my query then enable sequential scan, +> whenever I'm running this query? Why? + +setting seqscan to off is more of a troubleshooting tool than a tuning +tool, albeit sometimes it's the only tuning tool that MIGHT work. + +Once you've determined that the database is picking the wrong plan when +you turn seqscan back on, you need to figure out how to convince the +database to use the right plan more often. + +The best parameters to change and see how they affect this are the +*cost* parameters and the effective cache size. + +show all; will show them to you, the ones we're interested in are these: + +NOTICE: effective_cache_size is 100000 +NOTICE: random_page_cost is 1 +NOTICE: cpu_tuple_cost is 0.01 +NOTICE: cpu_index_tuple_cost is 0.0001 +NOTICE: cpu_operator_cost is 0.0025 + +To change them for one session, just use the set command. To make the +changes the permanent default, edit the $PGDATA/postgresql.conf file. + +effective_cache_size tells the planner about how big the kernel's file +level cache is. On my machine it's about 800 meg. It's measured in 8k +blocks, so 100,000 * 8k ~ 800 meg. The smaller this is, the more likely +the database will have to access the hard drive, and therefore the more +likely it will pick a seqscan if the other numbers point to it. + +random_page_cost tells the planner how much more a random page access +costs. The default is 4. Most systems seem to work well with numbers +from 1 to 2. + +lowering the cpu_index_tuple_cost also favors index scans. + + + +From pgsql-bugs-owner@postgresql.org Fri May 30 18:59:43 2003 +X-Original-To: pgsql-bugs@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 47213925D93 + for ; Fri, 30 May 2003 18:59:42 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) with ESMTP id 33532-03 for ; + Fri, 30 May 2003 18:59:40 -0400 (EDT) +Received: from louise.pinerecords.com (louise.pinerecords.com + [213.168.176.16]) + by developer.postgresql.org (Postfix) with ESMTP id 3EC97925D3E + for ; Fri, 30 May 2003 18:59:40 -0400 (EDT) +Received: from louise.pinerecords.com (kala@localhost [127.0.0.1]) + by louise.pinerecords.com with ESMTP id h4UMxdvI024661 + (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); + Sat, 31 May 2003 00:59:39 +0200 +Received: (from kala@localhost) + by louise.pinerecords.com (submit) id h4UMxd45024660; + Sat, 31 May 2003 00:59:39 +0200 +Date: Sat, 31 May 2003 00:59:39 +0200 +From: Tomas Szepe +To: Tom Lane +Cc: pgsql-bugs@postgresql.org +Subject: Re: db growing out of proportion +Message-ID: <20030530225939.GE21944@louise.pinerecords.com> +References: + <8938.1054300299@sss.pgh.pa.us> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: <8938.1054300299@sss.pgh.pa.us> +User-Agent: Mutt/1.4.1i +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/118 +X-Sequence-Number: 6079 + +> [tgl@sss.pgh.pa.us] +> +> Peter Childs writes: +> > On Fri, 30 May 2003, Tomas Szepe wrote: +> >> Trouble is, as the rows in the tables get deleted/inserted/updated +> >> (the frequency being a couple thousand rows per minute), the database +> >> is growing out of proportion in size. +> +> > Would more regular vacuum help. I think a vaccum every hour may do +> > the job. +> +> Also note that no amount of vacuuming will save you if the FSM is not +> large enough to keep track of all the free space. The default FSM +> settings, like all the other default settings in Postgres, are set up +> for a small installation. You'd probably need to raise them by at least +> a factor of 10 for this installation. + +Thanks, I'll try to tweak those settings and will let the list know how +things went. + +-- +Tomas Szepe + +From pgsql-bugs-owner@postgresql.org Fri May 30 19:01:00 2003 +X-Original-To: pgsql-bugs@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 24BF0925D93 + for ; Fri, 30 May 2003 19:00:59 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) with ESMTP id 33049-09 for ; + Fri, 30 May 2003 19:00:58 -0400 (EDT) +Received: from louise.pinerecords.com (louise.pinerecords.com + [213.168.176.16]) + by developer.postgresql.org (Postfix) with ESMTP id B67D0925D3E + for ; Fri, 30 May 2003 19:00:57 -0400 (EDT) +Received: from louise.pinerecords.com (kala@localhost [127.0.0.1]) + by louise.pinerecords.com with ESMTP id h4UN0pvI024706 + (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); + Sat, 31 May 2003 01:00:51 +0200 +Received: (from kala@localhost) + by louise.pinerecords.com (submit) id h4UN0ojI024705; + Sat, 31 May 2003 01:00:50 +0200 +Date: Sat, 31 May 2003 01:00:50 +0200 +From: Tomas Szepe +To: Stephan Szabo +Cc: pgsql-bugs@postgresql.org +Subject: Re: db growing out of proportion +Message-ID: <20030530230050.GF21944@louise.pinerecords.com> +References: <20030530072442.GD14159@louise.pinerecords.com> + <20030530083944.N91707-100000@megazone23.bigpanda.com> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: <20030530083944.N91707-100000@megazone23.bigpanda.com> +User-Agent: Mutt/1.4.1i +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/119 +X-Sequence-Number: 6080 + +> As Tom said, you probably need higher FSM settings, but also, do you have +> any long lived transactions (say from some kind of persistent connection +> system) that might be preventing vacuum from removing rows? + +No, not at all. + +-- +Tomas Szepe + +From pgsql-bugs-owner@postgresql.org Fri May 30 19:08:27 2003 +X-Original-To: pgsql-bugs@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id CF42A925DD8 + for ; Fri, 30 May 2003 19:08:24 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) with ESMTP id 35215-03 for ; + Fri, 30 May 2003 19:08:23 -0400 (EDT) +Received: from louise.pinerecords.com (louise.pinerecords.com + [213.168.176.16]) + by developer.postgresql.org (Postfix) with ESMTP id C329C925D3E + for ; Fri, 30 May 2003 19:08:22 -0400 (EDT) +Received: from louise.pinerecords.com (kala@localhost [127.0.0.1]) + by louise.pinerecords.com with ESMTP id h4UN8MvI024742 + (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); + Sat, 31 May 2003 01:08:22 +0200 +Received: (from kala@localhost) + by louise.pinerecords.com (submit) id h4UN8L3Q024741; + Sat, 31 May 2003 01:08:21 +0200 +Date: Sat, 31 May 2003 01:08:21 +0200 +From: Tomas Szepe +To: Todd Nemanich +Cc: pgsql-bugs@postgresql.org +Subject: Re: db growing out of proportion +Message-ID: <20030530230821.GG21944@louise.pinerecords.com> +References: <20030529163239.GA11101@louise.pinerecords.com> + <3ED769E6.3050300@twopunks.org> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: <3ED769E6.3050300@twopunks.org> +User-Agent: Mutt/1.4.1i +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/120 +X-Sequence-Number: 6081 + +> [todd@twopunks.org] +> +> Additionally, you may want to take a look at your query performance. Are +> most of your queries doing sequential scans? In my system, the crucial +> columns of the primary tables are int8 and float8 fields. I have those +> indexed, and I get a serious performance boost by making sure all +> SELECT/UPDATE/DELETE queries that use those columns in the WHERE have an +> explicit ::int8 or ::float8 (Explain analyze is your friend). During +> peak usage, there is an order of magnitude difference (usually 10 to +> 15x) between queries doing sequential scans on the table, and queries +> doing index scans. Might be worth investigating if your queries are +> taking 5 seconds when your DB is fresh. HTH. + +Yes, I have taken special care to fine-tune all queries on authentic +data. The db setup works as expected in whatever respect with the +exception of query times deterioration that apparently corelates to +the db's on-disk size growth. + +Thanks for your suggestions, + +-- +Tomas Szepe + +From pgsql-general-owner@postgresql.org Fri May 30 22:32:21 2003 +X-Original-To: pgsql-general@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP + id 6CDB9925D3A; Fri, 30 May 2003 22:32:13 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193:10024]) + (amavisd-new) + with ESMTP id 70638-06; Fri, 30 May 2003 22:32:11 -0400 (EDT) +Received: from candle.pha.pa.us (momjian.navpoint.com [207.106.42.251]) + by developer.postgresql.org (Postfix) with ESMTP + id 38778925F02; Fri, 30 May 2003 22:32:03 -0400 (EDT) +Received: (from pgman@localhost) + by candle.pha.pa.us (8.11.6/8.11.6) id h4V2VcV16487; + Fri, 30 May 2003 22:31:38 -0400 (EDT) +From: Bruce Momjian +Message-Id: <200305310231.h4V2VcV16487@candle.pha.pa.us> +Subject: Re: [PERFORM] Yet Another (Simple) Case of Index not used +In-Reply-To: <200304151423.h3FENUf06986@candle.pha.pa.us> +To: Bruce Momjian +Date: Fri, 30 May 2003 22:31:38 -0400 (EDT) +Cc: gearond@cvc.net, Dann Corbit , + Denis , pgsql-performance@postgresql.org, + pgsql-general@postgresql.org, pgsql-sql@postgresql.org +X-Mailer: ELM [version 2.4ME+ PL99 (25)] +MIME-Version: 1.0 +Content-Transfer-Encoding: 7bit +Content-Type: text/plain; charset=US-ASCII +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/1260 +X-Sequence-Number: 42914 + + +Added to TODO: + + * Consider using MVCC to cache count(*) queries with no WHERE + clause + +--------------------------------------------------------------------------- + +Bruce Momjian wrote: +> Dennis Gearon wrote: +> > from mysql manual: +> > ------------------------------------------------------------- +> > "COUNT(*) is optimized to return very quickly if the SELECT retrieves from one +> > table, no other columns are retrieved, and there is no WHERE clause. For example: +> > +> > mysql> select COUNT(*) from student;" +> > ------------------------------------------------------------- +> > +> > A nice little optimization, maybe not possible in a MVCC system. +> +> I think the only thing you can do with MVCC is to cache the value and +> tranaction id for "SELECT AGG(*) FROM tab" and make the cached value +> visible to transaction id's greater than the one that executed the +> query, and invalidate the cache every time the table is modified. +> +> In fact, don't clear the cache, just record the transaction id of the +> table modification command so we can use standard visibility routines to +> make the cache usable as long as possiible. +> +> The cleanest way would probably be to create an aggregate cache system +> table, and to insert into it when someone does an unqualified aggregate, +> and to delete from it when someone modifies the table --- the MVCC tuple +> visibility rules are handled automatically. Queries can look in there +> to see if a visible cached value already exists. Of course, the big +> question is whether this would be a big win, and whether the cost of +> upkeep would justify it. +> +> -- +> Bruce Momjian | http://candle.pha.pa.us +> pgman@candle.pha.pa.us | (610) 359-1001 +> + If your life is a hard drive, | 13 Roberts Road +> + Christ can be your backup. | Newtown Square, Pennsylvania 19073 +> +> +> ---------------------------(end of broadcast)--------------------------- +> TIP 2: you can get off all lists at once with the unregister command +> (send "unregister YourEmailAddressHere" to majordomo@postgresql.org) +> + +-- + Bruce Momjian | http://candle.pha.pa.us + pgman@candle.pha.pa.us | (610) 359-1001 + + If your life is a hard drive, | 13 Roberts Road + + Christ can be your backup. | Newtown Square, Pennsylvania 19073 + +From pgsql-bugs-owner@postgresql.org Fri May 30 23:21:46 2003 +X-Original-To: pgsql-bugs@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 7631692341F + for ; Fri, 30 May 2003 23:21:45 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193]) (amavisd-new, + port 10024) with ESMTP id 51033-06 for ; + Fri, 30 May 2003 23:21:35 -0400 (EDT) +Received: from chaos.mshome.net (unknown [148.64.8.86]) + by developer.postgresql.org (Postfix) with ESMTP id 37CAD923221 + for ; Fri, 30 May 2003 23:21:32 -0400 (EDT) +Received: from localhost.localdomain (thunder.mshome.net [192.168.0.250]) + by localhost.mshome.net (Postfix) with ESMTP id 6D2691C0551 + for ; Fri, 30 May 2003 21:21:24 -0600 (MDT) +Received: from logicalchaos.org (thunder.mshome.net [192.168.0.250]) + by chaos.mshome.net (Postfix) with SMTP id DBD021C0551 + for ; Fri, 30 May 2003 21:21:01 -0600 (MDT) +Date: Fri, 30 May 2003 21:21:01 -0600 +From: Robert Creager +To: pgsql-bugs@postgresql.org +Subject: Re: db growing out of proportion +Message-Id: <20030530212101.37cef86f.Robert_Creager@LogicalChaos.org> +In-Reply-To: <8938.1054300299@sss.pgh.pa.us> +References: + <8938.1054300299@sss.pgh.pa.us> +Organization: Starlight Vision, LLC. +X-Mailer: Sylpheed version 0.8.11claws (GTK+ 1.2.10; i686-pc-linux-gnu) +Mime-Version: 1.0 +Content-Type: multipart/signed; protocol="application/pgp-signature"; + micalg="pgp-sha1"; boundary="=.)Ka4uEls(Ax2_3" +X-Spam-Checker-Version: SpamAssassin 2.53 (1.174.2.15-2003-03-30-exp) +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/121 +X-Sequence-Number: 6082 + +--=.)Ka4uEls(Ax2_3 +Content-Type: text/plain; charset=US-ASCII +Content-Transfer-Encoding: 7bit + +On Fri, 30 May 2003 09:11:39 -0400 +Tom Lane said something like: + +> +> Also note that no amount of vacuuming will save you if the FSM is not +> large enough to keep track of all the free space. The default FSM +> settings, like all the other default settings in Postgres, are set up +> for a small installation. You'd probably need to raise them by at least +> a factor of 10 for this installation. +> + +Tom, + +Thanks for the hint. I just upped my shared_buffers to 8192, fsm_relations to 10000, fsm_pages to 100000, sort_mem to 64000, and an UPDATE which was taking over 2 hours dropped down to 1 to 2 minutes! + +Nice... + +Thanks, +Rob + +--=.)Ka4uEls(Ax2_3 +Content-Type: application/pgp-signature + +-----BEGIN PGP SIGNATURE----- +Version: GnuPG v1.2.1 (GNU/Linux) + +iEYEARECAAYFAj7YH50ACgkQgy51bQc2FFlZ7ACdEVN2enTsN+5ERP759DH4qtEu +ExQAoNVwIXCopBaRq+YOTcK49UhJME0z +=7wj2 +-----END PGP SIGNATURE----- + +--=.)Ka4uEls(Ax2_3-- + + +From pgsql-performance-owner@postgresql.org Fri May 30 23:29:35 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id C683192347C + for ; + Fri, 30 May 2003 23:29:32 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193]) (amavisd-new, + port 10024) + with ESMTP id 52242-07 for ; + Fri, 30 May 2003 23:29:19 -0400 (EDT) +Received: from chaos.mshome.net (unknown [148.64.8.86]) + by developer.postgresql.org (Postfix) with ESMTP id F3B1A92349D + for ; + Fri, 30 May 2003 23:29:10 -0400 (EDT) +Received: from localhost.localdomain (thunder.mshome.net [192.168.0.250]) + by localhost.mshome.net (Postfix) with ESMTP + id B7B631AF38B; Fri, 30 May 2003 21:29:05 -0600 (MDT) +Received: from logicalchaos.org (thunder.mshome.net [192.168.0.250]) + by chaos.mshome.net (Postfix) with SMTP + id E6EC91AF38B; Fri, 30 May 2003 21:28:46 -0600 (MDT) +Date: Fri, 30 May 2003 21:28:46 -0600 +From: Robert Creager +To: "scott.marlowe" +Cc: pgsql-performance +Subject: Re: Enabling and Disabling Sequencial Scan +Message-Id: <20030530212846.26a82109.Robert_Creager@LogicalChaos.org> +In-Reply-To: +References: <3ED7C003.1090303@netscape.net> + +Organization: Starlight Vision, LLC. +X-Mailer: Sylpheed version 0.8.11claws (GTK+ 1.2.10; i686-pc-linux-gnu) +Mime-Version: 1.0 +Content-Type: multipart/signed; protocol="application/pgp-signature"; + micalg="pgp-sha1"; boundary="=.OO0m/UOYQwKF)k" +X-Spam-Checker-Version: SpamAssassin 2.53 (1.174.2.15-2003-03-30-exp) +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/295 +X-Sequence-Number: 2074 + +--=.OO0m/UOYQwKF)k +Content-Type: text/plain; charset=US-ASCII +Content-Transfer-Encoding: 7bit + +On Fri, 30 May 2003 14:46:12 -0600 (MDT) +"scott.marlowe" said something like: + +> +> level cache is. On my machine it's about 800 meg. It's measured in 8k > blocks, so 100,000 * 8k ~ 800 meg. The smaller this is, the more + +Any thoughts on how to figure this out (disk buffer size)? For some reason, my system (2xAMD 2800+, 2Gb RAM 2.4.21 - /proc/meminfo) only shows a usage of 88kb of 'Buffers' usage, and that never changes. My 'Cached' usage is 1.7Gb. I've hit the kernel mailing list, and the one response I got said don't worry about it :-( + +Cheers, +Rob + +-- +O_ + +--=.OO0m/UOYQwKF)k +Content-Type: application/pgp-signature + +-----BEGIN PGP SIGNATURE----- +Version: GnuPG v1.2.1 (GNU/Linux) + +iEYEARECAAYFAj7YIW4ACgkQgy51bQc2FFmgxQCgymRXpBOA8Gi0yN53u+KugaTl +MrQAn2b0oPSs8WzKs18pU1nlAfuz2ijv +=v5nx +-----END PGP SIGNATURE----- + +--=.OO0m/UOYQwKF)k-- + + +From pgsql-bugs-owner@postgresql.org Sat May 31 00:21:26 2003 +X-Original-To: pgsql-bugs@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id A120F9231FA + for ; Sat, 31 May 2003 00:21:24 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193]) (amavisd-new, + port 10024) with ESMTP id 70804-06 for ; + Sat, 31 May 2003 00:21:13 -0400 (EDT) +Received: from sss.pgh.pa.us (unknown [192.204.191.242]) + by developer.postgresql.org (Postfix) with ESMTP id 5B930926052 + for ; Sat, 31 May 2003 00:11:31 -0400 (EDT) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h4V4BRU6017784; + Sat, 31 May 2003 00:11:27 -0400 (EDT) +To: Robert Creager +Cc: pgsql-bugs@postgresql.org +Subject: Re: db growing out of proportion +In-reply-to: <20030530212101.37cef86f.Robert_Creager@LogicalChaos.org> +References: + <8938.1054300299@sss.pgh.pa.us> + <20030530212101.37cef86f.Robert_Creager@LogicalChaos.org> +Comments: In-reply-to Robert Creager + message dated "Fri, 30 May 2003 21:21:01 -0600" +Date: Sat, 31 May 2003 00:11:26 -0400 +Message-ID: <17783.1054354286@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/122 +X-Sequence-Number: 6083 + +Robert Creager writes: +> Thanks for the hint. I just upped my shared_buffers to 8192, fsm_relations to 10000, fsm_pages to 100000, sort_mem to 64000, and an UPDATE which was taking over 2 hours dropped down to 1 to 2 minutes! + +Cool ... but it's not immediately obvious which of these changes did the +trick for you. What settings were you at before? And what's the +details of the problem query? + +The first three settings you mention all seem like reasonable choices, +but I'd be hesitant to recommend 64M sort_mem for general use (it won't +take very many concurrent sorts to drive you into the ground...). So +I'm interested to narrow down exactly what was the issue here. + + regards, tom lane + +From pgsql-bugs-owner@postgresql.org Sat May 31 00:51:00 2003 +X-Original-To: pgsql-bugs@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 812C99234DE + for ; Sat, 31 May 2003 00:50:57 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193]) (amavisd-new, + port 10024) with ESMTP id 86648-02 for ; + Sat, 31 May 2003 00:50:46 -0400 (EDT) +Received: from chaos.mshome.net (unknown [148.64.8.86]) + by developer.postgresql.org (Postfix) with ESMTP id 68804925F16 + for ; Sat, 31 May 2003 00:50:34 -0400 (EDT) +Received: from localhost.localdomain (thunder.mshome.net [192.168.0.250]) + by localhost.mshome.net (Postfix) with ESMTP + id 4437C1C0551; Fri, 30 May 2003 22:50:25 -0600 (MDT) +Received: from logicalchaos.org (thunder.mshome.net [192.168.0.250]) + by chaos.mshome.net (Postfix) with SMTP + id 22EC61C0551; Fri, 30 May 2003 22:50:03 -0600 (MDT) +Date: Fri, 30 May 2003 22:50:02 -0600 +From: Robert Creager +To: Tom Lane +Cc: pgsql-bugs@postgresql.org +Subject: Re: db growing out of proportion +Message-Id: <20030530225002.5750376f.Robert_Creager@LogicalChaos.org> +In-Reply-To: <17783.1054354286@sss.pgh.pa.us> +References: + <8938.1054300299@sss.pgh.pa.us> + <20030530212101.37cef86f.Robert_Creager@LogicalChaos.org> + <17783.1054354286@sss.pgh.pa.us> +Organization: Starlight Vision, LLC. +X-Mailer: Sylpheed version 0.8.11claws (GTK+ 1.2.10; i686-pc-linux-gnu) +Mime-Version: 1.0 +Content-Type: multipart/signed; protocol="application/pgp-signature"; + micalg="pgp-sha1"; boundary="=.mM+T)aNMI5cB+=" +X-Spam-Checker-Version: SpamAssassin 2.53 (1.174.2.15-2003-03-30-exp) +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/123 +X-Sequence-Number: 6084 + +--=.mM+T)aNMI5cB+= +Content-Type: text/plain; charset=US-ASCII +Content-Transfer-Encoding: 7bit + +On Sat, 31 May 2003 00:11:26 -0400 +Tom Lane said something like: +> +> Cool ... but it's not immediately obvious which of these changes did the +> trick for you. What settings were you at before? And what's the +> details of the problem query? +> +> The first three settings you mention all seem like reasonable choices, +> but I'd be hesitant to recommend 64M sort_mem for general use (it won't +> take very many concurrent sorts to drive you into the ground...). So +> I'm interested to narrow down exactly what was the issue here. +> +> regards, tom lane + +shared_buffers was 1024, now 8192 +max_fsm_relations was 1000, now 10000 +max_fsm_pages was 20000, now 100000 +wal_buffers was 8, now 16 +sort_mem was 1024, now 64000 +vacuum_mem was 1024, now 64000 +effective_cache_size was 1000, now 100000 + +I am in the process of reloading the dB, but obs_v and obs_i contain ~750000 records each. I'd be happy to play around with the settings if you would like to see the timing results. I'll also be able to get some explain analyze results tomorrow when finished reloading. Suggestions as to what values to change first? + +There is a 'C' language trigger on the obs_v and obs_i tables which essentially combines the data from the the obs_? tables and updates the catalog table when the obs_? records are updated. + +The query is: + +UPDATE obs_v +SET mag = obs_v.imag + zp.zero_v + cg.color_v * (obs_v.imag - i.imag), + use = true +FROM color_group AS cg, zero_pair AS zp, obs_i AS i, files AS f +WHERE obs_v.star_id = i.star_id + AND obs_v.file_id = f.file_id + AND cg.group_id = f.group_id + AND f.group_id = $group_id + AND zp.pair_id = f.pair_id + +which is called from a perl script (DBD::Pg - which sets $group_id), and the relevant tables are: + + Table "public.obs_v" + Column | Type | Modifiers +---------+---------+------------------------------------------------ + x | real | not null + y | real | not null + imag | real | not null + smag | real | not null + ra | real | not null + dec | real | not null + obs_id | integer | not null default nextval('"obs_id_seq"'::text) + file_id | integer | + use | boolean | default false + solve | boolean | default false + star_id | integer | + mag | real | +Indexes: obs_v_file_id_index btree (file_id), + obs_v_loc_index btree (ra, "dec"), + obs_v_obs_id_index btree (obs_id), + obs_v_star_id_index btree (star_id), + obs_v_use_index btree (use) +Foreign Key constraints: obs_v_files_constraint FOREIGN KEY (file_id) REFERENCES files(file_id) ON UPDATE NO ACTION ON DELETE CASCADE +Triggers: obs_v_trig + +with obs_i being identical (inherited from same root table) + + Table "public.color_group" + Column | Type | Modifiers +----------+---------+----------- + group_id | integer | + color_u | real | default 0 + color_b | real | default 0 + color_v | real | default 0 + color_r | real | default 0 + color_i | real | default 0 +Indexes: color_group_group_id_index btree (group_id) +Foreign Key constraints: $1 FOREIGN KEY (group_id) REFERENCES groups(group_id) ON UPDATE NO ACTION ON DELETE CASCADE + + Table "public.zero_pair" + Column | Type | Modifiers +---------+---------+----------- + pair_id | integer | not null + zero_u | real | default 0 + zero_b | real | default 0 + zero_v | real | default 0 + zero_r | real | default 0 + zero_i | real | default 0 +Indexes: zero_pair_pkey primary key btree (pair_id), + zero_pair_pair_id_index btree (pair_id) +Foreign Key constraints: $1 FOREIGN KEY (pair_id) REFERENCES pairs(pair_id) ON UPDATE NO ACTION ON DELETE CASCADE + + Table "public.files" + Column | Type | Modifiers +----------+--------------------------+------------------------------------------------------- + file_id | integer | not null default nextval('"files_file_id_seq"'::text) + group_id | integer | + pair_id | integer | + date | timestamp with time zone | not null + name | character varying | not null + ra_min | real | default 0 + ra_max | real | default 0 + dec_min | real | default 0 + dec_max | real | default 0 +Indexes: files_pkey primary key btree (file_id), + files_name_key unique btree (name), + files_id_index btree (file_id, group_id, pair_id), + files_range_index btree (ra_min, ra_max, dec_min, dec_max), + imported__file_id_idex btree (file_id) +Foreign Key constraints: $1 FOREIGN KEY (group_id) REFERENCES groups(group_id) ON UPDATE NO ACTION ON DELETE CASCADE, + $2 FOREIGN KEY (pair_id) REFERENCES pairs(pair_id) ON UPDATE NO ACTION ON DELETE CASCADE + + Table "public.catalog" + Column | Type | Modifiers +------------------+------------------+------------------------------------------------- + star_id | integer | not null default nextval('"star_id_seq"'::text) + loc_count | integer | default 0 + ra | real | not null + ra_sum | double precision | default 0 + ra_sigma | real | default 0 + ra_sum_square | double precision | default 0 + dec | real | not null + dec_sum | double precision | default 0 + dec_sigma | real | default 0 + dec_sum_square | double precision | default 0 + mag_u_count | integer | default 0 + mag_u | real | default 99 + mag_u_sum | double precision | default 0 + mag_u_sigma | real | default 0 + mag_u_sum_square | double precision | default 0 + mag_b_count | integer | default 0 + mag_b | real | default 99 + mag_b_sum | double precision | default 0 + mag_b_sigma | real | default 0 + mag_b_sum_square | double precision | default 0 + mag_v_count | integer | default 0 + mag_v | real | default 99 + mag_v_sum | double precision | default 0 + mag_v_sigma | real | default 0 + mag_v_sum_square | double precision | default 0 + mag_r_count | integer | default 0 + mag_r | real | default 99 + mag_r_sum | double precision | default 0 + mag_r_sigma | real | default 0 + mag_r_sum_square | double precision | default 0 + mag_i_count | integer | default 0 + mag_i | real | default 99 + mag_i_sum | double precision | default 0 + mag_i_sigma | real | default 0 + mag_i_sum_square | double precision | default 0 +Indexes: catalog_pkey primary key btree (star_id), + catalog_ra_decl_index btree (ra, "dec"), + catalog_star_id_index btree (star_id) + + + +-- +O_ + +--=.mM+T)aNMI5cB+= +Content-Type: application/pgp-signature + +-----BEGIN PGP SIGNATURE----- +Version: GnuPG v1.2.1 (GNU/Linux) + +iEYEARECAAYFAj7YNHoACgkQgy51bQc2FFl0FQCgxW/5Q1IXyE/0p3ypkF8o59Ek +4/IAn1B0HHGxy0coYVo3SmKHzUhWOhoy +=0IMG +-----END PGP SIGNATURE----- + +--=.mM+T)aNMI5cB+=-- + + +From pgsql-performance-owner@postgresql.org Sat May 31 11:07:30 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 8FECA925D5D + for ; + Sat, 31 May 2003 11:07:29 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193]) (amavisd-new, + port 10024) + with ESMTP id 84593-02 for ; + Sat, 31 May 2003 11:07:19 -0400 (EDT) +Received: from c001.snv.cp.net (h001.c001.snv.cp.net [209.228.32.115]) + by developer.postgresql.org (Postfix) with SMTP id 77A8492339C + for ; + Sat, 31 May 2003 11:07:18 -0400 (EDT) +Received: (cpmta 9722 invoked from network); 31 May 2003 08:07:16 -0700 +Received: from 209.228.32.118 (HELO mail.dilger.cc.criticalpath.net) + by smtp.register-admin.com (209.228.32.115) with SMTP; + 31 May 2003 08:07:16 -0700 +X-Sent: 31 May 2003 15:07:16 GMT +Received: from [216.68.146.219] by mail.dilger.cc with HTTP; + Sat, 31 May 2003 08:07:15 -0700 (PDT) +Content-Type: text/plain; charset=iso-8859-1 +Content-Disposition: inline +Content-Transfer-Encoding: 7bit +MIME-Version: 1.0 +To: yusuf0478@netscape.net +Cc: pgsql-performance@postgresql.org +From: "Nikolaus Dilger" +Subject: Re: Enabling and Disabling Sequencial Scan +X-Sent-From: nikolaus@dilger.cc +Date: Sat, 31 May 2003 08:07:15 -0700 (PDT) +X-Mailer: Web Mail 5.4.0-4_sol28 +Message-Id: + <20030531080716.20944.h004.c001.wm@mail.dilger.cc.criticalpath.net> +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/296 +X-Sequence-Number: 2075 + +David, + +I say go ahead and use it since you get a significant +performance gain. This is a special case where you +know more about your data than the planer does with +general system wide settings. In Oracle you could use +"hints". Since there are no hints in PostgreSQL +disabling and reenabling an option just before and +after a query has the same effect. + +Regards, +Nikolaus + +On Fri, 30 May 2003 16:33:07 -0400, Yusuf wrote: + +> +> In the application, that I'm working on, I have a +query +> that'll be a lot +> 60% faster if I disable sequential scan forcing it to +> you my index. +> +> Is it bad practice to disable sequential scan ( set +> enable_seqscan=false), run my query then enable +> sequential scan, +> whenever I'm running this query? Why? +> +> Thanks in advance +> +> - David Wendy +> +> +> ---------------------------(end of +> broadcast)--------------------------- +> TIP 1: subscribe and unsubscribe commands go to +> majordomo@postgresql.org + +From pgsql-bugs-owner@postgresql.org Sat May 31 12:13:30 2003 +X-Original-To: pgsql-bugs@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 24B7B92600C + for ; Sat, 31 May 2003 12:13:28 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193]) (amavisd-new, + port 10024) with ESMTP id 95002-07 for ; + Sat, 31 May 2003 12:13:17 -0400 (EDT) +Received: from sss.pgh.pa.us (unknown [192.204.191.242]) + by developer.postgresql.org (Postfix) with ESMTP id 30B9C926011 + for ; Sat, 31 May 2003 12:13:17 -0400 (EDT) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h4VGDCU6020749; + Sat, 31 May 2003 12:13:12 -0400 (EDT) +To: Robert Creager +Cc: pgsql-bugs@postgresql.org +Subject: Re: db growing out of proportion +In-reply-to: <20030530225002.5750376f.Robert_Creager@LogicalChaos.org> +References: + <8938.1054300299@sss.pgh.pa.us> + <20030530212101.37cef86f.Robert_Creager@LogicalChaos.org> + <17783.1054354286@sss.pgh.pa.us> + <20030530225002.5750376f.Robert_Creager@LogicalChaos.org> +Comments: In-reply-to Robert Creager + message dated "Fri, 30 May 2003 22:50:02 -0600" +Date: Sat, 31 May 2003 12:13:12 -0400 +Message-ID: <20748.1054397592@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/128 +X-Sequence-Number: 6089 + +Robert Creager writes: +>> I'm interested to narrow down exactly what was the issue here. + +> shared_buffers was 1024, now 8192 +> max_fsm_relations was 1000, now 10000 +> max_fsm_pages was 20000, now 100000 +> wal_buffers was 8, now 16 +> sort_mem was 1024, now 64000 +> vacuum_mem was 1024, now 64000 +> effective_cache_size was 1000, now 100000 + +> The query is: + +> UPDATE obs_v +> SET mag = obs_v.imag + zp.zero_v + cg.color_v * (obs_v.imag - i.imag), +> use = true +> FROM color_group AS cg, zero_pair AS zp, obs_i AS i, files AS f +> WHERE obs_v.star_id = i.star_id +> AND obs_v.file_id = f.file_id +> AND cg.group_id = f.group_id +> AND f.group_id = $group_id +> AND zp.pair_id = f.pair_id + +Hm. My best guess is that the increase in sort_mem allowed this query +to use a more efficient join plan. Perhaps the planner switched from +merge to hash join once it thought the hash table would fit in sort_mem; +or maybe the plan didn't change but the executor was able to keep +everything in memory instead of using temp files. The other changes you +mention seem good as general housekeeping, but I doubt they'd have much +direct effect on this query's speed. It'd be interesting to look at +EXPLAIN ANALYZE results for the same query at several different sort_mem +values. + + regards, tom lane + +From pgsql-performance-owner@postgresql.org Sat May 31 12:27:57 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 9A9B29250AF + for ; + Sat, 31 May 2003 12:27:56 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193]) (amavisd-new, + port 10024) + with ESMTP id 96991-03 for ; + Sat, 31 May 2003 12:27:46 -0400 (EDT) +Received: from TheWorld.com (pcls1.std.com [199.172.62.103]) + by developer.postgresql.org (Postfix) with ESMTP id BF1F592601D + for ; + Sat, 31 May 2003 12:27:45 -0400 (EDT) +Received: from trouble (pool-151-203-197-57.bos.east.verizon.net + [151.203.197.57]) + by TheWorld.com (8.12.8p1/8.12.8) with SMTP id h4VGRhJ8011224 + for ; Sat, 31 May 2003 12:27:43 -0400 +From: "Brian Tarbox" +To: +Subject: why Sequencial Scan when selecting on primary key of table? +Date: Sat, 31 May 2003 12:30:40 -0400 +Message-ID: <004301c32791$f983c710$01000001@trouble> +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit +X-Priority: 3 (Normal) +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) +In-Reply-To: + <20030531080716.20944.h004.c001.wm@mail.dilger.cc.criticalpath.net> +Importance: Normal +X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300 +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/297 +X-Sequence-Number: 2076 + +I have a simple table with a dozen integer fields and a primary key. + +When I say "explain select * from Patient where Patient_primary_key = 100" + +I get sequential scan. + +I've just converted my application from MySQL and am seeing everything run +about 3X slower. What do I have to do to get postgres to use indexes? + +Brian Tarbox + + +From pgsql-performance-owner@postgresql.org Sat May 31 13:02:25 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 8070B926039 + for ; + Sat, 31 May 2003 13:02:23 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193]) (amavisd-new, + port 10024) + with ESMTP id 98943-07 for ; + Sat, 31 May 2003 13:02:12 -0400 (EDT) +Received: from mail.libertyrms.com (unknown [209.167.124.227]) + by developer.postgresql.org (Postfix) with ESMTP id 2CA1F925FF7 + for ; + Sat, 31 May 2003 13:02:10 -0400 (EDT) +Received: from [10.1.2.130] (helo=dba2) + by mail.libertyrms.com with esmtp (Exim 3.22 #3 (Debian)) + id 19M9k9-0002Up-00 + for ; Sat, 31 May 2003 13:02:09 -0400 +Received: by dba2 (Postfix, from userid 1019) + id 452C3D1BB; Sat, 31 May 2003 13:02:08 -0400 (EDT) +Date: Sat, 31 May 2003 13:02:08 -0400 +From: Andrew Sullivan +To: pgsql-performance@postgresql.org +Subject: Re: why Sequencial Scan when selecting on primary key of table? +Message-ID: <20030531170205.GD22469@libertyrms.info> +Mail-Followup-To: Andrew Sullivan , + pgsql-performance@postgresql.org +References: + <20030531080716.20944.h004.c001.wm@mail.dilger.cc.criticalpath.net> + <004301c32791$f983c710$01000001@trouble> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: <004301c32791$f983c710$01000001@trouble> +User-Agent: Mutt/1.5.4i +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/298 +X-Sequence-Number: 2077 + +On Sat, May 31, 2003 at 12:30:40PM -0400, Brian Tarbox wrote: +> I have a simple table with a dozen integer fields and a primary key. +> +> When I say "explain select * from Patient where Patient_primary_key = 100" +> +> I get sequential scan. +> +> I've just converted my application from MySQL and am seeing everything run +> about 3X slower. What do I have to do to get postgres to use indexes? + +Usual questions: have you vacuumed? EXPLAIN ANALYSE output, schema, +&c. + +A + +-- +---- +Andrew Sullivan 204-4141 Yonge Street +Liberty RMS Toronto, Ontario Canada + M2P 2A8 + +1 416 646 3304 x110 + + +From pgsql-performance-owner@postgresql.org Sat May 31 13:14:00 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id AE08E92595B + for ; + Sat, 31 May 2003 13:13:58 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193]) (amavisd-new, + port 10024) + with ESMTP id 06259-09 for ; + Sat, 31 May 2003 13:13:48 -0400 (EDT) +Received: from sss.pgh.pa.us (unknown [192.204.191.242]) + by developer.postgresql.org (Postfix) with ESMTP id EB2D5925953 + for ; + Sat, 31 May 2003 13:13:47 -0400 (EDT) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h4VHDlU6021074; + Sat, 31 May 2003 13:13:47 -0400 (EDT) +To: "Brian Tarbox" +Cc: pgsql-performance@postgresql.org +Subject: Re: why Sequencial Scan when selecting on primary key of table? +In-reply-to: <004301c32791$f983c710$01000001@trouble> +References: <004301c32791$f983c710$01000001@trouble> +Comments: In-reply-to "Brian Tarbox" + message dated "Sat, 31 May 2003 12:30:40 -0400" +Date: Sat, 31 May 2003 13:13:47 -0400 +Message-ID: <21073.1054401227@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/299 +X-Sequence-Number: 2078 + +"Brian Tarbox" writes: +> When I say "explain select * from Patient where Patient_primary_key = 100" +> I get sequential scan. + +Perhaps Patient_primary_key is not an integer field? If not, you need +to cast the constant 100 to the right type. Or write '100' with +single quotes around it, which leaves Postgres to choose the constant's +datatype. (Yeah, I know, it's a pain in the neck. We've had a lot of +discussions about how to fix this without breaking datatype extensibility; +no luck so far.) + + regards, tom lane + +From pgsql-performance-owner@postgresql.org Sat May 31 13:43:20 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 6F76D925FFC + for ; + Sat, 31 May 2003 13:43:19 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193]) (amavisd-new, + port 10024) + with ESMTP id 10565-03 for ; + Sat, 31 May 2003 13:43:08 -0400 (EDT) +Received: from TheWorld.com (pcls2.std.com [199.172.62.104]) + by developer.postgresql.org (Postfix) with ESMTP id BBE2A926023 + for ; + Sat, 31 May 2003 13:43:07 -0400 (EDT) +Received: from trouble (pool-151-203-197-57.bos.east.verizon.net + [151.203.197.57]) + by TheWorld.com (8.12.8p1/8.12.8) with SMTP id h4VHgrRX029921; + Sat, 31 May 2003 13:43:05 -0400 +From: "Brian Tarbox" +To: "Tom Lane" +Cc: +Subject: Re: why Sequencial Scan when selecting on primary key of table? +Date: Sat, 31 May 2003 13:45:50 -0400 +Message-ID: <000001c3279c$79dc2d80$01000001@trouble> +MIME-Version: 1.0 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 7bit +X-Priority: 3 (Normal) +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) +In-Reply-To: <21073.1054401227@sss.pgh.pa.us> +Importance: Normal +X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300 +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/300 +X-Sequence-Number: 2079 + +The primary key field is an integer and I have performed vacuum analyse but +that does not seem to change anything. + +I've also heard that postgres will not indexes when JOINing tables. Can +that really be true?? + +Brian + + +-----Original Message----- +From: pgsql-performance-owner@postgresql.org +[mailto:pgsql-performance-owner@postgresql.org]On Behalf Of Tom Lane +Sent: Saturday, May 31, 2003 1:14 PM +To: Brian Tarbox +Cc: pgsql-performance@postgresql.org +Subject: Re: [PERFORM] why Sequencial Scan when selecting on primary key +of table? + + +"Brian Tarbox" writes: +> When I say "explain select * from Patient where Patient_primary_key = 100" +> I get sequential scan. + +Perhaps Patient_primary_key is not an integer field? If not, you need +to cast the constant 100 to the right type. Or write '100' with +single quotes around it, which leaves Postgres to choose the constant's +datatype. (Yeah, I know, it's a pain in the neck. We've had a lot of +discussions about how to fix this without breaking datatype extensibility; +no luck so far.) + + regards, tom lane + +---------------------------(end of broadcast)--------------------------- +TIP 6: Have you searched our list archives? + +http://archives.postgresql.org + + +From pgsql-performance-owner@postgresql.org Sat May 31 13:51:21 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 1BD39926028 + for ; + Sat, 31 May 2003 13:51:20 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193]) (amavisd-new, + port 10024) + with ESMTP id 11175-07 for ; + Sat, 31 May 2003 13:51:09 -0400 (EDT) +Received: from simmts2-srv.bellnexxia.net (simmts2.bellnexxia.net + [206.47.199.11]) + by developer.postgresql.org (Postfix) with ESMTP id 30889926020 + for ; + Sat, 31 May 2003 13:51:09 -0400 (EDT) +Received: from [192.168.1.200] ([64.231.215.231]) by + simmts2-srv.bellnexxia.net + (InterMail vM.5.01.05.32 201-253-122-126-132-20030307) with ESMTP id + <20030531175107.PKFC26980.simmts2-srv.bellnexxia.net@[192.168.1.200]>; + Sat, 31 May 2003 13:51:07 -0400 +Subject: Re: why Sequencial Scan when selecting on primary key of table? +From: Rod Taylor +To: Tom Lane +Cc: Brian Tarbox , + Postgresql Performance +In-Reply-To: <21073.1054401227@sss.pgh.pa.us> +References: <004301c32791$f983c710$01000001@trouble> + <21073.1054401227@sss.pgh.pa.us> +Content-Type: multipart/signed; micalg=pgp-sha1; + protocol="application/pgp-signature"; + boundary="=-KM+mrr7aYKiWLenALY1p" +Organization: +Message-Id: <1054403470.11968.34.camel@jester> +Mime-Version: 1.0 +X-Mailer: Ximian Evolution 1.2.4 +Date: 31 May 2003 13:51:11 -0400 +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/301 +X-Sequence-Number: 2080 + +--=-KM+mrr7aYKiWLenALY1p +Content-Type: text/plain +Content-Transfer-Encoding: quoted-printable + +On Sat, 2003-05-31 at 13:13, Tom Lane wrote: +> "Brian Tarbox" writes: +> > When I say "explain select * from Patient where Patient_primary_key =3D= + 100" +> > I get sequential scan. +>=20 +> Perhaps Patient_primary_key is not an integer field? If not, you need +> to cast the constant 100 to the right type. Or write '100' with +> single quotes around it, which leaves Postgres to choose the constant's +> datatype. + +Out of curiosity, why don't we confirm the unquoted value is an integer, +numeric, etc, then change it into type 'unknown'? From that point +forward it would be treated like it's quoted counterpart. + +Is this noticeably slower or am I missing something? + +--=20 +Rod Taylor + +PGP Key: http://www.rbt.ca/rbtpub.asc + +--=-KM+mrr7aYKiWLenALY1p +Content-Type: application/pgp-signature; name=signature.asc +Content-Description: This is a digitally signed message part + +-----BEGIN PGP SIGNATURE----- +Version: GnuPG v1.2.2 (FreeBSD) + +iD8DBQA+2OuO6DETLow6vwwRAkOnAKCFHPr4ikuBchuPZHEMogTroKkz+wCbBTxK +KWliKG4CQkAjbOePbRpo85s= +=TFCz +-----END PGP SIGNATURE----- + +--=-KM+mrr7aYKiWLenALY1p-- + + +From pgsql-performance-owner@postgresql.org Sat May 31 13:55:14 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id EFCF492602B + for ; + Sat, 31 May 2003 13:55:12 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193]) (amavisd-new, + port 10024) + with ESMTP id 11175-10 for ; + Sat, 31 May 2003 13:55:02 -0400 (EDT) +Received: from sss.pgh.pa.us (unknown [192.204.191.242]) + by developer.postgresql.org (Postfix) with ESMTP id 21722926034 + for ; + Sat, 31 May 2003 13:55:02 -0400 (EDT) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h4VHt1U6021290; + Sat, 31 May 2003 13:55:01 -0400 (EDT) +To: "Brian Tarbox" +Cc: pgsql-performance@postgresql.org +Subject: Re: why Sequencial Scan when selecting on primary key of table? +In-reply-to: <000001c3279c$79dc2d80$01000001@trouble> +References: <000001c3279c$79dc2d80$01000001@trouble> +Comments: In-reply-to "Brian Tarbox" + message dated "Sat, 31 May 2003 13:45:50 -0400" +Date: Sat, 31 May 2003 13:55:01 -0400 +Message-ID: <21289.1054403701@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/302 +X-Sequence-Number: 2081 + +"Brian Tarbox" writes: +> The primary key field is an integer and I have performed vacuum analyse but +> that does not seem to change anything. + +Hm. So how big is the table, exactly? On small tables a seqscan will +be preferred because the extra I/O to examine the index costs more than +the CPU to examine all the tuples on a disk page. + +> I've also heard that postgres will not indexes when JOINing tables. Can +> that really be true?? + +We have some join methods that like indexes and we have some that find +no benefit in 'em. Again, testing on toy-size tables is not a good +guide to what will happen on larger tables. + + regards, tom lane + +From pgsql-performance-owner@postgresql.org Sat May 31 14:02:49 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id CCCBB926035 + for ; + Sat, 31 May 2003 14:02:46 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193]) (amavisd-new, + port 10024) + with ESMTP id 12824-10 for ; + Sat, 31 May 2003 14:02:36 -0400 (EDT) +Received: from mail.libertyrms.com (unknown [209.167.124.227]) + by developer.postgresql.org (Postfix) with ESMTP id 1B157926020 + for ; + Sat, 31 May 2003 14:02:36 -0400 (EDT) +Received: from [10.1.2.130] (helo=dba2) + by mail.libertyrms.com with esmtp (Exim 3.22 #3 (Debian)) + id 19MAgd-0002tb-00 + for ; Sat, 31 May 2003 14:02:35 -0400 +Received: by dba2 (Postfix, from userid 1019) + id 756E0D1BB; Sat, 31 May 2003 14:02:35 -0400 (EDT) +Date: Sat, 31 May 2003 14:02:35 -0400 +From: Andrew Sullivan +To: pgsql-performance@postgresql.org +Subject: Re: why Sequencial Scan when selecting on primary key of table? +Message-ID: <20030531180235.GF22469@libertyrms.info> +Mail-Followup-To: Andrew Sullivan , + pgsql-performance@postgresql.org +References: <21073.1054401227@sss.pgh.pa.us> + <000001c3279c$79dc2d80$01000001@trouble> +Mime-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: <000001c3279c$79dc2d80$01000001@trouble> +User-Agent: Mutt/1.5.4i +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/303 +X-Sequence-Number: 2082 + +On Sat, May 31, 2003 at 01:45:50PM -0400, Brian Tarbox wrote: +> The primary key field is an integer and I have performed vacuum analyse but +> that does not seem to change anything. + +int4? int8? int2? Makes a difference. Please post the results of +EXPLAIN ANALYSE on the query you're having trouble with, and someone +may be able to help you. (You'll need to show us the table, too.) + +> I've also heard that postgres will not indexes when JOINing tables. Can +> that really be true?? + +No. + +A + +-- +---- +Andrew Sullivan 204-4141 Yonge Street +Liberty RMS Toronto, Ontario Canada + M2P 2A8 + +1 416 646 3304 x110 + + +From pgsql-performance-owner@postgresql.org Sat May 31 14:12:42 2003 +X-Original-To: pgsql-performance@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 55458926035 + for ; + Sat, 31 May 2003 14:12:42 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193]) (amavisd-new, + port 10024) + with ESMTP id 15024-06 for ; + Sat, 31 May 2003 14:12:31 -0400 (EDT) +Received: from sss.pgh.pa.us (unknown [192.204.191.242]) + by developer.postgresql.org (Postfix) with ESMTP id 9B113926043 + for ; + Sat, 31 May 2003 14:12:31 -0400 (EDT) +Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) + by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h4VICUU6021407; + Sat, 31 May 2003 14:12:31 -0400 (EDT) +To: Rod Taylor +Cc: Brian Tarbox , + Postgresql Performance +Subject: Re: why Sequencial Scan when selecting on primary key of table? +In-reply-to: <1054403470.11968.34.camel@jester> +References: <004301c32791$f983c710$01000001@trouble> + <21073.1054401227@sss.pgh.pa.us> <1054403470.11968.34.camel@jester> +Comments: In-reply-to Rod Taylor + message dated "31 May 2003 13:51:11 -0400" +Date: Sat, 31 May 2003 14:12:30 -0400 +Message-ID: <21406.1054404750@sss.pgh.pa.us> +From: Tom Lane +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/304 +X-Sequence-Number: 2083 + +Rod Taylor writes: +> Out of curiosity, why don't we confirm the unquoted value is an integer, +> numeric, etc, then change it into type 'unknown'? + +UNKNOWNNUMERIC is one of the ideas that's been proposed, but it's not +clear to me that it is better than other alternatives. In particular, +I don't like losing knowledge of the form and size of the constant. +Something like "WHERE int4col = 4.8" should yield FALSE, not "ERROR: +pg_atoi: unable to parse '4.8'" which is what you're likely to get with +a naive "unknown numeric type" approach. A perhaps-more-realistic +objection is that it only solves the problem for trivial "var = const" +cases. As soon as you look at even slightly more complicated +expressions, it stops doing much good. + +I'm still of the opinion that the best solution in the long run is to +get rid of most of the cross-datatype numeric operators, but there are +pitfalls there too. See last thread on the issue: +http://archives.postgresql.org/pgsql-hackers/2002-11/msg00468.php + + regards, tom lane + +From pgsql-bugs-owner@postgresql.org Sat May 31 21:53:57 2003 +X-Original-To: pgsql-bugs@postgresql.org +Received: from localhost (developer.postgresql.org [64.117.224.193]) + by developer.postgresql.org (Postfix) with ESMTP id 4CD9F926095 + for ; Sat, 31 May 2003 21:53:57 -0400 (EDT) +Received: from developer.postgresql.org ([64.117.224.193]) + by localhost (developer.postgresql.org [64.117.224.193]) (amavisd-new, + port 10024) with ESMTP id 74922-08 for ; + Sat, 31 May 2003 21:53:46 -0400 (EDT) +Received: from mail.quantium.net (b.ns.quantium.net [67.96.140.30]) + by developer.postgresql.org (Postfix) with SMTP id DCE0592604B + for ; Sat, 31 May 2003 21:53:44 -0400 (EDT) +Received: (qmail 31599 invoked from network); 31 May 2003 22:56:44 -0000 +Received: from 27-pool1.ras10.coden-le3.alerondial.net (HELO dave.to) + (206.149.128.27) + by quantium.net with SMTP; 31 May 2003 22:56:44 -0000 +Message-ID: <3ED93338.80806@dave.to> +Date: Sat, 31 May 2003 16:56:56 -0600 +From: Dave E Martin XXIII +User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; + rv:1.0.0) Gecko/20020623 Debian/1.0.0-0.woody.1 +X-Accept-Language: en +MIME-Version: 1.0 +To: pgsql-bugs@postgresql.org +Subject: Re: Index speeds up one row table (why)? +Content-Type: text/plain; charset=us-ascii; format=flowed +Content-Transfer-Encoding: 7bit +X-Virus-Scanned: by amavisd-new +X-Archive-Number: 200305/130 +X-Sequence-Number: 6091 + +Tom Lane Writes: + +>Bruno Wolff III writes: +>> It probably has one visible row in it. If it can changed a lot, there +>> may be lots of deleted tuples in a row. That would explain why an +>> index scan speeds things up. + +>Right, every UPDATE on unique_ids generates a dead row, and a seqscan +>has no alternative but to wade through them all. When a unique index is +>present, the indexscan code knows that after it's fetched one live tuple +... +>More-frequent vacuums would be a much more reliable solution, + + +The index I created wasn't unique (though it should have been), but +perhaps much of the same reasoning still applies. + +Also, I could have swore I tried a vacuum, and it didn't make a +difference, although experimenting just now, it did. The data collection +rate is considerably slower at the moment though, so perhaps last time +the table simply quickly got "inefficient" very quickly again +during/immediately after the vacuum (or I wasn't where I thought I was +when I vacuumed). I'll have to experiment with this a bit more, when the +data generation is high again. + +(ok, experimented a bit more just now) +Hm, it appears that degredation occurs with the index as well, I guess +at the time I created the index, it just initially did better because it +got to skip all the already dead rows at creation time: but this is +disturbing, I do a vacuum, and the access times are better, but still +horrible: + +explain analyze select next_id from bigint_unique_ids where +table_name='CONNECTION_DATA'; + + Index Scan using bigint_unique_ids__table_name on bigint_unique_ids +(cost=0.00..8.01 rows=1 width=8) (actual time=13.77..844.14 rows=1 loops=1) + Index Cond: (table_name = 'CONNECTION_DATA'::text) + Total runtime: 844.36 msec +(3 rows) + +vacuum; -- takes about 10 minutes +VACUUM + +explain analyze select next_id from bigint_unique_ids where +table_name='CONNECTION_DATA'; +Index Scan using bigint_unique_ids__table_name on bigint_unique_ids +(cost=0.00..84.01 rows=1 width=8) (actual time=0.17..99.94 rows=1 loops=1) + Index Cond: (table_name = 'CONNECTION_DATA'::text) + Total runtime: 100.09 msec + +vacuum; --takes about 2 minutes +Index Scan using bigint_unique_ids__table_name on bigint_unique_ids +(cost=0.00..179.01 rows=1 width=8) (actual time=0.45..219.05 rows=1 loops=1) + Index Cond: (table_name = 'CONNECTION_DATA'::text) + Total runtime: 219.20 msec + +--ACK, worse, ran twice more, got 212.5 ms, and 394.39 + +vacuum bigint_unique_ids; -- try specific table only, takes about 5 seconds +Index Scan using bigint_unique_ids__table_name on bigint_unique_ids +(cost=0.00..163.01 rows=1 width=8) (actual time=0.23..143.59 rows=1 loops=1) + Index Cond: (table_name = 'CONNECTION_DATA'::text) + Total runtime: 143.72 msec + +vacuum full bigint_unique_ids; -- try full, takes about 3 seconds. +Seq Scan on bigint_unique_ids (cost=0.00..1.02 rows=1 width=8) (actual +time=0.10..0.10 rows=1 loops=1) + Filter: (table_name = 'CONNECTION_DATA'::text) + Total runtime: 0.25 msec + +-- ah, much much much, better. + +So apparently vacuum by itself isn't going to be sufficent, i'm going to +need vacuum fulls? Or if I do vacuum's often enough (that should allow +old rows to be overwritten?) will that do it? I'm a bit hazy on why +vacuum isn't doing just as well as vacuum full, I thought the only +difference was that full released space back to the operating system +(and presumably defragments existing data, but for one row, this +shouldn't matter?). + +wait several minutes: + +Seq Scan on bigint_unique_ids (cost=0.00..39.01 rows=1 width=8) (actual +time=2.97..2.98 rows=1 loops=1) + Filter: (table_name = 'CONNECTION_DATA'::text) + Total runtime: 3.13 msec +reindex index bigint_unique_ids__table_name; +REINDEX + +Index Scan using bigint_unique_ids__table_name on bigint_unique_ids +(cost=0.00..5.97 rows=1 width=8) (actual time=0.11..0.20 rows=1 loops=1) + Index Cond: (table_name = 'CONNECTION_DATA'::text) + Total runtime: 0.30 msec + +It appears reindex has the same speed up effect. (and in this case made +it switch back from seq_scan to index scan). + +Let me throw in this too, if its helpful: + +vacuum verbose bigint_unique_ids; +INFO: --Relation public.bigint_unique_ids-- +INFO: Index bigint_unique_ids__table_name: Pages 29; Tuples 1: Deleted +5354. + CPU 0.01s/0.04u sec elapsed 0.05 sec. +INFO: Removed 11348 tuples in 79 pages. + CPU 0.00s/0.02u sec elapsed 0.02 sec. +INFO: Pages 79: Changed 1, Empty 0; Tup 1: Vac 11348, Keep 0, UnUsed 0. + Total CPU 0.03s/0.06u sec elapsed 0.14 sec. +INFO: --Relation pg_toast.pg_toast_21592-- +INFO: Pages 0: Changed 0, Empty 0; Tup 0: Vac 0, Keep 0, UnUsed 0. + Total CPU 0.00s/0.00u sec elapsed 0.00 sec. +VACUUM + +vacuum full verbose bigint_unique_ids; +INFO: --Relation public.bigint_unique_ids-- +INFO: Pages 79: Changed 1, reaped 79, Empty 0, New 0; Tup 1: Vac 297, +Keep/VTL 0/0, UnUsed 11157, MinLen 52, MaxLen 52; Re-using: Free/Avail. +Space 599716/22724; EndEmpty/Avail. Pages 76/3. + CPU 0.01s/0.00u sec elapsed 0.01 sec. +INFO: Index bigint_unique_ids__table_name: Pages 29; Tuples 1: Deleted 297. + CPU 0.00s/0.00u sec elapsed 0.00 sec. +INFO: Rel bigint_unique_ids: Pages: 79 --> 1; Tuple(s) moved: 1. + CPU 0.00s/0.00u sec elapsed 0.02 sec. +INFO: Index bigint_unique_ids__table_name: Pages 29; Tuples 1: Deleted 1. + CPU 0.00s/0.00u sec elapsed 0.00 sec. +INFO: --Relation pg_toast.pg_toast_21592-- +INFO: Pages 0: Changed 0, reaped 0, Empty 0, New 0; Tup 0: Vac 0, +Keep/VTL 0/0, UnUsed 0, MinLen 0, MaxLen 0; Re-using: Free/Avail. Space +0/0; EndEmpty/Avail. Pages 0/0. + CPU 0.00s/0.00u sec elapsed 0.00 sec. +INFO: Index pg_toast_21592_index: Pages 1; Tuples 0. + CPU 0.00s/0.00u sec elapsed 0.01 sec. +VACUUM + + +