欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

Innodb中怎么查詢存儲引擎查

本篇文章給大家分享的是有關(guān)Innodb中怎么查詢存儲引擎查,小編覺得挺實(shí)用的,因此分享給大家學(xué)習(xí),希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。

創(chuàng)新互聯(lián)公司是一家專業(yè)提供商丘企業(yè)網(wǎng)站建設(shè),專注與成都網(wǎng)站設(shè)計(jì)、網(wǎng)站制作HTML5建站、小程序制作等業(yè)務(wù)。10年已為商丘眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)網(wǎng)站建設(shè)公司優(yōu)惠進(jìn)行中。


源碼分析
查詢于存儲引擎的實(shí)現(xiàn)密切相關(guān),因此,以下內(nèi)容主要針對Innodb存儲引擎的查詢處理進(jìn)行深入研究。對于查詢輸出的入口點(diǎn),本文從do_select()(sql\sql_select.cc)函數(shù)開始。該函數(shù)主要用于查詢匹配的結(jié)果,并將查詢結(jié)果通過socket傳輸,或者寫到數(shù)據(jù)表中。
首先看一下調(diào)用邏輯,如下所示:

do_select(): 查詢?nèi)肟诤瘮?shù)。
| sub_select(): 查詢部分join的記錄。循環(huán)調(diào)用ha_innobase::rnd_next()和evaluate_join_record()獲取并處理該部分的每條記錄。(sql\sql_select.cc:11705)
| | evaluate_join_record(): 處理一條查詢記錄。(sql\sql_select.cc:11758)
| | rr_sequential():調(diào)用ha_innobase::rnd_next()讀取下一條記錄。(sql\records.cc:452)
| | | ha_innobase::rnd_next(): 讀取下一條記錄。(storage\innobase\handler\ha_innodb.cc:6141)
| | | | ha_innobase::general_fetch(): 從給定的索引位置獲取下一條或上一條記錄。(storage\innobase\handler\ha_innodb.cc:5948)
| | | | | row_search_for_MySQL(): 從數(shù)據(jù)庫中查詢一條記錄。以下分為6個階段分別處理各個部分。(storage\innobase\row\row0sel.c:3369)
| | | | | | 第一階段:釋放自適應(yīng)hash索引的鎖。
| | | | | | | rw_lock_get_writer()函數(shù)用于獲取讀寫鎖。如果獲取失敗,釋放目前的讀寫鎖。(storage\innobase\include\sync0rw.ic:122)
| | | | | | 第二階段:從預(yù)讀的cache中獲取記錄。
| | | | | | | row_sel_pop_cached_row_for_mysql():函數(shù)用于從cache中讀取一行記錄,(storage\innobase\row\row0sel.c:3167)
| | | | | | | | row_sel_copy_cached_field_for_mysql(): 函數(shù)讀取每個字段。(storage\innobase\row\row0sel.c:3134)
| | | | | | 第三階段:使用自適應(yīng)hash索引快速查找。
| | | | | | | row_sel_try_search_shortcut_for_mysql()函數(shù)使用hash索引獲取聚集索引的記錄。(storage\innobase\row\row0sel.c:3293)
| | | | | | | | row_sel_store_mysql_rec()函數(shù)將獲取的innobase格式的行記錄轉(zhuǎn)化為mysql格式。(storage\innobase\row\row0sel.c:2692)
| | | | | | | | | row_sel_field_store_in_mysql_format()函數(shù)將innobase格式的行記錄中的每個字段轉(zhuǎn)化為mysql格式。(storage\innobase\row\row0sel.c:2535)
| | | | | | 第四階段:打開并恢復(fù)索引的游標(biāo)位置。
| | | | | | | sel_restore_position_for_mysql(): 恢復(fù)索引的游標(biāo)位置。(storage\innobase\row\row0sel.c:3070)
| | | | | | | | btr_pcur_restore_position_func(): 恢復(fù)一個持久化游標(biāo)的位置。(storage\innobase\btr\btr0pcur.c:208)
| | | | | | | | | btr_cur_get_index(): 獲取索引。(storage\innobase\include\btr0pcur.ic:51)
| | | | | | | | | buf_page_optimistic_get():
| | | | | | | | | btr_pcur_get_rec(): 獲取持久化游標(biāo)的記錄。(storage\innobase\include\btr0pcur.ic:104)
| | | | | | | | | | btr_cur_get_rec (): 獲取當(dāng)前游標(biāo)位置的記錄。(storage\innobase\include\btr0pcur.ic:104)
| | | | | | | | | rec_get_offsets_func(): 獲取記錄中每個字段的偏移。(storage\innobase\rem\rem0rec.c:524)
| | | | | | | | btr_pcur_move_to_next(): 移動持久化游標(biāo)到下一條記錄。(storage\innobase\include\btr0pcur.ic:342)
| | | | | | 第五階段:查找匹配的記錄。
| | | | | | | page_rec_is_infimum(): 查看當(dāng)前記錄是否是該頁的infinum記錄。infinum記錄表示比任何鍵值都小的記錄。(storage\innobase\include\page0page.ic:415)
| | | | | | | page_rec_is_supermum(): 查看當(dāng)前記錄是否是該頁的supermum記錄。supermum記錄表示比任何鍵值都大的記錄。(storage\innobase\include\page0page.ic:403)
| | | | | | | rec_get_next_offs(): 獲取相同頁中下一條記錄的偏移量。(storage\innobase\include\rem0rec.ic:325)
| | | | | | | rec_get_offsets_func(): 獲取記錄中每個字段的偏移。(storage\innobase\rem\rem0rec.c:524)
| | | | | | | rec_offs_validate():驗(yàn)證記錄的偏移量。(storage\innobase\rem\rem0rec.c:954)
| | | | | | | row_sel_store_mysql_rec()函數(shù)將獲取的innobase格式的行記錄轉(zhuǎn)化為mysql格式。(storage\innobase\row\row0sel.c:2692)
| | | | | | | | row_sel_field_store_in_mysql_format()函數(shù)將innobase格式的行記錄中的每個字段轉(zhuǎn)化為mysql格式。(storage\innobase\row\row0sel.c:2535)
| | | | | | | | btr_pcur_store_position(): 存儲游標(biāo)的位置。(storage\innobase\btr\btr0pcur.c:89)
| | | | | | | | | btr_pcur_get_block(): 獲取持久化游標(biāo)的緩沖塊。(storage\innobase\include\btr0pcur.ic:90)
| | | | | | | | | btr_pcur_get_page_cur(): 獲取持久化游標(biāo)的頁的游標(biāo)。(storage\innobase\include\btr0pcur.ic:64)
| | | | | | | | | page_cur_get_rec(): 獲取游標(biāo)位置的記錄。(storage\innobase\include\page0cur.ic:76)
| | | | | | | | | dict_index_copy_rec_order_prefix(): 拷貝記錄。(storage\innobase\dict\dict0dict.c:4185)
| | | | | | | | | | rec_copy_prefix_to_buf(): 拷貝記錄的字段到緩存buffer中。(storage\innobase\rem\rem0rec.c:1383)
| | | | | | | | | | dict_index_get_nth_field(): 獲取第n個字段的起始地址。(storage\innobase\include\dict0dict.ic:620)
| | | | | | | | | | dict_field_get_col(): 獲取第n個字段的值。(storage\innobase\include\dict0dict.ic:663)
| | | | | | 第六階段:移動游標(biāo)到下一個索引記錄。
| | | | | | | btr_pcur_move_to_next(): 移動持久化游標(biāo)到下一條記錄。(storage\innobase\include\btr0pcur.ic:342)
| | | | | | | mtr_commit(): 提交事務(wù)。(storage\innobase\mtr\mtr0mtr.c:247)

 
       從以上查詢邏輯,可以清晰的看出,MySQL的查詢時如何進(jìn)行的。概言之,如果可以從自適應(yīng)hash索引(在內(nèi)存中)中得到結(jié)果,獲取結(jié)果從innobase格式轉(zhuǎn)化為mysql格式并輸出;否則,根據(jù)索引的游標(biāo)位置,獲取當(dāng)前頁中的記錄,并拷貝當(dāng)前記錄到內(nèi)存,同樣將結(jié)果轉(zhuǎn)化為mysql格式輸出。
       從以上內(nèi)容中,很難看出輸出結(jié)果有什么規(guī)律。實(shí)際上,輸出的結(jié)果是有一定規(guī)律的,這種規(guī)律與innodb存儲引擎的設(shè)計(jì)和存儲密切相關(guān)。
