Subject | Views and query optimization |
---|---|
Author | Bob Murdoch |
Post date | 2003-05-16T17:29:51Z |
If I create a view that performs a join between a couple of tables, should
I expect queries against that view to utilize the indices of the underlying
tables?
For example:
create table Orders(
order_id integer,
account_id integer,
entry_date date);
create index Order_Date_Idx on Orders (entry_date);
create table Order_Detail(
order_detail_id integer,
order_id integer,
qty integer);
With a view that looks like this:
create view Order_Sum(order_id, entry_date, qty) as
select
m.order_id, m.entry_date, sum(d.qty)
from
orders o
join order_detail d on (d.order_id = o.order_id)
group by
m.order_id, m.entry_date
Would a query such as this use the Order_Date_Idx?
select
order_id, qty
from
Order_Sum
where
entry_date between '1/1/2003' and '3/1/2003'
tia,
Bob M..
I expect queries against that view to utilize the indices of the underlying
tables?
For example:
create table Orders(
order_id integer,
account_id integer,
entry_date date);
create index Order_Date_Idx on Orders (entry_date);
create table Order_Detail(
order_detail_id integer,
order_id integer,
qty integer);
With a view that looks like this:
create view Order_Sum(order_id, entry_date, qty) as
select
m.order_id, m.entry_date, sum(d.qty)
from
orders o
join order_detail d on (d.order_id = o.order_id)
group by
m.order_id, m.entry_date
Would a query such as this use the Order_Date_Idx?
select
order_id, qty
from
Order_Sum
where
entry_date between '1/1/2003' and '3/1/2003'
tia,
Bob M..