Home » RDBMS Server » Server Administration » Query Tunning
Query Tunning [message #372075] Tue, 09 January 2001 06:43 Go to next message
sandeep
Messages: 110
Registered: October 2000
Senior Member
I want this query to be optimised. Is there any way I can do it?
The query goes like this.
SELECT DISTINCT toh.order_nb,"
toh.compaq_sales_organization_cd "SalesOrgCode",
toh.cust_ship_to_id "ShipID",
c1.detail_tx "Status",
toh.order_dt "OrderDate",
toh.order_close_dt "CloseDate",
toh.sold_to_party "SoldtoId",
tod.cust_po_nb "PoNB",
ts.SHIP_FROM_ID "ShipFromId",
ts.CARRIER_CD "CarrierId"

FROM tms_order_header toh,
tms_code_table_detail c1,
tms_order_detail tod,
TMS_SHIPMENT ts,
TMS_ORDER tmo

WHERE c1.detail_cd(+) = toh.order_status_cd
AND c1.group_cd (+)= 'OSD'
AND tod.compaq_sales_organization_cd = toh.compaq_sales_organization_cd
AND toh.order_dt > ( SELECT ADD_MONTHS(SYSDATE,-3)
FROM dual )
AND tod.order_nb = toh.order_nb
AND ts.SHIPMENT_ID = tmo.SHIPMENT_ID
AND tmo.ORDER_NB = toh.ORDER_NB

1. All the columns in the query are indexed.
2. All the big tables are in the left side of the join.
3.
Re: Query Tunning - some pointers... [message #372086 is a reply to message #372075] Tue, 09 January 2001 13:06 Go to previous messageGo to next message
Andrew again...
Messages: 270
Registered: July 2000
Senior Member
1.) make sure that the tables are analyzed (analyze table tms_order_header estimate statistics; etc.)

2.) replace the unnecessary subquery with:
> add_months(sysdate, -3). (This wont help much though).

3.) Do an explain plan on the query (TOAD is great for this, else use "set autotrace on" in sql*plus). "set timing on" to get duration.

4.) remember that the where clause (apart from the join) gets evaluated from the bottom up. Place most selective statement at the bottom.

5.) The order of the tables in the FROM clause can make a difference. Smallest ones first (or ones with least refererential integrity???)
Re: Query Tunning [message #372093 is a reply to message #372075] Tue, 09 January 2001 22:33 Go to previous message
Sandeep Udupa
Messages: 9
Registered: January 2001
Junior Member
Thanks
Previous Topic: Equivalent of "Database Link"?
Next Topic: Returning a value to VB
Goto Forum:
  


Current Time: Fri May 17 03:24:35 CDT 2024