pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tambet Matiisen <t.matiisen@aprote.ee>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: KÖPFERL Robert <robert.koepferl@sonorys.at>
Cc: pgsql-sql@postgresql.org
Subject: Re: Function to either return one or all records
Date: Thu, 21 Apr 2005 10:34:33 +0300
Message-ID: <A66A11DBF5525341AEF6B8DE39CDE7700729EC@black.aprote.com> (raw)



> -----Original Message-----
> From: Tom Lane [mailto:tgl@sss.pgh.pa.us] 
> Sent: Thursday, April 21, 2005 12:06 AM
> To: Tambet Matiisen
> Cc: KÖPFERL Robert; pgsql-sql@postgresql.org
> Subject: Re: [SQL] Function to either return one or all records 
> 
> 
> "Tambet Matiisen" <t.matiisen@aprote.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



view thread (5+ messages)

Message-ID: <A66A11DBF5525341AEF6B8DE39CDE7700729EC@black.aprote.com>
Permalink:  ../A66A11DBF5525341AEF6B8DE39CDE7700729EC@black.aprote.com/
Also on:    postgresql.org/message-id/A66A11DBF5525341AEF6B8DE39CDE7700729EC@black.aprote.com

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: t.matiisen@aprote.ee, tgl@sss.pgh.pa.us, robert.koepferl@sonorys.at
  Subject: Re: Function to either return one or all records
  In-Reply-To: <A66A11DBF5525341AEF6B8DE39CDE7700729EC@black.aprote.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