innodb存儲引擎的存儲是按照B+索引將主鍵作為鍵值進(jìn)行聚集存儲的,如果不指定主鍵,系統(tǒng)會隱藏建立一個主鍵。innodb存儲引擎中所有的葉子節(jié)點(diǎn)為數(shù)據(jù)記錄,并且數(shù)據(jù)記錄邏輯上可以順序訪問。并且innodb存儲引擎的數(shù)據(jù)存儲和獲取是按照頁來進(jìn)行的。因此,在查詢時,會將整個頁的數(shù)據(jù)加載到內(nèi)存中,innodb存儲引擎的默認(rèn)頁大小為16K。
實(shí)驗(yàn)測試
通過以上分析,不難理解,在查詢時,簡單查詢的輸出結(jié)果是一般按照B+索引的存儲順序排列的。為了進(jìn)一步的驗(yàn)證,進(jìn)行一下兩個實(shí)驗(yàn)
實(shí)驗(yàn)1:
以簡單的帶有主鍵的數(shù)據(jù)表student,表定義如下表所示。測試語句以簡單的select * from student;為例,進(jìn)行測試。
 

CREATE TABLE `student` (
  `std_id` int(11) NOT NULL,
  `std_name` varchar(20) NOT NULL DEFAULT '""',
  `std_spec` varchar(20) NOT NULL DEFAULT '""',
  `std_***` tinyint(4) NOT NULL DEFAULT '0',
  `std_age` tinyint(3) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`std_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

 
測試結(jié)果如下所示:
 

mysql> select * from student;
+------------+----------+-------------+---------+---------+
| std_id     | std_name | std_spec    | std_*** | std_age |
+------------+----------+-------------+---------+---------+
| 2012072301 | aaa      | computer    |       0 |      20 |
| 2012072303 | ccc      | computer    |       1 |      21 |
| 2012072304 | ddd      | computer    |       0 |      20 |
| 2012072305 | eee      | information |       0 |      22 |
| 2012072306 | fff      | computer    |       1 |      20 |
| 2012072307 | ggg      | computer    |       0 |      20 |
| 2012072308 | hhh      | computer    |       0 |      21 |
| 2012072309 | iii      | automatic   |       0 |      20 |
| 2012072310 | abc      | computer    |       1 |      20 |
| 2012072311 | kkk      | computer    |       0 |      18 |
| 2012072312 | lll      | computer    |       0 |      20 |
| 2012072313 | mmm      | computer    |       0 |      20 |
| 2012072314 | nnn      | computer    |       1 |      20 |
| 2012072315 | ooo      | information |       0 |      20 |
| 2012072316 | ppp      | computer    |       0 |      19 |
| 2012072317 | qqq      | computer    |       1 |      20 |
| 2012072318 | rrr      | information |       0 |      20 |
| 2012072319 | sss      | computer    |       1 |      20 |
| 2012072320 | ttt      | computer    |       0 |      20 |
| 2012072321 | uuu      | automatic   |       0 |      23 |
| 2012072322 | vvv      | computer    |       0 |      20 |
| 2012072323 | www      | computer    |       1 |      20 |
| 2012072324 | xxx      | computer    |       0 |      25 |
| 2012072325 | yyy      | automatic   |       0 |      20 |
| 2012072326 | zzz      | computer    |       1 |      20 |
| 2012080811 | bbb      | information |       0 |      20 |
+------------+----------+-------------+---------+---------+

 
實(shí)驗(yàn)2
       同樣以student表為例,將主鍵為2012080811的記錄更新操作,操作如下:
 

update student set std_id=2012072302 where std_id=2012080811;

 
       然后,在進(jìn)行測試,測試結(jié)果如下所示:
 

+------------+----------+-------------+---------+---------+
| std_id     | std_name | std_spec    | std_*** | std_age |
+------------+----------+-------------+---------+---------+
| 2012072301 | aaa      | computer    |       0 |      20 |
| 2012072302 | bbb      | information |       0 |      20 |
| 2012072303 | ccc      | computer    |       1 |      21 |
| 2012072304 | ddd      | computer    |       0 |      20 |
| 2012072305 | eee      | information |       0 |      22 |
| 2012072306 | fff      | computer    |       1 |      20 |
| 2012072307 | ggg      | computer    |       0 |      20 |
| 2012072308 | hhh      | computer    |       0 |      21 |
| 2012072309 | iii      | automatic   |       0 |      20 |
| 2012072310 | abc      | computer    |       1 |      20 |
| 2012072311 | kkk      | computer    |       0 |      18 |
| 2012072312 | lll      | computer    |       0 |      20 |
| 2012072313 | mmm      | computer    |       0 |      20 |
| 2012072314 | nnn      | computer    |       1 |      20 |
| 2012072315 | ooo      | information |       0 |      20 |
| 2012072316 | ppp      | computer    |       0 |      19 |
| 2012072317 | qqq      | computer    |       1 |      20 |
| 2012072318 | rrr      | information |       0 |      20 |
| 2012072319 | sss      | computer    |       1 |      20 |
| 2012072320 | ttt      | computer    |       0 |      20 |
| 2012072321 | uuu      | automatic   |       0 |      23 |
| 2012072322 | vvv      | computer    |       0 |      20 |
| 2012072323 | www      | computer    |       1 |      20 |
| 2012072324 | xxx      | computer    |       0 |      25 |
| 2012072325 | yyy      | automatic   |       0 |      20 |
| 2012072326 | zzz      | computer    |       1 |      20 |
+------------+----------+-------------+---------+---------+

以上就是Innodb中怎么查詢存儲引擎查,小編相信有部分知識點(diǎn)可能是我們?nèi)粘9ぷ鲿姷交蛴玫降摹OM隳芡ㄟ^這篇文章學(xué)到更多知識。更多詳情敬請關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

文章名稱:Innodb中怎么查詢存儲引擎查
URL分享:http://chinadenli.net/article6/goggog.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制開發(fā)軟件開發(fā)全網(wǎng)營銷推廣網(wǎng)站排名企業(yè)網(wǎng)站制作網(wǎng)站營銷

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)