• 通过trace分析优化器如何选择执行计划


    1.

    mysql> show variables like "optimizer_trace%"G;
    *************************** 1. row ***************************
    Variable_name: optimizer_trace
    Value: enabled=off,one_line=off
    *************************** 2. row ***************************
    Variable_name: optimizer_trace_features
    Value: greedy_search=on,range_optimizer=on,dynamic_range=on,repeated_subselect=on
    *************************** 3. row ***************************
    Variable_name: optimizer_trace_limit
    Value: 1
    *************************** 4. row ***************************
    Variable_name: optimizer_trace_max_mem_size
    Value: 16384
    *************************** 5. row ***************************
    Variable_name: optimizer_trace_offset
    Value: -1
    5 rows in set (0.01 sec)

    2.打开trace,设置格式为json,设置trace最大能够使用的内存大小,避免解析过程中因为默认内存过小而不能够完整显示。

    mysql> use sakila
    Reading table information for completion of table and column names
    You can turn off this feature to get a quicker startup with -A

    Database changed
    mysql> select rental_id from rental where 1=1 and rental_date >='2005-05-25 04:00:00' and rental_date <='2005-05-25 05:00:00' and inventory_id=4466;
    +-----------+
    | rental_id |
    +-----------+
    | 39 |
    +-----------+
    1 row in set (0.00 sec)

    3.检查MySQL是如何执行SQL的。

    mysql> use information_schema 

    mysql> select * from OPTIMIZER_TRACEG;
    *************************** 1. row ***************************
    QUERY: SELECT DATABASE()
    TRACE: {
    "steps": [
    {
    "join_preparation": {
    "select#": 1,
    "steps": [
    {
    "expanded_query": "/* select#1 */ select database() AS `DATABASE()`"
    }
    ] /* steps */
    } /* join_preparation */
    },
    {
    "join_optimization": {
    "select#": 1,
    "steps": [
    ] /* steps */
    } /* join_optimization */
    },
    {
    "join_execution": {
    "select#": 1,
    "steps": [
    ] /* steps */
    } /* join_execution */
    }
    ] /* steps */
    }
    MISSING_BYTES_BEYOND_MAX_MEM_SIZE: 0
    INSUFFICIENT_PRIVILEGES: 0
    1 row in set (0.00 sec)

  • 相关阅读:
    event.relatedTarget、event.fromElement、event.toElement
    before/after伪类常见用法
    $.getJSON 跨域
    ExtJS中store.findExact
    C#生成6位随机验证码
    C#验证手机号
    jQuery轮播图的事项 代码详细,容易理解。。。。谢谢观赏
    ES6 中 static 的this 丢失问题解决办法 简单明了 备注清晰 谢谢欣赏
    ES6 中 static 的this 问题 简单明了 备注清晰 谢谢欣赏
    ES6 中用class创建img 详细明了,步骤清晰,解释完美,谢谢欣赏
  • 原文地址:https://www.cnblogs.com/chinaops/p/10373687.html
Copyright © 2020-2023  润新知