MySQL聯合索引效能比較

2021-08-16 19:40:54 字數 2370 閱讀 2257

根節點至少2顆子樹(若存在子樹的情況下);

非根節點至少擁有m/2顆子樹,其範圍為m/2 <= childnum(x) <= m;

所有葉子節點都在同一層,且為null;

有k顆子樹的節點,其關鍵字數為k-1,ceil(m/2)-1 <= keynum(x) <= m-1;

m/2+(m/2)^2+...+(m/2)^(h-1) = n

\frac = n

(m/2)^(h-1) = n+1

h = (log_(m/2) (n+1))+1

m+(m)^2+...+(m)^(h-1) = n

\frac = n

(m)^(h-1) = n+1

h = (log_(m) (n+1))+1

根節點至少2顆子樹(若存在子樹的情況下);

有n顆子樹的節點有n個關鍵字;

所有內節點僅存放索引,資料全部儲存在葉子節點上。

紅黑樹高度為35;

show index from pre_sales_rfq
其中id為主鍵,(id, name,create_date)聯合索引

explain select * from index_test where id = 1

and name = 'jackshawn'

and create_date = '2017-09-21'

explain select * from pre_sales_rfq where project_id = 1

and item_id = 1

explain select * from pre_sales_project_rfq where item_id = 1

and project_id = 1

explain select * from pre_sales_project_rfq where project_id = 1

(id, name,create_date)聯合索引

explain select * from index_test where id = 1

and create_date = '2017-09-21'

explain select * from pre_sales_project_rfq where item_id = 1

explain select * from index_test where id = 1

and name ='%jack'

explain select * from index_test where id = 1

and name ='jack%'

explain select * from index_test where id > 1

and name ='jackshawn'

explain select * from index_test where id in(1,4) and name ='jackshawn'

explain select * from index_test where id between 1

and4

and name ='jackshawn'

explain select * from index_test where id -1 = 1

and name ='jackshawn'

## 乙個欄位不重複的總量與資料總量的比值,越**擇性越好。

select

count(distinct(key))/count(*) as selectivity from

table;

2.查詢效率高。

## 舉例如下擷取last_name前4個字元

alter

table employees.employees

add index `first_name_last_name4` (first_name, last_name(4));

select

count(distinct(concat(first_name, left(last_name, 4))))/count(*) as selectivity from employees.employees;

mysql之count效能比較

1 count 1 count count 列 使用場景 set profiling 1 select sql no cache count from t pay process record select sql no cache count 1 from t pay process record...

唯一索引和普通索引效能比較

前提條件 有乙個資料列不會有重複資料現在需要選擇建立索引,我們應該如何去選擇呢?1.普通索引 查詢時,遇第乙個不符合條件的才返回。更新時,找到位置直接更新 2.唯一性索引 查詢時,遇到第乙個符合條件的直接返回。更新時,先查詢是否唯一,再找到位置然後再更新。我們來通過底層分析一下 select 我們都...

redis memcache 效能比較

from redis和memcache非常像的,都是key,value的方式,將資料存放記憶體中。最近在學習redis,在網上看了一些這方面的資料,有三種觀點 1,redis讀寫記憶體比memcache快 2,memcache讀寫記憶體比redis快 3,memcache讀寫記憶體比redis快,但...