指定id列为主键,使用B树作为索引。
UNIQUE KEYidx_username(username) USING BTREE, KEYidx_mobile(mobile) USING BTREE, KEYidx_name(name) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC COMMENT=’用户信息表’; 插入一条数据: INSERT INTOtest.sys_user(id,username,password,name,mobil...
PRIMARY KEY (`id`) USING BTREE,KEY `idx_business_day_full_ps_code` (`business_day`,`full_ps_code`) ===以下索引可以忽略===KEY `idx_erp_month_businessday` (`erp`,`month`,`business_day`),KEY `idx_business_day_erp` (`business_day`,`erp`),KEY `idx_erp_month_ps_plan_id` (`e...
mysql> alter table t2 drop primary key, drop key idx_name; Query OK, 0 rows affected (0.04 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> alter table t2 add primary key (id) using btree, add key idx_name (name) using btree; Query OK, 0 rows affected (0.04 sec) Records: 0 D...
CREATETABLE`user` ( `id`bigint(10)NOTNULLAUTO_INCREMENT, `name`varchar(10)DEFAULTNULL, `age`int(2)DEFAULTNULL, `sex`char(1)DEFAULTNULL, `create_time`datetimeDEFAULTNULL,PRIMARYKEY(`id`) USING BTREE,KEY`idx_name` (`name`),KEY`idx_age` (`age`),KEY`idx_sex` (`sex`) ...
5、HASH索引,MEMORY数据表的默认索引类型,利用散列索引进行精确值查询的速度非常快。不过如果打算用一个MEMORY数据表进行范围比较(如id<100),散列索引的性能就比较差了,这种情况下可以改用BTREE索引,例如: CREATE TABLE namelist { id INT NOT NULL, name CHAR(100), ...
PRIMARY KEY (`id`), KEY `idx_name` (`name`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 我们将其设置 10 条数据,便于下面的索引的理解: INSERT INTO `user` VALUES ('1', 'andy', '20', '女'); INSERT INTO `user` VALUES ('10', 'baby', '12', '女'); ...
id不同,如果是子查询,id序号对递增,id值越大优先级越高,越先执行 mysql> explain select e.* -> from employee e -> where id = ( select user_id -> from performance -> where performance.score > 80 and performance.year = 2020 and performance.quarter = 2); ...
(20) NOT NULL DEFAULT '' COMMENT '用户等级', `register_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '注册时间', PRIMARY KEY (`id`), KEY `idx_userName_userAge_userLevel` (`user_name`,`user_age`,`user_level`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='...
select name,id from user where name="egon"; # 覆盖了索引 250w条记录-》ibd文件的大小167M 索引的简单使用 create table t1( id int, name varchar(10), ); create index idx_xxx on t1(id); drop index idx_xxx on t1; 命中索引也未必能起到很好的提速效果 ...