在IQueryable对象上应用where子句时,如何提高LINQ查询性能

时间:2016-10-11 11:02:01

标签: c# sql-server entity-framework linq iqueryable

我正在使用实体框架并使用我的LINQ查询中的where子句过滤记录会对性能产生巨大影响,例如:

public IQueryable<CUST> GetSearchCustomerQuery(Entities ctx, SearchVM model=null)
{
  var query = ctx.CUST.AsNoTracking().AsQueryable();

  var strcmpy = (string)HttpContext.Current.Session[En_UserSession.CustCompanyId.ToString()];
  var multiselectcmpList = strcmpy.Split(',').Select(n => Convert.ToInt32(n)).ToArray();

  query = query.Where(c => multiselectcmpList.Contains(c.B_BILL_CO.Value)).AsNoTracking();

  if(model.StatusIds != null)
  {
       var lststatus = ctx.UDEF.Where(u => u.NAME == "CUSTSTAT" && model.StatusIds.Contains(u.UNIQUE_ID)).Select(c => c.DATA).AsNoTracking();
       stParameter += "Status = " + string.Join(",", lststatus) + "\r";
  }

  if (model.PO != null)
  {
       query = query.Join(ctx.HIST, cu => cu.C_ID, hist => hist.C_ID, (cu, hist) => new { customer = cu, hist = hist }).Where(hist => hist.hist.PO_NUMBER.Contains(model.PO)).Select(recset => recset.customer).AsNoTracking();
                    stParameter += "P.O. = " + model.PO + "\r";
  }

  return query;
}

问题似乎LINQ在生成的SQL中的查询比较中创建嵌套或子查询,如下所示。

