12
返回列表 发新帖
楼主: yinyanhua820727

請求高手SQL優化挑戰(說明:數據庫為8I)

[复制链接]
论坛徽章:
1
咸鸭蛋
日期:2012-03-29 15:55:06
11#
发表于 2012-4-16 18:18 | 只看该作者
你们直接在主组织做业务?

使用道具 举报

回复
论坛徽章:
7
授权会员
日期:2005-10-30 17:05:33会员2007贡献徽章
日期:2007-09-26 18:42:10ITPUB十周年纪念徽章
日期:2011-11-01 16:19:41鲜花蛋
日期:2012-07-16 15:24:59ITPUB 11周年纪念徽章
日期:2012-10-09 18:05:072013年新春福章
日期:2013-02-25 14:51:24
12#
发表于 2012-4-17 21:21 | 只看该作者
本帖最后由 yiwenvtech 于 2012-4-17 21:23 编辑

1. aa不要放在from,不要关联,直接放在第3步之后的结果集查询里面的select子句用子查询某item的相同subinventory和locator的最后进出仓日期
2. transation date > sysdate - 100000等于没有条件,100000等于几乎100年,请结合具体需要使用一个较短的日期范围试试
3. 尝试不使用group by 和having,如果性能有改善,能快速获得结果集,则再使用select在结果集里再加总和过滤

使用道具 举报

回复
论坛徽章:
7
授权会员
日期:2005-10-30 17:05:33会员2007贡献徽章
日期:2007-09-26 18:42:10ITPUB十周年纪念徽章
日期:2011-11-01 16:19:41鲜花蛋
日期:2012-07-16 15:24:59ITPUB 11周年纪念徽章
日期:2012-10-09 18:05:072013年新春福章
日期:2013-02-25 14:51:24
13#
发表于 2012-4-17 21:26 | 只看该作者
你mtl_system_items_b为table full scan, 可尝试使用hint强制使用索引

使用道具 举报

回复
论坛徽章:
0
14#
 楼主| 发表于 2012-4-25 10:31 | 只看该作者
我現在已經優化成這樣了,可運行了4小時還沒出來
select a.item,
       a.des,
       a.loc,
       a.cla,
       a.sub,
       sum(a.qty),
       a.uom,
       a.t_date2,
       a.factory,
       b.max_date
  from (SELECT /*+rule */
         MSI.SEGMENT1 ITEM,
         MSI.DESCRIPTION DES,
         C.SEGMENT1 LOC,
         mc.segment1 cla,
         mmt.subinventory_code sub,
         mmt.transaction_quantity qty,
         mmt.transaction_uom UOM,
         to_char(MMT.TRANSACTION_DATE, 'yyyy-mm-dd') T_DATE2,
         decode(substr(msi.unit_length, 1, 1),
                1,
                '一厂',
                2,
                '二厂',
                3,
                '三厂',
                6,
                '開發部',
                8,
                '外協',
                '無') factory
          from inv.MTL_MATERIAL_TRANSACTIONS MMT,
               inv.MTL_SYSTEM_ITEMS_B        MSI,
               inv.mtl_item_categories       mic,
               INV.MTL_ITEM_LOCATIONS        C,
               inv.MTL_CATEGORIES_B          MC
         WHERE C.INVENTORY_LOCATION_ID(+) = MMT.LOCATOR_ID
           and mmt.inventory_item_id = MSI.INVENTORY_ITEM_ID
           and mic.inventory_item_id = msi.inventory_item_id
           and mic.category_id = mc.category_id) a,
       ( ----倉庫進倉最後一筆
        select item1, sub1, loc1, max_date
          from (select row_number() over(partition by a.item1, a.sub1, a.loc1 order by a.max_date desc) no,
                        a.item1,
                        a.sub1,
                        a.loc1,
                        a.max_date
                   from (select t.transaction_date  max_date,
                                msb.segment1        item1,
                                t.subinventory_code sub1,
                                mil1.segment1       loc1
                           from inv.mtl_material_transactions t,
                                inv.mtl_system_items_b        msb,
                                inv.mtl_item_locations        mil1
                          where t.inventory_item_id = msb.inventory_item_id
                            and t.locator_id = mil1.inventory_location_id
                            and msb.inventory_item_status_code = 'Active'
                            and t.transaction_quantity > 0) a)
         where no = 1) b
where a.item = b.item1
   and a.sub = b.sub1
   and a.loc = b.loc1
group by a.item,
          a.des,
          a.loc,
          a.cla,
          a.sub,
          a.uom,
          a.t_date2,
          a.factory,
          b.max_date

使用道具 举报

回复
论坛徽章:
0
15#
 楼主| 发表于 2012-4-25 10:32 | 只看该作者
a子查詢裡面的很快,可b子查詢裡面的改為row_number後還是很慢,大家還有沒有其它好辦法啊,有的話請共享,謝謝!

使用道具 举报

回复
论坛徽章:
0
16#
 楼主| 发表于 2012-4-25 10:53 | 只看该作者
select item1, sub1, loc1, max_date
  from (select row_number() over(partition by a.item1, a.sub1, a.loc1 order by a.max_date desc) no,
               a.item1,
               a.sub1,
               a.loc1,
               a.max_date
          from (select /*+rule */t.transaction_date  max_date,
                       msb.segment1        item1,
                       t.subinventory_code sub1,
                       mil1.segment1       loc1
                  from inv.mtl_material_transactions t,
                       inv.mtl_system_items_b        msb,
                       inv.mtl_item_locations        mil1
                 where t.inventory_item_id = msb.inventory_item_id
                   and t.locator_id = mil1.inventory_location_id
                   and msb.inventory_item_status_code = 'Active'
                   and t.transaction_quantity > 0) a)
where no = 1
這段怎麼優化啊?

使用道具 举报

回复
论坛徽章:
0
17#
发表于 2012-4-25 11:37 | 只看该作者
可寫procedure 將倉庫最后一筆insert tmp table,然后再join.

使用道具 举报

回复
论坛徽章:
7
授权会员
日期:2005-10-30 17:05:33会员2007贡献徽章
日期:2007-09-26 18:42:10ITPUB十周年纪念徽章
日期:2011-11-01 16:19:41鲜花蛋
日期:2012-07-16 15:24:59ITPUB 11周年纪念徽章
日期:2012-10-09 18:05:072013年新春福章
日期:2013-02-25 14:51:24
18#
发表于 2012-5-2 21:54 | 只看该作者
select max(t.transaction_date)  max_date,
                                t.subinventory_code sub1,
                                mil1.segment1       loc1
                           from inv.mtl_material_transactions t
where organization_id = ?
  and inventory_item_id = ?
and subinventory_code = ?
and locator_id =?

看看这个语句执行的快不快,如果可以的话可以这样取最近进出库日期(子查询或cursor循环)

使用道具 举报

回复
论坛徽章:
0
19#
发表于 2012-5-3 10:47 | 只看该作者
建议你考虑一下不用MMT table,因为看你就只是抓取库存而已, 你可以考虑一下用MOQ 表

使用道具 举报

回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表