当前位置:网站首页>Compatibility comparison between tidb and MySQL

Compatibility comparison between tidb and MySQL

2022-06-27 06:34:00 Tianxiang shop

  • TiDB Highly compatible MySQL 5.7 agreement 、MySQL 5.7 Common functions and grammar .MySQL 5.7 System tools in Ecology (PHPMyAdmin、Navicat、MySQL Workbench、mysqldump、Mydumper/Myloader)、 Clients and so on are suitable for TiDB.

  • but TiDB Some... Are not yet supported MySQL function , The possible reasons are as follows :

    • There's a better solution , for example JSON replace XML function .
    • At present, the demand for these functions is not high , For example, storing processes and functions .
    • It is difficult to implement some functions on distributed systems .
  • in addition to ,TiDB I won't support it MySQL Copy agreement , However, special tools are provided for MySQL Copy the data

    • from MySQL Copy :TiDB Data Migration (DM)  Yes, it will MySQL/MariaDB Data migration to TiDB Tools for , Can be used for incremental data replication .
    • towards MySQL Copy :TiCDC  It's a pull through TiKV The change log implements TiDB Incremental data synchronization tool , It can be done by  MySQL sink  take TiDB Incremental data is copied to MySQL.

Be careful

This page only covers MySQL And TiDB The overall difference . About Safety features Pessimistic transaction mode For relevant compatibility information, please refer to their specific pages .

