TempDB

  • Understood... but you have no criteria for the table... that makes a cross-join.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • There is in fact cross-join between D1 and D2.

    I believe they both contain almost complete list of students, so matching criteria are not effective. Criteria like "" cannot use index, so it leads to table scans as well.

    So optimizer chooses to join everything to everything and filter out the result.

    This intermediate result table is stored in your TempDB and overloads it.

    _____________
    Code for TallyGenerator

  • A method to make it easier to avoid such accidental crossjoins etc, is to abandon the legacy join syntax used here, and rewrite it using ANSI join syntax.

    /Kenneth

  • Thank you guys for your help.

  • Heh... or just pay attention to what you're doing   Either way, a trip to the estimated execution plan probably would have shown the bazillions of rows this was going to generate internally.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Well, 'paying attention' only gets you that far, and going ANSI lessens that burden somewhat.

    Apart from that, the legacy join syntax is way overdue by now, and really shouldn't be used anywhere.

    Especially not when writing new code.

    In SQL Server 2005 it's already halfway to total deprecation. Inner joins do still work, but if you suddenly need an outer join, that won't work anymore.

    So I still recommend, switch style to ANSI.

    It's easier to read, easier to understand, easier to write, and it's more predictable (regarding outer joins) how it works.

    /Kenneth

Viewing 6 posts - 16 through 20 (of 20 total)

You must be logged in to reply to this topic. Login to reply