~drizzle-trunk/drizzle/development

1 by brian
clean slate
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
/*************************************************************
12
Returns the page cursor component of a tree cursor. */
13
UNIV_INLINE
14
page_cur_t*
15
btr_cur_get_page_cur(
16
/*=================*/
17
				/* out: pointer to page cursor component */
18
	btr_cur_t*	cursor)	/* in: tree cursor */
19
{
20
	return(&(cursor->page_cur));
21
}
22
23
/*************************************************************
24
Returns the record pointer of a tree cursor. */
25
UNIV_INLINE
26
rec_t*
27
btr_cur_get_rec(
28
/*============*/
29
				/* out: pointer to record */
30
	btr_cur_t*	cursor)	/* in: tree cursor */
31
{
32
	return(page_cur_get_rec(&(cursor->page_cur)));
33
}
34
35
/*************************************************************
36
Invalidates a tree cursor by setting record pointer to NULL. */
37
UNIV_INLINE
38
void
39
btr_cur_invalidate(
40
/*===============*/
41
	btr_cur_t*	cursor)	/* in: tree cursor */
42
{
43
	page_cur_invalidate(&(cursor->page_cur));
44
}
45
46
/*************************************************************
47
Returns the page of a tree cursor. */
48
UNIV_INLINE
49
page_t*
50
btr_cur_get_page(
51
/*=============*/
52
				/* out: pointer to page */
53
	btr_cur_t*	cursor)	/* in: tree cursor */
54
{
55
	return(buf_frame_align(page_cur_get_rec(&(cursor->page_cur))));
56
}
57
58
/*************************************************************
59
Returns the index of a cursor. */
60
UNIV_INLINE
61
dict_index_t*
62
btr_cur_get_index(
63
/*==============*/
64
				/* out: index */
65
	btr_cur_t*	cursor)	/* in: B-tree cursor */
66
{
67
	return(cursor->index);
68
}
69
70
/*************************************************************
71
Positions a tree cursor at a given record. */
72
UNIV_INLINE
73
void
74
btr_cur_position(
75
/*=============*/
76
	dict_index_t*	index,	/* in: index */
77
	rec_t*		rec,	/* in: record in tree */
78
	btr_cur_t*	cursor)	/* in: cursor */
79
{
80
	page_cur_position(rec, btr_cur_get_page_cur(cursor));
81
82
	cursor->index = index;
83
}
84
85
/*************************************************************************
86
Checks if compressing an index page where a btr cursor is placed makes
87
sense. */
88
UNIV_INLINE
89
ibool
90
btr_cur_compress_recommendation(
91
/*============================*/
92
				/* out: TRUE if compression is recommended */
93
	btr_cur_t*	cursor,	/* in: btr cursor */
94
	mtr_t*		mtr)	/* in: mtr */
95
{
96
	page_t*		page;
97
98
	ut_ad(mtr_memo_contains(mtr, buf_block_align(btr_cur_get_rec(cursor)),
99
				MTR_MEMO_PAGE_X_FIX));
100
101
	page = btr_cur_get_page(cursor);
102
103
	if ((page_get_data_size(page) < BTR_CUR_PAGE_COMPRESS_LIMIT)
104
	    || ((btr_page_get_next(page, mtr) == FIL_NULL)
105
		&& (btr_page_get_prev(page, mtr) == FIL_NULL))) {
106
107
		/* The page fillfactor has dropped below a predefined
108
		minimum value OR the level in the B-tree contains just
109
		one page: we recommend compression if this is not the
110
		root page. */
111
112
		return(dict_index_get_page(cursor->index)
113
		       != buf_frame_get_page_no(page));
114
	}
115
116
	return(FALSE);
117
}
118
119
/*************************************************************************
120
Checks if the record on which the cursor is placed can be deleted without
121
making tree compression necessary (or, recommended). */
122
UNIV_INLINE
123
ibool
124
btr_cur_can_delete_without_compress(
125
/*================================*/
126
				/* out: TRUE if can be deleted without
127
				recommended compression */
128
	btr_cur_t*	cursor,	/* in: btr cursor */
129
	ulint		rec_size,/* in: rec_get_size(btr_cur_get_rec(cursor))*/
130
	mtr_t*		mtr)	/* in: mtr */
131
{
132
	page_t*		page;
133
134
	ut_ad(mtr_memo_contains(mtr, buf_block_align(btr_cur_get_rec(cursor)),
135
				MTR_MEMO_PAGE_X_FIX));
136
137
	page = btr_cur_get_page(cursor);
138
139
	if ((page_get_data_size(page) - rec_size < BTR_CUR_PAGE_COMPRESS_LIMIT)
140
	    || ((btr_page_get_next(page, mtr) == FIL_NULL)
141
		&& (btr_page_get_prev(page, mtr) == FIL_NULL))
142
	    || (page_get_n_recs(page) < 2)) {
143
144
		/* The page fillfactor will drop below a predefined
145
		minimum value, OR the level in the B-tree contains just
146
		one page, OR the page will become empty: we recommend
147
		compression if this is not the root page. */
148
149
		return(dict_index_get_page(cursor->index)
150
		       == buf_frame_get_page_no(page));
151
	}
152
153
	return(TRUE);
154
}