pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Frederic Jolliton <fred-pg@jolliton.com>
To: pgsql-performance@postgresql.org
Subject: Re: Important speed difference between a query and a
Date: Thu, 24 Apr 2003 18:41:49 +0200
Message-ID: <868ytzsv8y.fsf@mau.localdomain> (raw)
In-Reply-To: <20030424085451.P1362-100000@megazone23.bigpanda.com>
References: <20030424085451.P1362-100000@megazone23.bigpanda.com>


> On Thu, 24 Apr 2003, Frederic Jolliton wrote:
>> > CREATE FUNCTION get_info (integer) RETURNS SETOF type_get_info
>> >     AS '...' <- here the query show below, where 'LIMIT $1' is used instead of 'LIMIT 10'
>> >     LANGUAGE sql;
>>
>> Setting enable_seqscan to off give same result speed between the query
>> and the function !
>>
>> So, the query in the function is not using index but the exact same
>> query alone does !
>>
>> Is there an explanation ?

Stephan Szabo <sszabo@megazone23.bigpanda.com> writes:
> My guess is that limit $1 is assuming a larger number of rows when
> planning the queries, large enough that it expects seqscan to be
> better (assuming the limit is what it expects).  It's probably not
> going to plan that query each time the function is called so it's
> not going to know whether you're calling with a small number (index
> scan may be better) or a large number (seq scan may be better).  For
> example, if you sent 100000, the index scan might be a loser.
>
> Perhaps plpgsql with EXECUTE would work better for that, although
> it's likely to have some general overhead.

The server is rather fast, and the query return 10 to 50 rows in most
case. So, this is probably a solution, even if it's not very
clean. (Well, I have to find an example to RETURN the result of
EXECUTE..)

But, what I don't understand is why enable_seqscan change something if
the query is already planed.

-- 
Frédéric Jolliton




view thread (10+ messages)  latest in thread

Message-ID: <868ytzsv8y.fsf@mau.localdomain>
Permalink:  ../868ytzsv8y.fsf@mau.localdomain/
Also on:    postgresql.org/message-id/868ytzsv8y.fsf@mau.localdomain

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-performance@postgresql.org
  Cc: fred-pg@jolliton.com
  Subject: Re: Important speed difference between a query and a
  In-Reply-To: <868ytzsv8y.fsf@mau.localdomain>
  References: <20030424085451.P1362-100000@megazone23.bigpanda.com> <868ytzsv8y.fsf@mau.localdomain>

* 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