mysql 執行計劃詳解,Mysql中的explain執行計劃詳解(1)

創建一個表test_explain,并添加入下的數據

mysql> create ?table test_explain( a int primary key, b int);

Query OK, 0 rows affected (0.09 sec)

mysql> insert into test_explain value(1,1),(2,2),(3,3),(4,4),(5,5);

explian中的type字段:表示mysql在表中找到所需行的方式,或者叫訪問類型,常見的取值有ALL,INDEX ,RANGE,REF,EQ_REF,CONST(SYSTEM),NULL

情況1:type=all,全表掃描,mysql遍歷全表來找到匹配的行。

mysql> explain select b from test_explain where b>3\G;

*************************** 1. row ***************************

id: 1

select_type: SIMPLE

table: test_explain

partitions: NULL

type: ALL

possible_keys: NULL

key: NULL

key_len: NULL

ref: NULL

rows: 5

filtered: 33.33

Extra: Using where

1 row in set, 1 warning (0.01 sec)

情況2:type=index,索引掃描,MYSQL遍歷整個索引來查詢匹配的行

mysql> explain select a from test_explain where a>3\G;

*************************** 1. row ***************************

id: 1

select_type: SIMPLE

table: test_explain

partitions: NULL

type: index

possible_keys: PRIMARY

key: PRIMARY

key_len: 4

ref: NULL

rows: 5

filtered: 40.00

Extra: Using where; Using index

1 row in set, 1 warning (0.01 sec)

情況3:type=range,索引掃描范圍,常見于,>=,between等操作符

mysql> explain select * from test_explain where a>3 and a<5\G;

*************************** 1. row ***************************

id: 1

select_type: SIMPLE

table: test_explain

partitions: NULL

type: range

possible_keys: PRIMARY

key: PRIMARY

key_len: 4

ref: NULL

rows: 1

filtered: 100.00

Extra: Using where

1 row in set, 1 warning (0.01 sec)

情況4:type=ref,非唯一索引掃描或唯一索引掃描的前綴掃描,返回匹配某個單獨值的記錄行

首先為之前創建的表test_explain表的列b增加一個非唯一索引,操作如下:

mysql> alter table test_explain add index(b);,接著的實驗結果為:

mysql> explain select *from test_explain where b=3 \G

*************************** 1. row ***************************

id: 1

select_type: SIMPLE

table: test_explain

partitions: NULL

type: ref

possible_keys: b

key: b

key_len: 5

ref: const

rows: 1

filtered: 100.00

Extra: Using index

1 row in set, 1 warning (0.00 sec)

情況5:type=eq_ref,類似ref,區別就在使用的索引是唯一索引,對于每個索引鍵值,表中只有一條記錄匹配;簡單來說,就是在多表連接中使用primary key或者unique index作為關聯條件;注意的前提條件一定是多表連接中;

舉例:新建一個表test_explain2

mysql> create table test_explain2( d int primary key,

-> e char(10) unique key,

-> f int);

Query OK, 0 rows affected (0.08 sec)

mysql> insert into ?test_explain2 values(1,'a',1),(2,'b',2);

Query OK, 2 rows affected (0.04 sec)

Records: 2 ?Duplicates: 0 ?Warnings: 0

mysql> insert into ?test_explain2 values(3,'c',3),(4,'d',4);

Query OK, 2 rows affected (0.02 sec)

Records: 2 ?Duplicates: 0 ?Warnings: 0

接著來進行type=eq_ref的試驗驗證;

mysql> explain SELECT *from test_explain tt,test_explain2 ?yy where tt.a=yy.d \G

*************************** 1. row ***************************

id: 1

select_type: SIMPLE

table: yy

partitions: NULL

type: ALL

possible_keys: PRIMARY

key: NULL

key_len: NULL

ref: NULL

rows: 4

filtered: 100.00

Extra: NULL

*************************** 2. row ***************************

id: 1

select_type: SIMPLE

table: tt

partitions: NULL

type: eq_ref

possible_keys: PRIMARY

key: PRIMARY

key_len: 4

ref: test.yy.d

rows: 1

filtered: 100.00

Extra: NULL

2 rows in set, 1 warning (0.00 sec)

情況6:type=const/system,單表中最多有一個匹配行,查詢起來非常迅速,所以這個匹配行中的其他列值可以被優化器在當前查詢中當做常量來處理,例如根據主鍵或者唯一索引unique key進行的查詢;

mysql> explain select *from test_explain where a=1\G

*************************** 1. row ***************************

id: 1

select_type: SIMPLE

table: test_explain

partitions: NULL

type: const

possible_keys: PRIMARY

key: PRIMARY

key_len: 4

ref: const

rows: 1

filtered: 100.00

Extra: NULL

1 row in set, 1 warning (0.00 sec)

情況7:type=NULL,不用訪問表或者索引就可以得到結果,如;

