~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/innobase/row/row0ins.c

  • Committer: Eric Day
  • Date: 2009-10-31 21:53:33 UTC
  • mfrom: (1200 staging)
  • mto: This revision was merged to the branch mainline in revision 1202.
  • Revision ID: eday@oddments.org-20091031215333-j94bjoanwmi68p6f
Merged trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
*****************************************************************************/
18
18
 
19
 
/******************************************************
 
19
/**************************************************//**
 
20
@file row/row0ins.c
20
21
Insert into a table
21
22
 
22
23
Created 4/20/1996 Heikki Tuuri
28
29
#include "row0ins.ic"
29
30
#endif
30
31
 
 
32
#include "ha_prototypes.h"
31
33
#include "dict0dict.h"
32
34
#include "dict0boot.h"
33
35
#include "trx0undo.h"
50
52
#define ROW_INS_NEXT    2
51
53
 
52
54
 
53
 
/*************************************************************************
54
 
Creates an insert node struct. */
 
55
/*********************************************************************//**
 
56
Creates an insert node struct.
 
57
@return own: insert node struct */
55
58
UNIV_INTERN
56
59
ins_node_t*
57
60
ins_node_create(
58
61
/*============*/
59
 
                                        /* out, own: insert node struct */
60
 
        ulint           ins_type,       /* in: INS_VALUES, ... */
61
 
        dict_table_t*   table,          /* in: table where to insert */
62
 
        mem_heap_t*     heap)           /* in: mem heap where created */
 
62
        ulint           ins_type,       /*!< in: INS_VALUES, ... */
 
63
        dict_table_t*   table,          /*!< in: table where to insert */
 
64
        mem_heap_t*     heap)           /*!< in: mem heap where created */
63
65
{
64
66
        ins_node_t*     node;
65
67
 
85
87
        return(node);
86
88
}
87
89
 
88
 
/***************************************************************
 
90
/***********************************************************//**
89
91
Creates an entry template for each index of a table. */
90
92
UNIV_INTERN
91
93
void
92
94
ins_node_create_entry_list(
93
95
/*=======================*/
94
 
        ins_node_t*     node)   /* in: row insert node */
 
96
        ins_node_t*     node)   /*!< in: row insert node */
95
97
{
96
98
        dict_index_t*   index;
97
99
        dtuple_t*       entry;
111
113
        }
112
114
}
113
115
 
114
 
/*********************************************************************
 
116
/*****************************************************************//**
115
117
Adds system field buffers to a row. */
116
118
static
117
119
void
118
120
row_ins_alloc_sys_fields(
119
121
/*=====================*/
120
 
        ins_node_t*     node)   /* in: insert node */
 
122
        ins_node_t*     node)   /*!< in: insert node */
121
123
{
122
124
        dtuple_t*               row;
123
125
        dict_table_t*           table;
166
168
        dfield_set_data(dfield, ptr, DATA_ROLL_PTR_LEN);
167
169
}
168
170
 
169
 
/*************************************************************************
 
171
/*********************************************************************//**
170
172
Sets a new row to insert for an INS_DIRECT node. This function is only used
171
173
if we have constructed the row separately, which is a rare case; this
172
174
function is quite slow. */
174
176
void
175
177
ins_node_set_new_row(
176
178
/*=================*/
177
 
        ins_node_t*     node,   /* in: insert node */
178
 
        dtuple_t*       row)    /* in: new row (or first row) for the node */
 
179
        ins_node_t*     node,   /*!< in: insert node */
 
180
        dtuple_t*       row)    /*!< in: new row (or first row) for the node */
179
181
{
180
182
        node->state = INS_NODE_SET_IX_LOCK;
181
183
        node->index = NULL;
199
201
        node->trx_id = ut_dulint_zero;
200
202
}
201
203
 
202
 
/***********************************************************************
 
204
/*******************************************************************//**
203
205
Does an insert operation by updating a delete-marked existing record
204
206
in the index. This situation can occur if the delete-marked record is
205
 
kept in the index for consistent reads. */
 
207
kept in the index for consistent reads.
 
208
@return DB_SUCCESS or error code */
206
209
static
207
210
ulint
208
211
row_ins_sec_index_entry_by_modify(
209
212
/*==============================*/
210
 
                                /* out: DB_SUCCESS or error code */
211
 
        ulint           mode,   /* in: BTR_MODIFY_LEAF or BTR_MODIFY_TREE,
 
213
        ulint           mode,   /*!< in: BTR_MODIFY_LEAF or BTR_MODIFY_TREE,
212
214
                                depending on whether mtr holds just a leaf
213
215
                                latch or also a tree latch */
214
 
        btr_cur_t*      cursor, /* in: B-tree cursor */
215
 
        const dtuple_t* entry,  /* in: index entry to insert */
216
 
        que_thr_t*      thr,    /* in: query thread */
217
 
        mtr_t*          mtr)    /* in: mtr; must be committed before
 
216
        btr_cur_t*      cursor, /*!< in: B-tree cursor */
 
217
        const dtuple_t* entry,  /*!< in: index entry to insert */
 
218
        que_thr_t*      thr,    /*!< in: query thread */
 
219
        mtr_t*          mtr)    /*!< in: mtr; must be committed before
218
220
                                latching any further pages */
219
221
{
220
222
        big_rec_t*      dummy_big_rec;
270
272
        return(err);
271
273
}
272
274
 
273
 
/***********************************************************************
 
275
/*******************************************************************//**
274
276
Does an insert operation by delete unmarking and updating a delete marked
275
277
existing record in the index. This situation can occur if the delete marked
276
 
record is kept in the index for consistent reads. */
 
278
record is kept in the index for consistent reads.
 
279
@return DB_SUCCESS, DB_FAIL, or error code */
277
280
static
278
281
ulint
279
282
row_ins_clust_index_entry_by_modify(
280
283
/*================================*/
281
 
                                /* out: DB_SUCCESS, DB_FAIL, or error code */
282
 
        ulint           mode,   /* in: BTR_MODIFY_LEAF or BTR_MODIFY_TREE,
 
284
        ulint           mode,   /*!< in: BTR_MODIFY_LEAF or BTR_MODIFY_TREE,
283
285
                                depending on whether mtr holds just a leaf
284
286
                                latch or also a tree latch */
285
 
        btr_cur_t*      cursor, /* in: B-tree cursor */
286
 
        mem_heap_t**    heap,   /* in/out: pointer to memory heap, or NULL */
287
 
        big_rec_t**     big_rec,/* out: possible big rec vector of fields
 
287
        btr_cur_t*      cursor, /*!< in: B-tree cursor */
 
288
        mem_heap_t**    heap,   /*!< in/out: pointer to memory heap, or NULL */
 
289
        big_rec_t**     big_rec,/*!< out: possible big rec vector of fields
288
290
                                which have to be stored externally by the
289
291
                                caller */
290
 
        const dtuple_t* entry,  /* in: index entry to insert */
291
 
        que_thr_t*      thr,    /* in: query thread */
292
 
        mtr_t*          mtr)    /* in: mtr; must be committed before
 
292
        const dtuple_t* entry,  /*!< in: index entry to insert */
 
293
        que_thr_t*      thr,    /*!< in: query thread */
 
294
        mtr_t*          mtr)    /*!< in: mtr; must be committed before
293
295
                                latching any further pages */
294
296
{
295
297
        rec_t*          rec;
342
344
        return(err);
343
345
}
344
346
 
345
 
/*************************************************************************
 
347
/*********************************************************************//**
346
348
Returns TRUE if in a cascaded update/delete an ancestor node of node
347
 
updates (not DELETE, but UPDATE) table. */
 
349
updates (not DELETE, but UPDATE) table.
 
350
@return TRUE if an ancestor updates table */
348
351
static
349
352
ibool
350
353
row_ins_cascade_ancestor_updates_table(
351
354
/*===================================*/
352
 
                                /* out: TRUE if an ancestor updates table */
353
 
        que_node_t*     node,   /* in: node in a query graph */
354
 
        dict_table_t*   table)  /* in: table */
 
355
        que_node_t*     node,   /*!< in: node in a query graph */
 
356
        dict_table_t*   table)  /*!< in: table */
355
357
{
356
358
        que_node_t*     parent;
357
359
        upd_node_t*     upd_node;
375
377
        return(FALSE);
376
378
}
377
379
 
378
 
/*************************************************************************
 
380
/*********************************************************************//**
379
381
Returns the number of ancestor UPDATE or DELETE nodes of a
380
 
cascaded update/delete node. */
 
382
cascaded update/delete node.
 
383
@return number of ancestors */
381
384
static
382
385
ulint
383
386
row_ins_cascade_n_ancestors(
384
387
/*========================*/
385
 
                                /* out: number of ancestors */
386
 
        que_node_t*     node)   /* in: node in a query graph */
 
388
        que_node_t*     node)   /*!< in: node in a query graph */
387
389
{
388
390
        que_node_t*     parent;
389
391
        ulint           n_ancestors = 0;
401
403
        return(n_ancestors);
402
404
}
403
405
 
404
 
/**********************************************************************
 
406
/******************************************************************//**
405
407
Calculates the update vector node->cascade->update for a child table in
406
 
a cascaded update. */
 
408
a cascaded update.
 
409
@return number of fields in the calculated update vector; the value
 
410
can also be 0 if no foreign key fields changed; the returned value is
 
411
ULINT_UNDEFINED if the column type in the child table is too short to
 
