Skip to content

Commit e413c6e

Browse files
committed
Add test case for STD function used as window function
The test case also checks correct functionality of Frame_scan_cursor, as currently STD does not implement the remove() call.
1 parent 00bf18e commit e413c6e

File tree

2 files changed

+455
-0
lines changed

2 files changed

+455
-0
lines changed

mysql-test/r/win_std.result

Lines changed: 321 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,321 @@
1+
create table t1 (
2+
pk int primary key,
3+
a int,
4+
b int
5+
);
6+
create table t2 (
7+
pk int primary key,
8+
a int,
9+
b int,
10+
c char(10)
11+
);
12+
insert into t2 values
13+
( 1, 0, 1, 'one'),
14+
( 2, 0, 2, 'two'),
15+
( 3, 0, 3, 'three'),
16+
( 4, 1, 1, 'one'),
17+
( 5, 1, 1, 'two'),
18+
( 6, 1, 2, 'three');
19+
# First try some invalid queries.
20+
select std(c) over (order by a)
21+
from t2;
22+
std(c) over (order by a)
23+
0
24+
0
25+
0
26+
0
27+
0
28+
0
29+
Warnings:
30+
Warning 1292 Truncated incorrect DOUBLE value: 'one '
31+
Warning 1292 Truncated incorrect DOUBLE value: 'two '
32+
Warning 1292 Truncated incorrect DOUBLE value: 'three '
33+
Warning 1292 Truncated incorrect DOUBLE value: 'one '
34+
Warning 1292 Truncated incorrect DOUBLE value: 'two '
35+
Warning 1292 Truncated incorrect DOUBLE value: 'three '
36+
Warning 1292 Truncated incorrect DOUBLE value: 'one '
37+
Warning 1292 Truncated incorrect DOUBLE value: 'two '
38+
Warning 1292 Truncated incorrect DOUBLE value: 'three '
39+
Warning 1292 Truncated incorrect DOUBLE value: 'one '
40+
Warning 1292 Truncated incorrect DOUBLE value: 'two '
41+
Warning 1292 Truncated incorrect DOUBLE value: 'three '
42+
Warning 1292 Truncated incorrect DOUBLE value: 'one '
43+
Warning 1292 Truncated incorrect DOUBLE value: 'two '
44+
Warning 1292 Truncated incorrect DOUBLE value: 'three '
45+
Warning 1292 Truncated incorrect DOUBLE value: 'one '
46+
Warning 1292 Truncated incorrect DOUBLE value: 'two '
47+
Warning 1292 Truncated incorrect DOUBLE value: 'three '
48+
Warning 1292 Truncated incorrect DOUBLE value: 'one '
49+
Warning 1292 Truncated incorrect DOUBLE value: 'two '
50+
Warning 1292 Truncated incorrect DOUBLE value: 'three '
51+
Warning 1292 Truncated incorrect DOUBLE value: 'one '
52+
Warning 1292 Truncated incorrect DOUBLE value: 'two '
53+
Warning 1292 Truncated incorrect DOUBLE value: 'three '
54+
Warning 1292 Truncated incorrect DOUBLE value: 'one '
55+
Warning 1292 Truncated incorrect DOUBLE value: 'two '
56+
Warning 1292 Truncated incorrect DOUBLE value: 'three '
57+
# Empty frame.
58+
select std(b) over (order by a rows between 2 following and 1 following)
59+
from t2;
60+
std(b) over (order by a rows between 2 following and 1 following)
61+
NULL
62+
NULL
63+
NULL
64+
NULL
65+
NULL
66+
NULL
67+
select std(b) over (order by a range between 2 following and 1 following)
68+
from t2;
69+
std(b) over (order by a range between 2 following and 1 following)
70+
NULL
71+
NULL
72+
NULL
73+
NULL
74+
NULL
75+
NULL
76+
select std(b) over (order by a rows between 1 preceding and 2 preceding)
77+
from t2;
78+
std(b) over (order by a rows between 1 preceding and 2 preceding)
79+
NULL
80+
NULL
81+
NULL
82+
NULL
83+
NULL
84+
NULL
85+
select std(b) over (order by a range between 1 preceding and 2 preceding)
86+
from t2;
87+
std(b) over (order by a range between 1 preceding and 2 preceding)
88+
NULL
89+
NULL
90+
NULL
91+
NULL
92+
NULL
93+
NULL
94+
select std(b) over (order by a rows between 1 following and 0 following)
95+
from t2;
96+
std(b) over (order by a rows between 1 following and 0 following)
97+
NULL
98+
NULL
99+
NULL
100+
NULL
101+
NULL
102+
NULL
103+
select std(b) over (order by a range between 1 following and 0 following)
104+
from t2;
105+
std(b) over (order by a range between 1 following and 0 following)
106+
NULL
107+
NULL
108+
NULL
109+
NULL
110+
NULL
111+
NULL
112+
select std(b) over (order by a rows between 1 following and 0 preceding)
113+
from t2;
114+
std(b) over (order by a rows between 1 following and 0 preceding)
115+
NULL
116+
NULL
117+
NULL
118+
NULL
119+
NULL
120+
NULL
121+
select std(b) over (order by a range between 1 following and 0 preceding)
122+
from t2;
123+
std(b) over (order by a range between 1 following and 0 preceding)
124+
NULL
125+
NULL
126+
NULL
127+
NULL
128+
NULL
129+
NULL
130+
select std(b) over (order by a rows between 0 following and 1 preceding)
131+
from t2;
132+
std(b) over (order by a rows between 0 following and 1 preceding)
133+
NULL
134+
NULL
135+
NULL
136+
NULL
137+
NULL
138+
NULL
139+
select std(b) over (order by a range between 0 following and 1 preceding)
140+
from t2;
141+
std(b) over (order by a range between 0 following and 1 preceding)
142+
NULL
143+
NULL
144+
NULL
145+
NULL
146+
NULL
147+
NULL
148+
# 1 row frame.
149+
select std(b) over (order by a rows between current row and current row)
150+
from t2;
151+
std(b) over (order by a rows between current row and current row)
152+
0.0000
153+
0.0000
154+
0.0000
155+
0.0000
156+
0.0000
157+
0.0000
158+
select std(b) over (order by a rows between 0 preceding and current row)
159+
from t2;
160+
std(b) over (order by a rows between 0 preceding and current row)
161+
0.0000
162+
0.0000
163+
0.0000
164+
0.0000
165+
0.0000
166+
0.0000
167+
select std(b) over (order by a rows between 0 preceding and 0 preceding)
168+
from t2;
169+
std(b) over (order by a rows between 0 preceding and 0 preceding)
170+
0.0000
171+
0.0000
172+
0.0000
173+
0.0000
174+
0.0000
175+
0.0000
176+
select std(b) over (order by a rows between 0 preceding and 0 following)
177+
from t2;
178+
std(b) over (order by a rows between 0 preceding and 0 following)
179+
0.0000
180+
0.0000
181+
0.0000
182+
0.0000
183+
0.0000
184+
0.0000
185+
select std(b) over (order by a rows between 0 following and 0 preceding)
186+
from t2;
187+
std(b) over (order by a rows between 0 following and 0 preceding)
188+
0.0000
189+
0.0000
190+
0.0000
191+
0.0000
192+
0.0000
193+
0.0000
194+
select std(b) over (order by a rows between 0 following and current row)
195+
from t2;
196+
ERROR HY000: Unacceptable combination of window frame bound specifications
197+
select std(b) over (order by a rows between current row and 0 following)
198+
from t2;
199+
std(b) over (order by a rows between current row and 0 following)
200+
0.0000
201+
0.0000
202+
0.0000
203+
0.0000
204+
0.0000
205+
0.0000
206+
# Only peers frame.
207+
select a, b, std(b) over (order by a range between 0 preceding and 0 preceding)
208+
from t2;
209+
a b std(b) over (order by a range between 0 preceding and 0 preceding)
210+
0 1 0.8165
211+
0 2 0.8165
212+
0 3 0.8165
213+
1 1 0.4714
214+
1 1 0.4714
215+
1 2 0.4714
216+
select a, b, std(b) over (order by a range between 0 preceding and current row)
217+
from t2;
218+
a b std(b) over (order by a range between 0 preceding and current row)
219+
0 1 0.8165
220+
0 2 0.8165
221+
0 3 0.8165
222+
1 1 0.4714
223+
1 1 0.4714
224+
1 2 0.4714
225+
select a, b, std(b) over (order by a range between current row and 0 preceding)
226+
from t2;
227+
ERROR HY000: Unacceptable combination of window frame bound specifications
228+
select a, b, std(b) over (order by a range between current row and 0 following)
229+
from t2;
230+
a b std(b) over (order by a range between current row and 0 following)
231+
0 1 0.8165
232+
0 2 0.8165
233+
0 3 0.8165
234+
1 1 0.4714
235+
1 1 0.4714
236+
1 2 0.4714
237+
select a, b, std(b) over (order by a range between 0 following and 0 following)
238+
from t2;
239+
a b std(b) over (order by a range between 0 following and 0 following)
240+
0 1 0.8165
241+
0 2 0.8165
242+
0 3 0.8165
243+
1 1 0.4714
244+
1 1 0.4714
245+
1 2 0.4714
246+
# 2 rows frame.
247+
select pk, a, b, std(b) over (order by a, b, pk rows between 1 preceding and current row)
248+
from t2;
249+
pk a b std(b) over (order by a, b, pk rows between 1 preceding and current row)
250+
1 0 1 0.0000
251+
2 0 2 0.5000
252+
3 0 3 0.5000
253+
4 1 1 1.0000
254+
5 1 1 0.0000
255+
6 1 2 0.5000
256+
select pk, a, b, std(b) over (order by a, b, pk rows between 1 preceding and 0 preceding)
257+
from t2;
258+
pk a b std(b) over (order by a, b, pk rows between 1 preceding and 0 preceding)
259+
1 0 1 0.0000
260+
2 0 2 0.5000
261+
3 0 3 0.5000
262+
4 1 1 1.0000
263+
5 1 1 0.0000
264+
6 1 2 0.5000
265+
select pk, a, b, std(b) over (order by a, b, pk rows between current row and 1 following)
266+
from t2;
267+
pk a b std(b) over (order by a, b, pk rows between current row and 1 following)
268+
1 0 1 0.5000
269+
2 0 2 0.5000
270+
3 0 3 1.0000
271+
4 1 1 0.0000
272+
5 1 1 0.5000
273+
6 1 2 0.0000
274+
select pk, a, b, std(b) over (order by a, b, pk rows between 0 following and 1 following)
275+
from t2;
276+
pk a b std(b) over (order by a, b, pk rows between 0 following and 1 following)
277+
1 0 1 0.5000
278+
2 0 2 0.5000
279+
3 0 3 1.0000
280+
4 1 1 0.0000
281+
5 1 1 0.5000
282+
6 1 2 0.0000
283+
# 2 peers frame.
284+
select pk, a, b, std(b) over (order by a range between 1 preceding and current row)
285+
from t2;
286+
pk a b std(b) over (order by a range between 1 preceding and current row)
287+
1 0 1 0.8165
288+
2 0 2 0.8165
289+
3 0 3 0.8165
290+
4 1 1 0.7454
291+
5 1 1 0.7454
292+
6 1 2 0.7454
293+
select pk, a, b, std(b) over (order by a range between 1 preceding and 0 preceding)
294+
from t2;
295+
pk a b std(b) over (order by a range between 1 preceding and 0 preceding)
296+
1 0 1 0.8165
297+
2 0 2 0.8165
298+
3 0 3 0.8165
299+
4 1 1 0.7454
300+
5 1 1 0.7454
301+
6 1 2 0.7454
302+
select pk, a, b, std(b) over (order by a range between current row and 1 following)
303+
from t2;
304+
pk a b std(b) over (order by a range between current row and 1 following)
305+
1 0 1 0.7454
306+
2 0 2 0.7454
307+
3 0 3 0.7454
308+
4 1 1 0.4714
309+
5 1 1 0.4714
310+
6 1 2 0.4714
311+
select pk, a, b, std(b) over (order by a range between 0 following and 1 following)
312+
from t2;
313+
pk a b std(b) over (order by a range between 0 following and 1 following)
314+
1 0 1 0.7454
315+
2 0 2 0.7454
316+
3 0 3 0.7454
317+
4 1 1 0.4714
318+
5 1 1 0.4714
319+
6 1 2 0.4714
320+
drop table t1;
321+
drop table t2;

0 commit comments

Comments
 (0)