summaryrefslogtreecommitdiff
path: root/mysql-test/main/win_orderby.test
blob: 65421fc095caa5809d47276495b2e680e465b7d4 (plain)
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
#
# Tests for window functions and ORDER BY 
#

--disable_warnings
drop table if exists t0,t1;
--enable_warnings

create table t0(a int primary key);
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);

create table t1(
  pk int,
  a int,
  key(pk)
);

insert into t1
select 
  A.a + B.a* 10 + C.a * 100,
  1
from t0 A, t0 B, t0 C;

#enable after fix MDEV-27871
--disable_view_protocol
select 
  pk,
  count(a) over (order by pk rows between 2 preceding and 2 following)
from t1
where pk between 1 and 30
order by pk desc
limit 4;
--disable_view_protocol

drop table t0,t1;


--echo #
--echo # MDEV-30052: Crash with a query containing nested WINDOW clauses
--echo #

CREATE TABLE t1 (c INT);
insert into t1 values (1),(2);
UPDATE t1 SET c=1
WHERE c=2
ORDER BY
  (1 IN ((
      SELECT *
      FROM (SELECT * FROM t1) AS v1
      GROUP BY c
      WINDOW v2 AS (ORDER BY
                      (SELECT *
                       FROM t1
                       GROUP BY c
                       WINDOW v3 AS (PARTITION BY c)
                      )
                    )
    ))
  );
drop table t1;

--echo #
--echo # MDEV-29359: Server crashed with heap-use-after-free in
--echo # Field::is_null(long long) const (Just testcase)
--echo #

CREATE TABLE t1 (id int);
INSERT INTO t1 VALUES (-1),(0),(84);

SELECT
  id IN (SELECT id
         FROM t1
         WINDOW w AS (ORDER BY (SELECT  1
                                FROM t1
                                WHERE
                                  EXISTS ( SELECT id
                                           FROM t1
                                           GROUP BY id
                                           WINDOW w2 AS (ORDER BY id)
                                          )
                                )
                      )
         )
FROM t1;

DROP TABLE t1;

--echo #
--echo # End of 10.3 tests
--echo #