欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

MySQL源码中的BUG

程序员文章站 2022-05-23 21:09:30
...

今天在深入学习MySQL查询优化器的过程中,发现一个低级的错误,应该是开发人员出于笔误导致的,当然这个错误不会出现问题,仅仅会

今天在深入学习MySQL查询优化器的过程中,发现一个低级的错误,应该是开发人员出于笔误导致的,当然这个错误不会出现问题,仅仅会在debug环境下,输出trace信息的时候会误导开发人员。

现公布如下:

本文基于mysql-5.5.20源代码进行调试开发。

sql_select.cc文件的5439行,代码如下:

  • print_planidxrecord_count

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

  • /*
  • print_plan()
  • the structure providing all context info for
  • the query
  • read_time the cost of the best partial plan
  • record_count estimatethe number of records returned by the best
  • partial plan
  • idx length of the partial QEPpositions';
  • also an indexthebest_ref';
  • info commentappear above the printout
  • */
  • void
  • print_planuint idxdouble read_time,
  • double current_read_timechar *info)
  • 因此,sql_select.cc文件的5439行的代码应该讲read_time和record_count的顺序颠倒。修改后的代码如下:

  • print_planidxread_time

    由于这个错误,会在打印输出的debug trace信息中感到困惑。

    MySQL源码中的BUG