求教:Sybase多表关联性能优化

安德烈_T 2012-04-18 05:55:11
SQL如下:
declare @license_id varchar(90), @purchase_type varchar(20),@org_type varchar(10), @maker_code varchar(30),@order_day int,@order_date datetime
set @maker_code='MSKK0',@license_id='MSKK0002,MSKK0001', @purchase_type='ADDBIZ', @org_type='CO',@order_day=0
set @order_date = dateadd(dd,@order_day,getdate())

select distinct sig.item_group_id, sig.item_group_id_p, sig.item_group_name, sig.priority, psig.item_group_id p_item_group_id,psig.item_group_name p_item_group_name , psig.priority p_priority
from swl_license_group_link slgl inner join swl_item_group sig
on slgl.item_group_id = sig.item_group_id
inner join swl_item_unit siu
on sig.item_group_id = siu.item_group_id and status='0' and maker_code=@maker_code
and ((@org_type='CO' and target_co='1') or (@org_type='AC' and target_ac='1') or (@org_type='GO' and target_go='1'))
inner join swl_unit_item_link suil
on suil.item_unit_id = siu.item_unit_id
inner join part_master pm
on suil.item_code = pm.part_no and pm.lifecycle_status='AP' and pm.active_status='A' and pm.avail_to_sell='Y'
inner join sku_swl ss
on pm.sku_no =ss.sku_no and ((@org_type='CO' and salse_target_corp='1') or (@org_type='AC' and sales_target_edu='1') or (@org_type='GO' and sales_target_pub='1'))
inner join sku_extension se
on pm.sku_no=se.sku_no and first_so_date<=@order_date and last_so_date>=@order_date
inner join swl_item_group psig
on sig.item_group_id_p = psig.item_group_id
where slgl.license_id = @license_id and slgl.purchase_type = @purchase_type
union
select distinct sig.item_group_id, sig.item_group_id_p, sig.item_group_name, sig.priority, psig.item_group_id p_item_group_id,psig.item_group_name p_item_group_name , psig.priority p_priority
from swl_license_group_link slgl inner join swl_item_group sig
on slgl.item_group_id = sig.item_group_id
inner join swl_item_unit siu
on sig.item_group_id = siu.item_group_id and status='0' and maker_code=@maker_code
and ((@org_type='CO' and target_co='1') or (@org_type='AC' and target_ac='1') or (@org_type='GO' and target_go='1'))
inner join swl_unit_item_link suil
on suil.item_unit_id = siu.item_unit_id
inner join part_master pm
on suil.item_code = pm.part_no and pm.lifecycle_status='AP' and pm.active_status='A' and pm.avail_to_sell='Y'
inner join sku_swl ss
on pm.sku_no =ss.sku_no and ((@org_type='CO' and salse_target_corp='1') or (@org_type='AC' and sales_target_edu='1') or (@org_type='GO' and sales_target_pub='1'))
inner join sku_extension se
on pm.sku_no=se.sku_no and first_so_date<=@order_date and last_so_date>=@order_date
inner join swl_item_group psig
on sig.item_group_id_p = psig.item_group_id
where slgl.license_id = @license_id and slgl.purchase_type = 'DEFAULT'

...全文
133 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
baiynije 2012-04-19
  • 打赏
  • 举报
回复
寫這麼長的SQL的原因是什麼?
安德烈_T 2012-04-18
  • 打赏
  • 举报
回复
Total estimated I/O cost for statement 2 (at line 10): 2926.

