Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 2A50C9FB285 for ; Thu, 19 Oct 2006 15:34:16 -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 33851-02 for ; Thu, 19 Oct 2006 15:34:08 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 8C6349FB264 for ; Thu, 19 Oct 2006 15:34:07 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.3 Received: from mx.inode.at (lb01nat05.inode.at [62.99.145.5]) by svr4.postgresql.org (Postfix) with ESMTP id 1D4A65AF882 for ; Thu, 19 Oct 2006 18:34:02 +0000 (GMT) Received: from [83.64.182.18] (port=15892 helo=panettone.apus.local) by smartmx-05.inode.at with esmtp (Exim 4.50) id 1GaciM-0002is-UE; Thu, 19 Oct 2006 20:33:58 +0200 Received: from xjens.apus.local ([193.1.1.148]) by panettone.apus.local with esmtp (Exim 3.35 #1 (Debian)) id 1GaciM-0007kX-00; Thu, 19 Oct 2006 20:33:58 +0200 Date: Thu, 19 Oct 2006 20:34:00 +0200 To: "Merlin Moncure" Subject: Re: DB Performance decreases due to often written/accessed table From: "Jens Schipkowski" Organization: APUS Software GmbH Cc: pgsql-performance@postgresql.org Content-Type: text/plain; format=flowed; delsp=yes; charset=utf-8 MIME-Version: 1.0 References: Content-Transfer-Encoding: Quoted-Printable Message-ID: In-Reply-To: User-Agent: Opera Mail/9.02 (Linux) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.135 tagged_above=0 required=5 tests=FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200610/418 X-Sequence-Number: 21547 On Thu, 19 Oct 2006 19:32:22 +0200, Merlin Moncure = = wrote: > 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 =3D 1 AND >> regtwin.type <> 20 AND >> reg.attr1 =3D regtwin.attr1 AND >> reg.attr2 =3D regtwin.attr2 AND >> reg.attr3 =3D regtwin.attr3 AND >> reg.attr4 =3D regtwin.attr4 AND >> reg.attr5 =3D regtwin.attr5 AND >> reg.attr6 =3D regtwin.attr6 AND >> reg.idreg <> regtwin.idreg AND >> reg.register =3D 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 s= o >> 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. Believe it is normalized. We also seperated configuration and runtime = data. And this is a runtime table. This table holds short living data for devices to be registered by a = registration server. The INSERTs are triggered by external devices. The = = master data tables are perfectly normalized too. What you are seeing is = = not the real column names. I changed it due to readability. attr* have = really different names and meanings. A "twin" (in real, initiator/member= = of the same conferencing group) is defined by these attributes. Due to = high flexibility of this system (serverside configuration/ deviceside = configuration for runtime) there is no other way to normalize. > 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'. I will index it. Just prepared the test and will run it tomorrow. > 3. try where exists/not exists instead of where in/not in Did try it, before I switched to NOT IN. It was 10 times slower. > > merlin