溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

怎么測試MySQL8.0.16秒加字段功能

發(fā)布時間:2021-11-08 11:23:44 來源:億速云 閱讀:255 作者:iii 欄目:MySQL數(shù)據(jù)庫

這篇文章主要講解了“怎么測試MySQL8.0.16秒加字段功能”,文中的講解內(nèi)容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“怎么測試MySQL8.0.16秒加字段功能”吧!

Instant add column功能自MySQL 8.0.12版本引入,INSTANT操作僅修改數(shù)據(jù)字典中的元數(shù)據(jù)。在準備和執(zhí)行期間,

不會在表上采用獨占元數(shù)據(jù)鎖,并且表數(shù)據(jù)不受影響,從而使操作立即生效。允許并發(fā)DML。

InnoDB僅支持INSTANT進行如下操作:

Change index option                                             更改索引選項

Rename table (in ALTER way)                                     重命名表(以ALTER方式)

SET/DROP DEFAULT                                                設置/刪除缺省值

Add columns(non-generated) – We call this instant ADD COLUMN    添加列(非生成) - 我們稱之為立即加列

MODIFY COLUMN                                                   修改列

Add/drop virtual columns                                        添加/刪除虛擬列

添加新列作為表中的最后一列。

添加生成的虛擬列。

刪除生成的虛擬列。

設置現(xiàn)有列的默認值。

刪除現(xiàn)有列的默認值。

更改具有ENUM或SET數(shù)據(jù)類型的列所允許的值列表。要求是列的存儲大小不會更改。

instant功能存在的限制:

僅支持在一個語句中添加列,即如果同一語句中存在其他非INSTANT操作,則無法立即執(zhí)行

innodb行格式不能是COMPRESSED。

該表上不能有全文索引。

即時添加的列不能是PK。

只能順序加列,僅支持在最后添加列,而不支持在現(xiàn)有列的中間添加列

不支持壓縮表

不支持包含任何全文索引的表

不支持臨時表,臨時表只能使用copy的方式執(zhí)行DDL

不支持那些在數(shù)據(jù)詞典表空間中創(chuàng)建的表

數(shù)據(jù)字典中的表不能使用instant算法

實驗如下:

mysql> CREATE TABLE `test` (

    ->  `ID` int(11) NOT NULL AUTO_INCREMENT,

    ->  `NAME` varchar(50) NOT NULL,

    ->  PRIMARY KEY (`ID`)

    ->  ) AUTO_INCREMENT=1000;

Query OK, 0 rows affected (0.19 sec)

mysql>delimiter $$

mysql> create procedure pro_test()

    ->      begin

    ->      declare id int;

    ->      set id = 100000;

    ->      while id>0 do

    ->      insert into test(name) values ('love');  

    ->      set id = id-1;                                                                                                                                              

    ->      end while;

    ->      end $$

Query OK, 0 rows affected (0.04 sec)

mysql>delimiter ;

mysql>call pro_test();

mysql>call pro_test();

mysql>call pro_test();

mysql>call pro_test();

mysql>call pro_test();

mysql>call pro_test();

mysql>call pro_test();

多執(zhí)行幾次,生成更多的數(shù)據(jù)量。

mysql>select count(*) from test;

+----------+

| count(*) |

+----------+

| 20547289 |

+----------+

1 row in set (1 min 6.85 sec)

秒加字段測試:

mysql>alter table test add addr varchar(10),ALGORITHM=INSTANT;

Query OK, 0 rows affected (4.06 sec)

Records: 0  Duplicates: 0  Warnings: 0

mysql>ALTER TABLE test ADD COLUMN c ENUM('a', 'b', 'c'), ALGORITHM = INSTANT;

Query OK, 0 rows affected (0.12 sec)

Records: 0  Duplicates: 0  Warnings: 0

第一次用了4.06秒,第二次用了0.12秒

重命名:

mysql>ALTER TABLE test RENAME TO t2, ALGORITHM = INSTANT;

Query OK, 0 rows affected (0.19 sec)

mysql>ALTER TABLE t2 RENAME TO test, ALGORITHM = INSTANT;

Query OK, 0 rows affected (0.10 sec)

設置列缺省值:

mysql>ALTER TABLE test ALTER COLUMN name SET DEFAULT 100, ALGORITHM = INSTANT;

Query OK, 0 rows affected (0.09 sec)

Records: 0  Duplicates: 0  Warnings: 0

刪除列缺省值:

mysql>ALTER TABLE test alter COLUMN name DROP DEFAULT, ALGORITHM = INSTANT;

Query OK, 0 rows affected (0.13 sec)

Records: 0  Duplicates: 0  Warnings: 0

修改列:

