zoukankan      html  css  js  c++  java
  • 给一个含有21个字段的一千六百万大表增加一个字段需要多长时间?0.1秒

    以前做过一个一千六百万大表增添字段实验https://www.cnblogs.com/xiandedanteng/p/12323537.html,实验证明表无论大小增添字段都很快,或者说增添字段的耗时与表规模无关。

    但上次表字段有点少,于是这次把表增加到了21字段再实验。

    表结构:

    create table tb_20cols(
        id number(9,0),
        col01 integer not null,
        col02 integer not null,
        col03 integer not null,
        col04 integer not null,
        col05 integer not null,
        col06 integer not null,
        col07 integer not null,
        col08 integer not null,
        col09 integer not null,
        col10 integer not null,
        col11 integer not null,
        col12 integer not null,
        col13 integer not null,
        col14 integer not null,
        col15 integer not null,
        col16 integer not null,
        col17 integer not null,
        col18 integer not null,
        col19 integer not null,
        col20 integer not null)

    初次充值:

    insert into tb_20cols
    select 0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0
    from dual
    connect by level<2000001

    然后把以下语句重复三次就得到了一千六百万大表:

    insert into tb_20cols select * from tb_20cols;
    SQL> insert into tb_20cols select * from tb_20cols;
    
    已创建2000000行。
    
    SQL> insert into tb_20cols select * from tb_20cols;
    
    已创建4000000行。
    
    SQL> insert into tb_20cols select * from tb_20cols;
    
    已创建8000000行。
    
    SQL> select count(*) from tb_20cols;
    
      COUNT(*)
    ----------
      16000000

    最后见证奇迹的时刻:

    SQL> set timing on;
    SQL> alter table tb_20cols add remark nvarchar2(60);
    
    表已更改。
    
    已用时间:  00: 00: 00.10

    结果证明增添字段耗时不但与规模无关,和列数也没关系。

    道听途说的结论,网文的论断,可以姑且听之,但一定要做了实验后才能取信或是摒弃。

    --2020.04.11--

  • 相关阅读:
    分段、分页&&内存碎片、外存碎片
    mysql中的事务处理
    算法的在线演示网站
    为什么要使用树以及使用什么树
    平衡多叉树--B-Tree(B树)
    MVCC--多版本并发控制机制
    mysql中的锁
    平衡二叉树--红黑树(RB-Tree)
    平衡二叉树--AVL树
    自平衡方式--旋转
  • 原文地址:https://www.cnblogs.com/heyang78/p/12681507.html
Copyright © 2011-2022 走看看