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 /*********************************************************/
00300 UNIV_INLINE
00301 ibool
00302 btr_pcur_move_to_next(
00303 /*==================*/
00304   btr_pcur_t* cursor, 
00306   mtr_t*    mtr); 
00307 /*********************************************************/
00311 UNIV_INTERN
00312 ibool
00313 btr_pcur_move_to_prev(
00314 /*==================*/
00315   btr_pcur_t* cursor, 
00317   mtr_t*    mtr); 
00318 /*********************************************************/
00320 UNIV_INLINE
00321 void
00322 btr_pcur_move_to_last_on_page(
00323 /*==========================*/
00324   btr_pcur_t* cursor, 
00325   mtr_t*    mtr); 
00326 /*********************************************************/
00330 UNIV_INLINE
00331 ibool
00332 btr_pcur_move_to_next_user_rec(
00333 /*===========================*/
00334   btr_pcur_t* cursor, 
00336   mtr_t*    mtr); 
00337 /*********************************************************/
00342 UNIV_INTERN
00343 void
00344 btr_pcur_move_to_next_page(
00345 /*=======================*/
00346   btr_pcur_t* cursor, 
00348   mtr_t*    mtr); 
00349 /*********************************************************/
00359 UNIV_INTERN
00360 void
00361 btr_pcur_move_backward_from_page(
00362 /*=============================*/
00363   btr_pcur_t* cursor, 
00365   mtr_t*    mtr); 
00366 #ifdef UNIV_DEBUG
00367 /*********************************************************/
00370 UNIV_INLINE
00371 btr_cur_t*
00372 btr_pcur_get_btr_cur(
00373 /*=================*/
00374   const btr_pcur_t* cursor);  
00375 /*********************************************************/
00378 UNIV_INLINE
00379 page_cur_t*
00380 btr_pcur_get_page_cur(
00381 /*==================*/
00382   const btr_pcur_t* cursor);  
00383 #else /* UNIV_DEBUG */
00384 # define btr_pcur_get_btr_cur(cursor) (&(cursor)->btr_cur)
00385 # define btr_pcur_get_page_cur(cursor) (&(cursor)->btr_cur.page_cur)
00386 #endif /* UNIV_DEBUG */
00387 /*********************************************************/
00390 UNIV_INLINE
00391 page_t*
00392 btr_pcur_get_page(
00393 /*==============*/
00394   btr_pcur_t* cursor);
00395 /*********************************************************/
00398 UNIV_INLINE
00399 buf_block_t*
00400 btr_pcur_get_block(
00401 /*===============*/
00402   btr_pcur_t* cursor);
00403 /*********************************************************/
00406 UNIV_INLINE
00407 rec_t*
00408 btr_pcur_get_rec(
00409 /*=============*/
00410   btr_pcur_t* cursor);
00411 /*********************************************************/
00413 UNIV_INLINE
00414 ibool
00415 btr_pcur_is_on_user_rec(
00416 /*====================*/
00417   const btr_pcur_t* cursor);
00418 /*********************************************************/
00421 UNIV_INLINE
00422 ibool
00423 btr_pcur_is_after_last_on_page(
00424 /*===========================*/
00425   const btr_pcur_t* cursor);
00426 /*********************************************************/
00429 UNIV_INLINE
00430 ibool
00431 btr_pcur_is_before_first_on_page(
00432 /*=============================*/
00433   const btr_pcur_t* cursor);
00434 /*********************************************************/
00437 UNIV_INLINE
00438 ibool
00439 btr_pcur_is_before_first_in_tree(
00440 /*=============================*/
00441   btr_pcur_t* cursor, 
00442   mtr_t*    mtr); 
00443 /*********************************************************/
00446 UNIV_INLINE
00447 ibool
00448 btr_pcur_is_after_last_in_tree(
00449 /*===========================*/
00450   btr_pcur_t* cursor, 
00451   mtr_t*    mtr); 
00452 /*********************************************************/
00454 UNIV_INLINE
00455 void
00456 btr_pcur_move_to_next_on_page(
00457 /*==========================*/
00458   btr_pcur_t* cursor);
00459 /*********************************************************/
00461 UNIV_INLINE
00462 void
00463 btr_pcur_move_to_prev_on_page(
00464 /*==========================*/
00465   btr_pcur_t* cursor);
00468 /* The persistent B-tree cursor structure. This is used mainly for SQL
00469 selects, updates, and deletes. */
00470 
00471 struct btr_pcur_struct{
00472   btr_cur_t btr_cur;  
00473   ulint   latch_mode; 
00484   ulint   old_stored; 
00486   rec_t*    old_rec;  
00490   ulint   old_n_fields; 
00491   ulint   rel_pos;  
00495   buf_block_t*  block_when_stored;/* buffer block when the position was
00496           stored */
00497   ib_uint64_t modify_clock; 
00500   ulint   pos_state;  
00504   ulint   search_mode;  
00505   trx_t*    trx_if_known; 
00509   /*-----------------------------*/
00510   /* NOTE that the following fields may possess dynamically allocated
00511   memory which should be freed if not needed anymore! */
00512 
00513   mtr_t*    mtr;    
00516   byte*   old_rec_buf;  
00518   ulint   buf_size; 
00520 };
00521 
00522 #define BTR_PCUR_IS_POSITIONED  1997660512  /* TODO: currently, the state
00523             can be BTR_PCUR_IS_POSITIONED,
00524             though it really should be
00525             BTR_PCUR_WAS_POSITIONED,
00526             because we have no obligation
00527             to commit the cursor with
00528             mtr; similarly latch_mode may
00529             be out of date. This can
00530             lead to problems if btr_pcur
00531             is not used the right way;
00532             all current code should be
00533             ok. */
00534 #define BTR_PCUR_WAS_POSITIONED 1187549791
00535 #define BTR_PCUR_NOT_POSITIONED 1328997689
00536 
00537 #define BTR_PCUR_OLD_STORED 908467085
00538 #define BTR_PCUR_OLD_NOT_STORED 122766467
00539 
00540 #ifndef UNIV_NONINL
00541 #include "btr0pcur.ic"
00542 #endif
00543 
00544 #endif