1122
1122
/*********************************************************************//**
1123
1123
Sets a shared lock on a record. Used in locking possible duplicate key
1124
1124
records and also in checking foreign key constraints.
1125
@return DB_SUCCESS or error code */
1125
@return DB_SUCCESS, DB_SUCCESS_LOCKED_REC, or error code */
1128
1128
row_ins_set_shared_rec_lock(
1129
1129
/*========================*/
1130
1130
ulint type, /*!< in: LOCK_ORDINARY, LOCK_GAP, or
1135
1135
const ulint* offsets,/*!< in: rec_get_offsets(rec, index) */
1136
1136
que_thr_t* thr) /*!< in: query thread */
1140
1140
ut_ad(rec_offs_validate(rec, index, offsets));
1153
1153
/*********************************************************************//**
1154
1154
Sets a exclusive lock on a record. Used in locking possible duplicate key
1156
@return DB_SUCCESS or error code */
1156
@return DB_SUCCESS, DB_SUCCESS_LOCKED_REC, or error code */
1159
1159
row_ins_set_exclusive_rec_lock(
1160
1160
/*===========================*/
1161
1161
ulint type, /*!< in: LOCK_ORDINARY, LOCK_GAP, or
1166
1166
const ulint* offsets,/*!< in: rec_get_offsets(rec, index) */
1167
1167
que_thr_t* thr) /*!< in: query thread */
1171
1171
ut_ad(rec_offs_validate(rec, index, offsets));
1338
1337
/* Scan index records and check if there is a matching record */
1341
1340
const rec_t* rec = btr_pcur_get_rec(&pcur);
1342
1341
const buf_block_t* block = btr_pcur_get_block(&pcur);
1344
1343
if (page_rec_is_infimum(rec)) {
1349
1348
offsets = rec_get_offsets(rec, check_index,
1354
1353
err = row_ins_set_shared_rec_lock(LOCK_ORDINARY, block,
1355
1354
rec, check_index,
1357
if (err != DB_SUCCESS) {
1357
case DB_SUCCESS_LOCKED_REC:
1365
1365
cmp = cmp_dtuple_rec(entry, rec, offsets);
1370
1370
err = row_ins_set_shared_rec_lock(
1371
1371
LOCK_ORDINARY, block,
1372
1372
rec, check_index, offsets, thr);
1373
if (err != DB_SUCCESS) {
1374
case DB_SUCCESS_LOCKED_REC:
1378
1381
/* Found a matching record. Lock only
1383
1386
LOCK_REC_NOT_GAP, block,
1384
1387
rec, check_index, offsets, thr);
1386
if (err != DB_SUCCESS) {
1390
case DB_SUCCESS_LOCKED_REC:
1391
1397
if (check_ref) {
1392
1398
err = DB_SUCCESS;
1395
1401
} else if (foreign->type != 0) {
1396
1402
/* There is an ON UPDATE or ON DELETE
1397
1403
condition: check them in a separate
1430
1436
thr, foreign, rec, entry);
1432
1438
err = DB_ROW_IS_REFERENCED;
1439
1445
err = row_ins_set_shared_rec_lock(
1440
1446
LOCK_GAP, block,
1441
1447
rec, check_index, offsets, thr);
1442
if (err != DB_SUCCESS) {
1448
err = DB_NO_REFERENCED_ROW;
1449
row_ins_foreign_report_add_err(
1450
trx, foreign, rec, entry);
1460
moved = btr_pcur_move_to_next(&pcur, &mtr);
1464
rec = btr_pcur_get_rec(&pcur);
1465
row_ins_foreign_report_add_err(
1466
trx, foreign, rec, entry);
1467
err = DB_NO_REFERENCED_ROW;
1450
case DB_SUCCESS_LOCKED_REC:
1453
err = DB_NO_REFERENCED_ROW;
1454
row_ins_foreign_report_add_err(
1455
trx, foreign, rec, entry);
1463
} while (btr_pcur_move_to_next(&pcur, &mtr));
1466
row_ins_foreign_report_add_err(
1467
trx, foreign, btr_pcur_get_rec(&pcur), entry);
1468
err = DB_NO_REFERENCED_ROW;
1476
1474
btr_pcur_close(&pcur);
1478
1476
mtr_commit(&mtr);
1986
1994
the function will return in both low_match and up_match of the
1987
1995
cursor sensible values */
1989
if (!(thr_get_trx(thr)->check_unique_secondary)) {
1990
ignore_sec_unique = BTR_IGNORE_SEC_UNIQUE;
1997
if (dict_index_is_clust(index)) {
1999
} else if (!(thr_get_trx(thr)->check_unique_secondary)) {
2000
search_mode = mode | BTR_INSERT | BTR_IGNORE_SEC_UNIQUE;
2002
search_mode = mode | BTR_INSERT;
1993
2005
btr_cur_search_to_nth_level(index, 0, entry, PAGE_CUR_LE,
1994
mode | BTR_INSERT | ignore_sec_unique,
1995
2007
&cursor, 0, __FILE__, __LINE__, &mtr);
1997
2009
if (cursor.flag == BTR_CUR_INSERT_TO_IBUF) {
1998
2010
/* The insertion was made to the insert buffer already during
1999
2011
the search: we are done */
2013
ut_ad(search_mode & BTR_INSERT);
2001
2014
err = DB_SUCCESS;
2003
2016
goto function_exit;