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.

603 lines
19 KiB

22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
A fix and a test case for Bug#21483 "Server abort or deadlock on INSERT DELAYED with another implicit insert" Also fixes and adds test cases for bugs: 20497 "Trigger with INSERT DELAYED causes Error 1165" 21714 "Wrong NEW.value and server abort on INSERT DELAYED to a table with a trigger". Post-review fixes. Problem: In MySQL INSERT DELAYED is a way to pipe all inserts into a given table through a dedicated thread. This is necessary for simplistic storage engines like MyISAM, which do not have internal concurrency control or threading and thus can not achieve efficient INSERT throughput without support from SQL layer. DELAYED INSERT works as follows: For every distinct table, which can accept DELAYED inserts and has pending data to insert, a dedicated thread is created to write data to disk. All user connection threads that attempt to delayed-insert into this table interact with the dedicated thread in producer/consumer fashion: all records to-be inserted are pushed into a queue of the dedicated thread, which fetches the records and writes them. In this design, client connection threads never open or lock the delayed insert table. This functionality was introduced in version 3.23 and does not take into account existence of triggers, views, or pre-locking. E.g. if INSERT DELAYED is called from a stored function, which, in turn, is called from another stored function that uses the delayed table, a deadlock can occur, because delayed locking by-passes pre-locking. Besides: * the delayed thread works directly with the subject table through the storage engine API and does not invoke triggers * even if it was patched to invoke triggers, if triggers, in turn, used other tables, the delayed thread would have to open and lock involved tables (use pre-locking). * even if it was patched to use pre-locking, without deadlock detection the delayed thread could easily lock out user connection threads in case when the same table is used both in a trigger and on the right side of the insert query: the delayed thread would not release locks until all inserts are complete, and user connection can not complete inserts without having locks on the tables used on the right side of the query. Solution: These considerations suggest two general alternatives for the future of INSERT DELAYED: * it is considered a full-fledged alternative to normal INSERT * it is regarded as an optimisation that is only relevant for simplistic engines. Since we missed our chance to provide complete support of new features when 5.0 was in development, the first alternative currently renders infeasible. However, even the second alternative, which is to detect new features and convert DELAYED insert into a normal insert, is not easy to implement. The catch-22 is that we don't know if the subject table has triggers or is a view before we open it, and we only open it in the delayed thread. We don't know if the query involves pre-locking until we have opened all tables, and we always first create the delayed thread, and only then open the remaining tables. This patch detects the problematic scenarios and converts DELAYED INSERT to a normal INSERT using the following approach: * if the statement is executed under pre-locking (e.g. from within a stored function or trigger) or the right side may require pre-locking, we detect the situation before creating a delayed insert thread and convert the statement to a conventional INSERT. * if the subject table is a view or has triggers, we shutdown the delayed thread and convert the statement to a conventional INSERT.
19 years ago
A fix and a test case for Bug#21483 "Server abort or deadlock on INSERT DELAYED with another implicit insert" Also fixes and adds test cases for bugs: 20497 "Trigger with INSERT DELAYED causes Error 1165" 21714 "Wrong NEW.value and server abort on INSERT DELAYED to a table with a trigger". Post-review fixes. Problem: In MySQL INSERT DELAYED is a way to pipe all inserts into a given table through a dedicated thread. This is necessary for simplistic storage engines like MyISAM, which do not have internal concurrency control or threading and thus can not achieve efficient INSERT throughput without support from SQL layer. DELAYED INSERT works as follows: For every distinct table, which can accept DELAYED inserts and has pending data to insert, a dedicated thread is created to write data to disk. All user connection threads that attempt to delayed-insert into this table interact with the dedicated thread in producer/consumer fashion: all records to-be inserted are pushed into a queue of the dedicated thread, which fetches the records and writes them. In this design, client connection threads never open or lock the delayed insert table. This functionality was introduced in version 3.23 and does not take into account existence of triggers, views, or pre-locking. E.g. if INSERT DELAYED is called from a stored function, which, in turn, is called from another stored function that uses the delayed table, a deadlock can occur, because delayed locking by-passes pre-locking. Besides: * the delayed thread works directly with the subject table through the storage engine API and does not invoke triggers * even if it was patched to invoke triggers, if triggers, in turn, used other tables, the delayed thread would have to open and lock involved tables (use pre-locking). * even if it was patched to use pre-locking, without deadlock detection the delayed thread could easily lock out user connection threads in case when the same table is used both in a trigger and on the right side of the insert query: the delayed thread would not release locks until all inserts are complete, and user connection can not complete inserts without having locks on the tables used on the right side of the query. Solution: These considerations suggest two general alternatives for the future of INSERT DELAYED: * it is considered a full-fledged alternative to normal INSERT * it is regarded as an optimisation that is only relevant for simplistic engines. Since we missed our chance to provide complete support of new features when 5.0 was in development, the first alternative currently renders infeasible. However, even the second alternative, which is to detect new features and convert DELAYED insert into a normal insert, is not easy to implement. The catch-22 is that we don't know if the subject table has triggers or is a view before we open it, and we only open it in the delayed thread. We don't know if the query involves pre-locking until we have opened all tables, and we always first create the delayed thread, and only then open the remaining tables. This patch detects the problematic scenarios and converts DELAYED INSERT to a normal INSERT using the following approach: * if the statement is executed under pre-locking (e.g. from within a stored function or trigger) or the right side may require pre-locking, we detect the situation before creating a delayed insert thread and convert the statement to a conventional INSERT. * if the subject table is a view or has triggers, we shutdown the delayed thread and convert the statement to a conventional INSERT.
19 years ago
  1. drop table if exists t1,t2,t3;
  2. create table t1 (a int not null);
  3. insert into t1 values (1);
  4. insert into t1 values (a+2);
  5. insert into t1 values (a+3);
  6. insert into t1 values (4),(a+5);
  7. select * from t1;
  8. a
  9. 1
  10. 2
  11. 3
  12. 4
  13. 5
  14. drop table t1;
  15. create table t1 (id int not null auto_increment primary key, username varchar(32) not null, unique (username));
  16. insert into t1 values (0,"mysql");
  17. insert into t1 values (0,"mysql ab");
  18. insert into t1 values (0,"mysql a");
  19. insert into t1 values (0,"r1manic");
  20. insert into t1 values (0,"r1man");
  21. drop table t1;
  22. create table t1 (a int not null auto_increment, primary key (a), t timestamp, c char(10) default "hello", i int);
  23. insert into t1 values (default,default,default,default), (default,default,default,default), (4,0,"a",5),(default,default,default,default);
  24. select a,t>0,c,i from t1;
  25. a t>0 c i
  26. 1 1 hello NULL
  27. 2 1 hello NULL
  28. 4 0 a 5
  29. 5 1 hello NULL
  30. truncate table t1;
  31. insert into t1 set a=default,t=default,c=default;
  32. insert into t1 set a=default,t=default,c=default,i=default;
  33. insert into t1 set a=4,t=0,c="a",i=5;
  34. insert into t1 set a=5,t=0,c="a",i=null;
  35. insert into t1 set a=default,t=default,c=default,i=default;
  36. select a,t>0,c,i from t1;
  37. a t>0 c i
  38. 1 1 hello NULL
  39. 2 1 hello NULL
  40. 4 0 a 5
  41. 5 0 a NULL
  42. 6 1 hello NULL
  43. drop table t1;
  44. create table t1 (sid char(20), id int(2) NOT NULL auto_increment, key(sid, id));
  45. insert into t1 values ('skr',NULL),('skr',NULL),('test',NULL);
  46. select * from t1;
  47. sid id
  48. skr 1
  49. skr 2
  50. test 1
  51. insert into t1 values ('rts',NULL),('rts',NULL),('test',NULL);
  52. select * from t1;
  53. sid id
  54. rts 1
  55. rts 2
  56. skr 1
  57. skr 2
  58. test 1
  59. test 2
  60. drop table t1;
  61. create table t1 (id int NOT NULL DEFAULT 8);
  62. insert into t1 values(NULL);
  63. ERROR 23000: Column 'id' cannot be null
  64. insert into t1 values (1), (NULL), (2);
  65. Warnings:
  66. Warning 1048 Column 'id' cannot be null
  67. select * from t1;
  68. id
  69. 1
  70. 0
  71. 2
  72. drop table t1;
  73. create table t1 (email varchar(50));
  74. insert into t1 values ('sasha@mysql.com'),('monty@mysql.com'),('foo@hotmail.com'),('foo@aol.com'),('bar@aol.com');
  75. create table t2(id int not null auto_increment primary key, t2 varchar(50), unique(t2));
  76. insert delayed into t2 (t2) select distinct substring(email, locate('@', email)+1) from t1;
  77. select * from t2;
  78. id t2
  79. 1 mysql.com
  80. 2 hotmail.com
  81. 3 aol.com
  82. drop table t1,t2;
  83. drop database if exists mysqltest;
  84. create database mysqltest;
  85. use mysqltest;
  86. create table t1 (c int);
  87. insert into mysqltest.t1 set mysqltest.t1.c = '1';
  88. drop database mysqltest;
  89. use test;
  90. create table t1(number int auto_increment primary key, original_value varchar(50), f_double double, f_float float, f_double_7_2 double(7,2), f_float_4_3 float (4,3), f_double_u double unsigned, f_float_u float unsigned, f_double_15_1_u double(15,1) unsigned, f_float_3_1_u float (3,1) unsigned);
  91. set @value= "aa";
  92. insert into t1 values(null,@value,@value,@value,@value,@value,@value,@value,@value,@value);
  93. Warnings:
  94. Warning 1265 Data truncated for column 'f_double' at row 1
  95. Warning 1265 Data truncated for column 'f_float' at row 1
  96. Warning 1265 Data truncated for column 'f_double_7_2' at row 1
  97. Warning 1265 Data truncated for column 'f_float_4_3' at row 1
  98. Warning 1265 Data truncated for column 'f_double_u' at row 1
  99. Warning 1265 Data truncated for column 'f_float_u' at row 1
  100. Warning 1265 Data truncated for column 'f_double_15_1_u' at row 1
  101. Warning 1265 Data truncated for column 'f_float_3_1_u' at row 1
  102. select * from t1 where number =last_insert_id();
  103. number 1
  104. original_value aa
  105. f_double 0
  106. f_float 0
  107. f_double_7_2 0.00
  108. f_float_4_3 0.000
  109. f_double_u 0
  110. f_float_u 0
  111. f_double_15_1_u 0.0
  112. f_float_3_1_u 0.0
  113. set @value= "1aa";
  114. insert into t1 values(null,@value,@value,@value,@value,@value,@value,@value,@value,@value);
  115. Warnings:
  116. Warning 1265 Data truncated for column 'f_double' at row 1
  117. Warning 1265 Data truncated for column 'f_float' at row 1
  118. Warning 1265 Data truncated for column 'f_double_7_2' at row 1
  119. Warning 1265 Data truncated for column 'f_float_4_3' at row 1
  120. Warning 1265 Data truncated for column 'f_double_u' at row 1
  121. Warning 1265 Data truncated for column 'f_float_u' at row 1
  122. Warning 1265 Data truncated for column 'f_double_15_1_u' at row 1
  123. Warning 1265 Data truncated for column 'f_float_3_1_u' at row 1
  124. select * from t1 where number =last_insert_id();
  125. number 2
  126. original_value 1aa
  127. f_double 1
  128. f_float 1
  129. f_double_7_2 1.00
  130. f_float_4_3 1.000
  131. f_double_u 1
  132. f_float_u 1
  133. f_double_15_1_u 1.0
  134. f_float_3_1_u 1.0
  135. set @value= "aa1";
  136. insert into t1 values(null,@value,@value,@value,@value,@value,@value,@value,@value,@value);
  137. Warnings:
  138. Warning 1265 Data truncated for column 'f_double' at row 1
  139. Warning 1265 Data truncated for column 'f_float' at row 1
  140. Warning 1265 Data truncated for column 'f_double_7_2' at row 1
  141. Warning 1265 Data truncated for column 'f_float_4_3' at row 1
  142. Warning 1265 Data truncated for column 'f_double_u' at row 1
  143. Warning 1265 Data truncated for column 'f_float_u' at row 1
  144. Warning 1265 Data truncated for column 'f_double_15_1_u' at row 1
  145. Warning 1265 Data truncated for column 'f_float_3_1_u' at row 1
  146. select * from t1 where number =last_insert_id();
  147. number 3
  148. original_value aa1
  149. f_double 0
  150. f_float 0
  151. f_double_7_2 0.00
  152. f_float_4_3 0.000
  153. f_double_u 0
  154. f_float_u 0
  155. f_double_15_1_u 0.0
  156. f_float_3_1_u 0.0
  157. set @value= "1e+1111111111a";
  158. insert into t1 values(null,@value,@value,@value,@value,@value,@value,@value,@value,@value);
  159. Warnings:
  160. Warning 1264 Out of range value adjusted for column 'f_double' at row 1
  161. Warning 1264 Out of range value adjusted for column 'f_float' at row 1
  162. Warning 1264 Out of range value adjusted for column 'f_float' at row 1
  163. Warning 1264 Out of range value adjusted for column 'f_double_7_2' at row 1
  164. Warning 1264 Out of range value adjusted for column 'f_double_7_2' at row 1
  165. Warning 1264 Out of range value adjusted for column 'f_float_4_3' at row 1
  166. Warning 1264 Out of range value adjusted for column 'f_float_4_3' at row 1
  167. Warning 1264 Out of range value adjusted for column 'f_double_u' at row 1
  168. Warning 1264 Out of range value adjusted for column 'f_float_u' at row 1
  169. Warning 1264 Out of range value adjusted for column 'f_float_u' at row 1
  170. Warning 1264 Out of range value adjusted for column 'f_double_15_1_u' at row 1
  171. Warning 1264 Out of range value adjusted for column 'f_double_15_1_u' at row 1
  172. Warning 1264 Out of range value adjusted for column 'f_float_3_1_u' at row 1
  173. Warning 1264 Out of range value adjusted for column 'f_float_3_1_u' at row 1
  174. select * from t1 where number =last_insert_id();
  175. number 4
  176. original_value 1e+1111111111a
  177. f_double 1.79769313486232e+308
  178. f_float 3.40282e+38
  179. f_double_7_2 99999.99
  180. f_float_4_3 9.999
  181. f_double_u 1.79769313486232e+308
  182. f_float_u 3.40282e+38
  183. f_double_15_1_u 99999999999999.9
  184. f_float_3_1_u 99.9
  185. set @value= "-1e+1111111111a";
  186. insert into t1 values(null,@value,@value,@value,@value,@value,@value,@value,@value,@value);
  187. Warnings:
  188. Warning 1264 Out of range value adjusted for column 'f_double' at row 1
  189. Warning 1264 Out of range value adjusted for column 'f_float' at row 1
  190. Warning 1264 Out of range value adjusted for column 'f_float' at row 1
  191. Warning 1264 Out of range value adjusted for column 'f_double_7_2' at row 1
  192. Warning 1264 Out of range value adjusted for column 'f_double_7_2' at row 1
  193. Warning 1264 Out of range value adjusted for column 'f_float_4_3' at row 1
  194. Warning 1264 Out of range value adjusted for column 'f_float_4_3' at row 1
  195. Warning 1264 Out of range value adjusted for column 'f_double_u' at row 1
  196. Warning 1264 Out of range value adjusted for column 'f_double_u' at row 1
  197. Warning 1264 Out of range value adjusted for column 'f_float_u' at row 1
  198. Warning 1264 Out of range value adjusted for column 'f_float_u' at row 1
  199. Warning 1264 Out of range value adjusted for column 'f_double_15_1_u' at row 1
  200. Warning 1264 Out of range value adjusted for column 'f_double_15_1_u' at row 1
  201. Warning 1264 Out of range value adjusted for column 'f_float_3_1_u' at row 1
  202. Warning 1264 Out of range value adjusted for column 'f_float_3_1_u' at row 1
  203. select * from t1 where number =last_insert_id();
  204. number 5
  205. original_value -1e+1111111111a
  206. f_double -1.79769313486232e+308
  207. f_float -3.40282e+38
  208. f_double_7_2 -99999.99
  209. f_float_4_3 -9.999
  210. f_double_u 0
  211. f_float_u 0
  212. f_double_15_1_u 0.0
  213. f_float_3_1_u 0.0
  214. set @value= 1e+1111111111;
  215. ERROR 22007: Illegal double '1e+1111111111' value found during parsing
  216. set @value= -1e+1111111111;
  217. ERROR 22007: Illegal double '1e+1111111111' value found during parsing
  218. set @value= 1e+111;
  219. insert into t1 values(null,@value,@value,@value,@value,@value,@value,@value,@value,@value);
  220. Warnings:
  221. Warning 1264 Out of range value adjusted for column 'f_float' at row 1
  222. Warning 1264 Out of range value adjusted for column 'f_double_7_2' at row 1
  223. Warning 1264 Out of range value adjusted for column 'f_float_4_3' at row 1
  224. Warning 1264 Out of range value adjusted for column 'f_float_u' at row 1
  225. Warning 1264 Out of range value adjusted for column 'f_double_15_1_u' at row 1
  226. Warning 1264 Out of range value adjusted for column 'f_float_3_1_u' at row 1
  227. select * from t1 where number =last_insert_id();
  228. number 6
  229. original_value 1e+111
  230. f_double 1e+111
  231. f_float 3.40282e+38
  232. f_double_7_2 99999.99
  233. f_float_4_3 9.999
  234. f_double_u 1e+111
  235. f_float_u 3.40282e+38
  236. f_double_15_1_u 99999999999999.9
  237. f_float_3_1_u 99.9
  238. set @value= -1e+111;
  239. insert into t1 values(null,@value,@value,@value,@value,@value,@value,@value,@value,@value);
  240. Warnings:
  241. Warning 1264 Out of range value adjusted for column 'f_float' at row 1
  242. Warning 1264 Out of range value adjusted for column 'f_double_7_2' at row 1
  243. Warning 1264 Out of range value adjusted for column 'f_float_4_3' at row 1
  244. Warning 1264 Out of range value adjusted for column 'f_double_u' at row 1
  245. Warning 1264 Out of range value adjusted for column 'f_float_u' at row 1
  246. Warning 1264 Out of range value adjusted for column 'f_double_15_1_u' at row 1
  247. Warning 1264 Out of range value adjusted for column 'f_float_3_1_u' at row 1
  248. select * from t1 where number =last_insert_id();
  249. number 7
  250. original_value -1e+111
  251. f_double -1e+111
  252. f_float -3.40282e+38
  253. f_double_7_2 -99999.99
  254. f_float_4_3 -9.999
  255. f_double_u 0
  256. f_float_u 0
  257. f_double_15_1_u 0.0
  258. f_float_3_1_u 0.0
  259. set @value= 1;
  260. insert into t1 values(null,@value,@value,@value,@value,@value,@value,@value,@value,@value);
  261. select * from t1 where number =last_insert_id();
  262. number 8
  263. original_value 1
  264. f_double 1
  265. f_float 1
  266. f_double_7_2 1.00
  267. f_float_4_3 1.000
  268. f_double_u 1
  269. f_float_u 1
  270. f_double_15_1_u 1.0
  271. f_float_3_1_u 1.0
  272. set @value= -1;
  273. insert into t1 values(null,@value,@value,@value,@value,@value,@value,@value,@value,@value);
  274. Warnings:
  275. Warning 1264 Out of range value adjusted for column 'f_double_u' at row 1
  276. Warning 1264 Out of range value adjusted for column 'f_float_u' at row 1
  277. Warning 1264 Out of range value adjusted for column 'f_double_15_1_u' at row 1
  278. Warning 1264 Out of range value adjusted for column 'f_float_3_1_u' at row 1
  279. select * from t1 where number =last_insert_id();
  280. number 9
  281. original_value -1
  282. f_double -1
  283. f_float -1
  284. f_double_7_2 -1.00
  285. f_float_4_3 -1.000
  286. f_double_u 0
  287. f_float_u 0
  288. f_double_15_1_u 0.0
  289. f_float_3_1_u 0.0
  290. drop table t1;
  291. create table t1(id1 int not null auto_increment primary key, t char(12));
  292. create table t2(id2 int not null, t char(12));
  293. create table t3(id3 int not null, t char(12), index(id3));
  294. select count(*) from t2;
  295. count(*)
  296. 500
  297. insert into t2 select t1.* from t1, t2 t, t3 where t1.id1 = t.id2 and t.id2 = t3.id3;
  298. select count(*) from t2;
  299. count(*)
  300. 25500
  301. drop table t1,t2,t3;
  302. create table t1 (id int primary key, data int);
  303. insert into t1 values (1, 1), (2, 2), (3, 3);
  304. select row_count();
  305. row_count()
  306. 3
  307. insert ignore into t1 values (1, 1);
  308. select row_count();
  309. row_count()
  310. 0
  311. replace into t1 values (1, 11);
  312. select row_count();
  313. row_count()
  314. 2
  315. replace into t1 values (4, 4);
  316. select row_count();
  317. row_count()
  318. 1
  319. insert into t1 values (2, 2) on duplicate key update data= data + 10;
  320. select row_count();
  321. row_count()
  322. 2
  323. insert into t1 values (5, 5) on duplicate key update data= data + 10;
  324. select row_count();
  325. row_count()
  326. 1
  327. drop table t1;
  328. create table t1 (f1 int unique, f2 int);
  329. create table t2 (f3 int, f4 int);
  330. create view v1 as select * from t1, t2 where f1= f3;
  331. insert into t1 values (1,11), (2,22);
  332. insert into t2 values (1,12), (2,24);
  333. insert into v1 (f1) values (3) on duplicate key update f3= f3 + 10;
  334. ERROR HY000: Can not modify more than one base table through a join view 'test.v1'
  335. insert into v1 (f1) values (3) on duplicate key update f1= f3 + 10;
  336. select * from t1;
  337. f1 f2
  338. 1 11
  339. 2 22
  340. 3 NULL
  341. insert into v1 (f1) values (3) on duplicate key update f1= f3 + 10;
  342. select * from t1;
  343. f1 f2
  344. 1 11
  345. 2 22
  346. 12 NULL
  347. drop view v1;
  348. drop table t1,t2;
  349. DROP TABLE IF EXISTS t1;
  350. DROP FUNCTION IF EXISTS f1;
  351. DROP FUNCTION IF EXISTS f2;
  352. CREATE TABLE t1 (i INT);
  353. CREATE FUNCTION f1() RETURNS INT
  354. BEGIN
  355. INSERT INTO t1 VALUES (1);
  356. RETURN 1;
  357. END |
  358. CREATE FUNCTION f2() RETURNS INT
  359. BEGIN
  360. INSERT DELAYED INTO t1 VALUES (2);
  361. RETURN 1;
  362. END |
  363. SELECT f1();
  364. f1()
  365. 1
  366. SELECT f2();
  367. f2()
  368. 1
  369. INSERT INTO t1 VALUES (3);
  370. INSERT DELAYED INTO t1 VALUES (4);
  371. INSERT INTO t1 VALUES (f1());
  372. ERROR HY000: Can't update table 't1' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
  373. INSERT DELAYED INTO t1 VALUES (f1());
  374. ERROR HY000: Can't update table 't1' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
  375. INSERT INTO t1 VALUES (f2());
  376. ERROR HY000: Can't update table 't1' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
  377. INSERT DELAYED INTO t1 VALUES (f2());
  378. ERROR HY000: Can't update table 't1' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
  379. CREATE TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW
  380. INSERT INTO t1 VALUES (NEW.i);
  381. INSERT INTO t1 VALUES (1);
  382. ERROR HY000: Can't update table 't1' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
  383. INSERT DELAYED INTO t1 VALUES (1);
  384. ERROR HY000: Can't update table 't1' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
  385. SELECT * FROM t1;
  386. i
  387. 1
  388. 2
  389. 3
  390. 4
  391. DROP FUNCTION f2;
  392. DROP FUNCTION f1;
  393. DROP TABLE t1;
  394. DROP TABLE IF EXISTS t1, t2;
  395. CREATE TABLE t1 (i INT);
  396. CREATE TABLE t2 (i INT);
  397. CREATE TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW
  398. INSERT DELAYED INTO t2 VALUES (NEW.i);
  399. CREATE TRIGGER t1_bu BEFORE UPDATE ON t1 FOR EACH ROW
  400. INSERT DELAYED INTO t2 VALUES (NEW.i);
  401. CREATE TRIGGER t1_bd BEFORE DELETE ON t1 FOR EACH ROW
  402. INSERT DELAYED INTO t2 VALUES (OLD.i);
  403. INSERT INTO t1 VALUES (1);
  404. INSERT DELAYED INTO t1 VALUES (2);
  405. SELECT * FROM t1;
  406. i
  407. 1
  408. 2
  409. UPDATE t1 SET i = 3 WHERE i = 1;
  410. SELECT * FROM t1;
  411. i
  412. 3
  413. 2
  414. DELETE FROM t1 WHERE i = 3;
  415. SELECT * FROM t1;
  416. i
  417. 2
  418. SELECT * FROM t2;
  419. i
  420. 1
  421. 2
  422. 3
  423. 3
  424. DROP TABLE t1, t2;
  425. DROP TABLE IF EXISTS t1, t2;
  426. CREATE TABLE t1 (i INT);
  427. CREATE TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW
  428. SET @a= NEW.i;
  429. SET @a= 0;
  430. INSERT DELAYED INTO t1 VALUES (1);
  431. SELECT @a;
  432. @a
  433. 1
  434. INSERT DELAYED INTO t1 VALUES (2);
  435. SELECT @a;
  436. @a
  437. 2
  438. DROP TABLE t1;
  439. CREATE TABLE t1 (i INT);
  440. CREATE TABLE t2 (i INT);
  441. CREATE TRIGGER t1_ai AFTER INSERT ON t1 FOR EACH ROW
  442. INSERT INTO t2 VALUES (NEW.i);
  443. CREATE TRIGGER t1_au AFTER UPDATE ON t1 FOR EACH ROW
  444. INSERT DELAYED INTO t2 VALUES (NEW.i);
  445. CREATE TRIGGER t1_ad AFTER DELETE ON t1 FOR EACH ROW
  446. INSERT DELAYED INTO t2 VALUES (OLD.i);
  447. INSERT DELAYED INTO t1 VALUES (1);
  448. SELECT * FROM t1;
  449. i
  450. 1
  451. UPDATE t1 SET i = 2 WHERE i = 1;
  452. SELECT * FROM t1;
  453. i
  454. 2
  455. DELETE FROM t1 WHERE i = 2;
  456. SELECT * FROM t1;
  457. i
  458. SELECT * FROM t2;
  459. i
  460. 1
  461. 2
  462. 2
  463. DROP TABLE t1, t2;
  464. CREATE TABLE t1 (
  465. a char(20) NOT NULL,
  466. b char(7) DEFAULT NULL,
  467. c char(4) DEFAULT NULL
  468. );
  469. INSERT INTO t1(a,b,c) VALUES (9.999999e+0, 9.999999e+0, 9.999e+0);
  470. INSERT INTO t1(a,b,c) VALUES (1.225e-05, 1.225e-05, 1.225e-05);
  471. Warnings:
  472. Warning 1265 Data truncated for column 'c' at row 1
  473. INSERT INTO t1(a,b) VALUES (1.225e-04, 1.225e-04);
  474. INSERT INTO t1(a,b) VALUES (1.225e-01, 1.225e-01);
  475. INSERT INTO t1(a,b) VALUES (1.225877e-01, 1.225877e-01);
  476. INSERT INTO t1(a,b) VALUES (1.225e+01, 1.225e+01);
  477. INSERT INTO t1(a,b,c) VALUES (1.225e+01, 1.225e+01, 1.225e+01);
  478. INSERT INTO t1(a,b) VALUES (1.225e+05, 1.225e+05);
  479. INSERT INTO t1(a,b) VALUES (1.225e+10, 1.225e+10);
  480. INSERT INTO t1(a,b) VALUES (1.225e+15, 1.225e+15);
  481. INSERT INTO t1(a,b) VALUES (5000000e+0, 5000000e+0);
  482. INSERT INTO t1(a,b) VALUES (1.25e+78, 1.25e+78);
  483. INSERT INTO t1(a,b) VALUES (1.25e-94, 1.25e-94);
  484. INSERT INTO t1(a,b) VALUES (1.25e+203, 1.25e+203);
  485. INSERT INTO t1(a,b) VALUES (1.25e-175, 1.25e-175);
  486. INSERT INTO t1(a,c) VALUES (1.225e+0, 1.225e+0);
  487. INSERT INTO t1(a,c) VALUES (1.37e+0, 1.37e+0);
  488. INSERT INTO t1(a,c) VALUES (-1.37e+0, -1.37e+0);
  489. Warnings:
  490. Warning 1265 Data truncated for column 'c' at row 1
  491. INSERT INTO t1(a,c) VALUES (1.87e-3, 1.87e-3);
  492. Warnings:
  493. Warning 1265 Data truncated for column 'c' at row 1
  494. INSERT INTO t1(a,c) VALUES (-1.87e-2, -1.87e-2);
  495. Warnings:
  496. Warning 1265 Data truncated for column 'c' at row 1
  497. INSERT INTO t1(a,c) VALUES (5000e+0, 5000e+0);
  498. INSERT INTO t1(a,c) VALUES (-5000e+0, -5000e+0);
  499. Warnings:
  500. Warning 1265 Data truncated for column 'c' at row 1
  501. SELECT * FROM t1;
  502. a b c
  503. 9.999999 10 10
  504. 1.225e-05 1.2e-05 1e-0
  505. 0.0001225 0.00012 NULL
  506. 0.1225 0.1225 NULL
  507. 0.1225877 0.12259 NULL
  508. 12.25 12.25 NULL
  509. 12.25 12.25 12.2
  510. 122500 122500 NULL
  511. 12250000000 1.2e+10 NULL
  512. 1.225e+15 1.2e+15 NULL
  513. 5000000 5000000 NULL
  514. 1.25e+78 1.2e+78 NULL
  515. 1.25e-94 1.2e-94 NULL
  516. 1.25e+203 1e+203 NULL
  517. 1.25e-175 1e-175 NULL
  518. 1.225 NULL 1.23
  519. 1.37 NULL 1.37
  520. -1.37 NULL -1.3
  521. 0.00187 NULL 0.00
  522. -0.0187 NULL -0.0
  523. 5000 NULL 5000
  524. -5000 NULL -500
  525. DROP TABLE t1;
  526. CREATE TABLE t1 (
  527. a char(20) NOT NULL,
  528. b char(7) DEFAULT NULL,
  529. c char(5)
  530. );
  531. INSERT INTO t1(a,b,c) VALUES (9.999999e+0, 9.999999e+0, 9.999e+0);
  532. INSERT INTO t1(a,b,c) VALUES (1.225e-05, 1.225e-05, 1.225e-05);
  533. INSERT INTO t1(a,b) VALUES (1.225e-04, 1.225e-04);
  534. INSERT INTO t1(a,b) VALUES (1.225e-01, 1.225e-01);
  535. INSERT INTO t1(a,b) VALUES (1.225877e-01, 1.225877e-01);
  536. INSERT INTO t1(a,b) VALUES (1.225e+01, 1.225e+01);
  537. INSERT INTO t1(a,b,c) VALUES (1.225e+01, 1.225e+01, 1.225e+01);
  538. INSERT INTO t1(a,b) VALUES (1.225e+05, 1.225e+05);
  539. INSERT INTO t1(a,b) VALUES (1.225e+10, 1.225e+10);
  540. INSERT INTO t1(a,b) VALUES (1.225e+15, 1.225e+15);
  541. INSERT INTO t1(a,b) VALUES (5000000e+0, 5000000e+0);
  542. INSERT INTO t1(a,b) VALUES (1.25e+78, 1.25e+78);
  543. INSERT INTO t1(a,b) VALUES (1.25e-94, 1.25e-94);
  544. INSERT INTO t1(a,b) VALUES (1.25e+203, 1.25e+203);
  545. INSERT INTO t1(a,b) VALUES (1.25e-175, 1.25e-175);
  546. INSERT INTO t1(a,c) VALUES (1.225e+0, 1.225e+0);
  547. INSERT INTO t1(a,c) VALUES (1.37e+0, 1.37e+0);
  548. INSERT INTO t1(a,c) VALUES (-1.37e+0, -1.37e+0);
  549. INSERT INTO t1(a,c) VALUES (1.87e-3, 1.87e-3);
  550. INSERT INTO t1(a,c) VALUES (-1.87e-2, -1.87e-2);
  551. Warnings:
  552. Warning 1265 Data truncated for column 'c' at row 1
  553. INSERT INTO t1(a,c) VALUES (5000e+0, 5000e+0);
  554. INSERT INTO t1(a,c) VALUES (-5000e+0, -5000e+0);
  555. SELECT * FROM t1;
  556. a b c
  557. 9.999999 10 9.999
  558. 1.225e-05 1.2e-05 1e-05
  559. 0.0001225 0.00012 NULL
  560. 0.1225 0.1225 NULL
  561. 0.1225877 0.12259 NULL
  562. 12.25 12.25 NULL
  563. 12.25 12.25 12.25
  564. 122500 122500 NULL
  565. 12250000000 1.2e+10 NULL
  566. 1.225e+15 1.2e+15 NULL
  567. 5000000 5000000 NULL
  568. 1.25e+78 1.2e+78 NULL
  569. 1.25e-94 1.2e-94 NULL
  570. 1.25e+203 1e+203 NULL
  571. 1.25e-175 1e-175 NULL
  572. 1.225 NULL 1.225
  573. 1.37 NULL 1.37
  574. -1.37 NULL -1.37
  575. 0.00187 NULL 0.002
  576. -0.0187 NULL -0.01
  577. 5000 NULL 5000
  578. -5000 NULL -5000
  579. DROP TABLE t1;
  580. CREATE TABLE t (a CHAR(10),b INT);
  581. INSERT INTO t VALUES (),(),();
  582. INSERT INTO t(a) SELECT rand() FROM t;
  583. DROP TABLE t;
  584. CREATE TABLE t1 (c1 INT NOT NULL);
  585. INSERT INTO t1 VALUES(4188.32999999999992724042385816574096679687500),
  586. ('4188.32999999999992724042385816574096679687500'), (4188);
  587. SELECT * FROM t1;
  588. c1
  589. 4188
  590. 4188
  591. 4188
  592. CREATE TABLE t2 (c1 BIGINT);
  593. INSERT INTO t2 VALUES('15449237462.0000000000');
  594. SELECT * FROM t2;
  595. c1
  596. 15449237462
  597. DROP TABLE t1, t2;
  598. CREATE TABLE t1(f1 FLOAT);
  599. INSERT INTO t1 VALUES (1.23);
  600. CREATE TABLE t2(f1 CHAR(1));
  601. INSERT INTO t2 SELECT f1 FROM t1;
  602. DROP TABLE t1, t2;
  603. End of 5.0 tests.