Rule Definition
Improperly written Triangular Joins are worse than even Cursors or While Loops and can bring a CPU and Disk System right to it's knees. their processing algorithm is close to quadratic complexity.
For very small counts, the number of internal rows spawned are nearly trivial. But, it doesn't take very many rows to spawn nightmarish numbers of internal rows that can bring a server to its knees.
There's danger in thinking that just avoiding the loop leads to set based code. Triangular Joins are a form of "Hidden row by row agonizing row" that can and will crush performance in the face of even the smallest scalability expectations.
Remediation
restrict the conditions using other critersion
Violation Code Sample
SELECT x.OrderID, x.Freight,
(SELECT SUM(y.Freight) FROM dbo.Orders y
WHERE y.OrderID <= x.OrderID) AS RunningTotal,
(SELECT COUNT(y.Freight)
FROM dbo.Orders y
WHERE y.OrderID <= x.OrderID) AS RunningCount
FROM dbo.Orders X
ORDER BY x.OrderID
Related Technologies
Forms
PL/SQL
Technical Criterion
Efficiency - SQL and Data Handling Performance
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.