summaryrefslogtreecommitdiff
path: root/sql/partition_info.cc
diff options
context:
space:
mode:
authorMattias Jonsson <mattias.jonsson@oracle.com>2010-08-30 17:33:55 +0200
committerMattias Jonsson <mattias.jonsson@oracle.com>2010-08-30 17:33:55 +0200
commite7dc80b8078d2f63bd1d12f0d61f13c88e96f87f (patch)
tree95c1677d57c85cadeb341aee06221cfbe98753ec /sql/partition_info.cc
parent622250cba7fb85321814187a84732cbeb2c40088 (diff)
downloadmariadb-git-e7dc80b8078d2f63bd1d12f0d61f13c88e96f87f.tar.gz
Bug#50036: Inconsistent errors when using TIMESTAMP columns/expressions
It was hard to understand what the error really meant. The error checking in partitioning is done in several different parts during the execution of a query which can make it hard to return useful errors. Added a new error for bad VALUES part in the per PARTITION clause. Using the more verbose error that a column is not allowed in the partitioning function instead of just that the function is not allowed.
Diffstat (limited to 'sql/partition_info.cc')
-rw-r--r--sql/partition_info.cc66
1 files changed, 56 insertions, 10 deletions
diff --git a/sql/partition_info.cc b/sql/partition_info.cc
index caf28fdd83e..879e7b10023 100644
--- a/sql/partition_info.cc
+++ b/sql/partition_info.cc
@@ -742,7 +742,6 @@ bool partition_info::check_range_constants(THD *thd)
longlong part_range_value;
bool signed_flag= !part_expr->unsigned_flag;
- part_result_type= INT_RESULT;
range_int_array= (longlong*)sql_alloc(num_parts * sizeof(longlong));
if (unlikely(range_int_array == NULL))
{
@@ -917,7 +916,6 @@ bool partition_info::check_list_constants(THD *thd)
List_iterator<partition_element> list_func_it(partitions);
DBUG_ENTER("partition_info::check_list_constants");
- part_result_type= INT_RESULT;
num_list_values= 0;
/*
We begin by calculating the number of list values that have been
@@ -1608,6 +1606,52 @@ id_err:
return 1;
}
+
+/**
+ Check what kind of error to report
+
+ @param use_subpart_expr Use the subpart_expr instead of part_expr
+ @param part_str Name of partition to report error (or NULL)
+*/
+void partition_info::report_part_expr_error(bool use_subpart_expr)
+{
+ Item *expr= part_expr;
+ DBUG_ENTER("partition_info::report_part_expr_error");
+ if (use_subpart_expr)
+ expr= subpart_expr;
+
+ if (expr->type() == Item::FIELD_ITEM)
+ {
+ partition_type type= part_type;
+ bool list_of_fields= list_of_part_fields;
+ Item_field *item_field= (Item_field*) expr;
+ /*
+ The expression consists of a single field.
+ It must be of integer type unless KEY or COLUMNS partitioning.
+ */
+ if (use_subpart_expr)
+ {
+ type= subpart_type;
+ list_of_fields= list_of_subpart_fields;
+ }
+ if (!column_list &&
+ item_field->field &&
+ item_field->field->result_type() != INT_RESULT &&
+ !(type == HASH_PARTITION && list_of_fields))
+ {
+ my_error(ER_FIELD_TYPE_NOT_ALLOWED_AS_PARTITION_FIELD, MYF(0),
+ item_field->name);
+ DBUG_VOID_RETURN;
+ }
+ }
+ if (use_subpart_expr)
+ my_error(ER_PARTITION_FUNC_NOT_ALLOWED_ERROR, MYF(0), "SUBPARTITION");
+ else
+ my_error(ER_PARTITION_FUNC_NOT_ALLOWED_ERROR, MYF(0), "PARTITION");
+ DBUG_VOID_RETURN;
+}
+
+
/*
Create a new column value in current list with maxvalue
Called from parser
@@ -1891,7 +1935,7 @@ int partition_info::reorganize_into_single_field_col_val()
code.
SYNOPSIS
- fix_func_partition()
+ fix_partition_values()
thd Thread object
col_val Array of one value
part_elem The partition instance
@@ -1901,13 +1945,13 @@ int partition_info::reorganize_into_single_field_col_val()
TRUE Failure
FALSE Success
*/
-int partition_info::fix_func_partition(THD *thd,
- part_elem_value *val,
- partition_element *part_elem,
- uint part_id)
+int partition_info::fix_partition_values(THD *thd,
+ part_elem_value *val,
+ partition_element *part_elem,
+ uint part_id)
{
part_column_list_val *col_val= val->col_val_array;
- DBUG_ENTER("partition_info::fix_func_partition");
+ DBUG_ENTER("partition_info::fix_partition_values");
if (col_val->fixed)
{
@@ -1953,7 +1997,9 @@ int partition_info::fix_func_partition(THD *thd,
}
else if (item_expr->result_type() != INT_RESULT)
{
- my_error(ER_INCONSISTENT_TYPE_OF_FUNCTIONS_ERROR, MYF(0));
+ /* VALUES clause only allowed on partitions, not subpartitions */
+ my_error(ER_VALUES_IS_NOT_INT_TYPE_ERROR, MYF(0),
+ part_elem->partition_name);
DBUG_RETURN(TRUE);
}
if (part_type == RANGE_PARTITION)
@@ -2168,7 +2214,7 @@ int partition_info::fix_parser_data(THD *thd)
}
else
{
- if (fix_func_partition(thd, val, part_elem, i))
+ if (fix_partition_values(thd, val, part_elem, i))
{
DBUG_RETURN(TRUE);
}