• Mats Kindahl's avatar
    WL#5151: Conversion between different types when replicating · 2ef051a8
    Mats Kindahl authored
    Row-based replication requires the types of columns on the
    master and slave to be approximately the same (some safe
    conversions between strings are allowed), but does not
    allow safe conversions between fields of similar types such
    as TINYINT and INT.
    
    This patch implement type conversions between similar fields
    on the master and slave.
    
    The conversions are controlled using a new variable
    SLAVE_TYPE_CONVERSIONS of type SET('ALL_LOSSY','ALL_NON_LOSSY').
    
    Non-lossy conversions are any conversions that do not run the
    risk of losing any information, while lossy conversions can
    potentially truncate the value. The column definitions are
    checked to decide if the conversion is acceptable.
    
    If neither conversion is enabled, it is required that the
    definitions of the columns are identical on master and slave.
    
    Conversion is done by creating an internal conversion table,
    unpacking the master data into it, and then copy the data to
    the real table on the slave.
    
    .bzrignore:
      New files added
    client/Makefile.am:
      New files added
    client/mysqlbinlog.cc:
      Functions in rpl_utility.cc is now needed by mysqlbinlog.cc.
    libmysqld/Makefile.am:
      New files added
    mysql-test/extra/rpl_tests/check_type.inc:
      Test include file to check a single type conversion.
    mysql-test/extra/rpl_tests/rpl_extraSlave_Col.test:
      Switching to use INT instead of TEXT for column that should not have matching types.
    mysql-test/extra/rpl_tests/rpl_row_basic.test:
      Adding code to enable type conversions for BIT tests since InnoDB
      cannot handle them properly due to incorrect information stored as
      metadata.
    mysql-test/extra/rpl_tests/type_conversions.test:
      Test file to check a set of type conversions
      with current settings of slave_type_conversions.
    mysql-test/suite/rpl/t/rpl_typeconv.test:
      Test file to test conversions from master to slave with
      all possible values for slave_type_conversions.
      
      The test also checks that the slave_type_conversions
      variable works as expected.
    sql/field.cc:
      Changing definition of compatible_field_size to both check if 
      two field with identical base types are compatible and give an
      order between them if they are compatible.
      
      This only implement checking on the slave, so it will not affect
      replication from an old master to a new slave.
    sql/field.h:
      Changing prototypes for functions:
      - compatible_field_size()
      - init_for_tmp_table()
      - row_pack_length()
    sql/log_event.cc:
      Changing compability checks to build a conversion table if the fields
      are compatible, but does not have the same base type.
    sql/log_event_old.cc:
      Changing compability checks to build a conversion table if the fields
      are compatible, but does not have the same base type.
    sql/mysql_priv.h:
      Adding global option variable for SLAVE_TYPE_CONVERSIONS
    sql/mysqld.cc:
      Adding SLAVE_TYPE_CONVERSIONS global server variable.
    sql/rpl_record.cc:
      Changing unpack_row to use the conversion table if present.
    sql/rpl_rli.h:
      Removing function get_tabledef and replacing it with get_table_data().
      This function retrieve data for table opened for replication, not just
      table definition.
    sql/rpl_utility.cc:
      Function table_def::compatible_with is changed to compare table on master
      and slave for compatibility and generate a conversions table if they are
      compatible.
      
      Computing real type of fields from metadata for ENUM and SET types.
      Computing pack_length correctly for ENUM, SET, and BLOB types.
      
      Adding optimization to not check compatibility if no
      slave type conversions are enabled.
    sql/rpl_utility.h:
      Changing prototypes since implementation has changed.
      
      Modifying table_def::type() to return real type instead of stored type.
    sql/set_var.cc:
      Adding SLAVE_TYPE_CONVERSIONS variable.
    sql/set_var.h:
      Adding SLAVE_TYPE_CONVERSIONS variable.
    sql/share/errmsg.txt:
      Adding error messages for slave type conversions.
    sql/sql_class.h:
      Adding SLAVE_TYPE_CONVERSIONS variable.
    sql/sql_select.cc:
      Correcting create_virtual_tmp_table() to compute null bit positions
      correctly in the presence of bit fields.
    2ef051a8
rpl_row_basic_2myisam.result 17.6 KB