Why recursive cte ignores join hint?

  • Recursive cte is powerful.

    But the loop join will bring so many seeks if the anchor table has many rows.

    I want to try a merge join instead of loop join, proper index can be quite efficient for merge join (both inputs are sorted).

    But the truth is SQL Server ignores my hint and still use a loop join.

    Is there's something wrong or it's by design ?

  • Just MHO, it is probably by design as recursion by nature is a loop.

  • I could be wrong but I'd have to say it's because a recursive CTE is just the same as a While Loop (sometimes, it's worse). It's only going to process in a RBAR fashion and so can't do any kind of a join other than a loop join.

    Perhaps if you told us what the code is trying to accomplish and actually post the code and some test data according to the link in my signature below, we could help you avoid the problem of RBAR code altogether.

    --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)
    Intro to Tally Tables and Functions

Viewing 3 posts - 1 through 2 (of 2 total)

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