SQL Server 2014标准版
我需要找到特定月份往返特定城市的航班数量。例如
select count(*)
from flights
where flightTo_AirportCode = 'aaaa'
and flightFrom_Airportcode = 'bbbb'
and flightdate < '2016-04-01'
and flightdate > '2016-02-28' ;
表模式如下。
我正在尝试评估索引模型A或索引模型B(如下)是否更可取(建立索引需要花费数小时,并且磁盘空间一次只能存在一个,因此我想在跳之前先进行研究)。
根据我的经验,任何一个索引都可以。我对吗?
create index [modelA] on flights (flightTo_AirportCode, flightFrom_AirportCode, flightDate)
create index [modelB] on flights (flightDate, flightTo_AirportCode, flightFrom_AirportCode)
(或者,更好的是,我可以使用二进制索引或高级机制来解决这个问题吗?)
CREATE TABLE [dbo].[flights](
[flightId] [uniqueidentifier] NOT NULL,
[accountId] [uniqueidentifier] NULL,
[flightDate] [datetime] NULL,
[flightTo_AirportCode] [nvarchar](30) NULL,
[flightFrom_AirportCode] [nvarchar](30) NULL,
-- ... 45 more fields
CONSTRAINT [PK_flight] PRIMARY KEY CLUSTERED
(
[flightId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 70) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]