Mysql Prepared statement needs to be re-prepared

gaopengtttt發表於2018-01-04

這個是我自己的筆記沒有閱讀性。也沒仔細看。但是記錄下斷點以後好研究。

朋友遇到這個錯修改了引數
| table_definition_cache | 1400 |
| table_open_cache | 2000 |
均設定為16384就好了。

但是他搞不明白有什麼關係。我就看了一下這個報錯的錯誤碼
{ "ER_NEED_REPREPARE", 1615, "Prepared statement needs to be re-prepared" },
分析後他應該是在函式check_and_update_table_version中丟擲來的。
其註釋有

 Compare metadata versions of an element obtained from the table
  definition cache and its corresponding node in the parse tree. 

其邏輯有

static bool
check_and_update_table_version(THD *thd,
                               TABLE_LIST *tables, TABLE_SHARE *table_share)
{ if (! tables->is_table_ref_id_equal(table_share))
  {
    Reprepare_observer *reprepare_observer= thd->get_reprepare_observer(); if (reprepare_observer &&
        reprepare_observer->report_error(thd)) //這裡如果前面的指標為NULL則觸發這個報錯邏輯 { /*
        Version of the table share is different from the
        previous execution of the prepared statement, and it is
        unacceptable for this SQLCOM. Error has been reported.
      */ DBUG_ASSERT(thd->is_error()); return TRUE;
    } /* Always maintain the latest version and type */ tables->set_table_ref_id(table_share);
  }

  DBUG_EXECUTE_IF("reprepare_each_statement", return inject_reprepare(thd);); return FALSE;
} 

看來他們確實有聯絡,但是怎麼聯絡的說不上來,這個觀察者搞毛線的我也不知道。以後再說。
斷點設定

1 breakpoint     keep y 0x0000000000ebd5f3 in main(int, char**) at /root/mysql5.7.14/percona-server-5.7.14-7/sql/main.cc:25 breakpoint already hit 1 time 4 breakpoint     keep y 0x00000000016a04bd in open_table_from_share(THD*, TABLE_SHARE*, char const*, uint, uint, uint, TABLE*, bool)
                                               at /root/mysql5.7.14/percona-server-5.7.14-7/sql/table.cc:3038 breakpoint already hit 4 times 5 breakpoint     keep y 0x0000000001519a10 in check_and_update_table_version(THD*, TABLE_LIST*, TABLE_SHARE*)
                                               at /root/mysql5.7.14/percona-server-5.7.14-7/sql/sql_base.cc:4219 breakpoint already hit 4 times 6 breakpoint     keep y 0x00000000015285bb in Table_cache::add_used_table(THD*, TABLE*) at /root/mysql5.7.14/percona-server-5.7.14-7/sql/table_cache.h:353 breakpoint already hit 2 times 7 breakpoint     keep y 0x0000000001527427 in TABLE_LIST::set_table_ref_id(enum_table_ref_type, ulonglong)
                                               at /root/mysql5.7.14/percona-server-5.7.14-7/sql/table.h:2100 8 breakpoint     keep y 0x00000000015273e3 in TABLE_LIST::set_table_ref_id(TABLE_SHARE*) at /root/mysql5.7.14/percona-server-5.7.14-7/sql/table.h:2095 breakpoint already hit 1 time

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/7728585/viewspace-2149689/,如需轉載,請註明出處,否則將追究法律責任。

相關文章