00001 /****************************************************** 00002 Insert into a table 00003 00004 (c) 1996 Innobase Oy 00005 00006 Created 4/20/1996 Heikki Tuuri 00007 *******************************************************/ 00008 00009 #ifndef row0ins_h 00010 #define row0ins_h 00011 00012 #include "univ.i" 00013 #include "data0data.h" 00014 #include "que0types.h" 00015 #include "dict0types.h" 00016 #include "trx0types.h" 00017 #include "row0types.h" 00018 00019 /******************************************************************* 00020 Checks if foreign key constraint fails for an index entry. Sets shared locks 00021 which lock either the success or the failure of the constraint. NOTE that 00022 the caller must have a shared latch on dict_foreign_key_check_lock. */ 00023 00024 ulint 00025 row_ins_check_foreign_constraint( 00026 /*=============================*/ 00027 /* out: DB_SUCCESS, DB_LOCK_WAIT, 00028 DB_NO_REFERENCED_ROW, 00029 or DB_ROW_IS_REFERENCED */ 00030 ibool check_ref,/* in: TRUE If we want to check that 00031 the referenced table is ok, FALSE if we 00032 want to to check the foreign key table */ 00033 dict_foreign_t* foreign,/* in: foreign constraint; NOTE that the 00034 tables mentioned in it must be in the 00035 dictionary cache if they exist at all */ 00036 dict_table_t* table, /* in: if check_ref is TRUE, then the foreign 00037 table, else the referenced table */ 00038 dtuple_t* entry, /* in: index entry for index */ 00039 que_thr_t* thr); /* in: query thread */ 00040 /************************************************************************* 00041 Creates an insert node struct. */ 00042 00043 ins_node_t* 00044 ins_node_create( 00045 /*============*/ 00046 /* out, own: insert node struct */ 00047 ulint ins_type, /* in: INS_VALUES, ... */ 00048 dict_table_t* table, /* in: table where to insert */ 00049 mem_heap_t* heap); /* in: mem heap where created */ 00050 /************************************************************************* 00051 Sets a new row to insert for an INS_DIRECT node. This function is only used 00052 if we have constructed the row separately, which is a rare case; this 00053 function is quite slow. */ 00054 00055 void 00056 ins_node_set_new_row( 00057 /*=================*/ 00058 ins_node_t* node, /* in: insert node */ 00059 dtuple_t* row); /* in: new row (or first row) for the node */ 00060 /******************************************************************* 00061 Tries to insert an index entry to an index. If the index is clustered 00062 and a record with the same unique key is found, the other record is 00063 necessarily marked deleted by a committed transaction, or a unique key 00064 violation error occurs. The delete marked record is then updated to an 00065 existing record, and we must write an undo log record on the delete 00066 marked record. If the index is secondary, and a record with exactly the 00067 same fields is found, the other record is necessarily marked deleted. 00068 It is then unmarked. Otherwise, the entry is just inserted to the index. */ 00069 00070 ulint 00071 row_ins_index_entry_low( 00072 /*====================*/ 00073 /* out: DB_SUCCESS, DB_LOCK_WAIT, DB_FAIL 00074 if pessimistic retry needed, or error code */ 00075 ulint mode, /* in: BTR_MODIFY_LEAF or BTR_MODIFY_TREE, 00076 depending on whether we wish optimistic or 00077 pessimistic descent down the index tree */ 00078 dict_index_t* index, /* in: index */ 00079 dtuple_t* entry, /* in: index entry to insert */ 00080 ulint* ext_vec,/* in: array containing field numbers of 00081 externally stored fields in entry, or NULL */ 00082 ulint n_ext_vec,/* in: number of fields in ext_vec */ 00083 que_thr_t* thr); /* in: query thread */ 00084 /******************************************************************* 00085 Inserts an index entry to index. Tries first optimistic, then pessimistic 00086 descent down the tree. If the entry matches enough to a delete marked record, 00087 performs the insert by updating or delete unmarking the delete marked 00088 record. */ 00089 00090 ulint 00091 row_ins_index_entry( 00092 /*================*/ 00093 /* out: DB_SUCCESS, DB_LOCK_WAIT, 00094 DB_DUPLICATE_KEY, or some other error code */ 00095 dict_index_t* index, /* in: index */ 00096 dtuple_t* entry, /* in: index entry to insert */ 00097 ulint* ext_vec,/* in: array containing field numbers of 00098 externally stored fields in entry, or NULL */ 00099 ulint n_ext_vec,/* in: number of fields in ext_vec */ 00100 que_thr_t* thr); /* in: query thread */ 00101 /*************************************************************** 00102 Inserts a row to a table. */ 00103 00104 ulint 00105 row_ins( 00106 /*====*/ 00107 /* out: DB_SUCCESS if operation successfully 00108 completed, else error code or DB_LOCK_WAIT */ 00109 ins_node_t* node, /* in: row insert node */ 00110 que_thr_t* thr); /* in: query thread */ 00111 /*************************************************************** 00112 Inserts a row to a table. This is a high-level function used in 00113 SQL execution graphs. */ 00114 00115 que_thr_t* 00116 row_ins_step( 00117 /*=========*/ 00118 /* out: query thread to run next or NULL */ 00119 que_thr_t* thr); /* in: query thread */ 00120 00121 /* Insert node structure */ 00122 00123 struct ins_node_struct{ 00124 que_common_t common; /* node type: QUE_NODE_INSERT */ 00125 ulint ins_type;/* INS_VALUES, INS_SEARCHED, or INS_DIRECT */ 00126 dtuple_t* row; /* row to insert */ 00127 dict_table_t* table; /* table where to insert */ 00128 sel_node_t* select; /* select in searched insert */ 00129 que_node_t* values_list;/* list of expressions to evaluate and 00130 insert in an INS_VALUES insert */ 00131 ulint state; /* node execution state */ 00132 dict_index_t* index; /* NULL, or the next index where the index 00133 entry should be inserted */ 00134 dtuple_t* entry; /* NULL, or entry to insert in the index; 00135 after a successful insert of the entry, 00136 this should be reset to NULL */ 00137 UT_LIST_BASE_NODE_T(dtuple_t) 00138 entry_list;/* list of entries, one for each index */ 00139 byte* row_id_buf;/* buffer for the row id sys field in row */ 00140 dulint trx_id; /* trx id or the last trx which executed the 00141 node */ 00142 byte* trx_id_buf;/* buffer for the trx id sys field in row */ 00143 mem_heap_t* entry_sys_heap; 00144 /* memory heap used as auxiliary storage; 00145 entry_list and sys fields are stored here; 00146 if this is NULL, entry list should be created 00147 and buffers for sys fields in row allocated */ 00148 ulint magic_n; 00149 }; 00150 00151 #define INS_NODE_MAGIC_N 15849075 00152 00153 /* Insert node types */ 00154 #define INS_SEARCHED 0 /* INSERT INTO ... SELECT ... */ 00155 #define INS_VALUES 1 /* INSERT INTO ... VALUES ... */ 00156 #define INS_DIRECT 2 /* this is for internal use in dict0crea: 00157 insert the row directly */ 00158 00159 /* Node execution states */ 00160 #define INS_NODE_SET_IX_LOCK 1 /* we should set an IX lock on table */ 00161 #define INS_NODE_ALLOC_ROW_ID 2 /* row id should be allocated */ 00162 #define INS_NODE_INSERT_ENTRIES 3 /* index entries should be built and 00163 inserted */ 00164 00165 #ifndef UNIV_NONINL 00166 #include "row0ins.ic" 00167 #endif 00168 00169 #endif
1.4.7

