0115關於索引認識

2022-05-06 14:33:10 字數 2000 閱讀 7042

-- 關於索引一點理解

1從整體理解聯合索引,order by以及group by之間的過程

-- 改語句很有代表性,自己分析,理解為什麼

create table t6(

c1 char(1) not null default '',

c2 char(1) not null default '',

c3 char(1) not null default '',

c4 char(1) not null default '',

c5 char(1) not null default '',

key(c1,c2,c3,c4)

)engine innodb charset utf8;

insert into t6 values('a','b','c','d','e');

explain

select * from t6 where c1='a' and c2='b' and c4>'a' and c3='c';

explain

select * from t6 where c1='a' and c2='b' and c4='a' order by c3;

explain

select * from t6 where c1='a' and c2='b' and c4='a' order by c5;

explain

select * from t6 where c1='a' and c5='a' order by c2,c3;

explain

select * from t6 where c1='a' and c5='a' order by c3,c2;

explain

select * from t6 where c1='a' and c2='b' and c5='a' order by c2,c3;

explain

select * from t6 where c1='a' and c2='b' and c5='a' order by c3,c2;-- [改寫為order by c3,'b'],故直接修改為order by c3,語句寫的冗餘

explain

select * from t6 where c1='a' and c4='d' group by c2,c3;

explain

select * from t6 where c1='a' and c4='d' group by c3,c2;

-- 有時候使用了索引但是不會計入到key_len的長度當中,但是我們發現他們區別在extra中 使用索引的using where,但是沒有使用索引的using tempary;using filsort

理解

2關於explain中rows自己的一點認識

-- 需要掃瞄的行數,代表必須

explain

select * from ta where rid1=429 and rid2=36

select * from ta where rid2=36-- 12

-- 相當於先通過索引找到12行符合條件的語句,所以掃瞄行數肯定為12,然後回表使用where進行過濾,得到最終的6條

-- 所以建立更好的索引,可以減少掃瞄行數,索引功能作用大大的

一條sql語句的執行過程

3關於mysql是如何進行group by的分析結構

所以建立有效的索引,可以避免using tempary;using filesort;

MySQL索引專題一 認識索引

想寫mysql的索引專題是源於之前自己在學習mysql索引時痛苦的經歷,你在網上搜尋關於mysql的索引的文章,大多是支離破碎,沒有系統性的對知識點的羅列堆砌,文章中會說明你要如何如何做,但是很少涉及去講為什麼要這麼做,哪些不能做,很難對mysql有乙個系統性的認知,學習如果沒有系統性的話,就很難在...

認識和使用索引

索引 5.1 索引的概念 資料庫的索引好比新華字典的音序表,它是對資料庫表中一列或多列的值進行排序後的一種結構,其作用就是提高表中資料的查詢速度。注 建立表的時候建立索引 create table 表名 欄位名 資料型別 完整性約束條件 欄位名 資料型別 完整性約束條件 欄位名 資料型別 uniqu...

Oracle索引的新認識

首先,oracle的索引有。普通索引b 樹,bitmap索引,函式索引,組合索引,反轉索引。那麼這裡主要說一下常用的索引。b 樹索引就是普通索引。使用方式如下 create index idx a on my table a b 樹的組合索引用法如下 create index idx a b on ...