ITPub博客

首页 > 数据库 > MySQL > 联合索引测试

联合索引测试

原创 MySQL 作者:邪丶坏人 时间:2021-07-06 09:48:49 0 删除 编辑

create index idx_emp on emp(ename,deptno);

 where ename='SCOTT';

|   0 | SELECT STATEMENT            |         |        |       |     2 (100)|          |

|   1 |  TABLE ACCESS BY INDEX ROWID| EMP     |      1 |    29 |     2   (0)| 00:00:01 |

|*  2 |   INDEX RANGE SCAN          | IDX_EMP |      1 |       |     1   (0)| 00:00:01 |

mysql查询方式--ref


 where deptno='20';

|   0 | SELECT STATEMENT            |         |        |       |     2 (100)|          |

|   1 |  TABLE ACCESS BY INDEX ROWID| EMP     |      5 |   145 |     2   (0)| 00:00:01 |

|*  2 |   INDEX SKIP SCAN           | IDX_EMP |      5 |       |     1   (0)| 00:00:01 |

mysql查询方式--ALL


 where  ename='SCOTT' and deptno='20';

|   0 | SELECT STATEMENT            |         |        |       |     2 (100)|          |

|   1 |  TABLE ACCESS BY INDEX ROWID| EMP     |      1 |    29 |     2   (0)| 00:00:01 |

|*  2 |   INDEX RANGE SCAN          | IDX_EMP |      1 |       |     1   (0)| 00:00:01 |

mysql查询方式--ref


 where  deptno='20' and ename='SCOTT';

|   0 | SELECT STATEMENT            |         |        |       |     2 (100)|          |

|   1 |  TABLE ACCESS BY INDEX ROWID| EMP     |      1 |    29 |     2   (0)| 00:00:01 |

|*  2 |   INDEX RANGE SCAN          | IDX_EMP |      1 |       |     1   (0)| 00:00:01 | 

mysql查询方式--ref


 where ename='SCOTT' and job='ANALYST';

|   0 | SELECT STATEMENT            |         |        |       |     2 (100)|          |

|*  1 |  TABLE ACCESS BY INDEX ROWID| EMP     |      1 |    29 |     2   (0)| 00:00:01 |

|*  2 |   INDEX RANGE SCAN          | IDX_EMP |      1 |       |     1   (0)| 00:00:01 | 

mysql查询方式--ref


 where  job='ANALYST' and ename='SCOTT' ;

|   0 | SELECT STATEMENT            |         |        |       |     2 (100)|          |

|*  1 |  TABLE ACCESS BY INDEX ROWID| EMP     |      1 |    29 |     2   (0)| 00:00:01 |

|*  2 |   INDEX RANGE SCAN          | IDX_EMP |      1 |       |     1   (0)| 00:00:01 |

mysql查询方式--ref

 job='ANALYST' and deptno='20' ;

|   0 | SELECT STATEMENT            |         |        |       |     2 (100)|          |

|*  1 |  TABLE ACCESS BY INDEX ROWID| EMP     |      1 |    29 |     2   (0)| 00:00:01 |

|*  2 |   INDEX SKIP SCAN           | IDX_EMP |      5 |       |     1   (0)| 00:00:01 |

mysql查询方式--ALL


 deptno='20' and job='ANALYST' ;

|   0 | SELECT STATEMENT            |         |        |       |     2 (100)|          |

|*  1 |  TABLE ACCESS BY INDEX ROWID| EMP     |      1 |    29 |     2   (0)| 00:00:01 |

|*  2 |   INDEX SKIP SCAN           | IDX_EMP |      5 |       |     1   (0)| 00:00:01 |

mysql查询方式--ALL


 where job='ANALYST';

|   0 | SELECT STATEMENT  |      |        |       |     4 (100)|          |

|*  1 |  TABLE ACCESS FULL| EMP  |      2 |    58 |     4   (0)| 00:00:01 |  

mysql查询方式--ALL



mysql

在 MySQL 中如果创建了符合索引,例如创建复合索引(name,salary,dept),就相当于创建了(name,salary,dept)、

(name,salary)和 (name) 三个索引,这被称为复合索引前导列特性,因此在创建复合索引时应该将从常用作为查询条件的列放在最左边,依次递减。


create index idx_emp on emp(empno,ename,job,mgr);


where   empno='7788';

mysql查询方式--ref


where empno='7788' and ename='SCOTT';

mysql查询方式--ref


where   empno='7788' and ename='SCOTT' and job='ANALYST';

mysql查询方式--ref


where   empno=7788 and ename='SCOTT' and job='ANALYST' and mgr=7566;

mysql查询方式--ref


where   ename='SCOTT' and job='ANALYST' and mgr=7566;

mysql查询方式--ALL


where   job='ANALYST' and mgr=7566;

mysql查询方式--ALL


where   empno=7788  and job='ANALYST' and mgr=7566;

mysql查询方式--ref


where  empno=7788  and mgr=7566;

mysql查询方式--ref


where mgr=7566 and  empno=7788  ;

mysql查询方式--ref


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/31098809/viewspace-2779837/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: rac恢复到单机
请登录后发表评论 登录
全部评论
多年的DBA从业经验,有扎实的linux和Oracle运维和故障处理的能力; 对oracle rac,adg,ogg,rman备份恢复,异机恢复,分区表,数据迁移,sql优化,版本升级,数据库架构设计,故障处理都较为熟练

注册时间:2016-04-01

  • 博文量
    53
  • 访问量
    124327