Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 4D9264771CC for ; Wed, 22 Jan 2003 17:32:00 -0500 (EST) Received: from serwer.skawsoft.com.pl (serwer.skawsoft.com.pl [213.25.37.66]) by postgresql.org (Postfix) with ESMTP id 9711E476FF9 for ; Wed, 22 Jan 2003 16:49:50 -0500 (EST) Received: from klaster.net (pc81.krakow.cvx.ppp.tpnet.pl [213.76.38.81]) by serwer.skawsoft.com.pl (Postfix) with ESMTP id C15242B864 for ; Wed, 22 Jan 2003 22:45:30 +0100 (CET) Message-ID: <3E2F130B.4030002@klaster.net> Date: Wed, 22 Jan 2003 22:54:19 +0100 From: Tomasz Myrta User-Agent: Mozilla/5.0 (Windows; U; Win 9x 4.90; en-US; rv:1.2b) Gecko/20021016 X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Re: To use a VIEW or not to use a View..... References: <20030122130604.C1159-100000@megazone23.bigpanda.com> In-Reply-To: <20030122130604.C1159-100000@megazone23.bigpanda.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200301/347 X-Sequence-Number: 11212 Stephan Szabo wrote: >That's not the same join for optimization purposes >since postgresql treats explicit join syntax as a >constraint on the ordering of joins. > >The same join would be something like: > >przystanki p1 join miasta m1 using (id_miasta) >join (przystanki p2 join miasta m2 using (id_miasta)) > using (id_przystanku) > >minus the fact I think you'd need some explicit naming in >there. You are right. The result of your query is: explain select * from przystanki p1 join miasta m1 using (id_miasta) join (przystanki p2 join miasta m2 using (id_miasta)) using (id_przystanku) where id_przystanku=1230 Hash Join (cost=13.00..30.10 rows=1 width=128) -> Hash Join (cost=6.74..21.02 rows=374 width=64) -> Seq Scan on przystanki p2 (cost=0.00..7.74 rows=374 width=41) -> Hash (cost=5.99..5.99 rows=299 width=23) -> Seq Scan on miasta m2 (cost=0.00..5.99 rows=299 width=23) -> Hash (cost=6.26..6.26 rows=1 width=64) -> Nested Loop (cost=0.00..6.26 rows=1 width=64) -> Index Scan using przystanki_pkey on przystanki p1 (cost=0.00..3.14 rows=1 width=41) -> Index Scan using miasta_pkey on miasta m1 (cost=0.00..3.10 rows=1 width=23) Anyway - is it possible to expose table "przystanki alias p2" to get valid result? The problem is similiar to my problem "sub-select with aggregate" dated on 2002-10-23 and the answer (which doesn't satisfy me) is the same: if we pass static values to "przystanki p2 join miasta m2", the query will work ok: explain select * from przystanki p1 join miasta m1 using (id_miasta) cross join (przystanki p2 join miasta m2 using (id_miasta)) X where p1.id_przystanku=1230 and X.id_przystanku=1230 Nested Loop (cost=0.00..12.52 rows=1 width=128) -> Nested Loop (cost=0.00..6.26 rows=1 width=64) -> Index Scan using przystanki_pkey on przystanki p1 (cost=0.00..3.14 rows=1 width=41) -> Index Scan using miasta_pkey on miasta m1 (cost=0.00..3.10 rows=1 width=23) -> Materialize (cost=6.26..6.26 rows=1 width=64) -> Nested Loop (cost=0.00..6.26 rows=1 width=64) -> Index Scan using przystanki_pkey on przystanki p2 (cost=0.00..3.14 rows=1 width=41) -> Index Scan using miasta_pkey on miasta m2 (cost=0.00..3.10 rows=1 width=23) Stephan - I have some problems with mail relay to you. Does my mail server have any open-relay problem, or something like this (213.25.37.66) ? Regards, Tomasz Myrta