X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.192]) by svr1.postgresql.org (Postfix) with ESMTP id 13F93CCABE for ; Thu, 17 Jul 2003 19:24:34 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr4.postgresql.org [64.117.224.192]) (amavisd-new, port 10024) with ESMTP id 64589-04 for ; Thu, 17 Jul 2003 19:25:02 +0000 (GMT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id 0C822CCABA for ; Thu, 17 Jul 2003 16:24:33 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h6HJOxQ3006220; Thu, 17 Jul 2003 15:25:00 -0400 (EDT) To: josh@agliodbs.com Cc: Scott Cain , pgsql-sql@postgresql.org Subject: Re: OR vs UNION In-reply-to: <200307171200.18626.josh@agliodbs.com> References: <1058465506.3345.15.camel@localhost.localdomain> <200307171200.18626.josh@agliodbs.com> Comments: In-reply-to Josh Berkus message dated "Thu, 17 Jul 2003 12:00:18 -0700" Date: Thu, 17 Jul 2003 15:24:59 -0400 Message-ID: <6219.1058469899@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200307/240 X-Sequence-Number: 14354 Josh Berkus writes: > Certainly a query of the above form would not benefit from being a union. Actually we used to have code in the planner that would automatically transform an OR query to a UNION ALL construct (the old "ksqo" option). It fell into disfavor, partly because it didn't really preserve semantics exactly --- IIRC, should you mention the same field value more than once in the OR, the UNION ALL version would generate duplicate output rows. At the time it was put in, it offered significant performance wins, but subsequent planner improvements narrowed the gap to nearly nothing, and we eventually took it out. I'm not sure whether there's any possible win given the current state of the planner. If you dig for "ksqo" in the archives you can find all the details (at least on days when the search engine is working ;-)). regards, tom lane