Query Performance through Views
Posted in 1993
It appears that Informix Online 5.00 makes some rather mindless assumptions
about query optimization under the "create view" statement. It essentially
ignores any indexes it might be able to use based upon what columns are
selected when accessing the view. With "set explain on" the engine spits
out the same grossly inefficient query plan regardless of what columns I
specify in my query.
In the example query attached below two column values are specified which
comprise a composite key (shift_date & shift) which are the best path
to the data but OnLine completely ignores this information, grinds through
the tables in a sequential search, then filters for the values I specified.
It takes eons. (Query plan "estimated cost" = 9578).
The exact same query posted directly against the tables comes back
instantaneously. (Query plan "estimated cost" = 24). I believe the
query against the View should net the same performance.
Also: I "update statistics" daily.
My questions are:
1. How do I get Informix to use the optimal query path under a
view? Does 5.01/.02 have the same behavior?
2. Having just bet the farm on the suitability of building a
Data Warehouse centered around Informix Views, did I just
make a colossal blunder?
Ken Miles
Hewlett Packard Vancouver Division
kenm@vcd.hp.com
****************************************************************
The sqexplain.out file looks like this:
QUERY:
------
create view "informix".test_results (product_number,test_station,line_number,shift_date,shift,test_result,test_symptom_id,quantity) as select distinct x0.hp_item_nr ,x1.name ,x1.line ,x0.shift_date ,x0.shift ,x0.result_type ,x0.symptom_id ,x0.symptom_count from production:"informix".hp_item_defect x0 ,printer_prod:"gap".equipment_group x1 where (x0.equipment_id = x1.equipment_id ) with check option;
Estimated Cost: 9578
Estimated # of Rows Returned: 9502
1) production:informix.hp_item_defect: SEQUENTIAL SCAN
2) printer_prod:gap.equipment_group: INDEX PATH
(1) Index Keys: equipment_id
Lower Index Filter: printer_prod:gap.equipment_group.equipment_id =
production:informix.hp_item_defect.equipment_id
QUERY:
------
select shift_date,shift,test_station,product_number,test_symptom_id ,
quantity
from test_results
where
(product_number = 'C2144A' or product_number = 'C2144D') and
shift_date = '11/8/93' and
shift = 'V'
Estimated Cost: 2
Estimated # of Rows Returned: 1
1) (Temp Table For View): SEQUENTIAL SCAN
Filters: (((Temp Table For View).product_number = 'C2144A' OR
(Temp Table For View).product_number = 'C2144D' )
AND
((Temp Table For View).shift_date = '11/8/93'
AND
(Temp Table For View).shift = 'V' ) )