Received: from nexus.kearneydev.com (IDENT:root@nexus.kearneydev.com [208.136.214.2]) by hub.org (8.9.2/8.9.1) with ESMTP id KAA82417 for ; Tue, 23 Mar 1999 10:33:00 -0500 (EST) (envelope-from secret@kearneydev.com) Received: from kearneydev.com (atu.kearneydev.com [208.136.214.93]) by nexus.kearneydev.com (8.8.5/8.8.5) with ESMTP id KAA28368 for ; Tue, 23 Mar 1999 10:32:52 -0500 Message-ID: <36F7B427.4079B01@kearneydev.com> Date: Tue, 23 Mar 1999 10:32:55 -0500 From: secret Organization: Kearney Development Co., Inc. X-Mailer: Mozilla 4.5 [en] (WinNT; U) X-Accept-Language: en MIME-Version: 1.0 To: PG-SQL Subject: Simple Optimization Problem Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit I need to run a report using some parameters that are optional, I'm doing this by labeling "0" as the optional value. IE here is a simplified example: CREATE TABLE po (po_id int4 PRIMARY KEY, data text); (insert a bunch of rows) ftc=> explain select * from po where po_id=8888; NOTICE: QUERY PLAN: Index Scan using ipo_poid_units on po (cost=2.05 size=1 width=94) EXPLAIN ftc=> explain select * from po where (po_id=8888 or 0=8888); NOTICE: QUERY PLAN: Seq Scan on po (cost=449.96 size=1751 width=94) EXPLAIN I was hoping PostgreSQL could optimize out the boolean condition given in the where clause, but it causes it to disregard the index instead of throwing out 0=8888 in the first stage. This is the only way I can think to do this, I have crystal reports send through the SQL instead of doing the whole thing itself(Which involves returning all possible rows... Sigh)... This query is taking 20 minutes as a result... Is there any hope in 6.5 of the optimizer handling this better? David Secret MIS Director Kearney Development Co., Inc.