Connecting Tech Pros Worldwide Forums | Help | Site Map

Tuning The Sql Query

Newbie
 
Join Date: Sep 2007
Posts: 2
#1: Sep 20 '07
Hi,

This is Bhargav and I am trying to tune this query that is being used in a discoverer report and the columns in the select statement are the ones that are to be displayed in the discoverer output.

Can somebody help me as top how to tune this query. Any sort of help is greatly appreciated , as this is of high priority.

Regards,

Bhargav.

Expand|Select|Wrap|Line Numbers
  1. select
  2.   cost_orgs.organization_code || ' - ' || cost_orgs.organization_name cost_org,
  3.   on_hand_orgs.organization_code || ' - ' || on_hand_orgs.organization_name on_hand_org,
  4.   msi.segment1 item_name,
  5.   msi.description item_desc,
  6.   mcb.segment1 cost_cat_1,
  7.   mcb.segment2 cost_cat_2,
  8.   mcb.segment3 cost_cat_3,
  9.   mcb.segment1 || '.' || mcb.segment2 || '.' || mcb.segment3 cost_category,
  10.   upper(ctf1.cost_type) cost_type_1,
  11.   cicf1.item_cost item_cost_1,
  12.   cicf1.material_cost mtl_cost_1,
  13.   upper(ctf2.cost_type) cost_type_2,
  14.   cicf2.item_cost item_cost_2,
  15.   cicf2.material_cost mtl_cost_2,
  16.   sum(moh.transaction_quantity) on_hand_qty,
  17.   decode(msi.planning_make_buy_code,1,'M','B') make_buy_flag
  18. from
  19. --  mtl_parameters mp,
  20.   cst_item_costs cicf1,
  21.   cst_cost_types ctf1,
  22.   cst_item_costs cicf2,
  23.   cst_cost_types ctf2,
  24.   mtl_onhand_quantities moh,
  25.   inv.mtl_categories_b mcb,
  26.   inv.mtl_item_categories mic,
  27. --  inv.mtl_category_sets_tl mcst,
  28.   org_organization_definitions cost_orgs,
  29.   org_organization_definitions on_hand_orgs,
  30.   inv.mtl_system_items_b msi
  31. where 1=1
  32. and cost_orgs.organization_id = msi.organization_id
  33. and cicf1.organization_id = msi.organization_id
  34. and cicf1.inventory_item_id = msi.inventory_item_id
  35. and ctf1.cost_type_id = cicf1.cost_type_id --this should be set to frozen
  36. and cicf2.organization_id = msi.organization_id  --cross-product between sets will be resolved by Discoverer parameters
  37. and cicf2.inventory_item_id = msi.inventory_item_id
  38. and ctf2.cost_type_id = cicf2.cost_type_id
  39. and moh.organization_id = on_hand_orgs.ORGANIZATION_ID
  40. and moh.inventory_item_id = msi.inventory_item_id
  41. and mic.organization_id (+) = msi.organization_id
  42. and mic.inventory_item_id (+) = msi.inventory_item_id
  43. and mic.category_set_id (+) = 1100000006 --inventory cost category
  44. and mcb.category_id (+)= mic.category_id -- the inventory cost category consisists of mcb. segment1,2 and 3
  45. --and mcst.CATEGORY_SET_ID = mic.CATEGORY_SET_ID
  46. --and mcst.CATEGORY_SET_NAME = 'QC INVENTORY CATEGORY'
  47. --and msi.inventory_item_id = 512
  48. --and cicf1.COST_TYPE_ID = 1
  49. --and cicf2.COST_TYPE_ID = 1101
  50. --and msi.ORGANIZATION_ID = 89
  51. group by
  52.   cost_orgs.organization_code || ' - ' || cost_orgs.organization_name,
  53.   on_hand_orgs.organization_code || ' - ' || on_hand_orgs.organization_name,
  54.   msi.segment1,
  55.   msi.description,
  56.   mcb.segment1,
  57.   mcb.segment2,
  58.   mcb.segment3,
  59.   mcb.segment1 || '.' || mcb.segment2 || '.' || mcb.segment3,
  60.   upper(ctf1.cost_type),
  61.   cicf1.item_cost,
  62.   cicf1.material_cost,
  63.   upper(ctf2.cost_type),
  64.   cicf2.item_cost,
  65.   cicf2.material_cost,
  66.   decode(msi.planning_make_buy_code,1,'M','B')
  67.  --order by msi.SEGMENT1
/

amitpatel66's Avatar
Moderator
 
Join Date: Mar 2007
Location: Hyderabad, India
Posts: 2,192
#2: Sep 21 '07

re: Tuning The Sql Query


Make use of HINTS in the query (HINT - INDEX,PARALLEL will be helpful)
Newbie
 
Join Date: Sep 2007
Posts: 2
#3: Sep 21 '07

re: Tuning The Sql Query


Hi Amit,

I am not so familiar with using Hints in the sql query.

Can you pls give a small example and tell me which hint to use in this scenario, where so many joins are there.

Will appreciate your response in the earliest possible time.

Thanks,

Bhargav.
amitpatel66's Avatar
Moderator
 
Join Date: Mar 2007
Location: Hyderabad, India
Posts: 2,192
#4: Sep 21 '07

re: Tuning The Sql Query


Quote:

Originally Posted by orasolve

Hi Amit,

I am not so familiar with using Hints in the sql query.

Can you pls give a small example and tell me which hint to use in this scenario, where so many joins are there.

Will appreciate your response in the earliest possible time.

Thanks,

Bhargav.

Hi Bhargav,

You can make us of HINTS in your sql query to improve the performance of the Query.

There are many HINTS availabe with oracle that can be used but to make use of
the appropriate one will improve the performance.

See below example on making use of INDEX HINT in SQL Query:

Expand|Select|Wrap|Line Numbers
  1. SELECT /* INDEX(<table_alias>,<index_name>) */ FROM table_name table_alias
  2.  
Find more about INDEX HINT here

Another HINT PARALLEL can be used for parallel execution of your Query.
See more about usage of PARALLEL HINT here
Reply