412
fit the new value in the parent table: that means the update fails */
407
413
static
408
414
ulint
409
415
row_ins_cascade_calc_update_vec(
410
416
/*============================*/
411
 
                                        /* out: number of fields in the
412
 
                                        calculated update vector; the value
413
 
                                        can also be 0 if no foreign key
414
 
                                        fields changed; the returned value
415
 
                                        is ULINT_UNDEFINED if the column
416
 
                                        type in the child table is too short
417
 
                                        to fit the new value in the parent
418
 
                                        table: that means the update fails */
419
 
        upd_node_t*     node,           /* in: update node of the parent
 
417
        upd_node_t*     node,           /*!< in: update node of the parent
420
418
                                        table */
421
 
        dict_foreign_t* foreign,        /* in: foreign key constraint whose
 
419
        dict_foreign_t* foreign,        /*!< in: foreign key constraint whose
422
420
                                        type is != 0 */
423
 
        mem_heap_t*     heap)           /* in: memory heap to use as
 
421
        mem_heap_t*     heap)           /*!< in: memory heap to use as
424
422
                                        temporary storage */
425
423
{
426
424
        upd_node_t*     cascade         = node->cascade_node;
589
587
        return(n_fields_updated);
590
588
}
591
589
 
592
 
/*************************************************************************
 
590
/*********************************************************************//**
593
591
Set detailed error message associated with foreign key errors for
594
592
the given transaction. */
595
593
static
596
594
void
597
595
row_ins_set_detailed(
598
596
/*=================*/
599
 
        trx_t*          trx,            /* in: transaction */
600
 
        dict_foreign_t* foreign)        /* in: foreign key constraint */
 
597
        trx_t*          trx,            /*!< in: transaction */
 
598
        dict_foreign_t* foreign)        /*!< in: foreign key constraint */
601
599
{
602
600
        mutex_enter(&srv_misc_tmpfile_mutex);
603
601
        rewind(srv_misc_tmpfile);
615
613
        mutex_exit(&srv_misc_tmpfile_mutex);
616
614
}
617
615
 
618
 
/*************************************************************************
 
616
/*********************************************************************//**
619
617
Reports a foreign key error associated with an update or a delete of a
620
618
parent table index entry. */
621
619
static
622
620
void
623
621
row_ins_foreign_report_err(
624
622
/*=======================*/
625
 
        const char*     errstr,         /* in: error string from the viewpoint
 
623
        const char*     errstr,         /*!< in: error string from the viewpoint
626
624
                                        of the parent table */
627
 
        que_thr_t*      thr,            /* in: query thread whose run_node
 
625
        que_thr_t*      thr,            /*!< in: query thread whose run_node
628
626
                                        is an update node */
629
 
        dict_foreign_t* foreign,        /* in: foreign key constraint */
630
 
        const rec_t*    rec,            /* in: a matching index record in the
 
627
        dict_foreign_t* foreign,        /*!< in: foreign key constraint */
 
628
        const rec_t*    rec,            /*!< in: a matching index record in the
631
629
                                        child table */
632
 
        const dtuple_t* entry)          /* in: index entry in the parent
 
630
        const dtuple_t* entry)          /*!< in: index entry in the parent
633
631
                                        table */
634
632
{
635
633
        FILE*   ef      = dict_foreign_err_file;
671
669
        mutex_exit(&dict_foreign_err_mutex);
672
670
}
673
671
 
674
 
/*************************************************************************
 
672
/*********************************************************************//**
675
673
Reports a foreign key error to dict_foreign_err_file when we are trying
676
674
to add an index entry to a child table. Note that the adding may be the result
677
675
of an update, too. */
679
677
void
680
678
row_ins_foreign_report_add_err(
681
679
/*===========================*/
682
 
        trx_t*          trx,            /* in: transaction */
683
 
        dict_foreign_t* foreign,        /* in: foreign key constraint */
684
 
        const rec_t*    rec,            /* in: a record in the parent table:
 
680
        trx_t*          trx,            /*!< in: transaction */
 
681
        dict_foreign_t* foreign,        /*!< in: foreign key constraint */
 
682
        const rec_t*    rec,            /*!< in: a record in the parent table:
685
683
                                        it does not match entry because we
686
684
                                        have an error! */
687
 
        const dtuple_t* entry)          /* in: index entry to insert in the
 
685
        const dtuple_t* entry)          /*!< in: index entry to insert in the
688
686
                                        child table */
689
687
{
690
688
        FILE*   ef      = dict_foreign_err_file;
729
727
        mutex_exit(&dict_foreign_err_mutex);
730
728
}
731
729
 
732
 
/*************************************************************************
 
730
/*********************************************************************//**
733
731
Invalidate the query cache for the given table. */
734
732
static
735
733
void
736
734
row_ins_invalidate_query_cache(
737
735
/*===========================*/
738
 
        que_thr_t*      unused,         /* in: query thread whose run_node
 
736
        que_thr_t*      unused,         /*!< in: query thread whose run_node
739
737
                                        is an update node */
740
 
        const char*     name)           /* in: table name prefixed with
 
738
        const char*     name)           /*!< in: table name prefixed with
741
739
                                        database name and a '/' character */
742
740
{
743
741
        char*   buf;
755
753
        mem_free(buf);
756
754
}
757
755
 
758
 
