summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/suite/versioning/r/partition.result14
-rw-r--r--mysql-test/suite/versioning/t/partition.test12
-rw-r--r--sql/partition_info.h5
-rw-r--r--sql/share/errmsg-utf8.txt6
-rw-r--r--sql/sql_lex.cc6
-rw-r--r--sql/sql_lex.h2
-rw-r--r--sql/sql_partition.cc108
-rw-r--r--sql/sql_table.cc2
-rw-r--r--sql/sql_yacc.yy4
9 files changed, 122 insertions, 37 deletions
diff --git a/mysql-test/suite/versioning/r/partition.result b/mysql-test/suite/versioning/r/partition.result
index 8cd6e97f2d4..6feee27818b 100644
--- a/mysql-test/suite/versioning/r/partition.result
+++ b/mysql-test/suite/versioning/r/partition.result
@@ -96,6 +96,16 @@ with system versioning
partition by system_time (
partition p0 history,
partition pn current);
+create or replace table t1 (a int)
+partition by range (a) (
+partition p0 history,
+partition p1 current);
+ERROR HY000: Wrong partition type `SYSTEM_TIME` for partitioning by `RANGE`
+create or replace table t1 (b int)
+partition by range (a) (
+partition p0 current,
+partition p1 history);
+ERROR HY000: Wrong partition type `SYSTEM_TIME` for partitioning by `RANGE`
## ALTER TABLE
alter table t1 add partition (
partition p1 current);
@@ -150,7 +160,7 @@ partition by system_time limit 1;
alter table t1 change x big int;
create or replace table t1 (i int) engine myisam partition by hash(i) partitions 2;
alter table t1 add partition (partition px history);
-ERROR HY000: Wrong partitioning type, expected type: `SYSTEM_TIME`
+ERROR HY000: Wrong partition type `SYSTEM_TIME` for partitioning by `HASH`
## INSERT, UPDATE, DELETE
create or replace table t1 (x int)
with system versioning
@@ -1105,7 +1115,7 @@ drop table t1;
create table t1 (a int) with system versioning partition by system_time
(partition p1 history, partition pn current);
alter table t1 add partition (partition p2);
-ERROR HY000: Wrong partitioning type, expected type: `SYSTEM_TIME`
+ERROR HY000: Wrong partition type `HASH` for partitioning by `SYSTEM_TIME`
# MDEV-17891 Assertion failures in select_insert::abort_result_set and
# mysql_load upon attempt to replace into a full table
set @@max_heap_table_size= 1024*1024;
diff --git a/mysql-test/suite/versioning/t/partition.test b/mysql-test/suite/versioning/t/partition.test
index d026ff4e827..29de10e4738 100644
--- a/mysql-test/suite/versioning/t/partition.test
+++ b/mysql-test/suite/versioning/t/partition.test
@@ -106,6 +106,18 @@ partition by system_time (
partition p0 history,
partition pn current);
+--error ER_PARTITION_WRONG_TYPE
+create or replace table t1 (a int)
+partition by range (a) (
+ partition p0 history,
+ partition p1 current);
+
+--error ER_PARTITION_WRONG_TYPE
+create or replace table t1 (b int)
+partition by range (a) (
+ partition p0 current,
+ partition p1 history);
+
--echo ## ALTER TABLE
diff --git a/sql/partition_info.h b/sql/partition_info.h
index e95daec7d31..287aa6d2200 100644
--- a/sql/partition_info.h
+++ b/sql/partition_info.h
@@ -429,8 +429,13 @@ public:
return NULL;
}
uint next_part_no(uint new_parts) const;
+
+ int gen_part_type(THD *thd, String *str) const;
};
+void part_type_error(THD *thd, partition_info *work_part_info,
+ const char *part_type, partition_info *tab_part_info);
+
uint32 get_next_partition_id_range(struct st_partition_iter* part_iter);
bool check_partition_dirs(partition_info *part_info);
diff --git a/sql/share/errmsg-utf8.txt b/sql/share/errmsg-utf8.txt
index 76da0b8f598..b61bfbfc199 100644
--- a/sql/share/errmsg-utf8.txt
+++ b/sql/share/errmsg-utf8.txt
@@ -9773,9 +9773,9 @@ ER_UNUSED_23
spa "Nunca debería vd de ver esto"
ER_PARTITION_WRONG_TYPE
- chi "错误的分区类型,预期类型:%`s"
- eng "Wrong partitioning type, expected type: %`s"
- spa "Tipo de partición equivocada, tipo esperado: %`s"
+ chi "错误的分区类型,预期类型:%`s for partitioning by %`s"
+ eng "Wrong partition type %`s for partitioning by %`s"
+ spa "Tipo de partición equivocada, tipo esperado: %`s for partitioning by %`s"
WARN_VERS_PART_FULL
chi "版本化表%`s.%`s:partition%`s已满,添加更多历史分区(out of %s)"
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index 6a988596c5f..dbc38552e76 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -9733,6 +9733,7 @@ bool Lex_ident_sys_st::to_size_number(ulonglong *to) const
}
+#ifdef WITH_PARTITION_STORAGE_ENGINE
bool LEX::part_values_current(THD *thd)
{
partition_element *elem= part_info->curr_part_elem;
@@ -9740,7 +9741,7 @@ bool LEX::part_values_current(THD *thd)
{
if (unlikely(part_info->part_type != VERSIONING_PARTITION))
{
- my_error(ER_PARTITION_WRONG_TYPE, MYF(0), "SYSTEM_TIME");
+ part_type_error(thd, NULL, "SYSTEM_TIME", part_info);
return true;
}
}
@@ -9767,7 +9768,7 @@ bool LEX::part_values_history(THD *thd)
{
if (unlikely(part_info->part_type != VERSIONING_PARTITION))
{
- my_error(ER_PARTITION_WRONG_TYPE, MYF(0), "SYSTEM_TIME");
+ part_type_error(thd, NULL, "SYSTEM_TIME", part_info);
return true;
}
}
@@ -9788,6 +9789,7 @@ bool LEX::part_values_history(THD *thd)
elem->type= partition_element::HISTORY;
return false;
}
+#endif /* WITH_PARTITION_STORAGE_ENGINE */
bool LEX::last_field_generated_always_as_row_start_or_end(Lex_ident *p,
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index 6f3467fcd86..c16947edc5a 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -3776,8 +3776,10 @@ public:
bool table_or_sp_used();
bool is_partition_management() const;
+#ifdef WITH_PARTITION_STORAGE_ENGINE
bool part_values_current(THD *thd);
bool part_values_history(THD *thd);
+#endif
/**
@brief check if the statement is a single-level join
diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc
index 5fd9091c58f..d7078278557 100644
--- a/sql/sql_partition.cc
+++ b/sql/sql_partition.cc
@@ -2455,7 +2455,7 @@ end:
@retval != 0 Failure
*/
-static int add_key_with_algorithm(String *str, partition_info *part_info)
+static int add_key_with_algorithm(String *str, const partition_info *part_info)
{
int err= 0;
err+= str->append(STRING_WITH_LEN("KEY "));
@@ -2484,6 +2484,78 @@ char *generate_partition_syntax_for_frm(THD *thd, partition_info *part_info,
return res;
}
+
+/*
+ Generate the partition type syntax from the partition data structure.
+
+ @return Operation status.
+ @retval 0 Success
+ @retval > 0 Failure
+ @retval -1 Fatal error
+*/
+
+int partition_info::gen_part_type(THD *thd, String *str) const
+{
+ int err= 0;
+ switch (part_type)
+ {
+ case RANGE_PARTITION:
+ err+= str->append(STRING_WITH_LEN("RANGE "));
+ break;
+ case LIST_PARTITION:
+ err+= str->append(STRING_WITH_LEN("LIST "));
+ break;
+ case HASH_PARTITION:
+ if (linear_hash_ind)
+ err+= str->append(STRING_WITH_LEN("LINEAR "));
+ if (list_of_part_fields)
+ {
+ err+= add_key_with_algorithm(str, this);
+ err+= add_part_field_list(thd, str, part_field_list);
+ }
+ else
+ err+= str->append(STRING_WITH_LEN("HASH "));
+ break;
+ case VERSIONING_PARTITION:
+ err+= str->append(STRING_WITH_LEN("SYSTEM_TIME "));
+ break;
+ default:
+ DBUG_ASSERT(0);
+ /* We really shouldn't get here, no use in continuing from here */
+ my_error(ER_OUT_OF_RESOURCES, MYF(ME_FATAL));
+ return -1;
+ }
+ return err;
+}
+
+
+void part_type_error(THD *thd, partition_info *work_part_info,
+ const char *part_type,
+ partition_info *tab_part_info)
+{
+ StringBuffer<256> tab_part_type;
+ if (tab_part_info->gen_part_type(thd, &tab_part_type) < 0)
+ return;
+ tab_part_type.length(tab_part_type.length() - 1);
+ if (work_part_info)
+ {
+ DBUG_ASSERT(!part_type);
+ StringBuffer<256> work_part_type;
+ if (work_part_info->gen_part_type(thd, &work_part_type) < 0)
+ return;
+ work_part_type.length(work_part_type.length() - 1);
+ my_error(ER_PARTITION_WRONG_TYPE, MYF(0), work_part_type.c_ptr(),
+ tab_part_type.c_ptr());
+ }
+ else
+ {
+ DBUG_ASSERT(part_type);
+ my_error(ER_PARTITION_WRONG_TYPE, MYF(0), part_type,
+ tab_part_type.c_ptr());
+ }
+}
+
+
/*
Generate the partition syntax from the partition data structure.
Useful for support of generating defaults, SHOW CREATE TABLES
@@ -2527,34 +2599,10 @@ char *generate_partition_syntax(THD *thd, partition_info *part_info,
DBUG_ENTER("generate_partition_syntax");
err+= str.append(STRING_WITH_LEN(" PARTITION BY "));
- switch (part_info->part_type)
- {
- case RANGE_PARTITION:
- err+= str.append(STRING_WITH_LEN("RANGE "));
- break;
- case LIST_PARTITION:
- err+= str.append(STRING_WITH_LEN("LIST "));
- break;
- case HASH_PARTITION:
- if (part_info->linear_hash_ind)
- err+= str.append(STRING_WITH_LEN("LINEAR "));
- if (part_info->list_of_part_fields)
- {
- err+= add_key_with_algorithm(&str, part_info);
- err+= add_part_field_list(thd, &str, part_info->part_field_list);
- }
- else
- err+= str.append(STRING_WITH_LEN("HASH "));
- break;
- case VERSIONING_PARTITION:
- err+= str.append(STRING_WITH_LEN("SYSTEM_TIME "));
- break;
- default:
- DBUG_ASSERT(0);
- /* We really shouldn't get here, no use in continuing from here */
- my_error(ER_OUT_OF_RESOURCES, MYF(ME_FATAL));
- DBUG_RETURN(NULL);
- }
+ int err2= part_info->gen_part_type(thd, &str);
+ if (err2 < 0)
+ DBUG_RETURN(NULL);
+ err+= err2;
if (part_info->part_type == VERSIONING_PARTITION)
{
Vers_part_info *vers_info= part_info->vers_info;
@@ -5051,7 +5099,7 @@ uint prep_alter_part_table(THD *thd, TABLE *table, Alter_info *alter_info,
else if (thd->work_part_info->part_type == VERSIONING_PARTITION ||
tab_part_info->part_type == VERSIONING_PARTITION)
{
- my_error(ER_PARTITION_WRONG_TYPE, MYF(0), "SYSTEM_TIME");
+ part_type_error(thd, thd->work_part_info, NULL, tab_part_info);
}
else
{
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index c58b381460b..8094cc2b358 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -7733,6 +7733,7 @@ void append_drop_column(THD *thd, String *str, Field *field)
}
+#ifdef WITH_PARTITION_STORAGE_ENGINE
static inline
void rename_field_in_list(Create_field *field, List<const char> *field_list)
{
@@ -7745,6 +7746,7 @@ void rename_field_in_list(Create_field *field, List<const char> *field_list)
it.replace(field->field_name.str);
}
}
+#endif
/**
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 7bf3429642b..99c17b5bbf9 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -4815,13 +4815,17 @@ opt_part_values:
part_values_in {}
| CURRENT_SYM
{
+#ifdef WITH_PARTITION_STORAGE_ENGINE
if (Lex->part_values_current(thd))
MYSQL_YYABORT;
+#endif
}
| HISTORY_SYM
{
+#ifdef WITH_PARTITION_STORAGE_ENGINE
if (Lex->part_values_history(thd))
MYSQL_YYABORT;
+#endif
}
| DEFAULT
{