Code Monkey home page Code Monkey logo

Comments (4)

git-zjx avatar git-zjx commented on September 24, 2024

树高取决于数据页的大小么?

树高其实取决于叶子树(数据行数)和“N叉树”的N。 而N是由页大小和索引大小决定的

from git-zjx.github.io.

git-zjx avatar git-zjx commented on September 24, 2024

覆盖索引必须要覆盖所有的查询条件中的列吗?

因为覆盖索引的目的就是”不回表“,所以只有索引包含了 where 条件部分和 select 返回部分的所有字段,才能实现这个目的

from git-zjx.github.io.

git-zjx avatar git-zjx commented on September 24, 2024

关于用索引的问题

有些文章说模糊查询时以%开头不会用到索引,但和实际操作有些不符。这里主要是因为用索引有一种用法是 顺序遍历索引

from git-zjx.github.io.

git-zjx avatar git-zjx commented on September 24, 2024

如下的表结构和业务场景中,ca 和 cb 的索引是否有必要存在?

CREATE TABLE `geek` (
  `a` int(11) NOT NULL,
  `b` int(11) NOT NULL,
  `c` int(11) NOT NULL,
  `d` int(11) NOT NULL,
  PRIMARY KEY (`a`,`b`),
  KEY `c` (`c`),
  KEY `ca` (`c`,`a`),
  KEY `cb` (`c`,`b`)
) ENGINE=InnoDB;
# 业务场景
select * from geek where c=N order by a limit 1;
select * from geek where c=N order by b limit 1;

ca 索引是没有必要创建的

主键 a,b 的聚簇索引组织顺序相当于 order by a,b ,也就是先按 a 排序,再按 b 排序,c 无序
索引 ca 的组织是先按 c 排序,再按 a 排序,同时记录主键
索引 cb 的组织是先按 c 排序,在按 b 排序,同时记录主键
所以,ca 索引可以去掉

from git-zjx.github.io.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.