一种sql优化方案

--select @type3Count=count(1) from TWEB_ALogisticsYD bb  
-- LEFT JOIN dbo.TWEB_BCompanyJJ as B3 WITH(NOLOCK) ON B3.CompanyNo=bb.Col_117  
--where bb.Col_062 is not null and Col_049 is not null and (
--(( bb.Col_043=@CompanyNO or (bb.Col_117=@CompanyNO and bb.Col_117<>Col_043 and bb.Col_117<>isnull(bb.Col_051,'')))   AND bb.COL_117 NOT IN ( N'57378369305', N'02850617763', N'75772902711' ))
-- or (bb.Col_045=@Phone or   bb.Col_092=@Phone)
-- ) and (B3.LoadFlag IS NULL OR B3.LoadFlag=0)
SELECT  @type3Count=COUNT(1) FROM ( 
    SELECT bb.Col_003,bb.Col_117
    FROM TWEB_ALogisticsYD bb
    WHERE bb.Col_062 IS NOT NULL AND Col_049 IS NOT NULL
    AND (
            (bb.Col_043 = @CompanyNO OR (bb.Col_117 = @CompanyNO AND bb.Col_117 <> Col_043 AND bb.Col_117 <> ISNULL(bb.Col_051, '')))
            AND bb.Col_117 NOT IN (N'57378369305', N'02850617763', N'75772902711')
        )

    UNION

    SELECT bb.Col_003,bb.Col_117
    FROM TWEB_ALogisticsYD bb
    WHERE bb.Col_062 IS NOT NULL AND Col_049 IS NOT NULL AND (bb.Col_045 = @Phone OR bb.Col_092 = @Phone)
) AS t
LEFT JOIN dbo.TWEB_BCompanyJJ AS B3 WITH ( NOLOCK ) ON B3.CompanyNo = t.Col_117
where B3.LoadFlag IS NULL OR B3.LoadFlag = 0

两个表用or关联的 把or拆开

 

第二种方案

select @type9Count=count(1) from TWEB_ALogisticsYD bb
LEFT JOIN dbo.TWEB_BCompanyJJ as B3 WITH(NOLOCK) ON B3.CompanyNo=bb.Col_117

这一句用的比较多,数据都在TWEB_ALogisticsY 中 可以先通过条件 把TWEB_ALogisticsYD的数据先查出来。放到中间表中 再进行关联

----------------------------------

task的异步方式

Task.Run(() =>
{
try
{
l.model.FourLevelID = DAL.TB_AddressInfoDAL.GetFourLevelID(l.model.AdminCode);
l.model.DetailAddressType = 1;
//地图慧取到点部的地址反写到地址库表中

DAL.TB_AddressInfoDAL.Add(l.model);
l.model.Location = 2;
l.model.Source = "客户端";
DAL.TB_AddressInfoDAL.AddToSource(l.model, "HandleAddress_V2_2");//插入统计表
}
catch (Exception ex)
{
NLog.LogManager.GetCurrentClassLogger().Error(ex, "UploadYdList_Client回写数据->model:{0}", JsonConvert.SerializeObject(l.model));
}
});

---------------------------------------------

Parallel.For(0, forNum, i =>
{
Dictionary<string, string> dic = new Dictionary<string, string>();
dic.Add("ak", AppConst.DituhuiAk);
dic.Add("addresses", JsonConvert.SerializeObject(post.Skip(i * size).Take(size)));
dic.Add("need_district", "true");
dic.Add("callback", "");
dic.Add("related_point_fields", "name");

res.Add(HttpHelper.PostFormData(url, dic));
});

 

Parallel 的并行方式

select xx,phone FROM send  a JOIN (
 select '13891030091' phone  union select '13992085916' …………  UNION  SELECT '13619100234' ) b 
  on  a.Phone=b.phone
--替代下面  很多数据隔开的时候
in('13891030091','13992085916','13619100234'…………)

 

posted on 2017-12-27 14:38  雪原日暮  阅读(138)  评论(0编辑  收藏  举报