summaryrefslogtreecommitdiff
path: root/mysql-test/suite/innodb/t/innodb-alter-table.test
blob: 97f0075f344171a931da59b6bd91e2adc6001ded (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
--source include/innodb_page_size.inc

#
# MMDEV-8386: MariaDB creates very big tmp file and hangs on xtradb
#
drop database if exists moodle19;
create database moodle19;
use moodle19;

CREATE TABLE `mdl_course_modules` (
  `id` bigint(10) NOT NULL AUTO_INCREMENT,
  `course` bigint(10) NOT NULL DEFAULT '0',
  `module` bigint(10) NOT NULL DEFAULT '0',
  `instance` bigint(10) NOT NULL DEFAULT '0',
  `section` bigint(10) NOT NULL DEFAULT '0',
  `idnumber` varchar(100) DEFAULT NULL,
  `added` bigint(10) NOT NULL DEFAULT '0',
  `delay` varchar(10) NOT NULL DEFAULT '0',
  `score` smallint(4) NOT NULL DEFAULT '0',
  `indent` mediumint(5) NOT NULL DEFAULT '0',
  `visible` tinyint(1) NOT NULL DEFAULT '1',
  `checkboxesforprereqs` tinyint(1) NOT NULL DEFAULT '0',
  `stylewhencomplete` varchar(200) DEFAULT '',
  `checkboxforcomplete` tinyint(1) NOT NULL DEFAULT '0',
  `stylewhenlocked` varchar(200) DEFAULT 'locked',
  `visiblewhenlocked` tinyint(1) NOT NULL DEFAULT '1',
  `visibleold` tinyint(1) NOT NULL DEFAULT '1',
  `groupmode` smallint(4) NOT NULL DEFAULT '0',
  `groupingid` bigint(10) NOT NULL DEFAULT '0',
  `groupmembersonly` smallint(4) NOT NULL DEFAULT '0',
  `completion` tinyint(1) NOT NULL DEFAULT '0',
  `completiongradeitemnumber` bigint(10) DEFAULT NULL,
  `completionview` tinyint(1) NOT NULL DEFAULT '0',
  `completionexpected` bigint(10) NOT NULL DEFAULT '0',
  `availablefrom` bigint(10) NOT NULL DEFAULT '0',
  `availableuntil` bigint(10) NOT NULL DEFAULT '0',
  `showavailability` tinyint(1) NOT NULL DEFAULT '0',
  `showdescription` tinyint(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),
  KEY `mdl_courmodu_vis_ix` (`visible`),
  KEY `mdl_courmodu_cou_ix` (`course`),
  KEY `mdl_courmodu_mod_ix` (`module`),
  KEY `mdl_courmodu_ins_ix` (`instance`),
  KEY `mdl_courmodu_idncou_ix` (`idnumber`,`course`),
  KEY `mdl_courmodu_gro_ix` (`groupingid`)
) ENGINE=InnoDB AUTO_INCREMENT=447023 DEFAULT CHARSET=utf8 COMMENT='course_modules table retrofitted from MySQL';

let $num= 2701;
--disable_query_log
--echo # Inserting $num rows into the table...
while ($num) 
{
  eval INSERT INTO mdl_course_modules VALUES ($num,4,5,5,24,NULL,1141569781,'',0,0,1,0,'',0,'locked',1,1,0,0,0,0,NULL,0,0,0,0,0,0);
  dec $num;
}
--enable_query_log
ALTER TABLE moodle19.mdl_course_modules ADD stefantest LONGTEXT CHARACTER SET utf8 COLLATE utf8_general_ci AFTER showdescription;

drop database moodle19;

#
# Mdev-9469: Incorrect key file on alter table
#
use test;

CREATE TABLE `w_findispmon05u` (
`atpkey` INT(11) NOT NULL DEFAULT '0',
`atzo05` INT(11) NULL DEFAULT NULL,
`pos` BIGINT(21) NULL DEFAULT NULL,
`f5BnvB` INT(9) NULL DEFAULT NULL,
`f5atbvb` INT(11) NULL DEFAULT NULL,
`f5atbwmg` INT(11) NULL DEFAULT NULL,
`f5pBneu` BIGINT(12) NULL DEFAULT NULL,
`atbwdt` INT(11) NULL DEFAULT NULL,
`atbwzt` INT(11) NULL DEFAULT NULL,
`atbart` VARCHAR(10) NULL DEFAULT NULL
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB;
ALTER TABLE `w_findispmon05u`
CHANGE COLUMN `atpkey` `f5atpkey` INT(11) NOT NULL DEFAULT '0' FIRST,
CHANGE COLUMN `atzo05` `f5atzo05` INT(11) NULL DEFAULT NULL AFTER `f5atpkey`,
CHANGE COLUMN `atbwdt` `f5atbwdt` INT(11) NULL DEFAULT NULL AFTER `f5pBneu`,
CHANGE COLUMN `atbwzt` `f5atbwzt` INT(11) NULL DEFAULT NULL AFTER `f5atbwdt`,
CHANGE COLUMN `atbart` `f5atbart` VARCHAR(10) NULL DEFAULT NULL AFTER `f5atbwzt`,
ADD INDEX `atpkey` (`f5atpkey`),
ADD INDEX `inatkey` (`f5atzo05`, `pos`),
ADD INDEX `pos` (`pos`, `f5atzo05`);

SHOW WARNINGS;
SHOW CREATE TABLE `w_findispmon05u`;

DROP TABLE `w_findispmon05u`;

CREATE TABLE t (
        a INT NOT NULL,
        b INT NOT NULL,
        PRIMARY KEY (a)
) ENGINE=INNODB;

ALTER TABLE t
        CHANGE COLUMN b c INT NOT NULL,
        ADD UNIQUE INDEX (c);

SHOW WARNINGS;
SHOW CREATE TABLE t;

# this should fail
--error 1072
ALTER TABLE t
        CHANGE COLUMN c b INT NOT NULL,
        ADD UNIQUE INDEX (c);

DROP TABLE t;

#
# Check Foreign Keys
#
CREATE TABLE parent (
        a INT NOT NULL,
        b INT NOT NULL,
        PRIMARY KEY (a)
) ENGINE=INNODB;

CREATE TABLE child (
        a INT NOT NULL,
        b INT NOT NULL,
        PRIMARY KEY (a)
) ENGINE=INNODB;

ALTER TABLE child
        CHANGE COLUMN b c INT NOT NULL,
        ADD FOREIGN KEY (c) REFERENCES parent(a);

SHOW WARNINGS;

SHOW CREATE TABLE child;

DROP TABLE child, parent;

#
# MDEV-10535: ALTER TABLE causes standalone/wsrep cluster crash
#
CREATE TABLE IF NOT EXISTS ticket (
    id INT UNSIGNED NOT NULL AUTO_INCREMENT,
    mask VARCHAR(16) DEFAULT '' NOT NULL,
    subject VARCHAR(255)  DEFAULT '' NOT NULL,
    is_closed TINYINT(1) UNSIGNED DEFAULT 0 NOT NULL,
    is_deleted TINYINT(1) UNSIGNED DEFAULT 0 NOT NULL,
    team_id INT UNSIGNED DEFAULT 0 NOT NULL,
    category_id INT UNSIGNED DEFAULT 0 NOT NULL,
    first_message_id INT UNSIGNED DEFAULT 0 NOT NULL,
    created_date INT UNSIGNED,
    updated_date INT UNSIGNED,
    due_date INT UNSIGNED,
    first_wrote_address_id INT UNSIGNED NOT NULL DEFAULT 0,
    last_wrote_address_id INT UNSIGNED NOT NULL DEFAULT 0,
    spam_score DECIMAL(4,4) NOT NULL DEFAULT 0,
    spam_training VARCHAR(1) NOT NULL DEFAULT '',
    interesting_words VARCHAR(255) NOT NULL DEFAULT '',
    next_action VARCHAR(255) NOT NULL DEFAULT '',
    PRIMARY KEY (id)
) ENGINE=InnoDB;
 
ALTER TABLE ticket 
    CHANGE COLUMN team_id group_id INT UNSIGNED NOT NULL DEFAULT 0,
    CHANGE COLUMN category_id bucket_id INT UNSIGNED NOT NULL DEFAULT 0,
    ADD COLUMN org_id INT UNSIGNED NOT NULL DEFAULT 0, 
    ADD INDEX org_id (org_id);

SHOW CREATE TABLE ticket;

DROP TABLE ticket;