| 1 | /***************************************************************************** |
| 2 | |
| 3 | Copyright (c) 1994, 2015, Oracle and/or its affiliates. All Rights Reserved. |
| 4 | Copyright (c) 2018, 2022, MariaDB Corporation. |
| 5 | |
| 6 | This program is free software; you can redistribute it and/or modify it under |
| 7 | the terms of the GNU General Public License as published by the Free Software |
| 8 | Foundation; version 2 of the License. |
| 9 | |
| 10 | This program is distributed in the hope that it will be useful, but WITHOUT |
| 11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 12 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| 13 | |
| 14 | You should have received a copy of the GNU General Public License along with |
| 15 | this program; if not, write to the Free Software Foundation, Inc., |
| 16 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA |
| 17 | |
| 18 | *****************************************************************************/ |
| 19 | |
| 20 | /**************************************************//** |
| 21 | @file include/btr0cur.ic |
| 22 | The index tree cursor |
| 23 | |
| 24 | Created 10/16/1994 Heikki Tuuri |
| 25 | *******************************************************/ |
| 26 | |
| 27 | #include "btr0btr.h"cxx . . $ `<file>/storage/innobase/include/btr0btr.h`/ |
| 28 | |
| 29 | #ifdef UNIV_DEBUG |
| 30 | # define LIMIT_OPTIMISTIC_INSERT_DEBUG(NREC, CODE)\ |
| 31 | if (btr_cur_limit_optimistic_insert_debug > 1\ |
| 32 | && (NREC) >= btr_cur_limit_optimistic_insert_debug) {\ |
| 33 | CODE;\ |
| 34 | } |
| 35 | #else |
| 36 | # define LIMIT_OPTIMISTIC_INSERT_DEBUGcxx . . $ `storage/innobase/include/btr0cur.inl:36:10`!(NREC, CODE) |
| 37 | #endif /* UNIV_DEBUG */ |
| 38 | |
| 39 | /*********************************************************//** |
| 40 | Returns the compressed page on which the tree cursor is positioned. |
| 41 | @return pointer to compressed page, or NULL if the page is not compressed */ |
| 42 | UNIV_INLINEcxx . . $ `storage/innobase/include/univ.i:168:9`! |
| 43 | page_zip_des_tcxx . . $ page_zip_des_t#* |
| 44 | btr_cur_get_page_zipcxx . . $ btr_cur_get_page_zip(25879e64d517f276).( |
| 45 | /*=================*/ |
| 46 | btr_cur_tcxx . . $ btr_cur_t#* cursor) /*!< in: tree cursor */ |
| 47 | { |
| 48 | return(buf_block_get_page_zipcxx . . $ `storage/innobase/include/buf0buf.h:390:9`!(btr_cur_get_blockcxx . . $ `storage/innobase/include/btr0cur.h:63:9`!(cursor))); |
| 49 | } |
| 50 | |
| 51 | /*********************************************************//** |
| 52 | Positions a tree cursor at a given record. */ |
| 53 | UNIV_INLINEcxx . . $ `storage/innobase/include/univ.i:168:9`! |
| 54 | void |
| 55 | btr_cur_positioncxx . . $ btr_cur_position(46cb1d6e3e9bb86).( |
| 56 | /*=============*/ |
| 57 | dict_index_tcxx . . $ dict_index_t#* index, /*!< in: index */ |
| 58 | rec_tcxx . . $ rec_t#* rec, /*!< in: record in tree */ |
| 59 | buf_block_tcxx . . $ buf_block_t#* block, /*!< in: buffer block of rec */ |
| 60 | btr_cur_tcxx . . $ btr_cur_t#* cursor) /*!< out: cursor */ |
| 61 | { |
| 62 | page_cur_positioncxx . . $ page_cur_position(e1227e12cf545386).(rec, block, btr_cur_get_page_curcxx . . $ btr_cur_t#page_cur.(cursor)); |
| 63 | cursor->page_curcxx . . $ btr_cur_t#page_cur..indexcxx . . $ page_cur_t#index. = index; |
| 64 | } |
| 65 | |
| 66 | /*********************************************************************//** |
| 67 | Checks if compressing an index page where a btr cursor is placed makes |
| 68 | sense. |
| 69 | @return TRUE if compression is recommended */ |
| 70 | UNIV_INLINEcxx . . $ `storage/innobase/include/univ.i:168:9`! |
| 71 | iboolcxx . . $ `storage/innobase/include/univ.i:355:9`! |
| 72 | btr_cur_compress_recommendationcxx . . $ btr_cur_compress_recommendation(82f858bc4e1f6dfd).( |
| 73 | /*============================*/ |
| 74 | btr_cur_tcxx . . $ btr_cur_t#* cursor, /*!< in: btr cursor */ |
| 75 | mtr_tcxx . . $ mtr_t#* mtr) /*!< in: mtr */ |
| 76 | { |
| 77 | const page_tcxx . . $ ib_page_t#* page; |
| 78 | |
| 79 | ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(mtr->memo_contains_flagged(btr_cur_get_block(cursor), |
| 80 | MTR_MEMO_PAGE_X_FIX)); |
| 81 | |
| 82 | page = btr_cur_get_pagecxx . . $ `storage/innobase/include/btr0cur.h:76:9`!(cursor); |
| 83 | |
| 84 | LIMIT_OPTIMISTIC_INSERT_DEBUGcxx . . $ `storage/innobase/include/btr0cur.inl:36:10`!(page_get_n_recs(page) * 2U, |
| 85 | return(FALSE)); |
| 86 | |
| 87 | if (!page_has_siblingscxx . . $ page_has_siblings(190063cf6fb4afb1).(page) |
| 88 | || page_get_data_sizecxx . . $ page_get_data_size(469dcb4e54b221a8).(page) |
| 89 | < BTR_CUR_PAGE_COMPRESS_LIMITcxx . . $ btr_cur_t#index(4ab6b9797a912635).(cursor->index())) { |
| 90 | |
| 91 | /* The page fillfactor has dropped below a predefined |
| 92 | minimum value OR the level in the B-tree contains just |
| 93 | one page: we recommend compression if this is not the |
| 94 | root page. */ |
| 95 | |
| 96 | return cursor->indexcxx . . $ btr_cur_t#index(4ab6b9797a912635).()->pagecxx . . $ dict_index_t#page. |
| 97 | != btr_cur_get_blockcxx . . $ `storage/innobase/include/btr0cur.h:63:9`!(cursor)->pagecxx . . $ buf_block_t#page..idcxx . . $ buf_page_t#id(9d40bbb65128eac8).().page_nocxx . . $ page_id_t#page_no(d22c8608b6eae7b5).(); |
| 98 | } |
| 99 | |
| 100 | return(FALSEcxx . . $ `include/my_global.h:477:9`!); |
| 101 | } |
| 102 | |
| 103 | /*********************************************************************//** |
| 104 | Checks if the record on which the cursor is placed can be deleted without |
| 105 | making tree compression necessary (or, recommended). |
| 106 | @return TRUE if can be deleted without recommended compression */ |
| 107 | UNIV_INLINEcxx . . $ `storage/innobase/include/univ.i:168:9`! |
| 108 | iboolcxx . . $ ulint# |
| 109 | btr_cur_can_delete_without_compresscxx . . $ btr_cur_can_delete_without_compress(eb7ec0e77beb17fb).( |
| 110 | /*================================*/ |
| 111 | btr_cur_tcxx . . $ btr_cur_t#* cursor, /*!< in: btr cursor */ |
| 112 | ulintcxx . . $ ulint# rec_size,/*!< in: rec_get_size(btr_cur_get_rec(cursor))*/ |
| 113 | mtr_tcxx . . $ mtr_t#* mtr) /*!< in: mtr */ |
| 114 | { |
| 115 | page_tcxx . . $ ib_page_t#* page; |
| 116 | |
| 117 | ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(mtr->memo_contains_flagged(btr_cur_get_block(cursor), |
| 118 | MTR_MEMO_PAGE_X_FIX)); |
| 119 | |
| 120 | page = btr_cur_get_pagecxx . . $ btr_cur_t#block(1f66ca64e72a94a3).(cursor); |
| 121 | |
| 122 | if (!page_has_siblingscxx . . $ page_has_siblings(190063cf6fb4afb1).(page) || page_get_n_recscxx . . $ page_get_n_recs(469dcb4e54b221a8).(page) < 2 |
| 123 | || page_get_data_sizecxx . . $ page_get_data_size(469dcb4e54b221a8).(page) - rec_size |
| 124 | < BTR_CUR_PAGE_COMPRESS_LIMITcxx . . $ `storage/innobase/include/btr0cur.h:616:9`!(cursor->index())) { |
| 125 | |
| 126 | /* The page fillfactor will drop below a predefined |
| 127 | minimum value, OR the level in the B-tree contains just |
| 128 | one page, OR the page will become empty: we recommend |
| 129 | compression if this is not the root page. */ |
| 130 | |
| 131 | return cursor->indexcxx . . $ btr_cur_t#index(4ab6b9797a912635).()->pagecxx . . $ dict_index_t#page. |
| 132 | == btr_cur_get_blockcxx . . $ page_cur_t#block.(cursor)->pagecxx . . $ buf_block_t#page..idcxx . . $ buf_page_t#id(9d40bbb65128eac8).().page_nocxx . . $ page_id_t#page_no(d22c8608b6eae7b5).(); |
| 133 | } |
| 134 | |
| 135 | return(TRUEcxx . . $ `include/my_global.h:476:9`!); |
| 136 | } |
| 137 | |
| 138 | /*******************************************************************//** |
| 139 | Determine if an operation on off-page columns is an update. |
| 140 | @return TRUE if op != BTR_STORE_INSERT */ |
| 141 | UNIV_INLINEcxx . . $ `storage/innobase/include/univ.i:168:9`! |
| 142 | iboolcxx . . $ ulint# |
| 143 | btr_blob_op_is_updatecxx . . $ btr_blob_op_is_update(66657de476c47064).( |
| 144 | /*==================*/ |
| 145 | enum blob_opcxx . . $ blob_op# op) /*!< in: operation */ |
| 146 | { |
| 147 | switch (op) { |
| 148 | case BTR_STORE_INSERTcxx . . $ BTR_STORE_INSERT.: |
| 149 | case BTR_STORE_INSERT_BULKcxx . . $ BTR_STORE_INSERT_BULK.: |
| 150 | return(FALSEcxx . . $ `include/my_global.h:477:9`!); |
| 151 | case BTR_STORE_INSERT_UPDATEcxx . . $ BTR_STORE_INSERT_UPDATE.: |
| 152 | case BTR_STORE_UPDATEcxx . . $ BTR_STORE_UPDATE.: |
| 153 | return(TRUEcxx . . $ `include/my_global.h:476:9`!); |
| 154 | } |
| 155 | |
| 156 | ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(0); |
| 157 | return(FALSEcxx . . $ `include/my_global.h:477:9`!); |
| 158 | } |