X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id EDE04D1B545; Fri, 10 Oct 2003 08:14:56 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 53288-10; Fri, 10 Oct 2003 05:14:08 -0300 (ADT) Received: from anchor-post-35.mail.demon.net (anchor-post-35.mail.demon.net [194.217.242.85]) by svr1.postgresql.org (Postfix) with ESMTP id 318E2D1B4F0; Fri, 10 Oct 2003 05:13:51 -0300 (ADT) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-35.mail.demon.net with esmtp (Exim 3.35 #1) id 1A7sPI-000Oej-0Z; Fri, 10 Oct 2003 09:13:52 +0100 Received: from localhost (localhost.localdomain [127.0.0.1]) by mainbox.archonet.com (Postfix) with ESMTP id 1A5AE17537; Fri, 10 Oct 2003 09:13:51 +0100 (BST) Received: from client17.archonet.com (client17.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id 588E317536; Fri, 10 Oct 2003 09:13:50 +0100 (BST) From: Richard Huxton To: , "'Karsten Hilbert'" , "'Lista dyskusyjna pgsql-general'" , "Lista dyskusyjna pgsql-sql" Subject: Re: [SQL] SQL query problem (many table in FROM statement and many LEFT JOIN's) Date: Fri, 10 Oct 2003 09:13:50 +0100 User-Agent: KMail/1.5 References: <004001c38f03$8d8b8230$4701a8c0@marek> In-Reply-To: <004001c38f03$8d8b8230$4701a8c0@marek> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200310100913.50259.dev@archonet.com> X-Virus-Scanned: by AMaViS snapshot-20020531 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200310/481 X-Sequence-Number: 50554 On Friday 10 October 2003 08:53, Marek Lewczuk wrote: > > > SELECT > > > _CON.con_id, > > > > Please make sure you get the quoting right regarding table > > names. PostgreSQL will fold _CON into _con unless quoted > > "_CON". So, it may be that you created the table with quotes > > ("_CON"). Now, in your query you don't use quotes and thusly > > it is looking for a _con table. The simple rule of thumb is > > to either always or never use quotes. > > I don't think that this is the solution, becouse the query: > > SELECT > _CON.con_id, > _MOD.mod_ty, > _CON.dri_id, > _CON.man_cod, > _ENG.eng_pow > FROM > db_data.mda_mod _MOD, > db_data.mda_mod_con _CON, > db_data.mda_mak_eng _ENG, > db_data.set_mda_fue _FUE > WHERE > _MOD.mod_id = '283' AND > _CON.mod_id = _MOD.mod_id AND > _CON.psd <= NOW() AND > _CON.ped > NOW() AND > _ENG.eng_id = _CON.eng_id AND > _ENG.eng_fue = _FUE.fue_id > > ...is working fine. I belive that this some problem with LEFT JOIN and > FROM statement. If I will rewrite this query: I think what's happening here is the fact that if you use explicit joins in a query that forces the order of the joins. You originally had: db_data.mda_mod _MOD, db_data.mda_mod_con _CON, db_data.mda_mak_eng _ENG, db_data.set_mda_fue _FUE LEFT JOIN db_data.mda_mod_ver _VER ON _VER.ver_id = _CON.ver_id LEFT JOIN db_data.mda_mod_yea _YEA ON _YEA.yea_id = _CON.yea_id which was being parsed as something like: ( (_FUE LEFT JOIN _VER) LEFT JOIN _YEA ), _MOD, _CON, ENG Of course, if it tries to evaluate in this order it can't see _CON from the innermost brackets. I believe the "force planner order" is configurable in the forthcoming 7.4 -- Richard Huxton Archonet Ltd