mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / storage / innodb_plugin / include / read0read.ic
blobcf6a45cfc67dec1c12fd06527ea7bd7448b95e95
1 /*****************************************************************************
3 Copyright (c) 1997, 2009, Innobase Oy. All Rights Reserved.
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.
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.
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 St, Fifth Floor, Boston, MA 02110-1301 USA
17 *****************************************************************************/
19 /**************************************************//**
20 @file include/read0read.ic
21 Cursor read
23 Created 2/16/1997 Heikki Tuuri
24 *******************************************************/
26 /*********************************************************************//**
27 Gets the nth trx id in a read view.
28 @return trx id */
29 UNIV_INLINE
30 trx_id_t
31 read_view_get_nth_trx_id(
32 /*=====================*/
33         const read_view_t*      view,   /*!< in: read view */
34         ulint                   n)      /*!< in: position */
36         ut_ad(n < view->n_trx_ids);
38         return(*(view->trx_ids + n));
41 /*********************************************************************//**
42 Sets the nth trx id in a read view. */
43 UNIV_INLINE
44 void
45 read_view_set_nth_trx_id(
46 /*=====================*/
47         read_view_t*    view,   /*!< in: read view */
48         ulint           n,      /*!< in: position */
49         trx_id_t        trx_id) /*!< in: trx id to set */
51         ut_ad(n < view->n_trx_ids);
53         *(view->trx_ids + n) = trx_id;
56 /*********************************************************************//**
57 Checks if a read view sees the specified transaction.
58 @return TRUE if sees */
59 UNIV_INLINE
60 ibool
61 read_view_sees_trx_id(
62 /*==================*/
63         const read_view_t*      view,   /*!< in: read view */
64         trx_id_t                trx_id) /*!< in: trx id */
66         ulint   n_ids;
67         int     cmp;
68         ulint   i;
70         if (ut_dulint_cmp(trx_id, view->up_limit_id) < 0) {
72                 return(TRUE);
73         }
75         if (ut_dulint_cmp(trx_id, view->low_limit_id) >= 0) {
77                 return(FALSE);
78         }
80         /* We go through the trx ids in the array smallest first: this order
81         may save CPU time, because if there was a very long running
82         transaction in the trx id array, its trx id is looked at first, and
83         the first two comparisons may well decide the visibility of trx_id. */
85         n_ids = view->n_trx_ids;
87         for (i = 0; i < n_ids; i++) {
89                 cmp = ut_dulint_cmp(
90                         trx_id,
91                         read_view_get_nth_trx_id(view, n_ids - i - 1));
92                 if (cmp <= 0) {
93                         return(cmp < 0);
94                 }
95         }
97         return(TRUE);