慢查询日志-explain来了解SQL执行的状态

explain显示了mysql如何使用索引来处理select语句以及连接表。可以帮助选择更好的索引和写出更优化的查询语句。

使用方法,在select语句前加上explain就可以了,例如下:

explainselectorderId, orderNo, GroupId,supplierGroupId, consignerGroupId, orderType, orderStatus,contractType, contractNos, transferMethod,refInfoNo, orderSource, consignerCompanyCode,consignerCompanyName, platformOpenId,platformName, supplierCode, supplierName, supplierUserId,requireFeedbakTime, actualFeedbackTime,etd, eta, atd, ata, sourceLocationCode, sourceProvinceName,sourceProvinceCode, sourceCityName,sourceCityCode, sourceCountyName, sourceCountyCode,sourceAddress, sender, senderMobile,senderTel, sourceLocationQty, sourceLatitude,targetLocationCode, targetProvinceName,targetProvinceCode, targetCityName, targetCityCode,targetCountyName, targetCountyCode,targetAddress, receiver, receiverMobile, receiverTel,targetLocationQty, targetLatitude,vichleLimitCode, boxCategory, boxType, boxLength,equipmmentQty, goodsCategory, goodsType,goodsName, goodsNorms, goodsPack, goodsNumber,goodsTotalWeight, goodsMaxSingleVolumn,goodsMaxSingleWeight, goodsTotalVolume, volumnUnit,weightUnit, lengthUnit, goodsValue,goodsRemark, serviceConstraints, podReturnMethod,billPeriodCode, payMethodCode,donePayCost, billTermsCode, totalCost, prePayCost,prePayMethodCode, prePaySatus, isNeedInvoice,invoiceType, taxRate, planConfirmDate,confirmDate, remark, addUser, addDate, modifyUser, modifyTimefrom order_orderinfoWHERE (requireFeedbakTime <= ‘2017-04-25 17:35:49.904’and orderStatus = 10 );

结果如下:

《慢查询日志-explain来了解SQL执行的状态》

EXPLAIN列的解释

table列:显示这一行的数据是关于哪张表的

type列:这是重要的列,显示连接使用了何种类型。从最好到最差的连接类型为const、eq_reg、ref、range、index和ALL

possible_keys列:显示可能应用在这张表中的索引。如果为空,没有可能的索引。可以为相关的域从WHERE语句中选择一个合适的语句

key列:实际使用的索引。如果为NULL,则没有使用索引。很少的情况下,MYSQL会选择优化不足的索引。这种情况下,可以在SELECT语句中使用USE INDEX(indexname)来强制使用一个索引或者用IGNORE INDEX(indexname)来强制MYSQL忽略索引

key_len列:使用的索引的长度。在不损失精确性的情况下,长度越短越好

ref列:显示索引的哪一列被使用了,如果可能的话,是一个常数

rows列:MYSQL认为必须检查的用来返回请求数据的行数

Extra列:关于MYSQL如何解析查询的额外信息。�”ߏ��u

    原文作者:温东
    原文地址: https://www.jianshu.com/p/d3a7b8653884
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