MySQL源碼中的BUG

    今天在深入學習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信息中感到困惑。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章