1
SELECT 
   CountryCode, CountryName, CountryEName, FirstShow, iseTicketFirstShow 
FROM 
   Tristar.dbo.COMCountry 
WHERE 
  ContinentName = 'Continent Name' AND iseTicket = 1 
  and CountryCode in 
    (select Distinct CountryCode 
     from eTicketSubAirport 
     where AirportCode in 
         (select DISTINCT eTDestinationAirport 
          from eTicketMain 
          where eTChecked=1 and eTDepartAirport='TPE')
    ) 
ORDER BY 
   iseTicketFirstShow DESC, FirstShow,CountryEName

上面的代码花了 3 秒....这是不可接受的。2个内部选择自己执行得非常快。

如果我拿走了一个内部选择,例如....

SELECT 
   CountryCode, CountryName, CountryEName, FirstShow, iseTicketFirstShow 
FROM 
   Tristar.dbo.COMCountry 
WHERE 
   ContinentName = 'continent name' AND iseTicket = 1 
   and CountryCode in 
     (select Distinct CountryCode 
      from eTicketSubAirport) 
ORDER BY 
   iseTicketFirstShow DESC, FirstShow,CountryEName

这也执行得非常快。

哈希匹配太 79% 的处理。[eTicketSubAirport]

我不能删除选择的任何部分,因为它们都是必需的......

4

1 回答 1

2

尝试加入,它看起来像这样:

SELECT DISTINCT
   Country.CountryCode, 
   Country.CountryName, 
   Country.CountryEName, 
   Country.FirstShow, 
   Country.iseTicketFirstShow 
FROM 
   Tristar.dbo.COMCountry AS Country
   INNER JOIN eTicketSubAirport ON Country.CountryCode = eTicketSubAirport.CountryCode
   INNER JOIN eTicketMain       ON eTicketSubAirport.AirportCode = eTicketMain.eTDestinationAirport
WHERE 
  Country.ContinentName = 'Continent Name' 
  AND Country.iseTicket = 1 
  AND eTicketMain.eTChecked = 1 
  AND eTicketMain.eTDepartAirport = 'TPE'
ORDER BY 
   Country.iseTicketFirstShow DESC, 
   Country.FirstShow,
   Country.CountryEName
于 2012-09-26T07:23:04.733 回答