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
|
CREATE DATABASE dump_generated;
USE dump_generated;
CREATE TABLE t1 (pk INTEGER, a INTEGER, b INTEGER, c VARCHAR(16),
sum INTEGER GENERATED ALWAYS AS (a+b),
sub VARCHAR(4) GENERATED ALWAYS AS (SUBSTRING(c, 1, 4)),
key k1(sum),
key k2(sub)
) engine=innodb;
INSERT INTO t1(pk, a, b, c) VALUES (1, 11, 12, 'oneone'), (2, 21, 22, 'twotwo');
SELECT * FROM t1;
pk a b c sum sub
1 11 12 oneone 23 oneo
2 21 22 twotwo 43 twot
DELETE FROM t1;
SELECT * FROM t1;
pk a b c sum sub
1 11 12 oneone 23 oneo
2 21 22 twotwo 43 twot
DELETE FROM t1;
LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/t1.txt' INTO TABLE t1;
SELECT * FROM t1;
pk a b c sum sub
1 11 12 oneone 23 oneo
2 21 22 twotwo 43 twot
DROP TABLE t1;
# A table with regular columns after generated
CREATE TABLE t2 (pk INTEGER, a INTEGER, b INTEGER,
sum INTEGER GENERATED ALWAYS AS (a+b),
c VARCHAR(16),
key k1(sum)
) engine=innodb;
INSERT INTO t2(pk, a, b, c) VALUES (1, 11, 12, 'oneone'), (2, 21, 22, 'twotwo');
SELECT * FROM t2;
pk a b sum c
1 11 12 23 oneone
2 21 22 43 twotwo
DELETE FROM t2;
SELECT * FROM t2;
pk a b sum c
1 11 12 23 oneone
2 21 22 43 twotwo
DELETE FROM t2;
LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/t2.txt' INTO TABLE t2;
SELECT * FROM t2;
pk a b sum c
1 11 12 23 oneone
2 21 22 43 twotwo
DROP TABLE t2;
DROP DATABASE dump_generated;
|