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