Received: from candle.pha.pa.us (maillist@s5-03.ppp.op.net [209.152.195.67]) by hub.org (8.9.1/8.9.1) with ESMTP id SAA07959 for ; Thu, 3 Dec 1998 18:24:12 -0500 (EST) (envelope-from maillist@candle.pha.pa.us) Received: (from maillist@localhost) by candle.pha.pa.us (8.9.0/8.9.0) id SAA05873; Thu, 3 Dec 1998 18:23:37 -0500 (EST) From: Bruce Momjian Message-Id: <199812032323.SAA05873@candle.pha.pa.us> Subject: Re: [SQL] Optimizations In-Reply-To: <01BE1EC7.3A7A4790@MANSLEY> from Michael Ansley at "Dec 3, 1998 2:14:23 pm" To: michael.ansley@intec.co.za (Michael Ansley) Date: Thu, 3 Dec 1998 18:23:37 -0500 (EST) Cc: pgsql-sql@postgreSQL.org X-Mailer: ELM [version 2.4ME+ PL47 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit > 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 Using this is a sign of an SQL engine with a bad or nonexistant optimizer. We have a good optimizer which will properly handle such queries. > > 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. We don't support outer joins yet. -- Bruce Momjian | http://www.op.net/~candle maillist@candle.pha.pa.us | (610) 853-3000 + If your life is a hard drive, | 830 Blythe Avenue + Christ can be your backup. | Drexel Hill, Pennsylvania 19026