~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/include/btr0cur.ic

Tags: innodb-plugin-1.0.1
Imported 1.0.1 with clean - with no changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************************
 
2
The index tree cursor
 
3
 
 
4
(c) 1994-1996 Innobase Oy
 
5
 
 
6
Created 10/16/1994 Heikki Tuuri
 
7
*******************************************************/
 
8
 
 
9
#include "btr0btr.h"
 
10
 
 
11
#ifdef UNIV_DEBUG
 
12
/*************************************************************
 
13
Returns the page cursor component of a tree cursor. */
 
14
UNIV_INLINE
 
15
page_cur_t*
 
16
btr_cur_get_page_cur(
 
17
/*=================*/
 
18
                                        /* out: pointer to page cursor
 
19
                                        component */
 
20
        const btr_cur_t*        cursor) /* in: tree cursor */
 
21
{
 
22
        return(&((btr_cur_t*) cursor)->page_cur);
 
23
}
 
24
#endif /* UNIV_DEBUG */
 
25
/*************************************************************
 
26
Returns the buffer block on which the tree cursor is positioned. */
 
27
UNIV_INLINE
 
28
buf_block_t*
 
29
btr_cur_get_block(
 
30
/*==============*/
 
31
                                /* out: pointer to buffer block */
 
32
        btr_cur_t*      cursor) /* in: tree cursor */
 
33
{
 
34
        return(page_cur_get_block(btr_cur_get_page_cur(cursor)));
 
35
}
 
36
 
 
37
/*************************************************************
 
38
Returns the record pointer of a tree cursor. */
 
39
UNIV_INLINE
 
40
rec_t*
 
41
btr_cur_get_rec(
 
42
/*============*/
 
43
                                /* out: pointer to record */
 
44
        btr_cur_t*      cursor) /* in: tree cursor */
 
45
{
 
46
        return(page_cur_get_rec(&(cursor->page_cur)));
 
47
}
 
48
 
 
49
/*************************************************************
 
50
Returns the compressed page on which the tree cursor is positioned. */
 
51
UNIV_INLINE
 
52
page_zip_des_t*
 
53
btr_cur_get_page_zip(
 
54
/*=================*/
 
55
                                /* out: pointer to compressed page,
 
56
                                or NULL if the page is not compressed */
 
57
        btr_cur_t*      cursor) /* in: tree cursor */
 
58
{
 
59
        return(buf_block_get_page_zip(btr_cur_get_block(cursor)));
 
60
}
 
61
 
 
62
/*************************************************************
 
63
Invalidates a tree cursor by setting record pointer to NULL. */
 
64
UNIV_INLINE
 
65
void
 
66
btr_cur_invalidate(
 
67
/*===============*/
 
68
        btr_cur_t*      cursor) /* in: tree cursor */
 
69
{
 
70
        page_cur_invalidate(&(cursor->page_cur));
 
71
}
 
72
 
 
73
/*************************************************************
 
74
Returns the page of a tree cursor. */
 
75
UNIV_INLINE
 
76
page_t*
 
77
btr_cur_get_page(
 
78
/*=============*/
 
79
                                /* out: pointer to page */
 
80
        btr_cur_t*      cursor) /* in: tree cursor */
 
81
{
 
82
        return(page_align(page_cur_get_rec(&(cursor->page_cur))));
 
83
}
 
84
 
 
85
/*************************************************************
 
86
Returns the index of a cursor. */
 
87
UNIV_INLINE
 
88
dict_index_t*
 
89
btr_cur_get_index(
 
90
/*==============*/
 
91
                                /* out: index */
 
92
        btr_cur_t*      cursor) /* in: B-tree cursor */
 
93
{
 
94
        return(cursor->index);
 
95
}
 
96
 
 
97
/*************************************************************
 
98
Positions a tree cursor at a given record. */
 
99
UNIV_INLINE
 
100
void
 
101
btr_cur_position(
 
102
/*=============*/
 
103
        dict_index_t*   index,  /* in: index */
 
104
        rec_t*          rec,    /* in: record in tree */
 
105
        buf_block_t*    block,  /* in: buffer block of rec */
 
106
        btr_cur_t*      cursor) /* out: cursor */
 
107
{
 
108
        ut_ad(page_align(rec) == block->frame);
 
109
 
 
110
        page_cur_position(rec, block, btr_cur_get_page_cur(cursor));
 
111
 
 
112
        cursor->index = index;
 
113
}
 
114
 
 
115
/*************************************************************************
 
116
Checks if compressing an index page where a btr cursor is placed makes
 
117
sense. */
 
118
UNIV_INLINE
 
119
ibool
 
120
btr_cur_compress_recommendation(
 
121
/*============================*/
 
122
                                /* out: TRUE if compression is recommended */
 
123
        btr_cur_t*      cursor, /* in: btr cursor */
 
124
        mtr_t*          mtr)    /* in: mtr */
 
125
{
 
126
        page_t*         page;
 
127
 
 
128
        ut_ad(mtr_memo_contains(mtr, btr_cur_get_block(cursor),
 
129
                                MTR_MEMO_PAGE_X_FIX));
 
130
 
 
131
        page = btr_cur_get_page(cursor);
 
132
 
 
133
        if ((page_get_data_size(page) < BTR_CUR_PAGE_COMPRESS_LIMIT)
 
134
            || ((btr_page_get_next(page, mtr) == FIL_NULL)
 
135
                && (btr_page_get_prev(page, mtr) == FIL_NULL))) {
 
136
 
 
137
                /* The page fillfactor has dropped below a predefined
 
138
                minimum value OR the level in the B-tree contains just
 
139
                one page: we recommend compression if this is not the
 
140
                root page. */
 
141
 
 
142
                return(dict_index_get_page(cursor->index)
 
143
                       != page_get_page_no(page));
 
144
        }
 
145
 
 
146
        return(FALSE);
 
147
}
 
148
 
 
149
/*************************************************************************
 
150
Checks if the record on which the cursor is placed can be deleted without
 
151
making tree compression necessary (or, recommended). */
 
152
UNIV_INLINE
 
153
ibool
 
154
btr_cur_can_delete_without_compress(
 
155
/*================================*/
 
156
                                /* out: TRUE if can be deleted without
 
157
                                recommended compression */
 
158
        btr_cur_t*      cursor, /* in: btr cursor */
 
159
        ulint           rec_size,/* in: rec_get_size(btr_cur_get_rec(cursor))*/
 
160
        mtr_t*          mtr)    /* in: mtr */
 
161
{
 
162
        page_t*         page;
 
163
 
 
164
        ut_ad(mtr_memo_contains(mtr, btr_cur_get_block(cursor),
 
165
                                MTR_MEMO_PAGE_X_FIX));
 
166
 
 
167
        page = btr_cur_get_page(cursor);
 
168
 
 
169
        if ((page_get_data_size(page) - rec_size < BTR_CUR_PAGE_COMPRESS_LIMIT)
 
170
            || ((btr_page_get_next(page, mtr) == FIL_NULL)
 
171
                && (btr_page_get_prev(page, mtr) == FIL_NULL))
 
172
            || (page_get_n_recs(page) < 2)) {
 
173
 
 
174
                /* The page fillfactor will drop below a predefined
 
175
                minimum value, OR the level in the B-tree contains just
 
176
                one page, OR the page will become empty: we recommend
 
177
                compression if this is not the root page. */
 
178
 
 
179
                return(dict_index_get_page(cursor->index)
 
180
                       == page_get_page_no(page));
 
181
        }
 
182
 
 
183
        return(TRUE);
 
184
}