mysql>ALTER TABLE test MODIFY COLUMN c ENUM('a', 'b', 'c', 'd', 'e'), ALGORITHM=INSTANT;

Query OK, 0 rows affected (0.09 sec)

Records: 0  Duplicates: 0  Warnings: 0

更改索引,適用于表上已有索引:

mysql>>show index from test \G

*************************** 1. row ***************************

        Table: test

   Non_unique: 0

     Key_name: PRIMARY

 Seq_in_index: 1

  Column_name: ID

    Collation: A

  Cardinality: 19998192

     Sub_part: NULL

       Packed: NULL

         Null: 

   Index_type: BTREE

      Comment: 

Index_comment: 

      Visible: YES

   Expression: NULL

*************************** 2. row ***************************

        Table: test

   Non_unique: 1

     Key_name: name

 Seq_in_index: 1

  Column_name: NAME

    Collation: A

  Cardinality: 1

     Sub_part: NULL

       Packed: NULL

         Null: 

   Index_type: BTREE

      Comment: 

Index_comment: 

      Visible: YES

   Expression: NULL

2 rows in set (0.04 sec)

mysql>ALTER TABLE test DROP index name, ADD index name(name),ALGORITHM = INSTANT;

Query OK, 0 rows affected (0.13 sec)

Records: 0  Duplicates: 0  Warnings: 0

但在其他無索引的列上加新索引是不支持的:

mysql>alter table test  ADD index addr(addr),ALGORITHM = INSTANT;

ERROR 1845 (0A000): ALGORITHM=INSTANT is not supported for this operation. 

Try ALGORITHM=COPY/INPLACE.

增加虛擬列:

ALTER TABLE test ADD COLUMN (d INT GENERATED ALWAYS AS (1 + 1) VIRTUAL), ALGORITHM = INSTANT;

Query OK, 0 rows affected (2.83 sec)

Records: 0  Duplicates: 0  Warnings: 0

ysql>desc test;

+-------+---------------------------+------+-----+---------+-------------------+

| Field | Type                      | Null | Key | Default | Extra             |

+-------+---------------------------+------+-----+---------+-------------------+

| ID    | int(11)                   | NO   | PRI | NULL    | auto_increment    |

| NAME  | varchar(50)               | NO   |     | NULL    |                   |

| addr  | varchar(10)               | YES  |     | NULL    |                   |

| ip    | int(11)                   | YES  |     | NULL    |                   |

| c     | enum('a','b','c','d','e') | YES  |     | NULL    |                   |

| d     | int(11)                   | YES  |     | NULL    | VIRTUAL GENERATED |

+-------+---------------------------+------+-----+---------+-------------------+

刪除虛擬列:

mysql>ALTER TABLE test DROP COLUMN d, ALGORITHM = INSTANT;

Query OK, 0 rows affected (0.48 sec)

Records: 0  Duplicates: 0  Warnings: 0

mysql>desc test;

+-------+---------------------------+------+-----+---------+----------------+

| Field | Type                      | Null | Key | Default | Extra          |

+-------+---------------------------+------+-----+---------+----------------+

| ID    | int(11)                   | NO   | PRI | NULL    | auto_increment |

| NAME  | varchar(50)               | NO   | MUL | NULL    |                |

| addr  | varchar(10)               | YES  |     | NULL    |                |

| ip    | int(11)                   | YES  |     | NULL    |                |

| c     | enum('a','b','c','d','e') | YES  |     | NULL    |                |

+-------+---------------------------+------+-----+---------+----------------+

5 rows in set (0.04 sec)

但刪除普通列不支持:

mysql>ALTER TABLE test DROP c, ALGORITHM = INSTANT;

ERROR 1845 (0A000): ALGORITHM=INSTANT is not supported for this operation.

 Try ALGORITHM=COPY/INPLACE.

另外,用戶還可以通過來自information_schema的視圖觀察即時ADD COLUMN的結(jié)果:

mysql>SELECT table_id, name, instant_cols FROM information_schema.innodb_tables WHERE name LIKE 'test%';

+----------+----------------+--------------+

| table_id | name           | instant_cols |

+----------+----------------+--------------+

|     1060 | test/child     |            0 |

|     1064 | test/t1        |            0 |

|     1065 | test/tbl       |            0 |

|     1068 | test/employees |            0 |

|     1072 | test/test_null |            0 |

|     1073 | test/test      |            2 |

+----------+----------------+--------------+

6 rows in set (0.00 sec)

感謝各位的閱讀,以上就是“怎么測試MySQL8.0.16秒加字段功能”的內(nèi)容了,經(jīng)過本文的學習后,相信大家對怎么測試MySQL8.0.16秒加字段功能這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關知識點的文章,歡迎關注!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI