Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id E2032475CD4 for ; Thu, 4 Jul 2002 10:16:51 -0400 (EDT) Mailbox-Line: From mendola@bigfoot.com Thu Jul 4 10:16:51 2002 Received: from pns.mm.eutelsat.org (unknown [194.214.173.227]) by postgresql.org (Postfix) with ESMTP id 20C4E475FD2 for ; Thu, 4 Jul 2002 09:53:05 -0400 (EDT) Received: from nts-03.mm.eutelsat.org (localhost [127.0.0.1]) by pns.mm.eutelsat.org (8.11.6/linuxconf) with ESMTP id g64Dqmf25981 for ; Thu, 4 Jul 2002 15:52:48 +0200 Received: from dell-01.mm.eutelsat.org (IDENT:root@dell-01.mm.eutelsat.org [194.214.173.17]) by nts-03.mm.eutelsat.org (8.9.3/8.8.7) with ESMTP id OAA08926 for ; Thu, 4 Jul 2002 14:46:31 +0200 Received: from GMENDOLA2 (gmendola2.mm.eutelsat.org [194.214.173.26]) by dell-01.mm.eutelsat.org (8.11.2/8.8.7) with SMTP id g64DqXL12116 for ; Thu, 4 Jul 2002 15:52:33 +0200 Message-ID: <001901c22362$41daf130$070afea9@GMENDOLA2> From: "Gaetano Mendola" To: Subject: Union strange explain Date: Thu, 4 Jul 2002 15:54:03 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 X-Spam-Status: No, hits=0.0 required=5.0 tests=none version=2.30 X-Spam-Level: X-Archive-Number: 200207/60 X-Sequence-Number: 4746 Hi all, I have a view in this form: CREATE VIEW my_view AS < QUERY-A> UNION ALL Now if I do: # explain WHERE login = 'asdadad'; NOTICE: QUERY PLAN: Nested Loop (cost=0.00..7.08 rows=1 width=88) -> Nested Loop (cost=0.00..5.05 rows=1 width=52) -> Index Scan using user_login_login_key on user_login (cost=0.00..2.02 rows=1 width=16) -> Index Scan using idx_user_user_traffic on user_traffic ut (cost=0.00..3.02 rows=1 width=36) -> Index Scan using contracts_pkey on contracts c (cost=0.00..2.01 rows=1 width=36) # explain WHERE login = 'asdadad'; NOTICE: QUERY PLAN: Nested Loop (cost=0.00..4.22 rows=1 width=68) -> Nested Loop (cost=0.00..3.20 rows=1 width=40) -> Index Scan using user_login_login_key on user_login (cost=0.00..2.02 rows=1 width=16) -> Seq Scan on cas_subscription csub (cost=0.00..1.08 rows=8 width=24) -> Seq Scan on cas_service cser (cost=0.00..1.01 rows=1 width=28) if instead I do: # explain select * from my_view where login = 'asdadad'; NOTICE: QUERY PLAN: Subquery Scan foo (cost=367.73..393.27 rows=93 width=88) -> Unique (cost=367.73..393.27 rows=93 width=88) -> Sort (cost=367.73..367.73 rows=929 width=88) -> Append (cost=84.59..321.95 rows=929 width=88) -> Subquery Scan *SELECT* 1 (cost=84.59..303.59 rows=926 width=88) -> Hash Join (cost=84.59..303.59 rows=926 width=88) -> Hash Join (cost=81.57..262.53 rows=926 width=52) -> Seq Scan on user_traffic ut (cost=0.00..52.78 rows=2778 width=36) -> Hash (cost=78.16..78.16 rows=1364 width=16) -> Seq Scan on user_login (cost=0.00..78.16 rows=1364 width=16) -> Hash (cost=2.81..2.81 rows=81 width=36) -> Seq Scan on contracts c (cost=0.00..2.81 rows=81 width=36) -> Subquery Scan *SELECT* 2 (cost=0.00..18.36 rows=3 width=68) -> Nested Loop (cost=0.00..18.36 rows=3 width=68) -> Seq Scan on cas_service cser (cost=0.00..1.01 rows=1 width=28) -> Materialize (cost=17.31..17.31 rows=3 width=40) -> Nested Loop (cost=0.00..17.31 rows=3 width=40) -> Seq Scan on cas_subscription csub (cost=0.00..1.08 rows=8 width=24) -> Index Scan using user_login_pkey on user_login (cost=0.00..2.02 rows=1 width=16) How it is possible that the two Subquery Scan have two completely different plan ? How I can obtain for the two subselect the same plan like is in a single query ? Ciao Gaetano -- #exclude #include printf("\t\t\b\b\b\b\b\b");. printf("\t\t\b\b\b\b\b\b");