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

MySQL数据库

开发平台:

Visual C++

  1. /************************************************************************
  2. SQL data field and tuple
  3. (c) 1994-1996 Innobase Oy
  4. Created 5/30/1994 Heikki Tuuri
  5. *************************************************************************/
  6. #ifndef data0data_h
  7. #define data0data_h
  8. #include "univ.i"
  9. #include "data0types.h"
  10. #include "data0type.h"
  11. #include "mem0mem.h"
  12. /* Some non-inlined functions used in the MySQL interface: */
  13. void 
  14. dfield_set_data_noninline(
  15. dfield_t*  field, /* in: field */
  16. void* data, /* in: data */
  17. ulint len); /* in: length or UNIV_SQL_NULL */
  18. void* 
  19. dfield_get_data_noninline(
  20. dfield_t* field); /* in: field */
  21. ulint
  22. dfield_get_len_noninline(
  23. dfield_t* field); /* in: field */
  24. ulint 
  25. dtuple_get_n_fields_noninline(
  26. dtuple_t*  tuple); /* in: tuple */
  27. dfield_t* 
  28. dtuple_get_nth_field_noninline(
  29. dtuple_t*  tuple, /* in: tuple */
  30. ulint n); /* in: index of field */
  31. /*************************************************************************
  32. Gets pointer to the type struct of SQL data field. */
  33. UNIV_INLINE
  34. dtype_t*
  35. dfield_get_type(
  36. /*============*/
  37. /* out: pointer to the type struct */
  38. dfield_t* field); /* in: SQL data field */
  39. /*************************************************************************
  40. Sets the type struct of SQL data field. */
  41. UNIV_INLINE
  42. void
  43. dfield_set_type(
  44. /*============*/
  45. dfield_t* field, /* in: SQL data field */
  46. dtype_t* type); /* in: pointer to data type struct */
  47. /*************************************************************************
  48. Gets pointer to the data in a field. */
  49. UNIV_INLINE
  50. void* 
  51. dfield_get_data(
  52. /*============*/
  53. /* out: pointer to data */
  54. dfield_t* field); /* in: field */
  55. /*************************************************************************
  56. Gets length of field data. */
  57. UNIV_INLINE
  58. ulint
  59. dfield_get_len(
  60. /*===========*/
  61. /* out: length of data; UNIV_SQL_NULL if 
  62. SQL null data */
  63. dfield_t* field); /* in: field */
  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. Sets pointer to the data and length in a field. */
  74. UNIV_INLINE
  75. void 
  76. dfield_set_data(
  77. /*============*/
  78. dfield_t*  field, /* in: field */
  79. void* data, /* in: data */
  80. ulint len); /* in: length or UNIV_SQL_NULL */
  81. /**************************************************************************
  82. Writes an SQL null field full of zeros. */
  83. UNIV_INLINE
  84. void
  85. data_write_sql_null(
  86. /*================*/
  87. byte* data, /* in: pointer to a buffer of size len */
  88. ulint len); /* in: SQL null size in bytes */
  89. /*************************************************************************
  90. Copies the data and len fields. */
  91. UNIV_INLINE
  92. void 
  93. dfield_copy_data(
  94. /*=============*/
  95. dfield_t*  field1, /* in: field to copy to */
  96. dfield_t* field2);/* in: field to copy from */
  97. /*************************************************************************
  98. Copies a data field to another. */
  99. UNIV_INLINE
  100. void
  101. dfield_copy(
  102. /*========*/
  103. dfield_t* field1, /* in: field to copy to */
  104. dfield_t* field2);/* in: field to copy from */
  105. /*************************************************************************
  106. Tests if data length and content is equal for two dfields. */
  107. UNIV_INLINE
  108. ibool
  109. dfield_datas_are_equal(
  110. /*===================*/
  111. /* out: TRUE if equal */
  112. dfield_t* field1, /* in: field */
  113. dfield_t* field2);/* in: field */
  114. /*************************************************************************
  115. Tests if dfield data length and content is equal to the given. */
  116. UNIV_INLINE
  117. ibool
  118. dfield_data_is_equal(
  119. /*=================*/
  120. /* out: TRUE if equal */
  121. dfield_t* field, /* in: field */
  122. ulint len, /* in: data length or UNIV_SQL_NULL */
  123. byte* data); /* in: data */
  124. /*************************************************************************
  125. Gets number of fields in a data tuple. */
  126. UNIV_INLINE
  127. ulint 
  128. dtuple_get_n_fields(
  129. /*================*/
  130. /* out: number of fields */
  131. dtuple_t*  tuple); /* in: tuple */
  132. /*************************************************************************
  133. Gets nth field of a tuple. */
  134. UNIV_INLINE
  135. dfield_t* 
  136. dtuple_get_nth_field(
  137. /*=================*/
  138. /* out: nth field */
  139. dtuple_t*  tuple, /* in: tuple */
  140. ulint n); /* in: index of field */
  141. /*************************************************************************
  142. Gets info bits in a data tuple. */
  143. UNIV_INLINE
  144. ulint
  145. dtuple_get_info_bits(
  146. /*=================*/
  147. /* out: info bits */
  148. dtuple_t*  tuple); /* in: tuple */
  149. /*************************************************************************
  150. Sets info bits in a data tuple. */
  151. UNIV_INLINE
  152. void
  153. dtuple_set_info_bits(
  154. /*=================*/
  155. dtuple_t*  tuple, /* in: tuple */
  156. ulint info_bits); /* in: info bits */
  157. /*************************************************************************
  158. Gets number of fields used in record comparisons. */
  159. UNIV_INLINE
  160. ulint
  161. dtuple_get_n_fields_cmp(
  162. /*====================*/
  163. /* out: number of fields used in comparisons
  164. in rem0cmp.* */
  165. dtuple_t* tuple); /* in: tuple */
  166. /*************************************************************************
  167. Gets number of fields used in record comparisons. */
  168. UNIV_INLINE
  169. void
  170. dtuple_set_n_fields_cmp(
  171. /*====================*/
  172. dtuple_t* tuple, /* in: tuple */
  173. ulint n_fields_cmp); /* in: number of fields used in
  174. comparisons in rem0cmp.* */
  175. /**************************************************************
  176. Creates a data tuple to a memory heap. The default value for number
  177. of fields used in record comparisons for this tuple is n_fields. */
  178. UNIV_INLINE
  179. dtuple_t*
  180. dtuple_create(
  181. /*==========*/
  182.     /* out, own: created tuple */
  183. mem_heap_t* heap, /* in: memory heap where the tuple
  184. is created */
  185. ulint n_fields); /* in: number of fields */
  186. /*************************************************************************
  187. Creates a dtuple for use in MySQL. */
  188. dtuple_t*
  189. dtuple_create_for_mysql(
  190. /*====================*/
  191. /* out, own created dtuple */
  192. void** heap,    /* out: created memory heap */
  193. ulint n_fields); /* in: number of fields */
  194. /*************************************************************************
  195. Frees a dtuple used in MySQL. */
  196. void
  197. dtuple_free_for_mysql(
  198. /*==================*/
  199. void* heap);
  200. /*************************************************************************
  201. Sets number of fields used in a tuple. Normally this is set in
  202. dtuple_create, but if you want later to set it smaller, you can use this. */ 
  203. void
  204. dtuple_set_n_fields(
  205. /*================*/
  206. dtuple_t* tuple, /* in: tuple */
  207. ulint n_fields); /* in: number of fields */
  208. /**************************************************************
  209. The following function returns the sum of data lengths of a tuple. The space
  210. occupied by the field structs or the tuple struct is not counted. */
  211. UNIV_INLINE
  212. ulint
  213. dtuple_get_data_size(
  214. /*=================*/
  215. /* out: sum of data lens */
  216. dtuple_t* tuple); /* in: typed data tuple */
  217. /****************************************************************
  218. Returns TRUE if lengths of two dtuples are equal and respective data fields
  219. in them are equal. */
  220. UNIV_INLINE
  221. ibool
  222. dtuple_datas_are_equal(
  223. /*===================*/
  224. /* out: TRUE if length and datas are equal */
  225. dtuple_t* tuple1, /* in: tuple 1 */
  226. dtuple_t* tuple2); /* in: tuple 2 */
  227. /****************************************************************
  228. Folds a prefix given as the number of fields of a tuple. */
  229. UNIV_INLINE
  230. ulint
  231. dtuple_fold(
  232. /*========*/
  233. /* out: the folded value */
  234. dtuple_t* tuple, /* in: the tuple */
  235. ulint n_fields,/* in: number of complete fields to fold */
  236. ulint n_bytes,/* in: number of bytes to fold in an
  237. incomplete last field */
  238. dulint tree_id);/* in: index tree id */
  239. /***********************************************************************
  240. Sets types of fields binary in a tuple. */
  241. UNIV_INLINE
  242. void
  243. dtuple_set_types_binary(
  244. /*====================*/
  245. dtuple_t* tuple, /* in: data tuple */
  246. ulint n); /* in: number of fields to set */
  247. /**************************************************************
  248. Checks that a data field is typed. Asserts an error if not. */
  249. ibool
  250. dfield_check_typed(
  251. /*===============*/
  252. /* out: TRUE if ok */
  253. dfield_t* field); /* in: data field */
  254. /**************************************************************
  255. Checks that a data tuple is typed. Asserts an error if not. */
  256. ibool
  257. dtuple_check_typed(
  258. /*===============*/
  259. /* out: TRUE if ok */
  260. dtuple_t* tuple); /* in: tuple */
  261. /**************************************************************
  262. Validates the consistency of a tuple which must be complete, i.e,
  263. all fields must have been set. */
  264. ibool
  265. dtuple_validate(
  266. /*============*/
  267. /* out: TRUE if ok */
  268. dtuple_t* tuple); /* in: tuple */
  269. /*****************************************************************
  270. Pretty prints a dfield value according to its data type. */
  271. void
  272. dfield_print(
  273. /*=========*/
  274. dfield_t* dfield);/* in: dfield */
  275. /*****************************************************************
  276. Pretty prints a dfield value according to its data type. Also the hex string
  277. is printed if a string contains non-printable characters. */ 
  278. void
  279. dfield_print_also_hex(
  280. /*==================*/
  281. dfield_t* dfield);  /* in: dfield */
  282. /**************************************************************
  283. The following function prints the contents of a tuple. */
  284. void
  285. dtuple_print(
  286. /*=========*/
  287. dtuple_t* tuple); /* in: tuple */
  288. /**************************************************************
  289. The following function prints the contents of a tuple to a buffer. */
  290. ulint
  291. dtuple_sprintf(
  292. /*===========*/
  293. /* out: printed length in bytes */
  294. char* buf, /* in: print buffer */
  295. ulint buf_len,/* in: buf length in bytes */
  296. dtuple_t* tuple); /* in: tuple */
  297. /***************************************************************
  298. Generates a random tuple. */
  299. dtuple_t*
  300. dtuple_gen_rnd_tuple(
  301. /*=================*/
  302. /* out: pointer to the tuple */
  303. mem_heap_t* heap); /* in: memory heap where generated */
  304. /*******************************************************************
  305. Generates a test tuple for sort and comparison tests. */
  306. void
  307. dtuple_gen_test_tuple(
  308. /*==================*/
  309. dtuple_t* tuple, /* in/out: a tuple with 3 fields */
  310. ulint i); /* in: a number, 0 <= i < 512 */
  311. /*******************************************************************
  312. Generates a test tuple for B-tree speed tests. */
  313. void
  314. dtuple_gen_test_tuple3(
  315. /*===================*/
  316. dtuple_t* tuple, /* in/out: a tuple with 3 fields */
  317. ulint i, /* in: a number < 1000000 */
  318. ulint type, /* in: DTUPLE_TEST_FIXED30, ... */
  319. byte* buf); /* in: a buffer of size >= 8 bytes */
  320. /*******************************************************************
  321. Generates a test tuple for B-tree speed tests. */
  322. void
  323. dtuple_gen_search_tuple3(
  324. /*=====================*/
  325. dtuple_t* tuple, /* in/out: a tuple with 1 or 2 fields */
  326. ulint i, /* in: a number < 1000000 */
  327. byte* buf); /* in: a buffer of size >= 8 bytes */
  328. /*******************************************************************
  329. Generates a test tuple for TPC-A speed test. */
  330. void
  331. dtuple_gen_test_tuple_TPC_A(
  332. /*========================*/
  333. dtuple_t* tuple, /* in/out: a tuple with >= 3 fields */
  334. ulint i, /* in: a number < 10000 */
  335. byte* buf); /* in: a buffer of size >= 16 bytes */
  336. /*******************************************************************
  337. Generates a test tuple for B-tree speed tests. */
  338. void
  339. dtuple_gen_search_tuple_TPC_A(
  340. /*==========================*/
  341. dtuple_t* tuple, /* in/out: a tuple with 1 field */
  342. ulint i, /* in: a number < 10000 */
  343. byte* buf); /* in: a buffer of size >= 16 bytes */
  344. /*******************************************************************
  345. Generates a test tuple for TPC-C speed test. */
  346. void
  347. dtuple_gen_test_tuple_TPC_C(
  348. /*========================*/
  349. dtuple_t* tuple, /* in/out: a tuple with >= 12 fields */
  350. ulint i, /* in: a number < 100000 */
  351. byte* buf); /* in: a buffer of size >= 16 bytes */
  352. /*******************************************************************
  353. Generates a test tuple for B-tree speed tests. */
  354. void
  355. dtuple_gen_search_tuple_TPC_C(
  356. /*==========================*/
  357. dtuple_t* tuple, /* in/out: a tuple with 1 field */
  358. ulint i, /* in: a number < 100000 */
  359. byte* buf); /* in: a buffer of size >= 16 bytes */
  360. /* Types of the third field in dtuple_gen_test_tuple3 */
  361. #define DTUPLE_TEST_FIXED30 1
  362. #define DTUPLE_TEST_RND30 2
  363. #define DTUPLE_TEST_RND3500 3
  364. #define DTUPLE_TEST_FIXED2000 4
  365. #define DTUPLE_TEST_FIXED3 5
  366. /*######################################################################*/
  367. /* Structure for an SQL data field */
  368. struct dfield_struct{
  369. void* data; /* pointer to data */
  370. ulint len; /* data length; UNIV_SQL_NULL if SQL null */
  371. dtype_t type; /* type of data */
  372. ulint col_no; /* when building index entries, the column
  373. number can be stored here */
  374. };
  375. struct dtuple_struct {
  376. ulint info_bits; /* info bits of an index record:
  377. default is 0; this field is used
  378. if an index record is built from
  379. a data tuple */
  380. ulint n_fields; /* number of fields in dtuple */
  381. ulint n_fields_cmp; /* number of fields which should
  382. be used in comparison services
  383. of rem0cmp.*; the index search
  384. is performed by comparing only these
  385. fields, others are ignored; the
  386. default value in dtuple creation is
  387. the same value as n_fields */
  388. dfield_t* fields; /* fields */
  389. UT_LIST_NODE_T(dtuple_t) tuple_list;
  390. /* data tuples can be linked into a
  391. list using this field */
  392. ulint magic_n;
  393. };
  394. #define DATA_TUPLE_MAGIC_N 65478679
  395. #ifndef UNIV_NONINL
  396. #include "data0data.ic"
  397. #endif
  398. #endif