MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
methods1.inc
1 ################################################################################
2 # inc/partition_methods1.inc #
3 # #
4 # Purpose: #
5 # Create and check partitioned tables #
6 # The partitioning function use the column f_int1 #
7 # #
8 # For all partitioning methods #
9 # PARTITION BY HASH/KEY/LIST/RANGE #
10 # PARTITION BY RANGE/LIST ... SUBPARTITION BY HASH/KEY ... #
11 # do #
12 # 1. Create the partitioned table #
13 # 2 Insert the content of the table t0_template into t1 #
14 # 3. Execute inc/partition_check.inc #
15 # 4. Drop the table t1 #
16 # done #
17 # #
18 # The parameter #
19 # $unique -- PRIMARY KEY or UNIQUE INDEXes to be created within the #
20 # CREATE TABLE STATEMENT #
21 # has to be set before sourcing this routine. #
22 # Example: #
23 # let $unique= , UNIQUE INDEX uidx1 (f_int1); #
24 # inc/partition_method1s.inc #
25 # #
26 # Attention: The routine inc/partition_methods2.inc is very similar #
27 # to this one. So if something has to be changed here it #
28 # might be necessary to do it also there #
29 # #
30 #------------------------------------------------------------------------------#
31 # Original Author: mleich #
32 # Original Date: 2006-03-05 #
33 # Change Author: #
34 # Change Date: #
35 # Change: #
36 ################################################################################
37 
38 --disable_warnings
39 DROP TABLE IF EXISTS t1;
40 --enable_warnings
41 
42 let $partitioning= ;
43 #----------- PARTITION BY HASH
44 if ($with_partitioning)
45 {
46 let $partitioning= PARTITION BY HASH(f_int1) PARTITIONS 2;
47 }
48 eval CREATE TABLE t1 (
49 $column_list
50 $unique
51 )
52 $partitioning;
53 eval $insert_all;
54 --source suite/parts/inc/partition_check.inc
55 DROP TABLE t1;
56 
57 #----------- PARTITION BY KEY
58 if ($with_partitioning)
59 {
60 let $partitioning= PARTITION BY KEY(f_int1) PARTITIONS 5;
61 }
62 eval CREATE TABLE t1 (
63 $column_list
64 $unique
65 )
66 $partitioning;
67 eval $insert_all;
68 --source suite/parts/inc/partition_check.inc
69 DROP TABLE t1;
70 
71 #----------- PARTITION BY LIST
72 if ($with_partitioning)
73 {
74 let $partitioning= PARTITION BY LIST(MOD(f_int1,4))
75 (PARTITION part_3 VALUES IN (-3),
76  PARTITION part_2 VALUES IN (-2),
77  PARTITION part_1 VALUES IN (-1),
78  PARTITION part_N VALUES IN (NULL),
79  PARTITION part0 VALUES IN (0),
80  PARTITION part1 VALUES IN (1),
81  PARTITION part2 VALUES IN (2),
82  PARTITION part3 VALUES IN (3));
83 }
84 eval CREATE TABLE t1 (
85 $column_list
86 $unique
87 )
88 $partitioning;
89 eval $insert_all;
90 --source suite/parts/inc/partition_check.inc
91 DROP TABLE t1;
92 
93 #----------- PARTITION BY RANGE
94 if ($with_partitioning)
95 {
96 --disable_query_log
97 eval SET @aux = 'PARTITION BY RANGE(f_int1)
98 (PARTITION parta VALUES LESS THAN (0),
99 PARTITION partb VALUES LESS THAN ($max_row_div4),
100 PARTITION partc VALUES LESS THAN ($max_row_div2),
101 PARTITION partd VALUES LESS THAN ($max_row_div2 + $max_row_div4),
102 PARTITION parte VALUES LESS THAN ($max_row),
103 PARTITION partf VALUES LESS THAN $MAX_VALUE)';
104 let $partitioning= `SELECT @aux`;
105 --enable_query_log
106 }
107 eval CREATE TABLE t1 (
108 $column_list
109 $unique
110 )
111 $partitioning;
112 eval $insert_all;
113 --source suite/parts/inc/partition_check.inc
114 DROP TABLE t1;
115 
116 #----------- PARTITION BY RANGE -- SUBPARTITION BY HASH
117 if ($with_partitioning)
118 {
119 --disable_query_log
120 eval SET @aux =
121 'PARTITION BY RANGE(f_int1 DIV 2) SUBPARTITION BY HASH(f_int1) SUBPARTITIONS 2
122 (PARTITION parta VALUES LESS THAN (0),
123 PARTITION partb VALUES LESS THAN ($max_row_div4),
124 PARTITION partc VALUES LESS THAN ($max_row_div2),
125 PARTITION partd VALUES LESS THAN $MAX_VALUE)';
126 let $partitioning= `SELECT @aux`;
127 --enable_query_log
128 }
129 eval CREATE TABLE t1 (
130 $column_list
131 $unique
132 )
133 $partitioning;
134 eval $insert_all;
135 --source suite/parts/inc/partition_check.inc
136 DROP TABLE t1;
137 
138 #----------- PARTITION BY RANGE -- SUBPARTITION BY KEY
139 if ($with_partitioning)
140 {
141 --disable_query_log
142 eval SET @aux = 'PARTITION BY RANGE(f_int1) SUBPARTITION BY KEY(f_int1)
143 (PARTITION part1 VALUES LESS THAN (0)
144 (SUBPARTITION subpart11, SUBPARTITION subpart12),
145 PARTITION part2 VALUES LESS THAN ($max_row_div4)
146 (SUBPARTITION subpart21, SUBPARTITION subpart22),
147 PARTITION part3 VALUES LESS THAN ($max_row_div2)
148 (SUBPARTITION subpart31, SUBPARTITION subpart32),
149 PARTITION part4 VALUES LESS THAN $MAX_VALUE
150 (SUBPARTITION subpart41, SUBPARTITION subpart42))';
151 let $partitioning= `SELECT @aux`;
152 --enable_query_log
153 }
154 eval CREATE TABLE t1 (
155 $column_list
156 $unique
157 )
158 $partitioning;
159 eval $insert_all;
160 --source suite/parts/inc/partition_check.inc
161 DROP TABLE t1;
162 
163 #----------- PARTITION BY LIST -- SUBPARTITION BY HASH
164 if ($with_partitioning)
165 {
166 let $partitioning= PARTITION BY LIST(ABS(MOD(f_int1,3))) SUBPARTITION BY HASH(f_int1 + 1)
167 (PARTITION part1 VALUES IN (0)
168  (SUBPARTITION sp11, SUBPARTITION sp12),
169  PARTITION part2 VALUES IN (1)
170  (SUBPARTITION sp21, SUBPARTITION sp22),
171  PARTITION part3 VALUES IN (2)
172  (SUBPARTITION sp31, SUBPARTITION sp32),
173  PARTITION part4 VALUES IN (NULL)
174  (SUBPARTITION sp41, SUBPARTITION sp42));
175 }
176 eval CREATE TABLE t1 (
177 $column_list
178 $unique
179 )
180 $partitioning;
181 eval $insert_all;
182 --source suite/parts/inc/partition_check.inc
183 DROP TABLE t1;
184 
185 #----------- PARTITION BY LIST -- SUBPARTITION BY KEY
186 if ($with_partitioning)
187 {
188 --disable_query_log
189 eval SET @aux =
190 'PARTITION BY LIST(ABS(MOD(f_int1,2)))
191 SUBPARTITION BY KEY(f_int1) SUBPARTITIONS $sub_part_no
192 (PARTITION part1 VALUES IN (0),
193  PARTITION part2 VALUES IN (1),
194  PARTITION part3 VALUES IN (NULL))';
195 let $partitioning= `SELECT @aux`;
196 --enable_query_log
197 }
198 eval CREATE TABLE t1 (
199 $column_list
200 $unique
201 )
202 $partitioning;
203 eval $insert_all;
204 --source suite/parts/inc/partition_check.inc
205 DROP TABLE t1;