Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id A41A59FA5D8 for ; Thu, 19 Oct 2006 14:32:42 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 11574-07 for ; Thu, 19 Oct 2006 14:32:25 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.168]) by postgresql.org (Postfix) with ESMTP id 4F57C9FB21F for ; Thu, 19 Oct 2006 14:32:24 -0300 (ADT) Received: by ug-out-1314.google.com with SMTP id 30so457995ugc for ; Thu, 19 Oct 2006 10:32:22 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=UuyXyuU8qlKIQJH638Fwk0pnd8VHP2MZ5HjYWxHUMVo08/CMQhAS6GbyVkBOfpoSUavVBbX98szYQRWqsD1BY5VFYUuo7X3q4vaeABqXQ04jNm0mybpGCy3iL8YBpQCVr5KUu2SU1ydKT1WXgFuCObkzA6bgB3iB7/l3QyUzLSY= Received: by 10.78.204.7 with SMTP id b7mr341421hug; Thu, 19 Oct 2006 10:32:22 -0700 (PDT) Received: by 10.78.35.18 with HTTP; Thu, 19 Oct 2006 10:32:22 -0700 (PDT) Message-ID: Date: Thu, 19 Oct 2006 13:32:22 -0400 From: "Merlin Moncure" To: "Jens Schipkowski" Subject: Re: DB Performance decreases due to often written/accessed table Cc: pgsql-performance@postgresql.org In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.118 tagged_above=0 required=5 tests=AWL, SPF_PASS X-Spam-Level: X-Archive-Number: 200610/416 X-Sequence-Number: 21545 On 10/19/06, Jens Schipkowski wrote: > // select finds out which one has not an twin > // a twin is defined as record with the same attr* values > // decreases speed over time until timeout by postgresql > SELECT * > FROM tbl_reg reg > WHERE register <> loc1 AND > idreg NOT IN > ( > SELECT reg.idreg > FROM tbl_reg reg, tbl_reg regtwin > WHERE regtwin.register = 1 AND > regtwin.type <> 20 AND > reg.attr1 = regtwin.attr1 AND > reg.attr2 = regtwin.attr2 AND > reg.attr3 = regtwin.attr3 AND > reg.attr4 = regtwin.attr4 AND > reg.attr5 = regtwin.attr5 AND > reg.attr6 = regtwin.attr6 AND > reg.idreg <> regtwin.idreg AND > reg.register = 2 > ); [...] > We have the problem, that we cannot see any potential to improve SQL > statements. Indexing the attr* columns seems not to be an solution, > because the data mustn't be unique (twins) and changes really often so > reindexing will took too long. 1. your database design is the real culprit here. If you want things to run really quickly, solve the problem there by normalizing your schema. denomalization is the root cause of many, many, problems posted here on this list. 2. barring that, the above query will run fastest by creating multi-column indexes on regtwin (attr*) fields. and reg(attr*). the real solution to problems like this is often proper idnexing, especially multi column. saying indexes take to long to build is like saying: 'i have a problem, so i am going to replace it with a much worse problem'. 3. try where exists/not exists instead of where in/not in merlin