X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 10CF6DAA6C for ; Wed, 26 Oct 2005 00:53:52 -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 33232-04 for ; Wed, 26 Oct 2005 03:53:49 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id 9C097DA8FA for ; Wed, 26 Oct 2005 00:53:49 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j9Q3rieM001417; Tue, 25 Oct 2005 23:53:44 -0400 (EDT) To: Michael Fuhr Cc: chester c young , pgsql-sql@postgresql.org Subject: Re: broken join optimization? (8.0) In-reply-to: <20051026024211.GA98628@winnie.fuhr.org> References: <20051025235612.20767.qmail@web54301.mail.yahoo.com> <20051026024211.GA98628@winnie.fuhr.org> Comments: In-reply-to Michael Fuhr message dated "Tue, 25 Oct 2005 20:42:11 -0600" Date: Tue, 25 Oct 2005 23:53:44 -0400 Message-ID: <1416.1130298824@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006] X-Spam-Level: X-Archive-Number: 200510/301 X-Sequence-Number: 23154 Michael Fuhr writes: > On Tue, Oct 25, 2005 at 04:56:11PM -0700, chester c young wrote: >> in php (for example) it's frequently nice to get the structure of a >> table without any data, > Have you considered "SELECT * FROM mytable LIMIT 0"? Indeed. > I see the same behavior in the latest 8.1beta code. Maybe one of > the developers will comment on whether optimizing that is a simple > change, a difficult change, not worth changing because few people > find a use for it, or a behavior that can't be changed because of > something we're not considering. Not worth changing --- why should we expend cycles (even if it only takes a few, which isn't clear to me offhand) on every join query, to detect what's simply a brain-dead way of finding out table structure? I can't think of any realistic scenarios for a constant-false join clause. The relevant bit of code is in initsplan.c: /* * If the clause is variable-free, we force it to be evaluated at its * original syntactic level. Note that this should not happen for * top-level clauses, because query_planner() special-cases them. But it * will happen for variable-free JOIN/ON clauses. We don't have to be * real smart about such a case, we just have to be correct. */ if (bms_is_empty(relids)) relids = qualscope; Possibly you could get the planner to generate a gating Result node for such a case, the way it does for constant-false top level WHERE clauses, but I really doubt it's worth any extra cycles at all to make this happen. The proposed example is quite unconvincing ... why would anyone want to depend on the existence of a "dual" table rather than LIMIT 0? regards, tom lane