Debian Codegraph @

storage/innobase/row/row0ext.cc

raw
1 /*****************************************************************************
2
3 Copyright (c) 2006, 2026, Oracle and/or its affiliates.
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, version 2.0, as published by the
7 Free Software Foundation.
8
9 This program is designed to work with certain software (including
10 but not limited to OpenSSL) that is licensed under separate terms,
11 as designated in a particular file or component or in included license
12 documentation. The authors of MySQL hereby grant you an additional
13 permission to link the program and your derivative works with the
14 separately licensed software that they have either included with
15 the program or referenced in the documentation.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
20 for more details.
21
22 You should have received a copy of the GNU General Public License along with
23 this program; if not, write to the Free Software Foundation, Inc.,
24 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
26 *****************************************************************************/
27
28 /** @file row/row0ext.cc
29 Caching of externally stored column prefixes
30
31 Created September 2006 Marko Makela
32 *******************************************************/
33
34 #include "row0ext.h"
35 #include "lob0lob.h"
36
37 #ifdef UNIV_NONINL
38 #include "row0ext.ic"
39 #endif
40
41 #include "btr0cur.h"
42
43 /** Fills the column prefix cache of an externally stored column.
44 @param[in] index clustered index from which LOB is fetched.
45 @param[in,out] ext column prefix cache
46 @param[in] i index of ext->ext[]
47 @param[in] page_size page size
48 @param[in] dfield data field
49 @param[in] is_sdi true for SDI Index */
50 static void row_ext_cache_fill(const dict_index_t *index, row_ext_t *ext,
51 ulint i, const page_size_t &page_size,
52 IF_DEBUG(bool is_sdi, ) const dfield_t *dfield) {
53 const byte *field = static_cast<const byte *>(dfield_get_data(dfield));
54 ulint f_len = dfield_get_len(dfield);
55 byte *buf = ext->buf + i * ext->max_len;
56 lob::ref_t blobref(dfield->blobref());
57
58 ut_ad(ext->max_len > 0);
59 ut_ad(i < ext->n_ext);
60 ut_ad(dfield_is_ext(dfield));
61 ut_a(f_len >= BTR_EXTERN_FIELD_REF_SIZE);
62
63 if (blobref.is_null()) {
64 /* The BLOB pointer is not set: we cannot fetch it */
65 ext->len[i] = 0;
66 } else {
67 if (ext->max_len == REC_VERSION_56_MAX_INDEX_COL_LEN &&
68 f_len > BTR_EXTERN_FIELD_REF_SIZE) {
69 /* In this case, the field is in B format or beyond,
70 (refer to the definition of row_ext_t.max_len)
71 and the field is already fill with prefix, otherwise
72 f_len would be BTR_EXTERN_FIELD_REF_SIZE.
73 So there is no need to re-read the prefix externally,
74 but just copy the local prefix to buf. Please note
75 if the ext->len[i] is zero, it means an error
76 as above. */
77 memcpy(buf, field, f_len - BTR_EXTERN_FIELD_REF_SIZE);
78 ext->len[i] = f_len - BTR_EXTERN_FIELD_REF_SIZE;
79 } else {
80 /* Fetch at most ext->max_len of the column.
81 The column should be non-empty. However,
82 trx_rollback_or_clean_all_recovered() may try to
83 access a half-deleted BLOB if the server previously
84 crashed during the execution of
85 btr_free_externally_stored_field(). */
86 ext->len[i] = lob::btr_copy_externally_stored_field_prefix_func(
87 nullptr, index, buf, ext->max_len, page_size, field,
88 IF_DEBUG(is_sdi, ) f_len);
89 }
90 }
91 }
92
93 /** Creates a cache of column prefixes of externally stored columns.
94 @param[in] index the index to which LOB belongs.
95 @param[in] n_ext number of externally stored columns
96 @param[in] ext col_no's of externally stored columns in the InnoDB
97 table object, as reported by dict_col_get_no(); NOT relative to the records
98 in the clustered index
99 @param[in] flags table->flags
100 @param[in] tuple data tuple containing the field references of the
101 externally stored columns; must be indexed by col_no; the clustered index record
102 must be covered by a lock or a page latch to prevent deletion (rollback
103 or purge)
104 @param[in] is_sdi true for SDI Indexes
105 @param[in,out] heap heap where created
106 @return own: column prefix cache */
107 row_ext_t *row_ext_create_func(const dict_index_t *index, ulint n_ext,
108 const ulint *ext, uint32_t flags,
109 const dtuple_t *tuple,
110 IF_DEBUG(bool is_sdi, ) mem_heap_t *heap) {
111 ulint i;
112 const page_size_t &page_size = dict_tf_get_page_size(flags);
113
114 /* LOBs are available in clustered index only. */
115 ut_ad(index->is_clustered());
116
117 row_ext_t *ret;
118
119 ut_ad(n_ext > 0);
120
121 ret = static_cast<row_ext_t *>(
122 mem_heap_alloc(heap, (sizeof *ret) + (n_ext - 1) * sizeof ret->len));
123
124 ret->index = index;
125 ret->n_ext = n_ext;
126 ret->ext = ext;
127 ret->max_len = DICT_MAX_FIELD_LEN_BY_FORMAT_FLAG(flags);
128 ret->page_size.copy_from(page_size);
129
130 ret->buf = static_cast<byte *>(mem_heap_alloc(heap, n_ext * ret->max_len));
131
132 #ifdef UNIV_DEBUG
133 memset(ret->buf, 0xaa, n_ext * ret->max_len);
134 UNIV_MEM_ALLOC(ret->buf, n_ext * ret->max_len);
135 #endif
136
137 /* Fetch the BLOB prefixes */
138 for (i = 0; i < n_ext; i++) {
139 const dfield_t *dfield;
140
141 dfield = dtuple_get_nth_field(tuple, ext[i]);
142 row_ext_cache_fill(index, ret, i, page_size, IF_DEBUG(is_sdi, ) dfield);
143 }
144
145 return (ret);
146 }