Parse and Compile Time 1.
SQL Server cpu time: 100 ms.
Table: swl_license_group_link scan count 6356, logical reads: (regular=19076 apf=0 total=19076), physical reads: (regular=0 apf=0 total=0), apf IOs used=0
Table: swl_item_group scan count 6356, logical reads: (regular=19185 apf=0 total=19185), physical reads: (regular=0 apf=0 total=0), apf IOs used=0
Table: swl_item_unit scan count 1, logical reads: (regular=16470 apf=0 total=16470), physical reads: (regular=0 apf=0 total=0), apf IOs used=0
Table: swl_unit_item_link scan count 1228, logical reads: (regular=3744 apf=0 total=3744), physical reads: (regular=0 apf=0 total=0), apf IOs used=0
Table: part_master scan count 2438, logical reads: (regular=9773 apf=0 total=9773), physical reads: (regular=0 apf=0 total=0), apf IOs used=0
Table: sku_swl scan count 1920, logical reads: (regular=5760 apf=0 total=5760), physical reads: (regular=0 apf=0 total=0), apf IOs used=0
Table: sku_extension scan count 1920, logical reads: (regular=7680 apf=0 total=7680), physical reads: (regular=0 apf=0 total=0), apf IOs used=0
Table: swl_item_group scan count 1920, logical reads: (regular=5760 apf=0 total=5760), physical reads: (regular=0 apf=0 total=0), apf IOs used=0
Table: swl_license_group_link scan count 6356, logical reads: (regular=19068 apf=0 total=19068), physical reads: (regular=0 apf=0 total=0), apf IOs used=0
Table: swl_item_group scan count 6356, logical reads: (regular=19185 apf=0 total=19185), physical reads: (regular=0 apf=0 total=0), apf IOs used=0
Table: swl_item_unit scan count 1, logical reads: (regular=16470 apf=0 total=16470), physical reads: (regular=0 apf=0 total=0), apf IOs used=0
Table: swl_unit_item_link scan count 0, logical reads: (regular=0 apf=0 total=0), physical reads: (regular=0 apf=0 total=0), apf IOs used=0
Table: part_master scan count 0, logical reads: (regular=0 apf=0 total=0), physical reads: (regular=0 apf=0 total=0), apf IOs used=0
Table: sku_swl scan count 0, logical reads: (regular=0 apf=0 total=0), physical reads: (regular=0 apf=0 total=0), apf IOs used=0
Table: sku_extension scan count 0, logical reads: (regular=0 apf=0 total=0), physical reads: (regular=0 apf=0 total=0), apf IOs used=0
Table: swl_item_group scan count 0, logical reads: (regular=0 apf=0 total=0), physical reads: (regular=0 apf=0 total=0), apf IOs used=0
The sort for Worktable1 is done in Serial
Table: Worktable1 scan count 0, logical reads: (regular=2072 apf=0 total=2072), physical reads: (regular=0 apf=0 total=0), apf IOs used=0
Total actual I/O cost for this command: 4144.
Total writes for this command: 0

Execution Time 120.
SQL Server cpu time: 12000 ms. SQL Server elapsed time: 12143 ms.
(144 rows affected)
------------------------- Done --------------------------
安德烈_T 2012-04-18
  • 打赏
  • 举报
回复
执行过程如下:
------------------------ Execute ------------------------
Total actual I/O cost for this command: 0.
Total writes for this command: 0

Execution Time 0.
SQL Server cpu time: 0 ms. SQL Server elapsed time: 0 ms.
Total actual I/O cost for this command: 0.
Total writes for this command: 0

Execution Time 0.
SQL Server cpu time: 0 ms. SQL Server elapsed time: 0 ms.
(1 rows affected)
Total actual I/O cost for this command: 0.
Total writes for this command: 0

Execution Time 0.
SQL Server cpu time: 0 ms. SQL Server elapsed time: 0 ms.
(1 rows affected)

QUERY PLAN FOR STATEMENT 1 (at line 0).


STEP 1
The type of query is DECLARE.

Total estimated I/O cost for statement 1 (at line 0): 0.


QUERY PLAN FOR STATEMENT 2 (at line 10).


STEP 1
The type of query is INSERT.
The update mode is direct.

FROM TABLE
swl_item_unit
siu
Nested iteration.
Table Scan.
Forward scan.
Positioning at start of table.
Using I/O Size 16 Kbytes for data pages.
With LRU Buffer Replacement Strategy for data pages.

FROM TABLE
swl_item_group
sig
Nested iteration.
Using Clustered Index.
Index : swl_item_groupI1
Forward scan.
Positioning by key.
Keys are:
item_group_id ASC
Using I/O Size 4 Kbytes for data pages.
With LRU Buffer Replacement Strategy for data pages.

FROM TABLE
swl_license_group_link
slgl
EXISTS TABLE : nested iteration.
Using Clustered Index.
Index : swl_license_group_linkI1
Forward scan.
Positioning by key.
Keys are:
license_id ASC
purchase_type ASC
item_group_id ASC
Using I/O Size 4 Kbytes for data pages.
With LRU Buffer Replacement Strategy for data pages.

FROM TABLE
swl_unit_item_link
suil
Nested iteration.
Using Clustered Index.
Index : swl_unit_item_linkI1
Forward scan.
Positioning by key.
Keys are:
item_unit_id ASC
Using I/O Size 4 Kbytes for data pages.
With LRU Buffer Replacement Strategy for data pages.

