Skip to content

Commit 6f8fb41

Browse files
committed
MDEV-29841 More descriptive text for ER_PARTITION_WRONG_TYPE
For commands (1) alter table t1 add partition (partition p2); (2) alter table t1 add partition (partition px history); It printed the same error message: Wrong partitioning type, expected type: `SYSTEM_TIME` For (1) it is not clear from the syntax that we are trying to add HASH partition. For (2) it is not clear that the table partitioning is different than SYSTEM_TIME. Now it prints what type we are trying to add to what type of partitioning.
1 parent dd9da61 commit 6f8fb41

File tree

5 files changed

+90
-37
lines changed

5 files changed

+90
-37
lines changed

mysql-test/suite/versioning/r/partition.result

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ partition by system_time limit 1;
150150
alter table t1 change x big int;
151151
create or replace table t1 (i int) engine myisam partition by hash(i) partitions 2;
152152
alter table t1 add partition (partition px history);
153-
ERROR HY000: Wrong partitioning type, expected type: `SYSTEM_TIME`
153+
ERROR HY000: Wrong partition type `SYSTEM_TIME` for partitioning by `HASH`
154154
## INSERT, UPDATE, DELETE
155155
create or replace table t1 (x int)
156156
with system versioning
@@ -1105,7 +1105,7 @@ drop table t1;
11051105
create table t1 (a int) with system versioning partition by system_time
11061106
(partition p1 history, partition pn current);
11071107
alter table t1 add partition (partition p2);
1108-
ERROR HY000: Wrong partitioning type, expected type: `SYSTEM_TIME`
1108+
ERROR HY000: Wrong partition type `HASH` for partitioning by `SYSTEM_TIME`
11091109
# MDEV-17891 Assertion failures in select_insert::abort_result_set and
11101110
# mysql_load upon attempt to replace into a full table
11111111
set @@max_heap_table_size= 1024*1024;

sql/partition_info.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,13 @@ class partition_info : public DDL_LOG_STATE, public Sql_alloc
429429
return NULL;
430430
}
431431
uint next_part_no(uint new_parts) const;
432+
433+
int gen_part_type(THD *thd, String *str) const;
432434
};
433435

436+
void part_type_error(THD *thd, partition_info *work_part_info,
437+
const char *part_type, partition_info *tab_part_info);
438+
434439
uint32 get_next_partition_id_range(struct st_partition_iter* part_iter);
435440
bool check_partition_dirs(partition_info *part_info);
436441

sql/share/errmsg-utf8.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9773,9 +9773,9 @@ ER_UNUSED_23
97739773
spa "Nunca debería vd de ver esto"
97749774

97759775
ER_PARTITION_WRONG_TYPE
9776-
chi "错误的分区类型,预期类型:%`s"
9777-
eng "Wrong partitioning type, expected type: %`s"
9778-
spa "Tipo de partición equivocada, tipo esperado: %`s"
9776+
chi "错误的分区类型,预期类型:%`s for partitioning by %`s"
9777+
eng "Wrong partition type %`s for partitioning by %`s"
9778+
spa "Tipo de partición equivocada, tipo esperado: %`s for partitioning by %`s"
97799779

97809780
WARN_VERS_PART_FULL
97819781
chi "版本化表%`s.%`s:partition%`s已满,添加更多历史分区(out of %s)"

sql/sql_lex.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9739,7 +9739,7 @@ bool LEX::part_values_current(THD *thd)
97399739
{
97409740
if (unlikely(part_info->part_type != VERSIONING_PARTITION))
97419741
{
9742-
my_error(ER_PARTITION_WRONG_TYPE, MYF(0), "SYSTEM_TIME");
9742+
part_type_error(thd, NULL, "CURRENT", part_info);
97439743
return true;
97449744
}
97459745
}
@@ -9766,7 +9766,7 @@ bool LEX::part_values_history(THD *thd)
97669766
{
97679767
if (unlikely(part_info->part_type != VERSIONING_PARTITION))
97689768
{
9769-
my_error(ER_PARTITION_WRONG_TYPE, MYF(0), "SYSTEM_TIME");
9769+
part_type_error(thd, NULL, "HISTORY", part_info);
97709770
return true;
97719771
}
97729772
}

sql/sql_partition.cc

