From: Tom Lane <tgl@sss.pgh.pa.us>
To: Joost Kraaijeveld <J.Kraaijeveld@Askesis.nl>
Cc: Pgsql-Performance (E-mail) <pgsql-performance@postgresql.org>
Subject: Re: Retry: Is this possible / slow performance?
Date: Mon, 07 Feb 2005 12:03:56 -0500
Message-ID: <27755.1107795836@sss.pgh.pa.us> (raw)
In-Reply-To: <A3D1526C98B7C1409A687E0943EAC410605EF2@obelix.askesis.nl>
References: <A3D1526C98B7C1409A687E0943EAC410605EF2@obelix.askesis.nl>
"Joost Kraaijeveld" <J.Kraaijeveld@Askesis.nl> writes:
> Two queries: one with "set enable_seqscan = on" , the other with "set enable_seqscan = off". The first query lasts 59403 ms, the second query 31 ms ( the desc order variant has the same large difference: 122494 ms vs. 1297 ms). (for the query plans see below).
The reason for the difference is that the mergejoin plan has a much
lower startup cost than the hash plan, and since you're only fetching
100 rows the startup cost is dominant. IIRC the planner does make some
allowance for this effect when preparing a DECLARE CURSOR plan (ie,
it puts some weight on startup cost rather than considering only total
cost) ... but it's not so optimistic as to assume that you only want 100
out of an estimated 1 million+ result rows.
The best solution is probably to put a LIMIT into the DECLARE CURSOR,
so that the planner can see how much you intend to fetch.
regards, tom lane
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: tgl@sss.pgh.pa.us, J.Kraaijeveld@Askesis.nl
Subject: Re: Retry: Is this possible / slow performance?
In-Reply-To: <27755.1107795836@sss.pgh.pa.us>
* 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