我的数据库中有一个表,我们将其用作文件存储,文件本身存储在 varbinary(MAX) 列中。
CREATE TABLE [dbo].[FILE_TABLE](
[FILE_ID] [int] IDENTITY(1,1) NOT NULL,
[HTML_FILE] [nvarchar](max) NULL,
[XML_FILE] [varbinary](max) NULL,
[FILE_EXTENSION] [nvarchar](50) NULL
CONSTRAINT [PK_FILE_TABLE] PRIMARY KEY CLUSTERED
(
[FILE_ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
我们还创建了以下非聚集索引:
CREATE NONCLUSTERED INDEX [NonClusteredIndex-20180220-000116] ON [dbo].[FILE_TABLE]
(
[FILE_ID] ASC
)
INCLUDE ( [XML_FILE]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
该表具有语义和自由文本,可以对文档运行关键字搜索。当我们运行一个简单的自由文本查询时,性能很慢。该表只有 810 条记录,需要 30 秒才能返回 713 行。我们如何提高这个表或查询的性能?
SELECT * FROM FILE_TABLE WHERE freetext(XML_FILE,'lights')