Skip to content

Commit b195b8b

Browse files
committed
MDEV-34033 Exchange partition with virtual columns fails
Extend Item::Eq_config with omit_table_names parameter to compare without table names in Item_field::eq. Tests are re-applied from commit 0cf2176.
1 parent d4f3569 commit b195b8b

File tree

6 files changed

+67
-9
lines changed

6 files changed

+67
-9
lines changed

mysql-test/main/partition_exchange.result

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,6 +1250,28 @@ ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2;
12501250
ERROR HY000: Tables have different definitions
12511251
DROP TABLE t1, t2;
12521252
#
1253+
# MDEV-34033 Exchange partition with virtual columns fails
1254+
#
1255+
create or replace table t1(
1256+
id int primary key,
1257+
col1 int,
1258+
col2 boolean as (col1 is null))
1259+
partition by list (id) ( partition p1 values in (1)
1260+
);
1261+
create or replace table t1_working like t1;
1262+
alter table t1_working remove partitioning;
1263+
alter table t1 exchange partition p1 with table t1_working;
1264+
create or replace table t2(
1265+
id int primary key,
1266+
col1 int,
1267+
col2 boolean as (true))
1268+
partition by list (id) ( partition p1 values in (1)
1269+
);
1270+
create or replace table t2_working like t2;
1271+
alter table t2_working remove partitioning;
1272+
alter table t2 exchange partition p1 with table t2_working;
1273+
drop tables t1, t1_working, t2, t2_working;
1274+
#
12531275
# MDEV-35612 EXCHANGE PARTITION does not work for tables with unique blobs
12541276
#
12551277
create table t (a int, b text, unique (b), unique(a, b)) partition by list (a) (partition p0 values in (1,2), partition pdef default);

mysql-test/main/partition_exchange.test

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,38 @@ ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2;
552552
# Cleanup
553553
DROP TABLE t1, t2;
554554

555+
--echo #
556+
--echo # MDEV-34033 Exchange partition with virtual columns fails
557+
--echo #
558+
# this fails when the virtual persistent column
559+
# references another column
560+
create or replace table t1(
561+
id int primary key,
562+
col1 int,
563+
col2 boolean as (col1 is null))
564+
partition by list (id) ( partition p1 values in (1)
565+
);
566+
567+
create or replace table t1_working like t1;
568+
alter table t1_working remove partitioning;
569+
alter table t1 exchange partition p1 with table t1_working;
570+
571+
# this works when the virtual persistent column
572+
# does not reference another column
573+
create or replace table t2(
574+
id int primary key,
575+
col1 int,
576+
col2 boolean as (true))
577+
partition by list (id) ( partition p1 values in (1)
578+
);
579+
580+
create or replace table t2_working like t2;
581+
alter table t2_working remove partitioning;
582+
alter table t2 exchange partition p1 with table t2_working;
583+
584+
# Cleanup
585+
drop tables t1, t1_working, t2, t2_working;
586+
555587
--echo #
556588
--echo # MDEV-35612 EXCHANGE PARTITION does not work for tables with unique blobs
557589
--echo #

sql/field.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ class Virtual_column_info: public Sql_alloc,
659659
bool cleanup_session_expr();
660660
bool fix_and_check_expr(THD *thd, TABLE *table);
661661
bool check_access(THD *thd);
662-
inline bool is_equal(const Virtual_column_info* vcol) const;
662+
inline bool is_equal(const Virtual_column_info* vcol, bool cmp_names) const;
663663
inline void print(String*);
664664
};
665665

sql/item.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3557,7 +3557,7 @@ bool Item_field::eq(const Item *item, const Eq_config &config) const
35573557
return 0;
35583558

35593559
Item_field *item_field= (Item_field*) real_item2;
3560-
if (item_field->field && field)
3560+
if (!config.omit_table_names && item_field->field && field)
35613561
return item_field->field == field;
35623562
/*
35633563
We may come here when we are trying to find a function in a GROUP BY
@@ -3571,12 +3571,13 @@ bool Item_field::eq(const Item *item, const Eq_config &config) const
35713571
*/
35723572
return (!lex_string_cmp(system_charset_info, &item_field->name,
35733573
&field_name) &&
3574-
(!item_field->table_name.str || !table_name.str ||
3574+
(config.omit_table_names ||
3575+
(!item_field->table_name.str || !table_name.str ||
35753576
(!my_strcasecmp(table_alias_charset, item_field->table_name.str,
35763577
table_name.str) &&
35773578
(!item_field->db_name.str || !db_name.str ||
35783579
(item_field->db_name.str && !strcmp(item_field->db_name.str,
3579-
db_name.str))))));
3580+
db_name.str)))))));
35803581
}
35813582

35823583

sql/item.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,7 +1274,9 @@ class Item :public Value_source,
12741274
struct Eq_config
12751275
{
12761276
bool binary_cmp; /**< Make binary comparison */
1277-
Eq_config(bool binary_cmp) : binary_cmp(binary_cmp) {}
1277+
bool omit_table_names; /**< Skip table and db names comparison */
1278+
Eq_config(bool binary_cmp, bool omit_table_names= false)
1279+
: binary_cmp(binary_cmp), omit_table_names(omit_table_names) {}
12781280
};
12791281
virtual bool eq(const Item *, const Eq_config &config) const;
12801282
enum_field_types field_type() const
@@ -8183,11 +8185,12 @@ bool fix_escape_item(THD *thd, Item *escape_item, String *tmp_str,
81838185
bool escape_used_in_parsing, CHARSET_INFO *cmp_cs,
81848186
int *escape);
81858187

8186-
inline bool Virtual_column_info::is_equal(const Virtual_column_info* vcol) const
8188+
inline bool Virtual_column_info::is_equal(const Virtual_column_info* vcol,
8189+
bool omit_table_names) const
81878190
{
81888191
return type_handler() == vcol->type_handler()
81898192
&& stored_in_db == vcol->is_stored()
8190-
&& expr->eq(vcol->expr, true);
8193+
&& expr->eq(vcol->expr, {true, omit_table_names});
81918194
}
81928195

81938196
inline void Virtual_column_info::print(String* str)

sql/sql_table.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7048,7 +7048,7 @@ static bool fill_alter_inplace_info(THD *thd, TABLE *table,
70487048
alter_expr= ALTER_STORED_GCOL_EXPR;
70497049
else
70507050
alter_expr= ALTER_VIRTUAL_GCOL_EXPR;
7051-
if (!field->vcol_info->is_equal(new_field->vcol_info))
7051+
if (!field->vcol_info->is_equal(new_field->vcol_info, false))
70527052
{
70537053
ha_alter_info->handler_flags|= alter_expr;
70547054
value_changes= true;
@@ -7522,7 +7522,7 @@ bool mysql_compare_tables(TABLE *table, Alter_info *alter_info,
75227522
{
75237523
if (!tmp_new_field->field->vcol_info)
75247524
DBUG_RETURN(false);
7525-
if (!field->vcol_info->is_equal(tmp_new_field->field->vcol_info))
7525+
if (!field->vcol_info->is_equal(tmp_new_field->field->vcol_info, true))
75267526
DBUG_RETURN(false);
75277527
}
75287528

0 commit comments

Comments
 (0)