1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
create table t_p_hash (c1 varchar(20),c2 int, c3 varchar(20)) partition by hash(c1) partitions 3;
ERROR 1659 (HY000): Field 'c1' is of a not allowed type for this type of partitioning
create table t_p_hash (c1 varchar(20), c2 int,c3 varchar(20) ) partition by hash(c2+1) partitions 3;
create table t1 (c1 int primary key, c2 int) partition by key() partitions 5;
create table t2 (c1 int, c2 int) partition by list(c1)
(partition p0 values in (1,2,3),
partition p1 values in (5, 6),
partition p2 values in (default));
delimiter //
create procedure bulk_insert_hash()
begin
declare i int;
set i=1;
while i<10001 do
insert INTO t_p_hash (c1,c2 ,c3) values ('a',i,i);
set i=i+1;
end while;
end
//
delimiter ;
drop table t_p_key;
create table t_p_key (c1 varchar(20),c2 int,c3 varchar(20)) partition by key (c2);
create table t3 (c1 int, c2 int) partition by list(c1) (partition p0 values in (1,2,3),partition p1 values in (5, 6),
partition p2 values in (default));
CREATE TABLE `info_t`(id INT, gmt_create TIMESTAMP, info VARCHAR(20), PRIMARY KEY (gmt_create))
PARTITION BY RANGE(UNIX_TIMESTAMP(gmt_create))
(PARTITION p0 VALUES LESS THAN (UNIX_TIMESTAMP('2015-01-01 00:00:00')),
PARTITION p1 VALUES LESS THAN (UNIX_TIMESTAMP('2016-01-01 00:00:00')),
PARTITION p2 VALUES LESS THAN (UNIX_TIMESTAMP('2017-01-01 00:00:00')));
select * from info_t;
create table t2(c1 int primary key, c2 int, c3 int) partition by hash(c1) partitions 5;
explain select * from t1 partition(p4);
explain select * from t1 where c1 = 5 or c1 = 4;
select * from t_p_hash where c2<15 order by c2;
update t_p_hash set c1='special' where c2=10;
explain extended select c1, c2 from t_p_hash where c1='special' ;
create index idx_t_p_hash_c1 on t_p_hash (c1) local;
create index idx_t_p_hash_c3 on t_p_hash (c3) local ;
explain select * from t1 order by c1 desc;
create table t_p_key (c1 varchar(20),c2 int,c3 varchar(20)) partition by key (c2) partitions 3;
create unique index idx_t_p_key_c3_g on t_p_key (c3) global partition by key (c3) partitions 3;
explain extended select c1,c2 from t_p_key where c3='66'; //is_index_back=false
create table t_p_key1 (c1 varchar(20),c2 int,c3 varchar(20)) partition by key (c2) partitions 3;
create index idx_t_p_hash_c11 on t_p_key1 (c1) local;
create index idx_t_p_hash_c31 on t_p_key1 (c3) local ;
explain extended select c1,c2 from t_p_key1 where c3='66' ;
create unique index idx_t_p_hash_c3 on t_p_key1 (c3) local ;
ERROR 1503 (HY000): A UNIQUE INDEX must include all columns in the table's partitioning function
create unique index idx_t_p_hash_c3 on t_p_key1 (c3,c2) local ;
explain extended select c1,c2 from t_p_key where c3='66';
create table h1(c1 int, c2 int, key idx_h1_c1(c1));
create table h2(c1 int, c2 int, key idx_h1_c1(c1));
explain select h1.c1,h2.c2 from h1 ,h2 where h1.c1=h2.c1 ;
| =================================================
|ID|OPERATOR |NAME |EST. ROWS|COST |
-------------------------------------------------
|0 |HASH JOIN | |98010000 |58381710|
|1 | TABLE SCAN|h1(idx_h1_c1)|100000 |47311 |
|2 | TABLE SCAN|h2 |100000 |64066 |
=================================================
explain select /*+index(h2 idx_h2_c1)*/ h1.c1, h2.c2 from h1 ,h2 where h1.c1=h2.c1;
create table t5(a int primary key, b int, c int);
create outline ol_1 on select/*+max_concurrent(0)*/ * from t5 where b =1 and c = 1;
select * from t5 where b =1 and c = 1;
set ob_enable_trace_log = 1;
select count(*) from __all_table;
|