mysql> EXPLAIN SELECT 3 \G *************************** 1. row *************************** ? ? ? ? ? ?id: 1 ? select_type: SIMPLE ? ? ? ? table: NULL ? ?partitions: NULL ? ? ? ? ?type: NULL possible_keys: NULL ? ? ? ? ? key: NULL ? ? ? key_len: NULL ? ? ? ? ? ref: NULL ? ? ? ? ?rows: NULL ? ? ?filtered: NULL ? ? ? ? Extra: No tables used 1 row in set, 1 warning (0.00 sec)

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/533200.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/533200.shtml
英文地址,請注明出處:http://en.pswp.cn/news/533200.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

mac php命令行模式,phpstorm分別在Mac和Windows下啟動命令行,并啟用ssh

Mac:在terminal下運行 sudo -i 輸入密碼 就可以用ssh IP:端口 命令行登錄了DAssist是一個命令行開發輔助&#xff0c;可直接在系統命令行工具中使用&#xff0c;Linux和MacOS等自帶命令終端的系統好說&#xff0c;windows下也有cmd和powerShell。那么如何結合開發IDE工具進行…

matlab 價格統計,matlab中的金融數據統計

1.均勻分布隨機數生成函數unidrnd(N&#xff0c;m&#xff0c;n)N生成1到N之間的一個隨機數&#xff0c;確定輸出矩陣m行&#xff0c;n列。2.生成連續均勻分布的隨機數unifrnd(A,B&#xff0c;m,n)A,B表示上下界。3.生成正態分布隨機數normrnd(mu,sigma,m,n)mu均值&#xff0c;…

php訪問js文件不存在,php文件里js不能被執行

我想把上傳文件路徑返回到前端保存&#xff0c;但是后臺php文件里的js沒有執行&#xff0c;前臺input標簽里的value值一直為空后臺acceptfile.php代碼如下:<?php if(!isset($_REQUEST[filename])){exit(No file);}else{$upload_path dirname(__FILE__)./audio;date_defaul…

php 零寬斷言,正則表達式之零寬斷言實例詳解【基于PHP】

這篇文章主要介紹了正則表達式之零寬斷言,簡單介紹了零寬斷言的概念、分類及php實現技巧與相關注意事項,需要的朋友可以參考下本文實例講述了正則表達式之零寬斷言。分享給大家供大家參考&#xff0c;具體如下&#xff1a;前言之前我曾寫了一篇關于正則表達式的文章(//www.jb51…

python 邏輯回歸準確率是1,Python利用邏輯回歸模型解決MNIST手寫數字識別問題詳解...

本文實例講述了Python利用邏輯回歸模型解決MNIST手寫數字識別問題。分享給大家供大家參考&#xff0c;具體如下&#xff1a;1、MNIST手寫識別問題MNIST手寫數字識別問題&#xff1a;輸入黑白的手寫阿拉伯數字&#xff0c;通過機器學習判斷輸入的是幾。可以通過TensorFLow下載MN…

php面試題接口方面,php面試題6 - osc_xb4v1nhl的個人空間 - OSCHINA - 中文開源技術交流社區...

php面試題6一、總結二、php面試題6寫出你認為語言中的高級函數:1)preg_replace()2)preg_match()3) ignore_user_abort()4) debug_backtrace()5) date_default_timezone_set(“PRC”)6) get_class_methods() 得到類的方法名的數組7) preg_split() 字符串分割成數組8)json_encode…

軌道車輛垂向振動Matlab建模與仿真,基于matlab/simulink的車輛建模與故障分析

隨著鐵路行業高速發展,列車運行速度逐漸提高,鐵路安全越來越受到人們的重視,如何保證鐵道車輛運行安全及其故障監測成為一個亟待解決的重大課題。客車車輛在結構上的故障主要有一系彈簧斷裂、減振器失效、空氣彈簧漏氣、高圓彈簧斷裂、車輪踏面擦傷、軸承故障以及蛇形減震器故障…

關于php的問題有哪些,關于PHP的報錯問題?

關于這個報錯的表格我不知到怎么去做&#xff0c;下面的是代碼&#xff1a;header(content-type:text/html;charsetutf-8);session_start();include_once ../include/conf.php;include_once ../include/func.php;include_once ../include/mysql.func.php;check_login();$pageSi…

oracle消耗內存的查詢,在AIX中計算ORACLE消耗的私有內存總數

一早就收到兄弟伙發的QQ信息&#xff0c;關于aix中oracle內存計算的內容The RSS number is equal to the sum of the number of working-segment pages in memory times 4 andthe code-segment pages in memory times 4.The TRS number is equal to just the code-segment page…

php讀取ds18b20,DS18B20_單總線協議

