PageRenderTime 49ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/storage/xtradb/include/rem0cmp.h

https://gitlab.com/Cona/server
C Header | 301 lines | 137 code | 8 blank | 156 comment | 0 complexity | 18de40d13bec0c9faa0455567800bfb2 MD5 | raw file
  1. /*****************************************************************************
  2. Copyright (c) 1994, 2012, Oracle and/or its affiliates. All Rights Reserved.
  3. This program is free software; you can redistribute it and/or modify it under
  4. the terms of the GNU General Public License as published by the Free Software
  5. Foundation; version 2 of the License.
  6. This program is distributed in the hope that it will be useful, but WITHOUT
  7. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License along with
  10. this program; if not, write to the Free Software Foundation, Inc.,
  11. 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
  12. *****************************************************************************/
  13. /*******************************************************************//**
  14. @file include/rem0cmp.h
  15. Comparison services for records
  16. Created 7/1/1994 Heikki Tuuri
  17. ************************************************************************/
  18. #ifndef rem0cmp_h
  19. #define rem0cmp_h
  20. #include "univ.i"
  21. #include "data0data.h"
  22. #include "data0type.h"
  23. #include "dict0dict.h"
  24. #include "rem0rec.h"
  25. /*************************************************************//**
  26. Returns TRUE if two columns are equal for comparison purposes.
  27. @return TRUE if the columns are considered equal in comparisons */
  28. UNIV_INTERN
  29. ibool
  30. cmp_cols_are_equal(
  31. /*===============*/
  32. const dict_col_t* col1, /*!< in: column 1 */
  33. const dict_col_t* col2, /*!< in: column 2 */
  34. ibool check_charsets);
  35. /*!< in: whether to check charsets */
  36. /*************************************************************//**
  37. This function is used to compare two data fields for which we know the
  38. data type.
  39. @return 1, 0, -1, if data1 is greater, equal, less than data2, respectively */
  40. UNIV_INLINE
  41. int
  42. cmp_data_data(
  43. /*==========*/
  44. ulint mtype, /*!< in: main type */
  45. ulint prtype, /*!< in: precise type */
  46. const byte* data1, /*!< in: data field (== a pointer to a memory
  47. buffer) */
  48. ulint len1, /*!< in: data field length or UNIV_SQL_NULL */
  49. const byte* data2, /*!< in: data field (== a pointer to a memory
  50. buffer) */
  51. ulint len2); /*!< in: data field length or UNIV_SQL_NULL */
  52. /*************************************************************//**
  53. This function is used to compare two data fields for which we know the
  54. data type.
  55. @return 1, 0, -1, if data1 is greater, equal, less than data2, respectively */
  56. UNIV_INTERN
  57. int
  58. cmp_data_data_slow(
  59. /*===============*/
  60. ulint mtype, /*!< in: main type */
  61. ulint prtype, /*!< in: precise type */
  62. const byte* data1, /*!< in: data field (== a pointer to a memory
  63. buffer) */
  64. ulint len1, /*!< in: data field length or UNIV_SQL_NULL */
  65. const byte* data2, /*!< in: data field (== a pointer to a memory
  66. buffer) */
  67. ulint len2); /*!< in: data field length or UNIV_SQL_NULL */
  68. /*****************************************************************
  69. This function is used to compare two data fields for which we know the
  70. data type to be VARCHAR.
  71. @return 1, 0, -1, if lhs is greater, equal, less than rhs, respectively */
  72. UNIV_INTERN
  73. int
  74. cmp_data_data_slow_varchar(
  75. /*=======================*/
  76. const byte* lhs, /* in: data field (== a pointer to a memory
  77. buffer) */
  78. ulint lhs_len,/* in: data field length or UNIV_SQL_NULL */
  79. const byte* rhs, /* in: data field (== a pointer to a memory
  80. buffer) */
  81. ulint rhs_len);/* in: data field length or UNIV_SQL_NULL */
  82. /*****************************************************************
  83. This function is used to compare two varchar/char fields. The comparison
  84. is for the LIKE operator.
  85. @return 1, 0, -1, if lhs is greater, equal, less than rhs, respectively */
  86. UNIV_INTERN
  87. int
  88. cmp_data_data_slow_like_prefix(
  89. /*===========================*/
  90. const byte* data1, /* in: data field (== a pointer to a memory
  91. buffer) */
  92. ulint len1, /* in: data field length or UNIV_SQL_NULL */
  93. const byte* data2, /* in: data field (== a pointer to a memory
  94. buffer) */
  95. ulint len2); /* in: data field length or UNIV_SQL_NULL */
  96. /*****************************************************************
  97. This function is used to compare two varchar/char fields. The comparison
  98. is for the LIKE operator.
  99. @return 1, 0, -1, if data1 is greater, equal, less than data2, respectively */
  100. UNIV_INTERN
  101. int
  102. cmp_data_data_slow_like_suffix(
  103. /*===========================*/
  104. const byte* data1, /* in: data field (== a pointer to a memory
  105. buffer) */
  106. ulint len1, /* in: data field length or UNIV_SQL_NULL */
  107. const byte* data2, /* in: data field (== a pointer to a memory
  108. buffer) */
  109. ulint len2); /* in: data field length or UNIV_SQL_NULL */
  110. /*****************************************************************
  111. This function is used to compare two varchar/char fields. The comparison
  112. is for the LIKE operator.
  113. @return 1, 0, -1, if data1 is greater, equal, less than data2, respectively */
  114. UNIV_INTERN
  115. int
  116. cmp_data_data_slow_like_substr(
  117. /*===========================*/
  118. const byte* data1, /* in: data field (== a pointer to a memory
  119. buffer) */
  120. ulint len1, /* in: data field length or UNIV_SQL_NULL */
  121. const byte* data2, /* in: data field (== a pointer to a memory
  122. buffer) */
  123. ulint len2); /* in: data field length or UNIV_SQL_NULL */
  124. /*************************************************************//**
  125. This function is used to compare two dfields where at least the first
  126. has its data type field set.
  127. @return 1, 0, -1, if dfield1 is greater, equal, less than dfield2,
  128. respectively */
  129. UNIV_INLINE
  130. int
  131. cmp_dfield_dfield(
  132. /*==============*/
  133. const dfield_t* dfield1,/*!< in: data field; must have type field set */
  134. const dfield_t* dfield2);/*!< in: data field */
  135. /*************************************************************//**
  136. This function is used to compare a data tuple to a physical record.
  137. Only dtuple->n_fields_cmp first fields are taken into account for
  138. the data tuple! If we denote by n = n_fields_cmp, then rec must
  139. have either m >= n fields, or it must differ from dtuple in some of
  140. the m fields rec has. If rec has an externally stored field we do not
  141. compare it but return with value 0 if such a comparison should be
  142. made.
  143. @return 1, 0, -1, if dtuple is greater, equal, less than rec,
  144. respectively, when only the common first fields are compared, or until
  145. the first externally stored field in rec */
  146. UNIV_INTERN
  147. int
  148. cmp_dtuple_rec_with_match_low(
  149. /*==========================*/
  150. const dtuple_t* dtuple, /*!< in: data tuple */
  151. const rec_t* rec, /*!< in: physical record which differs from
  152. dtuple in some of the common fields, or which
  153. has an equal number or more fields than
  154. dtuple */
  155. const ulint* offsets,/*!< in: array returned by rec_get_offsets() */
  156. ulint n_cmp, /*!< in: number of fields to compare */
  157. ulint* matched_fields,
  158. /*!< in/out: number of already completely
  159. matched fields; when function returns,
  160. contains the value for current comparison */
  161. ulint* matched_bytes)
  162. /*!< in/out: number of already matched
  163. bytes within the first field not completely
  164. matched; when function returns, contains the
  165. value for current comparison */
  166. __attribute__((nonnull));
  167. #define cmp_dtuple_rec_with_match(tuple,rec,offsets,fields,bytes) \
  168. cmp_dtuple_rec_with_match_low( \
  169. tuple,rec,offsets,dtuple_get_n_fields_cmp(tuple),fields,bytes)
  170. /**************************************************************//**
  171. Compares a data tuple to a physical record.
  172. @see cmp_dtuple_rec_with_match
  173. @return 1, 0, -1, if dtuple is greater, equal, less than rec, respectively */
  174. UNIV_INTERN
  175. int
  176. cmp_dtuple_rec(
  177. /*===========*/
  178. const dtuple_t* dtuple, /*!< in: data tuple */
  179. const rec_t* rec, /*!< in: physical record */
  180. const ulint* offsets);/*!< in: array returned by rec_get_offsets() */
  181. /**************************************************************//**
  182. Checks if a dtuple is a prefix of a record. The last field in dtuple
  183. is allowed to be a prefix of the corresponding field in the record.
  184. @return TRUE if prefix */
  185. UNIV_INTERN
  186. ibool
  187. cmp_dtuple_is_prefix_of_rec(
  188. /*========================*/
  189. const dtuple_t* dtuple, /*!< in: data tuple */
  190. const rec_t* rec, /*!< in: physical record */
  191. const ulint* offsets);/*!< in: array returned by rec_get_offsets() */
  192. /*************************************************************//**
  193. Compare two physical records that contain the same number of columns,
  194. none of which are stored externally.
  195. @retval 1 if rec1 (including non-ordering columns) is greater than rec2
  196. @retval -1 if rec1 (including non-ordering columns) is less than rec2
  197. @retval 0 if rec1 is a duplicate of rec2 */
  198. UNIV_INTERN
  199. int
  200. cmp_rec_rec_simple(
  201. /*===============*/
  202. const rec_t* rec1, /*!< in: physical record */
  203. const rec_t* rec2, /*!< in: physical record */
  204. const ulint* offsets1,/*!< in: rec_get_offsets(rec1, ...) */
  205. const ulint* offsets2,/*!< in: rec_get_offsets(rec2, ...) */
  206. const dict_index_t* index, /*!< in: data dictionary index */
  207. struct TABLE* table) /*!< in: MySQL table, for reporting
  208. duplicate key value if applicable,
  209. or NULL */
  210. __attribute__((nonnull(1,2,3,4), warn_unused_result));
  211. /*************************************************************//**
  212. This function is used to compare two physical records. Only the common
  213. first fields are compared, and if an externally stored field is
  214. encountered, then 0 is returned.
  215. @return 1, 0, -1 if rec1 is greater, equal, less, respectively */
  216. UNIV_INTERN
  217. int
  218. cmp_rec_rec_with_match(
  219. /*===================*/
  220. const rec_t* rec1, /*!< in: physical record */
  221. const rec_t* rec2, /*!< in: physical record */
  222. const ulint* offsets1,/*!< in: rec_get_offsets(rec1, index) */
  223. const ulint* offsets2,/*!< in: rec_get_offsets(rec2, index) */
  224. dict_index_t* index, /*!< in: data dictionary index */
  225. ibool nulls_unequal,
  226. /* in: TRUE if this is for index statistics
  227. cardinality estimation, and innodb_stats_method
  228. is "nulls_unequal" or "nulls_ignored" */
  229. ulint* matched_fields, /*!< in/out: number of already completely
  230. matched fields; when the function returns,
  231. contains the value the for current
  232. comparison */
  233. ulint* matched_bytes);/*!< in/out: number of already matched
  234. bytes within the first field not completely
  235. matched; when the function returns, contains
  236. the value for the current comparison */
  237. /*************************************************************//**
  238. This function is used to compare two physical records. Only the common
  239. first fields are compared.
  240. @return 1, 0 , -1 if rec1 is greater, equal, less, respectively, than
  241. rec2; only the common first fields are compared */
  242. UNIV_INLINE
  243. int
  244. cmp_rec_rec(
  245. /*========*/
  246. const rec_t* rec1, /*!< in: physical record */
  247. const rec_t* rec2, /*!< in: physical record */
  248. const ulint* offsets1,/*!< in: rec_get_offsets(rec1, index) */
  249. const ulint* offsets2,/*!< in: rec_get_offsets(rec2, index) */
  250. dict_index_t* index); /*!< in: data dictionary index */
  251. /*****************************************************************
  252. This function is used to compare two dfields where at least the first
  253. has its data type field set. */
  254. UNIV_INTERN
  255. int
  256. cmp_dfield_dfield_like_prefix(
  257. /*==========================*/
  258. /* out: 1, 0, -1, if dfield1 is greater, equal,
  259. less than dfield2, respectively */
  260. dfield_t* dfield1,/* in: data field; must have type field set */
  261. dfield_t* dfield2);/* in: data field */
  262. /*****************************************************************
  263. This function is used to compare two dfields where at least the first
  264. has its data type field set. */
  265. UNIV_INLINE
  266. int
  267. cmp_dfield_dfield_like_substr(
  268. /*==========================*/
  269. /* out: 1, 0, -1, if dfield1 is greater, equal,
  270. less than dfield2, respectively */
  271. dfield_t* dfield1,/* in: data field; must have type field set */
  272. dfield_t* dfield2);/* in: data field */
  273. /*****************************************************************
  274. This function is used to compare two dfields where at least the first
  275. has its data type field set. */
  276. UNIV_INLINE
  277. int
  278. cmp_dfield_dfield_like_suffix(
  279. /*==========================*/
  280. /* out: 1, 0, -1, if dfield1 is greater, equal,
  281. less than dfield2, respectively */
  282. dfield_t* dfield1,/* in: data field; must have type field set */
  283. dfield_t* dfield2);/* in: data field */
  284. #ifndef UNIV_NONINL
  285. #include "rem0cmp.ic"
  286. #endif
  287. #endif