InnoDB Plugin  1.0
btr0cur.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (c) 1994, 2014, Oracle and/or its affiliates. All Rights Reserved.
4 
5 This program is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License as published by the Free Software
7 Foundation; version 2 of the License.
8 
9 This program is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12 
13 You should have received a copy of the GNU General Public License along with
14 this program; if not, write to the Free Software Foundation, Inc.,
15 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
16 
17 *****************************************************************************/
18 
19 /**************************************************/
26 #ifndef btr0cur_h
27 #define btr0cur_h
28 
29 #include "univ.i"
30 #include "dict0dict.h"
31 #include "page0cur.h"
32 #include "btr0types.h"
33 
35 enum {
53 };
54 
55 #ifndef UNIV_HOTBACKUP
56 #include "que0types.h"
57 #include "row0types.h"
58 #include "ha0ha.h"
59 
60 #define BTR_CUR_ADAPT
61 #define BTR_CUR_HASH_ADAPT
62 
63 #ifdef UNIV_DEBUG
64 /*********************************************************/
67 UNIV_INLINE
70 /*=================*/
71  const btr_cur_t* cursor);
72 /*********************************************************/
75 UNIV_INLINE
78 /*==============*/
79  const btr_cur_t* cursor);
80 /*********************************************************/
83 UNIV_INLINE
84 rec_t*
86 /*============*/
87  const btr_cur_t* cursor);
88 #else /* UNIV_DEBUG */
89 # define btr_cur_get_page_cur(cursor) (&(cursor)->page_cur)
90 # define btr_cur_get_block(cursor) ((cursor)->page_cur.block)
91 # define btr_cur_get_rec(cursor) ((cursor)->page_cur.rec)
92 #endif /* UNIV_DEBUG */
93 /*********************************************************/
96 UNIV_INLINE
99 /*=================*/
100  btr_cur_t* cursor);
101 /*********************************************************/
103 UNIV_INLINE
104 void
106 /*===============*/
107  btr_cur_t* cursor);
108 /*********************************************************/
111 UNIV_INLINE
112 page_t*
114 /*=============*/
115  btr_cur_t* cursor);
116 /*********************************************************/
120 #define btr_cur_get_index(cursor) ((cursor)->index)
121 /*********************************************************/
123 UNIV_INLINE
124 void
126 /*=============*/
127  dict_index_t* index,
128  rec_t* rec,
129  buf_block_t* block,
130  btr_cur_t* cursor);
131 /********************************************************************/
138 UNIV_INTERN
139 void
141 /*========================*/
142  dict_index_t* index,
143  ulint level,
144  const dtuple_t* tuple,
147  ulint mode,
154  ulint latch_mode,
165  btr_cur_t* cursor,
167  ulint has_search_latch,
170  const char* file,
171  ulint line,
172  mtr_t* mtr);
173 /*****************************************************************/
175 UNIV_INTERN
176 void
178 /*============================*/
179  bool from_left,
181  dict_index_t* index,
182  ulint latch_mode,
183  btr_cur_t* cursor,
184  ulint level,
186  const char* file,
187  ulint line,
188  mtr_t* mtr)
189  __attribute__((nonnull));
190 #define btr_cur_open_at_index_side(f,i,l,c,lv,m) \
191  btr_cur_open_at_index_side_func(f,i,l,c,lv,__FILE__,__LINE__,m)
192 /**********************************************************************/
194 UNIV_INTERN
195 void
197 /*=========================*/
198  dict_index_t* index,
199  ulint latch_mode,
200  btr_cur_t* cursor,
201  const char* file,
202  ulint line,
203  mtr_t* mtr);
204 #define btr_cur_open_at_rnd_pos(i,l,c,m) \
205  btr_cur_open_at_rnd_pos_func(i,l,c,__FILE__,__LINE__,m)
206 /*************************************************************/
213 UNIV_INTERN
214 dberr_t
216 /*======================*/
217  ulint flags,
220  btr_cur_t* cursor,
222  ulint** offsets,
223  mem_heap_t** heap,
224  dtuple_t* entry,
225  rec_t** rec,
227  big_rec_t** big_rec,
230  ulint n_ext,
231  que_thr_t* thr,
232  mtr_t* mtr)
238  __attribute__((nonnull(2,3,4,5,6,7,10), warn_unused_result));
239 /*************************************************************/
245 UNIV_INTERN
246 dberr_t
248 /*=======================*/
249  ulint flags,
255  btr_cur_t* cursor,
257  ulint** offsets,
258  mem_heap_t** heap,
260  dtuple_t* entry,
261  rec_t** rec,
263  big_rec_t** big_rec,
266  ulint n_ext,
267  que_thr_t* thr,
268  mtr_t* mtr)
269  __attribute__((nonnull(2,3,4,5,6,7,10), warn_unused_result));
270 /*************************************************************/
282 UNIV_INTERN
283 bool
285 /*==========================*/
286  page_zip_des_t* page_zip,
287  page_cur_t* cursor,
288  dict_index_t* index,
289 #ifdef UNIV_DEBUG
290  ulint* offsets,
291 #endif /* UNIV_DEBUG */
292  ulint length,
293  bool create,
295  mtr_t* mtr)
296  __attribute__((nonnull, warn_unused_result));
297 #ifdef UNIV_DEBUG
298 # define btr_cur_update_alloc_zip(page_zip,cursor,index,offsets,len,cr,mtr) \
299  btr_cur_update_alloc_zip_func(page_zip,cursor,index,offsets,len,cr,mtr)
300 #else /* UNIV_DEBUG */
301 # define btr_cur_update_alloc_zip(page_zip,cursor,index,offsets,len,cr,mtr) \
302  btr_cur_update_alloc_zip_func(page_zip,cursor,index,len,cr,mtr)
303 #endif /* UNIV_DEBUG */
304 /*************************************************************/
310 UNIV_INTERN
311 dberr_t
313 /*====================*/
314  ulint flags,
315  btr_cur_t* cursor,
318  ulint* offsets,
319  const upd_t* update,
320  ulint cmpl_info,
322  que_thr_t* thr,
323  trx_id_t trx_id,
324  mtr_t* mtr)
328  __attribute__((warn_unused_result, nonnull));
329 /***********************************************************/
331 UNIV_INTERN
332 void
334 /*========================*/
335  ulint flags,
336  const rec_t* rec,
337  dict_index_t* index,
338  const upd_t* update,
339  trx_id_t trx_id,
340  roll_ptr_t roll_ptr,
341  mtr_t* mtr)
342  __attribute__((nonnull));
343 /*************************************************************/
354 UNIV_INTERN
355 dberr_t
357 /*======================*/
358  ulint flags,
359  btr_cur_t* cursor,
362  ulint** offsets,
363  mem_heap_t** heap,
364  const upd_t* update,
366  ulint cmpl_info,
368  que_thr_t* thr,
369  trx_id_t trx_id,
370  mtr_t* mtr)
374  __attribute__((warn_unused_result, nonnull));
375 /*************************************************************/
381 UNIV_INTERN
382 dberr_t
384 /*=======================*/
385  ulint flags,
387  btr_cur_t* cursor,
390  ulint** offsets,
391  mem_heap_t** offsets_heap,
394  mem_heap_t* entry_heap,
397  big_rec_t** big_rec,
399  const upd_t* update,
402  ulint cmpl_info,
404  que_thr_t* thr,
405  trx_id_t trx_id,
406  mtr_t* mtr)
408  __attribute__((warn_unused_result, nonnull));
409 /***********************************************************/
415 UNIV_INTERN
416 dberr_t
418 /*===========================*/
419  buf_block_t* block,
420  rec_t* rec,
421  dict_index_t* index,
422  const ulint* offsets,
423  que_thr_t* thr,
424  mtr_t* mtr)
425  __attribute__((nonnull, warn_unused_result));
426 /***********************************************************/
429 UNIV_INTERN
430 dberr_t
432 /*=========================*/
433  ulint flags,
434  btr_cur_t* cursor,
435  ibool val,
436  que_thr_t* thr,
437  mtr_t* mtr)
438  __attribute__((nonnull, warn_unused_result));
439 /*************************************************************/
446 UNIV_INTERN
447 ibool
449 /*=======================*/
450  btr_cur_t* cursor,
453  ibool adjust,
455  mtr_t* mtr)
456  __attribute__((nonnull));
457 /*******************************************************/
462 UNIV_INTERN
463 ibool
465 /*===========================*/
466  btr_cur_t* cursor,
470 # ifdef UNIV_DEBUG
471  ulint flags,
472 # endif /* UNIV_DEBUG */
473  mtr_t* mtr)
477  __attribute__((nonnull, warn_unused_result));
478 # ifdef UNIV_DEBUG
479 # define btr_cur_optimistic_delete(cursor, flags, mtr) \
480  btr_cur_optimistic_delete_func(cursor, flags, mtr)
481 # else /* UNIV_DEBUG */
482 # define btr_cur_optimistic_delete(cursor, flags, mtr) \
483  btr_cur_optimistic_delete_func(cursor, mtr)
484 # endif /* UNIV_DEBUG */
485 /*************************************************************/
493 UNIV_INTERN
494 ibool
496 /*=======================*/
497  dberr_t* err,
502  ibool has_reserved_extents,
506  btr_cur_t* cursor,
510  ulint flags,
511  enum trx_rb_ctx rb_ctx,
512  mtr_t* mtr)
513  __attribute__((nonnull));
514 #endif /* !UNIV_HOTBACKUP */
515 /***********************************************************/
518 UNIV_INTERN
519 byte*
521 /*==========================*/
522  byte* ptr,
523  byte* end_ptr,
524  page_t* page,
525  page_zip_des_t* page_zip,
526  dict_index_t* index);
527 /****************************************************************/
531 UNIV_INTERN
532 byte*
534 /*=================================*/
535  byte* ptr,
536  byte* end_ptr,
537  page_t* page,
538  page_zip_des_t* page_zip,
539  dict_index_t* index);
540 /****************************************************************/
544 UNIV_INTERN
545 byte*
547 /*===============================*/
548  byte* ptr,
549  byte* end_ptr,
550  page_t* page,
551  page_zip_des_t* page_zip);
552 #ifndef UNIV_HOTBACKUP
553 /*******************************************************************/
556 UNIV_INTERN
557 ib_int64_t
559 /*=========================*/
560  dict_index_t* index,
561  const dtuple_t* tuple1,
562  ulint mode1,
563  const dtuple_t* tuple2,
564  ulint mode2);
565 /*******************************************************************/
574 UNIV_INTERN
575 void
577 /*======================================*/
578  dict_index_t* index);
585 ulint
587  const rec_t* rec,
588  const ulint* offsets);
589 
590 /*******************************************************************/
595 UNIV_INTERN
596 void
598 /*============================*/
599  page_zip_des_t* page_zip,
601  rec_t* rec,
602  dict_index_t* index,
603  const ulint* offsets,
604  const upd_t* update,
605  mtr_t* mtr)
606  __attribute__((nonnull(2,3,4,5,6)));
607 
609 enum blob_op {
616 };
617 
618 /*******************************************************************/
621 UNIV_INLINE
622 ibool
624 /*==================*/
625  enum blob_op op)
626  __attribute__((warn_unused_result));
627 
628 /*******************************************************************/
634 UNIV_INTERN
635 dberr_t
637 /*============================*/
638  dict_index_t* index,
640  buf_block_t* rec_block,
641  rec_t* rec,
642  const ulint* offsets,
646  const big_rec_t*big_rec_vec,
648  mtr_t* btr_mtr,
650  enum blob_op op)
651  __attribute__((nonnull, warn_unused_result));
652 
653 /*******************************************************************/
658 UNIV_INTERN
659 void
661 /*=============================*/
662  dict_index_t* index,
670  byte* field_ref,
671  const rec_t* rec,
673  const ulint* offsets,
675  page_zip_des_t* page_zip,
677  ulint i,
679  enum trx_rb_ctx rb_ctx,
680  mtr_t* local_mtr);
683 /*******************************************************************/
688 UNIV_INTERN
689 ulint
691 /*====================================*/
692  byte* buf,
693  ulint len,
694  ulint zip_size,
696  const byte* data,
700  ulint local_len);
701 /*******************************************************************/
705 UNIV_INTERN
706 byte*
708 /*=============================*/
709  ulint* len,
710  const byte* data,
714  ulint zip_size,
716  ulint local_len,
717  mem_heap_t* heap);
718 /*******************************************************************/
721 UNIV_INTERN
722 byte*
724 /*=================================*/
725  const rec_t* rec,
727  const ulint* offsets,
728  ulint zip_size,
730  ulint no,
731  ulint* len,
732  mem_heap_t* heap);
733 /*******************************************************************/
738 UNIV_INTERN
739 ulint
741 /*==========================*/
742  dtuple_t* tuple,
743  const upd_t* update,
744  mem_heap_t* heap)
745  __attribute__((nonnull));
746 /***********************************************************/
749 UNIV_INTERN
750 void
752 /*==============================*/
753  rec_t* rec,
754  page_zip_des_t* page_zip,
758  ibool val,
759  mtr_t* mtr);
760 /*######################################################################*/
761 
764 #define BTR_CUR_PAGE_COMPRESS_LIMIT (UNIV_PAGE_SIZE / 2)
765 
769 struct btr_path_t{
770  ulint nth_rec;
775  ulint n_recs;
776  ulint page_no;
777  ulint page_level;
781 };
782 
783 #define BTR_PATH_ARRAY_N_SLOTS 250
786 enum btr_cur_method {
802 };
803 
806 struct btr_cur_t {
815  /*------------------------------*/
822  /*------------------------------*/
825  /* @{ */
827  ulint tree_height;
830  ulint up_match;
844  ulint up_bytes;
848  ulint low_match;
856  ulint low_bytes;
860  ulint n_fields;
862  ulint n_bytes;
864  ulint fold;
866  /* @} */
871 };
872 
876 #define BTR_CUR_RETRY_DELETE_N_TIMES 100
877 
880 #define BTR_CUR_RETRY_SLEEP_TIME 50000
881 
888 /*-------------------------------------- @{ */
889 #define BTR_EXTERN_SPACE_ID 0
890 #define BTR_EXTERN_PAGE_NO 4
891 #define BTR_EXTERN_OFFSET 8
893 #define BTR_EXTERN_LEN 12
898 /*-------------------------------------- @} */
899 /* #define BTR_EXTERN_FIELD_REF_SIZE 20 // moved to btr0types.h */
900 
905 #define BTR_EXTERN_OWNER_FLAG 128
906 
911 #define BTR_EXTERN_INHERITED_FLAG 64
912 
914 extern ulint btr_cur_n_non_sea;
917 extern ulint btr_cur_n_sea;
921 extern ulint btr_cur_n_non_sea_old;
925 extern ulint btr_cur_n_sea_old;
926 #endif /* !UNIV_HOTBACKUP */
927 
928 #ifdef UNIV_DEBUG
929 /* Flag to limit optimistic insert records */
930 extern uint btr_cur_limit_optimistic_insert_debug;
931 #endif /* UNIV_DEBUG */
932 
933 #ifndef UNIV_NONINL
934 #include "btr0cur.ic"
935 #endif
936 
937 #endif