Why are the performances of these 2 queries so different?

前端 未结 3 2203
清酒与你
清酒与你 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

    You've introduced an OR condition. In most cases it is simply much faster to check explicitly for NULL and perform one query vs your method.

    For instance try this:

    IF @Filter IS NULL
     BEGIN
    SELECT TOP 100 ID FROM dbo.Products
    END
    ELSE
    BEGIN
    SELECT TOP 100 ID FROM dbo.Products
    WHERE @Filter CONTAINS(Name, @Filter)
    END
    

提交回复
热议问题