在一张表中添加字段,耗时180秒的优化(允许新添加的字段为 null)
1、在一张表中添加字段,耗时180秒。如图1
alter table `table` add `checksum` char(40) not null comment '校验和' after `schema` 180,559.53ms
2、查询表中的记录总数,数量为:173816 条。如图2
SELECT count(*) FROM `object`.`table`
3、决定允许新添加的字段为 null,重新添加字段,耗时 104 秒。如图3
alter table `table` add `checksum` char(40) null comment '校验和' after `schema` 104,526.58ms
4、确认其中存在一些不再使用的数据,决定先删除掉,最后仅剩下记录数量:30662。再添加字段。期望耗时更短一些。最终符合预期。总计耗时:87秒(52 秒 + 34 秒)。如图4
alter table `table` add `checksum` char(40) null comment '校验和' after `schema` 52,409.12ms delete from `table` where `theme_id` not in ('96b1c8b9-5b18-4760-9e26-50ab009ac011', '977f0897-b80b-4619-963d-6f075380712b', '97a5bec3-b1ef-4bb3-bc77-f62b3b8282c1', '97a78404-cd5b-43d3-812a-ce084c57183f', '97a7cacf-eb9e-4adb-8a29-382e6b489a41', '97b1825b-59cd-4182-8978-1e2961188cc0', '97b1a47d-7e45-4d86-99d7-d72da147857c', '97cdd852-2ca0-48eb-b119-6afb68e2254c', '97e19252-b7e6-412e-b0de-6942e763a916', '97efa3d0-91b0-445d-90e6-1ee192e0073c', '97f63919-acb6-4c66-ae05-c1a809205025', '9808525f-a419-4390-8308-c863e1913784', '98085762-3070-4f62-ad5a-bdc334c8ef28', '98085a7f-8916-4729-b07c-6c1eec4abae1', '98085f15-a880-4c4a-b112-d8e7505aaabb', '98086431-7734-4f0c-b61f-035cf91bc157', '98086432-c69c-4979-aa0d-bd8058a836d7', '98086433-d714-4739-917a-0db8218a8b76', '980c338b-4ca0-4cee-a573-1e353b119f26', '9811c067-826d-4e64-bb71-7720fcc4e6d0', '9811c3e9-166d-4589-b317-7cf04e22fd4f', '9811deff-c4d2-4329-891d-ccfffda0dde3', '9811df05-6538-4b71-ab4a-e8ed978dd2c0', '9811df08-68b2-409c-b823-125238b72ca0', '9811df0b-0895-4f27-ae42-ac5d4b5074c2', '9811e29a-12f8-4582-b1e6-76aff3756309', '9811e29b-9c87-43c5-8c94-cef49126958f', '981210c2-6f4a-49ad-87f2-4c58605facd6', '98121394-d87e-46c6-bdaf-1f279c63dd60', '981213ff-f3d7-4976-baca-d26eb5e41a65', '98182985-e967-482e-9654-26d556ce4aed', '98182986-308d-431d-b07a-eec71308e2a2', '98182986-631c-41a0-8bc1-8fa0d9d4b520', '98182986-9815-4646-aafa-fc622799028b', '98182986-d311-4fc4-bc99-ccb3238e803b', '9821f9d4-0725-413c-8e58-c1d28616f1fe', '9823d83a-dbc3-49ae-8d7d-2347457944aa', '9823d83b-314b-415b-81cc-1d43f51b3cbd', '9823d83b-5ff8-4e4f-ac40-7278f47522f0', '9823d83b-8d97-446a-af7c-2a8218fe2e8f', '9823d83b-bffa-4b07-8d87-ccc46a8f0c90', '9823d83b-e768-4d5c-9f4c-26423b55248e', '9823e7b6-8bde-420d-b2dc-e181f80ef5a1', '9823f651-ac25-43e1-a873-fa91dd9c7faa', '9823f6a0-cdf2-4143-a33e-a64d990d6074', '98245ed8-9546-4154-9751-6c115538584e', '982662e4-4f6e-48c1-a605-e1edda3fd6e8', '982662e4-8da6-498a-b7b3-4a361bef85e2', '982662e4-ca9b-41a5-a4dd-c25a6cfc5d11', '982662e4-f7f2-4717-8708-24f7df3b5a00', '98280480-1ce9-4179-88f6-94eb4b9c8e41', '982847ab-1f7e-4825-bc7f-63cb3c5eed83', '9828490c-53d7-489e-ad1e-c123fb67804e', '9829fc55-64bc-46d0-87b1-6434b895d625', '982e52e3-380e-4852-9c8d-97d918a667f5', '982e8efd-75c5-438b-bb6f-ffa0e4801380', '982e8efd-ae70-4ed7-a16b-791e765b532f', '983213e5-42e6-493a-8c9c-71be8f480c52', '9833ff01-02c8-46a8-bf76-4c6267a9df52', '983409d4-d7e6-4d35-b0d0-461a5d6135bc', '98360cb1-7663-47f3-925f-5642728a5ebf', '98360cb1-b9fc-4f98-96fc-7de39ecd1018', '98367cbc-2545-414a-a31d-f9b54ece220d', '98367cbc-672d-4f1f-ad3c-22f0dfe3d4f6', '98367cbc-97e3-42ce-9c2a-b6807df8f6e6', '983c85e5-725c-412c-b656-597fde97c9b0', '98568439-c540-4970-8cfb-427efa2b50e9', '98664bc2-dc62-4cab-bba6-139d334d6b3b', '986c9a69-3de0-4e54-8ebd-b75f95ea6c75', '986c9d3e-206c-43c7-8e77-f166731a5df5', '9892d628-8003-4479-839f-33d50bf39be3', '9894a850-76ac-4caf-8cd0-e25bd88fdb78', '9896d88f-2ed2-441d-916b-7358c79906c6') 34,048.19ms
近期评论