zoukankan      html  css  js  c++  java
  • Oracle DML操作时索引不会维护空值(NULL)

    Oracle DML操作时索引不会维护空值(NULL)

    如果一个字段有索引,以insert为例,插入时候字段的值为NULL,不会维护该字段的索引。

    create table zkm.test (id int);
    
    create index zkm.idx_id on zkm.test(id);
    
    begin
    for i in 1..1000000 loop
    insert into zkm.test values (null);
    end loop;
    end;
    /
    
    begin
    for i in 1..1000000 loop
    insert into zkm.test values (1);
    end loop;
    end;
    /
    View Code

    实际测试实验如下:

    有无索引
    插入值 NULL 1 NULL 1
    执行时间(s) 22.72 34.73 22.40 21.59

    1.无索引,插入NULL值。

    15:42:06 SYS@testdb(330)> create table zkm.test (id int);
    
    Table created.
    
    Elapsed: 00:00:00.01
    15:42:09 SYS@testdb(330)> begin
    15:42:14   2  for i in 1..1000000 loop
    15:42:14   3  insert into zkm.test values (null);
    15:42:14   4  end loop;
    15:42:14   5  end;
    15:42:14   6  /
    
    PL/SQL procedure successfully completed.
    
    Elapsed: 00:00:22.40

    2.有索引,插入NULL值

    15:42:37 SYS@testdb(330)> drop table zkm.test purge;
    
    Table dropped.
    
    Elapsed: 00:00:00.15
    15:43:25 SYS@testdb(330)> create table zkm.test (id int);
    
    Table created.
    
    Elapsed: 00:00:00.01
    15:43:31 SYS@testdb(330)> create index zkm.idx_id on zkm.test(id);
    
    Index created.
    
    Elapsed: 00:00:00.00
    15:43:33 SYS@testdb(330)> begin
    15:43:37   2  for i in 1..1000000 loop
    15:43:37   3  insert into zkm.test values (null);
    15:43:37   4  end loop;
    15:43:37   5  end;
    15:43:37   6  /
    
    PL/SQL procedure successfully completed.
    
    Elapsed: 00:00:22.72

    3.无索引,插入非NULL值

    15:44:50 SYS@testdb(330)> drop table zkm.test purge;
    
    Table dropped.
    
    Elapsed: 00:00:00.14
    15:44:51 SYS@testdb(330)> create table zkm.test (id int);
    
    Table created.
    
    Elapsed: 00:00:00.00
    15:44:53 SYS@testdb(330)> begin
    15:44:56   2  for i in 1..1000000 loop
    15:44:56   3  insert into zkm.test values (1);
    15:44:56   4  end loop;
    15:44:56   5  end;
    15:44:56   6  /
    
    PL/SQL procedure successfully completed.
    
    Elapsed: 00:00:21.59

    4.有索引,插入非NULL值

    15:45:49 SYS@testdb(330)> drop table zkm.test purge;
    
    Table dropped.
    
    Elapsed: 00:00:00.15
    15:45:55 SYS@testdb(330)> create table zkm.test (id int);
    
    Table created.
    
    Elapsed: 00:00:00.01
    15:45:57 SYS@testdb(330)> create index zkm.idx_id on zkm.test(id);
    
    Index created.
    
    Elapsed: 00:00:00.01
    15:45:59 SYS@testdb(330)> begin
    15:46:02   2  for i in 1..1000000 loop
    15:46:02   3  insert into zkm.test values (1);
    15:46:02   4  end loop;
    15:46:02   5  end;
    15:46:02   6  /
    
    PL/SQL procedure successfully completed.
    
    Elapsed: 00:00:34.73
  • 相关阅读:
    N!的位数
    c语言memset()函数
    通宵教室(ACM水题)
    欧拉函数+素数筛
    快速幂+大数取模
    观光浏览
    插入类排序(直接插入排序)
    showDoc使用方法
    $_POST与input('post.')区别
    “三日”面试官心得
  • 原文地址:https://www.cnblogs.com/PiscesCanon/p/15667730.html
Copyright © 2011-2022 走看看