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
6it under the terms of the GNU General Public License, version 2.0,
7as published by the Free Software Foundation.
8
9This program is also distributed with certain software (including
10but not limited to OpenSSL) that is licensed under separate terms,
11as designated in a particular file or component or in included license
12documentation.  The authors of MySQL hereby grant you an additional
13permission to link the program and your derivative works with the
14separately licensed software that they have included with MySQL.
15
16This program is distributed in the hope that it will be useful,
17but WITHOUT ANY WARRANTY; without even the implied warranty of
18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19GNU General Public License, version 2.0, for more details.
20
21You should have received a copy of the GNU General Public License along with
22this program; if not, write to the Free Software Foundation, Inc.,
2351 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
24
25*****************************************************************************/
26
27/**************************************************//**
28@file include/row0ext.ic
29Caching of externally stored column prefixes
30
31Created September 2006 Marko Makela
32*******************************************************/
33
34#include "rem0types.h"
35#include "btr0types.h"
36
37/********************************************************************//**
38Looks up a column prefix of an externally stored column.
39@return column prefix, or NULL if the column is not stored externally,
40or pointer to field_ref_zero if the BLOB pointer is unset */
41UNIV_INLINE
42const byte*
43row_ext_lookup_ith(
44/*===============*/
45	const row_ext_t*	ext,	/*!< in/out: column prefix cache */
46	ulint			i,	/*!< in: index of ext->ext[] */
47	ulint*			len)	/*!< out: length of prefix, in bytes,
48					at most ext->max_len */
49{
50	ut_ad(ext);
51	ut_ad(len);
52	ut_ad(i < ext->n_ext);
53
54	*len = ext->len[i];
55
56	ut_ad(*len <= ext->max_len);
57	ut_ad(ext->max_len > 0);
58
59	if (*len == 0) {
60		/* The BLOB could not be fetched to the cache. */
61		return(field_ref_zero);
62	} else {
63		return(ext->buf + i * ext->max_len);
64	}
65}
66
67/********************************************************************//**
68Looks up a column prefix of an externally stored column.
69@return column prefix, or NULL if the column is not stored externally,
70or pointer to field_ref_zero if the BLOB pointer is unset */
71UNIV_INLINE
72const byte*
73row_ext_lookup(
74/*===========*/
75	const row_ext_t*	ext,	/*!< in: column prefix cache */
76	ulint			col,	/*!< in: column number in the InnoDB
77					table object, as reported by
78					dict_col_get_no(); NOT relative to the
79					records in the clustered index */
80	ulint*			len)	/*!< out: length of prefix, in bytes,
81					at most ext->max_len */
82{
83	ulint	i;
84
85	ut_ad(ext);
86	ut_ad(len);
87
88	for (i = 0; i < ext->n_ext; i++) {
89		if (col == ext->ext[i]) {
90			return(row_ext_lookup_ith(ext, i, len));
91		}
92	}
93
94	return(NULL);
95}
96