Skip to content

Commit d587cca

Browse files
author
Andrzej Jarzabek
committed
Merge Bug#36210202 from branch 'mysql-8.0' into mysql-8.4
Change-Id: Ied2a322cbd370becc0ec0e77cb782d721db7b00a
2 parents e890b03 + 81a7f6f commit d587cca

File tree

8 files changed

+139
-98
lines changed

8 files changed

+139
-98
lines changed

storage/innobase/fts/fts0fts.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2523,7 +2523,8 @@ static fts_trx_table_t *fts_trx_table_create(
25232523
ftt->table = table;
25242524
ftt->fts_trx = fts_trx;
25252525

2526-
ftt->rows = rbt_create(sizeof(fts_trx_row_t), fts_trx_row_doc_id_cmp);
2526+
ftt->rows =
2527+
rbt_create(sizeof(fts_trx_row_t), fts_doc_id_field_cmp<fts_trx_row_t>);
25272528

25282529
return (ftt);
25292530
}
@@ -2543,7 +2544,8 @@ static fts_trx_table_t *fts_trx_table_clone(
25432544
ftt->table = ftt_src->table;
25442545
ftt->fts_trx = ftt_src->fts_trx;
25452546

2546-
ftt->rows = rbt_create(sizeof(fts_trx_row_t), fts_trx_row_doc_id_cmp);
2547+
ftt->rows =
2548+
rbt_create(sizeof(fts_trx_row_t), fts_doc_id_field_cmp<fts_trx_row_t>);
25472549

25482550
/* Copy the rb tree values to the new savepoint. */
25492551
rbt_merge_uniq(ftt->rows, ftt_src->rows);
@@ -4030,7 +4032,7 @@ dberr_t fts_write_node(trx_t *trx, /*!< in: transaction */
40304032

40314033
ut_a(ib_vector_size(doc_ids) > 0);
40324034

4033-
ib_vector_sort(doc_ids, fts_update_doc_id_cmp);
4035+
ib_vector_sort(doc_ids, fts_doc_id_field_cmp<fts_update_t>);
40344036

40354037
info = pars_info_create();
40364038

storage/innobase/fts/fts0opt.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ dberr_t fts_table_fetch_doc_ids(
10331033
if (error == DB_SUCCESS) {
10341034
fts_sql_commit(trx);
10351035

1036-
ib_vector_sort(doc_ids->doc_ids, fts_update_doc_id_cmp);
1036+
ib_vector_sort(doc_ids->doc_ids, fts_doc_id_field_cmp<fts_update_t>);
10371037
} else {
10381038
fts_sql_rollback(trx);
10391039
}

storage/innobase/fts/fts0que.cc

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,9 @@ struct fts_word_freq_t {
294294
double idf; /*!< Inverse document frequency */
295295
};
296296

297+
static ib_rbt_compare fts_ranking_doc_id_cmp =
298+
fts_doc_id_field_cmp<fts_ranking_t>;
299+
297300
/********************************************************************
298301
Callback function to fetch the rows in an FTS INDEX record.
299302
@return always true */
@@ -382,21 +385,7 @@ fts_query_terms_in_document(
382385
fts_query_t* query, /*!< in: FTS query state */
383386
doc_id_t doc_id, /*!< in: the word to check */
384387
ulint* total); /*!< out: total words in document */
385-
#endif
386-
387-
/********************************************************************
388-
Compare two fts_doc_freq_t doc_ids.
389-
@return < 0 if n1 < n2, 0 if n1 == n2, > 0 if n1 > n2 */
390-
static inline int fts_freq_doc_id_cmp(const void *p1, /*!< in: id1 */
391-
const void *p2) /*!< in: id2 */
392-
{
393-
const fts_doc_freq_t *fq1 = (const fts_doc_freq_t *)p1;
394-
const fts_doc_freq_t *fq2 = (const fts_doc_freq_t *)p2;
395-
396-
return ((int)(fq1->doc_id - fq2->doc_id));
397-
}
398388

399-
#if 0
400389
/*******************************************************************//**
401390
Print the table used for calculating LCS. */
402391
static
@@ -645,8 +634,8 @@ static fts_word_freq_t *fts_query_add_word_freq(
645634

646635
word_freq.doc_count = 0;
647636

648-
word_freq.doc_freqs =
649-
rbt_create(sizeof(fts_doc_freq_t), fts_freq_doc_id_cmp);
637+
word_freq.doc_freqs = rbt_create(sizeof(fts_doc_freq_t),
638+
fts_doc_id_field_cmp<fts_doc_freq_t>);
650639

651640
parent.last = rbt_add_node(query->word_freqs, &parent, &word_freq);
652641

@@ -3707,7 +3696,7 @@ dberr_t fts_query(trx_t *trx, dict_index_t *index, uint flags,
37073696
DEBUG_SYNC_C("fts_deleted_doc_ids_append");
37083697

37093698
/* Sort the vector so that we can do a binary search over the ids. */
3710-
ib_vector_sort(query.deleted->doc_ids, fts_update_doc_id_cmp);
3699+
ib_vector_sort(query.deleted->doc_ids, fts_doc_id_field_cmp<fts_update_t>);
37113700

37123701
/* Convert the query string to lower case before parsing. We own
37133702
the ut_malloc'ed result and so remember to free it before return. */

storage/innobase/include/fts0types.h

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -311,26 +311,8 @@ extern const fts_index_selector_t fts_index_selector[];
311311
/** It's defined in fts/fts0fts.c */
312312
extern const fts_index_selector_t fts_index_selector_5_7[];
313313

314-
/** Compare two fts_trx_row_t instances doc_ids.
315-
@param[in] p1 id1
316-
@param[in] p2 id2
317-
@return < 0 if n1 < n2, < 0 if n1 < n2, > 0 if n1 > n2 */
318-
static inline int fts_trx_row_doc_id_cmp(const void *p1, const void *p2);
319-
320-
/** Compare two fts_ranking_t instances doc_ids.
321-
@param[in] p1 id1
322-
@param[in] p2 id2
323-
@return < 0 if n1 < n2, < 0 if n1 < n2, > 0 if n1 > n2 */
324-
static inline int fts_ranking_doc_id_cmp(const void *p1, const void *p2);
325-
326-
/** Compare two fts_update_t instances doc_ids.
327-
@param[in] p1 id1
328-
@param[in] p2 id2
329-
@return < 0 if n1 < n2, < 0 if n1 < n2, > 0 if n1 > n2 */
330-
static inline int fts_update_doc_id_cmp(const void *p1, const void *p2);
331-
332314
/** Decode and return the integer that was encoded using our VLC scheme.*/
333-
static inline ulint fts_decode_vlc(
315+
inline ulint fts_decode_vlc(
334316
/*!< out: value decoded */
335317
byte **ptr); /*!< in: ptr to decode from, this ptr is
336318
incremented by the number of bytes decoded */
@@ -340,11 +322,11 @@ static inline ulint fts_decode_vlc(
340322
@param[in] src src string
341323
@param[in] heap heap to use
342324
*/
343-
static inline void fts_string_dup(fts_string_t *dst, const fts_string_t *src,
344-
mem_heap_t *heap);
325+
inline void fts_string_dup(fts_string_t *dst, const fts_string_t *src,
326+
mem_heap_t *heap);
345327

346328
/** Return length of val if it were encoded using our VLC scheme. */
347-
static inline ulint fts_get_encoded_len(
329+
inline ulint fts_get_encoded_len(
348330
/*!< out: length of value
349331
encoded, in bytes */
350332
ulint val); /*!< in: value to encode */
@@ -353,24 +335,23 @@ static inline ulint fts_get_encoded_len(
353335
@param[in] val value to encode
354336
@param[in] buf buffer, must have enough space
355337
@return length of value encoded, in bytes */
356-
static inline ulint fts_encode_int(ulint val, byte *buf);
338+
inline ulint fts_encode_int(ulint val, byte *buf);
357339

358340
/** Get the selected FTS aux INDEX suffix. */
359-
static inline const char *fts_get_suffix(
360-
ulint selected); /*!< in: selected index */
341+
inline const char *fts_get_suffix(ulint selected); /*!< in: selected index */
361342

362343
/** Return the selected FTS aux index suffix in 5.7 compatible format
363344
@param[in] selected selected index
364345
@return the suffix name */
365-
static inline const char *fts_get_suffix_5_7(ulint selected);
346+
inline const char *fts_get_suffix_5_7(ulint selected);
366347

367-
/** Select the FTS auxiliary index for the given character.
348+
/** Select the FTS auxiliary table for the given character.
368349
@param[in] cs charset
369350
@param[in] str string
370351
@param[in] len string length in bytes
371-
@return the index to use for the string */
372-
static inline ulint fts_select_index(const CHARSET_INFO *cs, const byte *str,
373-
ulint len);
352+
@retval the auxiliary table number to use for the string, zero-based */
353+
inline ulint fts_select_index(const CHARSET_INFO *cs, const byte *str,
354+
ulint len);
374355

375356
#include "fts0types.ic"
376357
#include "fts0vlc.ic"

storage/innobase/include/fts0types.ic

Lines changed: 33 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,9 @@ this program; if not, write to the Free Software Foundation, Inc.,
3838
#include "rem0cmp.h"
3939

4040
/** Duplicate a string. */
41-
static inline void fts_string_dup(
42-
fts_string_t *dst, /*!< in: dup to here */
43-
const fts_string_t *src, /*!< in: src string */
44-
mem_heap_t *heap) /*!< in: heap to use */
41+
inline void fts_string_dup(fts_string_t *dst, /*!< in: dup to here */
42+
const fts_string_t *src, /*!< in: src string */
43+
mem_heap_t *heap) /*!< in: heap to use */
4544
{
4645
dst->f_str = (byte *)mem_heap_alloc(heap, src->f_len + 1);
4746
memcpy(dst->f_str, src->f_str, src->f_len);
@@ -51,37 +50,30 @@ static inline void fts_string_dup(
5150
dst->f_n_char = src->f_n_char;
5251
}
5352

54-
/** Compare two fts_trx_row_t doc_ids.
55-
@return < 0 if n1 < n2, 0 if n1 == n2, > 0 if n1 > n2 */
56-
static inline int fts_trx_row_doc_id_cmp(const void *p1, /*!< in: id1 */
57-
const void *p2) /*!< in: id2 */
58-
{
59-
const fts_trx_row_t *tr1 = (const fts_trx_row_t *)p1;
60-
const fts_trx_row_t *tr2 = (const fts_trx_row_t *)p2;
61-
62-
return ((int)(tr1->doc_id - tr2->doc_id));
63-
}
64-
65-
/** Compare two fts_ranking_t doc_ids.
66-
@return < 0 if n1 < n2, 0 if n1 == n2, > 0 if n1 > n2 */
67-
static inline int fts_ranking_doc_id_cmp(const void *p1, /*!< in: id1 */
68-
const void *p2) /*!< in: id2 */
69-
{
70-
const fts_ranking_t *rk1 = (const fts_ranking_t *)p1;
71-
const fts_ranking_t *rk2 = (const fts_ranking_t *)p2;
72-
73-
return ((int)(rk1->doc_id - rk2->doc_id));
53+
/** Compare two doc_ids.
54+
@param[in] id1 1st doc_id to compare
55+
@param[in] id2 2nd doc_id to compare
56+
@return < 0 if id1 < id2, 0 if id1 == id2, > 0 if id1 > id2 */
57+
inline int fts_doc_id_cmp(doc_id_t id1, doc_id_t id2) {
58+
if (id1 < id2) {
59+
return -1;
60+
} else if (id1 > id2) {
61+
return 1;
62+
} else {
63+
return 0;
64+
}
7465
}
7566

76-
/** Compare two fts_update_t doc_ids.
77-
@return < 0 if n1 < n2, 0 if n1 == n2, > 0 if n1 > n2 */
78-
static inline int fts_update_doc_id_cmp(const void *p1, /*!< in: id1 */
79-
const void *p2) /*!< in: id2 */
80-
{
81-
const fts_update_t *up1 = (const fts_update_t *)p1;
82-
const fts_update_t *up2 = (const fts_update_t *)p2;
67+
/** Compare doc_ids of 2 objects.
68+
@param[in] p1 Pointer to first instance o1 of T
69+
@param[in] p2 Pointer to second instance o2 of T
70+
@return sign(o1->doc_id - o2->doc_id) */
71+
template <typename T>
72+
int fts_doc_id_field_cmp(const void *p1, const void *p2) {
73+
const T *o1 = static_cast<const T *>(p1);
74+
const T *o2 = static_cast<const T *>(p2);
8375

84-
return ((int)(up1->doc_id - up2->doc_id));
76+
return fts_doc_id_cmp(o1->doc_id, o2->doc_id);
8577
}
8678

8779
/** Get the first character's code position for FTS index partition
@@ -96,7 +88,7 @@ extern ulint innobase_strnxfrm(const CHARSET_INFO *cs, const uchar *p2,
9688
@param[in] cs charset
9789
@retval true if the charset is cjk
9890
@retval false if not. */
99-
static inline bool fts_is_charset_cjk(const CHARSET_INFO *cs) {
91+
inline bool fts_is_charset_cjk(const CHARSET_INFO *cs) {
10092
if (strcmp(cs->m_coll_name, "gb2312_chinese_ci") == 0 ||
10193
strcmp(cs->m_coll_name, "gbk_chinese_ci") == 0 ||
10294
strcmp(cs->m_coll_name, "big5_chinese_ci") == 0 ||
@@ -117,8 +109,8 @@ static inline bool fts_is_charset_cjk(const CHARSET_INFO *cs) {
117109
@param[in] str string
118110
@param[in] len string length
119111
@retval the index to use for the string */
120-
static inline ulint fts_select_index_by_range(const CHARSET_INFO *cs,
121-
const byte *str, ulint len) {
112+
inline ulint fts_select_index_by_range(const CHARSET_INFO *cs, const byte *str,
113+
ulint len) {
122114
ulint selected = 0;
123115
ulint value = innobase_strnxfrm(cs, str, len);
124116

@@ -143,8 +135,8 @@ static inline ulint fts_select_index_by_range(const CHARSET_INFO *cs,
143135
@param[in] str string
144136
@param[in] len string length
145137
@retval the index to use for the string */
146-
static inline ulint fts_select_index_by_hash(const CHARSET_INFO *cs,
147-
const byte *str, ulint len) {
138+
inline ulint fts_select_index_by_hash(const CHARSET_INFO *cs, const byte *str,
139+
ulint len) {
148140
int char_len;
149141

150142
ut_ad(!(str == nullptr && len > 0));
@@ -175,8 +167,8 @@ static inline ulint fts_select_index_by_hash(const CHARSET_INFO *cs,
175167
@param[in] str string
176168
@param[in] len string length in bytes
177169
@retval the auxiliary table number to use for the string, zero-based */
178-
static inline ulint fts_select_index(const CHARSET_INFO *cs, const byte *str,
179-
ulint len) {
170+
inline ulint fts_select_index(const CHARSET_INFO *cs, const byte *str,
171+
ulint len) {
180172
/* Words which compare equal using the character set's collation (have
181173
the same sort order) MUST go into the same auxiliary table.
182174
This is necessary as selecting a word using the equality operator will
@@ -199,16 +191,15 @@ static inline ulint fts_select_index(const CHARSET_INFO *cs, const byte *str,
199191
}
200192

201193
/** Return the selected FTS aux index suffix. */
202-
static inline const char *fts_get_suffix(
203-
ulint selected) /*!< in: selected index */
194+
inline const char *fts_get_suffix(ulint selected) /*!< in: selected index */
204195
{
205196
return (fts_index_selector[selected].suffix);
206197
}
207198

208199
/** Return the selected FTS aux index suffix in 5.7 compatible format
209200
@param[in] selected selected index
210201
@return the suffix name */
211-
static inline const char *fts_get_suffix_5_7(ulint selected) {
202+
inline const char *fts_get_suffix_5_7(ulint selected) {
212203
return (fts_index_selector_5_7[selected].suffix);
213204
}
214205

storage/innobase/include/fts0vlc.ic

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ this program; if not, write to the Free Software Foundation, Inc.,
3939
/** Return length of val if it were encoded using our VLC scheme.
4040
FIXME: We will need to be able encode 8 bytes value
4141
@return length of value encoded, in bytes */
42-
static inline ulint fts_get_encoded_len(ulint val) /* in: value to encode */
42+
inline ulint fts_get_encoded_len(ulint val) /* in: value to encode */
4343
{
4444
if (val <= 127) {
4545
return (1);
@@ -61,9 +61,8 @@ static inline ulint fts_get_encoded_len(ulint val) /* in: value to encode */
6161

6262
/** Encode an integer using our VLC scheme and return the length in bytes.
6363
@return length of value encoded, in bytes */
64-
static inline ulint fts_encode_int(
65-
ulint val, /* in: value to encode */
66-
byte *buf) /* in: buffer, must have enough space */
64+
inline ulint fts_encode_int(ulint val, /* in: value to encode */
65+
byte *buf) /* in: buffer, must have enough space */
6766
{
6867
ulint len;
6968

@@ -111,7 +110,7 @@ static inline ulint fts_encode_int(
111110

112111
/** Decode and return the integer that was encoded using our VLC scheme.
113112
@return value decoded */
114-
static inline ulint fts_decode_vlc(
113+
inline ulint fts_decode_vlc(
115114
byte **ptr) /* in: ptr to decode from, this ptr is
116115
incremented by the number of bytes decoded */
117116
{

unittest/gunit/innodb/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ SET(TESTS
5151
ut0mem
5252
ut0new
5353
ut0rnd
54+
ut0rbt
5455
)
5556

5657
ADD_COMPILE_FLAGS(

0 commit comments

Comments
 (0)