Debian Codegraph @

storage/innobase/lob/lob0update.cc

raw
1 /*****************************************************************************
2
3 Copyright (c) 2016, 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 #include "field.h"
29 #include "lob0impl.h"
30 #include "lob0index.h"
31 #include "lob0lob.h"
32 #include "lob0pages.h"
33 #include "my_dbug.h"
34 #include "row0upd.h"
35 #include "table.h"
36 #include "trx0trx.h"
37
38 namespace lob {
39
40 /** Replace a large object (LOB) with the given new data of equal length.
41 @param[in] ctx replace operation context.
42 @param[in] trx the transaction that is doing the read.
43 @param[in] index the clustered index containing the LOB.
44 @param[in] ref the LOB reference identifying the LOB.
45 @param[in] first_page the first page of the LOB.
46 @param[in] offset replace the LOB from the given offset.
47 @param[in] len the length of LOB data that needs to be
48 replaced.
49 @param[in] buf the buffer (owned by caller) with new data
50 (len bytes).
51 @param[in] count number of replace done on current LOB.
52 @return DB_SUCCESS on success, error code on failure. */
53 dberr_t replace(InsertContext &ctx, trx_t *trx, dict_index_t *index, ref_t ref,
54 first_page_t &first_page, ulint offset, ulint len, byte *buf,
55 int count);
56
57 /** Replace a small portion of large object (LOB) with the given new data of
58 equal length.
59 @param[in] ctx replace operation context.
60 @param[in] trx the transaction that is doing the read.
61 @param[in] index the clustered index containing the LOB.
62 @param[in] ref the LOB reference identifying the LOB.
63 @param[in] first_page the first page of the LOB.
64 @param[in] offset replace the LOB from the given offset.
65 @param[in] len the length of LOB data that needs to be
66 replaced.
67 @param[in] buf the buffer (owned by caller) with new data
68 (len bytes).
69 @return DB_SUCCESS on success, error code on failure. */
70 static dberr_t replace_inline(InsertContext &ctx, trx_t *trx,
71 dict_index_t *index, ref_t ref,
72 first_page_t &first_page, ulint offset, ulint len,
73 byte *buf);
74
75 #ifdef UNIV_DEBUG
76 /** Print an information message in the server log file, informing
77 that the LOB partial update feature code is hit.
78 @param[in] uf the update field information
79 @param[in] index index where partial update happens.*/
80 static void print_partial_update_hit(const upd_field_t *uf,
81 const dict_index_t *index) {
82 ib::info(ER_IB_MSG_632) << "LOB partial update of field=("
83 << uf->mysql_field->field_name << ") on index=("
84 << index->name << ") in table=(" << index->table_name
85 << ")";
86 }
87 #endif /* UNIV_DEBUG */
88
89 /** Update a portion of the given LOB.
90 @param[in] ctx update operation context information.
91 @param[in] trx the transaction that is doing the modification.
92 @param[in] index the clustered index containing the LOB.
93 @param[in] upd update vector
94 @param[in] field_no the LOB field number
95 @param[in] blobref LOB reference stored in clust record.
96 @return DB_SUCCESS on success, error code on failure. */
97 dberr_t update(InsertContext &ctx, trx_t *trx, dict_index_t *index,
98 const upd_t *upd, ulint field_no, ref_t blobref) {
99 DBUG_TRACE;
100 dberr_t err = DB_SUCCESS;
101 mtr_t *mtr = ctx.get_mtr();
102 const undo_no_t undo_no = (trx == nullptr ? 0 : trx->undo_no - 1);
103
104 const Binary_diff_vector *bdiff_vector =
105 upd->get_binary_diff_by_field_no(field_no);
106
107 const ulint bytes_changed = upd_t::get_total_modified_bytes(*bdiff_vector);
108
109 /* Whether the update to the LOB can be considered as a small change. */
110 const bool small_change =
111 (bytes_changed <= ref_t::LOB_SMALL_CHANGE_THRESHOLD);
112
113 const upd_field_t *const uf = upd->get_field_by_field_no(field_no, index);
114
115 #ifdef UNIV_DEBUG
116 /* Print information on server error log file, which can be
117 used to confirm if InnoDB did partial update or not. */
118 DBUG_EXECUTE_IF("lob_print_partial_update_hit",
119 print_partial_update_hit(uf, index););
120 #endif /* UNIV_DEBUG */
121
122 page_no_t first_page_no = blobref.page_no();
123 space_id_t space_id = blobref.space_id();
124
125 const page_size_t page_size = dict_table_page_size(index->table);
126 const page_id_t first_page_id(space_id, first_page_no);
127
128 first_page_t first_page(mtr, index);
129 first_page.load_x(first_page_id, page_size);
130 first_page.set_last_trx_id(trx->id);
131 first_page.set_last_trx_undo_no(undo_no);
132 uint32_t lob_version = 0;
133
134 if (small_change) {
135 lob_version = first_page.get_lob_version();
136 } else {
137 lob_version = first_page.incr_lob_version();
138 }
139
140 int count = 0;
141 for (Binary_diff_vector::const_iterator iter = bdiff_vector->begin();
142 iter != bdiff_vector->end(); ++iter, ++count) {
143 const Binary_diff *bdiff = iter;
144
145 if (small_change) {
146 err = replace_inline(ctx, trx, index, blobref, first_page,
147 bdiff->offset(), bdiff->length(),
148 (byte *)bdiff->new_data(uf->mysql_field));
149
150 } else {
151 err = replace(ctx, trx, index, blobref, first_page, bdiff->offset(),
152 bdiff->length(), (byte *)bdiff->new_data(uf->mysql_field),
153 count);
154 }
155
156 if (err != DB_SUCCESS) {
157 break;
158 }
159 }
160
161 blobref.set_offset(lob_version, mtr);
162
163 return err;
164 }
165
166 #ifdef UNIV_DEBUG
167
168 /** Validate the size of the given LOB.
169 @param[in] lob_size Expected size of the LOB, mostly obtained from
170 the LOB reference.
171 @param[in] index Clustered index containing the LOB.
172 @param[in] node_loc Location of the first LOB index entry.
173 @param[in] mtr Mini-transaction context.
174 @return true if size is valid, false otherwise. */
175 bool validate_size(const ulint lob_size, dict_index_t *index,
176 fil_addr_t node_loc, mtr_t *mtr) {
177 buf_block_t *block = nullptr;
178
179 ulint total_len = 0;
180
181 index_entry_t entry(mtr, index);
182
183 while (!fil_addr_is_null(node_loc)) {
184 if (block == nullptr) {
185 block = entry.load_x(node_loc);
186 } else if (block->page.id.page_no() != node_loc.page) {
187 block = entry.load_x(node_loc);
188 } else {
189 /* Next entry in the same page. */
190 ut_ad(block == entry.get_block());
191 entry.reset(node_loc);
192 }
193
194 /* Get the amount of data */
195 ulint data_len = entry.get_data_len();
196
197 total_len += data_len;
198
199 /* The next node should not be the same as the current node. */
200 ut_ad(!node_loc.is_equal(entry.get_next()));
201
202 node_loc = entry.get_next();
203 }
204
205 ut_ad(lob_size == total_len);
206
207 return (lob_size == total_len);
208 }
209 #endif /* UNIV_DEBUG */
210
211 /** Find the file location of the index entry which gives the portion of LOB
212 containing the requested offset.
213 @param[in] index The clustered index containing LOB.
214 @param[in] node_loc Location of first index entry.
215 @param[in] offset The LOB offset whose location we seek.
216 @param[in] mtr Mini-transaction context.
217 @return file location of index entry which contains requested LOB offset.*/
218 fil_addr_t find_offset(dict_index_t *index, fil_addr_t node_loc, ulint &offset,
219 mtr_t *mtr) {
220 DBUG_TRACE;
221 ut_ad(!fil_addr_is_null(node_loc));
222
223 buf_block_t *block = nullptr;
224
225 index_entry_t entry(mtr, index);
226
227 while (!fil_addr_is_null(node_loc)) {
228 if (block == nullptr) {
229 block = entry.load_x(node_loc);
230 } else if (block->page.id.page_no() != node_loc.page) {
231 block = entry.load_x(node_loc);
232 } else {
233 /* Next entry in the same page. */
234 ut_ad(block == entry.get_block());
235 entry.reset(node_loc);
236 }
237
238 /* Get the amount of data */
239 ulint data_len = entry.get_data_len();
240
241 if (offset < data_len) {
242 break;
243 }
244
245 offset -= data_len;
246
247 /* The next node should not be the same as the current node. */
248 ut_ad(!node_loc.is_equal(entry.get_next()));
249
250 node_loc = entry.get_next();
251 }
252
253 return node_loc;
254 }
255
256 /** Replace a large object (LOB) with the given new data of equal length.
257 @param[in] ctx replace operation context.
258 @param[in] trx the transaction that is doing the read.
259 @param[in] index the clustered index containing the LOB.
260 @param[in] ref the LOB reference identifying the LOB.
261 @param[in] first_page the first page of the LOB.
262 @param[in] offset replace the LOB from the given offset.
263 @param[in] len the length of LOB data that needs to be
264 replaced.
265 @param[in] buf the buffer (owned by caller) with new data
266 (len bytes).
267 @param[in] count number of replace done on current LOB.
268 @return DB_SUCCESS on success, error code on failure. */
269 dberr_t replace(InsertContext &ctx, trx_t *trx, dict_index_t *index, ref_t ref,
270 first_page_t &first_page, ulint offset, ulint len, byte *buf,
271 int count) {
272 DBUG_TRACE;
273
274 dberr_t ret(DB_SUCCESS);
275 mtr_t *mtr = ctx.get_mtr();
276 const undo_no_t undo_no = (trx == nullptr ? 0 : trx->undo_no - 1);
277 const uint32_t lob_version = first_page.get_lob_version();
278
279 ut_ad(offset >= DICT_ANTELOPE_MAX_INDEX_COL_LEN ||
280 dict_table_has_atomic_blobs(index->table));
281
282 if (!dict_table_has_atomic_blobs(index->table)) {
283 /* For compact and redundant row format, remove the local
284 prefix length from the offset. */
285
286 ut_ad(offset >= DICT_ANTELOPE_MAX_INDEX_COL_LEN);
287 offset -= DICT_ANTELOPE_MAX_INDEX_COL_LEN;
288 }
289
290 DBUG_LOG("lob", "adjusted offset=" << offset << ", len=" << len);
291
292 page_no_t first_page_no = ref.page_no();
293 space_id_t space_id = ref.space_id();
294
295 const page_size_t page_size = dict_table_page_size(index->table);
296 const page_id_t first_page_id(space_id, first_page_no);
297
298 if (count == 0) {
299 /** Repeatedly updating the LOB should increment the
300 ref count only once. */
301 #ifdef LOB_DEBUG
302 std::cout << "thread=" << std::this_thread::get_id()
303 << ", lob::replace(): table=" << index->table->name
304 << ", ref=" << ref << std::endl;
305 #endif
306 }
307
308 flst_base_node_t *base_node = first_page.index_list();
309 fil_addr_t node_loc = flst_get_first(base_node, mtr);
310
311 ulint page_offset = offset;
312
313 node_loc = find_offset(index, node_loc, page_offset, mtr);
314 ulint want = len; /* want to be replaced. */
315 const byte *ptr = buf;
316
317 index_entry_t cur_entry(mtr, index);
318
319 if (page_offset > 0) {
320 /* Part of the page contents needs to be changed. So the
321 old data must be read. */
322
323 buf_block_t *tmp_block = cur_entry.load_x(node_loc);
324
325 page_no_t cur_page_no = cur_entry.get_page_no();
326
327 buf_block_t *new_block = nullptr;
328
329 if (cur_page_no == first_page_no) {
330 /* If current page number is the same as first page
331 number, then first page is already loaded. Just update
332 the pointer. */
333 first_page.set_block(tmp_block);
334 new_block = first_page.replace(trx, page_offset, ptr, want, mtr);
335
336 if (new_block == nullptr) {
337 ret = DB_OUT_OF_FILE_SPACE;
338 goto error;
339 }
340
341 } else {
342 /* If current page number is NOT the same as first page
343 number, then load first page here. */
344 first_page.load_x(first_page_id, page_size);
345 data_page_t page(mtr, index);
346 page.load_x(cur_page_no);
347 new_block = page.replace(trx, page_offset, ptr, want, mtr);
348
349 if (new_block == nullptr) {
350 ret = DB_OUT_OF_FILE_SPACE;
351 goto error;
352 }
353 }
354 page_offset = 0;
355
356 data_page_t new_page(new_block, mtr, index);
357
358 /* Allocate a new index entry. First page is loaded by now. */
359 flst_node_t *new_node = first_page.alloc_index_entry(false);
360
361 if (new_node == nullptr) {
362 ret = DB_OUT_OF_FILE_SPACE;
363 goto error;
364 }
365
366 index_entry_t new_entry(new_node, mtr, index);
367 new_entry.set_versions_null();
368 new_entry.set_trx_id(trx->id);
369 new_entry.set_trx_id_modifier(trx->id);
370 new_entry.set_trx_undo_no(undo_no);
371 new_entry.set_trx_undo_no_modifier(undo_no);
372 new_entry.set_page_no(new_page.get_page_no());
373 new_entry.set_data_len(new_page.get_data_len());
374 new_entry.set_lob_version(lob_version);
375
376 cur_entry.set_trx_undo_no_modifier(undo_no);
377 cur_entry.set_trx_id_modifier(trx->id);
378 cur_entry.insert_after(base_node, new_entry);
379 cur_entry.remove(base_node);
380 new_entry.set_old_version(cur_entry);
381
382 node_loc = new_entry.get_next();
383 }
384
385 while (!fil_addr_is_null(node_loc) && want > 0) {
386 /* One page is updated for each iteration in the loop. */
387
388 buf_block_t *cur_block = cur_entry.load_x(node_loc);
389 page_no_t cur_page_no = cur_entry.get_page_no();
390
391 if (cur_page_no == first_page_no) {
392 first_page.set_block(cur_block);
393 } else {
394 first_page.load_x(first_page_id, page_size);
395 }
396
397 /* Get the page number */
398 page_no_t page_no = cur_entry.get_page_no();
399 page_id_t page_id(space_id, page_no);
400 ulint data_len = cur_entry.get_data_len();
401
402 if (want < data_len) {
403 break;
404 }
405
406 /* Full data in data page is replaced. So no need to
407 read old page. */
408 data_page_t new_page(mtr, index);
409
410 if (new_page.alloc(mtr, false) == nullptr) {
411 ret = DB_OUT_OF_FILE_SPACE;
412 goto error;
413 }
414
415 new_page.write(ptr, want);
416
417 /* Allocate a new index entry */
418 flst_node_t *new_node = first_page.alloc_index_entry(false);
419
420 if (new_node == nullptr) {
421 ret = DB_OUT_OF_FILE_SPACE;
422 goto error;
423 }
424
425 index_entry_t new_entry(new_node, mtr, index);
426 new_entry.set_lob_version(lob_version);
427 new_entry.set_versions_null();
428 new_entry.set_trx_id(trx->id);
429 new_entry.set_trx_id_modifier(trx->id);
430 new_entry.set_trx_undo_no(undo_no);
431 new_entry.set_trx_undo_no_modifier(undo_no);
432 new_entry.set_page_no(new_page.get_page_no());
433 new_entry.set_data_len(new_page.get_data_len());
434
435 cur_entry.set_trx_id_modifier(trx->id);
436 cur_entry.set_trx_undo_no_modifier(undo_no);
437 cur_entry.insert_after(base_node, new_entry);
438 cur_entry.remove(base_node);
439 new_entry.set_old_version(cur_entry);
440
441 node_loc = new_entry.get_next();
442 }
443
444 if (!fil_addr_is_null(node_loc) && want > 0) {
445 /* Part of the page contents needs to be changed. So the
446 old data must be read. */
447
448 cur_entry.load_x(node_loc);
449 first_page.load_x(first_page_id, page_size);
450
451 page_no_t cur_page_no = cur_entry.get_page_no();
452
453 buf_block_t *new_block = nullptr;
454
455 if (cur_page_no == first_page_no) {
456 new_block = first_page.replace(trx, 0, ptr, want, mtr);
457 } else {
458 data_page_t page(mtr, index);
459 page.load_x(cur_page_no);
460 new_block = page.replace(trx, 0, ptr, want, mtr);
461 }
462
463 data_page_t new_page(new_block, mtr, index);
464
465 /* Allocate a new index entry */
466 flst_node_t *new_node = first_page.alloc_index_entry(false);
467
468 if (new_node == nullptr) {
469 ret = DB_OUT_OF_FILE_SPACE;
470 goto error;
471 }
472
473 index_entry_t new_entry(new_node, mtr, index);
474 new_entry.set_lob_version(lob_version);
475 new_entry.set_versions_null();
476 new_entry.set_trx_id(trx->id);
477 new_entry.set_trx_id_modifier(trx->id);
478 new_entry.set_trx_undo_no(undo_no);
479 new_entry.set_trx_undo_no_modifier(undo_no);
480 new_entry.set_page_no(new_page.get_page_no());
481 new_entry.set_data_len(new_page.get_data_len());
482
483 cur_entry.set_trx_undo_no_modifier(undo_no);
484 cur_entry.set_trx_id_modifier(trx->id);
485 cur_entry.insert_after(base_node, new_entry);
486 cur_entry.remove(base_node);
487 new_entry.set_old_version(cur_entry);
488 }
489
490 #ifdef LOB_DEBUG
491 first_page.print_index_entries(std::cout);
492 #endif /* LOB_DEBUG */
493
494 return DB_SUCCESS;
495
496 error:
497 ut_ad(ret != DB_SUCCESS);
498
499 return ret;
500 }
501
502 static dberr_t replace_inline(InsertContext &ctx, trx_t *trx,
503 dict_index_t *index, ref_t ref,
504 first_page_t &first_page, ulint offset, ulint len,
505 byte *buf) {
506 DBUG_TRACE;
507
508 mtr_t *mtr = ctx.get_mtr();
509 const undo_no_t undo_no = (trx == nullptr ? 0 : trx->undo_no - 1);
510
511 ut_ad(offset >= DICT_ANTELOPE_MAX_INDEX_COL_LEN ||
512 dict_table_has_atomic_blobs(index->table));
513
514 if (!dict_table_has_atomic_blobs(index->table)) {
515 /* For compact and redundant row format, remove the local
516 prefix length from the offset. */
517
518 ut_ad(offset >= DICT_ANTELOPE_MAX_INDEX_COL_LEN);
519 offset -= DICT_ANTELOPE_MAX_INDEX_COL_LEN;
520 }
521
522 DBUG_LOG("lob", "adjusted offset=" << offset << ", len=" << len);
523
524 first_page.set_last_trx_id(trx->id);
525 first_page.set_last_trx_undo_no(undo_no);
526
527 page_no_t first_page_no = ref.page_no();
528 space_id_t space_id = ref.space_id();
529
530 const page_size_t page_size = dict_table_page_size(index->table);
531 const page_id_t first_page_id(space_id, first_page_no);
532
533 flst_base_node_t *base_node = first_page.index_list();
534 fil_addr_t node_loc = flst_get_first(base_node, mtr);
535
536 ulint page_offset = offset;
537
538 node_loc = find_offset(index, node_loc, page_offset, mtr);
539 ulint want = len; /* want to be replaced. */
540
541 /* This code is only meant for small changes to LOB. */
542 ut_ad(want <= ref_t::LOB_SMALL_CHANGE_THRESHOLD);
543
544 const byte *ptr = buf;
545
546 index_entry_t cur_entry(mtr, index);
547
548 ulint loop_count [[maybe_unused]] = 0;
549
550 while (!fil_addr_is_null(node_loc) && want > 0) {
551 ut_ad(loop_count <= 1);
552
553 /* Part of the page contents needs to be changed. So the
554 old data must be read. */
555
556 buf_block_t *tmp_block = cur_entry.load_x(node_loc);
557
558 page_no_t cur_page_no = cur_entry.get_page_no();
559
560 if (cur_page_no == first_page_no) {
561 /* If current page number is the same as first page
562 number, then first page is already loaded. Just update
563 the pointer. */
564 first_page.set_block(tmp_block);
565 first_page.replace_inline(page_offset, ptr, want, mtr);
566
567 } else {
568 /* If current page number is NOT the same as first page
569 number, then load first page here. */
570 first_page.load_x(first_page_id, page_size);
571 data_page_t page(mtr, index);
572 page.load_x(cur_page_no);
573 page.replace_inline(page_offset, ptr, want, mtr);
574 }
575
576 /* Even the LOB index is just updated in place itself. If a
577 rollback happens, the old value will be available in the undo
578 log record. */
579 cur_entry.set_trx_id_modifier(trx->id);
580 cur_entry.set_trx_undo_no_modifier(undo_no);
581
582 page_offset = 0;
583 node_loc = cur_entry.get_next();
584
585 loop_count++;
586 }
587
588 ut_ad(want == 0);
589
590 #ifdef UNIV_DEBUG
591 {
592 fil_addr_t first_node_loc = flst_get_first(base_node, mtr);
593 const ulint lob_size = ref.length();
594 ut_ad(validate_size(lob_size, index, first_node_loc, mtr));
595 }
596 #endif /* UNIV_DEBUG */
597
598 return DB_SUCCESS;
599 }
600
601 dberr_t apply_undolog(mtr_t *mtr, dict_index_t *index, ref_t ref,
602 const upd_field_t *uf) {
603 DBUG_TRACE;
604
605 const Lob_diff_vector &lob_diffs = *uf->lob_diffs;
606
607 page_no_t first_page_no = ref.page_no();
608 space_id_t space_id = ref.space_id();
609
610 #ifdef UNIV_DEBUG
611 const ulint lob_size = ref.length();
612 #endif /* UNIV_DEBUG */
613
614 const page_size_t page_size = dict_table_page_size(index->table);
615
616 /* Cannot do this for compressed blobs. */
617 ut_ad(!page_size.is_compressed());
618
619 const page_id_t first_page_id(space_id, first_page_no);
620
621 first_page_t first_page(mtr, index);
622 first_page.load_x(first_page_id, page_size);
623
624 first_page.set_last_trx_id(uf->last_trx_id);
625 first_page.set_last_trx_undo_no(uf->last_undo_no);
626
627 flst_base_node_t *base_node = first_page.index_list();
628 fil_addr_t node_loc = flst_get_first(base_node, mtr);
629
630 if (!dict_table_has_atomic_blobs(index->table)) {
631 for (auto iter = lob_diffs.begin(); iter != lob_diffs.end(); ++iter) {
632 const Lob_diff &lob_diff = *iter;
633 ulint offset = lob_diff.m_offset;
634
635 if (offset < DICT_ANTELOPE_MAX_INDEX_COL_LEN) {
636 /* In this case, partial update was not done.
637 It is possible to do it, but not yet done.*/
638 return DB_SUCCESS;
639 }
640 }
641 }
642
643 for (auto iter = lob_diffs.begin(); iter != lob_diffs.end(); ++iter) {
644 const Lob_diff &lob_diff = *iter;
645
646 ulint page_offset = lob_diff.m_offset;
647
648 ut_ad(lob_diff.m_offset >= DICT_ANTELOPE_MAX_INDEX_COL_LEN ||
649 dict_table_has_atomic_blobs(index->table));
650
651 if (!dict_table_has_atomic_blobs(index->table)) {
652 /* For compact and redundant row format, remove the
653 local prefix length from the offset. */
654
655 ut_ad(page_offset >= DICT_ANTELOPE_MAX_INDEX_COL_LEN);
656 page_offset -= DICT_ANTELOPE_MAX_INDEX_COL_LEN;
657 }
658
659 ut_ad(page_offset < lob_size);
660
661 /* Initially, point the node_loc to the first entry. */
662 node_loc = flst_get_first(base_node, mtr);
663
664 ut_ad(validate_size(lob_size, index, node_loc, mtr));
665
666 node_loc = find_offset(index, node_loc, page_offset, mtr);
667
668 ut_ad(!node_loc.is_null());
669
670 ulint want = lob_diff.m_length; /* want to be replaced. */
671
672 /* This code is only meant for small changes to LOB. */
673 ut_ad(want <= ref_t::LOB_SMALL_CHANGE_THRESHOLD);
674
675 const byte *ptr = lob_diff.m_old_data;
676
677 index_entry_t cur_entry(mtr, index);
678
679 ulint count = 0;
680
681 while (!fil_addr_is_null(node_loc) && want > 0) {
682 buf_block_t *tmp_block = cur_entry.load_x(node_loc);
683
684 page_no_t cur_page_no = cur_entry.get_page_no();
685
686 if (cur_page_no == first_page_no) {
687 /* If current page number is the same as first
688 page number, then first page is already loaded.
689 Just update the pointer. */
690
691 first_page.set_block(tmp_block);
692 first_page.replace_inline(page_offset, ptr, want, mtr);
693
694 } else {
695 /* If current page number is NOT the same as
696 first page number, then load first page here.*/
697 first_page.load_x(first_page_id, page_size);
698 data_page_t page(mtr, index);
699 page.load_x(cur_page_no);
700 page.replace_inline(page_offset, ptr, want, mtr);
701 }
702
703 /* Ensure that only 1 or 2 index entries will be modified.*/
704 ut_ad(count <= 1);
705
706 lob_index_diff_t &tmp = lob_diff.m_idx_diffs->at(count);
707 trx_id_t t1 = tmp.m_modifier_trxid;
708
709 cur_entry.set_trx_id_modifier(t1);
710
711 undo_no_t u1 = tmp.m_modifier_undo_no;
712
713 cur_entry.set_trx_undo_no_modifier(u1);
714
715 page_offset = 0;
716 node_loc = cur_entry.get_next();
717
718 count++;
719 }
720
721 ut_ad(want == 0);
722 }
723
724 return DB_SUCCESS;
725 }
726
727 } // namespace lob