/*************************************************************************
 
756
/*********************************************************************//**
759
757
Perform referential actions or checks when a parent row is deleted or updated
760
758
and the constraint had an ON DELETE or ON UPDATE condition which was not
761
 
RESTRICT. */
 
759
RESTRICT.
 
760
@return DB_SUCCESS, DB_LOCK_WAIT, or error code */
762
761
static
763
762
ulint
764
763
row_ins_foreign_check_on_constraint(
765
764
/*================================*/
766
 
                                        /* out: DB_SUCCESS, DB_LOCK_WAIT,
767
 
                                        or error code */
768
 
        que_thr_t*      thr,            /* in: query thread whose run_node
 
765
        que_thr_t*      thr,            /*!< in: query thread whose run_node
769
766
                                        is an update node */
770
 
        dict_foreign_t* foreign,        /* in: foreign key constraint whose
 
767
        dict_foreign_t* foreign,        /*!< in: foreign key constraint whose
771
768
                                        type is != 0 */
772
 
        btr_pcur_t*     pcur,           /* in: cursor placed on a matching
 
769
        btr_pcur_t*     pcur,           /*!< in: cursor placed on a matching
773
770
                                        index record in the child table */
774
 
        dtuple_t*       entry,          /* in: index entry in the parent
 
771
        dtuple_t*       entry,          /*!< in: index entry in the parent
775
772
                                        table */
776
 
        mtr_t*          mtr)            /* in: mtr holding the latch of pcur
 
773
        mtr_t*          mtr)            /*!< in: mtr holding the latch of pcur
777
774
                                        page */
778
775
{
779
776
        upd_node_t*     node;
1122
1119
        return(err);
1123
1120
}
1124
1121
 
1125
 
/*************************************************************************
 
1122
/*********************************************************************//**
1126
1123
Sets a shared lock on a record. Used in locking possible duplicate key
1127
 
records and also in checking foreign key constraints. */
 
1124
records and also in checking foreign key constraints.
 
1125
@return DB_SUCCESS or error code */
1128
1126
static
1129
1127
ulint
1130
1128
row_ins_set_shared_rec_lock(
1131
1129
/*========================*/
1132
 
                                        /* out: DB_SUCCESS or error code */
1133
 
        ulint                   type,   /* in: LOCK_ORDINARY, LOCK_GAP, or
 
1130
        ulint                   type,   /*!< in: LOCK_ORDINARY, LOCK_GAP, or
1134
1131
                                        LOCK_REC_NOT_GAP type lock */
1135
 
        const buf_block_t*      block,  /* in: buffer block of rec */
1136
 
        const rec_t*            rec,    /* in: record */
1137
 
        dict_index_t*           index,  /* in: index */
1138
 
        const ulint*            offsets,/* in: rec_get_offsets(rec, index) */
1139
 
        que_thr_t*              thr)    /* in: query thread */
 
1132
        const buf_block_t*      block,  /*!< in: buffer block of rec */
 
1133
        const rec_t*            rec,    /*!< in: record */
 
1134
        dict_index_t*           index,  /*!< in: index */
 
1135
        const ulint*            offsets,/*!< in: rec_get_offsets(rec, index) */
 
1136
        que_thr_t*              thr)    /*!< in: query thread */
1140
1137
{
1141
1138
        ulint   err;
1142
1139
 
1153
1150
        return(err);
1154
1151
}
1155
1152
 
1156
 
#ifndef UNIV_HOTBACKUP
1157
 
/*************************************************************************
 
1153
/*********************************************************************//**
1158
1154
Sets a exclusive lock on a record. Used in locking possible duplicate key
1159
 
records */
 
1155
records
 
1156
@return DB_SUCCESS or error code */
1160
1157
static
1161
1158
ulint
1162
1159
row_ins_set_exclusive_rec_lock(
1163
1160
/*===========================*/
1164
 
                                        /* out: DB_SUCCESS or error code */
1165
 
        ulint                   type,   /* in: LOCK_ORDINARY, LOCK_GAP, or
 
1161
        ulint                   type,   /*!< in: LOCK_ORDINARY, LOCK_GAP, or
1166
1162
                                        LOCK_REC_NOT_GAP type lock */
1167
 
        const buf_block_t*      block,  /* in: buffer block of rec */
1168
 
        const rec_t*            rec,    /* in: record */
1169
 
        dict_index_t*           index,  /* in: index */
1170
 
        const ulint*            offsets,/* in: rec_get_offsets(rec, index) */
1171
 
        que_thr_t*              thr)    /* in: query thread */
 
1163
        const buf_block_t*      block,  /*!< in: buffer block of rec */
 
1164
        const rec_t*            rec,    /*!< in: record */
 
1165
        dict_index_t*           index,  /*!< in: index */
 
1166
        const ulint*            offsets,/*!< in: rec_get_offsets(rec, index) */
 
1167
        que_thr_t*              thr)    /*!< in: query thread */
1172
1168
{
1173
1169
        ulint   err;
1174
1170
 
1184
1180
 
1185
1181
        return(err);
1186
1182
}
1187
 
#endif /* !UNIV_HOTBACKUP */
1188
1183
 
1189
 
/*******************************************************************
 
1184
/***************************************************************//**
1190
1185
Checks if foreign key constraint fails for an index entry. Sets shared locks
1191
1186
which lock either the success or the failure of the constraint. NOTE that
1192
 
the caller must have a shared latch on dict_operation_lock. */
 
1187
the caller must have a shared latch on dict_operation_lock.
 
1188
@return DB_SUCCESS, DB_NO_REFERENCED_ROW, or DB_ROW_IS_REFERENCED */
1193
1189
UNIV_INTERN
1194
1190
ulint
1195
1191
row_ins_check_foreign_constraint(
1196
1192
/*=============================*/
1197
 
                                /* out: DB_SUCCESS,
1198
 
                                DB_NO_REFERENCED_ROW,
1199
 
                                or DB_ROW_IS_REFERENCED */
1200
 
        ibool           check_ref,/* in: TRUE if we want to check that
 
1193
        ibool           check_ref,/*!< in: TRUE if we want to check that
1201
1194
                                the referenced table is ok, FALSE if we
1202
1195
                                want to to check the foreign key table */
1203
 
        dict_foreign_t* foreign,/* in: foreign constraint; NOTE that the
 
1196
        dict_foreign_t* foreign,/*!< in: foreign constraint; NOTE that the
1204
1197
                                tables mentioned in it must be in the
1205
1198
                                dictionary cache if they exist at all */
1206
 
        dict_table_t*   table,  /* in: if check_ref is TRUE, then the foreign
 
1199
        dict_table_t*   table,  /*!< in: if check_ref is TRUE, then the foreign
1207
1200
                                table, else the referenced table */
1208
 
        dtuple_t*       entry,  /* in: index entry for index */
1209
 
        que_thr_t*      thr)    /* in: query thread */
 
1201
        dtuple_t*       entry,  /*!< in: index entry for index */
 
1202
        que_thr_t*      thr)    /*!< in: query thread */
1210
1203
{
1211
1204
        upd_node_t*     upd_node;
1212
1205
        dict_table_t*   check_table;
1510
1503
        return(err);
1511
1504
}
1512
1505
 
1513
 
/*******************************************************************
 
1506
/***************************************************************//**
1514
1507
Checks if foreign key constraints fail for an index entry. If index
1515
1508
is not mentioned in any constraint, this function does nothing,
1516
1509
Otherwise does searches to the indexes of referenced tables and
1517
1510
sets shared locks which lock either the success or the failure of
1518
 
a constraint. */
 
1511
a constraint.
 
1512
@return DB_SUCCESS or error code */
1519
1513
static
1520
1514
ulint
1521
1515
row_ins_check_foreign_constraints(
1522
1516
/*==============================*/
1523
 
                                /* out: DB_SUCCESS or error code */
1524
 
        dict_table_t*   table,  /* in: table */
1525
 
        dict_index_t*   index,  /* in: index */
1526
 
        dtuple_t*       entry,  /* in: index entry for index */
1527
 
        que_thr_t*      thr)    /* in: query thread */
 
1517
        dict_table_t*   table,  /*!< in: table */
 
1518
        dict_index_t*   index,  /*!< in: index */
 
1519
        dtuple_t*       entry,  /*!< in: index entry for index */
 
1520
        que_thr_t*      thr)    /*!< in: query thread */
1528
1521
{
1529
1522
        dict_foreign_t* foreign;
1530
1523
        ulint           err;
1592
1585
        return(DB_SUCCESS);
1593
1586
}
1594
1587
 
1595
 
#ifndef UNIV_HOTBACKUP
1596
 
/*******************************************************************
 
1588
/***************************************************************//**
1597
1589
Checks if a unique key violation to rec would occur at the index entry
1598
 
insert. */
 
1590
insert.
 
1591
@return TRUE if error */
1599
1592
static
1600
1593
ibool
1601
1594
row_ins_dupl_error_with_rec(
1602
1595
/*========================*/
1603
 
                                /* out: TRUE if error */
1604
 
        const rec_t*    rec,    /* in: user record; NOTE that we assume
 
1596
        const rec_t*    rec,    /*!< in: user record; NOTE that we assume
1605
1597
                                that the caller already has a record lock on
1606
1598
                                the record! */
1607
 
        const dtuple_t* entry,  /* in: entry to insert */
1608
 
        dict_index_t*   index,  /* in: index */
1609
 
        const ulint*    offsets)/* in: rec_get_offsets(rec, index) */
 
1599
        const dtuple_t* entry,  /*!< in: entry to insert */
 
1600
        dict_index_t*   index,  /*!< in: index */
 
1601
        const ulint*    offsets)/*!< in: rec_get_offsets(rec, index) */
1610
1602
{
1611
1603
        ulint   matched_fields;
1612
1604
        ulint   matched_bytes;
1644
1636
 
1645
1637
        return(!rec_get_deleted_flag(rec, rec_offs_comp(offsets)));
1646
1638
}
1647
 
#endif /* !UNIV_HOTBACKUP */
1648
1639
 
1649
 
/*******************************************************************
 
1640
/***************************************************************//**
1650
1641
Scans a unique non-clustered index at a given index entry to determine
1651
1642
whether a uniqueness violation has occurred for the key value of the entry.
1652
 
Set shared locks on possible duplicate records. */
 
1643
Set shared locks on possible duplicate records.
 
1644
@return DB_SUCCESS, DB_DUPLICATE_KEY, or DB_LOCK_WAIT */
1653
1645
static
1654
1646
ulint
1655
1647
row_ins_scan_sec_index_for_duplicate(
1656
1648
/*=================================*/
1657
 
                                /* out: DB_SUCCESS, DB_DUPLICATE_KEY, or
1658
 
                                DB_LOCK_WAIT */
1659
 
        dict_index_t*   index,  /* in: non-clustered unique index */
1660
 
        dtuple_t*       entry,  /* in: index entry */
1661
 
        que_thr_t*      thr)    /* in: query thread */
 
1649
        dict_index_t*   index,  /*!< in: non-clustered unique index */
 
1650
        dtuple_t*       entry,  /*!< in: index entry */
 
1651
        que_thr_t*      thr)    /*!< in: query thread */
1662
1652
{
1663
 
#ifndef UNIV_HOTBACKUP
1664
1653
        ulint           n_unique;
1665
1654
        ulint           i;
1666
1655
        int             cmp;
1770
1759
        dtuple_set_n_fields_cmp(entry, n_fields_cmp);
1771
1760
 
1772
1761
        return(err);
1773
 
#else /* UNIV_HOTBACKUP */
1774
 
        /* This function depends on MySQL code that is not included in
1775
 
        InnoDB Hot Backup builds.  Besides, this function should never
1776
 
        be called in InnoDB Hot Backup. */
1777
 
        ut_error;
1778
 
        return(DB_FAIL);
1779
 
#endif /* UNIV_HOTBACKUP */
1780
1762
}
1781
1763
 
1782
 
/*******************************************************************
 
1764
/***************************************************************//**
1783
1765
Checks if a unique key violation error would occur at an index entry
1784
1766
insert. Sets shared locks on possible duplicate records. Works only
1785
 
for a clustered index! */
 
1767
for a clustered index!
 
1768
@return DB_SUCCESS if no error, DB_DUPLICATE_KEY if error,
 
1769
DB_LOCK_WAIT if we have to wait for a lock on a possible duplicate
 
1770
record */
1786
1771
static
1787
1772
ulint
1788
1773
row_ins_duplicate_error_in_clust(
1789
1774
/*=============================*/
1790
 
                                /* out: DB_SUCCESS if no error,
1791
 
                                DB_DUPLICATE_KEY if error, DB_LOCK_WAIT if we
1792
 
                                have to wait for a lock on a possible
1793
 
                                duplicate record */
1794
 
        btr_cur_t*      cursor, /* in: B-tree cursor */
1795
 
        dtuple_t*       entry,  /* in: entry to insert */
1796
 
        que_thr_t*      thr,    /* in: query thread */
1797
 
        mtr_t*          mtr)    /* in: mtr */
 
1775
        btr_cur_t*      cursor, /*!< in: B-tree cursor */
 
1776
        dtuple_t*       entry,  /*!< in: entry to insert */
 
1777
        que_thr_t*      thr,    /*!< in: query thread */
 
1778
        mtr_t*          mtr)    /*!< in: mtr */
1798
1779
{
1799
 
#ifndef UNIV_HOTBACKUP
1800
1780
        ulint   err;
1801
1781
        rec_t*  rec;
1802
1782
        ulint   n_unique;
1920
1900
                mem_heap_free(heap);
1921
1901
        }
1922
1902
        return(err);
1923
 
#else /* UNIV_HOTBACKUP */
1924
 
        /* This function depends on MySQL code that is not included in
1925
 
        InnoDB Hot Backup builds.  Besides, this function should never
1926
 
        be called in InnoDB Hot Backup. */
1927
 
        ut_error;
1928
 
        return(DB_FAIL);
1929
 
#endif /* UNIV_HOTBACKUP */
1930
1903
}
1931
1904
 
1932
 
/*******************************************************************
 
1905
/***************************************************************//**
1933
1906
Checks if an index entry has long enough common prefix with an existing
1934
1907
record so that the intended insert of the entry must be changed to a modify of
1935
1908
the existing record. In the case of a clustered index, the prefix must be
1936
1909
n_unique fields long, and in the case of a secondary index, all fields must be
1937
 
equal. */
 
1910
equal.
 
1911
@return 0 if no update, ROW_INS_PREV if previous should be updated;
 
1912
currently we do the search so that only the low_match record can match
 
1913
enough to the search tuple, not the next record */
1938
1914
UNIV_INLINE
1939
1915
ulint
1940
1916
row_ins_must_modify(
1941
1917
/*================*/
1942
 
                                /* out: 0 if no update, ROW_INS_PREV if
1943
 
                                previous should be updated; currently we
1944
 
                                do the search so that only the low_match
1945
 
                                record can match enough to the search tuple,
1946
 
                                not the next record */
1947
 
        btr_cur_t*      cursor) /* in: B-tree cursor */
 
1918
        btr_cur_t*      cursor) /*!< in: B-tree cursor */
1948
1919
{
1949
1920
        ulint   enough_match;
1950
1921
        rec_t*  rec;
1971
1942
        return(0);
1972
1943
}
1973
1944
 
1974
 
/*******************************************************************
 
1945
/***************************************************************//**
1975
1946
Tries to insert an index entry to an index. If the index is clustered
1976
1947
and a record with the same unique key is found, the other record is
1977
1948
necessarily marked deleted by a committed transaction, or a unique key
1979
1950
existing record, and we must write an undo log record on the delete
1980
1951
marked record. If the index is secondary, and a record with exactly the
1981
1952
same fields is found, the other record is necessarily marked deleted.
1982
 
It is then unmarked. Otherwise, the entry is just inserted to the index. */
 
1953
It is then unmarked. Otherwise, the entry is just inserted to the index.
 
1954
@return DB_SUCCESS, DB_LOCK_WAIT, DB_FAIL if pessimistic retry needed,
 
1955
or error code */
1983
1956
static
1984
1957
ulint
1985
1958
row_ins_index_entry_low(
1986
1959
/*====================*/
1987
 
                                /* out: DB_SUCCESS, DB_LOCK_WAIT, DB_FAIL
1988
 
                                if pessimistic retry needed, or error code */
1989
 
        ulint           mode,   /* in: BTR_MODIFY_LEAF or BTR_MODIFY_TREE,
 
1960
        ulint           mode,   /*!< in: BTR_MODIFY_LEAF or BTR_MODIFY_TREE,
1990
1961
                                depending on whether we wish optimistic or
1991
1962
                                pessimistic descent down the index tree */
1992
 
        dict_index_t*   index,  /* in: index */
1993
 
        dtuple_t*       entry,  /* in: index entry to insert */
1994
 
        ulint           n_ext,  /* in: number of externally stored columns */
1995
 
        que_thr_t*      thr)    /* in: query thread */
 
1963
        dict_index_t*   index,  /*!< in: index */
 
1964
        dtuple_t*       entry,  /*!< in: index entry to insert */
 
1965
        ulint           n_ext,  /*!< in: number of externally stored columns */
 
1966
        que_thr_t*      thr)    /*!< in: query thread */
1996
1967
{
1997
1968
        btr_cur_t       cursor;
1998
1969
        ulint           ignore_sec_unique       = 0;
2158
2129
        return(err);
2159
2130
}
2160
2131
 
2161
 
/*******************************************************************
 
2132
/***************************************************************//**
2162
2133
Inserts an index entry to index. Tries first optimistic, then pessimistic
2163
2134
descent down the tree. If the entry matches enough to a delete marked record,
2164
2135
performs the insert by updating or delete unmarking the delete marked
2165
 
record. */
 
2136
record.
 
2137
@return DB_SUCCESS, DB_LOCK_WAIT, DB_DUPLICATE_KEY, or some other error code */
2166
2138
UNIV_INTERN
2167
2139
ulint
2168
2140
row_ins_index_entry(
2169
2141
/*================*/
2170
 
                                /* out: DB_SUCCESS, DB_LOCK_WAIT,
2171
 
                                DB_DUPLICATE_KEY, or some other error code */
2172
 
        dict_index_t*   index,  /* in: index */
2173
 
        dtuple_t*       entry,  /* in: index entry to insert */
2174
 
        ulint           n_ext,  /* in: number of externally stored columns */
2175
 
        ibool           foreign,/* in: TRUE=check foreign key constraints */
2176
 
        que_thr_t*      thr)    /* in: query thread */
 
2142
        dict_index_t*   index,  /*!< in: index */
 
2143
        dtuple_t*       entry,  /*!< in: index entry to insert */
 
2144
        ulint           n_ext,  /*!< in: number of externally stored columns */
 
2145
        ibool           foreign,/*!< in: TRUE=check foreign key constraints */
 
2146
        que_thr_t*      thr)    /*!< in: query thread */
2177
2147
{
2178
2148
        ulint   err;
2179
2149
 
2202
2172
        return(err);
2203
2173
}
2204
2174
 
2205
 
/***************************************************************
 
2175
/***********************************************************//**
2206
2176
Sets the values of the dtuple fields in entry from the values of appropriate
2207
2177
columns in row. */
2208
2178
static
2209
2179
void
2210
2180
row_ins_index_entry_set_vals(
2211
2181
/*=========================*/
2212
 
        dict_index_t*   index,  /* in: index */
2213
 
        dtuple_t*       entry,  /* in: index entry to make */
2214
 
        const dtuple_t* row)    /* in: row */
 
