Skip to content

Commit e7d1522

Browse files
committed
MDEV-13089 identifier quoting in partitioning
cover ALTER TABLE
1 parent e4b466a commit e7d1522

File tree

6 files changed

+28
-25
lines changed

6 files changed

+28
-25
lines changed

mysql-test/suite/parts/r/show_create.result

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,5 @@ alter table t1 add partition (partition p1 values less than (10));
109109
set sql_mode= default;
110110
show table status;
111111
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment
112-
t1 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '"p0" VALUES LESS THAN (5) ENGINE = MyISAM,
113-
PARTITION "p1" VALUES LESS THAN (10)' at line 2
114-
Warnings:
115-
Warning 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '"p0" VALUES LESS THAN (5) ENGINE = MyISAM,
116-
PARTITION "p1" VALUES LESS THAN (10)' at line 2
112+
t1 MyISAM 10 Fixed 0 0 0 0 2048 0 NULL X X NULL latin1_swedish_ci NULL partitioned
117113
drop table t1;

mysql-test/suite/parts/t/show_create.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,6 @@ create table t1 (a int) partition by range(a) (partition p0 values less than (5)
4747
set sql_mode='ansi_quotes';
4848
alter table t1 add partition (partition p1 values less than (10));
4949
set sql_mode= default;
50+
--replace_column 12 X 13 X
5051
show table status;
5152
drop table t1;

sql/ha_partition.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9092,11 +9092,9 @@ int ha_partition::check_for_upgrade(HA_CHECK_OPT *check_opt)
90929092
}
90939093
m_part_info->key_algorithm= partition_info::KEY_ALGORITHM_51;
90949094
if (skip_generation ||
9095-
!(part_buf= generate_partition_syntax(thd, m_part_info,
9095+
!(part_buf= generate_partition_syntax_for_frm(thd, m_part_info,
90969096
&part_buf_len,
9097-
true,
9098-
NULL,
9099-
NULL)) ||
9097+
NULL, NULL)) ||
91009098
print_admin_msg(thd, SQL_ADMIN_MSG_TEXT_SIZE + 1, "error",
91019099
table_share->db.str,
91029100
table->alias,

sql/sql_partition.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2219,6 +2219,18 @@ static int add_key_with_algorithm(String *str, partition_info *part_info)
22192219
return err;
22202220
}
22212221

2222+
char *generate_partition_syntax_for_frm(THD *thd, partition_info *part_info,
2223+
uint *buf_length,
2224+
HA_CREATE_INFO *create_info,
2225+
Alter_info *alter_info)
2226+
{
2227+
sql_mode_t old_mode= thd->variables.sql_mode;
2228+
thd->variables.sql_mode &= ~MODE_ANSI_QUOTES;
2229+
char *res= generate_partition_syntax(thd, part_info, buf_length,
2230+
true, create_info, alter_info);
2231+
thd->variables.sql_mode= old_mode;
2232+
return res;
2233+
}
22222234

22232235
/*
22242236
Generate the partition syntax from the partition data structure.

sql/sql_partition.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,10 @@ char *generate_partition_syntax(THD *thd, partition_info *part_info,
272272
bool show_partition_options,
273273
HA_CREATE_INFO *create_info,
274274
Alter_info *alter_info);
275+
char *generate_partition_syntax_for_frm(THD *thd, partition_info *part_info,
276+
uint *buf_length,
277+
HA_CREATE_INFO *create_info,
278+
Alter_info *alter_info);
275279
bool verify_data_with_partition(TABLE *table, TABLE *part_table,
276280
uint32 part_id);
277281
bool compare_partition_options(HA_CREATE_INFO *table_create_info,

sql/sql_table.cc

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#include "strfunc.h" // find_type2, find_set
3131
#include "sql_truncate.h" // regenerate_locked_table
3232
#include "sql_partition.h" // mem_alloc_error,
33-
// generate_partition_syntax,
3433
// partition_info
3534
// NOT_A_PARTITION_ID
3635
#include "sql_db.h" // load_db_opt_by_name
@@ -1820,13 +1819,10 @@ bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags)
18201819
partition_info *part_info= lpt->table->part_info;
18211820
if (part_info)
18221821
{
1823-
if (!(part_syntax_buf= generate_partition_syntax(lpt->thd, part_info,
1824-
&syntax_len, TRUE,
1825-
lpt->create_info,
1826-
lpt->alter_info)))
1827-
{
1822+
part_syntax_buf= generate_partition_syntax_for_frm(lpt->thd, part_info,
1823+
&syntax_len, lpt->create_info, lpt->alter_info);
1824+
if (!part_syntax_buf)
18281825
DBUG_RETURN(TRUE);
1829-
}
18301826
part_info->part_info_string= part_syntax_buf;
18311827
part_info->part_info_len= syntax_len;
18321828
}
@@ -1902,10 +1898,9 @@ bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags)
19021898
{
19031899
TABLE_SHARE *share= lpt->table->s;
19041900
char *tmp_part_syntax_str;
1905-
if (!(part_syntax_buf= generate_partition_syntax(lpt->thd, part_info,
1906-
&syntax_len, TRUE,
1907-
lpt->create_info,
1908-
lpt->alter_info)))
1901+
part_syntax_buf= generate_partition_syntax_for_frm(lpt->thd,
1902+
part_info, &syntax_len, lpt->create_info, lpt->alter_info);
1903+
if (!part_syntax_buf)
19091904
{
19101905
error= 1;
19111906
goto err;
@@ -4564,11 +4559,8 @@ handler *mysql_create_frm_image(THD *thd,
45644559
We reverse the partitioning parser and generate a standard format
45654560
for syntax stored in frm file.
45664561
*/
4567-
sql_mode_t old_mode= thd->variables.sql_mode;
4568-
thd->variables.sql_mode &= ~MODE_ANSI_QUOTES;
4569-
part_syntax_buf= generate_partition_syntax(thd, part_info, &syntax_len,
4570-
true, create_info, alter_info);
4571-
thd->variables.sql_mode= old_mode;
4562+
part_syntax_buf= generate_partition_syntax_for_frm(thd, part_info,
4563+
&syntax_len, create_info, alter_info);
45724564
if (!part_syntax_buf)
45734565
goto err;
45744566
part_info->part_info_string= part_syntax_buf;

0 commit comments

Comments
 (0)