简体   繁体   English

SQL文本搜索速度

[英]SQL text search speed

I am trying to improve the speed of a text search procedure in a MSSQL database.我正在尝试提高 MSSQL 数据库中文本搜索过程的速度。

The procedure queries multiple tables to search for any matching records (properties, users, businesses etc.).该过程查询多个表以搜索任何匹配的记录(属性、用户、企业等)。 For example the users table has over 400,000 rows and we are searching 6 nvarchar columns for the specified search criteria.例如,users 表有超过 400,000 行,我们正在为指定的搜索条件搜索 6 个 nvarchar 列。 Also if there are spaces we search for each word in the search criteria seperately to improve accuracy of results.此外,如果有空格,我们会单独搜索搜索条件中的每个单词,以提高结果的准确性。 The same procedure searches a property table that holds over 120,000 rows and queries a single address column.相同的过程搜索包含超过 120,000 行的属性表并查询单个地址列。

I have implemented full text search to the appropriate tables and columns, however the search can take over 7 to 10 seconds to return results.我已经对适当的表和列实施了全文搜索,但是搜索可能需要 7 到 10 秒才能返回结果。 Idealy I would like this to be below 2 seconds.理想情况下,我希望这低于 2 秒。

This is an example of the query I am using to find users:这是我用来查找用户的查询示例:

SELECT
    u.[UserId]
FROM [mgr].[Users] u
LEFT JOIN [mgr].[UserAddresses] ua ON ua.[UserId] = u.[UserId]
LEFT JOIN [mgr].[vAddress] ad ON ad.[AddressId] = ua.[AddressId]
WHERE CONTAINS((u.[Forename], u.[Surname], u.[Email], u.[Phone], u.[WPhone], u.[MPhone]), @SearchCriteria)
OR CONTAINS(ad.[FullAddress], @SearchCriteria);

Is there anything I can do to improve the speed of this?我能做些什么来提高这个速度吗? We are expecting the amount of data in these tables to increase quite rapidly so any help to improve scalability would be great.我们预计这些表中的数据量会迅速增加,因此任何有助于提高可扩展性的方法都会很棒。

I wonder if it would be faster to split this into two queries:我想知道将其拆分为两个查询是否会更快:

SELECT u.[UserId]
FROM [mgr].[Users] u
WHERE CONTAINS((u.[Forename], u.[Surname], u.[Email], u.[Phone], u.[WPhone], u.[MPhone]), @SearchCriteria)
UNION  -- on purpose to remove duplicates
SELECT ua.[UserId]
FROM [mgr].[UserAddresses] ua ON  = u.[UserId] JOIN
     [mgr].[vAddress] ad
     ON ad.[AddressId] = ua.[AddressId]
WHERE CONTAINS(ad.[FullAddress], @SearchCriteria);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM