Creating a view using tables with a large number of rows
839900Feb 15 2011 — edited Feb 18 2011I have a view 'test_view' which is composed of two tables:
- 'table_a'
- 'table_b'
Each of them has more than 10 million records.
Query creating that view is below:
create view test_view as
select * from table_a t
union all
select * from table_b t
Efficiency of that view is very poor (while using it with other queries). Few indexes has been added but it didn't help. I think that the cost is high because of a large number of data.
When I created a table ('table_c') in which all rows from table 'table_a' and table 'table_b' were inserted - efficiency was much better (it was done just for test).
What is the logical difference (why the efficiency is so different) between view 'test_view' and table 'table_c' ?
Is there another solution to make that view run more efficiently (maybe some database settings should be modify) ?