diff options
author | apostle <vladkakurin007@gmail.com> | 2022-05-27 03:47:04 +0000 |
---|---|---|
committer | apostle <vladkakurin007@gmail.com> | 2022-05-27 03:47:04 +0000 |
commit | bd20462525bdac089356d18152f4e6e1753bde79 (patch) | |
tree | 8e6493ce733647859153dbd356f5c925f4bc2a33 | |
parent | cef157142725f88da2360e74fb259f93ca86417f (diff) | |
download | mariadb-git-bd20462525bdac089356d18152f4e6e1753bde79.tar.gz |
fixs for A/R
-rw-r--r-- | storage/innobase/btr/btr0cur.cc | 42 | ||||
-rw-r--r-- | storage/innobase/handler/ha_innodb.cc | 15 | ||||
-rw-r--r-- | storage/innobase/include/btr0cur.h | 14 | ||||
-rw-r--r-- | storage/innobase/include/btr0pcur.h | 15 | ||||
-rw-r--r-- | storage/innobase/include/btr0pcur.inl | 17 |
5 files changed, 55 insertions, 48 deletions
diff --git a/storage/innobase/btr/btr0cur.cc b/storage/innobase/btr/btr0cur.cc index 255ab481b44..07d70688976 100644 --- a/storage/innobase/btr/btr0cur.cc +++ b/storage/innobase/btr/btr0cur.cc @@ -2850,14 +2850,17 @@ btr_cur_open_at_index_side( /**********************************************************************//** Positions a cursor at a randomly chosen position within a B-tree. @return true if the index is available and we have put the cursor, false -if the index is unavailable */ +if the index is unavailable. Cursor->page_cur->rec can be null if +simulate_uniform=true, which means that no record is chosen in the +generated tree path. The caller should retry a call, that will +try a new tree path */ bool btr_cur_open_at_rnd_pos( - dict_index_t* index, /*!< in: index */ - ulint latch_mode, /*!< in: BTR_SEARCH_LEAF, ... */ - btr_cur_t* cursor, /*!< in/out: B-tree cursor */ - mtr_t* mtr, /*!< in: mtr */ - bool* probability_correctness) /*!< out: flag for A/R check */ + dict_index_t* index, /*!< in: index */ + ulint latch_mode, /*!< in: BTR_SEARCH_LEAF, ... */ + btr_cur_t* cursor, /*!< in/out: B-tree cursor */ + mtr_t* mtr, /*!< in: mtr */ + bool simulate_uniform) /*!< in: flag for uniform simulation */ { page_cur_t* page_cursor; ulint node_ptr_max_size = srv_page_size / 2; @@ -2869,11 +2872,10 @@ btr_cur_open_at_rnd_pos( ulint n_blocks = 0; ulint n_releases = 0; mem_heap_t* heap = NULL; + bool start_move_down = true; + double p = 1.0; rec_offs offsets_[REC_OFFS_NORMAL_SIZE]; rec_offs* offsets = offsets_; - *probability_correctness = true; - bool start_move_down = true; - double p = 1.0; rec_offs_init(offsets_); ut_ad(!index->is_spatial()); @@ -3041,14 +3043,18 @@ btr_cur_open_at_rnd_pos( } } } - if(!start_move_down) { - ulint n_recs = page_get_n_recs(block->page.frame); - double max_fanout = (double)srv_page_size / - (REC_N_NEW_EXTRA_BYTES + 1); - p *= (double)n_recs / max_fanout; - } else { - start_move_down= false; + + if(simulate_uniform) { + if(!start_move_down) { + ulint n_recs = page_get_n_recs(block->page.frame); + double max_fanout = (double)srv_page_size / + (REC_N_NEW_EXTRA_BYTES + 1); + p *= (double)n_recs / max_fanout; + } else { + start_move_down= false; + } } + page_cur_open_on_rnd_user_rec(block, page_cursor); if (height == 0) { @@ -3145,8 +3151,8 @@ btr_cur_open_at_rnd_pos( } double rand_uniform = (double)(rand() / (double(RAND_MAX))); - if(rand_uniform < p) - *probability_correctness = false; + if(simulate_uniform&& rand_uniform < p) + page_cursor->rec = NULL; return err == DB_SUCCESS; } diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 3ea5968d50d..e0480cfa4ba 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -9527,35 +9527,28 @@ ha_innobase::sample_next( rec_offs_init(offsets_); dict_index_t* index= innobase_get_index(MAX_KEY); - bool probability_correctness; do { mtr.start(); - res= btr_pcur_open_at_rnd_pos(index, BTR_SEARCH_LEAF, pcur, &mtr, &probability_correctness); + res= btr_pcur_open_at_rnd_pos(index, BTR_SEARCH_LEAF, pcur, &mtr, true); mtr.commit(); if(!res) { return HA_ERR_KEY_NOT_FOUND; } - } while (!probability_correctness); - - rec= btr_pcur_get_rec(pcur); + } while (!(rec= btr_pcur_get_rec(pcur))); mem_heap_t* heap= NULL; + auto _ = make_scope_exit([heap]() { if(heap) mem_heap_free(heap); }); + offsets= rec_get_offsets(rec, index, offsets, index->n_core_fields, ULINT_UNDEFINED, &heap); ut_ad(offsets); if (!offsets) - { - if (heap) - mem_heap_free(heap); return HA_ERR_INTERNAL_ERROR; - } res= row_sel_store_mysql_rec( buf, m_prebuilt, rec, NULL, true, index, offsets); - if(heap) - mem_heap_free(heap); return res ? 0 : HA_ERR_INTERNAL_ERROR; } diff --git a/storage/innobase/include/btr0cur.h b/storage/innobase/include/btr0cur.h index e9f4b2599d3..25bc8a40752 100644 --- a/storage/innobase/include/btr0cur.h +++ b/storage/innobase/include/btr0cur.h @@ -208,14 +208,16 @@ btr_cur_open_at_index_side( /**********************************************************************//** Positions a cursor at a randomly chosen position within a B-tree. @return true if the index is available and we have put the cursor, false -if the index is unavailable */ +if the index is unavailable. Cursor->page_cur->rec can be null if +simulate_uniform=true,which means that no record is chosen in the generated +tree path. The caller should retry a call, that will try a new tree path */ bool btr_cur_open_at_rnd_pos( - dict_index_t* index, /*!< in: index */ - ulint latch_mode, /*!< in: BTR_SEARCH_LEAF, ... */ - btr_cur_t* cursor, /*!< in/out: B-tree cursor */ - mtr_t* mtr, /*!< in: mtr */ - bool* probability_correctness = NULL); /*!< out: flag for A/R check */ + dict_index_t* index, /*!< in: index */ + ulint latch_mode, /*!< in: BTR_SEARCH_LEAF, ... */ + btr_cur_t* cursor, /*!< in/out: B-tree cursor */ + mtr_t* mtr, /*!< in: mtr */ + bool simulate_uniform= false); /*!< in: flag for uniform simulation */ /*************************************************************//** Tries to perform an insert to a page in an index tree, next to cursor. It is assumed that mtr holds an x-latch on the page. The operation does diff --git a/storage/innobase/include/btr0pcur.h b/storage/innobase/include/btr0pcur.h index 121da578800..bd45f57225e 100644 --- a/storage/innobase/include/btr0pcur.h +++ b/storage/innobase/include/btr0pcur.h @@ -201,15 +201,18 @@ btr_pcur_open_on_user_rec( /**********************************************************************//** Positions a cursor at a randomly chosen position within a B-tree. @return true if the index is available and we have put the cursor, false -if the index is unavailable */ +if the index is unavailable. Cursor->btr_cur->page_cur->rec can be null if +simulate_uniform=true, which means that no record is chosen in the +generated tree path. The caller should retry a call, that will +try a new tree path */ UNIV_INLINE bool btr_pcur_open_at_rnd_pos( - dict_index_t* index, /*!< in: index */ - ulint latch_mode, /*!< in: BTR_SEARCH_LEAF, ... */ - btr_pcur_t* cursor, /*!< in/out: B-tree pcur */ - mtr_t* mtr, /*!< in: mtr */ - bool* probability_correctness = NULL); /*!< out: flag for A/R check */ + dict_index_t* index, /*!< in: index */ + ulint latch_mode, /*!< in: BTR_SEARCH_LEAF, ... */ + btr_pcur_t* cursor, /*!< in/out: B-tree pcur */ + mtr_t* mtr, /*!< in: mtr */ + bool simulate_uniform= false); /*!< in: flag for uniform simulation */ /**************************************************************//** Frees the possible memory heap of a persistent cursor and sets the latch mode of the persistent cursor to BTR_NO_LATCHES. diff --git a/storage/innobase/include/btr0pcur.inl b/storage/innobase/include/btr0pcur.inl index 4ca256733e0..84fb1b4fa13 100644 --- a/storage/innobase/include/btr0pcur.inl +++ b/storage/innobase/include/btr0pcur.inl @@ -480,15 +480,18 @@ btr_pcur_open_at_index_side( /**********************************************************************//** Positions a cursor at a randomly chosen position within a B-tree. @return true if the index is available and we have put the cursor, false -if the index is unavailable */ +if the index is unavailable. Cursor->btr_cur->page_cur->rec can be null if +simulate_uniform=true, which means that no record is chosen in the +generated tree path. The caller should retry a call, that will +try a new tree path */ UNIV_INLINE bool btr_pcur_open_at_rnd_pos( - dict_index_t* index, /*!< in: index */ - ulint latch_mode, /*!< in: BTR_SEARCH_LEAF, ... */ - btr_pcur_t* cursor, /*!< in/out: B-tree pcur */ - mtr_t* mtr, /*!< in: mtr */ - bool* probability_correctness) /*!< out: flag for A/R check */ + dict_index_t* index, /*!< in: index */ + ulint latch_mode, /*!< in: BTR_SEARCH_LEAF, ... */ + btr_pcur_t* cursor, /*!< in/out: B-tree pcur */ + mtr_t* mtr, /*!< in: mtr */ + bool simulate_uniform) /*!< in: flag for uniform simulation */ { /* Initialize the cursor */ @@ -501,7 +504,7 @@ btr_pcur_open_at_rnd_pos( available = btr_cur_open_at_rnd_pos(index, latch_mode, btr_pcur_get_btr_cur(cursor), - mtr, probability_correctness); + mtr, simulate_uniform); cursor->pos_state = BTR_PCUR_IS_POSITIONED; cursor->old_stored = false; |