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.

338 lines
11 KiB

  1. drop table if exists t1;
  2. create table t1 (a int, b int)
  3. partition by key (a,a);
  4. ERROR HY000: Duplicate partition field name a
  5. create table t1 (a int, b int)
  6. partition by list column_list(a,a)
  7. ( partition p values in ((1,1)));
  8. ERROR HY000: Duplicate partition field name a
  9. create table t1 (a int signed)
  10. partition by list (a)
  11. ( partition p0 values in (1, 3, 5, 7, 9, NULL),
  12. partition p1 values in (2, 4, 6, 8, 0));
  13. insert into t1 values (NULL),(0),(1),(2),(2),(4),(4),(4),(8),(8);
  14. select * from t1 where NULL <= a;
  15. a
  16. select * from t1 where a is null;
  17. a
  18. NULL
  19. explain partitions select * from t1 where a is null;
  20. id select_type table partitions type possible_keys key key_len ref rows Extra
  21. 1 SIMPLE t1 p0 ALL NULL NULL NULL NULL 10 Using where
  22. select * from t1 where a <= 1;
  23. a
  24. 1
  25. 0
  26. drop table t1;
  27. create table t1 (a int signed)
  28. partition by list column_list(a)
  29. ( partition p0 values in (1, 3, 5, 7, 9, NULL),
  30. partition p1 values in (2, 4, 6, 8, 0));
  31. insert into t1 values (NULL),(0),(1),(2),(2),(4),(4),(4),(8),(8);
  32. select * from t1 where a <= NULL;
  33. a
  34. select * from t1 where a is null;
  35. a
  36. NULL
  37. explain partitions select * from t1 where a is null;
  38. id select_type table partitions type possible_keys key key_len ref rows Extra
  39. 1 SIMPLE t1 p0 ALL NULL NULL NULL NULL 2 Using where
  40. select * from t1 where a <= 1;
  41. a
  42. 1
  43. 0
  44. drop table t1;
  45. create table t1 (a int, b int)
  46. partition by list column_list(a,b)
  47. ( partition p0 values in ((1, NULL), (2, NULL), (NULL, NULL)),
  48. partition p1 values in ((1,1), (2,2)),
  49. partition p2 values in ((3, NULL), (NULL, 1)));
  50. insert into t1 values (3, NULL);
  51. insert into t1 values (NULL, 1);
  52. insert into t1 values (NULL, NULL);
  53. insert into t1 values (1, NULL);
  54. insert into t1 values (2, NULL);
  55. insert into t1 values (1,1);
  56. insert into t1 values (2,2);
  57. select * from t1 where a = 1;
  58. a b
  59. 1 NULL
  60. 1 1
  61. select * from t1 where a = 2;
  62. a b
  63. 2 NULL
  64. 2 2
  65. select * from t1 where a > 8;
  66. a b
  67. select * from t1 where a not between 8 and 8;
  68. a b
  69. 2 NULL
  70. 2 2
  71. 3 NULL
  72. 1 NULL
  73. 1 1
  74. show create table t1;
  75. Table Create Table
  76. t1 CREATE TABLE `t1` (
  77. `a` int(11) DEFAULT NULL,
  78. `b` int(11) DEFAULT NULL
  79. ) ENGINE=MyISAM DEFAULT CHARSET=latin1
  80. /*!50100 PARTITION BY LIST COLUMN_LIST(a,b)
  81. (PARTITION p0 VALUES IN ((1,NULL),(2,NULL),(NULL,NULL)) ENGINE = MyISAM,
  82. PARTITION p1 VALUES IN ((1,1),(2,2)) ENGINE = MyISAM,
  83. PARTITION p2 VALUES IN ((3,NULL),(NULL,1)) ENGINE = MyISAM) */
  84. drop table t1;
  85. create table t1 (a int)
  86. partition by list (a)
  87. ( partition p0 values in (1),
  88. partition p1 values in (1));
  89. ERROR HY000: Multiple definition of same constant in list partitioning
  90. create table t1 (a int)
  91. partition by list (a)
  92. ( partition p0 values in (2, 1),
  93. partition p1 values in (4, NULL, 3));
  94. insert into t1 values (1);
  95. insert into t1 values (2);
  96. insert into t1 values (3);
  97. insert into t1 values (4);
  98. insert into t1 values (NULL);
  99. insert into t1 values (5);
  100. ERROR HY000: Table has no partition for value 5
  101. drop table t1;
  102. create table t1 (a int)
  103. partition by list column_list(a)
  104. ( partition p0 values in (2, 1),
  105. partition p1 values in ((4), (NULL), (3)));
  106. ERROR 42000: Row expressions in VALUES IN only allowed for multi-field column partitioning near '))' at line 4
  107. create table t1 (a int)
  108. partition by list column_list(a)
  109. ( partition p0 values in (2, 1),
  110. partition p1 values in (4, NULL, 3));
  111. insert into t1 values (1);
  112. insert into t1 values (2);
  113. insert into t1 values (3);
  114. insert into t1 values (4);
  115. insert into t1 values (NULL);
  116. insert into t1 values (5);
  117. ERROR HY000: Table has no partition for value from column_list
  118. show create table t1;
  119. Table Create Table
  120. t1 CREATE TABLE `t1` (
  121. `a` int(11) DEFAULT NULL
  122. ) ENGINE=MyISAM DEFAULT CHARSET=latin1
  123. /*!50100 PARTITION BY LIST COLUMN_LIST(a)
  124. (PARTITION p0 VALUES IN (2,1) ENGINE = MyISAM,
  125. PARTITION p1 VALUES IN (4,NULL,3) ENGINE = MyISAM) */
  126. drop table t1;
  127. create table t1 (a int, b char(10), c varchar(25), d datetime)
  128. partition by range column_list(a,b,c,d)
  129. subpartition by hash (to_seconds(d))
  130. subpartitions 4
  131. ( partition p0 values less than (1, NULL, MAXVALUE, NULL),
  132. partition p1 values less than (1, 'a', MAXVALUE, TO_DAYS('1999-01-01')),
  133. partition p2 values less than (1, 'a', MAXVALUE, MAXVALUE),
  134. partition p3 values less than (1, MAXVALUE, MAXVALUE, MAXVALUE));
  135. drop table t1;
  136. create table t1 (a int, b char(10), c varchar(5), d int)
  137. partition by range column_list(a,b,c)
  138. subpartition by key (c,d)
  139. subpartitions 3
  140. ( partition p0 values less than (1,'abc','abc'),
  141. partition p1 values less than (2,'abc','abc'),
  142. partition p2 values less than (3,'abc','abc'),
  143. partition p3 values less than (4,'abc','abc'));
  144. insert into t1 values (1,'a','b',1),(2,'a','b',2),(3,'a','b',3);
  145. insert into t1 values (1,'b','c',1),(2,'b','c',2),(3,'b','c',3);
  146. insert into t1 values (1,'c','d',1),(2,'c','d',2),(3,'c','d',3);
  147. insert into t1 values (1,'d','e',1),(2,'d','e',2),(3,'d','e',3);
  148. select * from t1 where (a = 1 AND b < 'd' AND (c = 'b' OR (c = 'c' AND d = 1)) OR
  149. (a = 1 AND b >= 'a' AND (c = 'c' OR (c = 'd' AND d = 2))));
  150. a b c d
  151. 1 a b 1
  152. 1 b c 1
  153. drop table t1;
  154. create table t1 (a int, b varchar(2), c int)
  155. partition by range column_list (a, b, c)
  156. (partition p0 values less than (1, 'A', 1),
  157. partition p1 values less than (1, 'B', 1));
  158. insert into t1 values (1, 'A', 1);
  159. explain partitions select * from t1 where a = 1 AND b <= 'A' and c = 1;
  160. id select_type table partitions type possible_keys key key_len ref rows Extra
  161. 1 SIMPLE t1 p0,p1 system NULL NULL NULL NULL 1
  162. select * from t1 where a = 1 AND b <= 'A' and c = 1;
  163. a b c
  164. 1 A 1
  165. drop table t1;
  166. create table t1 (a char, b char, c char)
  167. partition by list column_list(a)
  168. ( partition p0 values in ('a'));
  169. insert into t1 (a) values ('a');
  170. select * from t1 where a = 'a';
  171. a b c
  172. a NULL NULL
  173. drop table t1;
  174. create table t1 (d timestamp)
  175. partition by range column_list(d)
  176. ( partition p0 values less than ('2000-01-01'),
  177. partition p1 values less than ('2040-01-01'));
  178. ERROR HY000: Partition column values of incorrect type
  179. create table t1 (a int, b int)
  180. partition by range column_list(a,b)
  181. (partition p0 values less than (null, 10));
  182. drop table t1;
  183. create table t1 (d date)
  184. partition by range column_list(d)
  185. ( partition p0 values less than ('2000-01-01'),
  186. partition p1 values less than ('2009-01-01'));
  187. drop table t1;
  188. create table t1 (d date)
  189. partition by range column_list(d)
  190. ( partition p0 values less than ('1999-01-01'),
  191. partition p1 values less than ('2000-01-01'));
  192. drop table t1;
  193. create table t1 (d date)
  194. partition by range column_list(d)
  195. ( partition p0 values less than ('2000-01-01'),
  196. partition p1 values less than ('3000-01-01'));
  197. drop table t1;
  198. create table t1 (a int, b int)
  199. partition by range column_list(a,b)
  200. (partition p2 values less than (99,99),
  201. partition p1 values less than (99,999));
  202. insert into t1 values (99,998);
  203. select * from t1 where b = 998;
  204. a b
  205. 99 998
  206. drop table t1;
  207. create table t1 as select to_seconds(null) as to_seconds;
  208. select data_type from information_schema.columns
  209. where column_name='to_seconds';
  210. data_type
  211. int
  212. drop table t1;
  213. create table t1 (a int, b int)
  214. partition by list column_list(a,b)
  215. (partition p0 values in ((maxvalue,maxvalue)));
  216. ERROR 42000: Cannot use MAXVALUE as value in List partitioning near 'maxvalue,maxvalue)))' at line 3
  217. create table t1 (a int, b int)
  218. partition by range column_list(a,b)
  219. (partition p0 values less than (maxvalue,maxvalue));
  220. drop table t1;
  221. create table t1 (a int)
  222. partition by list column_list(a)
  223. (partition p0 values in (0));
  224. select partition_method from information_schema.partitions where table_name='t1';
  225. partition_method
  226. LIST COLUMN_LIST
  227. drop table t1;
  228. create table t1 (a char(6))
  229. partition by range column_list(a)
  230. (partition p0 values less than ('H23456'),
  231. partition p1 values less than ('M23456'));
  232. insert into t1 values ('F23456');
  233. select * from t1;
  234. a
  235. F23456
  236. drop table t1;
  237. create table t1 (a char(6))
  238. partition by range column_list(a)
  239. (partition p0 values less than (H23456),
  240. partition p1 values less than (M23456));
  241. ERROR 42S22: Unknown column 'H23456' in 'field list'
  242. create table t1 (a char(6))
  243. partition by range column_list(a)
  244. (partition p0 values less than (23456),
  245. partition p1 values less than (23456));
  246. ERROR HY000: VALUES LESS THAN value must be strictly increasing for each partition
  247. create table t1 (a int, b int)
  248. partition by range column_list(a,b)
  249. (partition p0 values less than (10));
  250. ERROR 42000: Inconsistency in usage of column lists for partitioning near '))' at line 3
  251. create table t1 (a int, b int)
  252. partition by range column_list(a,b)
  253. (partition p0 values less than (1,1,1);
  254. ERROR HY000: Inconsistency in usage of column lists for partitioning
  255. create table t1 (a int, b int)
  256. partition by range column_list(a,b)
  257. (partition p0 values less than (1, NULL),
  258. partition p1 values less than (2, maxvalue),
  259. partition p2 values less than (3, 3),
  260. partition p3 values less than (10, NULL));
  261. insert into t1 values (10,0);
  262. ERROR HY000: Table has no partition for value from column_list
  263. insert into t1 values (0,1),(1,1),(2,1),(3,1),(3,4),(4,9),(9,1);
  264. select * from t1;
  265. a b
  266. 0 1
  267. 1 1
  268. 2 1
  269. 3 1
  270. 3 4
  271. 4 9
  272. 9 1
  273. alter table t1
  274. partition by range column_list(b,a)
  275. (partition p0 values less than (1,2),
  276. partition p1 values less than (3,3),
  277. partition p2 values less than (9,5));
  278. explain partitions select * from t1 where b < 2;
  279. id select_type table partitions type possible_keys key key_len ref rows Extra
  280. 1 SIMPLE t1 p0,p1 ALL NULL NULL NULL NULL 7 Using where
  281. select * from t1 where b < 2;
  282. a b
  283. 0 1
  284. 1 1
  285. 2 1
  286. 3 1
  287. 9 1
  288. explain partitions select * from t1 where b < 4;
  289. id select_type table partitions type possible_keys key key_len ref rows Extra
  290. 1 SIMPLE t1 p0,p1,p2 ALL NULL NULL NULL NULL 7 Using where
  291. select * from t1 where b < 4;
  292. a b
  293. 0 1
  294. 1 1
  295. 2 1
  296. 3 1
  297. 9 1
  298. alter table t1 reorganize partition p1 into
  299. (partition p11 values less than (2,2),
  300. partition p12 values less than (3,3));
  301. alter table t1 reorganize partition p0 into
  302. (partition p01 values less than (0,3),
  303. partition p02 values less than (1,1));
  304. ERROR HY000: Reorganize of range partitions cannot change total ranges except for last partition where it can extend the range
  305. alter table t1 reorganize partition p2 into
  306. (partition p2 values less than(9,6,1));
  307. ERROR HY000: Inconsistency in usage of column lists for partitioning
  308. alter table t1 reorganize partition p2 into
  309. (partition p2 values less than (10));
  310. ERROR HY000: Inconsistency in usage of column lists for partitioning
  311. alter table t1 reorganize partition p2 into
  312. (partition p21 values less than (4,7),
  313. partition p22 values less than (9,5));
  314. explain partitions select * from t1 where b < 4;
  315. id select_type table partitions type possible_keys key key_len ref rows Extra
  316. 1 SIMPLE t1 p0,p11,p12,p21 ALL NULL NULL NULL NULL 7 Using where
  317. select * from t1 where b < 4;
  318. a b
  319. 0 1
  320. 1 1
  321. 2 1
  322. 3 1
  323. 9 1
  324. drop table t1;
  325. create table t1 (a int, b int)
  326. partition by list column_list(a,b)
  327. subpartition by hash (b)
  328. subpartitions 2
  329. (partition p0 values in ((0,0), (1,1)),
  330. partition p1 values in ((1000,1000)));
  331. insert into t1 values (1000,1000);
  332. drop table t1;
  333. create table t1 (a char, b char, c char)
  334. partition by range column_list(a,b,c)
  335. ( partition p0 values less than ('a','b','c'));
  336. alter table t1 add partition
  337. (partition p1 values less than ('b','c','d'));
  338. drop table t1;