MySQL源码中的BUG

来源:互联网 发布:棋牌游戏数据库设计 编辑:程序博客网 时间:2024/06/11 13:54

    今天在深入学习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信息中感到困惑。
原创粉丝点击