Commit 47122a61 authored by Marko Mäkelä's avatar Marko Mäkelä

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
parent 03d1346e
......@@ -3890,6 +3890,13 @@ fts_write_node(
return(error);
}
/** Sort an array of doc_id */
void fts_doc_ids_sort(ib_vector_t *doc_ids)
{
doc_id_t *const data= reinterpret_cast<doc_id_t*>(doc_ids->data);
std::sort(data, data + doc_ids->used);
}
/*********************************************************************//**
Add rows to the DELETED_CACHE table.
@return DB_SUCCESS if all went well else error code*/
......@@ -3911,7 +3918,7 @@ fts_sync_add_deleted_cache(
ut_a(ib_vector_size(doc_ids) > 0);
ib_vector_sort(doc_ids, fts_doc_id_cmp);
fts_doc_ids_sort(doc_ids);
info = pars_info_create();
......
......@@ -1018,7 +1018,7 @@ fts_table_fetch_doc_ids(
mutex_exit(&dict_sys.mutex);
if (error == DB_SUCCESS) {
ib_vector_sort(doc_ids->doc_ids, fts_doc_id_cmp);
fts_doc_ids_sort(doc_ids->doc_ids);
}
if (alloc_bk_trx) {
......
......@@ -4038,7 +4038,7 @@ fts_query(
DEBUG_SYNC_C("fts_deleted_doc_ids_append");
/* Sort the vector so that we can do a binary search over the ids. */
ib_vector_sort(query.deleted->doc_ids, fts_doc_id_cmp);
fts_doc_ids_sort(query.deleted->doc_ids);
/* Convert the query string to lower case before parsing. We own
the ut_malloc'ed result and so remember to free it before return. */
......
......@@ -419,6 +419,9 @@ inline void fts_doc_ids_free(fts_doc_ids_t* doc_ids)
mem_heap_free(static_cast<mem_heap_t*>(doc_ids->self_heap->arg));
}
/** Sort an array of doc_id */
void fts_doc_ids_sort(ib_vector_t *doc_ids);
/******************************************************************//**
Notify the FTS system about an operation on an FTS-indexed table. */
void
......
......@@ -305,18 +305,6 @@ fts_ranking_doc_id_cmp(
const void* p1, /*!< in: id1 */
const void* p2); /*!< in: id2 */
/******************************************************************//**
Compare two doc_ids. */
UNIV_INLINE
int fts_doc_id_cmp(
/*==================*/
/*!< out:
< 0 if n1 < n2,
0 if n1 == n2,
> 0 if n1 > n2 */
const void* p1, /*!< in: id1 */
const void* p2); /*!< in: id2 */
/******************************************************************//**
Duplicate a string. */
UNIV_INLINE
......
......@@ -78,21 +78,6 @@ fts_ranking_doc_id_cmp(
return((int)(rk1->doc_id - rk2->doc_id));
}
/******************************************************************//**
Compare two doc_ids.
@return < 0 if n1 < n2, 0 if n1 == n2, > 0 if n1 > n2 */
UNIV_INLINE
int fts_doc_id_cmp(
/*==================*/
const void* p1, /*!< in: id1 */
const void* p2) /*!< in: id2 */
{
const doc_id_t* up1 = static_cast<const doc_id_t*>(p1);
const doc_id_t* up2 = static_cast<const doc_id_t*>(p2);
return static_cast<int>(*up1 - *up2);
}
/******************************************************************//**
Get the first character's code position for FTS index partition */
extern
......
......@@ -200,15 +200,6 @@ ib_vector_last_const(
/* out: pointer to last element */
const ib_vector_t* vec); /* in: vector */
/********************************************************************
Sort the vector elements. */
UNIV_INLINE
void
ib_vector_sort(
/*===========*/
ib_vector_t* vec, /* in/out: vector */
ib_compare_t compare); /* in: the comparator to use for sort */
/********************************************************************
The default ib_vector_t heap free. Does nothing. */
UNIV_INLINE
......
......@@ -304,19 +304,6 @@ ib_vector_remove(
return((old_used_count != vec->used) ? current : NULL);
}
/********************************************************************
Sort the vector elements. */
UNIV_INLINE
void
ib_vector_sort(
/*===========*/
/* out: void */
ib_vector_t* vec, /* in: vector */
ib_compare_t compare)/* in: the comparator to use for sort */
{
qsort(vec->data, vec->used, vec->sizeof_value, compare);
}
/********************************************************************
Destroy the vector. Make sure the vector owns the allocator, e.g.,
the heap in the the heap allocator. */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment