summaryrefslogtreecommitdiffstats
path: root/storage/rocksdb/mysql-test/rocksdb/t/ttl_secondary_with_partitions.test
blob: c10c83f9f9d6f47955545ddb6f923321ab87b4e5 (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
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
--source include/have_debug.inc
--source include/have_rocksdb.inc
--source include/have_partition.inc

#
# Create a table with multiple partitions, but in the comment don't specify
# that per-partition based column families (CF) should be created. Expect that
# default CF will be used and new one won't be created.
#
# In addition, specify TTL on one of the partitions. Insert a few things
# inside all the partitions, verify after compaction that the rows inside the
# partition with TTL has disappeared.
#
# Add secondary keys to all tables to test compatibility.
#
CREATE TABLE t1 (
    c1 INT,
    c2 INT,
    PRIMARY KEY (`c1`),
    KEY kc2 (`c2`)
) ENGINE=ROCKSDB
COMMENT="custom_p0_ttl_duration=1;"
PARTITION BY LIST(c1) (
    PARTITION custom_p0 VALUES IN (1, 4, 7),
    PARTITION custom_p1 VALUES IN (2, 5, 8),
    PARTITION custom_p2 VALUES IN (3, 6, 9)
);

set global rocksdb_debug_ttl_rec_ts = -3600;
INSERT INTO t1 values (1, 1);
INSERT INTO t1 values (2, 2);
INSERT INTO t1 values (3, 3);
INSERT INTO t1 values (4, 4);
INSERT INTO t1 values (5, 5);
INSERT INTO t1 values (6, 6);
INSERT INTO t1 values (7, 7);
INSERT INTO t1 values (8, 8);
INSERT INTO t1 values (9, 9);
set global rocksdb_debug_ttl_rec_ts = 0;

--sorted_result
SELECT * FROM t1 FORCE INDEX (PRIMARY);
--sorted_result
SELECT * FROM t1 FORCE INDEX (kc2);

set global rocksdb_force_flush_memtable_now=1;
set global rocksdb_compact_cf='default';

# 1,4, and 7 should be gone
--sorted_result
SELECT * FROM t1 FORCE INDEX (PRIMARY);
--sorted_result
SELECT * FROM t1 FORCE INDEX (kc2);
DROP TABLE t1;

#
# Create a table with multiple partitions and request for separate CF to be
# created per every partition. As a result we expect three different CF-s to be
# created.
#
# In addition, specify TTL on some of the partitions. Insert a few things
# inside all the partitions, verify after compaction that the rows inside the
# partition with TTL has disappeared.
#
CREATE TABLE t1 (
    c1 INT,
    c2 INT,
    name VARCHAR(25) NOT NULL,
    PRIMARY KEY (`c1`, `c2`) COMMENT 'custom_p0_cfname=foo;custom_p1_cfname=my_custom_cf;custom_p2_cfname=baz',
    KEY kc2 (`c2`)
) ENGINE=ROCKSDB
COMMENT="custom_p0_ttl_duration=1;custom_p1_ttl_duration=7;"
PARTITION BY LIST(c1) (
    PARTITION custom_p0 VALUES IN (1, 4, 7),
    PARTITION custom_p1 VALUES IN (2, 5, 8),
    PARTITION custom_p2 VALUES IN (3, 6, 9)
);

set global rocksdb_debug_ttl_rec_ts = -1200;
INSERT INTO t1 values (1,1,'a');
INSERT INTO t1 values (4,4,'aaaa');
INSERT INTO t1 values (7,7,'aaaaaaa');

set global rocksdb_debug_ttl_rec_ts = 1200;
INSERT INTO t1 values (2,2,'aa');
INSERT INTO t1 values (3,3,'aaa');
INSERT INTO t1 values (5,5,'aaaaa');
INSERT INTO t1 values (6,6,'aaaaaa');
INSERT INTO t1 values (8,8,'aaaaaaaa');
INSERT INTO t1 values (9,9,'aaaaaaaaa');
set global rocksdb_debug_ttl_rec_ts = 0;

--sorted_result
SELECT * FROM t1 FORCE INDEX (PRIMARY);
--sorted_result
SELECT * FROM t1 FORCE INDEX (kc2);

set global rocksdb_force_flush_memtable_now=1;
set @@global.rocksdb_compact_cf = 'foo';
set @@global.rocksdb_compact_cf = 'my_custom_cf';
set @@global.rocksdb_compact_cf = 'default';
--sorted_result
SELECT * FROM t1 FORCE INDEX (PRIMARY);
--sorted_result
SELECT * FROM t1 FORCE INDEX (kc2);

set global rocksdb_debug_ttl_snapshot_ts = 3600;
set @@global.rocksdb_compact_cf = 'foo';
--sorted_result
SELECT * FROM t1 FORCE INDEX (PRIMARY);
--sorted_result
SELECT * FROM t1 FORCE INDEX (kc2);

# Now 2,5,8 should be removed (this verifies that TTL is only operating on the
# particular CF.
set @@global.rocksdb_compact_cf = 'my_custom_cf';
set @@global.rocksdb_compact_cf = 'default';
set global rocksdb_debug_ttl_snapshot_ts = 0;
--sorted_result
SELECT * FROM t1 FORCE INDEX (PRIMARY);
--sorted_result
SELECT * FROM t1 FORCE INDEX (kc2);

DROP TABLE t1;

#
# Create a table with CF-s/TTL per partition and verify that ALTER TABLE + DROP
# PRIMARY, ADD PRIMARY work for that scenario and data is persisted/filtered as
# expected.
#
CREATE TABLE t1 (
    c1 INT,
    c2 INT,
    name VARCHAR(25) NOT NULL,
    event DATE,
    PRIMARY KEY (`c1`, `c2`) COMMENT 'custom_p0_cfname=foo;custom_p1_cfname=bar;custom_p2_cfname=baz;',
    KEY kc2 (c2)
) ENGINE=ROCKSDB
COMMENT="custom_p0_ttl_duration=9999;custom_p2_ttl_duration=5;"
PARTITION BY LIST(c1) (
    PARTITION custom_p0 VALUES IN (1, 2, 3),
    PARTITION custom_p1 VALUES IN (4, 5, 6),
    PARTITION custom_p2 VALUES IN (7, 8, 9)
);

INSERT INTO t1 VALUES (1, 1, "one", null);
INSERT INTO t1 VALUES (2, 2, "two", null);
INSERT INTO t1 VALUES (3, 3, "three", null);

INSERT INTO t1 VALUES (4, 4, "four", null);
INSERT INTO t1 VALUES (5, 5, "five", null);
INSERT INTO t1 VALUES (6, 6, "six", null);

INSERT INTO t1 VALUES (7, 7, "seven", null);
INSERT INTO t1 VALUES (8, 8, "eight", null);
INSERT INTO t1 VALUES (9, 9, "nine", null);

--sorted_result
SELECT * FROM t1 FORCE INDEX (PRIMARY);
--sorted_result
SELECT * FROM t1 FORCE INDEX (kc2);

# TTL should be reset after alter table
set global rocksdb_debug_ttl_rec_ts = 600;
ALTER TABLE t1 DROP PRIMARY KEY, ADD PRIMARY KEY(`c2`,`c1`) COMMENT 'custom_p0_cfname=foo;custom_p1_cfname=bar;custom_p2_cfname=baz;';
set global rocksdb_debug_ttl_rec_ts = 0;
SHOW CREATE TABLE t1;

# ...so nothing should be gone here
set global rocksdb_debug_ttl_snapshot_ts = 100;
set global rocksdb_force_flush_memtable_now=1;
set @@global.rocksdb_compact_cf = 'baz';
# Filter out expired secondary keys too
set @@global.rocksdb_compact_cf = 'default';
set global rocksdb_debug_ttl_snapshot_ts = 0;
--sorted_result
SELECT * FROM t1 FORCE INDEX (PRIMARY);
--sorted_result
SELECT * FROM t1 FORCE INDEX (kc2);

set global rocksdb_debug_ttl_snapshot_ts = 1200;
set @@global.rocksdb_compact_cf = 'foo';
set @@global.rocksdb_compact_cf = 'baz';
# Filter out expired secondary keys too
set @@global.rocksdb_compact_cf = 'default';
set global rocksdb_debug_ttl_snapshot_ts = 0;
--sorted_result
SELECT * FROM t1 FORCE INDEX (PRIMARY);
--sorted_result
SELECT * FROM t1 FORCE INDEX (kc2);

DROP TABLE t1;

#
# Create a table with non-partitioned TTL duration, with partitioned TTL
# columns
#
# In this case the same TTL duration will be applied across different TTL
# columns in different partitions, except for in p2 where we override the ttl
# duration.
#
CREATE TABLE t1 (
    c1 BIGINT,
    c2 BIGINT UNSIGNED NOT NULL,
    name VARCHAR(25) NOT NULL,
    event DATE,
    PRIMARY KEY (`c1`) COMMENT 'custom_p0_cfname=foo;custom_p1_cfname=bar;custom_p2_cfname=baz;',
    KEY kc2 (`c2`)
) ENGINE=ROCKSDB
COMMENT="ttl_duration=1;custom_p1_ttl_duration=100;custom_p1_ttl_col=c2;custom_p2_ttl_duration=5000;"
PARTITION BY LIST(c1) (
    PARTITION custom_p0 VALUES IN (1, 2, 3),
    PARTITION custom_p1 VALUES IN (4, 5, 6),
    PARTITION custom_p2 VALUES IN (7, 8, 9)
);

set global rocksdb_debug_ttl_rec_ts = -300;
INSERT INTO t1 VALUES (1, UNIX_TIMESTAMP(), "one", null);
INSERT INTO t1 VALUES (2, UNIX_TIMESTAMP(), "two", null);
INSERT INTO t1 VALUES (3, UNIX_TIMESTAMP(), "three", null);
set global rocksdb_debug_ttl_rec_ts = 0;

INSERT INTO t1 VALUES (4, UNIX_TIMESTAMP(), "four", null);
INSERT INTO t1 VALUES (5, UNIX_TIMESTAMP(), "five", null);
INSERT INTO t1 VALUES (6, UNIX_TIMESTAMP(), "six", null);

INSERT INTO t1 VALUES (7, UNIX_TIMESTAMP(), "seven", null);
INSERT INTO t1 VALUES (8, UNIX_TIMESTAMP(), "eight", null);
INSERT INTO t1 VALUES (9, UNIX_TIMESTAMP(), "nine", null);

set global rocksdb_force_flush_memtable_now=1;
set @@global.rocksdb_compact_cf = 'foo';
set @@global.rocksdb_compact_cf = 'baz';
set @@global.rocksdb_compact_cf = 'bar';
# Filter out expired secondary keys too
set @@global.rocksdb_compact_cf = 'default';

# here we expect only 1,2,3 to be gone, ttl implicit.
--sorted_result
SELECT c1 FROM t1 FORCE INDEX (PRIMARY);
--sorted_result
SELECT c1 FROM t1 FORCE INDEX (kc2);

# here we expect only 4,5,6 to be gone, ttl based on column c2.
set global rocksdb_debug_ttl_snapshot_ts = 600;
set @@global.rocksdb_compact_cf = 'bar';
# Filter out expired secondary keys too
set @@global.rocksdb_compact_cf = 'default';
set global rocksdb_debug_ttl_snapshot_ts = 0;
--sorted_result
SELECT c1 FROM t1 FORCE INDEX (PRIMARY);
--sorted_result
SELECT c1 FROM t1 FORCE INDEX (kc2);

# at this point only 7,8,9 should be left..
DROP TABLE t1;

#
# Add index inplace
#
CREATE TABLE t1 (
    c1 INT,
    c2 INT,
    PRIMARY KEY (`c1`) COMMENT 'custom_p0_cfname=foo;'
) ENGINE=ROCKSDB
COMMENT="custom_p0_ttl_duration=1;"
PARTITION BY LIST(c1) (
    PARTITION custom_p0 VALUES IN (1, 4, 7),
    PARTITION custom_p1 VALUES IN (2, 5, 8),
    PARTITION custom_p2 VALUES IN (3, 6, 9)
);

set global rocksdb_debug_ttl_rec_ts = -3600;
INSERT INTO t1 values (1, 1);
INSERT INTO t1 values (4, 4);
INSERT INTO t1 values (7, 7);
set global rocksdb_debug_ttl_rec_ts = 0;
INSERT INTO t1 values (2, 2);
INSERT INTO t1 values (3, 3);
INSERT INTO t1 values (5, 5);
INSERT INTO t1 values (6, 6);
INSERT INTO t1 values (8, 8);
INSERT INTO t1 values (9, 9);

# Nothing filtered out
--sorted_result
SELECT * FROM t1;

CREATE INDEX kc2 on t1 (c2);

set global rocksdb_force_flush_memtable_now=1;
set global rocksdb_compact_cf='foo';
set global rocksdb_compact_cf='default';

# 1,4, and 7 should be gone
--sorted_result
SELECT * FROM t1 FORCE INDEX (PRIMARY);
--sorted_result
SELECT * FROM t1 FORCE INDEX (kc2);
DROP TABLE t1;