X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id AD2FDD995D for ; Wed, 9 Nov 2005 08:55:33 -0400 (AST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 29643-08 for ; Wed, 9 Nov 2005 12:55:30 +0000 (GMT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75]) by svr1.postgresql.org (Postfix) with ESMTP id C3D1FD98DF for ; Wed, 9 Nov 2005 08:55:31 -0400 (AST) Received: from mainbox.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 B36AE40C1C3; Wed, 9 Nov 2005 12:55:26 +0000 (GMT) Received: from localhost (localhost.localdomain [127.0.0.1]) by mainbox.archonet.com (Postfix) with ESMTP id CD22915EDB; Wed, 9 Nov 2005 12:54:59 +0000 (GMT) Received: from mainbox.archonet.com ([127.0.0.1]) by localhost (mainbox [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 25179-04; Wed, 9 Nov 2005 12:54:51 +0000 (GMT) Received: from [192.168.1.17] (client17.office.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id 34AAF15EDA; Wed, 9 Nov 2005 12:54:46 +0000 (GMT) Message-ID: <4371F195.6060204@archonet.com> Date: Wed, 09 Nov 2005 12:54:45 +0000 From: Richard Huxton User-Agent: Mozilla Thunderbird 1.0.7 (X11/20051013) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Jan Kesten Cc: pgsql-performance@postgresql.org Subject: Re: Improving performance on multicolumn query References: <4371E6A7.50808@web.de> In-Reply-To: <4371E6A7.50808@web.de> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.032 required=5 tests=[AWL=0.032] X-Spam-Score: 0.032 X-Spam-Level: X-Archive-Number: 200511/154 X-Sequence-Number: 15411 Jan Kesten wrote: > > First, I'm using postgresql 7.4.7 on a 2GHz machine having 1.5GByte RAM > and I have a table with about 220 columns and 20000 rows - and the first > five columns build a primary key (and a unique index). > transfer=> explain analyse SELECT * FROM test WHERE test_a=9091150001 > AND test_b=1 AND test_c=2 AND test_d=0 AND test_e=0; > > Index Scan using test_idx on test (cost=0.00..50.27 rows=1 width=1891) > (actual time=0.161..0.167 rows=1 loops=1) > Index Cond: (test_a = 9091150001::bigint) > Filter: ((test_b = 1) AND (test_c = 2) AND (test_d = 0) AND (test_e 0)) This says it's taking less than a millisecond - which is almost certainly too fast to measure accurately anyway. Are you sure this query is the problem? > So, what to do to speed things up? If I understand correctly this > output, the planner uses my index (test_idx is the same as test_pkey > created along with the table), but only for the first column. 1. Are all of test_a/b/c/d/e bigint rather than int? 2. Have you tried explicitly casting your query parameters? ...WHERE test_a=123::bigint AND test_b=456::bigint... -- Richard Huxton Archonet Ltd