1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-27 18:02:13 +03:00

Backport of subquery optimizations to 5.3.

There are still test failures because of:
- Wrong query results in outer join + semi join
- EXPLAIN output differences
This commit is contained in:
Sergey Petrunya
2010-01-17 17:51:10 +03:00
parent 1a490f2da4
commit b83cb52e9e
57 changed files with 30727 additions and 504 deletions

View File

@ -66,3 +66,75 @@ public:
}
};
/*
Array of pointers to Elem that uses memory from MEM_ROOT
MEM_ROOT has no realloc() so this is supposed to be used for cases when
reallocations are rare.
*/
template <class Elem> class Array
{
enum {alloc_increment = 16};
Elem **buffer;
uint n_elements, max_element;
public:
Array(MEM_ROOT *mem_root, uint prealloc=16)
{
buffer= (Elem**)alloc_root(mem_root, prealloc * sizeof(Elem**));
max_element = buffer? prealloc : 0;
n_elements= 0;
}
Elem& at(int idx)
{
return *(((Elem*)buffer) + idx);
}
Elem **front()
{
return buffer;
}
Elem **back()
{
return buffer + n_elements;
}
bool append(MEM_ROOT *mem_root, Elem *el)
{
if (n_elements == max_element)
{
Elem **newbuf;
if (!(newbuf= (Elem**)alloc_root(mem_root, (n_elements + alloc_increment)*
sizeof(Elem**))))
{
return FALSE;
}
memcpy(newbuf, buffer, n_elements*sizeof(Elem*));
buffer= newbuf;
}
buffer[n_elements++]= el;
return FALSE;
}
int elements()
{
return n_elements;
}
void clear()
{
n_elements= 0;
}
typedef int (*CMP_FUNC)(Elem * const *el1, Elem *const *el2);
void sort(CMP_FUNC cmp_func)
{
my_qsort(buffer, n_elements, sizeof(Elem*), (qsort_cmp)cmp_func);
}
};