Commit 6d1f3e8d authored by kaa@polly.(none)'s avatar kaa@polly.(none)
Browse files

Fix for bug #31207: Test "join_nested" shows different strategy on IA64

CPUs / Intel's ICC compile

The bug is a combination of two problems:

1. IA64/ICC MySQL binaries use glibc's qsort(), not the one in mysys.

2. The order relation implemented by join_tab_cmp() is not transitive,
i.e. it is possible to choose such a, b and c that (a < b) && (b < c)
but (c < a). This implies that result of a sort using the relation
implemented by join_tab_cmp() depends on the order in which
elements are compared, i.e. the result is implementation-specific. Since
choose_plan() uses qsort() to pre-sort the
join tables using join_tab_cmp() as a compare function, the results of
the sorting may vary depending on qsort() implementation.

It is neither possible nor important to implement a better ordering
algorithm in join_tab_cmp(). Therefore the only way to fix it is to
force our own qsort() to be used by renaming it to my_qsort(), so we don't depend
on linker to decide that.

This patch also "fixes" bug #20530: qsort redefinition violates the
standard.
parent 80a2d47b
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -709,7 +709,9 @@ extern sig_handler my_set_alarm_variable(int signo);
extern void my_string_ptr_sort(void *base,uint items,size_s size);
extern void radixsort_for_str_ptr(uchar* base[], uint number_of_elements,
				  size_s size_of_element,uchar *buffer[]);
extern qsort_t qsort2(void *base_ptr, size_t total_elems, size_t size,
extern qsort_t my_qsort(void *base_ptr, size_t total_elems, size_t size,
                        qsort_cmp cmp);
extern qsort_t my_qsort2(void *base_ptr, size_t total_elems, size_t size,
                         qsort2_cmp cmp, void *cmp_argument);
extern qsort2_cmp get_ptr_compare(uint);
void my_store_ptr(byte *buff, uint pack_length, my_off_t pos);
+1 −1
Original line number Diff line number Diff line
@@ -73,7 +73,7 @@ sqlobjects = net.lo
sql_cmn_objects =	pack.lo client.lo my_time.lo

# Not needed in the minimum library
mysysobjects2 =		my_lib.lo
mysysobjects2 =		my_lib.lo mf_qsort.lo
mysysobjects =		$(mysysobjects1) $(mysysobjects2)
target_libadd =		$(mysysobjects) $(mystringsobjects) $(dbugobjects) \
 $(sql_cmn_objects) $(vio_objects) $(sqlobjects)
+2 −2
Original line number Diff line number Diff line
@@ -430,7 +430,7 @@ FT_INFO * ft_init_boolean_search(MI_INFO *info, uint keynr, byte *query,
  ftb->list=(FTB_WORD **)alloc_root(&ftb->mem_root,
                                     sizeof(FTB_WORD *)*ftb->queue.elements);
  memcpy(ftb->list, ftb->queue.root+1, sizeof(FTB_WORD *)*ftb->queue.elements);
  qsort2(ftb->list, ftb->queue.elements, sizeof(FTB_WORD *),
  my_qsort2(ftb->list, ftb->queue.elements, sizeof(FTB_WORD *),
            (qsort2_cmp)FTB_WORD_cmp_list, ftb->charset);
  if (ftb->queue.elements<2) ftb->with_scan &= ~FTB_FLAG_TRUNC;
  ftb->state=READY;
+2 −1
Original line number Diff line number Diff line
@@ -281,7 +281,8 @@ FT_INFO *ft_init_nlq_search(MI_INFO *info, uint keynr, byte *query,
	    &dptr, left_root_right);

  if (flags & FT_SORTED)
    qsort2(dlist->doc, dlist->ndocs, sizeof(FT_DOC), (qsort2_cmp)&FT_DOC_cmp, 0);
    my_qsort2(dlist->doc, dlist->ndocs, sizeof(FT_DOC), (qsort2_cmp)&FT_DOC_cmp,
              0);

err:
  delete_tree(&aio.dtree);
+1 −1
Original line number Diff line number Diff line
@@ -3148,7 +3148,7 @@ static void fakebigcodes(HUFF_COUNTS *huff_counts, HUFF_COUNTS *end_count)
    cur_sort_p= sort_counts;
    while (cur_count_p < end_count_p)
      *(cur_sort_p++)= cur_count_p++;
    (void) qsort(sort_counts, 256, sizeof(my_off_t*), (qsort_cmp) fakecmp);
    (void) my_qsort(sort_counts, 256, sizeof(my_off_t*), (qsort_cmp) fakecmp);

    /*
      Assign faked counts.
Loading