1 /******************************************************
4 (c) 1994-1996 Innobase Oy
6 Created 10/16/1994 Heikki Tuuri
7 *******************************************************/
12 # define LIMIT_OPTIMISTIC_INSERT_DEBUG(NREC, CODE)\
13 if (btr_cur_limit_optimistic_insert_debug\
14 && (NREC) >= (ulint)btr_cur_limit_optimistic_insert_debug) {\
18 # define LIMIT_OPTIMISTIC_INSERT_DEBUG(NREC, CODE)
19 #endif /* UNIV_DEBUG */
21 /*************************************************************
22 Returns the page cursor component of a tree cursor. */
27 /* out: pointer to page cursor component */
28 btr_cur_t* cursor) /* in: tree cursor */
30 return(&(cursor->page_cur));
33 /*************************************************************
34 Returns the record pointer of a tree cursor. */
39 /* out: pointer to record */
40 btr_cur_t* cursor) /* in: tree cursor */
42 return(page_cur_get_rec(&(cursor->page_cur)));
45 /*************************************************************
46 Invalidates a tree cursor by setting record pointer to NULL. */
51 btr_cur_t* cursor) /* in: tree cursor */
53 page_cur_invalidate(&(cursor->page_cur));
56 /*************************************************************
57 Returns the page of a tree cursor. */
62 /* out: pointer to page */
63 btr_cur_t* cursor) /* in: tree cursor */
65 return(buf_frame_align(page_cur_get_rec(&(cursor->page_cur))));
68 /*************************************************************
69 Returns the index of a cursor. */
75 btr_cur_t* cursor) /* in: B-tree cursor */
77 return(cursor->index);
80 /*************************************************************
81 Positions a tree cursor at a given record. */
86 dict_index_t* index, /* in: index */
87 rec_t* rec, /* in: record in tree */
88 btr_cur_t* cursor) /* in: cursor */
90 page_cur_position(rec, btr_cur_get_page_cur(cursor));
92 cursor->index = index;
95 /*************************************************************************
96 Checks if compressing an index page where a btr cursor is placed makes
100 btr_cur_compress_recommendation(
101 /*============================*/
102 /* out: TRUE if compression is recommended */
103 btr_cur_t* cursor, /* in: btr cursor */
104 mtr_t* mtr) /* in: mtr */
108 ut_ad(mtr_memo_contains(mtr, buf_block_align(btr_cur_get_rec(cursor)),
109 MTR_MEMO_PAGE_X_FIX));
111 page = btr_cur_get_page(cursor);
113 LIMIT_OPTIMISTIC_INSERT_DEBUG(page_get_n_recs(page) * 2,
116 if ((page_get_data_size(page) < BTR_CUR_PAGE_COMPRESS_LIMIT)
117 || ((btr_page_get_next(page, mtr) == FIL_NULL)
118 && (btr_page_get_prev(page, mtr) == FIL_NULL))) {
120 /* The page fillfactor has dropped below a predefined
121 minimum value OR the level in the B-tree contains just
122 one page: we recommend compression if this is not the
125 return(dict_index_get_page(cursor->index)
126 != buf_frame_get_page_no(page));
132 /*************************************************************************
133 Checks if the record on which the cursor is placed can be deleted without
134 making tree compression necessary (or, recommended). */
137 btr_cur_can_delete_without_compress(
138 /*================================*/
139 /* out: TRUE if can be deleted without
140 recommended compression */
141 btr_cur_t* cursor, /* in: btr cursor */
142 ulint rec_size,/* in: rec_get_size(btr_cur_get_rec(cursor))*/
143 mtr_t* mtr) /* in: mtr */
147 ut_ad(mtr_memo_contains(mtr, buf_block_align(btr_cur_get_rec(cursor)),
148 MTR_MEMO_PAGE_X_FIX));
150 page = btr_cur_get_page(cursor);
152 if ((page_get_data_size(page) - rec_size < BTR_CUR_PAGE_COMPRESS_LIMIT)
153 || ((btr_page_get_next(page, mtr) == FIL_NULL)
154 && (btr_page_get_prev(page, mtr) == FIL_NULL))
155 || (page_get_n_recs(page) < 2)) {
157 /* The page fillfactor will drop below a predefined
158 minimum value, OR the level in the B-tree contains just
159 one page, OR the page will become empty: we recommend
160 compression if this is not the root page. */
162 return(dict_index_get_page(cursor->index)
163 == buf_frame_get_page_no(page));