diff --git a/sql/filesort.cc b/sql/filesort.cc index 4fbc2a64b5b..b4f5b03692b 100644 --- a/sql/filesort.cc +++ b/sql/filesort.cc @@ -52,7 +52,7 @@ private: uchar **m_sort_keys; size_t m_compare_length; Sort_param *m_sort_param; - Queue m_queue; + Queue m_queue; }; @@ -68,7 +68,7 @@ int Bounded_queue::init(ha_rows max_elements, size_t cmplen, if (max_elements >= UINT_MAX - 1) return 1; // We allocate space for one extra element, for replace when queue is full. - return m_queue.init((uint)max_elements + 1, 0, true, + return m_queue.init((uint)max_elements + 1, true, (decltype(m_queue)::Queue_compare)get_ptr_compare(cmplen), &m_compare_length); } diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index 501ff7892fa..f8bea817b46 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -6654,7 +6654,7 @@ subselect_rowid_merge_engine::init(MY_BITMAP *non_null_key_parts, if (merge_keys[i]->sort_keys()) return TRUE; - if (pq.init(merge_keys_count, 0, false, + if (pq.init(merge_keys_count, false, subselect_rowid_merge_engine::cmp_keys_by_cur_rownum)) return TRUE; @@ -6713,8 +6713,9 @@ subselect_rowid_merge_engine::cmp_keys_by_null_selectivity(Ordered_key **k1, */ int -subselect_rowid_merge_engine::cmp_keys_by_cur_rownum(void *, Ordered_key *k1, - Ordered_key *k2) +subselect_rowid_merge_engine::cmp_keys_by_cur_rownum(void *, + const Ordered_key *k1, + const Ordered_key *k2) { rownum_t r1= k1->current(); rownum_t r2= k2->current(); diff --git a/sql/item_subselect.h b/sql/item_subselect.h index b8fd530c73c..0c1a509a30f 100644 --- a/sql/item_subselect.h +++ b/sql/item_subselect.h @@ -1368,7 +1368,7 @@ public: return FALSE; }; /* Return the current index element. */ - rownum_t current() + rownum_t current() const { DBUG_ASSERT(key_buff_elements && cur_key_idx < key_buff_elements); return key_buff[cur_key_idx]; @@ -1507,7 +1507,7 @@ protected: Priority queue of Ordered_key indexes, one per NULLable column. This queue is used by the partial match algorithm in method exec(). */ - Queue pq; + Queue pq; protected: /* Comparison function to compare keys in order of decreasing bitmap @@ -1518,7 +1518,9 @@ protected: Comparison function used by the priority queue pq, the 'smaller' key is the one with the smaller current row number. */ - static int cmp_keys_by_cur_rownum(void *arg, Ordered_key *k1, Ordered_key *k2); + static int cmp_keys_by_cur_rownum(void *arg, + const Ordered_key *k1, + const Ordered_key *k2); bool test_null_row(rownum_t row_num); bool exists_complementing_null_row(MY_BITMAP *keys_to_complement); diff --git a/sql/sql_hset.h b/sql/sql_hset.h index 80e45b160a9..9893726a7a3 100644 --- a/sql/sql_hset.h +++ b/sql/sql_hset.h @@ -62,18 +62,28 @@ public: @retval FALSE OK. The value either was inserted or existed in the hash. */ - bool insert(T *value) + bool insert(const T *value) { return my_hash_insert(&m_hash, reinterpret_cast(value)); } - bool remove(T *value) + bool remove(const T *value) { - return my_hash_delete(&m_hash, reinterpret_cast(value)); + return my_hash_delete(&m_hash, + reinterpret_cast(const_cast(value))); } T *find(const void *key, size_t klen) const { return (T*)my_hash_search(&m_hash, reinterpret_cast(key), klen); } + + T *find(const T *other) const + { + DBUG_ASSERT(m_hash.get_key); + size_t klen; + uchar *key= m_hash.get_key(reinterpret_cast(other), + &klen, false); + return find(key, klen); + } /** Is this hash set empty? */ bool is_empty() const { return m_hash.records == 0; } /** Returns the number of unique elements. */ diff --git a/sql/sql_list.h b/sql/sql_list.h index 048624e6a22..bcffdfeabff 100644 --- a/sql/sql_list.h +++ b/sql/sql_list.h @@ -496,8 +496,8 @@ public: inline List() :base_list() {} inline List(const List &tmp, MEM_ROOT *mem_root) : base_list(tmp, mem_root) {} - inline bool push_back(T *a) { return base_list::push_back(a); } - inline bool push_back(T *a, MEM_ROOT *mem_root) + inline bool push_back(const T *a) { return base_list::push_back((void *)a); } + inline bool push_back(const T *a, MEM_ROOT *mem_root) { return base_list::push_back((void*) a, mem_root); } inline bool push_front(const T *a) { return base_list::push_front(a); } inline bool push_front(const T *a, MEM_ROOT *mem_root) diff --git a/sql/sql_queue.h b/sql/sql_queue.h index 9bba089bac4..d7d16ea26fe 100644 --- a/sql/sql_queue.h +++ b/sql/sql_queue.h @@ -16,24 +16,25 @@ #ifndef QUEUE_INCLUDED #define QUEUE_INCLUDED +#include #include "queues.h" /** A typesafe wrapper of QUEUE, a priority heap */ -template +template class Queue { public: - typedef int (*Queue_compare)(Param *, Key *, Key *); + typedef int (*Queue_compare)(Param *, const Element *, const Element *); Queue() { m_queue.root= 0; } ~Queue() { delete_queue(&m_queue); } - int init(uint max_elements, uint offset_to_key, bool max_at_top, - Queue_compare compare, Param *param= 0) + int init(uint max_elements, bool max_at_top, Queue_compare compare, + Param *param= 0) { - return init_queue(&m_queue, max_elements, offset_to_key, max_at_top, - (queue_compare)compare, param, 0, 0); + return init_queue(&m_queue, max_elements, 0, max_at_top, + (queue_compare)compare, (void *)param, 0, 0); } size_t elements() const { return m_queue.elements; } @@ -42,11 +43,11 @@ public: bool is_empty() const { return elements() == 0; } Element *top() const { return (Element*)queue_top(&m_queue); } - void push(Element *element) { queue_insert(&m_queue, (uchar*)element); } + void push(const Element *element) { queue_insert(&m_queue, (uchar*)element); } Element *pop() { return (Element *)queue_remove_top(&m_queue); } void clear() { queue_remove_all(&m_queue); } void propagate_top() { queue_replace_top(&m_queue); } - void replace_top(Element *element) + void replace_top(const Element *element) { queue_top(&m_queue)= (uchar*)element; propagate_top(); diff --git a/sql/vector_mhnsw.cc b/sql/vector_mhnsw.cc index 4efec9d8bc9..9fe5378f177 100644 --- a/sql/vector_mhnsw.cc +++ b/sql/vector_mhnsw.cc @@ -78,21 +78,21 @@ int mhnsw_insert(TABLE *table, KEY *keyinfo) return err == HA_ERR_END_OF_FILE ? 0 : err; } -static int cmp_float(void *, float *a, float *b) -{ - return *a < *b ? -1 : *a == *b ? 0 : 1; -} - struct Node { float distance; uchar ref[1000]; }; +static int cmp_float(void *, const Node *a, const Node *b) +{ + return a->distance < b->distance ? -1 : a->distance == b->distance ? 0 : 1; +} + int mhnsw_read_first(TABLE *table, Item *dist, ulonglong limit) { TABLE *graph= table->hlindex; - Queue todo, result; + Queue todo, result; Node *cur; String *str, strbuf; const size_t ref_length= table->file->ref_length; @@ -105,10 +105,10 @@ int mhnsw_read_first(TABLE *table, Item *dist, ulonglong limit) DBUG_ASSERT(graph); - if (todo.init(1000, 0, 0, cmp_float)) // XXX + autoextent + if (todo.init(1000, 0, cmp_float)) // XXX + autoextent return HA_ERR_OUT_OF_MEM; - if (result.init(limit, 0, 1, cmp_float)) + if (result.init(limit, 1, cmp_float)) return HA_ERR_OUT_OF_MEM; if ((err= graph->file->ha_index_init(0, 1)))