SQL 优化

[复制链接]
查看11 | 回复6 | 2008-9-4 11:36:41 | 显示全部楼层 |阅读模式
各位大侠,帮我优化一下这段SQL,谢谢了
SELECT DISTINCT mmt.subinventory_code, mmt.inventory_item_id
FROM cux_invgcpor inv, mtl_material_transactions mmt
WHERE 1 = 1
AND mmt.subinventory_code = inv.subinventory_code
AND inv.org_id = mmt.organization_id
AND (mmt.organization_id = 215 OR mmt.organization_id = 3)
回复

使用道具 举报

千问 | 2008-9-4 11:36:41 | 显示全部楼层

目前给出的信息太少, 给出目前2表的数据量,2表哪些列建了index, 目前语句执行后的执行计划和统计数据!

回复

使用道具 举报

千问 | 2008-9-4 11:36:41 | 显示全部楼层
收集表和索引的统计信息先,有直方图把直方图也搜集下
回复

使用道具 举报

千问 | 2008-9-4 11:36:41 | 显示全部楼层
SELECTmmt.subinventory_code, mmt.inventory_item_id
FROM cux_invgcpor inv, mtl_material_transactions mmt
WHERE mmt.subinventory_code = inv.subinventory_code
AND inv.org_id = mmt.organization_id
AND mmt.organization_id = 215
AND inv.org_id
= 215
union
SELECTmmt.subinventory_code, mmt.inventory_item_id
FROM cux_invgcpor inv, mtl_material_transactions mmt
WHERE mmt.subinventory_code = inv.subinventory_code
AND inv.org_id = mmt.organization_id
AND mmt.organization_id = 3
AND inv.org_id
= 3
机构上面有索引吗?有的话像上面or展开试验一下。
回复

使用道具 举报

千问 | 2008-9-4 11:36:41 | 显示全部楼层
发现 inv表的存在 完全是为了验证 mmt数据项是否存在所以 习惯下面写法效率还是要看数据
SELECT DISTINCT mmt.subinventory_code, mmt.inventory_item_id
FROMmtl_material_transactions mmt
WHERE (mmt.organization_id = 215 OR mmt.organization_id = 3)
ANDEXISTS
(SELECT1 FROM cux_invgcpor inv WHEREmmt.subinventory_code = inv.subinventory_codeANDinv.org_id = mmt.organization_id )
回复

使用道具 举报

千问 | 2008-9-4 11:36:41 | 显示全部楼层
mmt 这个表数据太多了,是物料事务处理表,所有的物料进出仓都会经过此表,所以慢啊,
回复

使用道具 举报

千问 | 2008-9-4 11:36:41 | 显示全部楼层
最起码 给个 执行计划啥的啊!!!
回复

使用道具 举报

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

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行