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.

1588 lines
50 KiB

  1. -- source include/have_partition.inc
  2. -- source suite/versioning/common.inc
  3. -- source suite/versioning/engines.inc
  4. -- source include/have_sequence.inc
  5. set @save_persistent=@@global.innodb_stats_persistent;
  6. set global innodb_stats_persistent= 0;
  7. call mtr.add_suppression("need more HISTORY partitions");
  8. set system_versioning_alter_history=keep;
  9. --echo # Check conventional partitioning on temporal tables
  10. --replace_result $sys_datatype_expl SYS_DATATYPE
  11. eval create or replace table t1 (
  12. x int,
  13. row_start $sys_datatype_expl as row start invisible,
  14. row_end $sys_datatype_expl as row end invisible,
  15. period for system_time(row_start, row_end))
  16. with system versioning
  17. partition by range columns (x) (
  18. partition p0 values less than (100),
  19. partition p1 values less than (1000));
  20. insert into t1 values (3), (300);
  21. select * from t1;
  22. select * from t1 partition (p0);
  23. select * from t1 partition (p1);
  24. delete from t1;
  25. select * from t1;
  26. select * from t1 partition (p0);
  27. select * from t1 partition (p1);
  28. select * from t1 for system_time all;
  29. select * from t1 partition (p0) for system_time all;
  30. select * from t1 partition (p1) for system_time all;
  31. --echo # Engine change native <-> non-native versioning prohibited
  32. --replace_result $sys_datatype_expl SYS_DATATYPE $default_engine DEFAULT_ENGINE
  33. eval create or replace table t1 (
  34. i int,
  35. row_start $sys_datatype_expl as row start invisible,
  36. row_end $sys_datatype_expl as row end invisible,
  37. period for system_time(row_start, row_end))
  38. engine=$default_engine
  39. with system versioning partition by hash(i);
  40. --replace_result $non_default_engine NON_DEFAULT_ENGINE
  41. --error ER_VERS_ALTER_ENGINE_PROHIBITED
  42. eval alter table t1 engine=$non_default_engine;
  43. --echo ## CREATE TABLE
  44. --error ER_VERS_NOT_VERSIONED
  45. create or replace table t1 (x int)
  46. partition by system_time (
  47. partition p0 history,
  48. partition pn current);
  49. create or replace table t1 (x int);
  50. --error ER_VERS_NOT_VERSIONED
  51. alter table t1
  52. partition by system_time (
  53. partition p0 history,
  54. partition pn current);
  55. --error ER_VERS_WRONG_PARTS
  56. create or replace table t1 (x int)
  57. with system versioning
  58. partition by system_time (
  59. partition p0 current);
  60. --error ER_VERS_WRONG_PARTS
  61. create or replace table t1 (x int)
  62. with system versioning
  63. partition by system_time (
  64. partition p0 current,
  65. partition p1 current);
  66. --error ER_VERS_WRONG_PARTS
  67. create or replace table t1 (x int)
  68. with system versioning
  69. partition by system_time (
  70. partition p0 history,
  71. partition p1 history);
  72. --error ER_VERS_WRONG_PARTS
  73. create or replace table t1 (x int)
  74. with system versioning
  75. partition by system_time (
  76. partition pn current,
  77. partition p0 history);
  78. --error ER_VERS_WRONG_PARTS
  79. create or replace table t1 (x int)
  80. with system versioning
  81. partition by system_time (
  82. partition p0,
  83. partition pn current);
  84. create or replace table t1 (x int)
  85. with system versioning
  86. partition by system_time (
  87. partition p0 history,
  88. partition pn current);
  89. --echo ## ALTER TABLE
  90. --error ER_VERS_WRONG_PARTS
  91. alter table t1 add partition (
  92. partition p1 current);
  93. alter table t1 add partition (
  94. partition p1 history);
  95. --replace_result $default_engine DEFAULT_ENGINE
  96. show create table t1;
  97. insert into t1 values (1), (2);
  98. --error ER_VERS_WRONG_PARTS
  99. alter table t1 drop partition pn;
  100. alter table t1 drop partition p1;
  101. --error ER_VERS_WRONG_PARTS
  102. alter table t1 drop partition p0;
  103. select x from t1;
  104. --echo # rename works
  105. create or replace table t1 (x int) with system versioning
  106. partition by system_time;
  107. alter table t1 reorganize partition p0 into
  108. (partition custom_name history);
  109. --replace_result $default_engine DEFAULT_ENGINE
  110. show create table t1;
  111. --echo # merge and split doesn't (MDEV-19938)
  112. create or replace table t1 (x int) with system versioning
  113. partition by system_time limit 10 partitions 3;
  114. --error ER_REORG_HASH_ONLY_ON_SAME_NO
  115. alter table t1 reorganize partition p0, p1 into (partition p00 history);
  116. --error ER_REORG_HASH_ONLY_ON_SAME_NO
  117. alter table t1 reorganize partition p1 into (partition p1 history, partition p2 history);
  118. --echo # Bug tempesta-tech/mariadb#260: incorrect IB partitioning warning
  119. create or replace table t1 (x int)
  120. with system versioning
  121. partition by system_time limit 1;
  122. alter table t1 change x big int;
  123. create or replace table t1 (i int) engine myisam partition by hash(i) partitions 2;
  124. --error ER_PARTITION_WRONG_TYPE
  125. alter table t1 add partition (partition px history);
  126. --echo ## INSERT, UPDATE, DELETE
  127. create or replace table t1 (x int)
  128. with system versioning
  129. partition by system_time;
  130. set @now= now(6);
  131. insert into t1 values (1);
  132. set @str= concat('select x, row_start < @now as A, row_end > @now as B from t1 partition (p0)');
  133. prepare select_p0 from @str;
  134. set @str= concat('select x, row_start > @now as C, row_end = timestamp\'2038-01-19 03:14:07.999999\' as D from t1 partition (pn)');
  135. prepare select_pn from @str;
  136. execute select_p0;
  137. execute select_pn;
  138. set @str= concat('select row_start from t1 partition (pn) into @ts0');
  139. prepare stmt from @str; execute stmt; drop prepare stmt;
  140. --source suite/versioning/wait_system_clock.inc
  141. set @now= now(6);
  142. delete from t1;
  143. execute select_p0;
  144. execute select_pn;
  145. set @str= concat('select row_start from t1 partition (p0) into @ts1');
  146. prepare stmt from @str; execute stmt; drop prepare stmt;
  147. select @ts0 = @ts1;
  148. set @now= now(6);
  149. insert into t1 values (2);
  150. --source suite/versioning/wait_system_clock.inc
  151. execute select_p0;
  152. execute select_pn;
  153. set @str= concat('select row_start from t1 partition (pn) into @ts0');
  154. prepare stmt from @str; execute stmt; drop prepare stmt;
  155. set @now= now(6);
  156. update t1 set x = x + 1;
  157. --source suite/versioning/wait_system_clock.inc
  158. execute select_p0;
  159. execute select_pn;
  160. drop prepare select_p0;
  161. drop prepare select_pn;
  162. set @str= concat('select row_start from t1 partition (p0) where x = 2 into @ts1');
  163. prepare stmt from @str; execute stmt; drop prepare stmt;
  164. set @str= concat('select row_end from t1 partition (p0) where x = 2 into @ts2');
  165. prepare stmt from @str; execute stmt; drop prepare stmt;
  166. set @str= concat('select row_start from t1 partition (pn) into @ts3');
  167. prepare stmt from @str; execute stmt; drop prepare stmt;
  168. select @ts0 = @ts1;
  169. select @ts2 = @ts3;
  170. --echo ## rotation by LIMIT
  171. --error ER_PART_WRONG_VALUE
  172. create or replace table t1 (x int)
  173. with system versioning
  174. partition by system_time limit 0 partitions 3;
  175. create or replace table t1 (x int)
  176. with system versioning
  177. partition by system_time limit 2 partitions 3;
  178. --replace_result $default_engine DEFAULT_ENGINE
  179. show create table t1;
  180. --error ER_DROP_PARTITION_NON_EXISTENT
  181. alter table t1 drop partition non_existent;
  182. insert into t1 values (1), (2), (3), (4), (5), (6);
  183. select * from t1 partition (pn);
  184. delete from t1 where x < 4;
  185. delete from t1;
  186. --echo # You see warning above ^
  187. select * from t1 partition (p0);
  188. select * from t1 partition (p1);
  189. insert into t1 values (7), (8);
  190. --echo ### warn about full partition
  191. delete from t1;
  192. --echo # You see warning above ^
  193. select * from t1 partition (p1) order by x;
  194. --echo ## rotation by INTERVAL
  195. --error ER_PART_WRONG_VALUE
  196. create or replace table t1 (x int)
  197. with system versioning
  198. partition by system_time interval 0 second partitions 3;
  199. --error ER_PARSE_ERROR
  200. create table t1 (i int) with system versioning
  201. partition by system_time interval 6 day limit 98;
  202. --error ER_DATA_OUT_OF_RANGE
  203. create or replace table t1 (pk int) with system versioning
  204. partition by system_time interval 10 year partitions 3;
  205. --echo # INTERVAL and ALTER TABLE
  206. create or replace table t1 (i int) with system versioning
  207. partition by system_time interval 1 hour;
  208. set @ts=(select partition_description from information_schema.partitions
  209. where table_schema='test' and table_name='t1' and partition_name='p0');
  210. alter table t1 add column b int;
  211. select partition_name,partition_ordinal_position,partition_method,timediff(partition_description, @ts) from information_schema.partitions where table_schema='test' and table_name='t1';
  212. alter table t1 add partition (partition p1 history, partition p2 history);
  213. select partition_name,partition_ordinal_position,partition_method,timediff(partition_description, @ts) from information_schema.partitions where table_schema='test' and table_name='t1';
  214. alter table t1 drop partition p0;
  215. select partition_name,partition_ordinal_position,partition_method,timediff(partition_description, @ts) from information_schema.partitions where table_schema='test' and table_name='t1';
  216. --error ER_VERS_DROP_PARTITION_INTERVAL
  217. alter table t1 drop partition p2;
  218. select partition_name,partition_ordinal_position,partition_method,timediff(partition_description, @ts) from information_schema.partitions where table_schema='test' and table_name='t1';
  219. #
  220. # partition rotation (moved from partition_rotation.test)
  221. #
  222. set timestamp=unix_timestamp('2001-02-03 10:20:30');
  223. create or replace table t1 (i int) with system versioning
  224. partition by system_time interval 1 day
  225. subpartition by key (i) subpartitions 2
  226. (partition p1 history, partition pn current);
  227. set timestamp=unix_timestamp('2001-02-03 10:20:40');
  228. insert t1 values (1); delete from t1;
  229. set timestamp=unix_timestamp('2001-02-04 10:20:50');
  230. insert t1 values (2); delete from t1;
  231. select subpartition_name,partition_description,table_rows from information_schema.partitions where table_schema='test' and table_name='t1';
  232. set timestamp=unix_timestamp('2001-02-04 10:20:55');
  233. alter table t1 add partition (partition p0 history, partition p2 history);
  234. set timestamp=unix_timestamp('2001-02-04 10:30:00');
  235. insert t1 values (4),(5);
  236. set timestamp=unix_timestamp('2001-02-04 10:30:10');
  237. update t1 set i=6 where i=5;
  238. select subpartition_name,partition_description,table_rows from information_schema.partitions where table_schema='test' and table_name='t1';
  239. --echo ## pruning check
  240. set @ts=(select partition_description from information_schema.partitions
  241. where table_schema='test' and table_name='t1' and partition_name='p0' limit 1);
  242. --sorted_result
  243. select * from t1;
  244. --replace_column 10 #
  245. explain partitions select * from t1;
  246. --replace_column 10 #
  247. explain partitions select * from t1 for system_time as of '2001-02-04 10:20:30';
  248. set @ts=(select row_end from t1 for system_time all where i=1);
  249. select * from t1 for system_time all where row_end = @ts;
  250. --replace_column 5 # 10 # 11 #
  251. explain partitions select * from t1 for system_time all where row_end = @ts;
  252. --echo #
  253. --echo # MDEV-16023 Unfortunate error message WARN_VERS_PART_FULL
  254. --echo #
  255. set timestamp= unix_timestamp('2020-07-29 10:30:10');
  256. create or replace table t1 (a int) with system versioning
  257. partition by system_time interval 1 second (
  258. partition p0 history,
  259. partition p1 history,
  260. partition pc current
  261. );
  262. set timestamp= unix_timestamp('2020-07-29 10:30:14');
  263. insert into t1 values (1),(2),(3);
  264. show warnings;
  265. --echo # Cleanup
  266. set timestamp= default;
  267. --echo ## INTERVAL ... STARTS
  268. --error ER_PART_WRONG_VALUE
  269. create or replace table t1 (i int) with system versioning
  270. partition by system_time interval 1 day starts 'a';
  271. --error ER_PART_WRONG_VALUE
  272. create or replace table t1 (i int) with system versioning
  273. partition by system_time interval 1 day starts '00:00:00';
  274. --error ER_PART_WRONG_VALUE
  275. create or replace table t1 (i int) with system versioning
  276. partition by system_time interval 1 day starts '2000-00-01 00:00:00';
  277. --error ER_PART_WRONG_VALUE
  278. create or replace table t1 (i int) with system versioning
  279. partition by system_time interval 1 day starts 946684800;
  280. create or replace table t1 (i int) with system versioning
  281. partition by system_time interval 1 day starts '2000-01-01 00:00:00';
  282. --replace_result $default_engine DEFAULT_ENGINE
  283. show create table t1;
  284. --echo # Test STARTS warning
  285. set timestamp= unix_timestamp('2000-01-01 00:00:00');
  286. create or replace table t1 (i int) with system versioning
  287. partition by system_time interval 1 day;
  288. --replace_result $default_engine DEFAULT_ENGINE
  289. show create table t1;
  290. create or replace table t1 (i int) with system versioning
  291. partition by system_time interval 1 day starts '2000-01-01 00:00:01';
  292. --echo # Test default STARTS rounding
  293. set timestamp= unix_timestamp('1999-12-15 13:33:33');
  294. create or replace table t1 (i int) with system versioning
  295. partition by system_time interval 1 second;
  296. --replace_result $default_engine DEFAULT_ENGINE
  297. show create table t1;
  298. create or replace table t1 (i int) with system versioning
  299. partition by system_time interval 1 minute;
  300. --replace_result $default_engine DEFAULT_ENGINE
  301. show create table t1;
  302. create or replace table t1 (i int) with system versioning
  303. partition by system_time interval 1 hour;
  304. --replace_result $default_engine DEFAULT_ENGINE
  305. show create table t1;
  306. create or replace table t1 (i int) with system versioning
  307. partition by system_time interval 1 day;
  308. --replace_result $default_engine DEFAULT_ENGINE
  309. show create table t1;
  310. create or replace table t1 (i int) with system versioning
  311. partition by system_time interval 1 month;
  312. --replace_result $default_engine DEFAULT_ENGINE
  313. show create table t1;
  314. create or replace table t1 (i int) with system versioning
  315. partition by system_time interval 1 year;
  316. --replace_result $default_engine DEFAULT_ENGINE
  317. show create table t1;
  318. --echo # seconds equivalent of 1 day does not round:
  319. create or replace table t1 (i int) with system versioning
  320. partition by system_time interval 86400 second;
  321. --replace_result $default_engine DEFAULT_ENGINE
  322. show create table t1;
  323. --echo # STARTS value is in local time_zone:
  324. set time_zone="+03:00";
  325. create or replace table t1 (i int) with system versioning
  326. partition by system_time interval 1 day starts '2000-01-01 00:00:00';
  327. set timestamp= unix_timestamp('2000-01-01 00:00:00');
  328. create or replace table t2 (i int) with system versioning
  329. partition by system_time interval 1 day;
  330. --replace_result $default_engine DEFAULT_ENGINE
  331. show create table t1;
  332. --replace_result $default_engine DEFAULT_ENGINE
  333. show create table t2;
  334. set time_zone="+00:00";
  335. --replace_result $default_engine DEFAULT_ENGINE
  336. show create table t1;
  337. --replace_result $default_engine DEFAULT_ENGINE
  338. show create table t2;
  339. --echo # Test rotation
  340. set timestamp= unix_timestamp('2001-01-01 00:00:00');
  341. --echo # it's ok to add partitions for past:
  342. create or replace table t1 (i int) with system versioning
  343. partition by system_time interval 1 day starts '2000-01-01 00:00:00'
  344. partitions 3;
  345. --echo # we are warned when we push to present:
  346. insert into t1 values (0);
  347. set timestamp= unix_timestamp('2001-01-01 00:00:01');
  348. update t1 set i= i + 1;
  349. set timestamp= unix_timestamp('2001-01-01 00:00:02');
  350. update t1 set i= i + 1;
  351. select *, row_end from t1 partition (p0);
  352. select *, row_end from t1 partition (p1);
  353. set timestamp= unix_timestamp('2000-01-01 00:00:00');
  354. --echo # now we "overflow" first partition a bit:
  355. create or replace table t1 (i int) with system versioning
  356. partition by system_time interval 1 day starts '2000-01-03 00:00:00'
  357. partitions 3;
  358. insert into t1 values (0);
  359. set timestamp= unix_timestamp('2000-01-01 00:00:01');
  360. update t1 set i= i + 1;
  361. set timestamp= unix_timestamp('2000-01-02 00:00:01');
  362. update t1 set i= i + 1;
  363. set timestamp= unix_timestamp('2000-01-03 00:00:01');
  364. update t1 set i= i + 1;
  365. set timestamp= unix_timestamp('2000-01-04 00:00:01');
  366. update t1 set i= i + 1;
  367. select *, row_end from t1 partition (p0);
  368. select *, row_end from t1 partition (p1);
  369. set timestamp= unix_timestamp('2000-01-01 00:00:00');
  370. --echo # and this is how it usually goes:
  371. create or replace table t1 (i int) with system versioning
  372. partition by system_time interval 1 day
  373. partitions 3;
  374. insert into t1 values (0);
  375. set timestamp= unix_timestamp('2000-01-01 00:00:01');
  376. update t1 set i= i + 1;
  377. set timestamp= unix_timestamp('2000-01-02 00:00:01');
  378. update t1 set i= i + 1;
  379. set timestamp= unix_timestamp('2000-01-03 00:00:01');
  380. update t1 set i= i + 1;
  381. set timestamp= unix_timestamp('2000-01-04 00:00:01');
  382. update t1 set i= i + 1;
  383. alter table t1 add partition (partition p2 history, partition p3 history);
  384. select *, row_end from t1 partition (p0);
  385. select *, row_end from t1 partition (p1);
  386. select *, row_end from t1 partition (p2);
  387. select *, row_end from t1 partition (p3);
  388. drop tables t1, t2;
  389. --echo ## Subpartitions
  390. create or replace table t1 (x int)
  391. with system versioning
  392. partition by system_time limit 2 partitions 3
  393. subpartition by key (x)
  394. subpartitions 2;
  395. insert into t1 (x) values (1), (2), (3), (4), (5);
  396. select * from t1 partition (pnsp0);
  397. select * from t1 partition (pnsp1);
  398. --echo ### warn about full partition
  399. delete from t1 where x < 3;
  400. delete from t1;
  401. --echo # You see warning above ^
  402. delete from t1;
  403. --echo # You see warning above ^ (no matter if nothing was deleted)
  404. select * from t1 partition (p0sp0);
  405. select * from t1 partition (p0sp1);
  406. select * from t1 partition (p1sp0);
  407. select * from t1 partition (p1sp1);
  408. --echo # check implicit sys fields for implicit engine of partitioned table
  409. create or replace table t1 (a bigint)
  410. with system versioning
  411. partition by range (a)
  412. (partition p0 values less than (20) engine innodb,
  413. partition p1 values less than maxvalue engine innodb);
  414. insert into t1 values (1);
  415. select * from t1 partition (p0);
  416. --echo # check for partition engine
  417. create or replace table t1 (
  418. f_int1 integer default 0
  419. ) with system versioning
  420. partition by range(f_int1)
  421. subpartition by hash(f_int1)
  422. ( partition part1 values less than (1000)
  423. (subpartition subpart11 storage engine = 'innodb',
  424. subpartition subpart12 storage engine = 'innodb'));
  425. insert into t1 values (1);
  426. select * from t1 partition (part1);
  427. --echo #
  428. --echo # TRX_ID versioning (moved from partition_innodb.test)
  429. --echo #
  430. --echo # MDEV-15951 system versioning by trx id doesn't work with partitioning
  431. --echo # currently trx_id does not support partitioning by system_time
  432. --error ER_VERS_FIELD_WRONG_TYPE
  433. create or replace table t1(
  434. i int,
  435. row_start bigint unsigned generated always as row start,
  436. row_end bigint unsigned generated always as row end,
  437. period for system_time(row_start, row_end)
  438. ) engine=InnoDB with system versioning partition by system_time (
  439. partition p0 history,
  440. partition pn current
  441. );
  442. create or replace table t1(
  443. i int,
  444. row_start bigint unsigned generated always as row start,
  445. row_end bigint unsigned generated always as row end,
  446. period for system_time(row_start, row_end)
  447. ) engine=InnoDB with system versioning;
  448. --error ER_VERS_FIELD_WRONG_TYPE
  449. alter table t1 partition by system_time (
  450. partition p0 history,
  451. partition pn current
  452. );
  453. drop table t1;
  454. --error ER_VERS_TRX_PART_HISTORIC_ROW_NOT_SUPPORTED
  455. create or replace table t (
  456. a int primary key,
  457. row_start bigint unsigned as row start invisible,
  458. row_end bigint unsigned as row end invisible,
  459. period for system_time(row_start, row_end)
  460. ) engine=innodb with system versioning
  461. partition by key() (
  462. partition p1,
  463. partition p2
  464. );
  465. --error ER_VERS_TRX_PART_HISTORIC_ROW_NOT_SUPPORTED
  466. create or replace table t (
  467. a int primary key,
  468. row_start bigint unsigned as row start invisible,
  469. row_end bigint unsigned as row end invisible,
  470. period for system_time(row_start, row_end)
  471. ) engine=innodb with system versioning
  472. partition by key(a, row_start) (
  473. partition p1,
  474. partition p2
  475. );
  476. --error ER_VERS_TRX_PART_HISTORIC_ROW_NOT_SUPPORTED
  477. create or replace table t (
  478. a int primary key,
  479. row_start bigint unsigned as row start invisible,
  480. row_end bigint unsigned as row end invisible,
  481. period for system_time(row_start, row_end)
  482. ) engine=innodb with system versioning
  483. partition by hash(a + row_end * 2) (
  484. partition p1,
  485. partition p2
  486. );
  487. --error ER_VERS_TRX_PART_HISTORIC_ROW_NOT_SUPPORTED
  488. create or replace table t (
  489. a int primary key,
  490. row_start bigint unsigned as row start invisible,
  491. row_end bigint unsigned as row end invisible,
  492. period for system_time(row_start, row_end)
  493. ) engine=innodb with system versioning
  494. partition by range columns (a, row_start) (
  495. partition p1 values less than (100, 100)
  496. );
  497. --echo #
  498. --echo # Assertion in ALTER on warning from partitioning LIMIT [#446]
  499. --echo #
  500. create or replace table t1 (x int) with system versioning;
  501. insert into t1 values (1), (2);
  502. delete from t1;
  503. alter table t1 partition by system_time limit 1 (
  504. partition p1 history,
  505. partition pn current);
  506. --echo #
  507. --echo # MDEV-14649 Assertion `t->mysql_col_len == 8' failed in row_insert_for_mysql
  508. --echo #
  509. create or replace table t1 (i int) engine=innodb partition by key(i);
  510. alter table t1 add system versioning;
  511. insert into t1 values();
  512. --echo #
  513. --echo # MDEV-14722 Assertion in ha_commit_trans for sub-statement
  514. --echo #
  515. create or replace table t1 (i int) with system versioning
  516. partition by system_time interval 1 day;
  517. create or replace table t2 (f int);
  518. create or replace trigger tr before insert on t2
  519. for each row select table_rows from information_schema.tables
  520. where table_name = 't1' into @a;
  521. insert into t2 values (1);
  522. --echo #
  523. --echo # MDEV-14740 Locking assertion for system_time partitioning
  524. --echo #
  525. create or replace table t1 (i int) with system versioning
  526. partition by system_time interval 1 week;
  527. create or replace table t2 (f int);
  528. create or replace trigger tr before insert on t2
  529. for each row select count(*) from t1 into @a;
  530. insert into t2 values (1);
  531. --echo #
  532. --echo # MDEV-14747 ALTER PARTITION BY SYSTEM_TIME after LOCK TABLES
  533. --echo #
  534. create or replace table t1 (x int) with system versioning;
  535. lock table t1 write;
  536. alter table t1 partition by system_time interval 1 week (
  537. partition p1 history,
  538. partition pn current);
  539. unlock tables;
  540. --echo #
  541. --echo # MDEV-14748 Assertion in ha_myisammrg::attach_children()
  542. --echo #
  543. create or replace table t1 (x int) engine=myisam with system versioning
  544. partition by system_time interval 1 month (partition p1 history, partition pn current);
  545. create or replace table t2 (x int) engine=myisam;
  546. create or replace table t3 (x int) engine=merge union=(t2);
  547. create or replace table t4 (x int) engine=myisam;
  548. create or replace trigger tr after insert on t4 for each row insert into t2
  549. ( select x from t3 ) union ( select x from t1 );
  550. insert into t4 values (1);
  551. --echo #
  552. --echo # MDEV-14821 Assertion failure
  553. --echo #
  554. create or replace table t1 (x int) with system versioning;
  555. insert into t1 values (0), (1);
  556. update t1 set x= x + 1;
  557. alter table t1 partition by system_time limit 1 (
  558. partition p1 history,
  559. partition p2 history,
  560. partition pn current);
  561. delete from t1 where x = 1;
  562. --echo # You see warning above ^
  563. delete from t1 where x = 2;
  564. --echo # You see warning above ^
  565. --echo #
  566. --echo # MDEV-14923 Assertion upon INSERT into locked versioned partitioned table
  567. --echo #
  568. create or replace table t1 (x int) with system versioning
  569. partition by system_time;
  570. lock table t1 write;
  571. --error ER_SAME_NAME_PARTITION
  572. alter table t1 add partition (partition p0 history);
  573. insert into t1 values (1);
  574. unlock tables;
  575. --echo #
  576. --echo # MDEV-15103 Assertion in ha_partition::part_records() for updating VIEW
  577. --echo #
  578. create or replace table t1 (pk int primary key, f int) with system versioning
  579. partition by system_time limit 100;
  580. insert into t1 values (1,10), (2,20);
  581. create or replace view v1 as select * from t1;
  582. update v1 set f= 30;
  583. --echo #
  584. --echo # MDEV-15168 Unexpected ER_VERS_ENGINE_UNSUPPORTED upon dropping versioning on a partitioned table
  585. --echo #
  586. create or replace table t (a int) with system versioning
  587. partition by system_time;
  588. --error ER_DROP_VERSIONING_SYSTEM_TIME_PARTITION
  589. alter table t drop system versioning;
  590. --echo #
  591. --echo # MDEV-15191 Assertion `bit < (map)->n_bits' failed in bitmap_is_set upon INSERT
  592. --echo #
  593. create or replace table t1 (i int) with system versioning;
  594. insert into t1 values (1), (2);
  595. update t1 set i= 3;
  596. alter table t1 partition by system_time interval 1 month (partition p1 history, partition pn current);
  597. lock table t1 write;
  598. alter table t1 add partition (partition p2 history);
  599. insert into t1 values (4);
  600. unlock tables;
  601. --echo #
  602. --echo # MDEV-15036 Assertion `!is_set() || (m_status == DA_OK_BULK && is_bulk_op())' in Diagnostics_area::set_ok_status or unexpected ER_RANGE_NOT_INCREASING_ERROR
  603. --echo #
  604. create or replace table t1 (a int) with system versioning
  605. partition by system_time limit 2 partitions 4;
  606. insert into t1 values (1),(2),(3);
  607. update t1 set a = 4;
  608. delete from t1;
  609. delete from t1 where a is not null;
  610. --echo #
  611. --echo # MDEV-14823 Wrong error message upon selecting from a system_time partition
  612. --echo #
  613. create or replace table t1 (i int) with system versioning partition by system_time limit 10;
  614. --error ER_VERS_QUERY_IN_PARTITION
  615. select * from t1 partition (p0) for system_time all;
  616. --echo # MDEV-18929 2nd execution of SP does not detect ER_VERS_NOT_VERSIONED
  617. create or replace procedure sp()
  618. select * from t1 partition (p0) for system_time all;
  619. --error ER_VERS_QUERY_IN_PARTITION
  620. call sp;
  621. --error ER_VERS_QUERY_IN_PARTITION
  622. call sp;
  623. drop procedure sp;
  624. --echo #
  625. --echo # MDEV-15380 Index for versioned table gets corrupt after partitioning and DELETE
  626. --echo #
  627. create or replace table t1 (pk int primary key)
  628. engine=myisam
  629. with system versioning
  630. partition by key() partitions 3;
  631. set timestamp=1523466002.799571;
  632. insert into t1 values (11),(12);
  633. set timestamp=1523466004.169435;
  634. delete from t1 where pk in (11, 12);
  635. --echo Same test but for Aria storage engine
  636. create or replace table t1 (pk int primary key)
  637. engine=aria
  638. with system versioning
  639. partition by key() partitions 3;
  640. set timestamp=1523466002.799571;
  641. insert into t1 values (11),(12);
  642. set timestamp=1523466004.169435;
  643. delete from t1 where pk in (11, 12);
  644. --echo #
  645. --echo # MDEV-18136 Server crashes in Item_func_dyncol_create::prepare_arguments
  646. --echo #
  647. create or replace table t1 (pk int) with system versioning
  648. partition by system_time interval 7 second;
  649. alter table t1
  650. partition by system_time interval column_get(column_create(7,7), 7 as int) second (
  651. partition ver_p1 history,
  652. partition ver_pn current);
  653. --replace_result $default_engine DEFAULT_ENGINE
  654. show create table t1;
  655. set timestamp= default;
  656. --echo #
  657. --echo # MDEV-18794 Assertion `!m_innodb' failed in ha_partition::cmp_ref upon SELECT from partitioned table
  658. --echo #
  659. create or replace table t1 (pk int auto_increment, i int, c char(1), primary key (pk), key(i))
  660. engine=innodb with system versioning partition by key() partitions 2;
  661. insert into t1 (i, c) values (1, 'a'), (2, 'b'), (null, 'c'), (null, 'b');
  662. alter table t1 drop system versioning;
  663. replace into t1 select * from t1;
  664. select * from t1 where i > 0 or pk = 1000 limit 1;
  665. drop table t1;
  666. --echo #
  667. --echo # MDEV-19175 Server crashes in ha_partition::vers_can_native upon INSERT DELAYED into versioned partitioned table
  668. --echo #
  669. create or replace table t1 (f int) with system versioning partition by hash(f);
  670. # delayed works differently in embedded server
  671. --error 0,ER_DELAYED_NOT_SUPPORTED
  672. insert delayed into t1 values (1);
  673. --echo #
  674. --echo # MDEV-20068 History partition rotation is not done under LOCK TABLES
  675. --echo #
  676. create or replace table t1 (x int) with system versioning partition by system_time limit 1
  677. (partition p1 history, partition pn current);
  678. lock tables t1 write;
  679. insert into t1 values (0), (1), (2), (3);
  680. delete from t1 where x < 3;
  681. --echo # You see warning above ^
  682. delete from t1;
  683. --echo # You see warning above ^
  684. unlock tables;
  685. --echo #
  686. --echo # MDEV-20336 Assertion bitmap_is_set(read_partitions) upon SELECT FOR UPDATE from versioned table
  687. --echo #
  688. create or replace table t1 (pk int primary key) with system versioning partition by system_time limit 100 (partition p1 history, partition pn current);
  689. execute immediate 'select * from t1 for update';
  690. --echo #
  691. --echo # MDEV-19903 Setup default partitions for system versioning
  692. --echo #
  693. create or replace table t1 (x int) with system versioning partition by system_time;
  694. --replace_result $default_engine DEFAULT_ENGINE
  695. show create table t1;
  696. --echo # 2 partitions are created: p0 and pn
  697. select PARTITION_NAME, PARTITION_METHOD, PARTITION_DESCRIPTION from information_schema.partitions where table_name = 't1' order by PARTITION_NAME;
  698. create or replace table t1 (x int) with system versioning partition by system_time limit 10 partitions 4;
  699. --replace_result $default_engine DEFAULT_ENGINE
  700. show create table t1;
  701. --echo # 4 partitions are created: p0, p1, p2 and pn
  702. select PARTITION_NAME, PARTITION_METHOD, PARTITION_DESCRIPTION from information_schema.partitions where table_name = 't1' order by PARTITION_NAME;
  703. --echo # Test cleanup
  704. drop view v1;
  705. drop tables t, t1, t2, t3, t4;
  706. --echo #
  707. --echo # MDEV-18957 UPDATE with LIMIT clause is wrong for versioned partitioned tables
  708. --echo #
  709. create or replace table t1 (
  710. x int,
  711. a varchar(255)
  712. ) with system versioning partition by system_time (partition p1 history, partition pn current);
  713. insert into t1 (x) values (1), (2), (3), (4);
  714. update t1 set a= 'foo' limit 3;
  715. update t1 set a= 'bar' limit 4;
  716. select * from t1;
  717. drop table t1;
  718. --echo #
  719. --echo # MDEV-21011 Table corruption reported for versioned partitioned table after DELETE: "Found a misplaced row"
  720. --echo #
  721. create table t1 (a int) with system versioning
  722. partition by system_time limit 3
  723. (partition p1 history, partition p2 history, partition pn current);
  724. insert into t1 values (1),(2),(3),(4);
  725. delete from t1;
  726. delete from t1;
  727. check table t1;
  728. # cleanup
  729. drop table t1;
  730. --echo #
  731. --echo # MDEV-21233 Assertion `m_extra_cache' failed in ha_partition::late_extra_cache
  732. --echo #
  733. create table t1 (id int, a varchar(8)) with system versioning partition by key (id) partitions 2;
  734. insert into t1 values (1,'foo'),(2,'bar');
  735. create table t2 (b int);
  736. insert into t2 values (1),(2);
  737. update t1, t2 set a = 1;
  738. # cleanup
  739. drop table t1, t2;
  740. --echo #
  741. --echo # MDEV-20515 multi-update tries to position updated table by null reference
  742. --echo #
  743. create or replace table t1 (a int);
  744. insert into t1 values (0), (1);
  745. create or replace table t2 (b int) with system versioning
  746. partition by system_time
  747. (partition p1 history, partition pn current);
  748. insert into t2 values (0), (2);
  749. update t1 left join t2 on a > b set b= 2 order by b;
  750. # cleanup
  751. drop table t1, t2;
  752. --echo #
  753. --echo # MDEV-17091 Assertion `old_part_id == m_last_part' failed in
  754. --echo # ha_partition::update_row or `part_id == m_last_part' in
  755. --echo # ha_partition::delete_row upon UPDATE/DELETE after dropping versioning
  756. --echo #
  757. create or replace table t1 (pk int primary key, f int) engine=innodb
  758. with system versioning
  759. partition by key() partitions 2;
  760. insert into t1 values (1,10),(2,20);
  761. --echo # expected to hit same partition
  762. select * from t1 partition (p0);
  763. alter table t1 drop system versioning;
  764. --echo # 1 and 2 are expected to be in different partitions
  765. select * from t1 partition(p0);
  766. select * from t1 partition(p1);
  767. update t1 set f=pk;
  768. delete from t1;
  769. drop table t1;
  770. --echo #
  771. --echo # MDEV-22413 Server hangs upon UPDATE/DELETE on a view reading from versioned partitioned table
  772. --echo #
  773. create or replace table t1 (f char(6)) engine innodb with system versioning;
  774. insert into t1 values (null);
  775. update t1 set f= 'foo';
  776. update t1 set f= 'bar';
  777. --echo # You see warning above ^
  778. create or replace view v1 as select * from t1 for system_time all;
  779. --error ER_TABLE_NOT_LOCKED_FOR_WRITE
  780. update v1 set f = '';
  781. create or replace table t1 (f char(6)) engine innodb with system versioning
  782. partition by system_time limit 1
  783. (partition p1 history, partition p2 history, partition pn current);
  784. insert into t1 values (null);
  785. update t1 set f= 'foo';
  786. update t1 set f= 'bar';
  787. create or replace view v1 as select * from t1 for system_time all;
  788. --error ER_TABLE_NOT_LOCKED_FOR_WRITE
  789. update v1 set f= '';
  790. --error ER_TABLE_NOT_LOCKED_FOR_WRITE
  791. delete from v1;
  792. # cleanup
  793. drop view v1;
  794. drop table t1;
  795. --echo #
  796. --echo # MDEV-22112 Assertion `tab_part_info->part_type == RANGE_PARTITION || tab_part_info->part_type == LIST_PARTITION' failed in prep_alter_part_table
  797. --echo #
  798. create table t1 (a int) with system versioning partition by system_time;
  799. drop table t1;
  800. create table t1 (a int) with system versioning partition by system_time
  801. (partition p1 history, partition pn current);
  802. --error ER_PARTITION_WRONG_TYPE
  803. alter table t1 add partition (partition p2);
  804. --echo # MDEV-17891 Assertion failures in select_insert::abort_result_set and
  805. --echo # mysql_load upon attempt to replace into a full table
  806. --let $max_heap_table_size_orig= `select @@max_heap_table_size;`
  807. set @@max_heap_table_size= 1024*1024;
  808. create or replace table t1 (
  809. pk integer auto_increment,
  810. primary key (pk),
  811. f varchar(45000)
  812. ) with system versioning engine=memory
  813. partition by system_time interval 1 year (partition p1 history,
  814. partition pn current);
  815. --echo # fill the table until full
  816. insert into t1 () values (),(),(),(),(),(),(),(),(),(),(),(),(),(),(),();
  817. --error ER_RECORD_FILE_FULL
  818. insert into t1 (f) select f from t1;
  819. --echo # leave space for exactly one record in current partition
  820. delete from t1 where pk = 1;
  821. --echo # copy all data into history partition
  822. replace into t1 select * from t1;
  823. --error ER_RECORD_FILE_FULL
  824. replace into t1 select * from t1;
  825. create or replace table t1 (
  826. pk integer auto_increment,
  827. primary key (pk),
  828. f varchar(45000)
  829. ) with system versioning engine=memory
  830. partition by system_time interval 1 year (partition p1 history,
  831. partition pn current);
  832. insert into t1 () values (),(),(),(),(),(),(),(),(),(),(),(),(),(),(),();
  833. --disable_cursor_protocol
  834. --disable_ps2_protocol
  835. select * into outfile 'load.data' from t1;
  836. --enable_ps2_protocol
  837. load data infile 'load.data' replace into table t1;
  838. --error ER_RECORD_FILE_FULL
  839. load data infile 'load.data' replace into table t1;
  840. --error ER_RECORD_FILE_FULL
  841. load data infile 'load.data' replace into table t1;
  842. --enable_cursor_protocol
  843. # Cleanup
  844. --let $datadir= `select @@datadir`
  845. --remove_file $datadir/test/load.data
  846. eval set @@max_heap_table_size= $max_heap_table_size_orig;
  847. drop table t1;
  848. --echo #
  849. --echo # MDEV-22178 Assertion `info->alias.str' failed in partition_info::check_partition_info instead of ER_VERS_WRONG_PARTS
  850. --echo #
  851. create or replace table t1 (a int) with system versioning;
  852. --error ER_VERS_WRONG_PARTS
  853. alter table t1 partition by system_time (partition pn current);
  854. # Cleanup
  855. drop table t1;
  856. --echo #
  857. --echo # MDEV-22247 History partition overflow leads to wrong SELECT result
  858. --echo #
  859. set timestamp= unix_timestamp('2000-01-01 00:00:00');
  860. create or replace table t1 (x int) with system versioning
  861. partition by system_time interval 1 hour
  862. (partition p0 history, partition p1 history, partition pn current);
  863. insert into t1 values (0);
  864. update t1 set x= x + 1;
  865. set timestamp= unix_timestamp('2000-01-01 02:00:01');
  866. update t1 set x= x + 1;
  867. select *, row_start, row_end from t1 for system_time as of '2000-01-01 02:00:00';
  868. --replace_column 10 #
  869. explain partitions select * from t1 for system_time as of '2000-01-01 02:00:00';
  870. --replace_column 5 # 10 # 11 #
  871. explain partitions select * from t1;
  872. drop table t1;
  873. --echo #
  874. --echo # MDEV-27244 Table corruption upon adding serial data type
  875. --echo #
  876. create table t1 (f int, key(f)) with system versioning
  877. partition by system_time limit 10 (partition p0 history, partition pn current);
  878. alter table t1 add x serial;
  879. alter table t1 add partition (partition p1 history);
  880. alter table t1 add partition (partition p2 history);
  881. drop table t1;
  882. --echo #
  883. --echo # MDEV-27217 DELETE partition selection doesn't work for history partitions
  884. --echo #
  885. create table t1 (f char) with system versioning
  886. partition by system_time limit 10 (
  887. partition p0 history,
  888. partition p1 history,
  889. partition p2 history,
  890. partition pn current);
  891. --error ER_VERS_NOT_ALLOWED
  892. delete from t1 partition (p1);
  893. --error ER_VERS_NOT_ALLOWED
  894. delete from t1 partition (p0, pn);
  895. --error ER_VERS_NOT_ALLOWED
  896. delete from t1 partition (p0, p1);
  897. --error ER_VERS_NOT_ALLOWED
  898. delete from t1 partition (p0, p1, pn);
  899. drop table t1;
  900. set timestamp=unix_timestamp('2000-01-01 00:00:00');
  901. create or replace table t1 (i int) with system versioning
  902. partition by system_time interval 1 day (
  903. partition p0 history,
  904. partition p1 history,
  905. partition pn current);
  906. set timestamp=unix_timestamp('2000-01-02 00:00:00');
  907. insert t1 values (1);
  908. --error ER_VERS_NOT_ALLOWED
  909. delete from t1 partition (p0, pn);
  910. --error ER_VERS_NOT_ALLOWED
  911. delete from t1 partition (p0, p1, pn);
  912. drop table t1;
  913. set timestamp= default;
  914. --echo #
  915. --echo # MDEV-25546 LIMIT partitioning does not respect ROLLBACK
  916. --echo #
  917. create or replace table t1 (pk int primary key)
  918. with system versioning engine innodb
  919. partition by system_time limit 100 (
  920. partition p0 history,
  921. partition p1 history,
  922. partition pn current);
  923. insert into t1 select seq from seq_1_to_90;
  924. start transaction;
  925. # Puts 80 rows into p0
  926. replace into t1 select seq from seq_1_to_80;
  927. # Puts another 70 rows into p0
  928. replace into t1 select seq from seq_1_to_70;
  929. # Puts 60 rows into p1
  930. replace into t1 select seq from seq_1_to_60;
  931. select partition_name, table_rows
  932. from information_schema.partitions
  933. where table_name = 't1';
  934. rollback;
  935. select partition_name, table_rows
  936. from information_schema.partitions
  937. where table_name = 't1';
  938. # Should put 10 rows into the empty partition p0
  939. replace into t1 select seq from seq_1_to_10;
  940. select partition_name, table_rows
  941. from information_schema.partitions
  942. where table_name = 't1';
  943. # Cleanup
  944. drop table t1;
  945. --echo #
  946. --echo # MDEV-28271 Assertion on TRUNCATE PARTITION for PARTITION BY SYSTEM_TIME
  947. --echo #
  948. create table t1 (x int) with system versioning
  949. partition by system_time limit 1 (
  950. partition p0 history,
  951. partition p1 history,
  952. partition p2 history, # p2 just disables warning about p1 partition full
  953. partition pn current);
  954. insert into t1 values (0);
  955. update t1 set x= x + 1;
  956. update t1 set x= x + 1;
  957. select * from t1 partition (p0);
  958. select * from t1 partition (p1);
  959. select * from t1 partition (pn);
  960. delete from t1;
  961. delete history from t1;
  962. select * from t1 partition (p0);
  963. select * from t1 partition (p1);
  964. select * from t1 partition (pn);
  965. insert into t1 values (0);
  966. update t1 set x= x + 1;
  967. update t1 set x= x + 1;
  968. --echo # TRUNCATE PARTITION ALL does the same
  969. alter table t1 truncate partition all;
  970. select * from t1 partition (p0);
  971. select * from t1 partition (p1);
  972. select * from t1 partition (pn);
  973. insert into t1 values (0);
  974. update t1 set x= x + 1;
  975. update t1 set x= x + 1;
  976. --echo # TRUNCATE PARTITION deletes data from HISTORY partition
  977. alter table t1 truncate partition p1;
  978. select * from t1 partition (p0);
  979. select * from t1 partition (p1);
  980. select * from t1 partition (pn);
  981. --echo # or from CURRENT partition
  982. alter table t1 truncate partition pn;
  983. select * from t1 partition (p0);
  984. select * from t1 partition (p1);
  985. select * from t1 partition (pn);
  986. drop table t1;
  987. --echo #
  988. --echo # MDEV-20077 Warning on full history partition is delayed until next DML statement
  989. --echo #
  990. --echo # DELETE
  991. create table t1 (x int) with system versioning
  992. partition by system_time limit 100 (
  993. partition p0 history,
  994. partition p1 history,
  995. partition pn current);
  996. insert into t1 select seq from seq_0_to_200;
  997. --echo # p0 is filled with 100 records (no warnings):
  998. delete from t1 where x <= 99;
  999. --echo # p1 is filled with 1 + 100 records (warning is printed):
  1000. delete from t1 where x <= 100;
  1001. delete from t1;
  1002. --echo # You see warning above ^
  1003. select count(*) from t1 partition (p0);
  1004. select count(*) from t1 partition (p1);
  1005. drop table t1;
  1006. --echo # DELETE under LOCK TABLES
  1007. create table t1 (x int) with system versioning
  1008. partition by system_time limit 100 (
  1009. partition p0 history,
  1010. partition p1 history,
  1011. partition pn current);
  1012. insert into t1 select seq from seq_0_to_200;
  1013. lock tables t1 write;
  1014. --echo # (LOCK TABLES) p0 is filled with 100 records (no warnings):
  1015. delete from t1 where x <= 99;
  1016. --echo # (LOCK TABLES) p1 is filled with 1 + 100 records (warning is printed):
  1017. delete from t1 where x <= 100;
  1018. delete from t1;
  1019. --echo # You see warning above ^
  1020. unlock tables;
  1021. select count(*) from t1 partition (p0);
  1022. select count(*) from t1 partition (p1);
  1023. drop table t1;
  1024. --echo # DELETE multitable
  1025. create table t1 (x int) with system versioning
  1026. partition by system_time limit 100 (
  1027. partition p0 history,
  1028. partition p1 history,
  1029. partition pn current);
  1030. create table t2 (y int);
  1031. insert into t1 select seq from seq_0_to_200;
  1032. insert into t2 select seq from seq_0_to_3;
  1033. delete t1, t2 from t1 join t2 where x < 50 and y = 0;
  1034. delete t1, t2 from t1 join t2 where x < 100 and y = 1;
  1035. delete t1, t2 from t1 join t2 where x < 150 and y = 2;
  1036. delete t1, t2 from t1 join t2;
  1037. --echo # You see warning above ^
  1038. select count(*) from t1 partition (p0);
  1039. select count(*) from t1 partition (p1);
  1040. drop table t1;
  1041. --echo # UDPATE
  1042. create table t1 (x int) with system versioning
  1043. partition by system_time limit 100 (
  1044. partition p0 history,
  1045. partition p1 history,
  1046. partition pn current);
  1047. insert into t1 select seq from seq_0_to_49;
  1048. update t1 set x= x + 1;
  1049. update t1 set x= x + 1;
  1050. update t1 set x= x + 1;
  1051. update t1 set x= x + 1;
  1052. --echo # You see warning above ^
  1053. select count(*) from t1 partition (p0);
  1054. select count(*) from t1 partition (p1);
  1055. drop tables t1, t2;
  1056. --echo # UPDATE multitable
  1057. create table t1 (x int) with system versioning
  1058. partition by system_time limit 100 (
  1059. partition p0 history,
  1060. partition p1 history,
  1061. partition pn current);
  1062. create table t2 (y int);
  1063. insert into t1 select seq from seq_0_to_49;
  1064. insert into t2 values (5);
  1065. update t1, t2 set x= x + 1;
  1066. update t1, t2 set x= x + 1;
  1067. update t1, t2 set x= x + 1;
  1068. update t1, t2 set x= x + 1;
  1069. --echo # You see warning above ^
  1070. select count(*) from t1 partition (p0);
  1071. select count(*) from t1 partition (p1);
  1072. drop tables t1, t2;
  1073. --echo # INSERT .. ON DUPLICATE KEY UPDATE (ODKU)
  1074. create table t1 (x int primary key) with system versioning
  1075. partition by system_time limit 100 (
  1076. partition p0 history,
  1077. partition p1 history,
  1078. partition pn current);
  1079. insert into t1 select seq from seq_0_to_100;
  1080. delete from t1 where x <= 99;
  1081. insert into t1 values (100) on duplicate key update x= 400;
  1082. select count(*) from t1 partition (p0);
  1083. select count(*) from t1 partition (p1);
  1084. drop table t1;
  1085. --echo # INSERT .. SELECT .. ON DUPLICATE KEY UPDATE (ODKU)
  1086. create table t1 (x int primary key) with system versioning
  1087. partition by system_time limit 100 (
  1088. partition p0 history,
  1089. partition p1 history,
  1090. partition pn current);
  1091. create table t2 (y int);
  1092. insert into t2 values (100);
  1093. insert into t1 select seq from seq_0_to_100;
  1094. delete from t1 where x <= 99;
  1095. insert into t1 select * from t2 on duplicate key update x= 500;
  1096. select count(*) from t1 partition (p0);
  1097. select count(*) from t1 partition (p1);
  1098. drop tables t1, t2;
  1099. --echo # REPLACE
  1100. create table t1 (x int primary key) with system versioning
  1101. partition by system_time limit 100 (
  1102. partition p0 history,
  1103. partition p1 history,
  1104. partition pn current);
  1105. insert into t1 select seq from seq_0_to_100;
  1106. delete from t1 where x < 99;
  1107. replace t1 values (100);
  1108. replace t1 values (100);
  1109. select count(*) from t1 partition (p0);
  1110. select count(*) from t1 partition (p1);
  1111. drop table t1;
  1112. --echo # LOAD DATA .. REPLACE
  1113. create table t1 (x int primary key) with system versioning
  1114. partition by system_time limit 100 (
  1115. partition p0 history,
  1116. partition p1 history,
  1117. partition pn current);
  1118. insert into t1 select seq from seq_0_to_49;
  1119. --disable_cursor_protocol
  1120. --disable_ps2_protocol
  1121. select x into outfile 'MDEV-20077.data' from t1;
  1122. --enable_ps2_protocol
  1123. --enable_cursor_protocol
  1124. load data infile 'MDEV-20077.data' replace into table t1 (x);
  1125. load data infile 'MDEV-20077.data' replace into table t1 (x);
  1126. load data infile 'MDEV-20077.data' replace into table t1 (x);
  1127. load data infile 'MDEV-20077.data' replace into table t1 (x);
  1128. --echo # You see warning above ^
  1129. select count(*) from t1 partition (p0);
  1130. select count(*) from t1 partition (p1);
  1131. drop table t1;
  1132. --remove_file $datadir/test/MDEV-20077.data
  1133. --echo # REPLACE .. SELECT
  1134. create table t1 (x int primary key) with system versioning
  1135. partition by system_time limit 100 (
  1136. partition p0 history,
  1137. partition p1 history,
  1138. partition pn current);
  1139. insert into t1 select seq from seq_0_to_49;
  1140. replace t1 select * from t1;
  1141. replace t1 select * from t1;
  1142. replace t1 select * from t1;
  1143. replace t1 select * from t1;
  1144. --echo # You see warning above ^
  1145. select count(*) from t1 partition (p0);
  1146. select count(*) from t1 partition (p1);
  1147. drop table t1;
  1148. --echo #
  1149. --echo # MDEV-28552 Assertion `inited==RND' failed in handler::ha_rnd_end
  1150. --echo #
  1151. create table tcount (c int unsigned);
  1152. insert into tcount values (0);
  1153. create table t (f int) with system versioning
  1154. partition by system_time limit 1000
  1155. (partition p1 history, partition pn current);
  1156. insert into t values (1),(2);
  1157. create trigger tr before insert on t for each row update tcount set c = c + 1;
  1158. insert into t select * from t;
  1159. # cleanup
  1160. drop table tcount, t;
  1161. --echo #
  1162. --echo # MDEV-19569 Assertion `table_list->table' failed in find_field_in_table_ref and Assertion `table_ref->table || table_ref->view' in Field_iterator_table_ref::set_field_iterator
  1163. --echo #
  1164. set timestamp=unix_timestamp('2000-01-01 00:00:00');
  1165. create table t1 (i int);
  1166. create table t2 (i int);
  1167. --error ER_SUBQUERIES_NOT_SUPPORTED
  1168. alter table t1 partition by system_time
  1169. interval (select i from t2) day (partition p1 history, partition pn current);
  1170. drop table t1;
  1171. --error ER_SUBQUERIES_NOT_SUPPORTED
  1172. create table t1 (id int) with system versioning
  1173. partition by system_time
  1174. interval (select i from t2) day (partition p1 history, partition pn current);
  1175. --error ER_PART_WRONG_VALUE
  1176. create table t1 (id int) with system versioning
  1177. partition by system_time
  1178. interval "hello" day (partition p1 history, partition pn current);
  1179. create table t1 (id int) with system versioning
  1180. partition by system_time
  1181. interval 3.893 day (partition p1 history, partition pn current);
  1182. drop table t1, t2;
  1183. create table t1 (id int) with system versioning
  1184. partition by system_time interval "3-11" year_month (partition p1 history, partition pn current);
  1185. --replace_result $default_engine DEFAULT_ENGINE
  1186. show create table t1;
  1187. drop table t1;
  1188. create table t1 (id int) with system versioning
  1189. partition by system_time interval "3 11" day_hour (partition p1 history, partition pn current);
  1190. --replace_result $default_engine DEFAULT_ENGINE
  1191. show create table t1;
  1192. drop table t1;
  1193. create table t1 (id int) with system versioning
  1194. partition by system_time interval "3 11:12" day_minute (partition p1 history, partition pn current);
  1195. --replace_result $default_engine DEFAULT_ENGINE
  1196. show create table t1;
  1197. drop table t1;
  1198. create table t1 (id int) with system versioning
  1199. partition by system_time interval "3 11:12:13" day_second (partition p1 history, partition pn current);
  1200. --replace_result $default_engine DEFAULT_ENGINE
  1201. show create table t1;
  1202. drop table t1;
  1203. create table t1 (id int) with system versioning
  1204. partition by system_time interval "11:12" hour_minute (partition p1 history, partition pn current);
  1205. --replace_result $default_engine DEFAULT_ENGINE
  1206. show create table t1;
  1207. drop table t1;
  1208. create table t1 (id int) with system versioning
  1209. partition by system_time interval "11:12:13" hour_second (partition p1 history, partition pn current);
  1210. --replace_result $default_engine DEFAULT_ENGINE
  1211. show create table t1;
  1212. drop table t1;
  1213. create table t1 (id int) with system versioning
  1214. partition by system_time interval "12:13" minute_second (partition p1 history, partition pn current);
  1215. --replace_result $default_engine DEFAULT_ENGINE
  1216. show create table t1;
  1217. drop table t1;
  1218. --error ER_PART_WRONG_VALUE
  1219. create table t1 (id int) with system versioning
  1220. partition by system_time interval "12:13.123" minute_microsecond (partition p1 history, partition pn current);
  1221. --echo #
  1222. --echo # End of 10.3 tests
  1223. --echo #
  1224. --echo #
  1225. --echo # MDEV-22283 Server crashes in key_copy or unexpected error 156: The table already existed in the storage engine
  1226. --echo #
  1227. create table t1 (a int primary key) engine=aria page_checksum=0
  1228. with system versioning
  1229. partition by system_time (partition p1 history, partition pn current);
  1230. alter table t1 add partition (partition p2 history);
  1231. show table status;
  1232. drop table t1;
  1233. create table t1 (b int) engine=aria row_format=dynamic with system versioning
  1234. partition by system_time (partition p1 history, partition pn current);
  1235. insert into t1 values (1);
  1236. replace into t1 values (1);
  1237. # cleanup
  1238. drop table t1;
  1239. --echo #
  1240. --echo # MDEV-18794 Assertion `!m_innodb' failed in ha_partition::cmp_ref upon SELECT from partitioned table
  1241. --echo #
  1242. create or replace table t1 (pk int auto_increment, i int, c char(1), primary key (pk), key(i))
  1243. engine=innodb with system versioning partition by key() partitions 2;
  1244. insert into t1 (i, c) values (1, 'a'), (2, 'b'), (null, 'c'), (null, 'b');
  1245. alter table t1 drop system versioning;
  1246. replace into t1 select * from t1;
  1247. select * from t1 where i > 0 or pk = 1000 limit 1;
  1248. drop table t1;
  1249. --echo #
  1250. --echo # End of 10.4 tests
  1251. --echo #
  1252. --echo #
  1253. --echo # MDEV-22153 ALTER add default history partitions makes table inaccessible
  1254. --echo #
  1255. create or replace table t1 (x int) with system versioning partition by system_time;
  1256. alter table t1 add partition partitions 1;
  1257. --replace_result $default_engine DEFAULT_ENGINE
  1258. show create table t1;
  1259. alter table t1 add partition partitions 2;
  1260. --replace_result $default_engine DEFAULT_ENGINE
  1261. show create table t1;
  1262. alter table t1 add partition partitions 3;
  1263. --replace_result $default_engine DEFAULT_ENGINE
  1264. show create table t1;
  1265. drop tables t1;
  1266. --echo #
  1267. --echo # MDEV-22207 Drop default history partitions renders table inaccessible
  1268. --echo #
  1269. create or replace table t1 (i int) with system versioning
  1270. partition by system_time limit 1 partitions 5;
  1271. alter table t1 drop partition p0, p2;
  1272. --replace_result $default_engine DEFAULT_ENGINE
  1273. show create table t1;
  1274. alter table t1 add partition partitions 1;
  1275. --replace_result $default_engine DEFAULT_ENGINE
  1276. show create table t1;
  1277. drop tables t1;
  1278. --echo #
  1279. --echo # MDEV-22155 ALTER add default history partitions name clash on non-default partitions
  1280. --echo #
  1281. create or replace table t1 (x int) with system versioning
  1282. partition by system_time limit 1
  1283. (partition p2 history, partition p8 history, partition pn current);
  1284. alter table t1 add partition partitions 1;
  1285. alter table t1 add partition partitions 2;
  1286. --replace_result $default_engine DEFAULT_ENGINE
  1287. show create table t1;
  1288. alter table t1 add partition partitions 8;
  1289. --replace_result $default_engine DEFAULT_ENGINE
  1290. show create table t1;
  1291. drop tables t1;
  1292. --echo #
  1293. --echo # MDEV-29727 ALTER and CREATE with default partitioning
  1294. --echo # differently react to SQL_MODE => unusable SHOW CREATE
  1295. --echo #
  1296. create table t (a int) with system versioning;
  1297. --error WARN_VERS_PARAMETERS
  1298. alter table t partition by system_time partitions 3;
  1299. drop table t;
  1300. --error WARN_VERS_PARAMETERS
  1301. create table t (a int) with system versioning partition by system_time partitions 3;
  1302. --echo #
  1303. --echo # MDEV-36115 InnoDB: assertion: node->pcur->rel_pos == BTR_PCUR_ON
  1304. --echo # in row_update_for_mysql
  1305. --echo #
  1306. create table t (a int key) engine=innodb
  1307. with system versioning
  1308. partition by key() partitions 3;
  1309. start transaction;
  1310. insert into t values (1),(2),(3),(4),(5),(6),(7),(8);
  1311. set timestamp=+1;
  1312. delete from t;
  1313. insert into t values (1),(2);
  1314. DELETE from t;
  1315. drop table t;
  1316. --echo #
  1317. --echo # End of 10.5 tests
  1318. --echo #
  1319. set global innodb_stats_persistent= @save_persistent;
  1320. --source suite/versioning/common_finish.inc