row0ins.h
上传用户:tsgydb
上传日期:2007-04-14
资源大小:10674k
文件大小:5k
源码类别:

MySQL数据库

开发平台:

Visual C++

  1. /******************************************************
  2. Insert into a table
  3. (c) 1996 Innobase Oy
  4. Created 4/20/1996 Heikki Tuuri
  5. *******************************************************/
  6. #ifndef row0ins_h
  7. #define row0ins_h
  8. #include "univ.i"
  9. #include "data0data.h"
  10. #include "que0types.h"
  11. #include "dict0types.h"
  12. #include "trx0types.h"
  13. #include "row0types.h"
  14. /*************************************************************************
  15. Creates an insert node struct. */
  16. ins_node_t*
  17. ins_node_create(
  18. /*============*/
  19. /* out, own: insert node struct */
  20. ulint ins_type, /* in: INS_VALUES, ... */
  21. dict_table_t* table,  /* in: table where to insert */
  22. mem_heap_t* heap); /* in: mem heap where created */
  23. /*************************************************************************
  24. Sets a new row to insert for an INS_DIRECT node. This function is only used
  25. if we have constructed the row separately, which is a rare case; this
  26. function is quite slow. */
  27. void
  28. ins_node_set_new_row(
  29. /*=================*/
  30. ins_node_t* node, /* in: insert node */
  31. dtuple_t* row); /* in: new row (or first row) for the node */
  32. /*******************************************************************
  33. Tries to insert an index entry to an index. If the index is clustered
  34. and a record with the same unique key is found, the other record is
  35. necessarily marked deleted by a committed transaction, or a unique key
  36. violation error occurs. The delete marked record is then updated to an
  37. existing record, and we must write an undo log record on the delete
  38. marked record. If the index is secondary, and a record with exactly the
  39. same fields is found, the other record is necessarily marked deleted.
  40. It is then unmarked. Otherwise, the entry is just inserted to the index. */
  41. ulint
  42. row_ins_index_entry_low(
  43. /*====================*/
  44. /* out: DB_SUCCESS, DB_LOCK_WAIT, DB_FAIL
  45. if pessimistic retry needed, or error code */
  46. ulint mode, /* in: BTR_MODIFY_LEAF or BTR_MODIFY_TREE,
  47. depending on whether we wish optimistic or
  48. pessimistic descent down the index tree */
  49. dict_index_t* index, /* in: index */
  50. dtuple_t* entry, /* in: index entry to insert */
  51. que_thr_t* thr); /* in: query thread */
  52. /*******************************************************************
  53. Inserts an index entry to index. Tries first optimistic, then pessimistic
  54. descent down the tree. If the entry matches enough to a delete marked record,
  55. performs the insert by updating or delete unmarking the delete marked
  56. record. */
  57. ulint
  58. row_ins_index_entry(
  59. /*================*/
  60. /* out: DB_SUCCESS, DB_LOCK_WAIT,
  61. DB_DUPLICATE_KEY, or some other error code */
  62. dict_index_t* index, /* in: index */
  63. dtuple_t* entry, /* in: index entry to insert */
  64. que_thr_t* thr); /* in: query thread */
  65. /***************************************************************
  66. Inserts a row to a table. */
  67. ulint
  68. row_ins(
  69. /*====*/
  70. /* out: DB_SUCCESS if operation successfully
  71. completed, else error code or DB_LOCK_WAIT */
  72. ins_node_t* node, /* in: row insert node */
  73. que_thr_t* thr); /* in: query thread */
  74. /***************************************************************
  75. Inserts a row to a table. This is a high-level function used in
  76. SQL execution graphs. */
  77. que_thr_t*
  78. row_ins_step(
  79. /*=========*/
  80. /* out: query thread to run next or NULL */
  81. que_thr_t* thr); /* in: query thread */
  82. /* Insert node structure */
  83. struct ins_node_struct{
  84. que_common_t common; /* node type: QUE_NODE_INSERT */
  85. ulint ins_type;/* INS_VALUES, INS_SEARCHED, or INS_DIRECT */
  86. dtuple_t* row; /* row to insert */
  87. dict_table_t* table; /* table where to insert */
  88. sel_node_t* select; /* select in searched insert */
  89. que_node_t* values_list;/* list of expressions to evaluate and
  90. insert in an INS_VALUES insert */
  91. ulint state; /* node execution state */
  92. dict_index_t* index; /* NULL, or the next index where the index
  93. entry should be inserted */
  94. dtuple_t* entry; /* NULL, or entry to insert in the index;
  95. after a successful insert of the entry,
  96. this should be reset to NULL */
  97. UT_LIST_BASE_NODE_T(dtuple_t)
  98. entry_list;/* list of entries, one for each index */
  99. byte* row_id_buf;/* buffer for the row id sys field in row */
  100. dulint trx_id; /* trx id or the last trx which executed the
  101. node */
  102. byte* trx_id_buf;/* buffer for the trx id sys field in row */
  103. mem_heap_t* entry_sys_heap;
  104. /* memory heap used as auxiliary storage;
  105. entry_list and sys fields are stored here;
  106. if this is NULL, entry list should be created
  107. and buffers for sys fields in row allocated */
  108. ulint magic_n;
  109. };
  110. #define INS_NODE_MAGIC_N 15849075
  111. /* Insert node types */
  112. #define INS_SEARCHED 0 /* INSERT INTO ... SELECT ... */
  113. #define INS_VALUES 1 /* INSERT INTO ... VALUES ... */
  114. #define INS_DIRECT 2 /* this is for internal use in dict0crea:
  115. insert the row directly */
  116. /* Node execution states */
  117. #define INS_NODE_SET_IX_LOCK 1 /* we should set an IX lock on table */
  118. #define INS_NODE_ALLOC_ROW_ID 2 /* row id should be allocated */
  119. #define INS_NODE_INSERT_ENTRIES 3 /* index entries should be built and
  120. inserted */
  121. #ifndef UNIV_NONINL
  122. #include "row0ins.ic"
  123. #endif
  124. #endif