Received: from relay.icon.co.za (relay.icon.co.za [196.26.208.4]) by hub.org (8.9.1/8.9.1) with SMTP id OAA17030 for ; Thu, 3 Dec 1998 14:22:23 -0500 (EST) (envelope-from michael.ansley@intec.co.za) Received: (qmail 7335 invoked from network); 3 Dec 1998 12:15:09 -0000 Received: from mail450.icon.co.za (196.26.208.3) by relay.icon.co.za with SMTP; 3 Dec 1998 12:15:09 -0000 Received: from MANSLEY (m1-23-ctn.dial-up.net [196.34.157.23]) by mail450.icon.co.za (8.9.1/8.8.8) with SMTP id OAA10084 for ; Thu, 3 Dec 1998 14:15:04 +0200 (GMT) Received: by MANSLEY with Microsoft Mail id <01BE1EC7.3A7A4790@MANSLEY>; Thu, 3 Dec 1998 14:14:24 +0200 Message-ID: <01BE1EC7.3A7A4790@MANSLEY> From: Michael Ansley To: "'pgsql-sql@postgresql.org'" Subject: Optimizations Date: Thu, 3 Dec 1998 14:14:23 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by hub.org id OAA17039 Please would somebody tell me whether or not the optimizer sufficiently optimizes a cross join like this: SELECT * FROM table1 t1, table2, t2 WHERE t1.field1 = t2.field4 to SELECT * FROM table1 t1 INNER JOIN table2 t2 ON t1.field1 = t2.field4 As I understand it, both queries will always return the same results, however, the second query will execute substantially faster, particularly as the tables involved increase in number of rows. It seems that most people prefer the first syntax, as it is probably quite simple logically, however, I suspect that the optimizer does not optimize it absolutely. Also, when LEFT, and OUTER JOINs are required, people forget that the JOIN keyword exists, and try to use the same syntax as in the first query. If I wanted all records in table1, and only associated records from table2, then the only way that I know of to retrieve this information would be as follows: SELECT * FROM table1 t1 LEFT JOIN table2 t2 ON t1.field1 = t2.field4 Would somebody please enlighten me (with regard to the optimizer, as well as alternatives for the last query above). I suspect that a lot of people are inadvertently using cross joins, when that is not what they mean to be doing, and are not impressed with the speed. Thanks... ---------------------------------------- Michael Ansley Intec (Ireland) Tel : +27 21 430-9000 Cell : +27 82 784-4229 eMail: michael.ansley@intec.co.za ICQ : 23465105 ----------------------------------------