pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Huxton <dev@archonet.com>
To: Jan Kesten <jan.kesten@web.de>
Cc: pgsql-performance@postgresql.org
Subject: Re: Improving performance on multicolumn query
Date: Wed, 09 Nov 2005 12:54:45 +0000
Message-ID: <4371F195.6060204@archonet.com> (raw)
In-Reply-To: <4371E6A7.50808@web.de>
References: <4371E6A7.50808@web.de>

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



view thread (6+ messages)  latest in thread

Message-ID: <4371F195.6060204@archonet.com>
Permalink:  ../4371F195.6060204@archonet.com/
Also on:    postgresql.org/message-id/4371F195.6060204@archonet.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: dev@archonet.com, jan.kesten@web.de
  Subject: Re: Improving performance on multicolumn query
  In-Reply-To: <4371F195.6060204@archonet.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox