35 #ifndef UNIV_HOTBACKUP
122 row_upd_changes_first_fields_binary(
141 row_upd_index_is_referenced(
148 ibool froze_data_dict = FALSE;
149 ibool is_referenced = FALSE;
157 row_mysql_freeze_data_dictionary(trx);
158 froze_data_dict = TRUE;
166 is_referenced = TRUE;
174 if (froze_data_dict) {
178 return(is_referenced);
191 row_upd_check_references_constraints(
209 ibool got_s_lock = FALSE;
218 rec = btr_pcur_get_rec(pcur);
233 row_mysql_freeze_data_dictionary(trx);
246 || row_upd_changes_first_fields_binary(
247 entry, index, node->
update,
256 mutex_enter(&(dict_sys->
mutex));
261 mutex_exit(&(dict_sys->
mutex));
270 FALSE, foreign, table, entry, thr);
273 mutex_enter(&(dict_sys->
mutex));
281 mutex_exit(&(dict_sys->
mutex));
284 if (err != DB_SUCCESS) {
319 node->
state = UPD_NODE_UPDATE_CLUSTERED;
320 node->in_mysql_interface = FALSE;
324 node->upd_row = NULL;
325 node->upd_ext = NULL;
329 node->foreign = NULL;
330 node->cascade_heap = NULL;
331 node->cascade_node = NULL;
336 node->magic_n = UPD_NODE_MAGIC_N;
353 const ulint* offsets,
360 if (UNIV_LIKELY_NULL(page_zip)) {
362 page_zip, rec, offsets, pos, trx_id, roll_ptr);
367 field = rec_get_nth_field(rec, offsets, pos, &len);
368 ut_ad(len == DATA_TRX_ID_LEN);
369 #if DATA_TRX_ID + 1 != DATA_ROLL_PTR
370 # error "DATA_TRX_ID + 1 != DATA_ROLL_PTR"
377 #ifndef UNIV_HOTBACKUP
400 dfield = dtuple_get_nth_field(entry, pos);
401 field =
static_cast<byte *
>(dfield_get_data(dfield));
403 if (type == DATA_TRX_ID) {
406 ut_ad(type == DATA_ROLL_PTR);
421 const ulint* offsets,
434 for (i = 0; i < n_fields; i++) {
435 upd_field = upd_get_nth_field(update, i);
437 new_val = &(upd_field->
new_val);
464 old_len = UNIV_SQL_NULL;
490 const ulint* offsets,
510 for (i = 0; i < n_fields; i++) {
511 #ifdef UNIV_BLOB_DEBUG
513 const byte* field_ref = NULL;
516 upd_field = upd_get_nth_field(update, i);
517 new_val = &(upd_field->
new_val);
520 #ifdef UNIV_BLOB_DEBUG
523 field_ref = rec_get_nth_field(rec, offsets, i, &len);
524 ut_a(len != UNIV_SQL_NULL);
534 btr_blob_dbg_rbt_delete(index, &b,
"upd_in_place");
539 dfield_get_data(new_val),
542 #ifdef UNIV_BLOB_DEBUG
551 btr_blob_dbg_rbt_insert(index, &b,
"upd_in_place");
556 if (UNIV_LIKELY_NULL(page_zip)) {
561 #ifndef UNIV_HOTBACKUP
582 index, DATA_TRX_ID));
585 log_ptr += DATA_ROLL_PTR_LEN;
613 if (end_ptr < ptr + DATA_ROLL_PTR_LEN) {
619 ptr += DATA_ROLL_PTR_LEN;
626 #ifndef UNIV_HOTBACKUP
649 buf_end = log_ptr + MLOG_BUF_MARGIN;
655 for (i = 0; i < n_fields; i++) {
657 #if MLOG_BUF_MARGIN <= 30
658 # error "MLOG_BUF_MARGIN <= 30"
661 if (log_ptr + 30 > buf_end) {
664 log_ptr =
mlog_open(mtr, MLOG_BUF_MARGIN);
665 buf_end = log_ptr + MLOG_BUF_MARGIN;
668 upd_field = upd_get_nth_field(update, i);
670 new_val = &(upd_field->
new_val);
677 if (len != UNIV_SQL_NULL) {
678 if (log_ptr + len < buf_end) {
679 memcpy(log_ptr, dfield_get_data(new_val), len);
686 static_cast<byte *>(dfield_get_data(new_val)),
689 log_ptr =
mlog_open(mtr, MLOG_BUF_MARGIN);
690 buf_end = log_ptr + MLOG_BUF_MARGIN;
720 if (end_ptr < ptr + 1) {
737 for (i = 0; i < n_fields; i++) {
739 upd_field = upd_get_nth_field(update, i);
740 new_val = &(upd_field->
new_val);
758 if (len != UNIV_SQL_NULL) {
760 if (end_ptr < ptr + len) {
773 *update_out = update;
778 #ifndef UNIV_HOTBACKUP
801 ulint offsets_[REC_OFFS_SMALL_SIZE];
802 const ulint* offsets;
803 rec_offs_init(offsets_);
811 offsets = rec_get_offsets(rec, index, offsets_,
812 ULINT_UNDEFINED, &heap);
816 data = rec_get_nth_field(rec, offsets, i, &len);
818 dfield = dtuple_get_nth_field(entry, i);
831 if (!dfield_data_is_binary_equal(dfield, len, data)) {
833 upd_field = upd_get_nth_field(update, n_diff);
873 ulint offsets_[REC_OFFS_NORMAL_SIZE];
874 const ulint* offsets;
875 rec_offs_init(offsets_);
887 offsets = rec_get_offsets(rec, index, offsets_,
888 ULINT_UNDEFINED, &heap);
892 data = rec_get_nth_field(rec, offsets, i, &len);
894 dfield = dtuple_get_nth_field(entry, i);
899 if (i == trx_id_pos || i == roll_ptr_pos) {
906 || !dfield_data_is_binary_equal(dfield, len, data)) {
908 upd_field = upd_get_nth_field(update, n_diff);
947 *len = btr_copy_externally_stored_field_prefix(buf, *len,
961 row_upd_index_replace_new_col_val(
983 data =
static_cast<const byte *
>(dfield_get_data(dfield));
995 data = row_upd_ext_fetch(data, l, zip_size,
999 len = dtype_get_at_most_n_mbchars(col->
prtype,
1002 (
const char*) data);
1062 const upd_t* update,
1086 for (i = 0; i < n_fields; i++) {
1091 field = dict_index_get_nth_field(index, i);
1096 row_upd_index_replace_new_col_val(
1097 dtuple_get_nth_field(entry, i),
1098 field, col, uf, heap, zip_size);
1116 const upd_t* update,
1124 = dict_table_get_first_index(index->
table);
1125 const ulint zip_size
1135 field = dict_index_get_nth_field(index, i);
1141 row_upd_index_replace_new_col_val(
1142 dtuple_get_nth_field(entry, i),
1143 field, col, uf, heap, zip_size);
1162 const upd_t* update,
1181 table = index->
table;
1184 ext_cols =
static_cast<ulint *
>(
mem_heap_alloc(heap, n_cols *
sizeof *ext_cols));
1189 for (col_no = 0; col_no < n_cols; col_no++) {
1192 = dict_table_get_nth_col(table, col_no);
1193 const ulint clust_pos
1197 if (UNIV_UNLIKELY(clust_pos == ULINT_UNDEFINED)) {
1202 dfield = dtuple_get_nth_field(row, col_no);
1207 = upd_get_nth_field(update, i);
1209 if (upd_field->
field_no != clust_pos) {
1219 ext_cols[n_ext_cols++] = col_no;
1243 const upd_t* update,
1264 ut_ad(thr->graph->trx);
1268 clust_index = dict_table_get_first_index(index->
table);
1270 for (i = 0; i < n_unique; i++) {
1281 ind_field = dict_index_get_nth_field(index, i);
1288 if (upd_field == NULL) {
1297 dfield = dtuple_get_nth_field(row, col_no);
1305 }
else if (UNIV_LIKELY_NULL(ext)) {
1309 UNIV_MEM_INVALID(&dfield_len,
sizeof dfield_len);
1315 if (UNIV_LIKELY_NULL(buf)) {
1316 if (UNIV_UNLIKELY(buf == field_ref_zero)) {
1323 ut_ad(thr->graph->trx->is_recovered);
1336 buf =
static_cast<const unsigned char*
>(dfield_get_data(dfield));
1338 ut_a(dfield_len > 0);
1341 dfield = &dfield_ext;
1365 const upd_t* update)
1371 index = dict_table_get_first_index(table);
1375 upd_field = upd_get_nth_field(update, i);
1395 row_upd_changes_first_fields_binary(
1399 const upd_t* update,
1406 ut_ad(update && index);
1410 clust_index = dict_table_get_first_index(index->
table);
1412 for (i = 0; i < n; i++) {
1418 ind_field = dict_index_get_nth_field(index, i);
1424 for (j = 0; j < n_upd_fields; j++) {
1427 = upd_get_nth_field(update, j);
1431 dtuple_get_nth_field(entry, i),
1446 row_upd_copy_columns(
1449 const ulint* offsets,
1457 data = rec_get_nth_field(rec, offsets,
1471 row_upd_eval_new_vals(
1482 for (i = 0; i < n_fields; i++) {
1483 upd_field = upd_get_nth_field(update, i);
1485 exp = upd_field->
exp;
1505 ulint offsets_[REC_OFFS_NORMAL_SIZE];
1506 const ulint* offsets;
1507 rec_offs_init(offsets_);
1511 if (node->
row != NULL) {
1515 clust_index = dict_table_get_first_index(node->
table);
1517 rec = btr_pcur_get_rec(node->
pcur);
1519 offsets = rec_get_offsets(rec, clust_index, offsets_,
1520 ULINT_UNDEFINED, &heap);
1535 node->
row =
row_build(ROW_COPY_DATA, clust_index, rec, offsets,
1536 NULL, ext, node->
heap);
1537 if (node->is_delete) {
1538 node->upd_row = NULL;
1539 node->upd_ext = NULL;
1546 if (UNIV_LIKELY_NULL(heap)) {
1557 row_upd_sec_index_entry(
1570 ulint err = DB_SUCCESS;
1575 index = node->
index;
1577 referenced = row_upd_index_is_referenced(index, trx);
1589 btr_pcur_get_btr_cur(&pcur)->thr = thr;
1601 btr_cur = btr_pcur_get_btr_cur(&pcur);
1605 switch (search_result) {
1614 fputs(
"InnoDB: error in sec index entry update in\n"
1615 "InnoDB: ", stderr);
1616 dict_index_name_print(stderr, trx, index);
1618 "InnoDB: tuple ", stderr);
1619 dtuple_print(stderr, entry);
1621 "InnoDB: record ", stderr);
1628 "InnoDB: Submit a detailed bug report"
1629 " to http://bugs.mysql.com\n", stderr);
1639 err = btr_cur_del_mark_set_sec_rec(
1640 0, btr_cur, TRUE, thr, &mtr);
1642 if (err == DB_SUCCESS && referenced) {
1646 offsets = rec_get_offsets(
1647 rec, index, NULL, ULINT_UNDEFINED,
1652 err = row_upd_check_references_constraints(
1653 node, &pcur, index->
table,
1654 index, offsets, thr, &mtr);
1663 if (node->is_delete || err != DB_SUCCESS) {
1694 ut_ad((node->
state == UPD_NODE_UPDATE_ALL_SEC)
1695 || (node->
state == UPD_NODE_UPDATE_SOME_SEC));
1698 if (node->
state == UPD_NODE_UPDATE_ALL_SEC
1699 || row_upd_changes_ord_field_binary(node->
index, node->
update,
1700 thr, node->
row, node->
ext)) {
1701 return(row_upd_sec_index_entry(node, thr));
1708 # define row_upd_clust_rec_by_insert_inherit(rec,offsets,entry,update) \
1709 row_upd_clust_rec_by_insert_inherit_func(rec,offsets,entry,update)
1711 # define row_upd_clust_rec_by_insert_inherit(rec,offsets,entry,update) \
1712 row_upd_clust_rec_by_insert_inherit_func(entry,update)
1720 static __attribute__((warn_unused_result))
1722 row_upd_clust_rec_by_insert_inherit_func(
1726 const ulint* offsets,
1730 const upd_t* update)
1732 ibool inherit = FALSE;
1735 ut_ad(!rec == !offsets);
1739 dfield_t* dfield = dtuple_get_nth_field(entry, i);
1753 if (UNIV_LIKELY(rec != NULL)) {
1754 const byte* rec_data
1755 = rec_get_nth_field(rec, offsets, i, &len);
1757 ut_ad(len != UNIV_SQL_NULL);
1763 ut_ad(memcmp(rec_data, field_ref_zero,
1764 BTR_EXTERN_FIELD_REF_SIZE));
1772 ut_a(len != UNIV_SQL_NULL);
1773 ut_a(len >= BTR_EXTERN_FIELD_REF_SIZE);
1774 data =
static_cast<unsigned char*
>(dfield_get_data(dfield));
1777 ut_a(memcmp(data, field_ref_zero, BTR_EXTERN_FIELD_REF_SIZE));
1801 row_upd_clust_rec_by_insert(
1817 ibool change_ownership = FALSE;
1819 ulint* offsets = NULL;
1825 table = node->
table;
1827 btr_cur = btr_pcur_get_btr_cur(pcur);
1838 switch (node->
state) {
1841 case UPD_NODE_INSERT_BLOB:
1846 change_ownership = row_upd_clust_rec_by_insert_inherit(
1847 NULL, NULL, entry, node->
update);
1848 ut_a(change_ownership);
1850 case UPD_NODE_INSERT_CLUSTERED:
1854 case UPD_NODE_UPDATE_CLUSTERED:
1859 offsets = rec_get_offsets(rec, index, NULL,
1860 ULINT_UNDEFINED, &heap);
1863 err = btr_cur_del_mark_set_clust_rec(
1865 rec, index, offsets, TRUE, thr, mtr);
1866 if (err != DB_SUCCESS) {
1879 change_ownership = row_upd_clust_rec_by_insert_inherit(
1880 rec, offsets, entry, node->
update);
1882 if (change_ownership) {
1883 btr_pcur_store_position(pcur, mtr);
1891 err = row_upd_check_references_constraints(
1892 node, pcur, table, index, offsets, thr, mtr);
1894 if (err != DB_SUCCESS) {
1903 node->upd_ext ? node->upd_ext->
n_ext : 0,
1905 node->
state = change_ownership
1906 ? UPD_NODE_INSERT_BLOB
1907 : UPD_NODE_INSERT_CLUSTERED;
1909 if (err == DB_SUCCESS && change_ownership) {
1927 offsets = rec_get_offsets(rec, index, offsets,
1928 ULINT_UNDEFINED, &heap);
1933 rec, index, offsets, node->
update, mtr);
1967 btr_cur = btr_pcur_get_btr_cur(pcur);
1976 if (node->cmpl_info & UPD_NODE_NO_SIZE_CHANGE) {
1977 err = btr_cur_update_in_place(BTR_NO_LOCKING_FLAG,
1979 node->cmpl_info, thr, mtr);
1981 err = btr_cur_optimistic_update(BTR_NO_LOCKING_FLAG,
1983 node->cmpl_info, thr, mtr);
1988 if (UNIV_LIKELY(err == DB_SUCCESS)) {
1993 if (buf_LRU_buf_pool_running_out()) {
1995 return(DB_LOCK_TABLE_FULL);
2013 err = btr_cur_pessimistic_update(BTR_NO_LOCKING_FLAG, btr_cur,
2014 &heap, &big_rec, node->
update,
2015 node->cmpl_info, thr, mtr);
2018 if (err == DB_SUCCESS && big_rec) {
2019 ulint offsets_[REC_OFFS_NORMAL_SIZE];
2021 rec_offs_init(offsets_);
2029 rec_get_offsets(rec, index, offsets_,
2030 ULINT_UNDEFINED, &heap),
2031 mtr, TRUE, big_rec);
2035 if (UNIV_LIKELY_NULL(heap)) {
2051 row_upd_del_mark_clust_rec(
2069 ut_ad(node->is_delete);
2072 btr_cur = btr_pcur_get_btr_cur(pcur);
2077 row_upd_store_row(node);
2082 err = btr_cur_del_mark_set_clust_rec(
2085 if (err == DB_SUCCESS && referenced) {
2088 err = row_upd_check_references_constraints(
2089 node, pcur, index->
table, index, offsets, thr, mtr);
2116 ulint offsets_[REC_OFFS_NORMAL_SIZE];
2119 rec_offs_init(offsets_);
2121 index = dict_table_get_first_index(node->
table);
2123 referenced = row_upd_index_is_referenced(index,
thr_get_trx(thr));
2145 err = DB_RECORD_NOT_FOUND;
2156 if (node->is_delete && node->
table->
id == DICT_INDEXES_ID) {
2158 dict_drop_index_tree(btr_pcur_get_rec(pcur), mtr);
2175 rec = btr_pcur_get_rec(pcur);
2176 offsets = rec_get_offsets(rec, index, offsets_,
2177 ULINT_UNDEFINED, &heap);
2179 if (!node->has_clust_rec_x_lock) {
2181 0, btr_pcur_get_block(pcur),
2182 rec, index, offsets, thr);
2183 if (err != DB_SUCCESS) {
2191 if (node->is_delete) {
2192 err = row_upd_del_mark_clust_rec(
2193 node, index, offsets, thr, referenced, mtr);
2195 if (err == DB_SUCCESS) {
2196 node->
state = UPD_NODE_UPDATE_ALL_SEC;
2197 node->
index = dict_table_get_next_index(index);
2200 if (UNIV_LIKELY_NULL(heap)) {
2209 if (UNIV_UNLIKELY(!node->in_mysql_interface)) {
2212 row_upd_copy_columns(rec, offsets,
2214 row_upd_eval_new_vals(node->
update);
2217 if (UNIV_LIKELY_NULL(heap)) {
2221 if (node->cmpl_info & UPD_NODE_NO_ORD_CHANGE) {
2223 err = row_upd_clust_rec(node, index, thr, mtr);
2227 row_upd_store_row(node);
2229 if (row_upd_changes_ord_field_binary(index, node->
update, thr,
2243 err = row_upd_clust_rec_by_insert(
2244 node, index, thr, referenced, mtr);
2246 if (err != DB_SUCCESS) {
2251 node->
state = UPD_NODE_UPDATE_ALL_SEC;
2253 err = row_upd_clust_rec(node, index, thr, mtr);
2255 if (err != DB_SUCCESS) {
2260 node->
state = UPD_NODE_UPDATE_SOME_SEC;
2263 node->
index = dict_table_get_next_index(index);
2281 ulint err = DB_SUCCESS;
2285 if (UNIV_LIKELY(node->in_mysql_interface)) {
2293 node->cmpl_info = 0;
2295 node->cmpl_info = UPD_NODE_NO_ORD_CHANGE;
2299 if (node->
state == UPD_NODE_UPDATE_CLUSTERED
2300 || node->
state == UPD_NODE_INSERT_CLUSTERED
2301 || node->
state == UPD_NODE_INSERT_BLOB) {
2304 err = row_upd_clust_step(node, thr);
2306 if (err != DB_SUCCESS) {
2312 if (!node->is_delete && (node->cmpl_info & UPD_NODE_NO_ORD_CHANGE)) {
2317 while (node->
index != NULL) {
2320 err = row_upd_sec_step(node, thr);
2322 if (err != DB_SUCCESS) {
2327 node->
index = dict_table_get_next_index(node->
index);
2331 if (err == DB_SUCCESS) {
2334 if (node->
row != NULL) {
2337 node->upd_row = NULL;
2338 node->upd_ext = NULL;
2342 node->
state = UPD_NODE_UPDATE_CLUSTERED;
2361 ulint err = DB_SUCCESS;
2379 node->
state = UPD_NODE_SET_IX_LOCK;
2382 if (node->
state == UPD_NODE_SET_IX_LOCK) {
2384 if (!node->has_clust_rec_x_lock) {
2390 if (err != DB_SUCCESS) {
2392 goto error_handling;
2396 node->
state = UPD_NODE_UPDATE_CLUSTERED;
2398 if (node->searched_update) {
2414 if (!node->searched_update) {
2422 goto error_handling;
2437 err = row_upd(node, thr);
2442 if (err != DB_SUCCESS) {
2448 if (node->searched_update) {
2458 node->
state = UPD_NODE_UPDATE_CLUSTERED;