From: John A Meinel <john@arbash-meinel.com>
To: Gaetano Mendola <mendola@bigfoot.com>
Cc: Markus Bertheau ☭ <twanger@bluetwanger.de>
Cc: pgsql-performance@postgresql.org
Subject: Re: pl/pgsql faster than raw SQL?
Date: Tue, 08 Mar 2005 19:27:55 -0600
Message-ID: <422E511B.40102@arbash-meinel.com> (raw)
In-Reply-To: <422E4948.3090208@bigfoot.com>
References: <1110284432.4905.18.camel@dicaprio.akademie1.de>
<422E4948.3090208@bigfoot.com>
Gaetano Mendola wrote:
>Markus Bertheau ☭ wrote:
>
>
>>Hi, I have the following strange situation:
>>
>>
>
>that is no so strange. I have an example where:
>
>SELECT * FROM my_view WHERE field1 = 'New'; ==> 800 seconds
>
>SELECT * FROM my_view; ==> 2 seconds
>
>the only solution I had was to write a function table with
>the second select in a loop that was returnin the row if
>the field1 was equal = 'New'.
>It's strange but happen.
>
>
>
>Regards
>Gaetano Mendola
>
>
That sounds more like you had bad statistics on the field1 column, which
caused postgres to switch from a seqscan to an index scan, only there
were so many rows with field1='New' that it actually would have been
faster with a seqscan.
Otherwise what you did is very similar to the "nested loop" of postgres
which it selects when appropriate.
The other issue with views is that depending on their definition,
sometimes postgres can flatten them out and optimize the query, and
sometimes it can't. Order by is one of the big culprits for bad queries
involving views.
John
=:->
Attachments:
signature.asc (application/pgp-signature, 252B) 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, mendola@bigfoot.com, twanger@bluetwanger.de
Subject: Re: pl/pgsql faster than raw SQL?
In-Reply-To: <422E511B.40102@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