[MDEV-29495] Generalize can_convert_xxx() hook engine API to cover any arbitrary data type Created: 2022-09-08  Updated: 2023-03-30  Resolved: 2022-10-27

Status: Closed
Project: MariaDB Server
Component/s: Data Definition - Alter Table, Data types
Fix Version/s: 10.4.28, 10.5.19, 10.6.12, 10.7.8, 10.8.7, 10.9.5, 10.10.3

Type: Task Priority: Major
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Blocks
blocks MDEV-30969 Some ALGORITHM=INSTANT checks are mis... Open
Relates
relates to MDEV-20704 An index on a double column erroneous... Closed
relates to MDEV-28727 ALTER TABLE ALGORITHM=NOCOPY does not... Closed
relates to MDEV-28822 Table from older version requires tab... Closed
relates to MDEV-29481 mariadb-upgrade prints confusing stat... Closed

 Description   

The engine API have hooks to let the engine decide if it can perform ALGORITHM=NOCOPY for a minor data type change.
Originally they were implemented to handle ALTER changing a column character set from CHARACTER SET utf8mb3 to CHARACTER SET utf8mb4 without having to rebuild the table:

CREATE TABLE t1 (a TEXT CHARACTER SET utf8mb3) ENGINE=InnoDB;
INSERT INTO t1 VALUES ('test');
ALTER TABLE t1 MODIFY a TEXT CHARACTER SET utf8mb4;

The above ALTER does not rebuild the table, it only modifies the FRM file.

The hooks that we have so far can handle only string data types. They are implemented in these "class handler" methods, overridden by ha_innodb:

  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;
  }

In order to fix MDEV-29481, we may need a hook for the DOUBLE data type.
It's not desirable to add a new "can_convert_double()" method.

Let's remove the above three virtual methods and add one method which can handle any arbitrary data type:

  virtual bool can_convert_nocopy(const Field &,
                                  const Column_definition &) const
  {
    return false;
  }



 Comments   
Comment by Alexander Barkov [ 2022-10-27 ]

Hi marko,
can you please review a patch:
https://github.com/MariaDB/server/commit/21e18c94c0214a23396b736c4d58e066832cd0a1
Thanks!

Comment by Marko Mäkelä [ 2022-10-27 ]

Thank you, this corresponds to what we discussed earlier. Looks OK to me.

Generated at Thu Feb 08 10:09:02 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.