2182
        dict_index_t*   index,  /*!< in: index */
 
2183
        dtuple_t*       entry,  /*!< in: index entry to make */
 
2184
        const dtuple_t* row)    /*!< in: row */
2215
2185
{
2216
2186
        ulint   n_fields;
2217
2187
        ulint   i;
2254
2224
        }
2255
2225
}
2256
2226
 
2257
 
/***************************************************************
2258
 
Inserts a single index entry to the table. */
 
2227
/***********************************************************//**
 
2228
Inserts a single index entry to the table.
 
2229
@return DB_SUCCESS if operation successfully completed, else error
 
2230
code or DB_LOCK_WAIT */
2259
2231
static
2260
2232
ulint
2261
2233
row_ins_index_entry_step(
2262
2234
/*=====================*/
2263
 
                                /* out: DB_SUCCESS if operation successfully
2264
 
                                completed, else error code or DB_LOCK_WAIT */
2265
 
        ins_node_t*     node,   /* in: row insert node */
2266
 
        que_thr_t*      thr)    /* in: query thread */
 
2235
        ins_node_t*     node,   /*!< in: row insert node */
 
2236
        que_thr_t*      thr)    /*!< in: query thread */
2267
2237
{
2268
2238
        ulint   err;
2269
2239
 
2278
2248
        return(err);
2279
2249
}
2280
2250
 
2281
 
/***************************************************************
 
2251
/***********************************************************//**
2282
2252
Allocates a row id for row and inits the node->index field. */
2283
2253
UNIV_INLINE
2284
2254
void
2285
2255
row_ins_alloc_row_id_step(
2286
2256
/*======================*/
2287
 
        ins_node_t*     node)   /* in: row insert node */
 
2257
        ins_node_t*     node)   /*!< in: row insert node */
2288
2258
{
2289
2259
        dulint  row_id;
2290
2260
 
2304
2274
        dict_sys_write_row_id(node->row_id_buf, row_id);
2305
2275
}
2306
2276
 
2307
 
/***************************************************************
 
2277
/***********************************************************//**
2308
2278
Gets a row to insert from the values list. */
2309
2279
UNIV_INLINE
2310
2280
void
2311
2281
row_ins_get_row_from_values(
2312
2282
/*========================*/
2313
 
        ins_node_t*     node)   /* in: row insert node */
 
2283
        ins_node_t*     node)   /*!< in: row insert node */
2314
2284
{
2315
2285
        que_node_t*     list_node;
2316
2286
        dfield_t*       dfield;
2337
2307
        }
2338
2308
}
2339
2309
 
2340
 
/***************************************************************
 
2310
/***********************************************************//**
2341
2311
Gets a row to insert from the select list. */
2342
2312
UNIV_INLINE
2343
2313
void
2344
2314
row_ins_get_row_from_select(
2345
2315
/*========================*/
2346
 
        ins_node_t*     node)   /* in: row insert node */
 
2316
        ins_node_t*     node)   /*!< in: row insert node */
2347
2317
{
2348
2318
        que_node_t*     list_node;
2349
2319
        dfield_t*       dfield;
2368
2338
        }
2369
2339
}
2370
2340
 
2371
 
/***************************************************************
2372
 
Inserts a row to a table. */
 
2341
/***********************************************************//**
 
2342
Inserts a row to a table.
 
2343
@return DB_SUCCESS if operation successfully completed, else error
 
2344
code or DB_LOCK_WAIT */
2373
2345
static
2374
2346
ulint
2375
2347
row_ins(
2376
2348
/*====*/
2377
 
                                /* out: DB_SUCCESS if operation successfully
2378
 
                                completed, else error code or DB_LOCK_WAIT */
2379
 
        ins_node_t*     node,   /* in: row insert node */
2380
 
        que_thr_t*      thr)    /* in: query thread */
 
2349
        ins_node_t*     node,   /*!< in: row insert node */
 
2350
        que_thr_t*      thr)    /*!< in: query thread */
2381
2351
{
2382
2352
        ulint   err;
2383
2353
 
2423
2393
        return(DB_SUCCESS);
2424
2394
}
2425
2395
 
2426
 
/***************************************************************
 
2396
/***********************************************************//**
2427
2397
Inserts a row to a table. This is a high-level function used in SQL execution
2428
 
graphs. */
 
2398
graphs.
 
2399
@return query thread to run next or NULL */
2429
2400
UNIV_INTERN
2430
2401
que_thr_t*
2431
2402
row_ins_step(
2432
2403
/*=========*/
2433
 
                                /* out: query thread to run next or NULL */
2434
 
        que_thr_t*      thr)    /* in: query thread */
 
2404
        que_thr_t*      thr)    /*!< in: query thread */
2435
2405
{
2436
2406
        ins_node_t*     node;
2437
2407
        que_node_t*     parent;