Drizzled Public API Documentation

row0ext.cc
1 /*****************************************************************************
2 
3 Copyright (C) 2006, 2009, Innobase Oy. 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., 51 Franklin
15 St, Fifth Floor, Boston, MA 02110-1301 USA
16 
17 *****************************************************************************/
18 
19 /**************************************************/
26 #include "row0ext.h"
27 
28 #ifdef UNIV_NONINL
29 #include "row0ext.ic"
30 #endif
31 
32 #include "btr0cur.h"
33 
34 /********************************************************************/
36 static
37 void
38 row_ext_cache_fill(
39 /*===============*/
40  row_ext_t* ext,
41  ulint i,
42  ulint zip_size,
43  const dfield_t* dfield)
44 {
45  const byte* field = static_cast<const byte *>(dfield_get_data(dfield));
46  ulint f_len = dfield_get_len(dfield);
47  byte* buf = ext->buf + i * REC_MAX_INDEX_COL_LEN;
48 
49  ut_ad(i < ext->n_ext);
50  ut_ad(dfield_is_ext(dfield));
52 
53  if (UNIV_UNLIKELY(!memcmp(field_ref_zero,
54  field + f_len - BTR_EXTERN_FIELD_REF_SIZE,
56  /* The BLOB pointer is not set: we cannot fetch it */
57  ext->len[i] = 0;
58  } else {
59  /* Fetch at most REC_MAX_INDEX_COL_LEN of the column.
60  The column should be non-empty. However,
61  trx_rollback_or_clean_all_recovered() may try to
62  access a half-deleted BLOB if the server previously
63  crashed during the execution of
64  btr_free_externally_stored_field(). */
66  buf, REC_MAX_INDEX_COL_LEN, zip_size, field, f_len);
67  }
68 }
69 
70 /********************************************************************/
73 UNIV_INTERN
74 row_ext_t*
76 /*===========*/
77  ulint n_ext,
78  const ulint* ext,
82  const dtuple_t* tuple,
88  ulint zip_size,
89  mem_heap_t* heap)
90 {
91  ulint i;
92  row_ext_t* ret = static_cast<row_ext_t *>(mem_heap_alloc(heap, (sizeof *ret)
93  + (n_ext - 1) * sizeof ret->len));
94 
95  ut_ad(ut_is_2pow(zip_size));
96  ut_ad(zip_size <= UNIV_PAGE_SIZE);
97 
98  ret->n_ext = n_ext;
99  ret->ext = ext;
100  ret->buf = static_cast<byte *>(mem_heap_alloc(heap, n_ext * REC_MAX_INDEX_COL_LEN));
101 #ifdef UNIV_DEBUG
102  memset(ret->buf, 0xaa, n_ext * REC_MAX_INDEX_COL_LEN);
103  UNIV_MEM_ALLOC(ret->buf, n_ext * REC_MAX_INDEX_COL_LEN);
104 #endif
105 
106  /* Fetch the BLOB prefixes */
107  for (i = 0; i < n_ext; i++) {
108  const dfield_t* dfield;
109 
110  dfield = dtuple_get_nth_field(tuple, ext[i]);
111  row_ext_cache_fill(ret, i, zip_size, dfield);
112  }
113 
114  return(ret);
115 }
byte * buf
Definition: row0ext.h:88
UNIV_INTERN row_ext_t * row_ext_create(ulint n_ext, const ulint *ext, const dtuple_t *tuple, ulint zip_size, mem_heap_t *heap)
Definition: row0ext.cc:75
UNIV_INTERN ulint btr_copy_externally_stored_field_prefix(byte *buf, ulint len, ulint zip_size, const byte *data, ulint local_len)
Definition: btr0cur.cc:5098
UNIV_INLINE ulint dfield_is_ext(const dfield_t *field)
ulint len[1]
Definition: row0ext.h:89
ulint n_ext
Definition: row0ext.h:86
UNIV_INLINE ulint dfield_get_len(const dfield_t *field)
#define ut_is_2pow(n)
Definition: ut0ut.h:162
#define ut_a(EXPR)
Definition: ut0dbg.h:105
UNIV_INLINE void * mem_heap_alloc(mem_heap_t *heap, ulint n)
const ulint * ext
Definition: row0ext.h:87
#define ut_ad(EXPR)
Definition: ut0dbg.h:127
#define BTR_EXTERN_FIELD_REF_SIZE
Definition: btr0types.h:170
const byte field_ref_zero[BTR_EXTERN_FIELD_REF_SIZE]
Definition: btr0cur.cc:135