1. 程式人生 > >mysql生成100000個數據並檢驗索引的效果

mysql生成100000個數據並檢驗索引的效果

實驗簡述

  • 實驗目的: 本次實驗是為了檢驗索引的使用效果
  • 實驗平臺: windows
  • 資料庫: mysql

文章目錄

前提

workbench 提示連線超時

解決辦法: Edit->perferences->SQL Editors,將Mysql Session中的三個數字都調到10倍(意味著延長時間~)

建立100000個數據

use jxgl;
drop table if exists test;
CREATE TABLE test (
    id INT UNIQUE AUTO_INCREMENT,
    rq DATETIME NULL,
    srq VARCHAR(20) NULL,
    hh SMALLINT NULL,
    mm SMALLINT NULL,
    ss SMALLINT NULL,
    num NUMERIC(12 , 3 ),
    PRIMARY KEY (id)
)  AUTO_INCREMENT=1 ENGINE=MYISAM;

drop
procedure if exists p1; delimiter // create procedure p1() begin set @i=1; while @i <= 100000 do insert into test value( @i, now(), now(), hour(now()), MINUTE(now()), second(now()), RAND(@i) * 100 ); set @i = @i + 1; end while; end// call p1 // delimiter ;

在這裡插入圖片描述

設定索引的方法

  • 設定非聚類索引
create index indexname1 on test(id);
  • 設定唯一索引
create unique index indexname1 on test(id);

刪除索引的方式

  • 任何索引都是可以用這個方法刪除掉
drop index indexname1 on test;

效果

  • 檢驗方法就是不斷的插入,刪除,看看用時

效果不明顯,不搞不太懂是不是裝置不同的原因。在我電腦上差不多。。