X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 7BE4753CEB for ; Thu, 21 Apr 2005 04:34:48 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 87579-10 for ; Thu, 21 Apr 2005 07:34:38 +0000 (GMT) Received: from ns.aprote.ee (ns.aprote.ee [80.235.78.106]) by svr1.postgresql.org (Postfix) with ESMTP id CD91353CFE for ; Thu, 21 Apr 2005 04:34:34 -0300 (ADT) Received: Message by Barricade ns.aprote.ee with ESMTP id j3L7acxe019945 for ; Thu, 21 Apr 2005 10:36:39 +0300 content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-4" Content-Transfer-Encoding: quoted-printable X-MimeOLE: Produced By Microsoft Exchange V6.0.6556.0 Subject: Re: Function to either return one or all records Date: Thu, 21 Apr 2005 10:34:33 +0300 Message-ID: X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [SQL] Function to either return one or all records Thread-Index: AcVF7PM47Lyd7elTSiygL17urBbyPgAVyeJQ From: "Tambet Matiisen" To: "Tom Lane" Cc: =?iso-8859-4?Q?K=D6PFERL_Robert?= , X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.004 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200504/313 X-Sequence-Number: 21206 > -----Original Message----- > From: Tom Lane [mailto:tgl@sss.pgh.pa.us]=20 > Sent: Thursday, April 21, 2005 12:06 AM > To: Tambet Matiisen > Cc: K=D6PFERL Robert; pgsql-sql@postgresql.org > Subject: Re: [SQL] Function to either return one or all records=20 >=20 >=20 > "Tambet Matiisen" writes: > > Standard technique is to rewrite OR queries to UNION queries. I=20 > > believe PostgreSQL optimizer does not do that automatically. So you=20 > > could try instead: >=20 > > select * from id_bal_tbl where $1 is null > > union all > > select * from id_bal_tbl where id =3D $1; >=20 > ... but that won't do anything to solve the performance=20 > problem. Doesn't help for the second select to use an index,=20 > if the first one grovels over the whole table anyway ... >=20 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