forked from sergiisyrovatchenko/SQLSaturday
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path38 - unknown path.sql
47 lines (43 loc) · 1.33 KB
/
38 - unknown path.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
DECLARE @xml XML = '
<QueryPlan>
<RelOp NodeId="0" PhysicalOp="Stream Aggregate">
<StreamAggregate>
<GroupBy>
<ColumnReference Column="UnitPrice" />
</GroupBy>
<RelOp NodeId="1" PhysicalOp="Nested Loops">
<NestedLoops>
<RelOp NodeId="3">
<RelOp NodeId="4" PhysicalOp="Index Scan">
<OutputList />
<IndexScan>
<Warnings NoJoinPredicate="1" />
</IndexScan>
</RelOp>
</RelOp>
<RelOp NodeId="7" PhysicalOp="Nested Loops">
<Warnings TempdbSpills="1" />
</RelOp>
</NestedLoops>
</RelOp>
</StreamAggregate>
</RelOp>
</QueryPlan>'
;WITH cte AS
(
SELECT [type] = t.c.value('local-name(.)', 'NVARCHAR(100)')
, node = CAST(NULL AS XML)
, x = t.c.query('./*')
FROM @XML.nodes('*') t(c)
UNION ALL
SELECT t.c.value('local-name(.)', 'NVARCHAR(100)')
, t.c.query('.')
, t.c.query('./*')
FROM cte
CROSS APPLY x.nodes('*') t(c)
)
SELECT node
FROM cte
WHERE [type] = 'Warnings'
SELECT t.c.query('.')
FROM @xml.nodes('//Warnings') t(c)