You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

436 lines
9.5 KiB

20 years ago
Merge r102 from hotbackup/trunk. Corrected some comments. os_file_create_tmpfile(): Remove the implementation from InnoDB Hot Backup. In InnoDB Hot Backup builds, do not define dict_casedn_str(), which is invoked in fil_load_single_table_tablespace() on Windows. This function depends on innobase_casedn_str() and my_casedn_str(). Define btr_check_node_ptr() and data_error only #ifdef UNIV_DEBUG. They are only being used in ut_ad() assertions. Replace the occurrences of the type uint with ulint, because InnoDB Hot Backup does not define any uint data type. Disable lock_validate() in InnoDB Hot Backup builds. Disable some unused static variables of srv0srv.c in InnoDB Hot Backup builds. Disable some srv_table_...() functions in InnoDB Hot Backup builds. Disable some unused static variables in srv0start.c in InnoDB Hot Backup builds. Disable io_handler_thread() in InnoDB Hot Backup builds. Disable srv_calc_low32() and srv_calc_high32() in InnoDB Hot Backup builds to avoid warnings about unused functions. In fil_node_open_file(), avoid bogus assertions in InnoDB Hot Backup builds. In fil_load_single_table_tablespace(), remove the call to dict_casedn_str(), as it depends on MySQL code. Copy the code of recv_reset_log_files_for_backup() from InnoDB Hot Backup. Disable innobase_mysql_cmp(), cmp_whole_field(), cmp_data_data_slow(), cmp_dtuple_rec_with_match() and cmp_rec_rec_with_match() in InnoDB Hot Backup builds, as they depend on MySQL code. Adapt dtype_set_mblen() and dtype_get_fixed_size() for InnoDB Hot Backup builds, assuming that they will only be called on system tables, which do not contain multi-byte characters. Disable the static functions row_ins_set_exclusive_rec_lock() and row_ins_dupl_error_with_rec() in InnoDB Hot Backup builds to avoid warnings about unused functions. In row_sel_field_store_in_mysql_format(), disable some UTF-8 related assertions #ifndef UNIV_RELEASE_NOT_YET_STABLE.
20 years ago
20 years ago
Merge r102 from hotbackup/trunk. Corrected some comments. os_file_create_tmpfile(): Remove the implementation from InnoDB Hot Backup. In InnoDB Hot Backup builds, do not define dict_casedn_str(), which is invoked in fil_load_single_table_tablespace() on Windows. This function depends on innobase_casedn_str() and my_casedn_str(). Define btr_check_node_ptr() and data_error only #ifdef UNIV_DEBUG. They are only being used in ut_ad() assertions. Replace the occurrences of the type uint with ulint, because InnoDB Hot Backup does not define any uint data type. Disable lock_validate() in InnoDB Hot Backup builds. Disable some unused static variables of srv0srv.c in InnoDB Hot Backup builds. Disable some srv_table_...() functions in InnoDB Hot Backup builds. Disable some unused static variables in srv0start.c in InnoDB Hot Backup builds. Disable io_handler_thread() in InnoDB Hot Backup builds. Disable srv_calc_low32() and srv_calc_high32() in InnoDB Hot Backup builds to avoid warnings about unused functions. In fil_node_open_file(), avoid bogus assertions in InnoDB Hot Backup builds. In fil_load_single_table_tablespace(), remove the call to dict_casedn_str(), as it depends on MySQL code. Copy the code of recv_reset_log_files_for_backup() from InnoDB Hot Backup. Disable innobase_mysql_cmp(), cmp_whole_field(), cmp_data_data_slow(), cmp_dtuple_rec_with_match() and cmp_rec_rec_with_match() in InnoDB Hot Backup builds, as they depend on MySQL code. Adapt dtype_set_mblen() and dtype_get_fixed_size() for InnoDB Hot Backup builds, assuming that they will only be called on system tables, which do not contain multi-byte characters. Disable the static functions row_ins_set_exclusive_rec_lock() and row_ins_dupl_error_with_rec() in InnoDB Hot Backup builds to avoid warnings about unused functions. In row_sel_field_store_in_mysql_format(), disable some UTF-8 related assertions #ifndef UNIV_RELEASE_NOT_YET_STABLE.
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
  1. /************************************************************************
  2. SQL data field and tuple
  3. (c) 1994-1996 Innobase Oy
  4. Created 5/30/1994 Heikki Tuuri
  5. *************************************************************************/
  6. #include "mem0mem.h"
  7. #include "ut0rnd.h"
  8. #ifdef UNIV_DEBUG
  9. extern byte data_error;
  10. #endif /* UNIV_DEBUG */
  11. /*************************************************************************
  12. Gets pointer to the type struct of SQL data field. */
  13. UNIV_INLINE
  14. dtype_t*
  15. dfield_get_type(
  16. /*============*/
  17. /* out: pointer to the type struct */
  18. dfield_t* field) /* in: SQL data field */
  19. {
  20. ut_ad(field);
  21. return(&(field->type));
  22. }
  23. /*************************************************************************
  24. Sets the type struct of SQL data field. */
  25. UNIV_INLINE
  26. void
  27. dfield_set_type(
  28. /*============*/
  29. dfield_t* field, /* in: SQL data field */
  30. dtype_t* type) /* in: pointer to data type struct */
  31. {
  32. ut_ad(field && type);
  33. field->type = *type;
  34. }
  35. /*************************************************************************
  36. Gets pointer to the data in a field. */
  37. UNIV_INLINE
  38. void*
  39. dfield_get_data(
  40. /*============*/
  41. /* out: pointer to data */
  42. dfield_t* field) /* in: field */
  43. {
  44. ut_ad(field);
  45. ut_ad((field->len == UNIV_SQL_NULL)
  46. || (field->data != &data_error));
  47. return(field->data);
  48. }
  49. /*************************************************************************
  50. Gets length of field data. */
  51. UNIV_INLINE
  52. ulint
  53. dfield_get_len(
  54. /*===========*/
  55. /* out: length of data; UNIV_SQL_NULL if
  56. SQL null data */
  57. dfield_t* field) /* in: field */
  58. {
  59. ut_ad(field);
  60. ut_ad((field->len == UNIV_SQL_NULL)
  61. || (field->data != &data_error));
  62. return(field->len);
  63. }
  64. /*************************************************************************
  65. Sets length in a field. */
  66. UNIV_INLINE
  67. void
  68. dfield_set_len(
  69. /*===========*/
  70. dfield_t* field, /* in: field */
  71. ulint len) /* in: length or UNIV_SQL_NULL */
  72. {
  73. ut_ad(field);
  74. field->len = len;
  75. }
  76. /*************************************************************************
  77. Sets pointer to the data and length in a field. */
  78. UNIV_INLINE
  79. void
  80. dfield_set_data(
  81. /*============*/
  82. dfield_t* field, /* in: field */
  83. const void* data, /* in: data */
  84. ulint len) /* in: length or UNIV_SQL_NULL */
  85. {
  86. ut_ad(field);
  87. field->data = (void*) data;
  88. field->len = len;
  89. }
  90. /*************************************************************************
  91. Copies the data and len fields. */
  92. UNIV_INLINE
  93. void
  94. dfield_copy_data(
  95. /*=============*/
  96. dfield_t* field1, /* in: field to copy to */
  97. dfield_t* field2) /* in: field to copy from */
  98. {
  99. ut_ad(field1 && field2);
  100. field1->data = field2->data;
  101. field1->len = field2->len;
  102. }
  103. /*************************************************************************
  104. Copies a data field to another. */
  105. UNIV_INLINE
  106. void
  107. dfield_copy(
  108. /*========*/
  109. dfield_t* field1, /* in: field to copy to */
  110. dfield_t* field2) /* in: field to copy from */
  111. {
  112. *field1 = *field2;
  113. }
  114. /*************************************************************************
  115. Tests if data length and content is equal for two dfields. */
  116. UNIV_INLINE
  117. ibool
  118. dfield_datas_are_binary_equal(
  119. /*==========================*/
  120. /* out: TRUE if equal */
  121. dfield_t* field1, /* in: field */
  122. dfield_t* field2) /* in: field */
  123. {
  124. ulint len;
  125. len = field1->len;
  126. if ((len != field2->len)
  127. || ((len != UNIV_SQL_NULL)
  128. && (0 != ut_memcmp(field1->data, field2->data,
  129. len)))) {
  130. return(FALSE);
  131. }
  132. return(TRUE);
  133. }
  134. /*************************************************************************
  135. Gets info bits in a data tuple. */
  136. UNIV_INLINE
  137. ulint
  138. dtuple_get_info_bits(
  139. /*=================*/
  140. /* out: info bits */
  141. dtuple_t* tuple) /* in: tuple */
  142. {
  143. ut_ad(tuple);
  144. return(tuple->info_bits);
  145. }
  146. /*************************************************************************
  147. Sets info bits in a data tuple. */
  148. UNIV_INLINE
  149. void
  150. dtuple_set_info_bits(
  151. /*=================*/
  152. dtuple_t* tuple, /* in: tuple */
  153. ulint info_bits) /* in: info bits */
  154. {
  155. ut_ad(tuple);
  156. tuple->info_bits = info_bits;
  157. }
  158. /*************************************************************************
  159. Gets number of fields used in record comparisons. */
  160. UNIV_INLINE
  161. ulint
  162. dtuple_get_n_fields_cmp(
  163. /*====================*/
  164. /* out: number of fields used in comparisons
  165. in rem0cmp.* */
  166. dtuple_t* tuple) /* in: tuple */
  167. {
  168. ut_ad(tuple);
  169. return(tuple->n_fields_cmp);
  170. }
  171. /*************************************************************************
  172. Sets number of fields used in record comparisons. */
  173. UNIV_INLINE
  174. void
  175. dtuple_set_n_fields_cmp(
  176. /*====================*/
  177. dtuple_t* tuple, /* in: tuple */
  178. ulint n_fields_cmp) /* in: number of fields used in
  179. comparisons in rem0cmp.* */
  180. {
  181. ut_ad(tuple);
  182. ut_ad(n_fields_cmp <= tuple->n_fields);
  183. tuple->n_fields_cmp = n_fields_cmp;
  184. }
  185. /*************************************************************************
  186. Gets number of fields in a data tuple. */
  187. UNIV_INLINE
  188. ulint
  189. dtuple_get_n_fields(
  190. /*================*/
  191. /* out: number of fields */
  192. dtuple_t* tuple) /* in: tuple */
  193. {
  194. ut_ad(tuple);
  195. return(tuple->n_fields);
  196. }
  197. /*************************************************************************
  198. Gets nth field of a tuple. */
  199. UNIV_INLINE
  200. dfield_t*
  201. dtuple_get_nth_field(
  202. /*=================*/
  203. /* out: nth field */
  204. dtuple_t* tuple, /* in: tuple */
  205. ulint n) /* in: index of field */
  206. {
  207. ut_ad(tuple);
  208. ut_ad(n < tuple->n_fields);
  209. return(tuple->fields + n);
  210. }
  211. /**************************************************************
  212. Creates a data tuple to a memory heap. The default value for number
  213. of fields used in record comparisons for this tuple is n_fields. */
  214. UNIV_INLINE
  215. dtuple_t*
  216. dtuple_create(
  217. /*==========*/
  218. /* out, own: created tuple */
  219. mem_heap_t* heap, /* in: memory heap where the tuple
  220. is created */
  221. ulint n_fields) /* in: number of fields */
  222. {
  223. dtuple_t* tuple;
  224. ut_ad(heap);
  225. tuple = (dtuple_t*) mem_heap_alloc(heap, sizeof(dtuple_t)
  226. + n_fields * sizeof(dfield_t));
  227. tuple->info_bits = 0;
  228. tuple->n_fields = n_fields;
  229. tuple->n_fields_cmp = n_fields;
  230. tuple->fields = (dfield_t*)(((byte*)tuple) + sizeof(dtuple_t));
  231. #ifdef UNIV_DEBUG
  232. tuple->magic_n = DATA_TUPLE_MAGIC_N;
  233. { /* In the debug version, initialize fields to an error value */
  234. ulint i;
  235. for (i = 0; i < n_fields; i++) {
  236. (tuple->fields + i)->data = &data_error;
  237. dfield_get_type(tuple->fields + i)->mtype = DATA_ERROR;
  238. }
  239. }
  240. #endif
  241. return(tuple);
  242. }
  243. /**************************************************************
  244. The following function returns the sum of data lengths of a tuple. The space
  245. occupied by the field structs or the tuple struct is not counted. Neither
  246. is possible space in externally stored parts of the field. */
  247. UNIV_INLINE
  248. ulint
  249. dtuple_get_data_size(
  250. /*=================*/
  251. /* out: sum of data lengths */
  252. dtuple_t* tuple) /* in: typed data tuple */
  253. {
  254. dfield_t* field;
  255. ulint n_fields;
  256. ulint len;
  257. ulint i;
  258. ulint sum = 0;
  259. ut_ad(tuple);
  260. ut_ad(dtuple_check_typed(tuple));
  261. ut_ad(tuple->magic_n == DATA_TUPLE_MAGIC_N);
  262. n_fields = tuple->n_fields;
  263. for (i = 0; i < n_fields; i++) {
  264. field = dtuple_get_nth_field(tuple, i);
  265. len = dfield_get_len(field);
  266. if (len == UNIV_SQL_NULL) {
  267. len = dtype_get_sql_null_size(dfield_get_type(field));
  268. }
  269. sum += len;
  270. }
  271. return(sum);
  272. }
  273. /***********************************************************************
  274. Sets types of fields binary in a tuple. */
  275. UNIV_INLINE
  276. void
  277. dtuple_set_types_binary(
  278. /*====================*/
  279. dtuple_t* tuple, /* in: data tuple */
  280. ulint n) /* in: number of fields to set */
  281. {
  282. dtype_t* dfield_type;
  283. ulint i;
  284. for (i = 0; i < n; i++) {
  285. dfield_type = dfield_get_type(dtuple_get_nth_field(tuple, i));
  286. dtype_set(dfield_type, DATA_BINARY, 0, 0);
  287. }
  288. }
  289. /****************************************************************
  290. Folds a prefix given as the number of fields of a tuple. */
  291. UNIV_INLINE
  292. ulint
  293. dtuple_fold(
  294. /*========*/
  295. /* out: the folded value */
  296. dtuple_t* tuple, /* in: the tuple */
  297. ulint n_fields,/* in: number of complete fields to fold */
  298. ulint n_bytes,/* in: number of bytes to fold in an
  299. incomplete last field */
  300. dulint tree_id)/* in: index tree id */
  301. {
  302. dfield_t* field;
  303. ulint i;
  304. byte* data;
  305. ulint len;
  306. ulint fold;
  307. ut_ad(tuple);
  308. ut_ad(tuple->magic_n == DATA_TUPLE_MAGIC_N);
  309. ut_ad(dtuple_check_typed(tuple));
  310. fold = ut_fold_dulint(tree_id);
  311. for (i = 0; i < n_fields; i++) {
  312. field = dtuple_get_nth_field(tuple, i);
  313. data = (byte*) dfield_get_data(field);
  314. len = dfield_get_len(field);
  315. if (len != UNIV_SQL_NULL) {
  316. fold = ut_fold_ulint_pair(fold,
  317. ut_fold_binary(data, len));
  318. }
  319. }
  320. if (n_bytes > 0) {
  321. field = dtuple_get_nth_field(tuple, i);
  322. data = (byte*) dfield_get_data(field);
  323. len = dfield_get_len(field);
  324. if (len != UNIV_SQL_NULL) {
  325. if (len > n_bytes) {
  326. len = n_bytes;
  327. }
  328. fold = ut_fold_ulint_pair(fold,
  329. ut_fold_binary(data, len));
  330. }
  331. }
  332. return(fold);
  333. }
  334. /**************************************************************************
  335. Writes an SQL null field full of zeros. */
  336. UNIV_INLINE
  337. void
  338. data_write_sql_null(
  339. /*================*/
  340. byte* data, /* in: pointer to a buffer of size len */
  341. ulint len) /* in: SQL null size in bytes */
  342. {
  343. ulint j;
  344. for (j = 0; j < len; j++) {
  345. data[j] = '\0';
  346. }
  347. }
  348. /**************************************************************************
  349. Checks if a dtuple contains an SQL null value. */
  350. UNIV_INLINE
  351. ibool
  352. dtuple_contains_null(
  353. /*=================*/
  354. /* out: TRUE if some field is SQL null */
  355. dtuple_t* tuple) /* in: dtuple */
  356. {
  357. ulint n;
  358. ulint i;
  359. n = dtuple_get_n_fields(tuple);
  360. for (i = 0; i < n; i++) {
  361. if (dfield_get_len(dtuple_get_nth_field(tuple, i))
  362. == UNIV_SQL_NULL) {
  363. return(TRUE);
  364. }
  365. }
  366. return(FALSE);
  367. }