You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

346 lines
12 KiB

  1. /*****************************************************************************
  2. Copyright (c) 1994, 2009, Innobase Oy. All Rights Reserved.
  3. This program is free software; you can redistribute it and/or modify it under
  4. the terms of the GNU General Public License as published by the Free Software
  5. Foundation; version 2 of the License.
  6. This program is distributed in the hope that it will be useful, but WITHOUT
  7. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License along with
  10. this program; if not, write to the Free Software Foundation, Inc., 59 Temple
  11. Place, Suite 330, Boston, MA 02111-1307 USA
  12. *****************************************************************************/
  13. /********************************************************************//**
  14. @file include/page0cur.h
  15. The page cursor
  16. Created 10/4/1994 Heikki Tuuri
  17. *************************************************************************/
  18. #ifndef page0cur_h
  19. #define page0cur_h
  20. #include "univ.i"
  21. #include "buf0types.h"
  22. #include "page0page.h"
  23. #include "rem0rec.h"
  24. #include "data0data.h"
  25. #include "mtr0mtr.h"
  26. #define PAGE_CUR_ADAPT
  27. /* Page cursor search modes; the values must be in this order! */
  28. #define PAGE_CUR_UNSUPP 0
  29. #define PAGE_CUR_G 1
  30. #define PAGE_CUR_GE 2
  31. #define PAGE_CUR_L 3
  32. #define PAGE_CUR_LE 4
  33. /*#define PAGE_CUR_LE_OR_EXTENDS 5*/ /* This is a search mode used in
  34. "column LIKE 'abc%' ORDER BY column DESC";
  35. we have to find strings which are <= 'abc' or
  36. which extend it */
  37. #ifdef UNIV_SEARCH_DEBUG
  38. # define PAGE_CUR_DBG 6 /* As PAGE_CUR_LE, but skips search shortcut */
  39. #endif /* UNIV_SEARCH_DEBUG */
  40. #ifdef UNIV_DEBUG
  41. /*********************************************************//**
  42. Gets pointer to the page frame where the cursor is positioned.
  43. @return page */
  44. UNIV_INLINE
  45. page_t*
  46. page_cur_get_page(
  47. /*==============*/
  48. page_cur_t* cur); /*!< in: page cursor */
  49. /*********************************************************//**
  50. Gets pointer to the buffer block where the cursor is positioned.
  51. @return page */
  52. UNIV_INLINE
  53. buf_block_t*
  54. page_cur_get_block(
  55. /*===============*/
  56. page_cur_t* cur); /*!< in: page cursor */
  57. /*********************************************************//**
  58. Gets pointer to the page frame where the cursor is positioned.
  59. @return page */
  60. UNIV_INLINE
  61. page_zip_des_t*
  62. page_cur_get_page_zip(
  63. /*==================*/
  64. page_cur_t* cur); /*!< in: page cursor */
  65. /*********************************************************//**
  66. Gets the record where the cursor is positioned.
  67. @return record */
  68. UNIV_INLINE
  69. rec_t*
  70. page_cur_get_rec(
  71. /*=============*/
  72. page_cur_t* cur); /*!< in: page cursor */
  73. #else /* UNIV_DEBUG */
  74. # define page_cur_get_page(cur) page_align((cur)->rec)
  75. # define page_cur_get_block(cur) (cur)->block
  76. # define page_cur_get_page_zip(cur) buf_block_get_page_zip((cur)->block)
  77. # define page_cur_get_rec(cur) (cur)->rec
  78. #endif /* UNIV_DEBUG */
  79. /*********************************************************//**
  80. Sets the cursor object to point before the first user record
  81. on the page. */
  82. UNIV_INLINE
  83. void
  84. page_cur_set_before_first(
  85. /*======================*/
  86. const buf_block_t* block, /*!< in: index page */
  87. page_cur_t* cur); /*!< in: cursor */
  88. /*********************************************************//**
  89. Sets the cursor object to point after the last user record on
  90. the page. */
  91. UNIV_INLINE
  92. void
  93. page_cur_set_after_last(
  94. /*====================*/
  95. const buf_block_t* block, /*!< in: index page */
  96. page_cur_t* cur); /*!< in: cursor */
  97. /*********************************************************//**
  98. Returns TRUE if the cursor is before first user record on page.
  99. @return TRUE if at start */
  100. UNIV_INLINE
  101. ibool
  102. page_cur_is_before_first(
  103. /*=====================*/
  104. const page_cur_t* cur); /*!< in: cursor */
  105. /*********************************************************//**
  106. Returns TRUE if the cursor is after last user record.
  107. @return TRUE if at end */
  108. UNIV_INLINE
  109. ibool
  110. page_cur_is_after_last(
  111. /*===================*/
  112. const page_cur_t* cur); /*!< in: cursor */
  113. /**********************************************************//**
  114. Positions the cursor on the given record. */
  115. UNIV_INLINE
  116. void
  117. page_cur_position(
  118. /*==============*/
  119. const rec_t* rec, /*!< in: record on a page */
  120. const buf_block_t* block, /*!< in: buffer block containing
  121. the record */
  122. page_cur_t* cur); /*!< out: page cursor */
  123. /**********************************************************//**
  124. Invalidates a page cursor by setting the record pointer NULL. */
  125. UNIV_INLINE
  126. void
  127. page_cur_invalidate(
  128. /*================*/
  129. page_cur_t* cur); /*!< out: page cursor */
  130. /**********************************************************//**
  131. Moves the cursor to the next record on page. */
  132. UNIV_INLINE
  133. void
  134. page_cur_move_to_next(
  135. /*==================*/
  136. page_cur_t* cur); /*!< in/out: cursor; must not be after last */
  137. /**********************************************************//**
  138. Moves the cursor to the previous record on page. */
  139. UNIV_INLINE
  140. void
  141. page_cur_move_to_prev(
  142. /*==================*/
  143. page_cur_t* cur); /*!< in/out: cursor; not before first */
  144. #ifndef UNIV_HOTBACKUP
  145. /***********************************************************//**
  146. Inserts a record next to page cursor. Returns pointer to inserted record if
  147. succeed, i.e., enough space available, NULL otherwise. The cursor stays at
  148. the same logical position, but the physical position may change if it is
  149. pointing to a compressed page that was reorganized.
  150. @return pointer to record if succeed, NULL otherwise */
  151. UNIV_INLINE
  152. rec_t*
  153. page_cur_tuple_insert(
  154. /*==================*/
  155. page_cur_t* cursor, /*!< in/out: a page cursor */
  156. const dtuple_t* tuple, /*!< in: pointer to a data tuple */
  157. dict_index_t* index, /*!< in: record descriptor */
  158. ulint n_ext, /*!< in: number of externally stored columns */
  159. mtr_t* mtr); /*!< in: mini-transaction handle, or NULL */
  160. #endif /* !UNIV_HOTBACKUP */
  161. /***********************************************************//**
  162. Inserts a record next to page cursor. Returns pointer to inserted record if
  163. succeed, i.e., enough space available, NULL otherwise. The cursor stays at
  164. the same logical position, but the physical position may change if it is
  165. pointing to a compressed page that was reorganized.
  166. @return pointer to record if succeed, NULL otherwise */
  167. UNIV_INLINE
  168. rec_t*
  169. page_cur_rec_insert(
  170. /*================*/
  171. page_cur_t* cursor, /*!< in/out: a page cursor */
  172. const rec_t* rec, /*!< in: record to insert */
  173. dict_index_t* index, /*!< in: record descriptor */
  174. ulint* offsets,/*!< in/out: rec_get_offsets(rec, index) */
  175. mtr_t* mtr); /*!< in: mini-transaction handle, or NULL */
  176. /***********************************************************//**
  177. Inserts a record next to page cursor on an uncompressed page.
  178. Returns pointer to inserted record if succeed, i.e., enough
  179. space available, NULL otherwise. The cursor stays at the same position.
  180. @return pointer to record if succeed, NULL otherwise */
  181. UNIV_INTERN
  182. rec_t*
  183. page_cur_insert_rec_low(
  184. /*====================*/
  185. rec_t* current_rec,/*!< in: pointer to current record after
  186. which the new record is inserted */
  187. dict_index_t* index, /*!< in: record descriptor */
  188. const rec_t* rec, /*!< in: pointer to a physical record */
  189. ulint* offsets,/*!< in/out: rec_get_offsets(rec, index) */
  190. mtr_t* mtr); /*!< in: mini-transaction handle, or NULL */
  191. /***********************************************************//**
  192. Inserts a record next to page cursor on a compressed and uncompressed
  193. page. Returns pointer to inserted record if succeed, i.e.,
  194. enough space available, NULL otherwise.
  195. The cursor stays at the same position.
  196. @return pointer to record if succeed, NULL otherwise */
  197. UNIV_INTERN
  198. rec_t*
  199. page_cur_insert_rec_zip(
  200. /*====================*/
  201. rec_t** current_rec,/*!< in/out: pointer to current record after
  202. which the new record is inserted */
  203. buf_block_t* block, /*!< in: buffer block of *current_rec */
  204. dict_index_t* index, /*!< in: record descriptor */
  205. const rec_t* rec, /*!< in: pointer to a physical record */
  206. ulint* offsets,/*!< in/out: rec_get_offsets(rec, index) */
  207. mtr_t* mtr); /*!< in: mini-transaction handle, or NULL */
  208. /*************************************************************//**
  209. Copies records from page to a newly created page, from a given record onward,
  210. including that record. Infimum and supremum records are not copied. */
  211. UNIV_INTERN
  212. void
  213. page_copy_rec_list_end_to_created_page(
  214. /*===================================*/
  215. page_t* new_page, /*!< in/out: index page to copy to */
  216. rec_t* rec, /*!< in: first record to copy */
  217. dict_index_t* index, /*!< in: record descriptor */
  218. mtr_t* mtr); /*!< in: mtr */
  219. /***********************************************************//**
  220. Deletes a record at the page cursor. The cursor is moved to the
  221. next record after the deleted one. */
  222. UNIV_INTERN
  223. void
  224. page_cur_delete_rec(
  225. /*================*/
  226. page_cur_t* cursor, /*!< in/out: a page cursor */
  227. dict_index_t* index, /*!< in: record descriptor */
  228. const ulint* offsets,/*!< in: rec_get_offsets(cursor->rec, index) */
  229. mtr_t* mtr); /*!< in: mini-transaction handle */
  230. #ifndef UNIV_HOTBACKUP
  231. /****************************************************************//**
  232. Searches the right position for a page cursor.
  233. @return number of matched fields on the left */
  234. UNIV_INLINE
  235. ulint
  236. page_cur_search(
  237. /*============*/
  238. const buf_block_t* block, /*!< in: buffer block */
  239. const dict_index_t* index, /*!< in: record descriptor */
  240. const dtuple_t* tuple, /*!< in: data tuple */
  241. ulint mode, /*!< in: PAGE_CUR_L,
  242. PAGE_CUR_LE, PAGE_CUR_G, or
  243. PAGE_CUR_GE */
  244. page_cur_t* cursor);/*!< out: page cursor */
  245. /****************************************************************//**
  246. Searches the right position for a page cursor. */
  247. UNIV_INTERN
  248. void
  249. page_cur_search_with_match(
  250. /*=======================*/
  251. const buf_block_t* block, /*!< in: buffer block */
  252. const dict_index_t* index, /*!< in: record descriptor */
  253. const dtuple_t* tuple, /*!< in: data tuple */
  254. ulint mode, /*!< in: PAGE_CUR_L,
  255. PAGE_CUR_LE, PAGE_CUR_G, or
  256. PAGE_CUR_GE */
  257. ulint* iup_matched_fields,
  258. /*!< in/out: already matched
  259. fields in upper limit record */
  260. ulint* iup_matched_bytes,
  261. /*!< in/out: already matched
  262. bytes in a field not yet
  263. completely matched */
  264. ulint* ilow_matched_fields,
  265. /*!< in/out: already matched
  266. fields in lower limit record */
  267. ulint* ilow_matched_bytes,
  268. /*!< in/out: already matched
  269. bytes in a field not yet
  270. completely matched */
  271. page_cur_t* cursor);/*!< out: page cursor */
  272. /***********************************************************//**
  273. Positions a page cursor on a randomly chosen user record on a page. If there
  274. are no user records, sets the cursor on the infimum record. */
  275. UNIV_INTERN
  276. void
  277. page_cur_open_on_rnd_user_rec(
  278. /*==========================*/
  279. buf_block_t* block, /*!< in: page */
  280. page_cur_t* cursor);/*!< out: page cursor */
  281. #endif /* !UNIV_HOTBACKUP */
  282. /***********************************************************//**
  283. Parses a log record of a record insert on a page.
  284. @return end of log record or NULL */
  285. UNIV_INTERN
  286. byte*
  287. page_cur_parse_insert_rec(
  288. /*======================*/
  289. ibool is_short,/*!< in: TRUE if short inserts */
  290. byte* ptr, /*!< in: buffer */
  291. byte* end_ptr,/*!< in: buffer end */
  292. buf_block_t* block, /*!< in: page or NULL */
  293. dict_index_t* index, /*!< in: record descriptor */
  294. mtr_t* mtr); /*!< in: mtr or NULL */
  295. /**********************************************************//**
  296. Parses a log record of copying a record list end to a new created page.
  297. @return end of log record or NULL */
  298. UNIV_INTERN
  299. byte*
  300. page_parse_copy_rec_list_to_created_page(
  301. /*=====================================*/
  302. byte* ptr, /*!< in: buffer */
  303. byte* end_ptr,/*!< in: buffer end */
  304. buf_block_t* block, /*!< in: page or NULL */
  305. dict_index_t* index, /*!< in: record descriptor */
  306. mtr_t* mtr); /*!< in: mtr or NULL */
  307. /***********************************************************//**
  308. Parses log record of a record delete on a page.
  309. @return pointer to record end or NULL */
  310. UNIV_INTERN
  311. byte*
  312. page_cur_parse_delete_rec(
  313. /*======================*/
  314. byte* ptr, /*!< in: buffer */
  315. byte* end_ptr,/*!< in: buffer end */
  316. buf_block_t* block, /*!< in: page or NULL */
  317. dict_index_t* index, /*!< in: record descriptor */
  318. mtr_t* mtr); /*!< in: mtr or NULL */
  319. /** Index page cursor */
  320. struct page_cur_struct{
  321. byte* rec; /*!< pointer to a record on page */
  322. buf_block_t* block; /*!< pointer to the block containing rec */
  323. };
  324. #ifndef UNIV_NONINL
  325. #include "page0cur.ic"
  326. #endif
  327. #endif