summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sql/field.h22
-rw-r--r--sql/ha_partition.cc31
-rw-r--r--sql/ha_partition.h12
-rw-r--r--sql/handler.h19
-rw-r--r--sql/sql_table.cc2
-rw-r--r--storage/innobase/handler/ha_innodb.cc22
-rw-r--r--storage/innobase/handler/ha_innodb.h22
7 files changed, 43 insertions, 87 deletions
diff --git a/sql/field.h b/sql/field.h
index 9d40caf0932..40ff99a5b2e 100644
--- a/sql/field.h
+++ b/sql/field.h
@@ -1552,12 +1552,6 @@ public:
Used by the ALTER TABLE
*/
virtual bool is_equal(const Column_definition &new_field) const= 0;
- // Used as double dispatch pattern: calls virtual method of handler
- virtual bool
- can_be_converted_by_engine(const Column_definition &new_type) const
- {
- return false;
- }
/* convert decimal to longlong with overflow check */
longlong convert_decimal2longlong(const my_decimal *val, bool unsigned_flag,
int *err);
@@ -3621,10 +3615,6 @@ public:
void sql_type(String &str) const;
void sql_rpl_type(String*) const;
bool is_equal(const Column_definition &new_field) const;
- bool can_be_converted_by_engine(const Column_definition &new_type) const
- {
- return table->file->can_convert_string(this, new_type);
- }
virtual uchar *pack(uchar *to, const uchar *from,
uint max_length);
virtual const uchar *unpack(uchar* to, const uchar *from,
@@ -3751,10 +3741,6 @@ public:
uchar *new_ptr, uint32 length,
uchar *new_null_ptr, uint new_null_bit);
bool is_equal(const Column_definition &new_field) const;
- bool can_be_converted_by_engine(const Column_definition &new_type) const
- {
- return table->file->can_convert_varstring(this, new_type);
- }
void hash(ulong *nr, ulong *nr2);
uint length_size() const { return length_bytes; }
void print_key_value(String *out, uint32 length);
@@ -4128,10 +4114,6 @@ public:
uint32 char_length() const;
uint32 character_octet_length() const;
bool is_equal(const Column_definition &new_field) const;
- bool can_be_converted_by_engine(const Column_definition &new_type) const
- {
- return table->file->can_convert_blob(this, new_type);
- }
void print_key_value(String *out, uint32 length);
friend void TABLE::remember_blob_values(String *blob_storage);
@@ -4247,10 +4229,6 @@ public:
!table->copy_blobs;
}
bool is_equal(const Column_definition &new_field) const;
- bool can_be_converted_by_engine(const Column_definition &new_type) const
- {
- return table->file->can_convert_geom(this, new_type);
- }
int store(const char *to, size_t length, CHARSET_INFO *charset);
int store(double nr);
diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc
index 18a8cd5e027..06ae329ee3a 100644
--- a/sql/ha_partition.cc
+++ b/sql/ha_partition.cc
@@ -1,6 +1,6 @@
/*
Copyright (c) 2005, 2019, Oracle and/or its affiliates.
- Copyright (c) 2009, 2021, MariaDB
+ Copyright (c) 2009, 2022, MariaDB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -12021,35 +12021,12 @@ void ha_partition::clear_top_table_fields()
}
bool
-ha_partition::can_convert_string(const Field_string* field,
- const Column_definition& new_type) const
+ha_partition::can_convert_nocopy(const Field &field,
+ const Column_definition &new_type) const
{
for (uint index= 0; index < m_tot_parts; index++)
{
- if (!m_file[index]->can_convert_string(field, new_type))
- return false;
- }
- return true;
-}
-
-bool
-ha_partition::can_convert_varstring(const Field_varstring* field,
- const Column_definition& new_type) const{
- for (uint index= 0; index < m_tot_parts; index++)
- {
- if (!m_file[index]->can_convert_varstring(field, new_type))
- return false;
- }
- return true;
-}
-
-bool
-ha_partition::can_convert_blob(const Field_blob* field,
- const Column_definition& new_type) const
-{
- for (uint index= 0; index < m_tot_parts; index++)
- {
- if (!m_file[index]->can_convert_blob(field, new_type))
+ if (!m_file[index]->can_convert_nocopy(field, new_type))
return false;
}
return true;
diff --git a/sql/ha_partition.h b/sql/ha_partition.h
index 507db9efddf..2670784c759 100644
--- a/sql/ha_partition.h
+++ b/sql/ha_partition.h
@@ -1624,16 +1624,8 @@ public:
friend int cmp_key_rowid_part_id(void *ptr, uchar *ref1, uchar *ref2);
friend int cmp_key_part_id(void *key_p, uchar *ref1, uchar *ref2);
- bool can_convert_string(
- const Field_string* field,
- const Column_definition& new_field) const override;
- bool can_convert_varstring(
- const Field_varstring* field,
- const Column_definition& new_field) const override;
-
- bool can_convert_blob(
- const Field_blob* field,
- const Column_definition& new_field) const override;
+ bool can_convert_nocopy(const Field &field,
+ const Column_definition &new_field) const override;
};
#endif /* HA_PARTITION_INCLUDED */
diff --git a/sql/handler.h b/sql/handler.h
index aa68c30480e..541c408178b 100644
--- a/sql/handler.h
+++ b/sql/handler.h
@@ -4851,23 +4851,8 @@ public:
These functions check for such possibility.
Implementation could be based on Field_xxx::is_equal()
*/
- virtual bool can_convert_string(const Field_string *field,
- const Column_definition &new_type) const
- {
- return false;
- }
- virtual bool can_convert_varstring(const Field_varstring *field,
- const Column_definition &new_type) const
- {
- return false;
- }
- virtual bool can_convert_blob(const Field_blob *field,
- const Column_definition &new_type) const
- {
- return false;
- }
- virtual bool can_convert_geom(const Field_geom *field,
- const Column_definition &new_type) const
+ virtual bool can_convert_nocopy(const Field &,
+ const Column_definition &) const
{
return false;
}
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index efa5c06dd2a..63289e3ba59 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -6948,7 +6948,7 @@ static bool fill_alter_inplace_info(THD *thd, TABLE *table, bool varchar,
bool is_equal= field->is_equal(*new_field);
if (!is_equal)
{
- if (field->can_be_converted_by_engine(*new_field))
+ if (field->table->file->can_convert_nocopy(*field, *new_field))
{
/*
New column type differs from the old one, but storage engine can
diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc
index 3fa2a0c4d30..7acbe79d732 100644
--- a/storage/innobase/handler/ha_innodb.cc
+++ b/storage/innobase/handler/ha_innodb.cc
@@ -21159,6 +21159,26 @@ bool ha_innobase::can_convert_blob(const Field_blob *field,
return true;
}
+
+bool ha_innobase::can_convert_nocopy(const Field &field,
+ const Column_definition &new_type) const
+{
+ if (const Field_string *tf= dynamic_cast<const Field_string *>(&field))
+ return can_convert_string(tf, new_type);
+
+ if (const Field_varstring *tf= dynamic_cast<const Field_varstring *>(&field))
+ return can_convert_varstring(tf, new_type);
+
+ if (dynamic_cast<const Field_geom *>(&field))
+ return false;
+
+ if (const Field_blob *tf= dynamic_cast<const Field_blob *>(&field))
+ return can_convert_blob(tf, new_type);
+
+ return false;
+}
+
+
Compare_keys ha_innobase::compare_key_parts(
const Field &old_field, const Column_definition &new_field,
const KEY_PART_INFO &old_part, const KEY_PART_INFO &new_part) const
@@ -21169,7 +21189,7 @@ Compare_keys ha_innobase::compare_key_parts(
if (!is_equal)
{
- if (!old_field.can_be_converted_by_engine(new_field))
+ if (!old_field.table->file->can_convert_nocopy(old_field, new_field))
return Compare_keys::NotEqual;
if (!Charset(old_cs).eq_collation_specific_names(new_cs))
diff --git a/storage/innobase/handler/ha_innodb.h b/storage/innobase/handler/ha_innodb.h
index 97f62f4b398..b5f9438921c 100644
--- a/storage/innobase/handler/ha_innodb.h
+++ b/storage/innobase/handler/ha_innodb.h
@@ -419,15 +419,9 @@ public:
@retval false if pushed (always) */
bool rowid_filter_push(Rowid_filter *rowid_filter) override;
- bool
- can_convert_string(const Field_string* field,
- const Column_definition& new_field) const override;
- bool can_convert_varstring(
- const Field_varstring* field,
- const Column_definition& new_field) const override;
- bool
- can_convert_blob(const Field_blob* field,
- const Column_definition& new_field) const override;
+ bool can_convert_nocopy(const Field &field,
+ const Column_definition& new_field) const
+ override;
/** @return whether innodb_strict_mode is active */
static bool is_innodb_strict_mode(THD* thd);
@@ -442,6 +436,16 @@ public:
const KEY_PART_INFO& new_part) const override;
protected:
+ bool
+ can_convert_string(const Field_string* field,
+ const Column_definition& new_field) const;
+ bool can_convert_varstring(
+ const Field_varstring* field,
+ const Column_definition& new_field) const;
+ bool
+ can_convert_blob(const Field_blob* field,
+ const Column_definition& new_field) const;
+
dberr_t innobase_get_autoinc(ulonglong* value);
dberr_t innobase_lock_autoinc();
ulonglong innobase_peek_autoinc();