my_compare.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /* Copyright (c) 2011, Oracle and/or its affiliates.
  2. Copyright (c) Monty Program Ab; 1991-2011
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; version 2 of the License.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program; if not, write to the Free Software
  12. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
  13. #ifndef _my_compare_h
  14. #define _my_compare_h
  15. #include "myisampack.h"
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. #include "m_ctype.h" /* CHARSET_INFO */
  20. /*
  21. There is a hard limit for the maximum number of keys as there are only
  22. 8 bits in the index file header for the number of keys in a table.
  23. This means that 0..255 keys can exist for a table. The idea of
  24. HA_MAX_POSSIBLE_KEY is to ensure that one can use myisamchk & tools on
  25. a MyISAM table for which one has more keys than MyISAM is normally
  26. compiled for. If you don't have this, you will get a core dump when
  27. running myisamchk compiled for 128 keys on a table with 255 keys.
  28. */
  29. #define HA_MAX_POSSIBLE_KEY 255 /* For myisamchk */
  30. /*
  31. The following defines can be increased if necessary.
  32. But beware the dependency of MI_MAX_POSSIBLE_KEY_BUFF and HA_MAX_KEY_LENGTH.
  33. */
  34. #define HA_MAX_KEY_LENGTH 1000 /* Max length in bytes */
  35. #define HA_MAX_KEY_SEG 32 /* Max segments for key */
  36. #define HA_MAX_POSSIBLE_KEY_BUFF (HA_MAX_KEY_LENGTH + 24+ 6+6)
  37. #define HA_MAX_KEY_BUFF (HA_MAX_KEY_LENGTH+HA_MAX_KEY_SEG*6+8+8)
  38. typedef struct st_HA_KEYSEG /* Key-portion */
  39. {
  40. CHARSET_INFO *charset;
  41. uint32 start; /* Start of key in record */
  42. uint32 null_pos; /* position to NULL indicator */
  43. uint16 bit_pos; /* Position to bit part */
  44. uint16 flag;
  45. uint16 length; /* Keylength */
  46. uint16 language;
  47. uint8 type; /* Type of key (for sort) */
  48. uint8 null_bit; /* bitmask to test for NULL */
  49. uint8 bit_start,bit_end; /* if bit field */
  50. uint8 bit_length; /* Length of bit part */
  51. } HA_KEYSEG;
  52. #define get_key_length(length,key) \
  53. { if (*(const uchar*) (key) != 255) \
  54. length= (uint) *(const uchar*) ((key)++); \
  55. else \
  56. { length= mi_uint2korr((key)+1); (key)+=3; } \
  57. }
  58. #define get_key_length_rdonly(length,key) \
  59. { if (*(const uchar*) (key) != 255) \
  60. length= ((uint) *(const uchar*) ((key))); \
  61. else \
  62. { length= mi_uint2korr((key)+1); } \
  63. }
  64. #define get_key_pack_length(length,length_pack,key) \
  65. { if (*(const uchar*) (key) != 255) \
  66. { length= (uint) *(const uchar*) ((key)++); length_pack= 1; }\
  67. else \
  68. { length=mi_uint2korr((key)+1); (key)+= 3; length_pack= 3; } \
  69. }
  70. #define store_key_length_inc(key,length) \
  71. { if ((length) < 255) \
  72. { *(key)++= (length); } \
  73. else \
  74. { *(key)=255; mi_int2store((key)+1,(length)); (key)+=3; } \
  75. }
  76. #define size_to_store_key_length(length) ((length) < 255 ? 1 : 3)
  77. #define get_rec_bits(bit_ptr, bit_ofs, bit_len) \
  78. (((((uint16) (bit_ptr)[1] << 8) | (uint16) (bit_ptr)[0]) >> (bit_ofs)) & \
  79. ((1 << (bit_len)) - 1))
  80. #define set_rec_bits(bits, bit_ptr, bit_ofs, bit_len) \
  81. { \
  82. (bit_ptr)[0]= ((bit_ptr)[0] & ~(((1 << (bit_len)) - 1) << (bit_ofs))) | \
  83. ((bits) << (bit_ofs)); \
  84. if ((bit_ofs) + (bit_len) > 8) \
  85. (bit_ptr)[1]= ((bit_ptr)[1] & ~((1 << ((bit_len) - 8 + (bit_ofs))) - 1)) | \
  86. ((bits) >> (8 - (bit_ofs))); \
  87. }
  88. #define clr_rec_bits(bit_ptr, bit_ofs, bit_len) \
  89. set_rec_bits(0, bit_ptr, bit_ofs, bit_len)
  90. extern int ha_compare_text(CHARSET_INFO *, const uchar *, uint,
  91. const uchar *, uint , my_bool, my_bool);
  92. extern int ha_key_cmp(HA_KEYSEG *keyseg, const uchar *a,
  93. const uchar *b, uint key_length, uint nextflag,
  94. uint *diff_pos);
  95. extern HA_KEYSEG *ha_find_null(HA_KEYSEG *keyseg, const uchar *a);
  96. /*
  97. Inside an in-memory data record, memory pointers to pieces of the
  98. record (like BLOBs) are stored in their native byte order and in
  99. this amount of bytes.
  100. */
  101. #define portable_sizeof_char_ptr 8
  102. #ifdef __cplusplus
  103. }
  104. #endif
  105. /**
  106. Return values of index_cond_func_xxx functions.
  107. 0=ICP_NO_MATCH - index tuple doesn't satisfy the pushed index condition (the
  108. engine should discard the tuple and go to the next one)
  109. 1=ICP_MATCH - index tuple satisfies the pushed index condition (the
  110. engine should fetch and return the record)
  111. 2=ICP_OUT_OF_RANGE - index tuple is out range that we're scanning, e.g. this
  112. if we're scanning "t.key BETWEEN 10 AND 20" and got a
  113. "t.key=21" tuple (the engine should stop scanning and
  114. return HA_ERR_END_OF_FILE right away).
  115. 3=ICP_ABORTED_BY_USER - engine must stop scanning and should return
  116. HA_ERR_ABORTED_BY_USER right away
  117. -1= ICP_ERROR - Reserved for internal errors in engines. Should not be
  118. returned by index_cond_func_xxx
  119. */
  120. typedef enum icp_result {
  121. ICP_ERROR=-1,
  122. ICP_NO_MATCH=0,
  123. ICP_MATCH=1,
  124. ICP_OUT_OF_RANGE=2,
  125. ICP_ABORTED_BY_USER=3
  126. } ICP_RESULT;
  127. typedef ICP_RESULT (*index_cond_func_t)(void *param);
  128. #endif /* _my_compare_h */