.H文件#ifndef _ONEWIRE_H#define _ONEWIRE_H#include "STC15F2K60S2.H"#include #define OW_SKIP_ROM 0xcc#define DS18B20_CONVERT 0x44#define DS18B20_READ 0xbe//IC引腳定義sbit DQ P1^4;//函數聲明extern void Delay_OneWire(unsigned int t);extern void Wri…

oracle官方文檔查看方法,oracle官方文檔_查看初始化參數(舉例)

深藍的blog&#xff1a;http://blog.csdn.net/huangyanlong/article/details/46864217記錄了一下&#xff0c;使用oracle11g聯機文檔&#xff0c;查看初始化參數的步驟。如果想查看&#xff0c;可以修改的初始化參數的概念信息&#xff0c;可以點擊“ChangingParameter Values …

matlab usewhitebg,Matlab的:geo??show的網格和框架

對於問題1和問題2&#xff0c;原因是軸總是在圖的後面。因此&#xff0c;一種解決方案是在當前的軸上添加新軸並顯示網格&#xff0c;框和自定義刻度。對於問題3&#xff0c;我使用regexprep以取代S後綴負緯度(同上爲經度)。我唯一的問題是經度0將是0E&#xff0c;緯度0,0N。這…

oracle p l,使用P.A.L制作便攜軟件 (一) 基本原理 | 么么噠擁有者

因愛好自學所得&#xff0c;并非專業&#xff0c;此處只是拋磚引玉&#xff0c;歡迎相互交流、學習、提高&#xff0c;辛苦碼字不易&#xff0c;如轉載望保留鏈接出處。簡單介紹&#xff1a;P.A.L是PortableApps.com Launcher的簡稱&#xff0c;它是PortableApps.com開發的便攜…

oracle form執行后左上角沒出現oracle標記,oracle form學習筆記

新增form步驟打開模板TEMPLATE&#xff0c;將其改成自己所要的名稱&#xff0c;刪除Data Blacks中的BLOCKNAME,DETAILBLOCK,刪除Canvases中的BLOCKNAME,刪除Windows中的BLOCKNAME,新增自己的Windows&#xff0c;Canvases&#xff0c;DateBlacks&#xff0c;在form級別的PRE-FOR…

linux 建oracle分區表,Oracle 10g 11g分區表創建舉例

1.3. 創建其他類型分區表1.3.1. 用多列分區鍵創建范圍分區表SQL> create table aning_mutilcol_range2 (aning_id number,3 aning_name varchar2(100),4 aning_year number,5 aning_month number,6 aning_day number,7 aning_amount number8 )9 partition by range (aning_y…

php carbon 連續日期,日期及時間處理包 Carbon 在 Laravel 中的簡單使用

在編寫 PHP 應用時經常需要處理日期和時間&#xff0c;這篇文章帶你了解一下 Carbon – 繼承自 PHP DateTime 類的 API 擴展&#xff0c;它使得處理日期和時間更加簡單。Laravel 中默認使用的時間處理類就是 Carbon。namespace Carbon;class Carbon extends \DateTime{// code …

chmod g s oracle,chmod

chmod(1)名稱chmod - 更改文件的權限模式用法概要chmod [-fR] absolute-mode file...chmod [-fR] symbolic-mode-list file...chmod [-fR] acl_operation file...chmod [-fR] [- named_attribute]...attribute_specification_list file...描述chmod 實用程序可更改或分配文件的…

linux lzo 壓縮文件,Linux常用壓縮和解壓命令

.tar 解包 tar xvf filename.tar.tar 打包 tar cvf filename.tar dirname.gz 解壓1 gunzip filename.gz.gz 解壓2 gzip -d filename.gz.gz 壓縮 gzip filename.tar.gz 和 .tgz 解壓 tar zxvf filename.tar.gz.tar.gz 和 .tgz 壓縮 tar zcvf filename.tar.gz dirname.bz2 解壓1 …

linux進程cpu時間片,能講一下在Linux系統中時間片是怎么分配的還有優先級的具體算法是...

該樓層疑似違規已被系統折疊 隱藏此樓查看此樓圖 1 RT-Linux結構RT -Linux的關鍵技術是通過軟件來模擬硬件的中斷控制器。當Linux系統要封鎖CPU的中斷時時&#xff0c;RT-Linux中的實時子系統會截取到這個請求&#xff0c;把它記錄下來&#xff0c;而實際上并不真正封鎖硬件中斷…

linux中進行遠程服務器連機可以采用telnet,端口號為,使用telnet測試指定端口的連通性...

原標題&#xff1a;使用telnet測試指定端口的連通性telnet 是一個閹割版的 ssh &#xff0c;它數據不加密&#xff0c;數據容易被盜竊&#xff0c;也容易受中間人攻擊&#xff0c;所以默認情況下 telnet 端口是必須要被關閉的。telnet為用戶提供了在本地計算機上完成遠程主機工…