Drizzled Public API Documentation

btr0pcur.h
Go to the documentation of this file.
00001 /*****************************************************************************
00002 
00003 Copyright (C) 1996, 2010, Innobase Oy. All Rights Reserved.
00004 
00005 This program is free software; you can redistribute it and/or modify it under
00006 the terms of the GNU General Public License as published by the Free Software
00007 Foundation; version 2 of the License.
00008 
00009 This program is distributed in the hope that it will be useful, but WITHOUT
00010 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00011 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
00012 
00013 You should have received a copy of the GNU General Public License along with
00014 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
00015 St, Fifth Floor, Boston, MA 02110-1301 USA
00016 
00017 *****************************************************************************/
00018 
00019 /**************************************************/
00026 #pragma once
00027 #ifndef btr0pcur_h
00028 #define btr0pcur_h
00029 
00030 #include "univ.i"
00031 #include "dict0dict.h"
00032 #include "data0data.h"
00033 #include "mtr0mtr.h"
00034 #include "page0cur.h"
00035 #include "btr0cur.h"
00036 #include "btr0btr.h"
00037 #include "btr0types.h"
00038 
00039 /* Relative positions for a stored cursor position */
00040 #define BTR_PCUR_ON     1
00041 #define BTR_PCUR_BEFORE     2
00042 #define BTR_PCUR_AFTER      3
00043 /* Note that if the tree is not empty, btr_pcur_store_position does not
00044 use the following, but only uses the above three alternatives, where the
00045 position is stored relative to a specific record: this makes implementation
00046 of a scroll cursor easier */
00047 #define BTR_PCUR_BEFORE_FIRST_IN_TREE 4 /* in an empty tree */
00048 #define BTR_PCUR_AFTER_LAST_IN_TREE 5 /* in an empty tree */
00049 
00050 /**************************************************************/
00053 UNIV_INTERN
00054 btr_pcur_t*
00055 btr_pcur_create_for_mysql(void);
00056 /*============================*/
00057 /**************************************************************/
00059 UNIV_INTERN
00060 void
00061 btr_pcur_free_for_mysql(
00062 /*====================*/
00063   btr_pcur_t* cursor);  
00064 /**************************************************************/
00066 UNIV_INTERN
00067 void
00068 btr_pcur_copy_stored_position(
00069 /*==========================*/
00070   btr_pcur_t* pcur_receive, 
00072   btr_pcur_t* pcur_donate); 
00074 /**************************************************************/
00076 UNIV_INLINE
00077 void
00078 btr_pcur_init(
00079 /*==========*/
00080   btr_pcur_t* pcur);  
00081 /**************************************************************/
00084 UNIV_INLINE
00085 void
00086 btr_pcur_open_func(
00087 /*===============*/
00088   dict_index_t* index,  
00089   const dtuple_t* tuple,  
00090   ulint   mode, 
00096   ulint   latch_mode,
00097   btr_pcur_t* cursor, 
00098   const char* file, 
00099   ulint   line, 
00100   mtr_t*    mtr); 
00101 #define btr_pcur_open(i,t,md,l,c,m)       \
00102   btr_pcur_open_func(i,t,md,l,c,__FILE__,__LINE__,m)
00103 /**************************************************************/
00106 UNIV_INLINE
00107 void
00108 btr_pcur_open_with_no_init_func(
00109 /*============================*/
00110   dict_index_t* index,  
00111   const dtuple_t* tuple,  
00112   ulint   mode, 
00118   ulint   latch_mode,
00123   btr_pcur_t* cursor, 
00124   ulint   has_search_latch,
00127   const char* file, 
00128   ulint   line, 
00129   mtr_t*    mtr); 
00130 #define btr_pcur_open_with_no_init(ix,t,md,l,cur,has,m)     \
00131   btr_pcur_open_with_no_init_func(ix,t,md,l,cur,has,__FILE__,__LINE__,m)
00132 
00133 /*****************************************************************/
00135 UNIV_INLINE
00136 void
00137 btr_pcur_open_at_index_side(
00138 /*========================*/
00139   ibool   from_left,  
00141   dict_index_t* index,    
00142   ulint   latch_mode, 
00143   btr_pcur_t* pcur,   
00144   ibool   do_init,  
00145   mtr_t*    mtr);   
00146 /**************************************************************/
00150 UNIV_INLINE
00151 ulint
00152 btr_pcur_get_up_match(
00153 /*==================*/
00154   btr_pcur_t* cursor); 
00155 /**************************************************************/
00159 UNIV_INLINE
00160 ulint
00161 btr_pcur_get_low_match(
00162 /*===================*/
00163   btr_pcur_t* cursor); 
00164 /**************************************************************/
00171 UNIV_INTERN
00172 void
00173 btr_pcur_open_on_user_rec_func(
00174 /*===========================*/
00175   dict_index_t* index,    
00176   const dtuple_t* tuple,    
00177   ulint   mode,   
00178   ulint   latch_mode, 
00180   btr_pcur_t* cursor,   
00182   const char* file,   
00183   ulint   line,   
00184   mtr_t*    mtr);   
00185 #define btr_pcur_open_on_user_rec(i,t,md,l,c,m)       \
00186   btr_pcur_open_on_user_rec_func(i,t,md,l,c,__FILE__,__LINE__,m)
00187 /**********************************************************************/
00189 UNIV_INLINE
00190 void
00191 btr_pcur_open_at_rnd_pos_func(
00192 /*==========================*/
00193   dict_index_t* index,    
00194   ulint   latch_mode, 
00195   btr_pcur_t* cursor,   
00196   const char* file,   
00197   ulint   line,   
00198   mtr_t*    mtr);   
00199 #define btr_pcur_open_at_rnd_pos(i,l,c,m)       \
00200   btr_pcur_open_at_rnd_pos_func(i,l,c,__FILE__,__LINE__,m)
00201 /**************************************************************/
00204 UNIV_INLINE
00205 void
00206 btr_pcur_close(
00207 /*===========*/
00208   btr_pcur_t* cursor);  
00209 /**************************************************************/
00216 UNIV_INTERN
00217 void
00218 btr_pcur_store_position(
00219 /*====================*/
00220   btr_pcur_t* cursor, 
00221   mtr_t*    mtr); 
00222 /**************************************************************/
00237 UNIV_INTERN
00238 ibool
00239 btr_pcur_restore_position_func(
00240 /*===========================*/
00241   ulint   latch_mode, 
00242   btr_pcur_t* cursor,   
00243   const char* file,   
00244   ulint   line,   
00245   mtr_t*    mtr);   
00246 #define btr_pcur_restore_position(l,cur,mtr)        \
00247   btr_pcur_restore_position_func(l,cur,__FILE__,__LINE__,mtr)
00248 /**************************************************************/
00254 UNIV_INTERN
00255 void
00256 btr_pcur_release_leaf(
00257 /*==================*/
00258   btr_pcur_t* cursor, 
00259   mtr_t*    mtr); 
00260 /*********************************************************/
00263 UNIV_INLINE
00264 ulint
00265 btr_pcur_get_rel_pos(
00266 /*=================*/
00267   const btr_pcur_t* cursor);
00268 /*********************************************************/
00270 UNIV_INLINE
00271 void
00272 btr_pcur_set_mtr(
00273 /*=============*/
00274   btr_pcur_t* cursor, 
00275   mtr_t*    mtr); 
00276 /*********************************************************/
00279 UNIV_INLINE
00280 mtr_t*
00281 btr_pcur_get_mtr(
00282 /*=============*/
00283   btr_pcur_t* cursor);  
00284 /**************************************************************/
00290 UNIV_INLINE
00291 void
00292 btr_pcur_commit_specify_mtr(
00293 /*========================*/
00294   btr_pcur_t* pcur, 
00295   mtr_t*    mtr); 
00296 /**************************************************************/
00299 UNIV_INLINE
00300 ibool
00301 btr_pcur_is_detached(
00302 /*=================*/
00303   btr_pcur_t* pcur);  
00304 /*********************************************************/
00308 UNIV_INLINE
00309 ibool
00310 btr_pcur_move_to_next(
00311 /*==================*/
00312   btr_pcur_t* cursor, 
00314   mtr_t*    mtr); 
00315 /*********************************************************/
00319 UNIV_INTERN
00320 ibool
00321 btr_pcur_move_to_prev(
00322 /*==================*/
00323   btr_pcur_t* cursor, 
00325   mtr_t*    mtr); 
00326 /*********************************************************/
00328 UNIV_INLINE
00329 void
00330 btr_pcur_move_to_last_on_page(
00331 /*==========================*/
00332   btr_pcur_t* cursor, 
00333   mtr_t*    mtr); 
00334 /*********************************************************/
00338 UNIV_INLINE
00339 ibool
00340 btr_pcur_move_to_next_user_rec(
00341 /*===========================*/
00342   btr_pcur_t* cursor, 
00344   mtr_t*    mtr); 
00345 /*********************************************************/
00350 UNIV_INTERN
00351 void
00352 btr_pcur_move_to_next_page(
00353 /*=======================*/
00354   btr_pcur_t* cursor, 
00356   mtr_t*    mtr); 
00357 /*********************************************************/
00367 UNIV_INTERN
00368 void
00369 btr_pcur_move_backward_from_page(
00370 /*=============================*/
00371   btr_pcur_t* cursor, 
00373   mtr_t*    mtr); 
00374 #ifdef UNIV_DEBUG
00375 /*********************************************************/
00378 UNIV_INLINE
00379 btr_cur_t*
00380 btr_pcur_get_btr_cur(
00381 /*=================*/
00382   const btr_pcur_t* cursor);  
00383 /*********************************************************/
00386 UNIV_INLINE
00387 page_cur_t*
00388 btr_pcur_get_page_cur(
00389 /*==================*/
00390   const btr_pcur_t* cursor);  
00391 #else /* UNIV_DEBUG */
00392 # define btr_pcur_get_btr_cur(cursor) (&(cursor)->btr_cur)
00393 # define btr_pcur_get_page_cur(cursor) (&(cursor)->btr_cur.page_cur)
00394 #endif /* UNIV_DEBUG */
00395 /*********************************************************/
00398 UNIV_INLINE
00399 page_t*
00400 btr_pcur_get_page(
00401 /*==============*/
00402   btr_pcur_t* cursor);
00403 /*********************************************************/
00406 UNIV_INLINE
00407 buf_block_t*
00408 btr_pcur_get_block(
00409 /*===============*/
00410   btr_pcur_t* cursor);
00411 /*********************************************************/
00414 UNIV_INLINE
00415 rec_t*
00416 btr_pcur_get_rec(
00417 /*=============*/
00418   btr_pcur_t* cursor);
00419 /*********************************************************/
00421 UNIV_INLINE
00422 ibool
00423 btr_pcur_is_on_user_rec(
00424 /*====================*/
00425   const btr_pcur_t* cursor);
00426 /*********************************************************/
00429 UNIV_INLINE
00430 ibool
00431 btr_pcur_is_after_last_on_page(
00432 /*===========================*/
00433   const btr_pcur_t* cursor);
00434 /*********************************************************/
00437 UNIV_INLINE
00438 ibool
00439 btr_pcur_is_before_first_on_page(
00440 /*=============================*/
00441   const btr_pcur_t* cursor);
00442 /*********************************************************/
00445 UNIV_INLINE
00446 ibool
00447 btr_pcur_is_before_first_in_tree(
00448 /*=============================*/
00449   btr_pcur_t* cursor, 
00450   mtr_t*    mtr); 
00451 /*********************************************************/
00454 UNIV_INLINE
00455 ibool
00456 btr_pcur_is_after_last_in_tree(
00457 /*===========================*/
00458   btr_pcur_t* cursor, 
00459   mtr_t*    mtr); 
00460 /*********************************************************/
00462 UNIV_INLINE
00463 void
00464 btr_pcur_move_to_next_on_page(
00465 /*==========================*/
00466   btr_pcur_t* cursor);
00467 /*********************************************************/
00469 UNIV_INLINE
00470 void
00471 btr_pcur_move_to_prev_on_page(
00472 /*==========================*/
00473   btr_pcur_t* cursor);
00476 /* The persistent B-tree cursor structure. This is used mainly for SQL
00477 selects, updates, and deletes. */
00478 
00479 struct btr_pcur_struct{
00480   btr_cur_t btr_cur;  
00481   ulint   latch_mode; 
00492   ulint   old_stored; 
00494   rec_t*    old_rec;  
00498   ulint   old_n_fields; 
00499   ulint   rel_pos;  
00503   buf_block_t*  block_when_stored;/* buffer block when the position was
00504           stored */
00505   ib_uint64_t modify_clock; 
00508   ulint   pos_state;  
00512   ulint   search_mode;  
00513   trx_t*    trx_if_known; 
00517   /*-----------------------------*/
00518   /* NOTE that the following fields may possess dynamically allocated
00519   memory which should be freed if not needed anymore! */
00520 
00521   mtr_t*    mtr;    
00524   byte*   old_rec_buf;  
00526   ulint   buf_size; 
00528 };
00529 
00530 #define BTR_PCUR_IS_POSITIONED  1997660512  /* TODO: currently, the state
00531             can be BTR_PCUR_IS_POSITIONED,
00532             though it really should be
00533             BTR_PCUR_WAS_POSITIONED,
00534             because we have no obligation
00535             to commit the cursor with
00536             mtr; similarly latch_mode may
00537             be out of date. This can
00538             lead to problems if btr_pcur
00539             is not used the right way;
00540             all current code should be
00541             ok. */
00542 #define BTR_PCUR_WAS_POSITIONED 1187549791
00543 #define BTR_PCUR_NOT_POSITIONED 1328997689
00544 
00545 #define BTR_PCUR_OLD_STORED 908467085
00546 #define BTR_PCUR_OLD_NOT_STORED 122766467
00547 
00548 #ifndef UNIV_NONINL
00549 #include "btr0pcur.ic"
00550 #endif
00551 
00552 #endif