我有一个图书在线销售网站,在系统中,有一个名为 的表格Order
,其中有一些列如下:
OrderID int (Primary key),
Library_ID int,
Mode int,
BookId int,
Ext_User_ID varchar(2000),
Activated varchar(1),
RequiredDate datetime,
AmountBuy int,
APPROVAL_DATE datetime,
...
所以该表有超过 700 万行,目前我正在向网页添加更多查询条件,sql 脚本如下所示:
SELECT * FROM Book b, Library l, [Order] o
WHERE o.bookid = b.bookID
AND o.mode = 'A'
AND o.library_ID = l.library_ID
AND l.library_ID > 19
AND b.publisher_id > 1000
AND b.print_id > 800
AND NOT EXISTS (SELECT * FROM ExtBOOK WHERE b.bookid = extbookid AND library_ID = l.library_ID)
AND o.activated = 'Y'
AND b.eisbn13 LIKE '978%'
AND len(o.ext_user_id) > 3
AND b.bookid > 200000
AND b.bookid in (SELECT bookid FROM category WHERE categoryid > 2)
ORDER BY o.orderid DESC
Order
该脚本可能包含所有可能的查询条件,在我在 Management Studio 上运行它并打开“包含的实际执行计划”后,建议说我需要在表上创建索引
CREATE NONCLUSTERED INDEX [<Name of Missing Index, sysname,>]
ON [dbo].[Order] ([MODE],[ACTIVATED],[LIBRARY_ID],[BOOKID])
INCLUDE ([OrderID],[EXT_USER_ID],[APPROVAL_DATE])
但是,当我去创建索引时,我发现其他三个索引已经存在,它们是:
create nonclustered index IDX_Order_1 { MODE asc}
create nonclustered index IDX_Order_2 { Library_ID asc, EXT_USER_ID asc, BookID asc}
create nonclustered index IDX_Order_3 { BOOKID asc, Library_id asc, MODE asc }
所以上面的3个索引已经创建了,问题是,如果我想创建我的索引,我的意思是我觉得有些重复,我可以合并它们吗?或者每个索引都是针对特定查询的,因为表每天都在增长,除了我的查询之外,我无法确定使用哪个应用程序或什么 sql 脚本。任何想法?