Commit cd87e655 authored by unknown's avatar unknown

Merge dator5.(none):/home/pappa/bug20770

into  dator5.(none):/home/pappa/push_tree_w28


sql/ha_partition.cc:
  Auto merged
sql/ha_partition.h:
  Auto merged
parents 39e48fb2 f481a6a8
......@@ -1082,4 +1082,43 @@ a
2
1
drop table t1;
create table t1 (a int) engine myisam
partition by range (a)
subpartition by hash (a)
(partition p0 VALUES LESS THAN (1) DATA DIRECTORY = 'hello/master-data/tmpdata' INDEX DIRECTORY = 'hello/master-data/tmpinx'
(SUBPARTITION subpart00, SUBPARTITION subpart01));
t1#P#p0#SP#subpart00.MYD
t1#P#p0#SP#subpart00.MYI
t1#P#p0#SP#subpart01.MYD
t1#P#p0#SP#subpart01.MYI
t1.frm
t1.par
t1#P#p0#SP#subpart00.MYD
t1#P#p0#SP#subpart01.MYD
t1#P#p0#SP#subpart00.MYI
t1#P#p0#SP#subpart01.MYI
ALTER TABLE t1 REORGANIZE PARTITION p0 INTO
(partition p1 VALUES LESS THAN (1) DATA DIRECTORY = 'hello/master-data/tmpdata' INDEX DIRECTORY = 'hello/master-data/tmpinx'
(SUBPARTITION subpart10, SUBPARTITION subpart11),
partition p2 VALUES LESS THAN (2) DATA DIRECTORY = 'hello/master-data/tmpdata' INDEX DIRECTORY = 'hello/master-data/tmpinx'
(SUBPARTITION subpart20, SUBPARTITION subpart21));
t1#P#p1#SP#subpart10.MYD
t1#P#p1#SP#subpart10.MYI
t1#P#p1#SP#subpart11.MYD
t1#P#p1#SP#subpart11.MYI
t1#P#p2#SP#subpart20.MYD
t1#P#p2#SP#subpart20.MYI
t1#P#p2#SP#subpart21.MYD
t1#P#p2#SP#subpart21.MYI
t1.frm
t1.par
t1#P#p1#SP#subpart10.MYD
t1#P#p1#SP#subpart11.MYD
t1#P#p2#SP#subpart20.MYD
t1#P#p2#SP#subpart21.MYD
t1#P#p1#SP#subpart10.MYI
t1#P#p1#SP#subpart11.MYI
t1#P#p2#SP#subpart20.MYI
t1#P#p2#SP#subpart21.MYI
drop table t1;
End of 5.1 tests
......@@ -519,3 +519,115 @@ partition p3 values less than (1998),
partition p4 values less than (1999),
partition p5 values less than (2000));
drop table t1;
CREATE TABLE t1 (a date)
PARTITION BY RANGE (TO_DAYS(a))
(PARTITION p3xx VALUES LESS THAN (TO_DAYS('2004-01-01')),
PARTITION p401 VALUES LESS THAN (TO_DAYS('2004-02-01')),
PARTITION p402 VALUES LESS THAN (TO_DAYS('2004-03-01')),
PARTITION p403 VALUES LESS THAN (TO_DAYS('2004-04-01')),
PARTITION p404 VALUES LESS THAN (TO_DAYS('2004-05-01')),
PARTITION p405 VALUES LESS THAN (TO_DAYS('2004-06-01')),
PARTITION p406 VALUES LESS THAN (TO_DAYS('2004-07-01')),
PARTITION p407 VALUES LESS THAN (TO_DAYS('2004-08-01')),
PARTITION p408 VALUES LESS THAN (TO_DAYS('2004-09-01')),
PARTITION p409 VALUES LESS THAN (TO_DAYS('2004-10-01')),
PARTITION p410 VALUES LESS THAN (TO_DAYS('2004-11-01')),
PARTITION p411 VALUES LESS THAN (TO_DAYS('2004-12-01')),
PARTITION p412 VALUES LESS THAN (TO_DAYS('2005-01-01')),
PARTITION p501 VALUES LESS THAN (TO_DAYS('2005-02-01')),
PARTITION p502 VALUES LESS THAN (TO_DAYS('2005-03-01')),
PARTITION p503 VALUES LESS THAN (TO_DAYS('2005-04-01')),
PARTITION p504 VALUES LESS THAN (TO_DAYS('2005-05-01')),
PARTITION p505 VALUES LESS THAN (TO_DAYS('2005-06-01')),
PARTITION p506 VALUES LESS THAN (TO_DAYS('2005-07-01')),
PARTITION p507 VALUES LESS THAN (TO_DAYS('2005-08-01')),
PARTITION p508 VALUES LESS THAN (TO_DAYS('2005-09-01')),
PARTITION p509 VALUES LESS THAN (TO_DAYS('2005-10-01')),
PARTITION p510 VALUES LESS THAN (TO_DAYS('2005-11-01')),
PARTITION p511 VALUES LESS THAN (TO_DAYS('2005-12-01')),
PARTITION p512 VALUES LESS THAN (TO_DAYS('2006-01-01')),
PARTITION p601 VALUES LESS THAN (TO_DAYS('2006-02-01')),
PARTITION p602 VALUES LESS THAN (TO_DAYS('2006-03-01')),
PARTITION p603 VALUES LESS THAN (TO_DAYS('2006-04-01')),
PARTITION p604 VALUES LESS THAN (TO_DAYS('2006-05-01')),
PARTITION p605 VALUES LESS THAN (TO_DAYS('2006-06-01')),
PARTITION p606 VALUES LESS THAN (TO_DAYS('2006-07-01')),
PARTITION p607 VALUES LESS THAN (TO_DAYS('2006-08-01')));
INSERT INTO t1 VALUES ('2003-01-13'),('2003-06-20'),('2003-08-30');
INSERT INTO t1 VALUES ('2003-04-13'),('2003-07-20'),('2003-10-30');
INSERT INTO t1 VALUES ('2003-05-13'),('2003-11-20'),('2003-12-30');
INSERT INTO t1 VALUES ('2004-01-13'),('2004-01-20'),('2004-01-30');
INSERT INTO t1 VALUES ('2004-02-13'),('2004-02-20'),('2004-02-28');
INSERT INTO t1 VALUES ('2004-03-13'),('2004-03-20'),('2004-03-30');
INSERT INTO t1 VALUES ('2004-04-13'),('2004-04-20'),('2004-04-30');
INSERT INTO t1 VALUES ('2004-05-13'),('2004-05-20'),('2004-05-30');
INSERT INTO t1 VALUES ('2004-06-13'),('2004-06-20'),('2004-06-30');
INSERT INTO t1 VALUES ('2004-07-13'),('2004-07-20'),('2004-07-30');
INSERT INTO t1 VALUES ('2004-08-13'),('2004-08-20'),('2004-08-30');
INSERT INTO t1 VALUES ('2004-09-13'),('2004-09-20'),('2004-09-30');
INSERT INTO t1 VALUES ('2004-10-13'),('2004-10-20'),('2004-10-30');
INSERT INTO t1 VALUES ('2004-11-13'),('2004-11-20'),('2004-11-30');
INSERT INTO t1 VALUES ('2004-12-13'),('2004-12-20'),('2004-12-30');
INSERT INTO t1 VALUES ('2005-01-13'),('2005-01-20'),('2005-01-30');
INSERT INTO t1 VALUES ('2005-02-13'),('2005-02-20'),('2005-02-28');
INSERT INTO t1 VALUES ('2005-03-13'),('2005-03-20'),('2005-03-30');
INSERT INTO t1 VALUES ('2005-04-13'),('2005-04-20'),('2005-04-30');
INSERT INTO t1 VALUES ('2005-05-13'),('2005-05-20'),('2005-05-30');
INSERT INTO t1 VALUES ('2005-06-13'),('2005-06-20'),('2005-06-30');
INSERT INTO t1 VALUES ('2005-07-13'),('2005-07-20'),('2005-07-30');
INSERT INTO t1 VALUES ('2005-08-13'),('2005-08-20'),('2005-08-30');
INSERT INTO t1 VALUES ('2005-09-13'),('2005-09-20'),('2005-09-30');
INSERT INTO t1 VALUES ('2005-10-13'),('2005-10-20'),('2005-10-30');
INSERT INTO t1 VALUES ('2005-11-13'),('2005-11-20'),('2005-11-30');
INSERT INTO t1 VALUES ('2005-12-13'),('2005-12-20'),('2005-12-30');
INSERT INTO t1 VALUES ('2006-01-13'),('2006-01-20'),('2006-01-30');
INSERT INTO t1 VALUES ('2006-02-13'),('2006-02-20'),('2006-02-28');
INSERT INTO t1 VALUES ('2006-03-13'),('2006-03-20'),('2006-03-30');
INSERT INTO t1 VALUES ('2006-04-13'),('2006-04-20'),('2006-04-30');
INSERT INTO t1 VALUES ('2006-05-13'),('2006-05-20'),('2006-05-30');
INSERT INTO t1 VALUES ('2006-06-13'),('2006-06-20'),('2006-06-30');
INSERT INTO t1 VALUES ('2006-07-13'),('2006-07-20'),('2006-07-30');
SELECT * FROM t1
WHERE a >= '2004-07-01' AND a <= '2004-09-30';
a
2004-07-13
2004-07-20
2004-07-30
2004-08-13
2004-08-20
2004-08-30
2004-09-13
2004-09-20
2004-09-30
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE a >= '2004-07-01' AND a <= '2004-09-30';
id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t1 p407,p408,p409 ALL NULL NULL NULL NULL 9 Using where
SELECT * from t1
WHERE (a >= '2004-07-01' AND a <= '2004-09-30') OR
(a >= '2005-07-01' AND a <= '2005-09-30');
a
2004-07-13
2004-07-20
2004-07-30
2004-08-13
2004-08-20
2004-08-30
2004-09-13
2004-09-20
2004-09-30
2005-07-13
2005-07-20
2005-07-30
2005-08-13
2005-08-20
2005-08-30
2005-09-13
2005-09-20
2005-09-30
EXPLAIN PARTITIONS SELECT * from t1
WHERE (a >= '2004-07-01' AND a <= '2004-09-30') OR
(a >= '2005-07-01' AND a <= '2005-09-30');
id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t1 p407,p408,p409,p507,p508,p509 ALL NULL NULL NULL NULL 18 Using where
DROP TABLE t1;
......@@ -1261,4 +1261,47 @@ insert into t1 values (1),(2);
select * from t1 ORDER BY a DESC;
drop table t1;
#
# Bug 20770 Partitions: DATA DIRECTORY clause change in reorganize
# doesn't remove old directory
#
--disable_query_log
--exec mkdir $MYSQLTEST_VARDIR/master-data/tmpdata || true
eval SET @data_dir = 'DATA DIRECTORY = ''$MYSQLTEST_VARDIR/master-data/tmpdata''';
let $data_directory = `select @data_dir`;
--exec mkdir $MYSQLTEST_VARDIR/master-data/tmpinx || true
eval SET @inx_dir = 'INDEX DIRECTORY = ''$MYSQLTEST_VARDIR/master-data/tmpinx''';
let $inx_directory = `select @inx_dir`;
--enable_query_log
--replace_result $MYSQLTEST_VARDIR "hello"
eval create table t1 (a int) engine myisam
partition by range (a)
subpartition by hash (a)
(partition p0 VALUES LESS THAN (1) $data_directory $inx_directory
(SUBPARTITION subpart00, SUBPARTITION subpart01));
--replace_result $MYSQLTEST_VARDIR "hello"
--exec ls $MYSQLTEST_VARDIR/master-data/test || true
--replace_result $MYSQLTEST_VARDIR "hello"
--exec ls $MYSQLTEST_VARDIR/master-data/tmpdata || true
--replace_result $MYSQLTEST_VARDIR "hello"
--exec ls $MYSQLTEST_VARDIR/master-data/tmpinx || true
--replace_result $MYSQLTEST_VARDIR "hello"
eval ALTER TABLE t1 REORGANIZE PARTITION p0 INTO
(partition p1 VALUES LESS THAN (1) $data_directory $inx_directory
(SUBPARTITION subpart10, SUBPARTITION subpart11),
partition p2 VALUES LESS THAN (2) $data_directory $inx_directory
(SUBPARTITION subpart20, SUBPARTITION subpart21));
--replace_result $MYSQLTEST_VARDIR "hello"
--exec ls $MYSQLTEST_VARDIR/master-data/test || true
--replace_result $MYSQLTEST_VARDIR "hello"
--exec ls $MYSQLTEST_VARDIR/master-data/tmpdata || true
--replace_result $MYSQLTEST_VARDIR "hello"
--exec ls $MYSQLTEST_VARDIR/master-data/tmpinx || true
drop table t1;
--echo End of 5.1 tests
......@@ -555,3 +555,90 @@ reorganize partition p5 into
drop table t1;
#
# New test cases for date based partitioning
#
CREATE TABLE t1 (a date)
PARTITION BY RANGE (TO_DAYS(a))
(PARTITION p3xx VALUES LESS THAN (TO_DAYS('2004-01-01')),
PARTITION p401 VALUES LESS THAN (TO_DAYS('2004-02-01')),
PARTITION p402 VALUES LESS THAN (TO_DAYS('2004-03-01')),
PARTITION p403 VALUES LESS THAN (TO_DAYS('2004-04-01')),
PARTITION p404 VALUES LESS THAN (TO_DAYS('2004-05-01')),
PARTITION p405 VALUES LESS THAN (TO_DAYS('2004-06-01')),
PARTITION p406 VALUES LESS THAN (TO_DAYS('2004-07-01')),
PARTITION p407 VALUES LESS THAN (TO_DAYS('2004-08-01')),
PARTITION p408 VALUES LESS THAN (TO_DAYS('2004-09-01')),
PARTITION p409 VALUES LESS THAN (TO_DAYS('2004-10-01')),
PARTITION p410 VALUES LESS THAN (TO_DAYS('2004-11-01')),
PARTITION p411 VALUES LESS THAN (TO_DAYS('2004-12-01')),
PARTITION p412 VALUES LESS THAN (TO_DAYS('2005-01-01')),
PARTITION p501 VALUES LESS THAN (TO_DAYS('2005-02-01')),
PARTITION p502 VALUES LESS THAN (TO_DAYS('2005-03-01')),
PARTITION p503 VALUES LESS THAN (TO_DAYS('2005-04-01')),
PARTITION p504 VALUES LESS THAN (TO_DAYS('2005-05-01')),
PARTITION p505 VALUES LESS THAN (TO_DAYS('2005-06-01')),
PARTITION p506 VALUES LESS THAN (TO_DAYS('2005-07-01')),
PARTITION p507 VALUES LESS THAN (TO_DAYS('2005-08-01')),
PARTITION p508 VALUES LESS THAN (TO_DAYS('2005-09-01')),
PARTITION p509 VALUES LESS THAN (TO_DAYS('2005-10-01')),
PARTITION p510 VALUES LESS THAN (TO_DAYS('2005-11-01')),
PARTITION p511 VALUES LESS THAN (TO_DAYS('2005-12-01')),
PARTITION p512 VALUES LESS THAN (TO_DAYS('2006-01-01')),
PARTITION p601 VALUES LESS THAN (TO_DAYS('2006-02-01')),
PARTITION p602 VALUES LESS THAN (TO_DAYS('2006-03-01')),
PARTITION p603 VALUES LESS THAN (TO_DAYS('2006-04-01')),
PARTITION p604 VALUES LESS THAN (TO_DAYS('2006-05-01')),
PARTITION p605 VALUES LESS THAN (TO_DAYS('2006-06-01')),
PARTITION p606 VALUES LESS THAN (TO_DAYS('2006-07-01')),
PARTITION p607 VALUES LESS THAN (TO_DAYS('2006-08-01')));
INSERT INTO t1 VALUES ('2003-01-13'),('2003-06-20'),('2003-08-30');
INSERT INTO t1 VALUES ('2003-04-13'),('2003-07-20'),('2003-10-30');
INSERT INTO t1 VALUES ('2003-05-13'),('2003-11-20'),('2003-12-30');
INSERT INTO t1 VALUES ('2004-01-13'),('2004-01-20'),('2004-01-30');
INSERT INTO t1 VALUES ('2004-02-13'),('2004-02-20'),('2004-02-28');
INSERT INTO t1 VALUES ('2004-03-13'),('2004-03-20'),('2004-03-30');
INSERT INTO t1 VALUES ('2004-04-13'),('2004-04-20'),('2004-04-30');
INSERT INTO t1 VALUES ('2004-05-13'),('2004-05-20'),('2004-05-30');
INSERT INTO t1 VALUES ('2004-06-13'),('2004-06-20'),('2004-06-30');
INSERT INTO t1 VALUES ('2004-07-13'),('2004-07-20'),('2004-07-30');
INSERT INTO t1 VALUES ('2004-08-13'),('2004-08-20'),('2004-08-30');
INSERT INTO t1 VALUES ('2004-09-13'),('2004-09-20'),('2004-09-30');
INSERT INTO t1 VALUES ('2004-10-13'),('2004-10-20'),('2004-10-30');
INSERT INTO t1 VALUES ('2004-11-13'),('2004-11-20'),('2004-11-30');
INSERT INTO t1 VALUES ('2004-12-13'),('2004-12-20'),('2004-12-30');
INSERT INTO t1 VALUES ('2005-01-13'),('2005-01-20'),('2005-01-30');
INSERT INTO t1 VALUES ('2005-02-13'),('2005-02-20'),('2005-02-28');
INSERT INTO t1 VALUES ('2005-03-13'),('2005-03-20'),('2005-03-30');
INSERT INTO t1 VALUES ('2005-04-13'),('2005-04-20'),('2005-04-30');
INSERT INTO t1 VALUES ('2005-05-13'),('2005-05-20'),('2005-05-30');
INSERT INTO t1 VALUES ('2005-06-13'),('2005-06-20'),('2005-06-30');
INSERT INTO t1 VALUES ('2005-07-13'),('2005-07-20'),('2005-07-30');
INSERT INTO t1 VALUES ('2005-08-13'),('2005-08-20'),('2005-08-30');
INSERT INTO t1 VALUES ('2005-09-13'),('2005-09-20'),('2005-09-30');
INSERT INTO t1 VALUES ('2005-10-13'),('2005-10-20'),('2005-10-30');
INSERT INTO t1 VALUES ('2005-11-13'),('2005-11-20'),('2005-11-30');
INSERT INTO t1 VALUES ('2005-12-13'),('2005-12-20'),('2005-12-30');
INSERT INTO t1 VALUES ('2006-01-13'),('2006-01-20'),('2006-01-30');
INSERT INTO t1 VALUES ('2006-02-13'),('2006-02-20'),('2006-02-28');
INSERT INTO t1 VALUES ('2006-03-13'),('2006-03-20'),('2006-03-30');
INSERT INTO t1 VALUES ('2006-04-13'),('2006-04-20'),('2006-04-30');
INSERT INTO t1 VALUES ('2006-05-13'),('2006-05-20'),('2006-05-30');
INSERT INTO t1 VALUES ('2006-06-13'),('2006-06-20'),('2006-06-30');
INSERT INTO t1 VALUES ('2006-07-13'),('2006-07-20'),('2006-07-30');
SELECT * FROM t1
WHERE a >= '2004-07-01' AND a <= '2004-09-30';
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE a >= '2004-07-01' AND a <= '2004-09-30';
SELECT * from t1
WHERE (a >= '2004-07-01' AND a <= '2004-09-30') OR
(a >= '2005-07-01' AND a <= '2005-09-30');
EXPLAIN PARTITIONS SELECT * from t1
WHERE (a >= '2004-07-01' AND a <= '2004-09-30') OR
(a >= '2005-07-01' AND a <= '2005-09-30');
DROP TABLE t1;
......@@ -1126,13 +1126,15 @@ int ha_partition::handle_opt_partitions(THD *thd, HA_CHECK_OPT *check_opt,
int ha_partition::prepare_new_partition(TABLE *table,
HA_CREATE_INFO *create_info,
handler *file, const char *part_name)
handler *file, const char *part_name,
partition_element *p_elem)
{
int error;
bool create_flag= FALSE;
bool open_flag= FALSE;
DBUG_ENTER("prepare_new_partition");
set_up_table_before_create(table, part_name, create_info, 0, p_elem);
if ((error= file->create(part_name, table, create_info)))
goto error;
create_flag= TRUE;
......@@ -1425,7 +1427,8 @@ int ha_partition::change_partitions(HA_CREATE_INFO *create_info,
DBUG_PRINT("info", ("Add subpartition %s", part_name_buff));
if ((error= prepare_new_partition(table, create_info,
new_file_array[part],
(const char *)part_name_buff)))
(const char *)part_name_buff,
sub_elem)))
{
cleanup_new_partition(part_count);
DBUG_RETURN(error);
......@@ -1441,7 +1444,8 @@ int ha_partition::change_partitions(HA_CREATE_INFO *create_info,
DBUG_PRINT("info", ("Add partition %s", part_name_buff));
if ((error= prepare_new_partition(table, create_info,
new_file_array[i],
(const char *)part_name_buff)))
(const char *)part_name_buff,
part_elem)))
{
cleanup_new_partition(part_count);
DBUG_RETURN(error);
......@@ -1653,7 +1657,7 @@ uint ha_partition::del_ren_cre_table(const char *from,
error= (*file)->delete_table((const char*) from_buff);
else
{
set_up_table_before_create(table_arg, from_buff, create_info, i);
set_up_table_before_create(table_arg, from_buff, create_info, i, NULL);
error= (*file)->create(from_buff, table_arg, create_info);
}
name_buffer_ptr= strend(name_buffer_ptr) + 1;
......@@ -1729,12 +1733,15 @@ partition_element *ha_partition::find_partition_element(uint part_id)
void ha_partition::set_up_table_before_create(TABLE *table,
const char *partition_name_with_path,
HA_CREATE_INFO *info,
uint part_id)
uint part_id,
partition_element *part_elem)
{
partition_element *part_elem= find_partition_element(part_id);
if (!part_elem)
return; // Fatal error
{
part_elem= find_partition_element(part_id);
if (!part_elem)
return; // Fatal error
}
table->s->max_rows= part_elem->part_max_rows;
table->s->min_rows= part_elem->part_min_rows;
const char *partition_name= strrchr(partition_name_with_path, FN_LIBCHAR);
......
......@@ -204,7 +204,8 @@ class ha_partition :public handler
int copy_partitions(ulonglong *copied, ulonglong *deleted);
void cleanup_new_partition(uint part_count);
int prepare_new_partition(TABLE *table, HA_CREATE_INFO *create_info,
handler *file, const char *part_name);
handler *file, const char *part_name,
partition_element *p_elem);
/*
delete_table, rename_table and create uses very similar logic which
is packed into this routine.
......@@ -224,7 +225,8 @@ class ha_partition :public handler
void set_up_table_before_create(TABLE *table_arg,
const char *partition_name_with_path,
HA_CREATE_INFO *info,
uint part_id);
uint part_id,
partition_element *p_elem);
partition_element *find_partition_element(uint part_id);
public:
......
......@@ -3716,14 +3716,15 @@ sub_part_definition:
{
LEX *lex= Lex;
partition_info *part_info= lex->part_info;
partition_element *p_elem= new partition_element();
if (!p_elem ||
part_info->current_partition->subpartitions.push_back(p_elem))
partition_element *curr_part= part_info->current_partition;
partition_element *sub_p_elem= new partition_element(curr_part);
if (!sub_p_elem ||
curr_part->subpartitions.push_back(sub_p_elem))
{
mem_alloc_error(sizeof(partition_element));
YYABORT;
}
part_info->curr_part_elem= p_elem;
part_info->curr_part_elem= sub_p_elem;
part_info->use_default_subpartitions= FALSE;
part_info->use_default_no_subpartitions= FALSE;
part_info->count_curr_subparts++;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment