You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

659 lines
23 KiB

Applying InnoDB snapshot 5.1-ss5282, Fixes BUG#44030 1. Fixes BUG#44030 - Error: (1500) Couldn't read the MAX(ID) autoinc value from the index (PRIMARY) 2. Disables the innodb-autoinc test for innodb plugin temporarily. The testcase for this bug has different result file for InnoDB plugin. Should add the testcase to Innodb suite with a different result file. Detailed revision comments: r5243 | sunny | 2009-06-04 03:17:14 +0300 (Thu, 04 Jun 2009) | 14 lines branches/5.1: When the InnoDB and MySQL data dictionaries go out of sync, before the bug fix we would assert on missing autoinc columns. With this fix we allow MySQL to open the table but set the next autoinc value for the column to the MAX value. This effectively disables the next value generation. INSERTs will fail with a generic AUTOINC failure. However, the user should be able to read/dump the table, set the column values explicitly, use ALTER TABLE to set the next autoinc value and/or sync the two data dictionaries to resume normal operations. Fix Bug#44030 Error: (1500) Couldn't read the MAX(ID) autoinc value from the index (PRIMARY) rb://118 r5252 | sunny | 2009-06-04 10:16:24 +0300 (Thu, 04 Jun 2009) | 2 lines branches/5.1: The version of the result file checked in was broken in r5243. r5259 | vasil | 2009-06-05 10:29:16 +0300 (Fri, 05 Jun 2009) | 7 lines branches/5.1: Remove the word "Error" from the printout because the mysqltest suite interprets it as an error and thus the innodb-autoinc test fails. Approved by: Sunny (via IM) r5466 | vasil | 2009-07-02 10:46:45 +0300 (Thu, 02 Jul 2009) | 6 lines branches/5.1: Adjust the failing innodb-autoinc test to conform to the latest behavior of the MySQL code. The idea and the comment in innodb-autoinc.test come from Sunny.
17 years ago
Applying InnoDB snapshot 5.1-ss5282, Fixes BUG#44030 1. Fixes BUG#44030 - Error: (1500) Couldn't read the MAX(ID) autoinc value from the index (PRIMARY) 2. Disables the innodb-autoinc test for innodb plugin temporarily. The testcase for this bug has different result file for InnoDB plugin. Should add the testcase to Innodb suite with a different result file. Detailed revision comments: r5243 | sunny | 2009-06-04 03:17:14 +0300 (Thu, 04 Jun 2009) | 14 lines branches/5.1: When the InnoDB and MySQL data dictionaries go out of sync, before the bug fix we would assert on missing autoinc columns. With this fix we allow MySQL to open the table but set the next autoinc value for the column to the MAX value. This effectively disables the next value generation. INSERTs will fail with a generic AUTOINC failure. However, the user should be able to read/dump the table, set the column values explicitly, use ALTER TABLE to set the next autoinc value and/or sync the two data dictionaries to resume normal operations. Fix Bug#44030 Error: (1500) Couldn't read the MAX(ID) autoinc value from the index (PRIMARY) rb://118 r5252 | sunny | 2009-06-04 10:16:24 +0300 (Thu, 04 Jun 2009) | 2 lines branches/5.1: The version of the result file checked in was broken in r5243. r5259 | vasil | 2009-06-05 10:29:16 +0300 (Fri, 05 Jun 2009) | 7 lines branches/5.1: Remove the word "Error" from the printout because the mysqltest suite interprets it as an error and thus the innodb-autoinc test fails. Approved by: Sunny (via IM) r5466 | vasil | 2009-07-02 10:46:45 +0300 (Thu, 02 Jul 2009) | 6 lines branches/5.1: Adjust the failing innodb-autoinc test to conform to the latest behavior of the MySQL code. The idea and the comment in innodb-autoinc.test come from Sunny.
17 years ago
Applying InnoDB snapshot 5.1-ss5282, Fixes BUG#44030 1. Fixes BUG#44030 - Error: (1500) Couldn't read the MAX(ID) autoinc value from the index (PRIMARY) 2. Disables the innodb-autoinc test for innodb plugin temporarily. The testcase for this bug has different result file for InnoDB plugin. Should add the testcase to Innodb suite with a different result file. Detailed revision comments: r5243 | sunny | 2009-06-04 03:17:14 +0300 (Thu, 04 Jun 2009) | 14 lines branches/5.1: When the InnoDB and MySQL data dictionaries go out of sync, before the bug fix we would assert on missing autoinc columns. With this fix we allow MySQL to open the table but set the next autoinc value for the column to the MAX value. This effectively disables the next value generation. INSERTs will fail with a generic AUTOINC failure. However, the user should be able to read/dump the table, set the column values explicitly, use ALTER TABLE to set the next autoinc value and/or sync the two data dictionaries to resume normal operations. Fix Bug#44030 Error: (1500) Couldn't read the MAX(ID) autoinc value from the index (PRIMARY) rb://118 r5252 | sunny | 2009-06-04 10:16:24 +0300 (Thu, 04 Jun 2009) | 2 lines branches/5.1: The version of the result file checked in was broken in r5243. r5259 | vasil | 2009-06-05 10:29:16 +0300 (Fri, 05 Jun 2009) | 7 lines branches/5.1: Remove the word "Error" from the printout because the mysqltest suite interprets it as an error and thus the innodb-autoinc test fails. Approved by: Sunny (via IM) r5466 | vasil | 2009-07-02 10:46:45 +0300 (Thu, 02 Jul 2009) | 6 lines branches/5.1: Adjust the failing innodb-autoinc test to conform to the latest behavior of the MySQL code. The idea and the comment in innodb-autoinc.test come from Sunny.
17 years ago
Applying InnoDB snapshot 5.1-ss5282, Fixes BUG#44030 1. Fixes BUG#44030 - Error: (1500) Couldn't read the MAX(ID) autoinc value from the index (PRIMARY) 2. Disables the innodb-autoinc test for innodb plugin temporarily. The testcase for this bug has different result file for InnoDB plugin. Should add the testcase to Innodb suite with a different result file. Detailed revision comments: r5243 | sunny | 2009-06-04 03:17:14 +0300 (Thu, 04 Jun 2009) | 14 lines branches/5.1: When the InnoDB and MySQL data dictionaries go out of sync, before the bug fix we would assert on missing autoinc columns. With this fix we allow MySQL to open the table but set the next autoinc value for the column to the MAX value. This effectively disables the next value generation. INSERTs will fail with a generic AUTOINC failure. However, the user should be able to read/dump the table, set the column values explicitly, use ALTER TABLE to set the next autoinc value and/or sync the two data dictionaries to resume normal operations. Fix Bug#44030 Error: (1500) Couldn't read the MAX(ID) autoinc value from the index (PRIMARY) rb://118 r5252 | sunny | 2009-06-04 10:16:24 +0300 (Thu, 04 Jun 2009) | 2 lines branches/5.1: The version of the result file checked in was broken in r5243. r5259 | vasil | 2009-06-05 10:29:16 +0300 (Fri, 05 Jun 2009) | 7 lines branches/5.1: Remove the word "Error" from the printout because the mysqltest suite interprets it as an error and thus the innodb-autoinc test fails. Approved by: Sunny (via IM) r5466 | vasil | 2009-07-02 10:46:45 +0300 (Thu, 02 Jul 2009) | 6 lines branches/5.1: Adjust the failing innodb-autoinc test to conform to the latest behavior of the MySQL code. The idea and the comment in innodb-autoinc.test come from Sunny.
17 years ago
  1. -- source include/have_innodb.inc
  2. # embedded server ignores 'delayed', so skip this
  3. -- source include/not_embedded.inc
  4. --disable_warnings
  5. drop table if exists t1;
  6. --enable_warnings
  7. #
  8. # Bug #34335
  9. #
  10. CREATE TABLE t1 (c1 BIGINT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
  11. INSERT INTO t1 VALUES (9223372036854775807, null);
  12. -- error ER_DUP_ENTRY,1062
  13. INSERT INTO t1 (c2) VALUES ('innodb');
  14. SELECT * FROM t1;
  15. DROP TABLE t1;
  16. #
  17. ## Test AUTOINC overflow
  18. ##
  19. # TINYINT
  20. CREATE TABLE t1 (c1 TINYINT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
  21. INSERT INTO t1 VALUES (127, null);
  22. -- error ER_DUP_ENTRY,1062
  23. INSERT INTO t1 (c2) VALUES ('innodb');
  24. SELECT * FROM t1;
  25. DROP TABLE t1;
  26. CREATE TABLE t1 (c1 TINYINT UNSIGNED PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
  27. INSERT INTO t1 VALUES (255, null);
  28. -- error ER_DUP_ENTRY,1062
  29. INSERT INTO t1 (c2) VALUES ('innodb');
  30. SELECT * FROM t1;
  31. DROP TABLE t1;
  32. #
  33. # SMALLINT
  34. #
  35. CREATE TABLE t1 (c1 SMALLINT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
  36. INSERT INTO t1 VALUES (32767, null);
  37. -- error ER_DUP_ENTRY,1062
  38. INSERT INTO t1 (c2) VALUES ('innodb');
  39. SELECT * FROM t1;
  40. DROP TABLE t1;
  41. CREATE TABLE t1 (c1 SMALLINT UNSIGNED PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
  42. INSERT INTO t1 VALUES (65535, null);
  43. -- error ER_DUP_ENTRY,1062
  44. INSERT INTO t1 (c2) VALUES ('innodb');
  45. SELECT * FROM t1;
  46. DROP TABLE t1;
  47. #
  48. # MEDIUMINT
  49. #
  50. CREATE TABLE t1 (c1 MEDIUMINT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
  51. INSERT INTO t1 VALUES (8388607, null);
  52. -- error ER_DUP_ENTRY,1062
  53. INSERT INTO t1 (c2) VALUES ('innodb');
  54. SELECT * FROM t1;
  55. DROP TABLE t1;
  56. CREATE TABLE t1 (c1 MEDIUMINT UNSIGNED PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
  57. INSERT INTO t1 VALUES (16777215, null);
  58. -- error ER_DUP_ENTRY,1062
  59. INSERT INTO t1 (c2) VALUES ('innodb');
  60. SELECT * FROM t1;
  61. DROP TABLE t1;
  62. #
  63. # INT
  64. #
  65. CREATE TABLE t1 (c1 INT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
  66. INSERT INTO t1 VALUES (2147483647, null);
  67. -- error ER_DUP_ENTRY,1062
  68. INSERT INTO t1 (c2) VALUES ('innodb');
  69. SELECT * FROM t1;
  70. DROP TABLE t1;
  71. CREATE TABLE t1 (c1 INT UNSIGNED PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
  72. INSERT INTO t1 VALUES (4294967295, null);
  73. -- error ER_DUP_ENTRY,1062
  74. INSERT INTO t1 (c2) VALUES ('innodb');
  75. SELECT * FROM t1;
  76. DROP TABLE t1;
  77. #
  78. # BIGINT
  79. #
  80. CREATE TABLE t1 (c1 BIGINT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
  81. INSERT INTO t1 VALUES (9223372036854775807, null);
  82. -- error ER_DUP_ENTRY,1062
  83. INSERT INTO t1 (c2) VALUES ('innodb');
  84. SELECT * FROM t1;
  85. DROP TABLE t1;
  86. CREATE TABLE t1 (c1 BIGINT UNSIGNED PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
  87. INSERT INTO t1 VALUES (18446744073709551615, null);
  88. -- error ER_AUTOINC_READ_FAILED,1467
  89. INSERT INTO t1 (c2) VALUES ('innodb');
  90. SELECT * FROM t1;
  91. DROP TABLE t1;
  92. #
  93. # Bug 37531
  94. # After truncate, auto_increment behaves incorrectly for InnoDB
  95. #
  96. CREATE TABLE t1(c1 INT PRIMARY KEY AUTO_INCREMENT) ENGINE=InnoDB;
  97. INSERT INTO t1 VALUES (1), (2), (3);
  98. INSERT INTO t1 VALUES (NULL), (NULL), (NULL);
  99. SELECT c1 FROM t1;
  100. SHOW CREATE TABLE t1;
  101. TRUNCATE TABLE t1;
  102. SHOW CREATE TABLE t1;
  103. INSERT INTO t1 VALUES (1), (2), (3);
  104. INSERT INTO t1 VALUES (NULL), (NULL), (NULL);
  105. SELECT c1 FROM t1;
  106. SHOW CREATE TABLE t1;
  107. DROP TABLE t1;
  108. #
  109. # Deleting all records should not reset the AUTOINC counter.
  110. #
  111. CREATE TABLE t1(c1 INT PRIMARY KEY AUTO_INCREMENT) ENGINE=InnoDB;
  112. INSERT INTO t1 VALUES (1), (2), (3);
  113. INSERT INTO t1 VALUES (NULL), (NULL), (NULL);
  114. SELECT c1 FROM t1;
  115. SHOW CREATE TABLE t1;
  116. DELETE FROM t1;
  117. SHOW CREATE TABLE t1;
  118. INSERT INTO t1 VALUES (1), (2), (3);
  119. INSERT INTO t1 VALUES (NULL), (NULL), (NULL);
  120. SELECT c1 FROM t1;
  121. SHOW CREATE TABLE t1;
  122. DROP TABLE t1;
  123. #
  124. # Bug 38839
  125. # Reset the last value generated at end of statement
  126. #
  127. DROP TABLE IF EXISTS t1;
  128. CREATE TABLE t1 (c1 INT AUTO_INCREMENT, c2 INT, PRIMARY KEY(c1)) ENGINE=InnoDB;
  129. INSERT INTO t1 VALUES (NULL, 1);
  130. DELETE FROM t1 WHERE c1 = 1;
  131. INSERT INTO t1 VALUES (2,1);
  132. INSERT INTO t1 VALUES (NULL,8);
  133. SELECT * FROM t1;
  134. DROP TABLE t1;
  135. # Bug 38839 -- same as above but for multi value insert
  136. DROP TABLE IF EXISTS t1;
  137. CREATE TABLE t1 (c1 INT AUTO_INCREMENT, c2 INT, PRIMARY KEY(c1)) ENGINE=InnoDB;
  138. INSERT INTO t1 VALUES (NULL, 1);
  139. DELETE FROM t1 WHERE c1 = 1;
  140. INSERT INTO t1 VALUES (2,1), (NULL, 8);
  141. INSERT INTO t1 VALUES (NULL,9);
  142. SELECT * FROM t1;
  143. DROP TABLE t1;
  144. #
  145. # Test changes to AUTOINC next value calculation
  146. SET @@SESSION.AUTO_INCREMENT_INCREMENT=100, @@SESSION.AUTO_INCREMENT_OFFSET=10;
  147. SHOW VARIABLES LIKE "%auto_inc%";
  148. DROP TABLE IF EXISTS t1;
  149. CREATE TABLE t1 (c1 INT AUTO_INCREMENT, PRIMARY KEY(c1)) ENGINE=InnoDB;
  150. INSERT INTO t1 VALUES (NULL),(5),(NULL);
  151. INSERT INTO t1 VALUES (250),(NULL);
  152. SELECT * FROM t1;
  153. INSERT INTO t1 VALUES (1000);
  154. SET @@INSERT_ID=400;
  155. INSERT INTO t1 VALUES(NULL),(NULL);
  156. SELECT * FROM t1;
  157. DROP TABLE t1;
  158. # Test with SIGNED INT column, by inserting a 0 for the first column value
  159. # 0 is treated in the same was NULL.
  160. # Reset the AUTOINC session variables
  161. SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=1;
  162. SET @@INSERT_ID=1;
  163. SHOW VARIABLES LIKE "%auto_inc%";
  164. DROP TABLE IF EXISTS t1;
  165. CREATE TABLE t1 (c1 INT AUTO_INCREMENT, PRIMARY KEY(c1)) ENGINE=InnoDB;
  166. INSERT INTO t1 VALUES(0);
  167. SELECT * FROM t1;
  168. SET @@SESSION.AUTO_INCREMENT_INCREMENT=100, @@SESSION.AUTO_INCREMENT_OFFSET=10;
  169. INSERT INTO t1 VALUES (-1), (NULL),(2),(NULL);
  170. INSERT INTO t1 VALUES (250),(NULL);
  171. SELECT * FROM t1;
  172. SET @@INSERT_ID=400;
  173. # Duplicate error expected here for autoinc_lock_mode != TRADITIONAL
  174. -- error ER_DUP_ENTRY,1062
  175. INSERT INTO t1 VALUES(NULL),(NULL);
  176. SELECT * FROM t1;
  177. DROP TABLE t1;
  178. # Test with SIGNED INT column
  179. # Reset the AUTOINC session variables
  180. SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=1;
  181. SET @@INSERT_ID=1;
  182. SHOW VARIABLES LIKE "%auto_inc%";
  183. DROP TABLE IF EXISTS t1;
  184. CREATE TABLE t1 (c1 INT AUTO_INCREMENT, PRIMARY KEY(c1)) ENGINE=InnoDB;
  185. INSERT INTO t1 VALUES(-1);
  186. SELECT * FROM t1;
  187. SET @@SESSION.AUTO_INCREMENT_INCREMENT=100, @@SESSION.AUTO_INCREMENT_OFFSET=10;
  188. SHOW VARIABLES LIKE "%auto_inc%";
  189. INSERT INTO t1 VALUES (-2), (NULL),(2),(NULL);
  190. INSERT INTO t1 VALUES (250),(NULL);
  191. SELECT * FROM t1;
  192. INSERT INTO t1 VALUES (1000);
  193. SET @@INSERT_ID=400;
  194. INSERT INTO t1 VALUES(NULL),(NULL);
  195. SELECT * FROM t1;
  196. DROP TABLE t1;
  197. # Test with UNSIGNED INT column, single insert
  198. # The sign in the value is ignored and a new column value is generated
  199. # Reset the AUTOINC session variables
  200. SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=1;
  201. SET @@INSERT_ID=1;
  202. SHOW VARIABLES LIKE "%auto_inc%";
  203. DROP TABLE IF EXISTS t1;
  204. CREATE TABLE t1 (c1 INT UNSIGNED AUTO_INCREMENT, PRIMARY KEY(c1)) ENGINE=InnoDB;
  205. INSERT INTO t1 VALUES(-1);
  206. SELECT * FROM t1;
  207. SET @@SESSION.AUTO_INCREMENT_INCREMENT=100, @@SESSION.AUTO_INCREMENT_OFFSET=10;
  208. SHOW VARIABLES LIKE "%auto_inc%";
  209. INSERT INTO t1 VALUES (-2);
  210. INSERT INTO t1 VALUES (NULL);
  211. INSERT INTO t1 VALUES (2);
  212. INSERT INTO t1 VALUES (NULL);
  213. INSERT INTO t1 VALUES (250);
  214. INSERT INTO t1 VALUES (NULL);
  215. SELECT * FROM t1;
  216. INSERT INTO t1 VALUES (1000);
  217. SET @@INSERT_ID=400;
  218. INSERT INTO t1 VALUES(NULL);
  219. INSERT INTO t1 VALUES(NULL);
  220. SELECT * FROM t1;
  221. DROP TABLE t1;
  222. # Test with UNSIGNED INT column, multi-value inserts
  223. # The sign in the value is ignored and a new column value is generated
  224. # Reset the AUTOINC session variables
  225. SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=1;
  226. SET @@INSERT_ID=1;
  227. SHOW VARIABLES LIKE "%auto_inc%";
  228. DROP TABLE IF EXISTS t1;
  229. CREATE TABLE t1 (c1 INT UNSIGNED AUTO_INCREMENT, PRIMARY KEY(c1)) ENGINE=InnoDB;
  230. INSERT INTO t1 VALUES(-1);
  231. SELECT * FROM t1;
  232. SET @@SESSION.AUTO_INCREMENT_INCREMENT=100, @@SESSION.AUTO_INCREMENT_OFFSET=10;
  233. SHOW VARIABLES LIKE "%auto_inc%";
  234. INSERT INTO t1 VALUES (-2),(NULL),(2),(NULL);
  235. INSERT INTO t1 VALUES (250),(NULL);
  236. SELECT * FROM t1;
  237. INSERT INTO t1 VALUES (1000);
  238. SET @@INSERT_ID=400;
  239. # Duplicate error expected here for autoinc_lock_mode != TRADITIONAL
  240. -- error ER_DUP_ENTRY,1062
  241. INSERT INTO t1 VALUES(NULL),(NULL);
  242. SELECT * FROM t1;
  243. DROP TABLE t1;
  244. #
  245. # Check for overflow handling when increment is > 1
  246. SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=1;
  247. SET @@INSERT_ID=1;
  248. SHOW VARIABLES LIKE "%auto_inc%";
  249. DROP TABLE IF EXISTS t1;
  250. CREATE TABLE t1 (c1 BIGINT AUTO_INCREMENT, PRIMARY KEY(c1)) ENGINE=InnoDB;
  251. # TODO: Fix the autoinc init code
  252. # We have to do this because of a bug in the AUTOINC init code.
  253. INSERT INTO t1 VALUES(NULL);
  254. INSERT INTO t1 VALUES (9223372036854775794); #-- 2^63 - 14
  255. SELECT * FROM t1;
  256. SET @@SESSION.AUTO_INCREMENT_INCREMENT=2, @@SESSION.AUTO_INCREMENT_OFFSET=10;
  257. SHOW VARIABLES LIKE "%auto_inc%";
  258. # This should just fit
  259. INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL);
  260. SELECT * FROM t1;
  261. DROP TABLE t1;
  262. #
  263. # Check for overflow handling when increment and offser are > 1
  264. SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=1;
  265. SET @@INSERT_ID=1;
  266. SHOW VARIABLES LIKE "%auto_inc%";
  267. DROP TABLE IF EXISTS t1;
  268. CREATE TABLE t1 (c1 BIGINT UNSIGNED AUTO_INCREMENT, PRIMARY KEY(c1)) ENGINE=InnoDB;
  269. # TODO: Fix the autoinc init code
  270. # We have to do this because of a bug in the AUTOINC init code.
  271. INSERT INTO t1 VALUES(NULL);
  272. INSERT INTO t1 VALUES (18446744073709551603); #-- 2^64 - 13
  273. SELECT * FROM t1;
  274. SET @@SESSION.AUTO_INCREMENT_INCREMENT=2, @@SESSION.AUTO_INCREMENT_OFFSET=10;
  275. SHOW VARIABLES LIKE "%auto_inc%";
  276. # This should fail because of overflow but it doesn't, it seems to be
  277. # a MySQL server bug. It wraps around to 0 for the last value.
  278. # See MySQL Bug# 39828
  279. #
  280. # Instead of wrapping around, it asserts when MySQL is compiled --with-debug
  281. # (see sql/handler.cc:handler::update_auto_increment()). Don't test for
  282. # overflow until Bug #39828 is fixed.
  283. #
  284. # Since this asserts when compiled --with-debug, we can't properly test this
  285. # until Bug #39828 is fixed. For now, this test is meaningless.
  286. #if Bug #39828 is fixed
  287. #INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL);
  288. #else
  289. INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL);
  290. #endif
  291. SELECT * FROM t1;
  292. DROP TABLE t1;
  293. #
  294. # Check for overflow handling when increment and offset are odd numbers
  295. SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=1;
  296. SET @@INSERT_ID=1;
  297. SHOW VARIABLES LIKE "%auto_inc%";
  298. DROP TABLE IF EXISTS t1;
  299. CREATE TABLE t1 (c1 BIGINT UNSIGNED AUTO_INCREMENT, PRIMARY KEY(c1)) ENGINE=InnoDB;
  300. # TODO: Fix the autoinc init code
  301. # We have to do this because of a bug in the AUTOINC init code.
  302. INSERT INTO t1 VALUES(NULL);
  303. INSERT INTO t1 VALUES (18446744073709551603); #-- 2^64 - 13
  304. SELECT * FROM t1;
  305. SET @@SESSION.AUTO_INCREMENT_INCREMENT=5, @@SESSION.AUTO_INCREMENT_OFFSET=7;
  306. SHOW VARIABLES LIKE "%auto_inc%";
  307. # This should fail because of overflow but it doesn't. It fails with
  308. # a duplicate entry message because of a MySQL server bug, it wraps
  309. # around. See MySQL Bug# 39828, once MySQL fix the bug we can replace
  310. # the ER_DUP_ENTRY, 1062 below with the appropriate error message
  311. #
  312. # Since this asserts when compiled --with-debug, we can't properly test this
  313. # until Bug #39828 is fixed. For now, this test is meaningless.
  314. #if Bug #39828 is fixed
  315. # Still need to fix this error code, error should mention overflow
  316. #-- error ER_DUP_ENTRY,1062
  317. #INSERT INTO t1 VALUES (NULL),(NULL), (NULL);
  318. #else
  319. INSERT INTO t1 VALUES (NULL),(NULL);
  320. #endif
  321. SELECT * FROM t1;
  322. DROP TABLE t1;
  323. # Check for overflow handling when increment and offset are odd numbers
  324. # and check for large -ve numbers
  325. SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=1;
  326. SET @@INSERT_ID=1;
  327. SHOW VARIABLES LIKE "%auto_inc%";
  328. DROP TABLE IF EXISTS t1;
  329. CREATE TABLE t1 (c1 BIGINT AUTO_INCREMENT, PRIMARY KEY(c1)) ENGINE=InnoDB;
  330. # TODO: Fix the autoinc init code
  331. # We have to do this because of a bug in the AUTOINC init code.
  332. INSERT INTO t1 VALUES(NULL);
  333. INSERT INTO t1 VALUES(-9223372036854775806); #-- -2^63 + 2
  334. INSERT INTO t1 VALUES(-9223372036854775807); #-- -2^63 + 1
  335. INSERT INTO t1 VALUES(-9223372036854775808); #-- -2^63
  336. SELECT * FROM t1;
  337. SET @@SESSION.AUTO_INCREMENT_INCREMENT=3, @@SESSION.AUTO_INCREMENT_OFFSET=3;
  338. SHOW VARIABLES LIKE "%auto_inc%";
  339. INSERT INTO t1 VALUES (NULL),(NULL), (NULL);
  340. SELECT * FROM t1;
  341. DROP TABLE t1;
  342. #
  343. # Check for overflow handling when increment and offset are very
  344. # large numbers 2^60
  345. SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=1;
  346. SET @@INSERT_ID=1;
  347. SHOW VARIABLES LIKE "%auto_inc%";
  348. DROP TABLE IF EXISTS t1;
  349. CREATE TABLE t1 (c1 BIGINT UNSIGNED AUTO_INCREMENT, PRIMARY KEY(c1)) ENGINE=InnoDB;
  350. # TODO: Fix the autoinc init code
  351. # We have to do this because of a bug in the AUTOINC init code.
  352. INSERT INTO t1 VALUES(NULL);
  353. INSERT INTO t1 VALUES (18446744073709551610); #-- 2^64 - 2
  354. SELECT * FROM t1;
  355. SET @@SESSION.AUTO_INCREMENT_INCREMENT=1152921504606846976, @@SESSION.AUTO_INCREMENT_OFFSET=1152921504606846976;
  356. SHOW VARIABLES LIKE "%auto_inc%";
  357. # This should fail because of overflow but it doesn't. It wraps around
  358. # and the autoinc values look bogus too.
  359. # See MySQL Bug# 39828, once MySQL fix the bug we can enable the error
  360. # code expected test.
  361. # -- error ER_AUTOINC_READ_FAILED,1467
  362. #
  363. # Since this asserts when compiled --with-debug, we can't properly test this
  364. # until Bug #39828 is fixed. For now, this test is meaningless.
  365. #if Bug #39828 is fixed
  366. #-- error ER_AUTOINC_READ_FAILED,1467
  367. #INSERT INTO t1 VALUES (NULL),(NULL);
  368. #else
  369. INSERT INTO t1 VALUES (NULL);
  370. #endif
  371. SELECT * FROM t1;
  372. DROP TABLE t1;
  373. #
  374. # Check for floating point autoinc column handling
  375. #
  376. SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=1;
  377. SET @@INSERT_ID=1;
  378. SHOW VARIABLES LIKE "%auto_inc%";
  379. CREATE TABLE t1 (c1 DOUBLE NOT NULL AUTO_INCREMENT, c2 INT, PRIMARY KEY (c1)) ENGINE=InnoDB;
  380. INSERT INTO t1 VALUES(NULL, 1);
  381. INSERT INTO t1 VALUES(NULL, 2);
  382. SELECT * FROM t1;
  383. ALTER TABLE t1 CHANGE c1 c1 SERIAL;
  384. SELECT * FROM t1;
  385. INSERT INTO t1 VALUES(NULL, 3);
  386. INSERT INTO t1 VALUES(NULL, 4);
  387. SELECT * FROM t1;
  388. DROP TABLE IF EXISTS t1;
  389. CREATE TABLE t1 (c1 FLOAT NOT NULL AUTO_INCREMENT, c2 INT, PRIMARY KEY (c1)) ENGINE=InnoDB;
  390. INSERT INTO t1 VALUES(NULL, 1);
  391. INSERT INTO t1 VALUES(NULL, 2);
  392. SELECT * FROM t1;
  393. ALTER TABLE t1 CHANGE c1 c1 SERIAL;
  394. SELECT * FROM t1;
  395. INSERT INTO t1 VALUES(NULL, 3);
  396. INSERT INTO t1 VALUES(NULL, 4);
  397. SELECT * FROM t1;
  398. DROP TABLE t1;
  399. #
  400. # Bug# 42714: AUTOINC column calculated next value not greater than highest
  401. # value stored in table.
  402. #
  403. SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=5;
  404. DROP TABLE IF EXISTS t1;
  405. DROP TABLE IF EXISTS t2;
  406. CREATE TABLE t1 (
  407. a INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
  408. b INT(10) UNSIGNED NOT NULL,
  409. c ENUM('FALSE','TRUE') DEFAULT NULL,
  410. PRIMARY KEY (a)) ENGINE = InnoDB;
  411. CREATE TABLE t2 (
  412. m INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
  413. n INT(10) UNSIGNED NOT NULL,
  414. o enum('FALSE','TRUE') DEFAULT NULL,
  415. PRIMARY KEY (m)) ENGINE = InnoDB;
  416. INSERT INTO t2 (n,o) VALUES
  417. (1 , 'true'), (1 , 'false'), (2 , 'true'), (2 , 'false'), (3 , 'true'),
  418. (3 , 'false'), (4 , 'true'), (4 , 'false'), (5 , 'true'), (5 , 'false');
  419. SHOW CREATE TABLE t2;
  420. INSERT INTO t1 (b,c) SELECT n,o FROM t2 ;
  421. SHOW CREATE TABLE t1;
  422. INSERT INTO t1 (b,c) SELECT n,o FROM t2 ;
  423. SELECT * FROM t1;
  424. SHOW CREATE TABLE t1;
  425. INSERT INTO t1 (b,c) SELECT n,o FROM t2 WHERE o = 'false';
  426. SELECT * FROM t1;
  427. SHOW CREATE TABLE t1;
  428. INSERT INTO t1 (b,c) SELECT n,o FROM t2 WHERE o = 'false';
  429. SELECT * FROM t1;
  430. SHOW CREATE TABLE t1;
  431. INSERT INTO t1 (b,c) SELECT n,o FROM t2 WHERE o = 'false';
  432. SHOW CREATE TABLE t1;
  433. INSERT INTO t1 (b,c) SELECT n,o FROM t2 WHERE o = 'false';
  434. SHOW CREATE TABLE t1;
  435. INSERT INTO t1 (b,c) SELECT n,o FROM t2 WHERE o = 'false';
  436. SELECT * FROM t1;
  437. SHOW CREATE TABLE t1;
  438. DROP TABLE t1;
  439. DROP TABLE t2;
  440. #
  441. # 43203: Overflow from auto incrementing causes server segv
  442. #
  443. DROP TABLE IF EXISTS t1;
  444. DROP TABLE IF EXISTS t2;
  445. CREATE TABLE t1(
  446. c1 INT(10) UNSIGNED NOT NULL AUTO_INCREMENT
  447. PRIMARY KEY) ENGINE=InnoDB;
  448. INSERT INTO t1 VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL);
  449. CREATE TABLE t2(
  450. c1 TINYINT(3) UNSIGNED NOT NULL AUTO_INCREMENT
  451. PRIMARY KEY) ENGINE=InnoDB;
  452. -- error ER_DUP_ENTRY,1062
  453. INSERT INTO t2 SELECT c1 FROM t1;
  454. -- error ER_DUP_ENTRY,1467
  455. INSERT INTO t2 SELECT NULL FROM t1;
  456. DROP TABLE t1;
  457. DROP TABLE t2;
  458. #
  459. # 44030: Error: (1500) Couldn't read the MAX(ID) autoinc value from
  460. # the index (PRIMARY)
  461. # This test requires a restart of the server
  462. SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=1;
  463. CREATE TABLE t1 (c1 INT PRIMARY KEY AUTO_INCREMENT) ENGINE=InnoDB;
  464. INSERT INTO t1 VALUES (null);
  465. INSERT INTO t1 VALUES (null);
  466. ALTER TABLE t1 CHANGE c1 d1 INT NOT NULL AUTO_INCREMENT;
  467. SELECT * FROM t1;
  468. # Restart the server
  469. -- source include/restart_mysqld.inc
  470. # The MySQL and InnoDB data dictionaries should now be out of sync.
  471. # The select should print message to the error log
  472. SELECT * FROM t1;
  473. # MySQL have made a change (http://lists.mysql.com/commits/75268) that no
  474. # longer results in the two data dictionaries being out of sync. If they
  475. # revert their changes then this check for ER_AUTOINC_READ_FAILED will need
  476. # to be enabled.
  477. -- error ER_AUTOINC_READ_FAILED,1467
  478. INSERT INTO t1 VALUES(null);
  479. ALTER TABLE t1 AUTO_INCREMENT = 3;
  480. SHOW CREATE TABLE t1;
  481. INSERT INTO t1 VALUES(null);
  482. SELECT * FROM t1;
  483. DROP TABLE t1;
  484. # If the user has specified negative values for an AUTOINC column then
  485. # InnoDB should ignore those values when setting the table's max value.
  486. SET @@SESSION.AUTO_INCREMENT_INCREMENT=1, @@SESSION.AUTO_INCREMENT_OFFSET=1;
  487. SHOW VARIABLES LIKE "%auto_inc%";
  488. # TINYINT
  489. CREATE TABLE t1 (c1 TINYINT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
  490. INSERT INTO t1 VALUES (1, NULL);
  491. INSERT INTO t1 VALUES (-1, 'innodb');
  492. INSERT INTO t1 VALUES (-127, 'innodb');
  493. INSERT INTO t1 VALUES (NULL, NULL);
  494. SHOW CREATE TABLE t1;
  495. SELECT * FROM t1;
  496. DROP TABLE t1;
  497. CREATE TABLE t1 (c1 TINYINT UNSIGNED PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
  498. INSERT INTO t1 VALUES (1, NULL);
  499. INSERT INTO t1 VALUES (-1, 'innodb');
  500. INSERT INTO t1 VALUES (-127, 'innodb');
  501. INSERT INTO t1 VALUES (NULL, NULL);
  502. SHOW CREATE TABLE t1;
  503. SELECT * FROM t1;
  504. DROP TABLE t1;
  505. #
  506. # SMALLINT
  507. #
  508. CREATE TABLE t1 (c1 SMALLINT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
  509. INSERT INTO t1 VALUES (1, NULL);
  510. INSERT INTO t1 VALUES (-1, 'innodb');
  511. INSERT INTO t1 VALUES (-32767, 'innodb');
  512. INSERT INTO t1 VALUES (NULL, NULL);
  513. SHOW CREATE TABLE t1;
  514. SELECT * FROM t1;
  515. DROP TABLE t1;
  516. CREATE TABLE t1 (c1 SMALLINT UNSIGNED PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
  517. INSERT INTO t1 VALUES (1, NULL);
  518. INSERT INTO t1 VALUES (-1, 'innodb');
  519. INSERT INTO t1 VALUES (-32757, 'innodb');
  520. INSERT INTO t1 VALUES (NULL, NULL);
  521. SHOW CREATE TABLE t1;
  522. SELECT * FROM t1;
  523. DROP TABLE t1;
  524. #
  525. # MEDIUMINT
  526. #
  527. CREATE TABLE t1 (c1 MEDIUMINT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
  528. INSERT INTO t1 VALUES (1, NULL);
  529. INSERT INTO t1 VALUES (-1, 'innodb');
  530. INSERT INTO t1 VALUES (-8388607, 'innodb');
  531. INSERT INTO t1 VALUES (NULL, NULL);
  532. SHOW CREATE TABLE t1;
  533. SELECT * FROM t1;
  534. DROP TABLE t1;
  535. CREATE TABLE t1 (c1 MEDIUMINT UNSIGNED PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
  536. INSERT INTO t1 VALUES (1, NULL);
  537. INSERT INTO t1 VALUES (-1, 'innodb');
  538. INSERT INTO t1 VALUES (-8388607, 'innodb');
  539. INSERT INTO t1 VALUES (NULL, NULL);
  540. SHOW CREATE TABLE t1;
  541. SELECT * FROM t1;
  542. DROP TABLE t1;
  543. #
  544. # INT
  545. #
  546. CREATE TABLE t1 (c1 INT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
  547. INSERT INTO t1 VALUES (1, NULL);
  548. INSERT INTO t1 VALUES (-1, 'innodb');
  549. INSERT INTO t1 VALUES (-2147483647, 'innodb');
  550. INSERT INTO t1 VALUES (NULL, NULL);
  551. SHOW CREATE TABLE t1;
  552. SELECT * FROM t1;
  553. DROP TABLE t1;
  554. CREATE TABLE t1 (c1 INT UNSIGNED PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
  555. INSERT INTO t1 VALUES (1, NULL);
  556. INSERT INTO t1 VALUES (-1, 'innodb');
  557. INSERT INTO t1 VALUES (-2147483647, 'innodb');
  558. INSERT INTO t1 VALUES (NULL, NULL);
  559. SHOW CREATE TABLE t1;
  560. SELECT * FROM t1;
  561. DROP TABLE t1;
  562. #
  563. # BIGINT
  564. #
  565. CREATE TABLE t1 (c1 BIGINT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
  566. INSERT INTO t1 VALUES (1, NULL);
  567. INSERT INTO t1 VALUES (-1, 'innodb');
  568. INSERT INTO t1 VALUES (-9223372036854775807, 'innodb');
  569. INSERT INTO t1 VALUES (NULL, NULL);
  570. SHOW CREATE TABLE t1;
  571. SELECT * FROM t1;
  572. DROP TABLE t1;
  573. CREATE TABLE t1 (c1 BIGINT UNSIGNED PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
  574. INSERT INTO t1 VALUES (1, NULL);
  575. INSERT INTO t1 VALUES (-1, 'innodb');
  576. INSERT INTO t1 VALUES (-9223372036854775807, 'innodb');
  577. INSERT INTO t1 VALUES (NULL, NULL);
  578. SHOW CREATE TABLE t1;
  579. SELECT * FROM t1;
  580. DROP TABLE t1;
  581. #
  582. # End negative number check
  583. ##
  584. # 47125: auto_increment start value is ignored if an index is created
  585. # and engine=innodb
  586. #
  587. CREATE TABLE t1 (c1 INT AUTO_INCREMENT, c2 INT, PRIMARY KEY(c1)) AUTO_INCREMENT=10 ENGINE=InnoDB;
  588. CREATE INDEX i1 on t1(c2);
  589. SHOW CREATE TABLE t1;
  590. INSERT INTO t1 (c2) values (0);
  591. SELECT * FROM t1;
  592. DROP TABLE t1;
  593. ##
  594. # 49032: Use the correct function to read the AUTOINC column value
  595. #
  596. DROP TABLE IF EXISTS t1;
  597. CREATE TABLE t1(C1 DOUBLE AUTO_INCREMENT KEY, C2 CHAR(10)) ENGINE=InnoDB;
  598. INSERT INTO t1(C1, C2) VALUES (1, 'innodb'), (3, 'innodb');
  599. # Restart the server
  600. -- source include/restart_mysqld.inc
  601. INSERT INTO t1(C2) VALUES ('innodb');
  602. SHOW CREATE TABLE t1;
  603. DROP TABLE t1;
  604. CREATE TABLE t1(C1 FLOAT AUTO_INCREMENT KEY, C2 CHAR(10)) ENGINE=InnoDB;
  605. INSERT INTO t1(C1, C2) VALUES (1, 'innodb'), (3, 'innodb');
  606. # Restart the server
  607. -- source include/restart_mysqld.inc
  608. INSERT INTO t1(C2) VALUES ('innodb');
  609. SHOW CREATE TABLE t1;
  610. DROP TABLE t1;
  611. ##
  612. # 47720: REPLACE INTO Autoincrement column with negative values
  613. #
  614. DROP TABLE IF EXISTS t1;
  615. CREATE TABLE t1 (c1 INT AUTO_INCREMENT PRIMARY KEY) ENGINE=InnoDB;
  616. INSERT INTO t1 SET c1 = 1;
  617. SHOW CREATE TABLE t1;
  618. INSERT INTO t1 SET c1 = 2;
  619. INSERT INTO t1 SET c1 = -1;
  620. SELECT * FROM t1;
  621. -- error ER_DUP_ENTRY,1062
  622. INSERT INTO t1 SET c1 = -1;
  623. SHOW CREATE TABLE t1;
  624. REPLACE INTO t1 VALUES (-1);
  625. SELECT * FROM t1;
  626. SHOW CREATE TABLE t1;
  627. DROP TABLE t1;