手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

MySQL源码中的BUG

[日期:2012-08-09] 来源:Linux社区  作者:king_wangheng [字体:大 中 小]

今天在深入学习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的顺序颠倒。修改后的代码如下:

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

    linux
    相关资讯       MySQL源码 
    本文评论   查看全部评论 (0)
    表情: 表情 姓名: 字数

           

    评论声明
    • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
    • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
    • 本站管理人员有权保留或删除其管辖留言中的任意内容
    • 本站有权在网站内转载或引用您的评论
    • 参与本评论即表明您已经阅读并接受上述条款