• arnipetursson (11/12/2013)


    When I run the two queries (outer join vs NOT EXISTS),

    the outer join query runs in 4-9ms (69 logical IO n the temp tables and 0 scans and 0 logical IO on the work table)

    and the not exists query runs in 28-32ms (109 logical IO on the temp tables and 50 scans and 5079 logical IO on the work table).

    It looks like the #CourseCompleted table is scanned 50 times in the NOT EXISTS query, whereas only 30 times in the outer join query.

    I wonder if these results hold over larger data sets.

    I usually use a LEFT JOIN for this reason.

    deroby (11/12/2013)


    2. I've seen it 'fail' when people use a <somefield> that turns out to be NULL-able

    That is easily avoidable, particularly when you're joining on a foreign key, by choosing <somefield> as one of the columns in your JOIN criteria. I agree though that it is a possible newbie mistake.

    Nice article Patrick!


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St