From: | "Gaetano Mendola" <mendola(at)bigfoot(dot)com> |
---|---|
To: | <pgsql-admin(at)postgresql(dot)org> |
Subject: | Union strange explain |
Date: | 2002-07-04 13:54:03 |
Message-ID: | 001901c22362$41daf130$070afea9@GMENDOLA2 |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-admin |
Hi all,
I have a view in this form:
CREATE VIEW my_view AS
< QUERY-A>
UNION ALL
<QUERY-B>
Now if I do:
# explain <QUERY-A> 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 <QUERY-B> 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 <windows>
#include <CSRSS>
printf("\t\t\b\b\b\b\b\b");.
printf("\t\t\b\b\b\b\b\b");
From | Date | Subject | |
---|---|---|---|
Next Message | Michael Meskes | 2002-07-04 14:21:01 | Re: [HACKERS] ecpg problem : pre-processor translated long constant to char |
Previous Message | Gary Stainburn | 2002-07-04 13:25:14 | Which DB is using space. |