<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ## bug描述 設置 foreign_key_checks=0 刪除被引用的索引后,再設置foreign_key_checks=1,對引用表進行DML操作會導致 mysqld crash,以下是重現的測例: ~~~ drop table if exists t2; drop table if exists t1; create table t1 (a int, b int, key idx1(a)) engine=innodb; insert into t1 values(1,1); insert into t1 values(2,2); create table t2 (a int, b int, foreign key (b) references t1(a)) engine=innodb; set session foreign_key_checks = 0; alter table t1 drop key idx1; set session foreign_key_checks = 1; insert into t2 values (1,1); //此語句執行時mysqld會crash ~~~ ## 分析 對于引用約束,在mysql實現中引用表和被引用表都會記錄表的引用關系。 以下鏈表記錄該表引用了哪些表,鏈表中每個元素為 dict_foreign_t ~~~ table->foreign_list ~~~ 以下鏈表記錄該表被哪些表引用,鏈表中每個元素為 dict_foreign_t ~~~ table->referenced_list ~~~ dict_foreign_t 結構如下 ~~~ dict_foreign_t { foreign_table // t2 foreign_index referenced_table // t1 referenced_index // idx1 ...... } ~~~ 對于上面的測例,t1為被引用表,t2為引用表。 * 對于t1 table->foreign_list 為null table->referenced_list 則記錄了引用關系 * 對于t2 table->foreign_list 記錄了引用關系 table->referenced_list 則為null 對于刪除索引操作,如果索引涉及到引用關系,那么對應引用關系中的索引也應該做相應調整。對于測例中的刪索引操作?`alter table t1 drop key idx1;`?應該做如下調整 * 修改t1表的引用關系 table->referenced_list中dict_foreign_t->referenced_index 置為null * 修改t2表的引用關系 table->foreign_list中dict_foreign_t->referenced_index 置為null 而此bug修復之前, 并沒有修改t2表的引用關系, 從而導致后面對t2表進行DML操作時,如果訪問了無效的dict_foreign_t->referenced_index就會導致crash。 ## 修復方法 刪除被引用的索引后,應修改引用表的引用關系,即應修改table->referenced_list。 詳見[官方修復](https://github.com/mysql/mysql-server/commit/dde1b32d9e292255d09dbbe15145b346fbc208f6 "FOREIGN KEY REFERENCES FREED MEMORY AFTER DROP INDEX") ## 附加說明 如果刪除引用表對應的外鍵時,mysql如何處理的呢?同刪除被引用表的索引一樣,都需要調整引用表和被引用表的關系。 實際上,當刪除引用表對應的外鍵時,如果存在和此外鍵相似(這里的相似是指索引列數和列順序相同)的索引時,會用相似的索引代替刪除的外鍵,從而保持原有的引用約束關系。 例如,在下面的例子中,原來t2存在有兩個索引idx1和idx2,都可以作為外鍵,函數`dict_foreign_find_index`選擇了idx1作為外鍵。當刪除idx1后,同樣通過dict_foreign_find_index選擇了idx2做為了外鍵。 ~~~ drop table if exists t2; drop table if exists t1; create table t1 (a int, b int, key(a)) engine=innodb; create table t2 (a int, b int, foreign key (b) references t1(a), key idx1(b), key idx2(b)) engine=innodb; alter table t2 drop key idx1; ~~~ 同樣,此bug修復后,刪除被引用表的索引時,如果存在相似的索引會用相似的索引代替。 例如,在下面的例子中,原來t1存在有兩個索引idx1和idx2,都可以作為被引用索引,函數dict_foreign_find_index選擇了idx1作為被引用索引。當刪除idx1后,同樣通過dict_foreign_find_index選擇了idx2做為了新的被引用索引。 ~~~ drop table if exists t2; drop table if exists t1; create table t1 (a int, b int, key idx1(a), key idx2(a)) engine=innodb; create table t2 (a int, b int, foreign key (b) references t1(a)) engine=innodb; ~~~ 其實,相似索引的存在是完全沒有必要的。如果禁止創建相似的索引,那么引用約束這塊的處理也不會這么復雜了。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看