• vk-kirov (1/27/2010)


    Carlo Romagnano (1/27/2010)


    FROM BOL:

    Including an extremely large number of values (many thousands) in an IN clause can consume resources and return errors 8623 or 8632.

    This may happen only when a list of values is used in the IN statement. The author used a subquery, so it's O.K.

    Exactly. The query processor will not first execute the subquery to create at a list of teacher_id values and then insert that in the outer query; the optimizer will produce one integral plan to execute the whole query. Which, in my case, consists of scanning the teacher table, and then for each row looking for the first matching value in student.teacher_id (where the exact method of looking depends on whether and how this column is indexed).


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/