-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplan.jq
46 lines (45 loc) · 1.86 KB
/
plan.jq
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
def lpad($n): tostring | " " * ($n - length) + .;
def ispredicate: .type | strings | endswith("Condition") or . == "Split Range";
.. | .planNodes? | values |
. as $planNodes |
(map(select(.kind == "RELATIONAL") | .index // 0) | max | tostring | length) as $maxRelationalNodeIDLength |
# render tree part
(
{} |
recurse(
{depth: ((.depth // 0) + 1), link: $planNodes[.link.childIndex // 0].childLinks[]};
select($planNodes[.link.childIndex // 0].kind == "RELATIONAL" or .link.type == "Scalar")
) |
{index: (.link.childIndex // 0), type: (.link.type // ""), depth: (.depth // 0)} as {$index, $type, $depth} |
$planNodes[$index] |
(.metadata.scan_type | rtrimstr("Scan")) as $scanType |
{
idStr: (if .childLinks | any(ispredicate) then "*\($index)" else $index end | lpad($maxRelationalNodeIDLength + 1)),
displayNameStr: ( [.metadata.call_type, .metadata.iterator_type, $scanType, .displayName] | map(strings) | join(" ")),
linkTypeStr: ($type | if . != "" then "[\(.)] " else . end),
indent: (" " * $depth // ""),
metadataStr: (
.metadata // {} |
del(.["subquery_cluster_node", "scan_type", "iterator_type", "call_type"]) |
to_entries |
map(if .key == "scan_target" then .key = $scanType else . end | "\(.key): \(.value)") |
sort |
join(", ") |
if . != "" then " (\(.))" else . end
)
} |
"\(.idStr) \(.indent)\(.linkTypeStr)\(.displayNameStr)\(.metadataStr)"
),
# render predicates part
(
map(
.index as $nodeIndex |
.childLinks // [] | map(select(ispredicate)) | to_entries[] |
{
type: .value.type,
prefix: (if .key == 0 then "\($nodeIndex // 0):" else "" end),
description: $planNodes[.value.childIndex].shortRepresentation.description,
} |
"\(.prefix | lpad($maxRelationalNodeIDLength + 2)) \(.type): \(.description)"
) | select(. != []) | "Predicates:", .[]
)