Re: Function to either return one or all records

From: "Tambet Matiisen" <t(dot)matiisen(at)aprote(dot)ee>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: KÖPFERL Robert <robert(dot)koepferl(at)sonorys(dot)at>, <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Function to either return one or all records
Date: 2005-04-21 07:34:33
Message-ID: A66A11DBF5525341AEF6B8DE39CDE7700729EC@black.aprote.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

> -----Original Message-----
> From: Tom Lane [mailto:tgl(at)sss(dot)pgh(dot)pa(dot)us]
> Sent: Thursday, April 21, 2005 12:06 AM
> To: Tambet Matiisen
> Cc: KÖPFERL Robert; pgsql-sql(at)postgresql(dot)org
> Subject: Re: [SQL] Function to either return one or all records
>
>
> "Tambet Matiisen" <t(dot)matiisen(at)aprote(dot)ee> writes:
> > Standard technique is to rewrite OR queries to UNION queries. I
> > believe PostgreSQL optimizer does not do that automatically. So you
> > could try instead:
>
> > select * from id_bal_tbl where $1 is null
> > union all
> > select * from id_bal_tbl where id = $1;
>
> ... but that won't do anything to solve the performance
> problem. Doesn't help for the second select to use an index,
> if the first one grovels over the whole table anyway ...
>

Hmm, I tought about that before sending mail to list and did a little test. My test indicated, that the seq scan was discarded, it was definitely faster than OR query. I couldn't verify plan, as EXPLAIN shows only function scan.

Tambet

Browse pgsql-sql by date

  From Date Subject
Next Message Stéphane RIFF 2005-04-21 09:06:46 Re: Query question
Previous Message KÖPFERL Robert 2005-04-21 06:43:03 Re: Function to either return one or all records