Lines changed: 78 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2455,7 +2455,7 @@ static int add_partition_values(String *str, partition_info *part_info,
24552455
@retval != 0 Failure
24562456
*/
24572457

2458-
static int add_key_with_algorithm(String *str, partition_info *part_info)
2458+
static int add_key_with_algorithm(String *str, const partition_info *part_info)
24592459
{
24602460
int err= 0;
24612461
err+= str->append(STRING_WITH_LEN("KEY "));
@@ -2484,6 +2484,78 @@ char *generate_partition_syntax_for_frm(THD *thd, partition_info *part_info,
24842484
return res;
24852485
}
24862486

2487+
2488+
/*
2489+
Generate the partition type syntax from the partition data structure.
2490+
2491+
@return Operation status.
2492+
@retval 0 Success
2493+
@retval > 0 Failure
2494+
@retval -1 Fatal error
2495+
*/
2496+
2497+
int partition_info::gen_part_type(THD *thd, String *str) const
2498+
{
2499+
int err= 0;
2500+
switch (part_type)
2501+
{
2502+
case RANGE_PARTITION:
2503+
err+= str->append(STRING_WITH_LEN("RANGE "));
2504+
break;
2505+
case LIST_PARTITION:
2506+
err+= str->append(STRING_WITH_LEN("LIST "));
2507+
break;
2508+
case HASH_PARTITION:
2509+
if (linear_hash_ind)
2510+
err+= str->append(STRING_WITH_LEN("LINEAR "));
2511+
if (list_of_part_fields)
2512+
{
2513+
err+= add_key_with_algorithm(str, this);
2514+
err+= add_part_field_list(thd, str, part_field_list);
2515+
}
2516+
else
2517+
err+= str->append(STRING_WITH_LEN("HASH "));
2518+
break;
2519+
case VERSIONING_PARTITION:
2520+
err+= str->append(STRING_WITH_LEN("SYSTEM_TIME "));
2521+
break;
2522+
default:
2523+
DBUG_ASSERT(0);
2524+
/* We really shouldn't get here, no use in continuing from here */
2525+
my_error(ER_OUT_OF_RESOURCES, MYF(ME_FATAL));
2526+
return -1;
2527+
}
2528+
return err;
2529+
}
2530+
2531+
2532+
void part_type_error(THD *thd, partition_info *work_part_info,
2533+
const char *part_type,
2534+
partition_info *tab_part_info)
2535+
{
2536+
StringBuffer<256> tab_part_type;
2537+
if (tab_part_info->gen_part_type(thd, &tab_part_type) < 0)
2538+
return;
2539+
tab_part_type.length(tab_part_type.length() - 1);
2540+
if (work_part_info)
2541+
{
2542+
DBUG_ASSERT(!part_type);
2543+
StringBuffer<256> work_part_type;
2544+
if (work_part_info->gen_part_type(thd, &work_part_type) < 0)
2545+
return;
2546+
work_part_type.length(work_part_type.length() - 1);
2547+
my_error(ER_PARTITION_WRONG_TYPE, MYF(0), work_part_type.c_ptr(),
2548+
tab_part_type.c_ptr());
2549+
}
2550+
else
2551+
{
2552+
DBUG_ASSERT(part_type);
2553+
my_error(ER_PARTITION_WRONG_TYPE, MYF(0), part_type,
2554+
tab_part_type.c_ptr());
2555+
}
2556+
}
2557+
2558+
24872559
/*
24882560
Generate the partition syntax from the partition data structure.
24892561
Useful for support of generating defaults, SHOW CREATE TABLES
@@ -2527,34 +2599,10 @@ char *generate_partition_syntax(THD *thd, partition_info *part_info,
25272599
DBUG_ENTER("generate_partition_syntax");
25282600

25292601
err+= str.append(STRING_WITH_LEN(" PARTITION BY "));
2530-
switch (part_info->part_type)
2531-
{
2532-
case RANGE_PARTITION:
2533-
err+= str.append(STRING_WITH_LEN("RANGE "));
2534-
break;
2535-
case LIST_PARTITION:
2536-
err+= str.append(STRING_WITH_LEN("LIST "));
2537-
break;
2538-
case HASH_PARTITION:
2539-
if (part_info->linear_hash_ind)
2540-
err+= str.append(STRING_WITH_LEN("LINEAR "));
2541-
if (part_info->list_of_part_fields)
2542-
{
2543-
err+= add_key_with_algorithm(&str, part_info);
2544-
err+= add_part_field_list(thd, &str, part_info->part_field_list);
2545-
}
2546-
else
2547-
err+= str.append(STRING_WITH_LEN("HASH "));
2548-
break;
2549-
case VERSIONING_PARTITION:
2550-
err+= str.append(STRING_WITH_LEN("SYSTEM_TIME "));
2551-
break;
2552-
default:
2553-
DBUG_ASSERT(0);
2554-
/* We really shouldn't get here, no use in continuing from here */
2555-
my_error(ER_OUT_OF_RESOURCES, MYF(ME_FATAL));
2556-
DBUG_RETURN(NULL);
2557-
}
2602+
int err2= part_info->gen_part_type(thd, &str);
2603+
if (err2 < 0)
2604+
DBUG_RETURN(NULL);
2605+
err+= err2;
25582606
if (part_info->part_type == VERSIONING_PARTITION)
25592607
{
25602608
Vers_part_info *vers_info= part_info->vers_info;
@@ -5044,7 +5092,7 @@ uint prep_alter_part_table(THD *thd, TABLE *table, Alter_info *alter_info,
50445092
else if (thd->work_part_info->part_type == VERSIONING_PARTITION ||
50455093
tab_part_info->part_type == VERSIONING_PARTITION)
50465094
{
5047-
my_error(ER_PARTITION_WRONG_TYPE, MYF(0), "SYSTEM_TIME");
5095+
part_type_error(thd, thd->work_part_info, NULL, tab_part_info);
50485096
}
50495097
else
50505098
{

0 commit comments

Comments
 (0)