Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1689464
  • 博文数量: 107
  • 博客积分: 1715
  • 博客等级: 上尉
  • 技术积分: 3168
  • 用 户 组: 普通用户
  • 注册时间: 2012-04-18 18:42
个人简介

阿里巴巴DBA,原去哪儿网DBA。专注于MySQL源码研究、DBA运维、CGroup虚拟化及Linux Kernel源码研究等。 github:https://github.com/HengWang/ Email:king_wangheng@163.com 微博 :@王恒-Henry QQ :506437736

文章分类

全部博文(107)

文章存档

2014年(2)

2013年(38)

2012年(67)

分类: Mysql/postgreSQL

2012-07-24 18:09:06

    今天在深入学习MySQL查询优化器的过程中,发现一个低级的错误,应该是开发人员出于笔误导致的,当然这个错误不会出现问题,仅仅会在debug环境下,输出trace信息的时候会误导开发人员。
    现公布如下:
    本文基于mysql-5.5.20源代码进行调试开发。
    sql_select.cc文件的5439行,代码如下:

点击(此处)折叠或打开

  1. DBUG_EXECUTE("opt", print_plan(join, idx, read_time, record_count, idx,
  2.                                  "SOFAR:"););

    其中通过查看print_plan函数可以发现,输入参数:read_time和record_count的顺序是错误的。print_plan函数在sql_test.cc的266行定义如下:

点击(此处)折叠或打开

  1. /*
  2.  print_plan()
  3.     join pointer to the structure providing all context info for
  4.                  the query
  5.     read_time the cost of the best partial plan
  6.     record_count estimate for the number of records returned by the best
  7.                  partial plan
  8.     idx length of the partial QEP in 'join->positions';
  9.                  also an index in the array 'join->best_ref';
  10.     info comment string to appear above the printout
  11. */
  12. void
  13. print_plan(JOIN* join, uint idx, double record_count, double read_time,
  14.            double current_read_time, const char *info)
    因此,sql_select.cc文件的5439行的代码应该讲read_time和record_count的顺序颠倒。修改后的代码如下:    

点击(此处)折叠或打开

  1. DBUG_EXECUTE("opt", print_plan(join, idx, record_count, read_time, idx,
  2.                                  "SOFAR:"););
    由于这个错误,会在打印输出的debug trace信息中感到困惑。
    

    
阅读(1998) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~