Skip to content

Commit 47122a6

Browse files
committed
MDEV-33383: Replace fts_doc_id_cmp, ib_vector_sort
fts_doc_ids_sort(): Sort an array of doc_id_t by C++11 std::sort(). fts_doc_id_cmp(), ib_vector_sort(): Remove. The comparison was returning an incorrect result when the difference exceeded the int range. Reviewed by: Thirunarayanan Balathandayuthapani
1 parent 03d1346 commit 47122a6

File tree

8 files changed

+13
-52
lines changed

8 files changed

+13
-52
lines changed

storage/innobase/fts/fts0fts.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3890,6 +3890,13 @@ fts_write_node(
38903890
return(error);
38913891
}
38923892

3893+
/** Sort an array of doc_id */
3894+
void fts_doc_ids_sort(ib_vector_t *doc_ids)
3895+
{
3896+
doc_id_t *const data= reinterpret_cast<doc_id_t*>(doc_ids->data);
3897+
std::sort(data, data + doc_ids->used);
3898+
}
3899+
38933900
/*********************************************************************//**
38943901
Add rows to the DELETED_CACHE table.
38953902
@return DB_SUCCESS if all went well else error code*/
@@ -3911,7 +3918,7 @@ fts_sync_add_deleted_cache(
39113918

39123919
ut_a(ib_vector_size(doc_ids) > 0);
39133920

3914-
ib_vector_sort(doc_ids, fts_doc_id_cmp);
3921+
fts_doc_ids_sort(doc_ids);
39153922

39163923
info = pars_info_create();
39173924

storage/innobase/fts/fts0opt.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,7 @@ fts_table_fetch_doc_ids(
10181018
mutex_exit(&dict_sys.mutex);
10191019

10201020
if (error == DB_SUCCESS) {
1021-
ib_vector_sort(doc_ids->doc_ids, fts_doc_id_cmp);
1021+
fts_doc_ids_sort(doc_ids->doc_ids);
10221022
}
10231023

10241024
if (alloc_bk_trx) {

storage/innobase/fts/fts0que.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4038,7 +4038,7 @@ fts_query(
40384038
DEBUG_SYNC_C("fts_deleted_doc_ids_append");
40394039

40404040
/* Sort the vector so that we can do a binary search over the ids. */
4041-
ib_vector_sort(query.deleted->doc_ids, fts_doc_id_cmp);
4041+
fts_doc_ids_sort(query.deleted->doc_ids);
40424042

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

storage/innobase/include/fts0fts.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,9 @@ inline void fts_doc_ids_free(fts_doc_ids_t* doc_ids)
419419
mem_heap_free(static_cast<mem_heap_t*>(doc_ids->self_heap->arg));
420420
}
421421

422+
/** Sort an array of doc_id */
423+
void fts_doc_ids_sort(ib_vector_t *doc_ids);
424+
422425
/******************************************************************//**
423426
Notify the FTS system about an operation on an FTS-indexed table. */
424427
void

storage/innobase/include/fts0types.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -305,18 +305,6 @@ fts_ranking_doc_id_cmp(
305305
const void*p1,/*!< in: id1 */
306306
const void*p2);/*!< in: id2 */
307307

308-
/******************************************************************//**
309-
Compare two doc_ids. */
310-
UNIV_INLINE
311-
int fts_doc_id_cmp(
312-
/*==================*/
313-
/*!< out:
314-
< 0 if n1 < n2,
315-
0 if n1 == n2,
316-
> 0 if n1 > n2 */
317-
const void*p1,/*!< in: id1 */
318-
const void*p2);/*!< in: id2 */
319-
320308
/******************************************************************//**
321309
Duplicate a string. */
322310
UNIV_INLINE

storage/innobase/include/fts0types.inl

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -78,21 +78,6 @@ fts_ranking_doc_id_cmp(
7878
return((int)(rk1->doc_id - rk2->doc_id));
7979
}
8080

81-
/******************************************************************//**
82-
Compare two doc_ids.
83-
@return < 0 if n1 < n2, 0 if n1 == n2, > 0 if n1 > n2 */
84-
UNIV_INLINE
85-
int fts_doc_id_cmp(
86-
/*==================*/
87-
const void* p1,/*!< in: id1 */
88-
const void* p2)/*!< in: id2 */
89-
{
90-
const doc_id_t* up1 = static_cast<const doc_id_t*>(p1);
91-
const doc_id_t* up2 = static_cast<const doc_id_t*>(p2);
92-
93-
return static_cast<int>(*up1 - *up2);
94-
}
95-
9681
/******************************************************************//**
9782
Get the first character's code position for FTS index partition */
9883
extern

storage/innobase/include/ut0vec.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -200,15 +200,6 @@ ib_vector_last_const(
200200
/* out: pointer to last element */
201201
const ib_vector_t*vec);/* in: vector */
202202

203-
/********************************************************************
204-
Sort the vector elements. */
205-
UNIV_INLINE
206-
void
207-
ib_vector_sort(
208-
/*===========*/
209-
ib_vector_t*vec,/* in/out: vector */
210-
ib_compare_tcompare);/* in: the comparator to use for sort */
211-
212203
/********************************************************************
213204
The default ib_vector_t heap free. Does nothing. */
214205
UNIV_INLINE

storage/innobase/include/ut0vec.inl

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -304,19 +304,6 @@ ib_vector_remove(
304304
return((old_used_count != vec->used) ? current : NULL);
305305
}
306306

307-
/********************************************************************
308-
Sort the vector elements. */
309-
UNIV_INLINE
310-
void
311-
ib_vector_sort(
312-
/*===========*/
313-
/* out: void */
314-
ib_vector_t* vec,/* in: vector */
315-
ib_compare_tcompare)/* in: the comparator to use for sort */
316-
{
317-
qsort(vec->data, vec->used, vec->sizeof_value, compare);
318-
}
319-
320307
/********************************************************************
321308
Destroy the vector. Make sure the vector owns the allocator, e.g.,
322309
the heap in the the heap allocator. */

0 commit comments

Comments
 (0)