简体   繁体   English

如何使用两个Nvarchar(max)列加快T-SQL的搜索速度

[英]How to speed up T-SQL like search with two Nvarchar(max) columns

I've narrowed the query to this: 我将查询范围缩小到:

select * FROM items where accountid=4755 and (itemId like N'%9976%' or [description] like N'%9976%' or fulldescription like N'%9976%' )  

Both 'Description' and 'FullDescription' have been scaled down from nvarchar(max) to nvarchar(4000). 'Description'和'FullDescription'已从nvarchar(max)缩小为nvarchar(4000)。

Seems that still I cannot build index on that because it is too big (can't go any lower). 似乎仍然无法建立索引,因为它太大了(不能再降低了)。 Also, if I remove either 'Description' or 'FullDescription' it works fast, so the slowness is the compound effect. 另外,如果我删除“描述”或“完整描述”,它会快速运行,因此缓慢是复合效果。 Also, this query without the LIKE conditions contains only 1,000 rows in a relatively small database. 同样,没有LIKE条件的此查询在相对较小的数据库中仅包含1,000行。

We did end up with something similar to what Amir suggested here.. Since 98% of the data is pretty short we've created another two columns nvarchar(450) which meets the 900 bytes limit, then created indexes for them. 我们最终得到了与Amir在此处建议的类似的结果。由于98%的数据非常短,我们创建了另外两列满足900个字节限制的nvarchar(450),然后为它们创建了索引。

We're hosted on Azure and time is pressing, so we didn't look into free text search. 我们托管在Azure上,时间紧迫,因此我们没有考虑免费文本搜索。 We also came across Azure Search service which may be a fit for this, but that requires a time consuming POC. 我们还遇到了可能适合此操作的Azure搜索服务,但是这需要耗时的POC。

Thanks everyone. 感谢大家。

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

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