FROM TABLE
part_master
pm
Nested iteration.
Index : part_masterI2
Forward scan.
Positioning by key.
Keys are:
part_no ASC
Using I/O Size 4 Kbytes for index leaf pages.
With LRU Buffer Replacement Strategy for index leaf pages.
Using I/O Size 4 Kbytes for data pages.
With LRU Buffer Replacement Strategy for data pages.

FROM TABLE
sku_swl
ss
EXISTS TABLE : nested iteration.
Using Clustered Index.
Index : sku_swlI1
Forward scan.
Positioning by key.
Keys are:
sku_no ASC
Using I/O Size 4 Kbytes for data pages.
With LRU Buffer Replacement Strategy for data pages.

FROM TABLE
sku_extension
se
EXISTS TABLE : nested iteration.
Using Clustered Index.
Index : sku_extensionI1
Forward scan.
Positioning by key.
Keys are:
sku_no ASC
Using I/O Size 4 Kbytes for data pages.
With LRU Buffer Replacement Strategy for data pages.

FROM TABLE
swl_item_group
psig
Nested iteration.
Using Clustered Index.
Index : swl_item_groupI1
Forward scan.
Positioning by key.
Keys are:
item_group_id ASC
Using I/O Size 4 Kbytes for data pages.
With LRU Buffer Replacement Strategy for data pages.
TO TABLE
Worktable1.

STEP 1
The type of query is INSERT.
The update mode is direct.

FROM TABLE
swl_item_unit
siu
Nested iteration.
Table Scan.
Forward scan.
Positioning at start of table.
Using I/O Size 16 Kbytes for data pages.
With LRU Buffer Replacement Strategy for data pages.

FROM TABLE
swl_item_group
sig
Nested iteration.
Using Clustered Index.
Index : swl_item_groupI1
Forward scan.
Positioning by key.
Keys are:
item_group_id ASC
Using I/O Size 4 Kbytes for data pages.
With LRU Buffer Replacement Strategy for data pages.

FROM TABLE
swl_license_group_link
slgl
EXISTS TABLE : nested iteration.
Using Clustered Index.
Index : swl_license_group_linkI1
Forward scan.
Positioning by key.
Keys are:
license_id ASC
purchase_type ASC
item_group_id ASC
Using I/O Size 4 Kbytes for data pages.
With LRU Buffer Replacement Strategy for data pages.

FROM TABLE
swl_unit_item_link
suil
Nested iteration.
Using Clustered Index.
Index : swl_unit_item_linkI1
Forward scan.
Positioning by key.
Keys are:
item_unit_id ASC
Using I/O Size 4 Kbytes for data pages.
With LRU Buffer Replacement Strategy for data pages.

FROM TABLE
part_master
pm
Nested iteration.
Index : part_masterI2
Forward scan.
Positioning by key.
Keys are:
part_no ASC
Using I/O Size 4 Kbytes for index leaf pages.
With LRU Buffer Replacement Strategy for index leaf pages.
Using I/O Size 4 Kbytes for data pages.
With LRU Buffer Replacement Strategy for data pages.

FROM TABLE
sku_swl
ss
EXISTS TABLE : nested iteration.
Using Clustered Index.
Index : sku_swlI1
Forward scan.
Positioning by key.
Keys are:
sku_no ASC
Using I/O Size 4 Kbytes for data pages.
With LRU Buffer Replacement Strategy for data pages.

FROM TABLE
sku_extension
se
EXISTS TABLE : nested iteration.
Using Clustered Index.
Index : sku_extensionI1
Forward scan.
Positioning by key.
Keys are:
sku_no ASC
Using I/O Size 4 Kbytes for data pages.
With LRU Buffer Replacement Strategy for data pages.

FROM TABLE
swl_item_group
psig
Nested iteration.
Using Clustered Index.
Index : swl_item_groupI1
Forward scan.
Positioning by key.
Keys are:
item_group_id ASC
Using I/O Size 4 Kbytes for data pages.
With LRU Buffer Replacement Strategy for data pages.
TO TABLE
Worktable1.

STEP 1
The type of query is SELECT.
This step involves sorting.

FROM TABLE
Worktable1.
Using GETSORTED
Table Scan.
Forward scan.
Positioning at start of table.
Using I/O Size 16 Kbytes for data pages.
With MRU Buffer Replacement Strategy for data pages.

2,596

社区成员

发帖
与我相关
我的任务
社区描述
Sybase相关技术讨论区
社区管理员
  • Sybase社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