Why are the performances of these 2 queries so different?

前端 未结 3 2160
清酒与你
清酒与你 2021-02-20 03:41

I have a stored proc that searches for products (250,000 rows) using a full text index.

The stored proc takes a parameter that is the full text search condition. This pa

3条回答
  •  心在旅途
    2021-02-20 04:19

    OR can crush performance, so do it this way:

    DECLARE @Filter VARCHAR(100)
    SET @Filter = 'FORMSOF(INFLECTIONAL, robe)'
    
    IF @Filter IS NOT NULL
    BEGIN
        SELECT TOP 100 ID FROM dbo.Products
        WHERE CONTAINS(Name, @Filter)
    END
    ELSE
    BEGIN
        SELECT TOP 100 ID FROM dbo.Products
    END
    

    Look at this article: Dynamic Search Conditions in T-SQL by Erland Sommarskog and this question: SQL Server 2008 - Conditional Query.

提交回复
热议问题