From: John A Meinel <john@arbash-meinel.com>
To: Clark Slater <list@slatech.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: faster search
Date: Fri, 10 Jun 2005 13:00:54 -0500
Message-ID: <42A9D556.7070108@arbash-meinel.com> (raw)
In-Reply-To: <20050610132812.R94573@vbp2.vbp2.com>
References: <20050610132812.R94573@vbp2.vbp2.com>
Clark Slater wrote:
> Hi-
>
> Would someone please enlighten me as
> to why I'm not seeing a faster execution
> time on the simple scenario below?
>
> there are 412,485 rows in the table and the
> query matches on 132,528 rows, taking
> almost a minute to execute. vaccuum
> analyze was just run.
Well, if you are matching 130k out of 400k rows, then a sequential scan
is certainly prefered to an index scan. And then you have to sort those
130k rows by partnumber. This *might* be spilling to disk depending on
what your workmem/sortmem is set to.
I would also say that what you would really want is some way to get the
whole thing from an index. And I think the way to do that is:
CREATE INDEX test_partnum_listid_typeid_idx ON
test(partnumber, productlistid, typeid);
VACUUM ANALYZE test;
EXPLAIN ANALYZE SELECT * FROM test
WHERE productlistid=3 AND typeid=9
ORDER BY partnumber, productlistid, typeid
LIMIT 15
;
The trick is that you have to match the order by exactly with the index,
so the planner realizes it can do an indexed lookup to get the information.
You could also just create an index on partnumber, and see how that
affects your original query. I think the planner could use an index
lookup on partnumber to get the ordering correct. But it will have to do
filtering after the fact based on productlistid and typeid.
With my extended index, I think the planner can be smarter and lookup
all 3 by the index.
>
> Thanks!
> Clark
Good luck,
John
=:->
Attachments:
signature.asc (application/pgp-signature, 250B) download
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: john@arbash-meinel.com, list@slatech.com
Subject: Re: faster search
In-Reply-To: <42A9D556.7070108@arbash-meinel.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