oracle working with CTE with condition
DEFINE fromtable1= true;WITH firstQuery AS ( SELECT columns FROM table),secondQuery AS ( SELECT columns FROM second_table) IF @fromtable1= true BEGIN SELECT * FROM firstQuery ENDELSE BEGIN SELECT *...
View ArticleSQL Server query with common table expression suspended with pageiolatch_sh
I have a cte based query which runs for a very long time, and on the Activity Monitor for the query there are multiple rows showing the query is suspended in pageiolatch_sh. The strange thing is that...
View ArticleWhat are use cases for Recursive CTEs?
I am looking for examples of why you would use a recursive CTE, but the dozens of examples I have found in my web searching basically reduce to two:Generating a sequenceIterating through an employee...
View ArticleRepeated CTEs vs Recursive CTE
I'd like to ask which of the following two functions is better for retrieving a hierarchical list of child items from a table. Here are the two function definitions:Version 1 (Recursive CTE):CREATE OR...
View ArticleHow to adapt a recursive CTE over multiple tables?
I'm using PostgreSQL 17I am modelling a package index for the Haskell ecosystem, and a feature that is useful is to determine transitive dependencies. Haskell packages can be normalised as:Package...
View ArticleCreate a plan guide to cache (lazy spool) CTE result
I normally create plan guides by first constructing a query that uses the correct plan, and copying it across to the similar query that doesn't. However, that is sometimes tricky, especially if the...
View ArticleCTE Error when installing sp_WhoIsActive
I have several identical (near as I can tell) SQL Servers where I've recently added sp_WhoIsActive (showing some folks how much I like this tool) but one of them will not let me create the stored...
View Article