1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

Fixed LP bug #698882.

Made sure that the optimal fields are used by TABLE_REF objects
when building index access keys to joined tables.
Fixed a bug in the template function that sorts the elements of
a list using the bubble sort algorithm. The bug caused poor
performance of the function. Also added an optimization that
skips comparison with the most heavy elements that has been 
already properly placed in the list.
Made the comparison of the fields belonging to the same Item_equal
more granular: fields belonging to the same table are also ordered
according to some rules.
This commit is contained in:
Igor Babaev
2011-01-15 11:14:36 -08:00
parent cb4fa7f401
commit 84a0c9b2a2
18 changed files with 485 additions and 47 deletions

View File

@ -515,36 +515,40 @@ public:
/*
Exchange sort algorithm for List<T>.
Bubble sort algorithm for List<T>.
This sort function is supposed to be used only for very short list.
Currently it is used for the lists of Item_equal objects and
for some lists in the table elimination algorithms. In both
cases the sorted lists are very short.
*/
template <class T>
inline void exchange_sort(List<T> *list_to_sort,
int (*sort_func)(T *a, T *b, void *arg), void *arg)
inline void bubble_sort(List<T> *list_to_sort,
int (*sort_func)(T *a, T *b, void *arg), void *arg)
{
bool swap;
T **ref1= 0;
T **ref2= 0;
List_iterator<T> it(*list_to_sort);
do
{
T **last_ref= ref1;
T *item1= it++;
T **ref1= it.ref();
ref1= it.ref();
T *item2;
swap= FALSE;
while ((item2= it++))
while ((item2= it++) && (ref2= it.ref()) != last_ref)
{
T **ref2= it.ref();
if (sort_func(item1, item2, arg) < 0)
{
T *item= *ref1;
*ref1= *ref2;
*ref2= item;
*ref1= item2;
*ref2= item1;
swap= TRUE;
}
else
{
item1= item2;
ref1= ref2;
}
ref1= ref2;
}
it.rewind();
} while (swap);