• rgp151 (12/8/2016)


    Yeah, I can't figure this out. But it is the case that if I simply insert the result of the nested query into a temp table first, then select from the temp table, the whole thing completes in a few minutes.

    I don't get it. It doesn't make any sense and I wish I knew what was going on, but for now, at least putting into a temp table works.

    It may be frustrating, but often it's best to materialize something that otherwise can "get lost in the plan", so to speak. I can't begin to tell you how often I've had CTEs that pull a rather small number of rows end up choking the rest of the query until I put the results into a temp table instead and join to that temp table instead. It just seems sometimes that there are some queries that the optimizer simply can not fathom a good row-count guess for, until it's "written in stone", so to speak.

    Steve (aka sgmunson) 🙂 🙂 🙂
    Rent Servers for Income (picks and shovels strategy)