> -----Original Message----- > From: Tom Lane [mailto:[EMAIL PROTECTED] > 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" <[EMAIL PROTECTED]> 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 ---------------------------(end of broadcast)--------------------------- TIP 6: Have you searched our list archives? http://archives.postgresql.org