MySQL  8.0.21
Source Code Documentation
my_compare.h
Go to the documentation of this file.
1 /* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
2 
3  This program is free software; you can redistribute it and/or modify
4  it under the terms of the GNU General Public License, version 2.0,
5  as published by the Free Software Foundation.
6 
7  This program is also distributed with certain software (including
8  but not limited to OpenSSL) that is licensed under separate terms,
9  as designated in a particular file or component or in included license
10  documentation. The authors of MySQL hereby grant you an additional
11  permission to link the program and your derivative works with the
12  separately licensed software that they have included with MySQL.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License, version 2.0, for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22 
23 #ifndef _my_compare_h
24 #define _my_compare_h
25 
26 /**
27  @file include/my_compare.h
28 */
29 
30 #include <sys/types.h>
31 
32 #include "m_ctype.h" /* CHARSET_INFO */
33 #include "my_inttypes.h"
34 #include "myisampack.h"
35 
36 /*
37  There is a hard limit for the maximum number of keys as there are only
38  8 bits in the index file header for the number of keys in a table.
39  This means that 0..255 keys can exist for a table. The idea of
40  HA_MAX_POSSIBLE_KEY is to ensure that one can use myisamchk & tools on
41  a MyISAM table for which one has more keys than MyISAM is normally
42  compiled for. If you don't have this, you will get a core dump when
43  running myisamchk compiled for 128 keys on a table with 255 keys.
44 */
45 
46 #define HA_MAX_POSSIBLE_KEY 255 /* For myisamchk */
47 /*
48  The following defines can be increased if necessary.
49  But beware the dependency of MI_MAX_POSSIBLE_KEY_BUFF and HA_MAX_KEY_LENGTH.
50 */
51 
52 #define HA_MAX_KEY_LENGTH 1000 /* Max length in bytes */
53 #define HA_MAX_KEY_SEG 16 /* Max segments for key */
54 
55 #define HA_MAX_POSSIBLE_KEY_BUFF (HA_MAX_KEY_LENGTH + 24 + 6 + 6)
56 #define HA_MAX_KEY_BUFF (HA_MAX_KEY_LENGTH + HA_MAX_KEY_SEG * 6 + 8 + 8)
57 
58 struct HA_KEYSEG /* Key-portion */
59 {
61  uint32 start; /* Start of key in record */
62  uint32 null_pos; /* position to NULL indicator */
63  uint16 bit_pos; /* Position to bit part */
65  uint16 length; /* Keylength */
67  uint8 type; /* Type of key (for sort) */
68  uint8 null_bit; /* bitmask to test for NULL */
69  uint8 bit_start, bit_end; /* if bit field */
70  uint8 bit_length; /* Length of bit part */
71 };
72 
73 static inline uint get_key_length(const uchar **key) {
74  if (**key != 255) return *(*key)++;
75  uint length = mi_uint2korr((*key) + 1);
76  (*key) += 3;
77  return length;
78 }
79 
80 static inline uint get_key_pack_length(const uchar **key, uint *length_pack) {
81  *length_pack = (**key != 255) ? 1 : 3;
82  return get_key_length(key);
83 }
84 
85 #define store_key_length_inc(key, length) \
86  { \
87  if ((length) < 255) { \
88  *(key)++ = (length); \
89  } else { \
90  *(key) = 255; \
91  mi_int2store((key) + 1, (length)); \
92  (key) += 3; \
93  } \
94  }
95 
96 #define size_to_store_key_length(length) ((length) < 255 ? 1 : 3)
97 
98 #define get_rec_bits(bit_ptr, bit_ofs, bit_len) \
99  (((((uint16)(bit_ptr)[1] << 8) | (uint16)(bit_ptr)[0]) >> (bit_ofs)) & \
100  ((1 << (bit_len)) - 1))
101 
102 #define set_rec_bits(bits, bit_ptr, bit_ofs, bit_len) \
103  { \
104  (bit_ptr)[0] = ((bit_ptr)[0] & ~(((1 << (bit_len)) - 1) << (bit_ofs))) | \
105  ((bits) << (bit_ofs)); \
106  if ((bit_ofs) + (bit_len) > 8) \
107  (bit_ptr)[1] = \
108  ((bit_ptr)[1] & ~((1 << ((bit_len)-8 + (bit_ofs))) - 1)) | \
109  ((bits) >> (8 - (bit_ofs))); \
110  }
111 
112 #define clr_rec_bits(bit_ptr, bit_ofs, bit_len) \
113  set_rec_bits(0, bit_ptr, bit_ofs, bit_len)
114 
115 extern int ha_compare_text(const CHARSET_INFO *, const uchar *, uint,
116  const uchar *, uint, bool);
117 extern int ha_key_cmp(const HA_KEYSEG *keyseg, const uchar *a, const uchar *b,
118  uint key_length, uint nextflag, uint *diff_pos);
119 
120 /**
121  Compare two numbers of the same type.
122  @param val1 the first number
123  @param val2 the second number
124  @retval -1 if val1 is less than val2,
125  @retval 0 if val1 is equal to val2,
126  @retval 1 if val1 is greater than val2
127 */
128 template <class T>
129 int compare_numbers(T val1, T val2) {
130  return val1 < val2 ? -1 : (val1 == val2 ? 0 : 1);
131 }
132 
133 #endif /* _my_compare_h */
uint32 start
Definition: my_compare.h:61
unsigned char uchar
Definition: my_inttypes.h:51
uint8 bit_end
Definition: my_compare.h:69
Storing of values in high byte first order.
uint8 bit_start
Definition: my_compare.h:69
uint16 bit_pos
Definition: my_compare.h:63
Some integer typedefs for easier portability.
const CHARSET_INFO * charset
Definition: my_compare.h:60
static uint get_key_pack_length(const uchar **key, uint *length_pack)
Definition: my_compare.h:80
uint32 null_pos
Definition: my_compare.h:62
static HA_KEYSEG keyseg[10]
Definition: mi_test1.cc:47
uint16 length
Definition: my_compare.h:65
int ha_compare_text(const CHARSET_INFO *, const uchar *, uint, const uchar *, uint, bool)
Definition: my_compare.cc:45
uint8 null_bit
Definition: my_compare.h:68
uint16 flag
Definition: my_compare.h:64
uint16_t uint16
Definition: my_inttypes.h:64
unsigned int uint
Definition: uca-dump.cc:29
int compare_numbers(T val1, T val2)
Compare two numbers of the same type.
Definition: my_compare.h:129
int ha_key_cmp(const HA_KEYSEG *keyseg, const uchar *a, const uchar *b, uint key_length, uint nextflag, uint *diff_pos)
Definition: my_compare.cc:130
uint32_t uint32
Definition: my_inttypes.h:66
Definition: m_ctype.h:359
uint8_t uint8
Definition: my_inttypes.h:62
uint16 language
Definition: my_compare.h:66
static const char * key
Definition: suite_stubs.c:14
static uint16 mi_uint2korr(const uchar *A)
Definition: myisampack.h:62
uint8 bit_length
Definition: my_compare.h:70
uint8 type
Definition: my_compare.h:67
A better implementation of the UNIX ctype(3) library.
static uint get_key_length(const uchar **key)
Definition: my_compare.h:73
Definition: my_compare.h:58
static uint key_length
Definition: mi_test1.cc:42