X-Original-To: pgsql-performance-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 3EC119FA65C for ; Wed, 21 Jun 2006 15:48:18 -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 36362-03 for ; Wed, 21 Jun 2006 15:48:07 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from noel.decibel.org (noel.decibel.org [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id 7F0FC9F9CC1 for ; Wed, 21 Jun 2006 15:48:06 -0300 (ADT) Received: by noel.decibel.org (Postfix, from userid 1001) id 41AAB56482; Wed, 21 Jun 2006 13:48:04 -0500 (CDT) Received: (hashcash-sendmail, from uid 1001); Wed, 21 Jun 2006 13:48:03 -0500 Date: Wed, 21 Jun 2006 13:48:03 -0500 From: "Jim C. Nasby" To: nicky Cc: pgsql-performance@postgresql.org Subject: Re: Speeding up query, Joining 55mil and 43mil records. Message-ID: <20060621184803.GC93655@pervasive.com> References: <44994DE7.5070801@valuecare.nl> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <44994DE7.5070801@valuecare.nl> X-Operating-System: FreeBSD 6.0-RELEASE-p4 amd64 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.11 X-Hashcash: 1:20:060621:nicky@valuecare.nl::3Rw0ynAfVznpJun1:0000000000000000000 0000000000000000000000002OP9 X-Hashcash: 1:20:060621:pgsql-performance@postgresql.org::HsYnSw5oRY4Za+B8:00000 0000000000000000000000001oRh X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200606/413 X-Sequence-Number: 19770 On Wed, Jun 21, 2006 at 03:47:19PM +0200, nicky wrote: > WHERE substr(t0.code,1,2) not in ('14','15','16','17') > AND (substr(t0.correctie,4,1) <> '1' OR t0.correctie is null) > AND EXTRACT(YEAR from t1.datum) > 2004; How much data do you expect to be getting back from that where clause? Unless you plan on inserting most of the table, some well-placed indexes would probably help, and fixing the datum portion might as well (depending on how far back the data goes). Specifically: CREATE INDEX t0_code_partial ON t0(substr(code,1,2)); (yeah, I know t0 is an alias, but I already snipped the table name) and AND t1.datum >= '1/1/2005' (might need to cast that to a date or whatever). -- Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com Pervasive Software http://pervasive.com work: 512-231-6117 vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461