Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> tuning a query on union_all view..
we have an union_all view (don't ask why)
SELECT
order_id
,'REGULAR'
,id
,product_id
,discount_code_id
,price
,quantity
,fulfilled_state
,subscription_renewal_code
,create_ts
,update_ts
order_id
,'GIFT'
,id
,product_id
,discount_code_id
,price
,quantity
,fulfilled_state
,subscription_renewal_code
,create_ts
,update_ts
the tables are pretty much identical
so r the indexes..
as you can see the following query uses both indices
select * from test_all_order_items where order_id=:var
0 SELECT STATEMENTCost=
1 VIEW TEST_ALL_ORDER_ITEMS
2 UNION-ALL 3 TABLE ACCESS ORDER_ITEMS 4 INDEX ORDER_ITEMS_ORDERS 5 TABLE ACCESS GIFT_ORDER_ITEMS 6 INDEX GIFT_ITEMS_ORDERS
2* select id from orders where member_id=1
0 SELECT STATEMENTCost=
1 TABLE ACCESS ORDERS
2 INDEX ORDERS_MEMBERS
while this query fails to utilize the needed indices... why?
select * from test_all_order_items t, orders o
where t.order_id = o.id and o.member_id = 2682
0 SELECT STATEMENTCost=
1 NESTED LOOPS
2 VIEW TEST_ALL_ORDER_ITEMS 3 UNION-ALL 4 TABLE ACCESS ORDER_ITEMS 5 TABLE ACCESS GIFT_ORDER_ITEMS 6 TABLE ACCESS ORDERS 7 INDEX ORDERS_PK
We are using rule-based optimizer.. this is 8.1.7
thnx.
.......
We use Oracle 8.1.6-8.1.7 on Solaris 2.6, 2.7 boxes
Andrey Dmitriev eFax: (978) 383-5892 Daytime: (917) 750-3630 AOL: NetComrade ICQ: 11340726 remove NSPAM to emailReceived on Fri Dec 07 2001 - 11:00:36 CST