Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 25BF29FBB73 for ; Thu, 15 Feb 2007 10:06:38 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-new, port 10024) with ESMTP id 29471-01 for ; Thu, 15 Feb 2007 10:06:34 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75]) by postgresql.org (Postfix) with ESMTP id A99789FBB87 for ; Thu, 15 Feb 2007 10:06:33 -0400 (AST) Received: from server3.office.archonet.com (84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99]) by smtp.metronet.co.uk (MetroNet Mail) with ESMTP id B5AEA75A77; Thu, 15 Feb 2007 14:01:59 +0000 (GMT) Received: from [192.168.1.36] (dell36.office.archonet.com [192.168.1.36]) by server3.office.archonet.com (Postfix) with ESMTP id 389AA274164; Thu, 15 Feb 2007 14:01:56 +0000 (GMT) Message-ID: <45D467C6.5090501@archonet.com> Date: Thu, 15 Feb 2007 14:01:42 +0000 From: Richard Huxton User-Agent: IceDove 1.5.0.9 (X11/20061220) MIME-Version: 1.0 To: Konstantinos Krikellas Cc: pgsql-performance@postgresql.org, Stratis Viglas Subject: Re: Problem with joining queries. References: <1171544313.31678.22.camel@kkrik-desktop> In-Reply-To: <1171544313.31678.22.camel@kkrik-desktop> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.212 tagged_above=0 required=5 tests=AWL, BAYES_50, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200702/167 X-Sequence-Number: 23221 Konstantinos Krikellas wrote: > Hi, > > I am using PostgreSQL for benchmarking and I study the following query: > > SELECT * > FROM k10_1, k10_2, k10_3, k10_4, k10_5 > WHERE k10_1.times4 = k10_2.times4 > AND k10_2.times4 = k10_3.times4 > AND k10_3.times4 = k10_4.times4 > AND k10_4.times4 = k10_5.times4 > Each table has 10000 tuples of 72 bytes each (constant). The field That's 72 bytes plus about 24 for each row header. Plus 4 bytes for the text length, and you can't assume each character is only one byte if you're using UTF-8 or similar. > times4 in every table is valued in [0,2500), each value appearing > exactly four times but in random order. It is easy to extract that the > result has exactly 2,560,000 tuples or approximate size 185 MB. The > database has been 'VACUUM FULL'-ed and is static. > > When I execute this query with EXPLAIN ANALYSE, the query is executed in > 10-20 sec and consumes only 8Mb of memory, depending to the machine (I > have tried it on P4-2.0GHz, P4-2.2GHz and Athlon 4200++ 64x2, all with 2 > Gb RAM and Linux OS, Ubuntu Edgy or Fedora 6). However, when I execute > exactly the same query normally and direct the output to /dev/null, > PostgreSQL consumes all the available memory (RAM and swap), and the > query cannot be executed, as I receive the message 'Out of memory'. The > same thing happened to all the machines. I have tried to adjust working > memory and shared buffers but it still performed in the same way. Not happening here (8.2.x, output redirected using "\o /dev/null") - are you sure it's not psql (or whatever client) that's using up your memory, as it tries to build the entire result set before sending it to /dev/null? Don't forget, you've got 5 copies of the columns so that would be ~ 700MB. If it is the backend, you'll need to give some of the tuning parameters you're using, since it works here on my much smaller dev server (1GB RAM and plenty of other stuff using it). -- Richard Huxton Archonet Ltd