From: | Reece Hart <reece(at)harts(dot)net> |
---|---|
To: | Dann Corbit <DCorbit(at)connx(dot)com> |
Cc: | Ashish Karalkar <ashish(dot)karalkar(at)info-spectrum(dot)com>, Andrej Ricnik-Bay <andrej(dot)groups(at)gmail(dot)com>, Ron Johnson <ron(dot)l(dot)johnson(at)cox(dot)net>, pgsql-general(at)postgresql(dot)org |
Subject: | Re: Views- Advantages and Disadvantages |
Date: | 2007-05-09 21:45:24 |
Message-ID: | 1178747124.4565.26.camel@snafu.site |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Wed, 2007-05-09 at 12:02 -0700, Dann Corbit wrote:
> Views can hide important information from the optimizer (especially
> index information).
I believe that you're mistaken, and you can see it rather easily by
explaining a select on a view (or even a view of views). For example:
rkh(at)csb-dev=> \d palias
View "unison.palias"
Column | Type | Modifiers
-------------+--------------------------+-----------
palias_id | integer |
pseq_id | integer |
origin_id | integer |
alias | text |
descr | text |
tax_id | integer |
ref_pseq_id | integer |
added | timestamp with time zone |
View definition:
SELECT pa.palias_id, pv.pseq_id, pa.origin_id, pa.alias,
pa.descr, pa.tax_id, pv.ref_pseq_id, pv.added
FROM paliasorigin pa, pseqalias pv
WHERE pv.palias_id = pa.palias_id AND pv.is_current = true;
rkh(at)csb-dev=> explain select * from palias where tax_id=9606;
QUERY
PLAN
------------------------------------------------------------------------------------------------------------
Hash Join (cost=701397.95..1634572.27 rows=1293890 width=137)
Hash Cond: (pv.palias_id = pa.palias_id)
-> Seq Scan on pseqalias pv (cost=0.00..474670.85
rows=20706650 width=20)
Filter: is_current
-> Hash (cost=647199.80..647199.80 rows=1692012 width=121)
-> Bitmap Heap Scan on paliasorigin pa
(cost=33808.65..647199.80 rows=1692012 width=121)
Recheck Cond: (tax_id = 9606)
-> Bitmap Index Scan on paliasorigin_tax_id_idx
(cost=0.00..33385.65 rows=1692012 width=0)
Index Cond: (tax_id = 9606)
(9 rows)
Long ago I compared a few views with their inlined counterparts and the
upshot is that there is exactly or practically zero difference.
-Reece
--
Reece Hart, http://harts.net/reece/, GPG:0x25EC91A0
From | Date | Subject | |
---|---|---|---|
Next Message | Alvaro Herrera | 2007-05-09 21:53:05 | Re: In theory question |
Previous Message | David Wall | 2007-05-09 21:40:35 | Replication for PG 8 recommendations |