Unsupported features

  • Stored procedures and functions
  • trigger
  • event
  • Custom function
  • Foreign key constraints  #18209
  • Full text syntax and indexing  #1793
  • Functions of space type ( namely  GIS/GEOMETRY)、 Data types and indexes  #6347
  • Not  asciilatin1binaryutf8utf8mb4gbk  Character set for
  • SYS schema
  • MySQL Tracking optimizer
  • XML function
  • X-Protocol #1109
  • Savepoints #6840
  • Column level permissions  #9766
  • XA  grammar (TiDB Internal use of two-phase commit , But it didn't pass SQL Interface disclosure )
  • CREATE TABLE tblName AS SELECT stmt  grammar  #4754
  • CHECK TABLE  grammar  #4673
  • CHECKSUM TABLE  grammar  #1895
  • REPAIR TABLE  grammar
  • OPTIMIZE TABLE  grammar
  • HANDLER  sentence
  • CREATE TABLESPACE  sentence

And MySQL A detailed description of the different features

Self increasing ID

  • TiDB The self incrementing column of can guarantee the uniqueness , It can also ensure that in a single TiDB server Self increasing in China , But there is no guarantee that there will be more TiDB server Self increasing in China , Continuity of automatically assigned values is not guaranteed . Mixing default values with custom values is not recommended , If mixed, you may receive  Duplicated Error  Error messages for .

  • TiDB It can be done by  tidb_allow_remove_auto_inc  The system variable turns on or off... That allows columns to be removed  AUTO_INCREMENT  attribute . The syntax for deleting column attributes is :ALTER TABLE MODIFY  or  ALTER TABLE CHANGE.

  • TiDB Adding columns is not supported  AUTO_INCREMENT  attribute , After removing this attribute, it cannot be recovered .

Self increasing ID For details, please refer to  AUTO_INCREMENT.

Be careful

If no primary key is specified when creating a table ,TiDB Will use  _tidb_rowid  To identify lines , This value will be allocated and auto incremented ( If it exists ) Share one distributor . If the auto increment column is specified as the primary key , be TiDB This column will be used to identify rows . So there are the following example cases :

mysql> CREATE TABLE t(id INT UNIQUE KEY AUTO_INCREMENT); Query OK, 0 rows affected (0.05 sec) mysql> INSERT INTO t VALUES(),(),(); Query OK, 3 rows affected (0.00 sec) Records: 3 Duplicates: 0 Warnings: 0 mysql> SELECT _tidb_rowid, id FROM t; +-------------+------+ | _tidb_rowid | id | +-------------+------+ | 4 | 1 | | 5 | 2 | | 6 | 3 | +-------------+------+ 3 rows in set (0.01 sec)

Be careful

Use  AUTO_INCREMENT  It may bring hot issues to the production environment , Therefore, it is recommended to use  AUTO_RANDOM  Instead of . Please refer to  TiDB Dealing with hot issues .

Performance schema

TiDB The main use of Prometheus and Grafana To store and query relevant performance monitoring indicators , therefore Performance schema Some tables are empty .

Query plan

EXPLAIN/EXPLAIN FOR  Output format 、 Content 、 Permission settings and MySQL There is a big difference , See understand TiDB Implementation plan .

Built-in functions

Support common MySQL Built-in functions , Some functions do not support . Can be carried out by  SHOW BUILTINS  Statement to view available built-in functions . Reference resources  SQL Grammar documents .

DDL The limitation of

TiDB in , All those who support DDL Changes are performed online . And MySQL comparison ,TiDB Medium DDL There are the following limitations :

  • Not in a single line  ALTER TABLE  Statement . for example , You cannot add multiple columns or indexes to a single statement , otherwise , It may output  Unsupported multi schema change  Error of .

  • ALTER TABLE  A few types of changes are not supported . such as ,TiDB No support from  DECIMAL  To  DATE  Changes . When an unsupported type change is encountered ,TiDB Will report  Unsupported modify column: type %d not match origin %d  Error of . For more details , Please refer to  ALTER TABLE.

  • TiDB in ,ALGORITHM={INSTANT,INPLACE,COPY}  Syntax is only used as a way to specify , Do not change  ALTER  Algorithm , For details, please refer to  ALTER TABLE.

  • Adding or deleting... Is not supported  CLUSTERED  Primary key of type . To learn about  CLUSTERED  Details of the primary key , Please refer to Cluster index .

  • Specifying different types of indexes... Is not supported (HASH|BTREE|RTREE|FULLTEXT). If different types of indexes are specified ,TiDB These indexes are parsed and ignored .

  • Partition table support  HASHRANGE  and  LIST  Partition type . For unsupported partition types ,TiDB May report  Warning: Unsupported partition type %s, treat as normal table  error , among  %s  Is a specific partition type that is not supported .

  • Partition tables also support  ADDDROPTRUNCATE  operation . Other partition operations are ignored .TiDB The following partition table syntax is not supported :

    • PARTITION BY KEY
    • SUBPARTITION
    • {CHECK|TRUNCATE|OPTIMIZE|REPAIR|IMPORT|DISCARD|REBUILD|REORGANIZE|COALESCE} PARTITION

    For more details , Please refer to Partition table document .

ANALYZE TABLE

TiDB Medium Information Statistics And MySQL There's a difference in :TiDB The information statistics in will completely reconstruct the statistics of the table , The statement execution process is long , But in MySQL/InnoDB in , It is a lightweight statement , The execution process is short .

For more information on statistical differences, see  ANALYZE TABLE.

SELECT  The limitation of

  • I won't support it  SELECT ... INTO @ Variable   grammar .
  • I won't support it  SELECT ... GROUP BY ... WITH ROLLUP  grammar .
  • TiDB Medium  SELECT .. GROUP BY expr  The return result of and MySQL 5.7 Don't agree with each other .MySQL 5.7 The result is equivalent to  GROUP BY expr ORDER BY expr.

For details, see  SELECT.

UPDATE  sentence

For details, see  UPDATE.

View

TiDB Views in are not updatable , I won't support it  UPDATEINSERTDELETE  Wait for write operation .

A temporary table

See  TiDB Local temporary tables and MySQL Compatibility of temporary tables .

Character set and collation

Storage engine

  • Specify the storage engine only if it is syntactically compatible when creating tables , actually TiDB The meta information will be uniformly described as InnoDB Storage engine .TiDB Support similar MySQL Storage engine abstraction , But it needs to be passed when the system is started  --store  Configuration item to specify the storage engine .

SQL Pattern

TiDB Support most  SQL Pattern . Don't support SQL The pattern is as follows :

  • Compatibility mode is not supported , for example :Oracle  and  PostgreSQL(TiDB Resolve but ignore these two compatibility modes ),MySQL 5.7 Compatibility mode deprecated ,MySQL 8.0 Compatibility mode removed .
  • TiDB Of  ONLY_FULL_GROUP_BY  Patterns and MySQL 5.7 There are subtle Semantic difference .
  • NO_DIR_IN_CREATE  and  NO_ENGINE_SUBSTITUTION  It is only used to solve problems related to MySQL Compatibility problem , It doesn't apply to TiDB.

default setting

  • Character set :

    • TiDB Default :utf8mb4.
    • MySQL 5.7 Default :latin1.
    • MySQL 8.0 Default :utf8mb4.
  • Sort rule :

    • TiDB in  utf8mb4  Character set default :utf8mb4_bin.
    • MySQL 5.7 in  utf8mb4  Character set default :utf8mb4_general_ci.
    • MySQL 8.0 in  utf8mb4  Character set default :utf8mb4_0900_ai_ci.
  • foreign_key_checks

    • TiDB Default :OFF, It only supports setting this value to  OFF.
    • MySQL 5.7 Default :ON.
  • SQL mode:

    • TiDB Default :ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION.
    • MySQL 5.7 Default and TiDB identical .
    • MySQL 8.0 Default  ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION.
  • lower_case_table_names

    • TiDB Default :2, It only supports setting this value to  2.
    • MySQL The default is as follows :
      • Linux The value in the system is  0
      • Windows The value in the system is  1
      • macOS The value in the system is  2
  • explicit_defaults_for_timestamp

    • TiDB Default :ON, It only supports setting this value to  ON.
    • MySQL 5.7 Default :OFF.
    • MySQL 8.0 Default :ON.

The difference between date and time processing

The time zone

  • TiDB All time zone rules currently installed in the system are used for calculation ( It's usually  tzdata  package ), All time zone names can be used without importing time zone table data , Calculation rules cannot be modified by importing time zone table data .

  • MySQL Local time zone is used by default , It depends on the current time zone rules built into the system ( For example, when does daylight saving time begin ) Calculate ; And before Import time zone table data The time zone cannot be specified by the time zone name .

Type system

  • I won't support it FLOAT4/FLOAT8.

  • I won't support it  SQL_TSI_*( Include  SQL_TSI_MONTHSQL_TSI_WEEKSQL_TSI_DAYSQL_TSI_HOURSQL_TSI_MINUTE  and  SQL_TSI_SECOND, But does not include  SQL_TSI_YEAR).

MySQL Incompatibilities caused by deprecated features

TiDB I won't support it MySQL Features marked as deprecated in , Include :

  • Specify the precision of the floating point type .MySQL 8.0  Abandoning With this function , It is suggested to use it instead  DECIMAL  type .
  • ZEROFILL  attribute . MySQL 8.0  Abandoning With this function , It is recommended to fill in digital values in business applications .
原网站

版权声明
本文为[Tianxiang shop]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/178/202206270608219333.html