【程序员必备】30天从零开始玩转AI大模型,这波操作太秀了!
2026/1/22 17:48:04
mysql> select count(*) from test_data; +----------+ | count(*) | +----------+ | 1000000 | +----------+ 1 row in set (0.74 sec) mysql> desc test_data; +-------+---------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------+---------------+------+-----+---------+----------------+ | id | int | NO | PRI | NULL | auto_increment | | m | varchar(30) | YES | | NULL | | | n | varchar(80) | YES | | NULL | | | x | decimal(12,6) | YES | | NULL | | | y | decimal(18,3) | YES | | NULL | | +-------+---------------+------+-----+---------+----------------+ 5 rows in set (0.05 sec) mysql> alter table test_data add z decimal(10,3); Query OK, 0 rows affected (0.13 sec) Records: 0 Duplicates: 0 Warnings: 0 - 可见增加字段是直接元数据变更。 mysql> mysql> alter table test_data modify m varchar(50); Query OK, 0 rows affected (0.02 sec) Records: 0 Duplicates: 0 Warnings: 0 - 可见上次结论,64以下到64以上会耗时较长,数据不仅仅是元数据变更 mysql> alter table test_data modify m varchar(150); Query OK, 1000000 rows affected (49.92 sec) Records: 1000000 Duplicates: 0 Warnings: 0 mysql> alter table test_data modify m varchar(160); Query OK, 0 rows affected (0.02 sec) Records: 0 Duplicates: 0 Warnings: 0 - 而64以上再次改变是,仅仅元数据变更。 - 那么数据精度改变。从实际效果而言,耗时较长。数据重新在做组织。 - mysql> alter table test_data modify x decimal(18,6); Query OK, 1000000 rows affected (47.20 sec) Records: 1000000 Duplicates: 0 Warnings: 0 mysql> alter table test_data modify y decimal(18,6); Query OK, 1000000 rows affected (46.73 sec) Records: 1000000 Duplicates: 0 Warnings: 0XXG@xxg> desc test_data; 名称 是否为空? 类型 ----------------------------------------------------------------- -------- -------------------------------------------- M VARCHAR2(30) N VARCHAR2(80) X NUMBER(12,6) Y NUMBER(18,3) XXG@xxg> set timing on; XXG@xxg> select count(*) from test_data; COUNT(*) ---------- 2500000 已用时间: 00: 00: 00.38 XXG@xxg> alter table test_data add z decimal(10,3); 表已更改。 - 在11g(2005年)就实现的增加字段是直接元数据变更,是所有数据库都学习和借鉴的。 已用时间: 00: 00: 01.23 XXG@xxg> alter table test_data modify m varchar(50); 表已更改。 已用时间: 00: 00: 00.19 XXG@xxg> alter table test_data modify m varchar(150); 表已更改。 已用时间: 00: 00: 00.16 XXG@xxg> alter table test_data modify m varchar(160); 表已更改。 - 无论如何扩位,都是快速完成。不存在数据重组的问题。 已用时间: 00: 00: 00.15 XXG@xxg> alter table test_data modify x decimal(18,6); 表已更改。 已用时间: 00: 00: 00.16 XXG@xxg> alter table test_data modify y decimal(18,6); alter table test_data modify y decimal(18,6) * 第 1 行出现错误: ORA-01440: 要减小精度或标度, 则要修改的列必须为空 已用时间: 00: 00: 00.39 XXG@xxg> alter table test_data modify y decimal(21,6); 表已更改。 已用时间: 00: 00: 00.05