show index通常用來查詢表結構中的索引情況:
-- 表的結構 `login_total_2018`
--create table `login_total_2018` (
`id` int(11) not null,
`tdate` date not null comment '登入時間',
`agent_id` int(11) not null comment '渠道id',
`site_id` int(11) not null default '0' comment '廣告位id',
`cplaceid` varchar(50) default null comment '子id',
`adid` varchar(20) default null comment '創意id',
`turn` int(11) unsigned not null comment '輪數id',
`login_count` int(11) not null comment '賬號數',
`active` int(11) unsigned not null comment '活躍天數(0:當天)',
`plat_id` int(11) unsigned not null comment '平台id'
) engine=myisam default charset=utf8;
存在以下索引:
--
-- indexes for table `login_total_2018`
--alter table `login_total_2018`
add primary key (`id`),
add key `tdate` (`tdate`),
add key `agent_id` (`agent_id`),
add key `site_id` (`site_id`),
add key `plat_id` (`plat_id`),
add key `active` (`active`);
---- 使用表auto_increment `login_total_2018`
--alter table `login_total_2018`
modify `id` int(11) not null auto_increment;
commit;
那麼查詢當前表的索引:
show index from `login_total_2018`
結果如下:
在mysql中的** 他是對下面的字段這樣解釋的
table : 表的名稱
non_unique : 如果該列索引中不包括重複的值則為0 否則為1
key_name : 索引名稱,如果是主鍵的話 則為primary
seq_in_index : 索引中序列的序列號,從1開始,如果是組合索引 那麼按照欄位在建立索引時的順序排列 如 ('c1', 'c2', 'c3') 那麼 分別為 1, 2, 3
column_name : 列的名稱
collation : 列以什麼方式儲存在索引中。在mysql中,有值『a』(公升序)或null(無分序)
cardinality : 索引中唯一值的數目的估計值,通過執行 analyze table or myisamchk -a 來更新,基數根據被儲存為整數的統計資料來計數,所以對於小表該值沒必要太過於精確,而對於大資料量的表來說,改值越大當進行聯合時,mysql使用該索引的機 會就越大。
sub_part : 索引的長度,如果是部分被編入索引 則該值表示索引的長度 ,如果是整列被編入索引則為null,例如name_index和school_index 兩個索引,比較一下上面兩個索引建立時候的區別
packed : 指示關鍵字如何被壓縮。如果沒有被壓縮,則為null
null : 如果該列的值有null,則是yes 否則為no..
index_type : 所用索引方法(btree, fulltext, hash, rtree)
commnet : 關於在其列中沒有描述的索引的資訊
SHOW INDEX語法 檢視索引狀態
show index from tbl name from db name show index會返回表索引資訊。其格式與odbc中的sqlstatistics呼叫相似。show index會返回以下字段 table 表的名稱。non unique 如果索引不能包括重複詞,則為0。如果可以,則為1。...
MySQ樹狀結構資料 遞迴查詢
for example create table products id int,name varchar 100 parent id int insert into products values 15,category15 0 not a descendant of 19 16,category...
Mysq實現序號排名查詢以及問題記錄
1 mysql獲取序號排名 在查詢前需要懂得 與 的區別 賦值的意思。在set update select 中表示賦值的意思,用的比較少一般都用 但是在用變數實現行號時 比如本文標題獲取排列序號 一定要用 等於的意思,只有當set 和 update時,和 的意思是一樣的,表示賦值,其餘情況都是等於的...