Skip to content

Commit c1a7c10

Browse files
author
Arun Kuruvila
committed
Bug#28483283: BACKPORT BUGFIX 26929724 TO MYSQL 5.5 AND 5.6
Description: MYISAM index corruption occurs for bulk insert or repair table which involves "repair by sorting" algorithm. Analysis: The index corruption happens because of the incorrect sorting done by "my_qsort2()". This happens for a bulk insert with more than 450001959 rows or repair table with more than 450001959 rows. In 5.7, "my_qsort2()" is replaced by std::sort() as part of Bug#26929724. Fix:- Back ported Bug#26929724 fix to ensure MyISAM repair by sorting algorithm uses std::sort().
1 parent 5521020 commit c1a7c10

File tree

3 files changed

+33
-11
lines changed

3 files changed

+33
-11
lines changed

storage/myisam/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved.
22
#
33
# This program is free software; you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License as published by
@@ -24,7 +24,7 @@ SET(MYISAM_SOURCES ft_boolean_search.c ft_nlq_search.c ft_parser.c ft_static.c
2424
mi_rfirst.c mi_rlast.c mi_rnext.c mi_rnext_same.c mi_rprev.c mi_rrnd.c
2525
mi_rsame.c mi_rsamepos.c mi_scan.c mi_search.c mi_static.c mi_statrec.c
2626
mi_unique.c mi_update.c mi_write.c rt_index.c rt_key.c rt_mbr.c
27-
rt_split.c sort.c sp_key.c mi_extrafunc.h myisamdef.h
27+
rt_split.c sort.cc sp_key.c mi_extrafunc.h myisamdef.h
2828
rt_index.h mi_rkey.c)
2929

3030
MYSQL_ADD_PLUGIN(myisam ${MYISAM_SOURCES}

storage/myisam/myisamdef.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License as published by
@@ -474,6 +474,10 @@ extern mysql_mutex_t THR_LOCK_myisam;
474474
#define mysql_rwlock_wrlock(A) {}
475475
#define mysql_rwlock_rdlock(A) {}
476476
#define mysql_rwlock_unlock(A) {}
477+
#endif
478+
479+
#ifdef __cplusplus
480+
extern "C" {
477481
#endif
478482

479483
/* Some extern variables */
@@ -637,6 +641,10 @@ extern ulonglong mi_safe_mul(ulonglong a,ulonglong b);
637641
extern int _mi_ft_update(MI_INFO *info, uint keynr, uchar *keybuf,
638642
const uchar *oldrec, const uchar *newrec, my_off_t pos);
639643

644+
#ifdef __cplusplus
645+
}
646+
#endif
647+
640648
struct st_sort_info;
641649

642650

storage/myisam/sort.c renamed to storage/myisam/sort.cc

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -18,6 +18,9 @@
1818
them in sorted order through SORT_INFO functions.
1919
*/
2020

21+
#include <algorithm>
22+
#include <functional>
23+
#include <my_global.h>
2124
#include "fulltext.h"
2225
#if defined(__WIN__)
2326
#include <fcntl.h>
@@ -36,6 +39,17 @@
3639
#define MYF_RW MYF(MY_NABP | MY_WME | MY_WAIT_IF_FULL)
3740
#define DISK_BUFFER_SIZE (IO_SIZE*16)
3841

42+
class Key_compare :
43+
public std::binary_function<const uchar*, const uchar*, bool>
44+
{
45+
public:
46+
Key_compare(MI_SORT_PARAM *param) : info(param) {}
47+
bool operator()(const uchar *a, const uchar *b)
48+
{
49+
return info->key_cmp(info, &a, &b) < 0;
50+
}
51+
MI_SORT_PARAM *info;
52+
};
3953

4054
/*
4155
Pointers of functions for store and read keys from temp file
@@ -568,7 +582,7 @@ int thr_write_keys(MI_SORT_PARAM *sort_param)
568582
length=param->sort_buffer_length;
569583
while (length >= MIN_SORT_BUFFER)
570584
{
571-
if ((mergebuf= my_malloc(length, MYF(0))))
585+
if ((mergebuf= (uchar *) my_malloc(length, MYF(0))))
572586
break;
573587
length=length*3/4;
574588
}
@@ -655,8 +669,8 @@ static int write_keys(MI_SORT_PARAM *info, register uchar **sort_keys,
655669
uint sort_length=info->key_length;
656670
DBUG_ENTER("write_keys");
657671

658-
my_qsort2((uchar*) sort_keys,count,sizeof(uchar*),(qsort2_cmp) info->key_cmp,
659-
info);
672+
std::sort(sort_keys, sort_keys + count, Key_compare(info));
673+
660674
if (!my_b_inited(tempfile) &&
661675
open_cached_file(tempfile, my_tmpdir(info->tmpdir), "ST",
662676
DISK_BUFFER_SIZE, info->sort_info->param->myf_rw))
@@ -698,8 +712,8 @@ static int write_keys_varlen(MI_SORT_PARAM *info,
698712
int err;
699713
DBUG_ENTER("write_keys_varlen");
700714

701-
my_qsort2((uchar*) sort_keys,count,sizeof(uchar*),(qsort2_cmp) info->key_cmp,
702-
info);
715+
std::sort(sort_keys, sort_keys + count, Key_compare(info));
716+
703717
if (!my_b_inited(tempfile) &&
704718
open_cached_file(tempfile, my_tmpdir(info->tmpdir), "ST",
705719
DISK_BUFFER_SIZE, info->sort_info->param->myf_rw))
@@ -740,8 +754,8 @@ static int write_index(MI_SORT_PARAM *info, register uchar **sort_keys,
740754
{
741755
DBUG_ENTER("write_index");
742756

743-
my_qsort2((uchar*) sort_keys,(size_t) count,sizeof(uchar*),
744-
(qsort2_cmp) info->key_cmp,info);
757+
std::sort(sort_keys, sort_keys + count, Key_compare(info));
758+
745759
while (count--)
746760
{
747761
if ((*info->key_write)(info,*sort_keys++))

0 commit comments

Comments
 (0)