mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / storage / innobase / include / btr0cur.ic
blobd894f0546d9a70ef8e9e2ced49b8f8e8ad2dfaa3
1 /******************************************************
2 The index tree cursor
4 (c) 1994-1996 Innobase Oy
6 Created 10/16/1994 Heikki Tuuri
7 *******************************************************/
9 #include "btr0btr.h"
11 #ifdef UNIV_DEBUG
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) {\
15         CODE;\
17 #else
18 # define LIMIT_OPTIMISTIC_INSERT_DEBUG(NREC, CODE)
19 #endif /* UNIV_DEBUG */
21 /*************************************************************
22 Returns the page cursor component of a tree cursor. */
23 UNIV_INLINE
24 page_cur_t*
25 btr_cur_get_page_cur(
26 /*=================*/
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. */
35 UNIV_INLINE
36 rec_t*
37 btr_cur_get_rec(
38 /*============*/
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. */
47 UNIV_INLINE
48 void
49 btr_cur_invalidate(
50 /*===============*/
51         btr_cur_t*      cursor) /* in: tree cursor */
53         page_cur_invalidate(&(cursor->page_cur));
56 /*************************************************************
57 Returns the page of a tree cursor. */
58 UNIV_INLINE
59 page_t*
60 btr_cur_get_page(
61 /*=============*/
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. */
70 UNIV_INLINE
71 dict_index_t*
72 btr_cur_get_index(
73 /*==============*/
74                                 /* out: index */
75         btr_cur_t*      cursor) /* in: B-tree cursor */
77         return(cursor->index);
80 /*************************************************************
81 Positions a tree cursor at a given record. */
82 UNIV_INLINE
83 void
84 btr_cur_position(
85 /*=============*/
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
97 sense. */
98 UNIV_INLINE
99 ibool
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 */
106         page_t*         page;
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,
114                                       return(FALSE));
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
123                 root page. */
125                 return(dict_index_get_page(cursor->index)
126                        != buf_frame_get_page_no(page));
127         }
129         return(FALSE);
132 /*************************************************************************
133 Checks if the record on which the cursor is placed can be deleted without
134 making tree compression necessary (or, recommended). */
135 UNIV_INLINE
136 ibool
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 */
145         page_t*         page;
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));
164         }
166         return(TRUE);