我创建了一个视图,它是几个表的联合。
create view report as
select date,a,b,0,0 from table1
union all
select date,0,0,c,d from table2
我选择日期的位置:
select * from report where date = '2013-01-01'
我查看说明,我看到 where 过滤器在执行结束时执行(在追加之后)。我如何以这样一种方式创建视图,即在追加之前每个表上的位置。
谢谢你
在 postgres9.1 中使用
解释 ::(表和列重命名以保护隐私)
"Aggregate (cost=127286.88..127286.89 rows=1 width=8)"
" -> Subquery Scan on external_reports (cost=0.00..127254.46 rows=12969 width=8)"
" Filter: (external_reports.date = '2012-09-09 00:00:00'::timestamp without time zone)"
" -> Append (cost=0.00..94831.27 rows=2593855 width=54)"
" -> Result (cost=0.00..71.38 rows=10 width=112)"
" -> Append (cost=0.00..71.38 rows=10 width=112)"
" -> Seq Scan on report1 (cost=0.00..14.26 rows=2 width=112)"
" Filter: ((x)::text = 'ADS'::text)"
" -> Seq Scan on report2 (cost=0.00..14.26 rows=2 width=112)"
" Filter: ((x)::text = 'ADS2'::text)"
" -> Seq Scan on report3 (cost=0.00..14.26 rows=2 width=112)"
" Filter: ((x)::text = 'ADS3'::text)"
" -> Seq Scan on report4 (cost=0.00..14.26 rows=2 width=112)"
" Filter: ((x)::text = 'ADS4'::text)"
" -> Seq Scan on report5 (cost=0.00..14.26 rows=2 width=112)"
" Filter: ((x)::text = 'ADS5'::text)"
" -> Seq Scan on report6 (cost=0.00..65421.34 rows=2459934 width=54)"
" -> Subquery Scan on "*SELECT* 7" (cost=0.00..4739.22 rows=133911 width=52)"
" -> Seq Scan on report___ (cost=0.00..3400.11 rows=133911 width=52)"