1/*****************************************************************************
2
3Copyright (c) 2006, 2019, 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, version 2.0, as published by the
7Free Software Foundation.
8
9This program is also distributed with certain software (including but not
10limited to OpenSSL) that is licensed under separate terms, as designated in a
11particular file or component or in included license documentation. The authors
12of MySQL hereby grant you an additional permission to link the program and
13your derivative works with the separately licensed software that they have
14included with MySQL.
15
16This program is distributed in the hope that it will be useful, but WITHOUT
17ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
19for 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 St, Fifth Floor, Boston, MA 02110-1301  USA
24
25*****************************************************************************/
26
27/** @file include/row0ext.ic
28 Caching of externally stored column prefixes
29
30 Created September 2006 Marko Makela
31 *******************************************************/
32
33#include "btr0types.h"
34#include "rem0types.h"
35
36/** Looks up a column prefix of an externally stored column.
37 @return column prefix, or NULL if the column is not stored externally,
38 or pointer to field_ref_zero if the BLOB pointer is unset */
39UNIV_INLINE
40const byte *row_ext_lookup_ith(
41    const row_ext_t *ext, /*!< in/out: column prefix cache */
42    ulint i,              /*!< in: index of ext->ext[] */
43    ulint *len)           /*!< out: length of prefix, in bytes,
44                          at most ext->max_len */
45{
46  ut_ad(ext);
47  ut_ad(len);
48  ut_ad(i < ext->n_ext);
49
50  *len = ext->len[i];
51
52  ut_ad(*len <= ext->max_len);
53  ut_ad(ext->max_len > 0);
54
55  if (*len == 0) {
56    /* The BLOB could not be fetched to the cache. */
57    return (field_ref_zero);
58  } else {
59    return (ext->buf + i * ext->max_len);
60  }
61}
62
63/** Looks up a column prefix of an externally stored column.
64 @return column prefix, or NULL if the column is not stored externally,
65 or pointer to field_ref_zero if the BLOB pointer is unset */
66UNIV_INLINE
67const byte *row_ext_lookup(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 (nullptr);
87}
88