Skip site navigation (1) Skip section navigation (2)

How does the planner execute unions?

From: Chris Hoover <revoohc(at)gmail(dot)com>
To: pgsql-performance(at)postgresql(dot)org
Subject: How does the planner execute unions?
Date: 2005-08-26 20:14:18
Message-ID: 1d219a6f0508261314516fdb0@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-performance
Hopefully a quick question.

In 7.3.4, how does the planner execute a query with union alls in it?

Does it execute the unions serially, or does it launch a "thread" for
each union (or maybe something else entirely).

Thanks,

Chris

Here is an explain from the view I'm thinking about, how does postgres
run this query?
hmd=# explain select count(1) from clmhdr where hdr_user_id = 'user_id';
                                                               QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------
 Aggregate  (cost=42.48..42.48 rows=1 width=924)
   ->  Subquery Scan clmhdr  (cost=0.00..42.41 rows=30 width=924)
         ->  Append  (cost=0.00..42.41 rows=30 width=924)
               ->  Subquery Scan "*SELECT* 1"  (cost=0.00..7.07 rows=5
width=924)
                     ->  Index Scan using
clmhdr_live_hdr_user_id_hdr_clm_status_idx on clmhdr_live 
(cost=0.00..7.07 rows=5 width=924)
                           Index Cond: (hdr_user_id =
'user_id'::character varying)
               ->  Subquery Scan "*SELECT* 2"  (cost=0.00..7.07 rows=5
width=924)
                     ->  Index Scan using
clmhdr_2003_hdr_user_id_hdr_clm_status_idx on clmhdr_2003 
(cost=0.00..7.07 rows=5 width=924)
                           Index Cond: (hdr_user_id =
'user_id'::character varying)
               ->  Subquery Scan "*SELECT* 3"  (cost=0.00..7.07 rows=5
width=924)
                     ->  Index Scan using
clmhdr_2004_hdr_user_id_hdr_clm_status_idx on clmhdr_2004 
(cost=0.00..7.07 rows=5 width=924)
                           Index Cond: (hdr_user_id =
'user_id'::character varying)
               ->  Subquery Scan "*SELECT* 4"  (cost=0.00..7.07 rows=5
width=924)
                     ->  Index Scan using
clmhdr_2005_hdr_user_id_hdr_clm_status_idx on clmhdr_2005 
(cost=0.00..7.07 rows=5 width=924)
                           Index Cond: (hdr_user_id =
'user_id'::character varying)
               ->  Subquery Scan "*SELECT* 5"  (cost=0.00..7.07 rows=5
width=924)
                     ->  Index Scan using
clmhdr_2006_hdr_user_id_hdr_clm_status_idx on clmhdr_2006 
(cost=0.00..7.07 rows=5 width=924)
                           Index Cond: (hdr_user_id =
'user_id'::character varying)
               ->  Subquery Scan "*SELECT* 6"  (cost=0.00..7.07 rows=5
width=924)
                     ->  Index Scan using
clmhdr_2007_hdr_user_id_hdr_clm_status_idx on clmhdr_2007 
(cost=0.00..7.07 rows=5 width=924)
                           Index Cond: (hdr_user_id =
'user_id'::character varying)
(21 rows)

hmd=#

Responses

pgsql-performance by date

Next:From: Bruno Wolff IIIDate: 2005-08-26 20:45:54
Subject: Re: How does the planner execute unions?
Previous:From: Alan StangeDate: 2005-08-26 19:01:55
Subject: Re: difference in plan between 8.0 and 8.1?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group