1/*****************************************************************************
2
3Copyright (c) 2006, 2009, Oracle and/or its affiliates. All Rights Reserved.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License as published by the Free Software
7Foundation; version 2 of the License.
8
9This program is distributed in the hope that it will be useful, but WITHOUT
10ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
13You should have received a copy of the GNU General Public License along with
14this program; if not, write to the Free Software Foundation, Inc.,
1551 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
16
17*****************************************************************************/
18
19/**************************************************//**
20@file include/row0ext.ic
21Caching of externally stored column prefixes
22
23Created September 2006 Marko Makela
24*******************************************************/
25
26#include "rem0types.h"
27#include "btr0types.h"
28
29/********************************************************************//**
30Looks up a column prefix of an externally stored column.
31@return column prefix, or NULL if the column is not stored externally,
32or pointer to field_ref_zero if the BLOB pointer is unset */
33UNIV_INLINE
34const byte*
35row_ext_lookup_ith(
36/*===============*/
37 const row_ext_t* ext, /*!< in/out: column prefix cache */
38 ulint i, /*!< in: index of ext->ext[] */
39 ulint* len) /*!< out: length of prefix, in bytes,
40 at most ext->max_len */
41{
42 ut_ad(ext);
43 ut_ad(len);
44 ut_ad(i < ext->n_ext);
45
46 *len = ext->len[i];
47
48 ut_ad(*len <= ext->max_len);
49 ut_ad(ext->max_len > 0);
50
51 if (*len == 0) {
52 /* The BLOB could not be fetched to the cache. */
53 return(field_ref_zero);
54 } else {
55 return(ext->buf + i * ext->max_len);
56 }
57}
58
59/********************************************************************//**
60Looks up a column prefix of an externally stored column.
61@return column prefix, or NULL if the column is not stored externally,
62or pointer to field_ref_zero if the BLOB pointer is unset */
63UNIV_INLINE
64const byte*
65row_ext_lookup(
66/*===========*/
67 const row_ext_t* ext, /*!< in: column prefix cache */
68 ulint col, /*!< in: column number in the InnoDB
69 table object, as reported by
70 dict_col_get_no(); NOT relative to the
71 records in the clustered index */
72 ulint* len) /*!< out: length of prefix, in bytes,
73 at most ext->max_len */
74{
75 ulint i;
76
77 ut_ad(ext);
78 ut_ad(len);
79
80 for (i = 0; i < ext->n_ext; i++) {
81 if (col == ext->ext[i]) {
82 return(row_ext_lookup_ith(ext, i, len));
83 }
84 }
85
86 return(NULL);
87}
88