Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id BDC286504BB for ; Sun, 23 Nov 2008 03:21:04 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 53063-05 for ; Sun, 23 Nov 2008 03:21:01 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from 27.mail-out.ovh.net (27.mail-out.ovh.net [91.121.30.210]) by mail.postgresql.org (Postfix) with SMTP id 0B579650495 for ; Sun, 23 Nov 2008 03:21:00 -0400 (AST) Received: (qmail 8301 invoked by uid 503); 23 Nov 2008 00:42:58 -0000 Received: from b7.ovh.net (HELO mail177.ha.ovh.net) (213.186.33.57) by 27.mail-out.ovh.net with SMTP; 23 Nov 2008 00:42:58 -0000 Received: from b0.ovh.net (HELO queue-out) (213.186.33.50) by b0.ovh.net with SMTP; 22 Nov 2008 23:23:59 -0000 Received: from par69-8-88-161-102-87.fbx.proxad.net (HELO soyouz) (88.161.102.87) by ns0.ovh.net with SMTP; 22 Nov 2008 23:23:58 -0000 Date: Sun, 23 Nov 2008 00:24:52 +0100 To: Andrus Subject: Re: Hash join on int takes 8..114 seconds From: PFC Cc: pgsql-performance@postgresql.org Content-Type: text/plain; format=flowed; delsp=yes; charset=utf-8 MIME-Version: 1.0 References: <49253FE1.3070706@archonet.com> <0205611B528C4C2CBA99AFC64E57D6E8@andrusnotebook> <75A918DFCF25470FAF96B3FE3D25A38B@andrusnotebook> Content-Transfer-Encoding: 7bit Message-ID: In-Reply-To: User-Agent: Opera Mail/9.62 (Linux) X-Ovh-Tracer-Id: 10704493364319684230 X-Ovh-Remote: 88.161.102.87 (par69-8-88-161-102-87.fbx.proxad.net) X-Ovh-Local: 213.186.33.20 (ns0.ovh.net) X-Spam-Check: DONE|H 0.500114/N X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200811/212 X-Sequence-Number: 31943 > Thank you very much for great sample. > I tried to create testcase from this to match production db: > > 1.2 million orders > 3.5 million order details > 13400 products with char(20) as primary keys containing ean-13 codes > mostly > 3 last year data > every order has usually 1..3 detail lines > same product can appear multiple times in order > products are queried by start of code > > This sample does not distribute products randomly between orders. > How to change this so that every order contains 3 (or 1..6 ) random > products? > I tried to use random row sample from > http://www.pgsql.cz/index.php/PostgreSQL_SQL_Tricks-i > > but in this case constant product is returned always. It seems than > query containing randon() is executed only once. You could try writing a plpgsql function which would generate the data set. Or you could use your existing data set. By the way, a simple way to de-bloat your big table without blocking would be this : - stop all inserts and updates - begin - create table new like old table - insert into new select * from old (order by perhaps) - create indexes - rename new into old - commit If this is just a reporting database where you insert a batch of new data every day, for instance, that's very easy to do. If it's OLTP, then, no.