I've created a complex process that uses several CTEs (mainly for recursive hierarchical work).
On small sample sets of data everything goes as expected but when I apply the code to large sets of data I received unexpected (and wrong) results.
I think I've narrowed it done to the CTEs. The recursive CTEs are "fed" data processed in several earlier CTEs, and that seems to be the problem.
I set up a sample data set as follows:
- Four rows with unique data
- Each row receives a random row number (this is added in a CTE
I then take the results of the first CTE and perform a self-join in a second CTE.
I expected all rows to join, each to itself. What actually happens is that unequal rows join up.
Can someone offer up an explanation for this behaviour?