BUG#16002: More review fixes

parent 64ca1650
......@@ -365,13 +365,28 @@ COUNT(*)
DROP TABLE t1;
create table t1 (a bigint unsigned)
partition by range (a)
(partition p0 values less than (10),
partition p1 values less than (0));
ERROR HY000: VALUES LESS THAN value must be strictly increasing for each partition
create table t1 (a bigint unsigned)
partition by range (a)
(partition p0 values less than (0),
partition p1 values less than (10));
ERROR HY000: VALUES LESS THAN value must be strictly increasing for each partition
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` bigint(20) unsigned DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 PARTITION BY RANGE (a) (PARTITION p0 VALUES LESS THAN (0) ENGINE = MyISAM, PARTITION p1 VALUES LESS THAN (10) ENGINE = MyISAM)
drop table t1;
create table t1 (a bigint unsigned)
partition by range (a)
(partition p0 values less than (2),
partition p1 values less than (10));
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` bigint(20) unsigned DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 PARTITION BY RANGE (a) (PARTITION p0 VALUES LESS THAN (2) ENGINE = MyISAM, PARTITION p1 VALUES LESS THAN (10) ENGINE = MyISAM)
insert into t1 values (0xFFFFFFFFFFFFFFFF);
ERROR HY000: Table has no partition for value 18446744073709551615
drop table t1;
......@@ -392,16 +392,24 @@ DROP TABLE t1;
# BUG 16002: Unsigned partition functions not handled correctly
#
--error ER_RANGE_NOT_INCREASING_ERROR
create table t1 (a bigint unsigned)
partition by range (a)
(partition p0 values less than (10),
partition p1 values less than (0));
create table t1 (a bigint unsigned)
partition by range (a)
(partition p0 values less than (0),
partition p1 values less than (10));
show create table t1;
drop table t1;
create table t1 (a bigint unsigned)
partition by range (a)
(partition p0 values less than (2),
partition p1 values less than (10));
show create table t1;
--error ER_NO_PARTITION_FOR_GIVEN_VALUE
insert into t1 values (0xFFFFFFFFFFFFFFFF);
drop table t1;
......@@ -444,9 +444,9 @@ bool partition_info::check_engine_mix(handlerton **engine_array, uint no_parts)
bool partition_info::check_range_constants()
{
partition_element* part_def;
longlong current_largest_int= LONGLONG_MIN;
ulonglong current_largest_uint= 0;
longlong part_range_value_int;
longlong current_largest;
longlong part_range_value;
bool first= TRUE;
uint i;
List_iterator<partition_element> it(partitions);
bool result= TRUE;
......@@ -465,33 +465,26 @@ bool partition_info::check_range_constants()
do
{
part_def= it++;
if (signed_flag)
if ((i != (no_parts - 1)) || !defined_max_value)
{
if ((i != (no_parts - 1)) || !defined_max_value)
part_range_value_int= part_def->range_value;
else
part_range_value_int= LONGLONG_MAX;
if (likely(current_largest_int < part_range_value_int))
{
current_largest_int= part_range_value_int;
range_int_array[i]= part_range_value_int;
}
else
{
my_error(ER_RANGE_NOT_INCREASING_ERROR, MYF(0));
goto end;
}
part_range_value= part_def->range_value;
if (!signed_flag)
part_range_value-= 0x8000000000000000ULL;
}
else
part_range_value= LONGLONG_MAX;
if (first)
{
current_largest= part_range_value;
range_int_array[0]= part_range_value;
first= FALSE;
}
else
{
ulonglong upart_range_value_int;
if ((i == (no_parts - 1)) && defined_max_value)
part_def->range_value= ULONGLONG_MAX;
upart_range_value_int= part_def->range_value;
if (likely(current_largest_uint < upart_range_value_int))
if (likely(current_largest < part_range_value))
{
current_largest_uint= upart_range_value_int;
range_int_array[i]= part_range_value_int;
current_largest= part_range_value;
range_int_array[i]= part_range_value;
}
else
{
......@@ -533,18 +526,6 @@ int partition_info::list_part_cmp(const void* a, const void* b)
return 0;
}
int partition_info::list_part_cmp_unsigned(const void* a, const void* b)
{
ulonglong a1= ((LIST_PART_ENTRY*)a)->list_value;
ulonglong b1= ((LIST_PART_ENTRY*)b)->list_value;
if (a1 < b1)
return -1;
else if (a1 > b1)
return +1;
else
return 0;
}
/*
This routine allocates an array for all list constants to achieve a fast
......@@ -572,7 +553,7 @@ bool partition_info::check_list_constants()
uint list_index= 0;
part_elem_value *list_value;
bool result= TRUE;
longlong curr_value, prev_value;
longlong curr_value, prev_value, type_add, calc_value;
partition_element* part_def;
bool found_null= FALSE;
List_iterator<partition_element> list_func_it(partitions);
......@@ -623,13 +604,22 @@ bool partition_info::check_list_constants()
}
i= 0;
/*
Fix to be able to reuse signed sort functions also for unsigned
partition functions.
*/
type_add= (longlong)(part_expr->unsigned_flag ?
0x8000000000000000ULL :
0ULL);
do
{
part_def= list_func_it++;
List_iterator<part_elem_value> list_val_it2(part_def->list_val_list);
while ((list_value= list_val_it2++))
{
list_array[list_index].list_value= list_value->value;
calc_value= list_value->value - type_add;
list_array[list_index].list_value= calc_value;
list_array[list_index++].partition_id= i;
}
} while (++i < no_parts);
......@@ -637,12 +627,8 @@ bool partition_info::check_list_constants()
if (fixed)
{
bool first= TRUE;
if (!part_expr->unsigned_flag)
qsort((void*)list_array, no_list_values, sizeof(LIST_PART_ENTRY),
&list_part_cmp);
else
qsort((void*)list_array, no_list_values, sizeof(LIST_PART_ENTRY),
&list_part_cmp_unsigned);
qsort((void*)list_array, no_list_values, sizeof(LIST_PART_ENTRY),
&list_part_cmp);
i= prev_value= 0; //prev_value initialised to quiet compiler
do
......
......@@ -1752,8 +1752,7 @@ static int add_partition_options(File fptr, partition_element *p_elem)
return err + add_engine(fptr,p_elem->engine_type);
}
static int add_partition_values(File fptr, partition_info *part_info,
partition_element *p_elem)
static int add_partition_values(File fptr, partition_info *part_info, partition_element *p_elem)
{
int err= 0;
......@@ -1766,7 +1765,7 @@ static int add_partition_values(File fptr, partition_info *part_info,
if (p_elem->signed_flag)
err+= add_int(fptr, p_elem->range_value);
else
err+= add_uint(fptr, (ulonglong)p_elem->range_value);
err+= add_uint(fptr, p_elem->range_value);
err+= add_end_parenthesis(fptr);
}
else
......@@ -2382,6 +2381,7 @@ int get_partition_id_list(partition_info *part_info,
int min_list_index= 0;
int max_list_index= part_info->no_list_values - 1;
longlong part_func_value= part_val_int(part_info->part_expr);
longlong list_value;
bool unsigned_flag= part_info->part_expr->unsigned_flag;
DBUG_ENTER("get_partition_id_list");
......@@ -2394,50 +2394,25 @@ int get_partition_id_list(partition_info *part_info,
}
goto notfound;
}
if (unsigned_flag)
part_func_value-= 0x8000000000000000ULL;
*func_value= part_func_value;
if (!unsigned_flag)
while (max_list_index >= min_list_index)
{
longlong list_value;
while (max_list_index >= min_list_index)
list_index= (max_list_index + min_list_index) >> 1;
list_value= list_array[list_index].list_value;
if (list_value < part_func_value)
min_list_index= list_index + 1;
else if (list_value > part_func_value)
{
list_index= (max_list_index + min_list_index) >> 1;
list_value= list_array[list_index].list_value;
if (list_value < part_func_value)
min_list_index= list_index + 1;
else if (list_value > part_func_value)
{
if (!list_index)
goto notfound;
max_list_index= list_index - 1;
}
else
{
*part_id= (uint32)list_array[list_index].partition_id;
DBUG_RETURN(0);
}
if (!list_index)
goto notfound;
max_list_index= list_index - 1;
}
}
else
{
ulonglong ulist_value;
ulonglong upart_func_value= part_func_value;
while (max_list_index >= min_list_index)
else
{
list_index= (max_list_index + min_list_index) >> 1;
ulist_value= list_array[list_index].list_value;
if (ulist_value < upart_func_value)
min_list_index= list_index + 1;
else if (ulist_value > upart_func_value)
{
if (!list_index)
goto notfound;
max_list_index= list_index - 1;
}
else
{
*part_id= (uint32)list_array[list_index].partition_id;
DBUG_RETURN(0);
}
*part_id= (uint32)list_array[list_index].partition_id;
DBUG_RETURN(0);
}
}
notfound:
......@@ -2496,57 +2471,30 @@ uint32 get_list_array_idx_for_endpoint(partition_info *part_info,
bool unsigned_flag= part_info->part_expr->unsigned_flag;
DBUG_ENTER("get_list_array_idx_for_endpoint");
if (!unsigned_flag)
if (unsigned_flag)
part_func_value-= 0x8000000000000000ULL;
longlong list_value;
while (max_list_index >= min_list_index)
{
longlong list_value;
while (max_list_index >= min_list_index)
list_index= (max_list_index + min_list_index) >> 1;
list_value= list_array[list_index].list_value;
if (list_value < part_func_value)
min_list_index= list_index + 1;
else if (list_value > part_func_value)
{
list_index= (max_list_index + min_list_index) >> 1;
list_value= list_array[list_index].list_value;
if (list_value < part_func_value)
min_list_index= list_index + 1;
else if (list_value > part_func_value)
{
if (!list_index)
goto notfound_signed;
max_list_index= list_index - 1;
}
else
{
DBUG_RETURN(list_index + test(left_endpoint ^ include_endpoint));
}
if (!list_index)
goto notfound;
max_list_index= list_index - 1;
}
notfound_signed:
if (list_value < part_func_value)
list_index++;
DBUG_RETURN(list_index);
}
else
{
ulonglong upart_func_value= part_func_value;
ulonglong ulist_value;
while (max_list_index >= min_list_index)
else
{
list_index= (max_list_index + min_list_index) >> 1;
ulist_value= list_array[list_index].list_value;
if (ulist_value < upart_func_value)
min_list_index= list_index + 1;
else if (ulist_value > upart_func_value)
{
if (!list_index)
goto notfound_unsigned;
max_list_index= list_index - 1;
}
else
{
DBUG_RETURN(list_index + test(left_endpoint ^ include_endpoint));
}
DBUG_RETURN(list_index + test(left_endpoint ^ include_endpoint));
}
notfound_unsigned:
if (ulist_value < upart_func_value)
list_index++;
DBUG_RETURN(list_index);
}
notfound:
if (list_value < part_func_value)
list_index++;
DBUG_RETURN(list_index);
}
......@@ -2568,52 +2516,26 @@ int get_partition_id_range(partition_info *part_info,
*part_id= 0;
DBUG_RETURN(0);
}
if (unsigned_flag)
part_func_value-= 0x8000000000000000ULL;
*func_value= part_func_value;
if (!unsigned_flag)
{
while (max_part_id > min_part_id)
{
loc_part_id= (max_part_id + min_part_id + 1) >> 1;
if (range_array[loc_part_id] <= part_func_value)
min_part_id= loc_part_id + 1;
else
max_part_id= loc_part_id - 1;
}
loc_part_id= max_part_id;
if (part_func_value >= range_array[loc_part_id])
if (loc_part_id != max_partition)
loc_part_id++;
*part_id= (uint32)loc_part_id;
if (loc_part_id == max_partition)
if (range_array[loc_part_id] != LONGLONG_MAX)
if (part_func_value >= range_array[loc_part_id])
DBUG_RETURN(HA_ERR_NO_PARTITION_FOUND);
}
else
while (max_part_id > min_part_id)
{
ulonglong upart_func_value= part_func_value;
ulonglong urange_value;
while (max_part_id > min_part_id)
{
loc_part_id= (max_part_id + min_part_id + 1) >> 1;
urange_value= range_array[loc_part_id];
if (urange_value <= upart_func_value)
min_part_id= loc_part_id + 1;
else
max_part_id= loc_part_id - 1;
}
loc_part_id= max_part_id;
urange_value= range_array[loc_part_id];
if (upart_func_value >= urange_value)
if (loc_part_id != max_partition)
loc_part_id++;
*part_id= (uint32)loc_part_id;
urange_value= range_array[loc_part_id];
if (loc_part_id == max_partition)
if (urange_value != ULONGLONG_MAX)
if (upart_func_value >= urange_value)
DBUG_RETURN(HA_ERR_NO_PARTITION_FOUND);
loc_part_id= (max_part_id + min_part_id + 1) >> 1;
if (range_array[loc_part_id] <= part_func_value)
min_part_id= loc_part_id + 1;
else
max_part_id= loc_part_id - 1;
}
loc_part_id= max_part_id;
if (part_func_value >= range_array[loc_part_id])
if (loc_part_id != max_partition)
loc_part_id++;
*part_id= (uint32)loc_part_id;
if (loc_part_id == max_partition)
if (range_array[loc_part_id] != LONGLONG_MAX)
if (part_func_value >= range_array[loc_part_id])
DBUG_RETURN(HA_ERR_NO_PARTITION_FOUND);
DBUG_RETURN(0);
}
......@@ -2671,71 +2593,34 @@ uint32 get_partition_id_range_for_endpoint(partition_info *part_info,
bool unsigned_flag= part_info->part_expr->unsigned_flag;
DBUG_ENTER("get_partition_id_range_for_endpoint");
if (!unsigned_flag)
if (unsigned_flag)
part_func_value-= 0x8000000000000000ULL;
while (max_part_id > min_part_id)
{
while (max_part_id > min_part_id)
{
loc_part_id= (max_part_id + min_part_id + 1) >> 1;
if (range_array[loc_part_id] <= part_func_value)
min_part_id= loc_part_id + 1;
else
max_part_id= loc_part_id - 1;
}
loc_part_id= max_part_id;
if (loc_part_id < max_partition &&
part_func_value >= range_array[loc_part_id+1])
{
loc_part_id++;
}
if (left_endpoint)
{
if (part_func_value >= range_array[loc_part_id])
loc_part_id++;
}
else
{
if (part_func_value == range_array[loc_part_id])
loc_part_id += test(include_endpoint);
else if (part_func_value > range_array[loc_part_id])
loc_part_id++;
loc_part_id= (max_part_id + min_part_id + 1) >> 1;
if (range_array[loc_part_id] <= part_func_value)
min_part_id= loc_part_id + 1;
else
max_part_id= loc_part_id - 1;
}
loc_part_id= max_part_id;
if (loc_part_id < max_partition &&
part_func_value >= range_array[loc_part_id+1])
{
loc_part_id++;
}
if (left_endpoint)
{
if (part_func_value >= range_array[loc_part_id])
loc_part_id++;
}
}
else
else
{
ulonglong upart_func_value= part_func_value;
ulonglong urange_value;
while (max_part_id > min_part_id)
{
loc_part_id= (max_part_id + min_part_id + 1) >> 1;
urange_value= range_array[loc_part_id];
if (urange_value <= upart_func_value)
min_part_id= loc_part_id + 1;
else
max_part_id= loc_part_id - 1;
}
loc_part_id= max_part_id;
urange_value= range_array[loc_part_id+1];
if (loc_part_id < max_partition &&
upart_func_value >= urange_value)
{
loc_part_id++;
}
if (left_endpoint)
{
urange_value= range_array[loc_part_id];
if (upart_func_value >= urange_value)
loc_part_id++;
}
else
{
urange_value= range_array[loc_part_id];
if (upart_func_value == urange_value)
loc_part_id += test(include_endpoint);
else if (upart_func_value > urange_value)
loc_part_id++;
if (part_func_value == range_array[loc_part_id])
loc_part_id += test(include_endpoint);
else if (part_func_value > range_array[loc_part_id])
loc_part_id++;
}
loc_part_id++;
}
DBUG_RETURN(loc_part_id);
}
......
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