exec sp_executesql N'SELECT TOP (250) 
    [Project1].[C_ID] AS [C_ID], 
    [Project1].[C_ID_ALPHA] AS [C_ID_ALPHA], 
    [Project1].[C_NAME] AS [C_NAME], 
    [Project1].[C_NAME2] AS [C_NAME2], 
    [Project1].[C_ADDR1] AS [C_ADDR1], 
    [Project1].[C_ADDRNUM1] AS [C_ADDRNUM1], 
    [Project1].[C_ADDR2] AS [C_ADDR2], 
    [Project1].[C_CITY] AS [C_CITY], 
    [Project1].[C_STATE] AS [C_STATE], 
    [Project1].[C_ZIP] AS [C_ZIP], 
    [Project1].[C_PHO] AS [C_PHO], 
    [Project1].[C_PCONT] AS [C_PCONT], 
    [Project1].[C_FAX] AS [C_FAX], 
    [Project1].[C_FCONT] AS [C_FCONT], 
    [Project1].[C_CSTAT] AS [C_CSTAT], 
    [Project1].[C_SALESREP] AS [C_SALESREP], 
    [Project1].[C_QUOTE] AS [C_QUOTE], 
    [Project1].[C_ENDDATE] AS [C_ENDDATE], 
    [Project1].[C_TYPE] AS [C_TYPE], 
    [Project1].[C_RTES] AS [C_RTES], 
    [Project1].[C_NRTES] AS [C_NRTES], 
    [Project1].[C_LOCS] AS [C_LOCS], 
    [Project1].[C_NLOCS] AS [C_NLOCS], 
    [Project1].[C_SUFFIX] AS [C_SUFFIX], 
    [Project1].[ISCHILD] AS [ISCHILD], 
    [Project1].[C_BILL_TO] AS [C_BILL_TO], 
    [Project1].[C_COMMENTS] AS [C_COMMENTS], 
    [Project1].[C_MEMO] AS [C_MEMO], 
    [Project1].[C_LST_PAY] AS [C_LST_PAY], 
    [Project1].[C_LST_DATE] AS [C_LST_DATE], 
    [Project1].[C_PRV_BAL] AS [C_PRV_BAL], 
    [Project1].[C_CUR_BAL] AS [C_CUR_BAL], 
    [Project1].[C_UN_BILL] AS [C_UN_BILL], 
    [Project1].[C_CUR_DUE] AS [C_CUR_DUE], 
    [Project1].[C_30D] AS [C_30D], 
    [Project1].[C_60D] AS [C_60D], 
    [Project1].[C_90D] AS [C_90D], 
    [Project1].[C_FIN_CHG] AS [C_FIN_CHG], 
    [Project1].[B_NAME] AS [B_NAME], 
    [Project1].[B_NAME2] AS [B_NAME2], 
    [Project1].[B_ADDR1] AS [B_ADDR1], 
    [Project1].[B_ADDR2] AS [B_ADDR2], 
    [Project1].[B_CITY] AS [B_CITY], 
    [Project1].[B_STATE] AS [B_STATE], 
    [Project1].[B_ZIP] AS [B_ZIP], 
    [Project1].[B_PHO] AS [B_PHO], 
    [Project1].[B_PCONT] AS [B_PCONT], 
    [Project1].[B_FAX] AS [B_FAX], 
    [Project1].[B_FCONT] AS [B_FCONT], 
    [Project1].[B_B_CYCLE] AS [B_B_CYCLE], 
    [Project1].[B_TAXABLE] AS [B_TAXABLE], 
    [Project1].[B_ACCTTYPE] AS [B_ACCTTYPE], 
    [Project1].[B_FIN_DESC] AS [B_FIN_DESC], 
    [Project1].[B_DELINQ] AS [B_DELINQ], 
    [Project1].[B_STMT_TYP] AS [B_STMT_TYP], 
    [Project1].[B_BILL_TYP] AS [B_BILL_TYP], 
    [Project1].[B_BILL_CO] AS [B_BILL_CO], 
    [Project1].[B_PO_NUM] AS [B_PO_NUM], 
    [Project1].[B_SUSPENDS] AS [B_SUSPENDS], 
    [Project1].[B_SUSPENDE] AS [B_SUSPENDE], 
    [Project1].[B_STRT_DAT] AS [B_STRT_DAT], 
    [Project1].[B_STOP_DAT] AS [B_STOP_DAT], 
    [Project1].[B_STRT_STA] AS [B_STRT_STA], 
    [Project1].[B_STOP_STA] AS [B_STOP_STA], 
    [Project1].[B_STRT_COD] AS [B_STRT_COD], 
    [Project1].[B_STOP_COD] AS [B_STOP_COD], 
    [Project1].[B_STRT_AMT] AS [B_STRT_AMT], 
    [Project1].[B_STOP_AMT] AS [B_STOP_AMT], 
    [Project1].[B_CONTRACT] AS [B_CONTRACT], 
    [Project1].[B_CONTAINS] AS [B_CONTAINS], 
    [Project1].[B_GRID] AS [B_GRID], 
    [Project1].[B_AREA] AS [B_AREA], 
    [Project1].[B_PAYBYCC] AS [B_PAYBYCC], 
    [Project1].[B_MTD] AS [B_MTD], 
    [Project1].[B_YTD] AS [B_YTD], 
    [Project1].[B_LMTD] AS [B_LMTD], 
    [Project1].[B_LYTD] AS [B_LYTD], 
    [Project1].[C_UNAPPLIED] AS [C_UNAPPLIED], 
    [Project1].[B_CONTRACT_NUM] AS [B_CONTRACT_NUM], 
    [Project1].[B_CONTRACT_DATE] AS [B_CONTRACT_DATE], 
    [Project1].[C_15D] AS [C_15D], 
    [Project1].[C_45D] AS [C_45D], 
    [Project1].[REFERRAL] AS [REFERRAL], 
    [Project1].[SREP1] AS [SREP1], 
    [Project1].[SREP2] AS [SREP2], 
    [Project1].[CREP1] AS [CREP1], 
    [Project1].[CREP2] AS [CREP2], 
    [Project1].[B_NAME_2ND] AS [B_NAME_2ND], 
    [Project1].[B_NAME_2ND2] AS [B_NAME_2ND2], 
    [Project1].[B_ADDR1_2ND] AS [B_ADDR1_2ND], 
    [Project1].[B_ADDR1_2ND2] AS [B_ADDR1_2ND2], 
    [Project1].[B_CITY_2ND] AS [B_CITY_2ND], 
    [Project1].[B_STATE_2ND] AS [B_STATE_2ND], 
    [Project1].[B_ZIP_2ND] AS [B_ZIP_2ND], 
    [Project1].[C_DEPOSIT] AS [C_DEPOSIT], 
    [Project1].[CREP1_NOTES] AS [CREP1_NOTES], 
    [Project1].[CREP2_NOTES] AS [CREP2_NOTES], 
    [Project1].[SREP1_NOTES] AS [SREP1_NOTES], 
    [Project1].[SREP2_NOTES] AS [SREP2_NOTES], 
    [Project1].[C_TYPE2] AS [C_TYPE2], 
    [Project1].[C_TYPE3] AS [C_TYPE3], 
    [Project1].[B_TERMS] AS [B_TERMS], 
    [Project1].[REFERRAL2] AS [REFERRAL2], 
    [Project1].[KFACTOR] AS [KFACTOR], 
    [Project1].[GAL_DEGREE_DAY] AS [GAL_DEGREE_DAY], 
    [Project1].[LCK_GAL_DEGREE_DAY] AS [LCK_GAL_DEGREE_DAY], 
    [Project1].[GAL_DAY] AS [GAL_DAY], 
    [Project1].[LCK_GAL_DAY] AS [LCK_GAL_DAY], 
    [Project1].[B_BILL_INFO1] AS [B_BILL_INFO1], 
    [Project1].[B_BILL_INFO2] AS [B_BILL_INFO2], 
    [Project1].[B_BILL_INFO3] AS [B_BILL_INFO3], 
    [Project1].[B_BILL_INFO4] AS [B_BILL_INFO4], 
    [Project1].[C_DELNQLVL] AS [C_DELNQLVL], 
    [Project1].[B_PAGE] AS [B_PAGE], 
    [Project1].[B_TAXAREA] AS [B_TAXAREA], 
    [Project1].[T_ID] AS [T_ID], 
    [Project1].[C_EMAIL] AS [C_EMAIL], 
    [Project1].[B_EMAIL] AS [B_EMAIL], 
    [Project1].[OUTPUT] AS [OUTPUT], 
    [Project1].[C_120D] AS [C_120D], 
    [Project1].[C_150D] AS [C_150D], 
    [Project1].[B_SURCHARGE] AS [B_SURCHARGE], 
    [Project1].[SITEFILE] AS [SITEFILE], 
    [Project1].[QUOTE_SHEET] AS [QUOTE_SHEET], 
    [Project1].[C_TYPE4] AS [C_TYPE4], 
    [Project1].[C_TYPE5] AS [C_TYPE5], 
    [Project1].[C_TYPE6] AS [C_TYPE6], 
    [Project1].[C_TYPE7] AS [C_TYPE7], 
    [Project1].[C_TYPE8] AS [C_TYPE8], 
    [Project1].[C_TYPE9] AS [C_TYPE9], 
    [Project1].[C_LOCS2] AS [C_LOCS2], 
    [Project1].[C_NLOCS2] AS [C_NLOCS2], 
    [Project1].[C_SUFFIX2] AS [C_SUFFIX2], 
    [Project1].[ISCHILD2] AS [ISCHILD2], 
    [Project1].[C_LOCS3] AS [C_LOCS3], 
    [Project1].[C_NLOCS3] AS [C_NLOCS3], 
    [Project1].[C_SUFFIX3] AS [C_SUFFIX3], 
    [Project1].[ISCHILD3] AS [ISCHILD3], 
    [Project1].[TOTAL_TONS] AS [TOTAL_TONS], 
    [Project1].[B_TARIFF] AS [B_TARIFF], 
    [Project1].[C_LE] AS [C_LE], 
    [Project1].[C_LSD] AS [C_LSD], 
    [Project1].[C_SECTION] AS [C_SECTION], 
    [Project1].[C_TOWNSHIP] AS [C_TOWNSHIP], 
    [Project1].[C_RANGE] AS [C_RANGE], 
    [Project1].[C_MERIDIAN] AS [C_MERIDIAN], 
    [Project1].[C_CURRENCY] AS [C_CURRENCY], 
    [Project1].[GUARANTEED_PRICE] AS [GUARANTEED_PRICE], 
    [Project1].[REGION] AS [REGION], 
    [Project1].[DISTRICT] AS [DISTRICT], 
    [Project1].[PROFILE_AREA] AS [PROFILE_AREA], 
    [Project1].[CLIENT_ID] AS [CLIENT_ID], 
    [Project1].[BUSINESS_UNIT] AS [BUSINESS_UNIT], 
    [Project1].[LOCATION_TYPE] AS [LOCATION_TYPE], 
    [Project1].[RANK_CLASS] AS [RANK_CLASS], 
    [Project1].[DIVISION] AS [DIVISION], 
    [Project1].[CLIENT_SHARED_PERCENTAGE] AS [CLIENT_SHARED_PERCENTAGE], 
    [Project1].[SURCHARGE_BENCHMARK] AS [SURCHARGE_BENCHMARK], 
    [Project1].[LOCATION_ID] AS [LOCATION_ID], 
    [Project1].[NATIONAL_ACCT] AS [NATIONAL_ACCT], 
    [Project1].[V_STORENO] AS [V_STORENO], 
    [Project1].[PARENT_C_ID] AS [PARENT_C_ID], 
    [Project1].[AUTHORIZEDPAYEE] AS [AUTHORIZEDPAYEE], 
    [Project1].[REBATEPAY] AS [REBATEPAY], 
    [Project1].[LastUpdated] AS [LastUpdated], 
    [Project1].[B_QB_PATH] AS [B_QB_PATH], 
    [Project1].[ContactViaPhone] AS [ContactViaPhone], 
    [Project1].[Tax_Exempt_ID] AS [Tax_Exempt_ID], 
    [Project1].[updated] AS [updated], 
    [Project1].[ROWID] AS [ROWID], 
    [Project1].[PHONETYPE] AS [PHONETYPE], 
    [Project1].[C_ContactViaPhone] AS [C_ContactViaPhone], 
    [Project1].[C_PhoneType] AS [C_PhoneType], 
    [Project1].[C_WEBSITE] AS [C_WEBSITE], 
    [Project1].[IsAddressCertified] AS [IsAddressCertified], 
    [Project1].[Flex_Date] AS [Flex_Date], 
    [Project1].[AutoEmailCustomerReceipt] AS [AutoEmailCustomerReceipt]
    FROM ( 
    SELECT [Project1].[C_ID] AS [C_ID], [Project1].[C_ID_ALPHA] AS [C_ID_ALPHA], [Project1].[C_NAME] AS [C_NAME], [Project1].[C_NAME2] AS [C_NAME2], 
[Project1].[C_ADDR1] AS [C_ADDR1], [Project1].[C_ADDRNUM1] AS [C_ADDRNUM1], [Project1].[C_ADDR2] AS [C_ADDR2], [Project1].[C_CITY] AS [C_CITY], 
[Project1].[C_STATE] AS [C_STATE], [Project1].[C_ZIP] AS [C_ZIP], [Project1].[C_PHO] AS [C_PHO], [Project1].[C_PCONT] AS [C_PCONT], [Project1].[C_FAX] AS 
[C_FAX], [Project1].[C_FCONT] AS [C_FCONT], [Project1].[C_CSTAT] AS [C_CSTAT], [Project1].[C_SALESREP] AS [C_SALESREP], [Project1].[C_QUOTE] AS [C_QUOTE], 
[Project1].[C_ENDDATE] AS [C_ENDDATE], [Project1].[C_TYPE] AS [C_TYPE], [Project1].[C_RTES] AS [C_RTES], [Project1].[C_NRTES] AS [C_NRTES], [Project1].[C_LOCS] 
AS [C_LOCS], [Project1].[C_NLOCS] AS [C_NLOCS], [Project1].[C_SUFFIX] AS [C_SUFFIX], [Project1].[ISCHILD] AS [ISCHILD], [Project1].[C_BILL_TO] AS [C_BILL_TO], 
[Project1].[C_COMMENTS] AS [C_COMMENTS], [Project1].[C_MEMO] AS [C_MEMO], [Project1].[C_LST_PAY] AS [C_LST_PAY], [Project1].[C_LST_DATE] AS [C_LST_DATE], [Project1].[C_PRV_BAL] AS [C_PRV_BAL], [Project1].[C_CUR_BAL] AS [C_CUR_BAL], [Project1].[C_UN_BILL] AS [C_UN_BILL], [Project1].[C_CUR_DUE] AS [C_CUR_DUE], [Project1].[C_30D] AS [C_30D], [Project1].[C_60D] AS [C_60D], [Project1].[C_90D] AS [C_90D], [Project1].[C_FIN_CHG] AS [C_FIN_CHG], [Project1].[B_NAME] AS [B_NAME], [Project1].[B_NAME2] AS [B_NAME2], [Project1].[B_ADDR1] AS [B_ADDR1], [Project1].[B_ADDR2] AS [B_ADDR2], [Project1].[B_CITY] AS [B_CITY], [Project1].[B_STATE] AS [B_STATE], [Project1].[B_ZIP] AS [B_ZIP], [Project1].[B_PHO] AS [B_PHO], [Project1].[B_PCONT] AS [B_PCONT], [Project1].[B_FAX] AS [B_FAX], [Project1].[B_FCONT] AS [B_FCONT], [Project1].[B_B_CYCLE] AS [B_B_CYCLE], [Project1].[B_TAXABLE] AS [B_TAXABLE], [Project1].[B_ACCTTYPE] AS [B_ACCTTYPE], [Project1].[B_FIN_DESC] AS [B_FIN_DESC], [Project1].[B_DELINQ] AS [B_DELINQ], [Project1].[B_STMT_TYP] AS [B_STMT_TYP], [Project1].[B_BILL_TYP] AS [B_BILL_TYP], [Project1].[B_PO_NUM] AS [B_PO_NUM], [Project1].[B_SUSPENDS] AS [B_SUSPENDS], [Project1].[B_SUSPENDE] AS [B_SUSPENDE], [Project1].[B_STRT_DAT] AS [B_STRT_DAT], [Project1].[B_STOP_DAT] AS [B_STOP_DAT], [Project1].[B_STRT_STA] AS [B_STRT_STA], [Project1].[B_STOP_STA] AS [B_STOP_STA], [Project1].[B_STRT_COD] AS [B_STRT_COD], [Project1].[B_STOP_COD] AS [B_STOP_COD], [Project1].[B_STRT_AMT] AS [B_STRT_AMT], [Project1].[B_STOP_AMT] AS [B_STOP_AMT], [Project1].[B_CONTRACT] AS [B_CONTRACT], [Project1].[B_CONTAINS] AS [B_CONTAINS], [Project1].[B_GRID] AS [B_GRID], [Project1].[B_AREA] AS [B_AREA], [Project1].[B_PAYBYCC] AS [B_PAYBYCC], [Project1].[B_MTD] AS [B_MTD], [Project1].[B_YTD] AS [B_YTD], [Project1].[B_LMTD] AS [B_LMTD], [Project1].[B_LYTD] AS [B_LYTD], [Project1].[C_UNAPPLIED] AS [C_UNAPPLIED], [Project1].[B_CONTRACT_NUM] AS [B_CONTRACT_NUM], [Project1].[B_CONTRACT_DATE] AS [B_CONTRACT_DATE], [Project1].[C_15D] AS [C_15D], [Project1].[C_45D] AS [C_45D], [Project1].[REFERRAL] AS [REFERRAL], [Project1].[SREP1] AS [SREP1], [Project1].[SREP2] AS [SREP2], 
[Project1].[CREP1] AS [CREP1], [Project1].[CREP2] AS [CREP2], [Project1].[B_NAME_2ND] AS [B_NAME_2ND], [Project1].[B_NAME_2ND2] AS [B_NAME_2ND2], 
[Project1].[B_ADDR1_2ND] AS [B_ADDR1_2ND], [Project1].[B_ADDR1_2ND2] AS [B_ADDR1_2ND2], [Project1].[B_CITY_2ND] AS [B_CITY_2ND], [Project1].[B_STATE_2ND] AS 
[B_STATE_2ND], [Project1].[B_ZIP_2ND] AS [B_ZIP_2ND], [Project1].[C_DEPOSIT] AS [C_DEPOSIT], [Project1].[CREP1_NOTES] AS [CREP1_NOTES], [Project1].[CREP2_NOTES] 
AS [CREP2_NOTES], [Project1].[SREP1_NOTES] AS [SREP1_NOTES], [Project1].[SREP2_NOTES] AS [SREP2_NOTES], [Project1].[C_TYPE2] AS [C_TYPE2], [Project1].[C_TYPE3] 
AS [C_TYPE3], [Project1].[B_TERMS] AS [B_TERMS], [Project1].[REFERRAL2] AS [REFERRAL2], [Project1].[KFACTOR] AS [KFACTOR], [Project1].[GAL_DEGREE_DAY] AS 
[GAL_DEGREE_DAY], [Project1].[LCK_GAL_DEGREE_DAY] AS [LCK_GAL_DEGREE_DAY], [Project1].[GAL_DAY] AS [GAL_DAY], [Project1].[LCK_GAL_DAY] AS [LCK_GAL_DAY], 
[Project1].[B_BILL_INFO1] AS [B_BILL_INFO1], [Project1].[B_BILL_INFO2] AS [B_BILL_INFO2], [Project1].[B_BILL_INFO3] AS [B_BILL_INFO3], [Project1].[B_BILL_INFO4] 
AS [B_BILL_INFO4], [Project1].[C_DELNQLVL] AS [C_DELNQLVL], [Project1].[B_PAGE] AS [B_PAGE], [Project1].[B_TAXAREA] AS [B_TAXAREA], [Project1].[T_ID] AS [T_ID], 
[Project1].[C_EMAIL] AS [C_EMAIL], [Project1].[B_EMAIL] AS [B_EMAIL], [Project1].[OUTPUT] AS [OUTPUT], [Project1].[C_120D] AS [C_120D], [Project1].[C_150D] AS 
[C_150D], [Project1].[B_SURCHARGE] AS [B_SURCHARGE], [Project1].[SITEFILE] AS [SITEFILE], [Project1].[QUOTE_SHEET] AS [QUOTE_SHEET], [Project1].[C_TYPE4] AS 
[C_TYPE4], [Project1].[C_TYPE5] AS [C_TYPE5], [Project1].[C_TYPE6] AS [C_TYPE6], [Project1].[C_TYPE7] AS [C_TYPE7], [Project1].[C_TYPE8] AS [C_TYPE8], 
[Project1].[C_TYPE9] AS [C_TYPE9], [Project1].[C_LOCS2] AS [C_LOCS2], [Project1].[C_NLOCS2] AS [C_NLOCS2], [Project1].[C_SUFFIX2] AS [C_SUFFIX2], 
[Project1].[ISCHILD2] AS [ISCHILD2], [Project1].[C_LOCS3] AS [C_LOCS3], [Project1].[C_NLOCS3] AS [C_NLOCS3], [Project1].[C_SUFFIX3] AS [C_SUFFIX3], [Project1].[ISCHILD3] AS [ISCHILD3], [Project1].[TOTAL_TONS] AS [TOTAL_TONS], [Project1].[B_TARIFF] AS [B_TARIFF], [Project1].[C_LE] AS [C_LE], [Project1].[C_LSD] AS [C_LSD], [Project1].[C_SECTION] AS [C_SECTION], [Project1].[C_TOWNSHIP] AS [C_TOWNSHIP], [Project1].[C_RANGE] AS [C_RANGE], [Project1].[C_MERIDIAN] AS [C_MERIDIAN], [Project1].[C_CURRENCY] AS [C_CURRENCY], [Project1].[GUARANTEED_PRICE] AS [GUARANTEED_PRICE], [Project1].[REGION] AS [REGION], [Project1].[DISTRICT] AS [DISTRICT], [Project1].[PROFILE_AREA] AS [PROFILE_AREA], [Project1].[CLIENT_ID] AS [CLIENT_ID], [Project1].[BUSINESS_UNIT] AS [BUSINESS_UNIT], [Project1].[LOCATION_TYPE] AS [LOCATION_TYPE], [Project1].[RANK_CLASS] AS [RANK_CLASS], [Project1].[DIVISION] AS [DIVISION], [Project1].[CLIENT_SHARED_PERCENTAGE] AS [CLIENT_SHARED_PERCENTAGE], [Project1].[SURCHARGE_BENCHMARK] AS [SURCHARGE_BENCHMARK], [Project1].[LOCATION_ID] AS [LOCATION_ID], [Project1].[NATIONAL_ACCT] AS [NATIONAL_ACCT], [Project1].[V_STORENO] AS [V_STORENO], [Project1].[PARENT_C_ID] AS [PARENT_C_ID], [Project1].[AUTHORIZEDPAYEE] AS [AUTHORIZEDPAYEE], [Project1].[REBATEPAY] AS [REBATEPAY], [Project1].[LastUpdated] AS [LastUpdated], [Project1].[B_QB_PATH] AS [B_QB_PATH], [Project1].[ContactViaPhone] AS [ContactViaPhone], [Project1].[Tax_Exempt_ID] AS [Tax_Exempt_ID], [Project1].[updated] AS [updated], [Project1].[ROWID] AS [ROWID], [Project1].[PHONETYPE] AS [PHONETYPE], [Project1].[C_ContactViaPhone] AS [C_ContactViaPhone], [Project1].[C_PhoneType] AS [C_PhoneType], [Project1].[C_WEBSITE] AS [C_WEBSITE], [Project1].[IsAddressCertified] AS [IsAddressCertified], [Project1].[Flex_Date] AS [Flex_Date], [Project1].[AutoEmailCustomerReceipt] AS [AutoEmailCustomerReceipt], [Project1].[B_BILL_CO] AS [B_BILL_CO], row_number() OVER (ORDER BY [Project1].[C_NAME] ASC) AS [row_number]
        FROM ( SELECT 
            [Extent1].[C_ID] AS [C_ID], 
            [Extent1].[C_ID_ALPHA] AS [C_ID_ALPHA], 
            [Extent1].[C_NAME] AS [C_NAME], 
            [Extent1].[C_NAME2] AS [C_NAME2], 
            [Extent1].[C_ADDR1] AS [C_ADDR1], 
            [Extent1].[C_ADDRNUM1] AS [C_ADDRNUM1], 
            [Extent1].[C_ADDR2] AS [C_ADDR2], 
            [Extent1].[C_CITY] AS [C_CITY], 
            [Extent1].[C_STATE] AS [C_STATE], 
            [Extent1].[C_ZIP] AS [C_ZIP], 
            [Extent1].[C_PHO] AS [C_PHO], 
            [Extent1].[C_PCONT] AS [C_PCONT], 
            [Extent1].[C_FAX] AS [C_FAX], 
            [Extent1].[C_FCONT] AS [C_FCONT], 
            [Extent1].[C_CSTAT] AS [C_CSTAT], 
            [Extent1].[C_SALESREP] AS [C_SALESREP], 
            [Extent1].[C_QUOTE] AS [C_QUOTE], 
            [Extent1].[C_ENDDATE] AS [C_ENDDATE], 
            [Extent1].[C_TYPE] AS [C_TYPE], 
            [Extent1].[C_RTES] AS [C_RTES], 
            [Extent1].[C_NRTES] AS [C_NRTES], 
            [Extent1].[C_LOCS] AS [C_LOCS], 
            [Extent1].[C_NLOCS] AS [C_NLOCS], 
            [Extent1].[C_SUFFIX] AS [C_SUFFIX], 
            [Extent1].[ISCHILD] AS [ISCHILD], 
            [Extent1].[C_BILL_TO] AS [C_BILL_TO], 
            [Extent1].[C_COMMENTS] AS [C_COMMENTS], 
            [Extent1].[C_MEMO] AS [C_MEMO], 
            [Extent1].[C_LST_PAY] AS [C_LST_PAY], 
            [Extent1].[C_LST_DATE] AS [C_LST_DATE], 
            [Extent1].[C_PRV_BAL] AS [C_PRV_BAL], 
            [Extent1].[C_CUR_BAL] AS [C_CUR_BAL], 
            [Extent1].[C_UN_BILL] AS [C_UN_BILL], 
            [Extent1].[C_CUR_DUE] AS [C_CUR_DUE], 
            [Extent1].[C_30D] AS [C_30D], 
            [Extent1].[C_60D] AS [C_60D], 
            [Extent1].[C_90D] AS [C_90D], 
            [Extent1].[C_FIN_CHG] AS [C_FIN_CHG], 
            [Extent1].[B_NAME] AS [B_NAME], 
            [Extent1].[B_NAME2] AS [B_NAME2], 
            [Extent1].[B_ADDR1] AS [B_ADDR1], 
            [Extent1].[B_ADDR2] AS [B_ADDR2], 
            [Extent1].[B_CITY] AS [B_CITY], 
            [Extent1].[B_STATE] AS [B_STATE], 
            [Extent1].[B_ZIP] AS [B_ZIP], 
            [Extent1].[B_PHO] AS [B_PHO], 
            [Extent1].[B_PCONT] AS [B_PCONT], 
            [Extent1].[B_FAX] AS [B_FAX], 
            [Extent1].[B_FCONT] AS [B_FCONT], 
            [Extent1].[B_B_CYCLE] AS [B_B_CYCLE], 
            [Extent1].[B_TAXABLE] AS [B_TAXABLE], 
            [Extent1].[B_ACCTTYPE] AS [B_ACCTTYPE], 
            [Extent1].[B_FIN_DESC] AS [B_FIN_DESC], 
            [Extent1].[B_DELINQ] AS [B_DELINQ], 
            [Extent1].[B_STMT_TYP] AS [B_STMT_TYP], 
            [Extent1].[B_BILL_TYP] AS [B_BILL_TYP], 
            [Extent1].[B_PO_NUM] AS [B_PO_NUM], 
            [Extent1].[B_SUSPENDS] AS [B_SUSPENDS], 
            [Extent1].[B_SUSPENDE] AS [B_SUSPENDE], 
            [Extent1].[B_STRT_DAT] AS [B_STRT_DAT], 
            [Extent1].[B_STOP_DAT] AS [B_STOP_DAT], 
            [Extent1].[B_STRT_STA] AS [B_STRT_STA], 
            [Extent1].[B_STOP_STA] AS [B_STOP_STA], 
            [Extent1].[B_STRT_COD] AS [B_STRT_COD], 
            [Extent1].[B_STOP_COD] AS [B_STOP_COD], 
            [Extent1].[B_STRT_AMT] AS [B_STRT_AMT], 
            [Extent1].[B_STOP_AMT] AS [B_STOP_AMT], 
            [Extent1].[B_CONTRACT] AS [B_CONTRACT], 
            [Extent1].[B_CONTAINS] AS [B_CONTAINS], 
            [Extent1].[B_GRID] AS [B_GRID], 
            [Extent1].[B_AREA] AS [B_AREA], 
            [Extent1].[B_PAYBYCC] AS [B_PAYBYCC], 
            [Extent1].[B_MTD] AS [B_MTD], 
            [Extent1].[B_YTD] AS [B_YTD], 
            [Extent1].[B_LMTD] AS [B_LMTD], 
            [Extent1].[B_LYTD] AS [B_LYTD], 
            [Extent1].[C_UNAPPLIED] AS [C_UNAPPLIED], 
            [Extent1].[B_CONTRACT_NUM] AS [B_CONTRACT_NUM], 
            [Extent1].[B_CONTRACT_DATE] AS [B_CONTRACT_DATE], 
            [Extent1].[C_15D] AS [C_15D], 
            [Extent1].[C_45D] AS [C_45D], 
            [Extent1].[REFERRAL] AS [REFERRAL], 
            [Extent1].[SREP1] AS [SREP1], 
            [Extent1].[SREP2] AS [SREP2], 
            [Extent1].[CREP1] AS [CREP1], 
            [Extent1].[CREP2] AS [CREP2], 
            [Extent1].[B_NAME_2ND] AS [B_NAME_2ND], 
            [Extent1].[B_NAME_2ND2] AS [B_NAME_2ND2], 
            [Extent1].[B_ADDR1_2ND] AS [B_ADDR1_2ND], 
            [Extent1].[B_ADDR1_2ND2] AS [B_ADDR1_2ND2], 
            [Extent1].[B_CITY_2ND] AS [B_CITY_2ND], 
            [Extent1].[B_STATE_2ND] AS [B_STATE_2ND], 
            [Extent1].[B_ZIP_2ND] AS [B_ZIP_2ND], 
            [Extent1].[C_DEPOSIT] AS [C_DEPOSIT], 
            [Extent1].[CREP1_NOTES] AS [CREP1_NOTES], 
            [Extent1].[CREP2_NOTES] AS [CREP2_NOTES], 
            [Extent1].[SREP1_NOTES] AS [SREP1_NOTES], 
            [Extent1].[SREP2_NOTES] AS [SREP2_NOTES], 
            [Extent1].[C_TYPE2] AS [C_TYPE2], 
            [Extent1].[C_TYPE3] AS [C_TYPE3], 
            [Extent1].[B_TERMS] AS [B_TERMS], 
            [Extent1].[REFERRAL2] AS [REFERRAL2], 
            [Extent1].[KFACTOR] AS [KFACTOR], 
            [Extent1].[GAL_DEGREE_DAY] AS [GAL_DEGREE_DAY], 
            [Extent1].[LCK_GAL_DEGREE_DAY] AS [LCK_GAL_DEGREE_DAY], 
            [Extent1].[GAL_DAY] AS [GAL_DAY], 
            [Extent1].[LCK_GAL_DAY] AS [LCK_GAL_DAY], 
            [Extent1].[B_BILL_INFO1] AS [B_BILL_INFO1], 
            [Extent1].[B_BILL_INFO2] AS [B_BILL_INFO2], 
            [Extent1].[B_BILL_INFO3] AS [B_BILL_INFO3], 
            [Extent1].[B_BILL_INFO4] AS [B_BILL_INFO4], 
            [Extent1].[C_DELNQLVL] AS [C_DELNQLVL], 
            [Extent1].[B_PAGE] AS [B_PAGE], 
            [Extent1].[B_TAXAREA] AS [B_TAXAREA], 
            [Extent1].[T_ID] AS [T_ID], 
            [Extent1].[C_EMAIL] AS [C_EMAIL], 
            [Extent1].[B_EMAIL] AS [B_EMAIL], 
            [Extent1].[OUTPUT] AS [OUTPUT], 
            [Extent1].[C_120D] AS [C_120D], 
            [Extent1].[C_150D] AS [C_150D], 
            [Extent1].[B_SURCHARGE] AS [B_SURCHARGE], 
            [Extent1].[SITEFILE] AS [SITEFILE], 
            [Extent1].[QUOTE_SHEET] AS [QUOTE_SHEET], 
            [Extent1].[C_TYPE4] AS [C_TYPE4], 
            [Extent1].[C_TYPE5] AS [C_TYPE5], 
            [Extent1].[C_TYPE6] AS [C_TYPE6], 
            [Extent1].[C_TYPE7] AS [C_TYPE7], 
            [Extent1].[C_TYPE8] AS [C_TYPE8], 
            [Extent1].[C_TYPE9] AS [C_TYPE9], 
            [Extent1].[C_LOCS2] AS [C_LOCS2], 
            [Extent1].[C_NLOCS2] AS [C_NLOCS2], 
            [Extent1].[C_SUFFIX2] AS [C_SUFFIX2], 
            [Extent1].[ISCHILD2] AS [ISCHILD2], 
            [Extent1].[C_LOCS3] AS [C_LOCS3], 
            [Extent1].[C_NLOCS3] AS [C_NLOCS3], 
            [Extent1].[C_SUFFIX3] AS [C_SUFFIX3], 
            [Extent1].[ISCHILD3] AS [ISCHILD3], 
            [Extent1].[TOTAL_TONS] AS [TOTAL_TONS], 
            [Extent1].[B_TARIFF] AS [B_TARIFF], 
            [Extent1].[C_LE] AS [C_LE], 
            [Extent1].[C_LSD] AS [C_LSD], 
            [Extent1].[C_SECTION] AS [C_SECTION], 
            [Extent1].[C_TOWNSHIP] AS [C_TOWNSHIP], 
            [Extent1].[C_RANGE] AS [C_RANGE], 
            [Extent1].[C_MERIDIAN] AS [C_MERIDIAN], 
            [Extent1].[C_CURRENCY] AS [C_CURRENCY], 
            [Extent1].[GUARANTEED_PRICE] AS [GUARANTEED_PRICE], 
            [Extent1].[REGION] AS [REGION], 
            [Extent1].[DISTRICT] AS [DISTRICT], 
            [Extent1].[PROFILE_AREA] AS [PROFILE_AREA], 
            [Extent1].[CLIENT_ID] AS [CLIENT_ID], 
            [Extent1].[BUSINESS_UNIT] AS [BUSINESS_UNIT], 
            [Extent1].[LOCATION_TYPE] AS [LOCATION_TYPE], 
            [Extent1].[RANK_CLASS] AS [RANK_CLASS], 
            [Extent1].[DIVISION] AS [DIVISION], 
            [Extent1].[CLIENT_SHARED_PERCENTAGE] AS [CLIENT_SHARED_PERCENTAGE], 
            [Extent1].[SURCHARGE_BENCHMARK] AS [SURCHARGE_BENCHMARK], 
            [Extent1].[LOCATION_ID] AS [LOCATION_ID], 
            [Extent1].[NATIONAL_ACCT] AS [NATIONAL_ACCT], 
            [Extent1].[V_STORENO] AS [V_STORENO], 
            [Extent1].[PARENT_C_ID] AS [PARENT_C_ID], 
            [Extent1].[AUTHORIZEDPAYEE] AS [AUTHORIZEDPAYEE], 
            [Extent1].[REBATEPAY] AS [REBATEPAY], 
            [Extent1].[LastUpdated] AS [LastUpdated], 
            [Extent1].[B_QB_PATH] AS [B_QB_PATH], 
            [Extent1].[ContactViaPhone] AS [ContactViaPhone], 
            [Extent1].[Tax_Exempt_ID] AS [Tax_Exempt_ID], 
            [Extent1].[updated] AS [updated], 
            [Extent1].[ROWID] AS [ROWID], 
            [Extent1].[PHONETYPE] AS [PHONETYPE], 
            [Extent1].[C_ContactViaPhone] AS [C_ContactViaPhone], 
            [Extent1].[C_PhoneType] AS [C_PhoneType], 
            [Extent1].[C_WEBSITE] AS [C_WEBSITE], 
            [Extent1].[IsAddressCertified] AS [IsAddressCertified], 
            [Extent1].[Flex_Date] AS [Flex_Date], 
            [Extent1].[AutoEmailCustomerReceipt] AS [AutoEmailCustomerReceipt], 
            [Extent1].[B_BILL_CO] AS [B_BILL_CO]
            FROM  [dbo].[CUST] AS [Extent1]
            INNER JOIN [dbo].[HIST] AS [Extent2] ON [Extent1].[C_ID] = [Extent2].[C_ID]
            WHERE ([Extent1].[B_BILL_CO] IN (17, 18, 19, 20, 21, 22, 1, 23, 33, 24, 25, 26, 27, 28, 29, 30, 35, 32, 31)) AND ([Extent1].[B_BILL_CO] IS NOT NULL) AND ([Extent1].[C_CSTAT] IN (97, 644, 101, 807, 7005, 192, 8177, 531, 8178, 98, 325, 100, 8095)) AND ([Extent1].[C_CSTAT] IS NOT NULL) AND ([Extent2].[PO_NUMBER] LIKE @p__linq__0 ESCAPE N''~'')
        )  AS [Project1]
    )  AS [Project1]
    WHERE [Project1].[row_number] > 0
    ORDER BY [Project1].[C_NAME] ASC',N'@p__linq__0 nvarchar(4000)',@p__linq__0=N'%055%'

以上查询需要超过5分钟才能获得结果。请问,任何人都建议我如何才能提高绩效?

0 个答案:

没有答案