pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Gaetano Mendola <mendola@bigfoot.com>
To: pgsql-admin@postgresql.org
Subject: Union strange explain
Date: Thu, 4 Jul 2002 15:54:03 +0200
Message-ID: <001901c22362$41daf130$070afea9@GMENDOLA2> (raw)

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");






view thread (5+ messages)  latest in thread

Message-ID: <001901c22362$41daf130$070afea9@GMENDOLA2>
Permalink:  ../001901c22362$41daf130$070afea9@GMENDOLA2/
Also on:    postgresql.org/message-id/001901c22362$41daf130$070afea9@GMENDOLA2

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: mendola@bigfoot.com
  Subject: Re: Union strange explain
  In-Reply-To: <001901c22362$41daf130$070afea9@GMENDOLA2>
  References: <001901c22362$41daf130$070afea9@GMENDOLA2>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox