求教: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'