create
table
`employees`
(`id`
int(11)
notnull
auto_increment
,`name`
varchar(24
)not
null
default
''comment
'姓名'
,`age`
int(11)
notnull
default
'0'comment
'年齡'
,`position`
varchar(20
)not
null
default
''comment
'職位'
,`hire_time`
timestamp
notnull
default
current_timestamp
comment
'入職時間'
,primary
key(
`id`),
key`idx_name_age_position`
(`name`
,`age`
,`position`
)using
btree
)engine
=innodb
auto_increment=1
default
comment
='員工記錄表'
;insert
into employees(name,age,position,hire_time)
values
('lilei',22
,'manager'
,now()
);insert
into employees(name,age,position,hire_time)
values
('hanmeimei',23
,'dev'
,now()
);insert
into employees(name,age,position,hire_time)
values
('lucy',23
,'dev'
,now()
);‐‐ 插入100000示例資料
-- 測試小例子:
-- 先關閉mysql的查詢快取,得到真實的查詢效率
setglobal query_cache_size=0;
setglobal query_cache_type=0;
-- 執行時間7.541s
select
*from employees where name >
'lilei'
;-- 執行時間7.769s
-- 測試小例子:employees_copy1表只有少量的資料,所以沒有走索引
在innodb儲存引擎中,索引下推只能用於二級索引,因為在聚餐索引(主鍵索引)中,最下方的葉子節點儲存了整行資料,所以使用索引下推也沒有效率的提公升
至於範圍查詢索引沒有使用索引下推:因為範圍查詢索引的結果集一般比較大,而like %查詢結果集大多數比較小,所以mysql給like%使用索引下推而範圍查詢沒有,當然like%也不一定都會走索引下推;
mysql索引了解一下
索引是mysql中非常重要的知識,類似於書籍的目錄,可以提高檢索效率,降低資料庫的io成本。本文主要介紹最常用的b tree索引。b tree索引結構見上圖。最底下的是葉子節點,上層是非葉子節點。非葉子節點中存放鍵值和指向下層的指標 葉子節點存放鍵值和資料,存放的資料根據實現的不同而不同。例如 可以...
mysql優化之覆蓋索引
1 當發起乙個被索引覆蓋的查詢時,在explain的extra列可以看到using index的資訊,此時就使用了覆蓋索引 mysql explain select store id,film id from inventory g 1.row id 1 select type table inve...
記錄一下需要優化的東西
優化 1,減少dc 2,圖集打包 3,減低模型片面數 三角面 4,使用光照貼圖,烘焙貼圖 使用著色器 高效shader 5,遮擋剔除 6,物件池 7,多細節層次 lod 8,mipmap 9,使用預設 10,壓縮類庫 11,降低解析度 12,關閉垂直同步 13,粒子特效優化 14,優化地形 15,記...