woooodlin

昨晚辗转反侧,灵光闪现,突然想到了覆盖索引+主动回表的方式,管你几个字段,我只要一个普通索引。

所以千万级大表的like模糊查询能不能做?

废话不多说,那就搞一搞。

建表
create table emp
(
    id       int unsigned auto_increment
        primary key,
    empno    mediumint unsigned default 0  not null,
    ename    varchar(20)        default \'\' not null,
    job      varchar(9)         default \'\' not null,
    mgr      mediumint unsigned default 0  not null,
    hiredate date                          not null,
    sal      decimal(7, 2)                 not null,
    comm     decimal(7, 2)                 not null,
    deptno   mediumint unsigned default 0  not null
)
    charset = utf8;


导入千万级数据

方法在这里

bigdata> select count(*) from emp
[2021-08-19 11:08:25] 1 row retrieved starting from 1 in 2 s 900 ms (execution: 2 s 874 ms, fetching: 26 ms)
未建索引下的模糊查询
bigdata> select ename, empno, job from emp where ename like \'%S%\'
[2021-08-19 11:14:25] 2,765,363 rows retrieved starting from 1 in 9 s 360 ms (execution: 8 ms, fetching: 9 s 352 ms)

仅右模糊的就不考虑了,都知道是走索引的。

上法宝,覆盖索引

不幸的是,直接卡在了创建索引这一步,因为表已经千万数据了,直接建索引机器就卡死了,顺便搜索了一下解决方案,总结的很好,但是我不用

分类:

技术点:

相关文章:

  • 2022-01-01
  • 2021-12-28
  • 2021-05-14
  • 2021-10-04
  • 2021-10-06
  • 2021-12-15
  • 2021-05-17
  • 2021-11-22
猜你喜欢
  • 2022-01-08
  • 2021-11-02
  • 2021-12-02
  • 2021-12-10
  • 2021-12-10
  • 2021-11-18
相关资源
相似解决方案