summaryrefslogtreecommitdiffstats
path: root/mysql-test/suite/galera/t/galera_toi_alter_auto_increment.test
blob: 793e87cb53e8062e94b5c9fc530f0b7a1f281a5d (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
#
# Test the operation of ALTER TABLE ... AUTO_INCREMENT
#

--source include/galera_cluster.inc
--source include/have_innodb.inc

--connection node_1
CREATE TABLE ten (f1 INTEGER NOT NULL PRIMARY KEY) ENGINE=InnoDB;
INSERT INTO ten VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10);

CREATE TABLE t1 (f1 INTEGER AUTO_INCREMENT PRIMARY KEY, f2 INTEGER) ENGINE=InnoDB;

INSERT INTO t1 (f2) SELECT 1 FROM ten;

--connection node_2
INSERT INTO t1 (f2) SELECT 1 FROM ten;

ALTER TABLE t1 AUTO_INCREMENT = 1000;
INSERT INTO t1 (f2) SELECT 1 FROM ten;

--connection node_1
INSERT INTO t1 (f2) SELECT 1 FROM ten;

SELECT MIN(f1) >= 1000, COUNT(*) = 20, COUNT(DISTINCT f1) = 20 FROM t1 WHERE f1 >= 1000;

--connection node_2
SELECT MIN(f1) >= 1000, COUNT(*) = 20, COUNT(DISTINCT f1) = 20 FROM t1 WHERE f1 >= 1000;

#
# AUTO_INCREMENT set to a value lower than the current one.
# The ALTER does nothing, the sequence continues from the current maximum.
#

--connection node_1
ALTER TABLE t1 AUTO_INCREMENT = 5;
INSERT INTO t1 (f2) SELECT 1 FROM ten;

--connection node_2
INSERT INTO t1 (f2) SELECT 1 FROM ten;
SELECT MIN(f1) >= 1000, COUNT(*) = 40, COUNT(DISTINCT f1) = 40 FROM t1 WHERE f1 >= 1000;

--connection node_1
SELECT MIN(f1) >= 1000, COUNT(*) = 40, COUNT(DISTINCT f1) = 40 FROM t1 WHERE f1 >= 1000;

DROP TABLE t1;

#
# Under wsrep_auto_increment_control = OFF
#

--connection node_1
--let $auto_increment_control_orig = `SELECT @@wsrep_auto_increment_control`
--let $auto_increment_increment_node1 = `SELECT @@auto_increment_increment`
--let $auto_increment_offset_node1 = `SELECT @@auto_increment_offset`

# Restore stock MySQL defaults
SET GLOBAL wsrep_auto_increment_control = OFF;
SET GLOBAL auto_increment_increment = 1;
SET GLOBAL auto_increment_offset = 1;

#Open a fresh connection to node_1 so that the variables above take effect
--let $galera_connection_name = node_1a
--let $galera_server_number = 1
--source include/galera_connect.inc

--connection node_2
--let $auto_increment_increment_node2 = `SELECT @@auto_increment_increment`
--let $auto_increment_offset_node2 = `SELECT @@auto_increment_offset`

SET GLOBAL wsrep_auto_increment_control = OFF;
SET GLOBAL auto_increment_increment = 1;
SET GLOBAL auto_increment_offset = 1;

#Open a fresh connection to node_2
--let $galera_connection_name = node_2a
--let $galera_server_number = 2
--source include/galera_connect.inc

--connection node_1a

CREATE TABLE t1 (f1 INTEGER AUTO_INCREMENT PRIMARY KEY, f2 INTEGER) ENGINE=InnoDB;

--connection node_2a
--let $wait_condition = SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1'
--source include/wait_condition.inc

ALTER TABLE t1 AUTO_INCREMENT=100;

--connection node_1a
INSERT INTO t1 (f2) SELECT 1 FROM ten;

--connection node_2a
INSERT INTO t1 (f2) SELECT 1 FROM ten;

SELECT MIN(f1) = 100, MAX(f1) = 119, COUNT(f1) = 20, COUNT(DISTINCT f1) = 20 FROM t1;

--connection node_1a
SELECT MIN(f1) = 100, MAX(f1) = 119, COUNT(f1) = 20, COUNT(DISTINCT f1) = 20 FROM t1;

DROP TABLE t1;

#
# Restore all variables as they were
#

--disable_query_log

--connection node_1
--eval SET GLOBAL wsrep_auto_increment_control = $auto_increment_control_orig
--eval SET GLOBAL auto_increment_increment = $auto_increment_increment_node1
--eval SET GLOBAL auto_increment_offset = $auto_increment_offset_node1

--connection node_2
--eval SET GLOBAL wsrep_auto_increment_control = $auto_increment_control_orig
--eval SET GLOBAL auto_increment_increment = $auto_increment_increment_node2
--eval SET GLOBAL auto_increment_offset = $auto_increment_offset_node2

--enable_query_log

DROP TABLE ten;