久久精品人人爽,华人av在线,亚洲性视频网站,欧美专区一二三

MySQL多列索引怎么用

136次閱讀
沒有評論

共計 2427 個字符,預計需要花費 7 分鐘才能閱讀完成。

這篇文章將為大家詳細講解有關 MySQL 多列索引怎么用,丸趣 TV 小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。

    針對此問題進行測試:
假設某個表有一個聯合索引(c1,c2,c3,c4)一下___只能使用該聯合索引的 c1,c2,c3 部分
A where c1=x and c2=x and c4 x and c3=x
B where c1=x and c2=x and c4=x order by c3
C where c1=x and c4= x group by c3,c2
D where c1=x and c5=x order by c2,c3
E where c1=x and c2=x and c5=? order by c2,c
1、創建測試表

點擊 (此處) 折疊或打開

mysql
show
create
table
t1 \G

***************************
row
***************************

 Table:
t1

Create
Table:
CREATE
TABLE
`t1`
(

 `c1`
mediumint(8)
unsigned
NULL
DEFAULT
0 ,

 `c2`
smallint(5)
unsigned
NULL
DEFAULT
0 ,

 `c3`
int(10)
unsigned
NULL
DEFAULT
0 ,

 `c4`
int(10)
unsigned
NULL
DEFAULT
0 ,

 `c5`
mediumint(8)
unsigned
NULL,

 `c6`
varchar(2)
DEFAULT
NULL,

 KEY
`idx_t1_c1_c2_c3_c4`
(`c1`,`c2`,`c3`,`c4`)

)
ENGINE=InnoDB
DEFAULT
CHARSET=utf8

2、選項 A 執行計劃

點擊 (此處) 折疊或打開

mysql
explain
select
from
where
c1=100
c2=2
c4 1000
c3=1419401948 \G

***************************
row
***************************

 id: 1

 select_type: SIMPLE

 table:
t1

 partitions:
NULL

 type: range

possible_keys: idx_t1_c1_c2_c3_c4

 key: idx_t1_c1_c2_c3_c4

 key_len: 13

 ref:
NULL

 rows: 1

 filtered: 100.00

 Extra: Using index condition

3、選項 B 執行計劃

點擊 (此處) 折疊或打開

mysql
explain
select
from
where
c1=100
c2=2
c4=1419317673 order by c3 \G

***************************
row
***************************

 id: 1

 select_type: SIMPLE

 table:
t1

 partitions:
NULL

 type: ref

possible_keys: idx_t1_c1_c2_c3_c4

 key: idx_t1_c1_c2_c3_c4

 key_len: 5

 ref: const,const

 rows: 1

 filtered: 10.00

 Extra: Using index condition

4、選項 C 執行計劃

點擊 (此處) 折疊或打開

mysql
explain
select
from
where
c1=100
c4=1419317673 group by c3,c2 \G

***************************
row
***************************

 id: 1

 select_type: SIMPLE

 table:
t1

 partitions:
NULL

 type: ref

possible_keys: idx_t1_c1_c2_c3_c4

 key: idx_t1_c1_c2_c3_c4

 key_len: 3

 ref: const

 rows: 1

 filtered: 10.00

 Extra: Using index condition;
Using temporary;
Using filesort

5、選項 D 執行計劃

點擊 (此處) 折疊或打開

mysql
explain
select
from
where
c1=100
c5=2 order by c2,c3 \G

***************************
row
***************************

 id: 1

 select_type: SIMPLE

 table:
t1

 partitions:
NULL

 type: ref

possible_keys: idx_t1_c1_c2_c3_c4

 key: idx_t1_c1_c2_c3_c4

 key_len: 3

 ref: const

 rows: 1

 filtered: 10.00

 Extra: Using index condition;
Using
where

6、選項 E 執行計劃

點擊 (此處) 折疊或打開

mysql
explain
select
from
where
c1=1000
c2=200
c5=2 order by c2,c3 \G

***************************
row
***************************

 id: 1

 select_type: SIMPLE

 table:
t1

 partitions:
NULL

 type: ref

possible_keys: idx_t1_c1_c2_c3_c4

 key: idx_t1_c1_c2_c3_c4

 key_len: 5

 ref: const,const

 rows: 1

 filtered: 10.00

 Extra: Using index condition;
Using
where

關于“MySQL 多列索引怎么用”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。

正文完
 
丸趣
版權聲明:本站原創文章,由 丸趣 2023-07-27發表,共計2427字。
轉載說明:除特殊說明外本站除技術相關以外文章皆由網絡搜集發布,轉載請注明出處。
評論(沒有評論)
主站蜘蛛池模板: 察隅县| 江陵县| 托克托县| 定陶县| 凭祥市| 怀柔区| 镇雄县| 山东| 灵宝市| 察哈| 张家口市| 四川省| 怀来县| 桦川县| 汕尾市| 东丽区| 吉安县| 武隆县| 德令哈市| 三明市| 广汉市| 攀枝花市| 林口县| 台中市| 通辽市| 阳东县| 富平县| 乌兰察布市| 洱源县| 城口县| 新民市| 龙井市| 武夷山市| 康平县| 南阳市| 柳江县| 全椒县| 寿阳县| 黎平县| 白水县| 鹤山市|