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.

255 lines
8.6 KiB

10 years ago
10 years ago
10 years ago
  1. /*****************************************************************************
  2. Copyright (c) 1994, 2016, Oracle and/or its affiliates. All Rights Reserved.
  3. Copyright (c) 2017, MariaDB Corporation.
  4. This program is free software; you can redistribute it and/or modify it under
  5. the terms of the GNU General Public License as published by the Free Software
  6. Foundation; version 2 of the License.
  7. This program is distributed in the hope that it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License along with
  11. this program; if not, write to the Free Software Foundation, Inc.,
  12. 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
  13. *****************************************************************************/
  14. /*******************************************************************//**
  15. @file include/rem0cmp.h
  16. Comparison services for records
  17. Created 7/1/1994 Heikki Tuuri
  18. ************************************************************************/
  19. #ifndef rem0cmp_h
  20. #define rem0cmp_h
  21. #include "data0data.h"
  22. #include "data0type.h"
  23. #include "dict0types.h"
  24. #include "rem0types.h"
  25. #include "page0types.h"
  26. /*************************************************************//**
  27. Returns TRUE if two columns are equal for comparison purposes.
  28. @return TRUE if the columns are considered equal in comparisons */
  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. /** Compare two data fields.
  37. @param[in] mtype main type
  38. @param[in] prtype precise type
  39. @param[in] data1 data field
  40. @param[in] len1 length of data1 in bytes, or UNIV_SQL_NULL
  41. @param[in] data2 data field
  42. @param[in] len2 length of data2 in bytes, or UNIV_SQL_NULL
  43. @return the comparison result of data1 and data2
  44. @retval 0 if data1 is equal to data2
  45. @retval negative if data1 is less than data2
  46. @retval positive if data1 is greater than data2 */
  47. int
  48. cmp_data_data(
  49. ulint mtype,
  50. ulint prtype,
  51. const byte* data1,
  52. ulint len1,
  53. const byte* data2,
  54. ulint len2)
  55. MY_ATTRIBUTE((warn_unused_result));
  56. /** Compare two data fields.
  57. @param[in] dfield1 data field; must have type field set
  58. @param[in] dfield2 data field
  59. @return the comparison result of dfield1 and dfield2
  60. @retval 0 if dfield1 is equal to dfield2
  61. @retval negative if dfield1 is less than dfield2
  62. @retval positive if dfield1 is greater than dfield2 */
  63. UNIV_INLINE
  64. int
  65. cmp_dfield_dfield(
  66. /*==============*/
  67. const dfield_t* dfield1,/*!< in: data field; must have type field set */
  68. const dfield_t* dfield2);/*!< in: data field */
  69. /** Compare a GIS data tuple to a physical record.
  70. @param[in] dtuple data tuple
  71. @param[in] rec B-tree record
  72. @param[in] offsets rec_get_offsets(rec)
  73. @param[in] mode compare mode
  74. @retval negative if dtuple is less than rec */
  75. int
  76. cmp_dtuple_rec_with_gis(
  77. /*====================*/
  78. const dtuple_t* dtuple,
  79. const rec_t* rec,
  80. const ulint* offsets,
  81. page_cur_mode_t mode)
  82. MY_ATTRIBUTE((nonnull));
  83. /** Compare a GIS data tuple to a physical record in rtree non-leaf node.
  84. We need to check the page number field, since we don't store pk field in
  85. rtree non-leaf node.
  86. @param[in] dtuple data tuple
  87. @param[in] rec R-tree record
  88. @param[in] offsets rec_get_offsets(rec)
  89. @param[in] mode compare mode
  90. @retval negative if dtuple is less than rec */
  91. int
  92. cmp_dtuple_rec_with_gis_internal(
  93. const dtuple_t* dtuple,
  94. const rec_t* rec,
  95. const ulint* offsets);
  96. /** Compare a data tuple to a physical record.
  97. @param[in] dtuple data tuple
  98. @param[in] rec B-tree record
  99. @param[in] offsets rec_get_offsets(rec)
  100. @param[in] n_cmp number of fields to compare
  101. @param[in,out] matched_fields number of completely matched fields
  102. @return the comparison result of dtuple and rec
  103. @retval 0 if dtuple is equal to rec
  104. @retval negative if dtuple is less than rec
  105. @retval positive if dtuple is greater than rec */
  106. int
  107. cmp_dtuple_rec_with_match_low(
  108. const dtuple_t* dtuple,
  109. const rec_t* rec,
  110. const ulint* offsets,
  111. ulint n_cmp,
  112. ulint* matched_fields)
  113. MY_ATTRIBUTE((nonnull));
  114. #define cmp_dtuple_rec_with_match(tuple,rec,offsets,fields) \
  115. cmp_dtuple_rec_with_match_low( \
  116. tuple,rec,offsets,dtuple_get_n_fields_cmp(tuple),fields)
  117. /** Compare a data tuple to a physical record.
  118. @param[in] dtuple data tuple
  119. @param[in] rec B-tree or R-tree index record
  120. @param[in] index index tree
  121. @param[in] offsets rec_get_offsets(rec)
  122. @param[in,out] matched_fields number of completely matched fields
  123. @param[in,out] matched_bytes number of matched bytes in the first
  124. field that is not matched
  125. @return the comparison result of dtuple and rec
  126. @retval 0 if dtuple is equal to rec
  127. @retval negative if dtuple is less than rec
  128. @retval positive if dtuple is greater than rec */
  129. int
  130. cmp_dtuple_rec_with_match_bytes(
  131. const dtuple_t* dtuple,
  132. const rec_t* rec,
  133. const dict_index_t* index,
  134. const ulint* offsets,
  135. ulint* matched_fields,
  136. ulint* matched_bytes)
  137. MY_ATTRIBUTE((warn_unused_result));
  138. /** Compare a data tuple to a physical record.
  139. @see cmp_dtuple_rec_with_match
  140. @param[in] dtuple data tuple
  141. @param[in] rec B-tree record
  142. @param[in] offsets rec_get_offsets(rec)
  143. @return the comparison result of dtuple and rec
  144. @retval 0 if dtuple is equal to rec
  145. @retval negative if dtuple is less than rec
  146. @retval positive if dtuple is greater than rec */
  147. int
  148. cmp_dtuple_rec(
  149. const dtuple_t* dtuple,
  150. const rec_t* rec,
  151. const ulint* offsets);
  152. /**************************************************************//**
  153. Checks if a dtuple is a prefix of a record. The last field in dtuple
  154. is allowed to be a prefix of the corresponding field in the record.
  155. @return TRUE if prefix */
  156. ibool
  157. cmp_dtuple_is_prefix_of_rec(
  158. /*========================*/
  159. const dtuple_t* dtuple, /*!< in: data tuple */
  160. const rec_t* rec, /*!< in: physical record */
  161. const ulint* offsets);/*!< in: array returned by rec_get_offsets() */
  162. /** Compare two physical records that contain the same number of columns,
  163. none of which are stored externally.
  164. @retval positive if rec1 (including non-ordering columns) is greater than rec2
  165. @retval negative if rec1 (including non-ordering columns) is less than rec2
  166. @retval 0 if rec1 is a duplicate of rec2 */
  167. int
  168. cmp_rec_rec_simple(
  169. /*===============*/
  170. const rec_t* rec1, /*!< in: physical record */
  171. const rec_t* rec2, /*!< in: physical record */
  172. const ulint* offsets1,/*!< in: rec_get_offsets(rec1, ...) */
  173. const ulint* offsets2,/*!< in: rec_get_offsets(rec2, ...) */
  174. const dict_index_t* index, /*!< in: data dictionary index */
  175. struct TABLE* table) /*!< in: MySQL table, for reporting
  176. duplicate key value if applicable,
  177. or NULL */
  178. MY_ATTRIBUTE((nonnull(1,2,3,4), warn_unused_result));
  179. /** Compare two B-tree records.
  180. @param[in] rec1 B-tree record
  181. @param[in] rec2 B-tree record
  182. @param[in] offsets1 rec_get_offsets(rec1, index)
  183. @param[in] offsets2 rec_get_offsets(rec2, index)
  184. @param[in] index B-tree index
  185. @param[in] nulls_unequal true if this is for index cardinality
  186. statistics estimation, and innodb_stats_method=nulls_unequal
  187. or innodb_stats_method=nulls_ignored
  188. @param[out] matched_fields number of completely matched fields
  189. within the first field not completely matched
  190. @return the comparison result
  191. @retval 0 if rec1 is equal to rec2
  192. @retval negative if rec1 is less than rec2
  193. @retval positive if rec2 is greater than rec2 */
  194. int
  195. cmp_rec_rec_with_match(
  196. const rec_t* rec1,
  197. const rec_t* rec2,
  198. const ulint* offsets1,
  199. const ulint* offsets2,
  200. const dict_index_t* index,
  201. bool nulls_unequal,
  202. ulint* matched_fields);
  203. /** Compare two B-tree records.
  204. Only the common first fields are compared, and externally stored field
  205. are treated as equal.
  206. @param[in] rec1 B-tree record
  207. @param[in] rec2 B-tree record
  208. @param[in] offsets1 rec_get_offsets(rec1, index)
  209. @param[in] offsets2 rec_get_offsets(rec2, index)
  210. @param[out] matched_fields number of completely matched fields
  211. within the first field not completely matched
  212. @return positive, 0, negative if rec1 is greater, equal, less, than rec2,
  213. respectively */
  214. UNIV_INLINE
  215. int
  216. cmp_rec_rec(
  217. const rec_t* rec1,
  218. const rec_t* rec2,
  219. const ulint* offsets1,
  220. const ulint* offsets2,
  221. const dict_index_t* index,
  222. ulint* matched_fields = NULL);
  223. /** Compare two data fields.
  224. @param[in] dfield1 data field
  225. @param[in] dfield2 data field
  226. @return the comparison result of dfield1 and dfield2
  227. @retval 0 if dfield1 is equal to dfield2, or a prefix of dfield1
  228. @retval negative if dfield1 is less than dfield2
  229. @retval positive if dfield1 is greater than dfield2 */
  230. UNIV_INLINE
  231. int
  232. cmp_dfield_dfield_like_prefix(
  233. const dfield_t* dfield1,
  234. const dfield_t* dfield2);
  235. #include "rem0cmp.ic"
  236. #endif