美文网首页
BTree索引使用技巧

BTree索引使用技巧

作者: c_gentle | 来源:发表于2020-08-24 11:34 被阅读0次

explain是解释计划,说明SQL的执行情况

explain select * from t_content where content_id = 17076710;
drop index idx_uid on t_content;
create index idx_uid on t_content(uid);
explain select * from t_content where uid=16940130;

drop index idx_uid on t_content;
create index idx_uid on t_content(uid);

精准匹配,允许使用btree索引

explain select * from t_content where uid = 16940130;

范围匹配,允许使用btree索引

explain select * from t_content where uid > 1260000 and uid < 12610000;

查询优化器会自动进行类型转换,但仍然建议使用与定义相符的类型

explain select * from t_content where uid like '1694%';

drop index idx_share_url on t_content;
create index idx_share_url on t_content(share_url);

字符串字段btree索引允许进行"前缀查询"

explain select * from t_content where share_url like 'http://a.f.budejie.com/share/%';

后缀查询与模糊匹配btree均不支持

explain select * from t_content where share_url like '%http://a.f.budejie.com/share/17076710';
explain select * from t_content where share_url like '%http://a.f.budejie.com/share/17076710%';

drop index idx_uid_sid on t_content;
create index idx_uid_sid on t_content( uid , source_id );

复合索引查询条件必须包含左侧列

EXPLAIN select * from t_content where uid = 14206986 ;

直接书写右侧列将导致数据无法查询,如果书写右侧列,必须要把左侧列书写上

EXPLAIN select * from t_content where uid=14206986 and source_id = 13054 ;

<>与not in会导致不使用索引

EXPLAIN select * from t_content where source_id <> 13054 ;
EXPLAIN select * from t_content where source_id <=13053 or source_id >=13055;

相关文章

  • BTree索引使用技巧

    explain是解释计划,说明SQL的执行情况 explain select * from t_content w...

  • mysql索引结构

    主要有以下四种 BTree索引 MySQL 使用的是 Btree 索引。 ...

  • MySQL面试题 | 附答案解析(四)

    7. 索引算法有哪些? 索引算法有 BTree算法和Hash算法 BTree算法 BTree是最常用的mysql数...

  • MySQL多列索引的生效规则

    mysql中 myisam,innodb默认使用的是 Btree索引,至于btree的数据结构是怎样的都不重要,...

  • 四,索引及执行计划

    1,索引作用 2,索引的分类(算法) 3,BTree索引算法演变 4,BTree索引功能上的分类 辅助索引 聚集索...

  • Mysql Innodb的索引结构:B+ Tree 聚簇

    索引 索引(Index)是帮助MySQL高效获取数据的数据结构。MongoDb索引使用BTree,而Mysql的M...

  • MySQL索引详解(三)索引的底层原理

    索引的总共有四种类型:BTree索引,HASH索引,FullText索引和RTree索引不同的存储引擎使用是不同实...

  • MySQL索引

    默认使用BTREE索引方式 索引提高了查询的速度,但是降低了INSERT、UPDATE、DELETE的速度,因为在...

  • MySQL索引和锁

    Mysql索引使用的数据结构主要有BTree索引 和 哈希索引 。对于哈希索引来说,底层的数据结构就是哈希表,因此...

  • Elasticsearch 调研

    1. 基础概念 1.1 倒排索引原理 1.2 倒排索引构成 单词词典,使用 BTree 记录所有文档的单词,记录单...

网友评论

      本文标题:BTree索引使用技巧

      本文链接:https://www.haomeiwen.com/subject/ehqvdktx.html