mirror of
https://github.com/MariaDB/server.git
synced 2025-07-27 18:02:13 +03:00
MDEV-415: Back-port of the WL task #1393 from the mysql-5.6 code line.
The task adds a more efficient handling of the queries with ORDER BY order LIMIT n, such that n is small enough and no indexes are used for order.
This commit is contained in:
@ -19,6 +19,77 @@
|
||||
|
||||
#include <my_sys.h>
|
||||
|
||||
/**
|
||||
A wrapper class which provides array bounds checking.
|
||||
We do *not* own the array, we simply have a pointer to the first element,
|
||||
and a length.
|
||||
|
||||
@remark
|
||||
We want the compiler-generated versions of:
|
||||
- the copy CTOR (memberwise initialization)
|
||||
- the assignment operator (memberwise assignment)
|
||||
|
||||
@param Element_type The type of the elements of the container.
|
||||
*/
|
||||
template <typename Element_type> class Bounds_checked_array
|
||||
{
|
||||
public:
|
||||
Bounds_checked_array() : m_array(NULL), m_size(0) {}
|
||||
|
||||
Bounds_checked_array(Element_type *el, size_t size)
|
||||
: m_array(el), m_size(size)
|
||||
{}
|
||||
|
||||
void reset() { m_array= NULL; m_size= 0; }
|
||||
|
||||
void reset(Element_type *array, size_t size)
|
||||
{
|
||||
m_array= array;
|
||||
m_size= size;
|
||||
}
|
||||
|
||||
/**
|
||||
Set a new bound on the array. Does not resize the underlying
|
||||
array, so the new size must be smaller than or equal to the
|
||||
current size.
|
||||
*/
|
||||
void resize(size_t new_size)
|
||||
{
|
||||
DBUG_ASSERT(new_size <= m_size);
|
||||
m_size= new_size;
|
||||
}
|
||||
|
||||
Element_type &operator[](size_t n)
|
||||
{
|
||||
DBUG_ASSERT(n < m_size);
|
||||
return m_array[n];
|
||||
}
|
||||
|
||||
const Element_type &operator[](size_t n) const
|
||||
{
|
||||
DBUG_ASSERT(n < m_size);
|
||||
return m_array[n];
|
||||
}
|
||||
|
||||
size_t element_size() const { return sizeof(Element_type); }
|
||||
size_t size() const { return m_size; }
|
||||
|
||||
bool is_null() const { return m_array == NULL; }
|
||||
|
||||
void pop_front()
|
||||
{
|
||||
DBUG_ASSERT(m_size > 0);
|
||||
m_array+= 1;
|
||||
m_size-= 1;
|
||||
}
|
||||
|
||||
Element_type *array() const { return m_array; }
|
||||
|
||||
private:
|
||||
Element_type *m_array;
|
||||
size_t m_size;
|
||||
};
|
||||
|
||||
/*
|
||||
A typesafe wrapper around DYNAMIC_ARRAY
|
||||
*/
|
||||
|
Reference in New Issue
Block a user