摘要:

      继上一篇的文章 MySQL5.6 针对 MySQL5.5 各个方面又提升了很多,特别在性能和一些新参数上面,现在看看大致提升了哪些方面(后续不定时更新)。

一:性能、功能上的提升。

在线DDL即 online DDL,日常的增删字段和索引都不会出现问题,但还是有很多操作不支持完全的在线DDL,包括增加一个全文索引,修改列的数据类型,删除一个主键,修改表的字符集等,其中主键可以通过自己指定的方式进行操作,操作方式有2种:algorithm=inplace|copy 。也可以看官方的例子

dba@192.168.200.59 : dchat_main 05:44:54>alter table messages_tt add primary key(m_id),algorithm=inplace;
Query OK, 0 rows affected (26.59 sec)
Records: 0  Duplicates: 0  Warnings: 0

dba@192.168.200.59 : dchat_main 05:45:53>alter table messages_tt drop primary key;
Query OK, 684076 rows affected (16.46 sec)
Records: 684076  Duplicates: 0  Warnings: 0

dba@192.168.200.59 : dchat_main 05:46:20>alter table messages_tt add primary key(m_id),algorithm=copy;
Query OK, 684076 rows affected (17.54 sec)
Records: 684076  Duplicates: 0  Warnings: 0

dba@192.168.200.59 : dchat_main 05:46:48>alter table messages_tt drop primary key;
Query OK, 684076 rows affected (16.73 sec)
Records: 684076  Duplicates: 0  Warnings: 0

dba@192.168.200.59 : dchat_main 05:48:19>alter table messages_tt add primary key(m_id);默认,和第一次inplace效果一样
Query OK, 0 rows affected (26.31 sec)
Records: 0  Duplicates: 0  Warnings: 0

下面是MySQL官方的测试例子:

mysql> CREATE TABLE add_pk_via_inplace (c1 INT, c2 VARCHAR(10), c3 DATETIME);
Query OK, 0 rows affected (0.02 sec)

mysql> INSERT INTO add_pk_via_inplace VALUES (1,'a','2014-11-03 11:01:37'),(NULL,NULL,NULL);
Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> SELECT * FROM add_pk_via_inplace;
+------+------+---------------------+
| c1   | c2   | c3                  |
+------+------+---------------------+
|    1 | a    | 2014-11-03 11:01:37 |
| NULL | NULL | NULL                |
+------+------+---------------------+
2 rows in set (0.00 sec)

mysql> SET sql_mode = '';
Query OK, 0 rows affected (0.00 sec)

mysql> ALTER TABLE add_pk_via_inplace ADD PRIMARY KEY (c1,c2,c3), ALGORITHM=INPLACE;
ERROR 1846 (0A000): ALGORITHM=INPLACE is not supported. Reason: cannot silently convert NULL 
values, as required in this SQL_MODE. Try ALGORITHM=COPY.

mysql> SET sql_mode ='strict_trans_tables';
Query OK, 0 rows affected (0.00 sec)

mysql> ALTER TABLE add_pk_via_inplace ADD PRIMARY KEY (c1,c2,c3), ALGORITHM=INPLACE;
ERROR 1138 (22004): Invalid use of NULL value
mysql> DELETE FROM add_pk_via_inplace WHERE c1 IS NULL OR c2 IS NULL OR c3 IS NULL;
Query OK, 1 row affected (0.01 sec)

mysql> SELECT * FROM add_pk_via_inplace;
+------+------+---------------------+
| c1   | c2   | c3                  |
+------+------+---------------------+
|    1 | a    | 2014-11-03 11:01:37 |
+------+------+---------------------+
1 row in set (0.00 sec)

mysql> ALTER TABLE add_pk_via_inplace ADD PRIMARY KEY (c1,c2,c3), ALGORITHM=INPLACE;
Query OK, 0 rows affected (0.09 sec)
Records: 0  Duplicates: 0  Warnings: 0
View Code

相关文章:

  • 2021-12-26
  • 2022-12-23
  • 2022-12-23
  • 2021-06-15
  • 2021-07-18
  • 2022-12-23
  • 2022-01-31
猜你喜欢
  • 2021-06-22
  • 2021-12-18
  • 2022-12-23
  • 2022-02-03
  • 2021-10-17
  • 2021-10-17
  • 2022-12-23
相关资源
相似解决方案