SQL Async Multiple Queries Combine Results — Maximum Results (Top XYZ)

后端 未结 4 1553
忘了有多久
忘了有多久 2021-01-26 08:47

I have a search function set up, where I run multiple queries simultaneously. The top 1000 results of each query are written to a table. (These run async--I am just leaving out

4条回答
  •  不思量自难忘°
    2021-01-26 09:10

    The following will likely give you a plan that achieves your desired result of not processing any rows after the 1,000th one has been found.

    WITH CTE
         AS (SELECT Text
             FROM   A
             WHERE  CONTAINS(Text, '"searchString"')
             UNION ALL
             SELECT Text
             FROM   B
             WHERE  CONTAINS(Text, '"searchString"')
             UNION ALL
             SELECT Text
             FROM   C
             WHERE  CONTAINS(Text, '"searchString"'))
    INSERT INTO Results
    SELECT TOP 1000 Text
    FROM   CTE 
    

提交回复
热议问题