-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLaTeX.sql
More file actions
175 lines (169 loc) · 5.77 KB
/
Copy pathLaTeX.sql
File metadata and controls
175 lines (169 loc) · 5.77 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
-- number formats
declare @timesFormat varchar(10) = 'N1'; -- 1 decimal
declare @countFormat varchar(10) = 'N0'; -- no decimals
drop table if exists #results;
with results as (
select
rm.model,
rm.query,
round(rm.Median, 0) as Median
from (
select distinct
model,
query,
PERCENTILE_CONT(0.5) within group
(order by executionTime) over (partition by model, query) as Median
from Timings
) rm
join (
select
model,
query,
avg(executionTime) as Average,
min(executionTime) as Minimum,
max(executionTime) as Maximum,
stdevp(executionTime) as Deviation
from Timings
group by model, query
) ro
on
ro.model = rm.model
and
ro.query = rm.query
)
select
*
into
#results
from
results
pivot (
max(Median) for model in (
[Temporal], [Optional], [Type 1], [Type 2], [Type 3], [Type 4], [Type 5], [Type 6], [Type 7], [Junk]
)
) pvt;
select
case query
when 'TIY' then '\tiy/'
when 'YIT' then '\yit/'
when 'TOY' then '\toy/'
when 'w/D' then '{\footnotesize Dim}'
when 'w/F' then '{\footnotesize Fact}'
end + ' & ' +
isnull(format(1E0 * [Temporal] / 1000, @timesFormat), '{\NA}') + ' & ' +
isnull(format(1E0 * [Optional] / 1000, @timesFormat), '{\NA}') + ' & ' +
isnull(format(1E0 * [Type 1] / 1000, @timesFormat), '{\NA}') + ' & ' +
isnull(format(1E0 * [Type 2] / 1000, @timesFormat), '{\NA}') + ' & ' +
isnull(format(1E0 * [Type 3] / 1000, @timesFormat), '{\NA}') + ' & ' +
isnull(format(1E0 * [Type 4] / 1000, @timesFormat), '{\NA}') + ' & ' +
isnull(format(1E0 * [Type 5] / 1000, @timesFormat), '{\NA}') + ' & ' +
isnull(format(1E0 * [Type 6] / 1000, @timesFormat), '{\NA}') + ' & ' +
isnull(format(1E0 * [Type 7] / 1000, @timesFormat), '{\NA}') + ' & ' +
isnull(format(1E0 * [Junk] / 1000, @timesFormat), '{\NA}') + ' \\' as tabular
from -- select * from
#results
order by
case query when 'TIY' then 1 when 'YIT' then 2 when 'TOY' then 3 when 'w/D' then 4 when 'w/F' then 5 end;
with waste as (
select
r.query,
case when c.[Temporal] > 0 then c.[Temporal] / r.[Temporal] else c.[Temporal] / w.[Temporal] end as [Temporal],
case when c.[Optional] > 0 then c.[Optional] / r.[Optional] else c.[Optional] / w.[Optional] end as [Optional],
case when c.[Type 1] > 0 then c.[Type 1] / r.[Type 1] else c.[Type 1] / w.[Type 1] end as [Type 1],
case when c.[Type 2] > 0 then c.[Type 2] / r.[Type 2] else c.[Type 2] / w.[Type 2] end as [Type 2],
case when c.[Type 3] > 0 then c.[Type 3] / r.[Type 3] else c.[Type 3] / w.[Type 3] end as [Type 3],
case when c.[Type 4] > 0 then c.[Type 4] / r.[Type 4] else c.[Type 4] / w.[Type 4] end as [Type 4],
case when c.[Type 5] > 0 then c.[Type 5] / r.[Type 5] else c.[Type 5] / w.[Type 5] end as [Type 5],
case when c.[Type 6] > 0 then c.[Type 6] / r.[Type 6] else c.[Type 6] / w.[Type 6] end as [Type 6],
case when c.[Type 7] > 0 then c.[Type 7] / r.[Type 7] else c.[Type 7] / w.[Type 7] end as [Type 7],
case when c.[Junk] > 0 then c.[Junk] / r.[Junk] else c.[Junk] / w.[Junk] end as [Junk]
from
#results r
cross apply (
select
sum([Temporal]) as [Temporal],
sum([Optional]) as [Optional],
sum([Type 1]) as [Type 1],
sum([Type 2]) as [Type 2],
sum([Type 3]) as [Type 3],
sum([Type 4]) as [Type 4],
sum([Type 5]) as [Type 5],
sum([Type 6]) as [Type 6],
sum([Type 7]) as [Type 7],
sum([Junk]) as [Junk]
from
#results
where
query in ('w/D', 'w/F')
) w
cross apply (
values (
1E0 * (w.[Temporal] - r.[Temporal]),
1E0 * (w.[Optional] - r.[Optional]),
1E0 * (w.[Type 1] - r.[Type 1]),
1E0 * (w.[Type 2] - r.[Type 2]),
1E0 * (w.[Type 3] - r.[Type 3]),
1E0 * (w.[Type 4] - r.[Type 4]),
1E0 * (w.[Type 5] - r.[Type 5]),
1E0 * (w.[Type 6] - r.[Type 6]),
1E0 * (w.[Type 7] - r.[Type 7]),
1E0 * (w.[Junk] - r.[Junk])
)
) c (
[Temporal],
[Optional],
[Type 1],
[Type 2],
[Type 3],
[Type 4],
[Type 5],
[Type 6],
[Type 7],
[Junk]
)
where
r.query in ('TIY', 'YIT', 'TOY')
)
select
w.tabular
from (
select
query,
case query
when 'TIY' then '\tiy/'
when 'YIT' then '\yit/'
when 'TOY' then '\toy/'
when 'w/D' then '{\footnotesize Dim}'
when 'w/F' then '{\footnotesize Fact}'
end + ' & ' +
isnull(format(1E0 * [Temporal], @countFormat), '') + ' & ' +
isnull(format(1E0 * [Optional], @countFormat), '') + ' & ' +
isnull(format(1E0 * [Type 1] , @countFormat), '') + ' & ' +
isnull(format(1E0 * [Type 2] , @countFormat), '') + ' & ' +
isnull(format(1E0 * [Type 3] , @countFormat), '') + ' & ' +
isnull(format(1E0 * [Type 4] , @countFormat), '') + ' & ' +
isnull(format(1E0 * [Type 5] , @countFormat), '') + ' & ' +
isnull(format(1E0 * [Type 6] , @countFormat), '') + ' & ' +
isnull(format(1E0 * [Type 7] , @countFormat), '') + ' & ' +
isnull(format(1E0 * [Junk] , @countFormat), '') + ' \\' as tabular
from
waste
union
select
'Tot' as query,
'Tot & ' +
isnull(format(sum(1E0 * abs([Temporal])), @countFormat), '') + ' & ' +
isnull(format(sum(1E0 * abs([Optional])), @countFormat), '') + ' & ' +
isnull(format(sum(1E0 * abs([Type 1] )), @countFormat), '') + ' & ' +
isnull(format(sum(1E0 * abs([Type 2] )), @countFormat), '') + ' & ' +
isnull(format(sum(1E0 * abs([Type 3] )), @countFormat), '') + ' & ' +
isnull(format(sum(1E0 * abs([Type 4] )), @countFormat), '') + ' & ' +
isnull(format(sum(1E0 * abs([Type 5] )), @countFormat), '') + ' & ' +
isnull(format(sum(1E0 * abs([Type 6] )), @countFormat), '') + ' & ' +
isnull(format(sum(1E0 * abs([Type 7] )), @countFormat), '') + ' & ' +
isnull(format(sum(1E0 * abs([Junk] )), @countFormat), '') + ' \\'
from
waste
) w
order by
case query when 'TIY' then 1 when 'YIT' then 2 when 'TOY' then 3 else 5 end;