Commit 4cb0d43a authored by Monty's avatar Monty

MDEV-28054 Various crashes upon INSERT/UPDATE after changing Aria settings

The cause of the crash was that test was setting
aria_sort_buffer_size to MAX_LONG_LONG, which caused an overflow in
my_malloc() when trying to allocate the buffer + 8 bytes.

Fixed by reducing max size of sort_buffer for Aria and MyISAM

Other things:
- Added code in maria_repair_parallell() to not allocate a big sort buffer
  for small files.
- Updated size of minumim sort buffer in Aria
parent 1ef22e28
...@@ -2814,7 +2814,7 @@ DROP TABLE t1; ...@@ -2814,7 +2814,7 @@ DROP TABLE t1;
# cardinalities=1 # cardinalities=1
# #
SET aria_repair_threads=2; SET aria_repair_threads=2;
SET aria_sort_buffer_size=8192; SET aria_sort_buffer_size=16384;
CREATE TABLE t1(a CHAR(255), KEY(a), KEY(a), KEY(a)); CREATE TABLE t1(a CHAR(255), KEY(a), KEY(a), KEY(a));
Warnings: Warnings:
Note 1831 Duplicate index `a_2`. This is deprecated and will be disallowed in a future release Note 1831 Duplicate index `a_2`. This is deprecated and will be disallowed in a future release
...@@ -2839,19 +2839,8 @@ SET aria_repair_threads=@@global.aria_repair_threads; ...@@ -2839,19 +2839,8 @@ SET aria_repair_threads=@@global.aria_repair_threads;
# low myisam_sort_buffer_size # low myisam_sort_buffer_size
# #
CREATE TABLE t1(a INT, b CHAR(10), KEY(a), KEY(b)); CREATE TABLE t1(a INT, b CHAR(10), KEY(a), KEY(b));
INSERT INTO t1 VALUES(1,'0'),(2,'0'),(3,'0'),(4,'0'),(5,'0'), INSERT INTO t1 select seq,'0' from seq_1_to_65536;
(6,'0'),(7,'0'); SET aria_sort_buffer_size=16384;
INSERT INTO t1 SELECT a+10,b FROM t1;
INSERT INTO t1 SELECT a+20,b FROM t1;
INSERT INTO t1 SELECT a+40,b FROM t1;
INSERT INTO t1 SELECT a+80,b FROM t1;
INSERT INTO t1 SELECT a+160,b FROM t1;
INSERT INTO t1 SELECT a+320,b FROM t1;
INSERT INTO t1 SELECT a+640,b FROM t1;
INSERT INTO t1 SELECT a+1280,b FROM t1;
INSERT INTO t1 SELECT a+2560,b FROM t1;
INSERT INTO t1 SELECT a+5120,b FROM t1;
SET aria_sort_buffer_size=4096;
REPAIR TABLE t1; REPAIR TABLE t1;
Table Op Msg_type Msg_text Table Op Msg_type Msg_text
test.t1 repair error aria_sort_buffer_size is too small. X test.t1 repair error aria_sort_buffer_size is too small. X
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
-- source include/have_maria.inc -- source include/have_maria.inc
-- source include/have_partition.inc -- source include/have_partition.inc
-- source include/have_sequence.inc
call mtr.add_suppression("Can't find record in '.*'"); call mtr.add_suppression("Can't find record in '.*'");
...@@ -2034,7 +2035,7 @@ DROP TABLE t1; ...@@ -2034,7 +2035,7 @@ DROP TABLE t1;
--echo # cardinalities=1 --echo # cardinalities=1
--echo # --echo #
SET aria_repair_threads=2; SET aria_repair_threads=2;
SET aria_sort_buffer_size=8192; SET aria_sort_buffer_size=16384;
CREATE TABLE t1(a CHAR(255), KEY(a), KEY(a), KEY(a)); CREATE TABLE t1(a CHAR(255), KEY(a), KEY(a), KEY(a));
INSERT INTO t1 VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9),(0),(1),(2),(3); INSERT INTO t1 VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9),(0),(1),(2),(3);
--replace_regex /Current aria_sort_buffer_size.*/X/ --replace_regex /Current aria_sort_buffer_size.*/X/
...@@ -2050,19 +2051,8 @@ SET aria_repair_threads=@@global.aria_repair_threads; ...@@ -2050,19 +2051,8 @@ SET aria_repair_threads=@@global.aria_repair_threads;
--echo # low myisam_sort_buffer_size --echo # low myisam_sort_buffer_size
--echo # --echo #
CREATE TABLE t1(a INT, b CHAR(10), KEY(a), KEY(b)); CREATE TABLE t1(a INT, b CHAR(10), KEY(a), KEY(b));
INSERT INTO t1 VALUES(1,'0'),(2,'0'),(3,'0'),(4,'0'),(5,'0'), INSERT INTO t1 select seq,'0' from seq_1_to_65536;
(6,'0'),(7,'0'); SET aria_sort_buffer_size=16384;
INSERT INTO t1 SELECT a+10,b FROM t1;
INSERT INTO t1 SELECT a+20,b FROM t1;
INSERT INTO t1 SELECT a+40,b FROM t1;
INSERT INTO t1 SELECT a+80,b FROM t1;
INSERT INTO t1 SELECT a+160,b FROM t1;
INSERT INTO t1 SELECT a+320,b FROM t1;
INSERT INTO t1 SELECT a+640,b FROM t1;
INSERT INTO t1 SELECT a+1280,b FROM t1;
INSERT INTO t1 SELECT a+2560,b FROM t1;
INSERT INTO t1 SELECT a+5120,b FROM t1;
SET aria_sort_buffer_size=4096;
--replace_regex /Current aria_sort_buffer_size.*/X/ --replace_regex /Current aria_sort_buffer_size.*/X/
REPAIR TABLE t1; REPAIR TABLE t1;
CHECK TABLE t1; CHECK TABLE t1;
......
SET sql_mode='';
CREATE TEMPORARY TABLE t1 (a tinyINT,b CHAR(1)) ENGINE=InnoDB ROW_FORMAT=REDUNDANT;
INSERT INTO t1 VALUES (1,1),(3,3),(2,2);
SET SESSION tmp_table_size=True;
Warnings:
Warning 1292 Truncated incorrect tmp_table_size value: '1'
CREATE TABLE t2 (c INT, d DATE) ENGINE=InnoDB PARTITION BY RANGE (YEAR (d)) SUBPARTITION BY HASH (TO_DAYS (d)) (PARTITION p0 VALUES LESS THAN (1990) (SUBPARTITION s0, SUBPARTITION s1), PARTITION p1 VALUES LESS THAN MAXVALUE (SUBPARTITION s4, SUBPARTITION s5));
SET SESSION aria_sort_buffer_size=CAST(-1 AS UNSIGNED INT);
Warnings:
Note 1105 Cast to unsigned converted negative integer to it's positive complement
Note 1105 Cast to unsigned converted negative integer to it's positive complement
Warning 1292 Truncated incorrect aria_sort_buffer_size value: '18446744073709551615'
INSERT INTO t1 SELECT '', SEQ FROM seq_1_to_258;
Warnings:
Warning 1366 Incorrect integer value: '' for column `test`.`t1`.`a` at row 1
Warning 1366 Incorrect integer value: '' for column `test`.`t1`.`a` at row 2
Warning 1366 Incorrect integer value: '' for column `test`.`t1`.`a` at row 3
Warning 1366 Incorrect integer value: '' for column `test`.`t1`.`a` at row 4
Warning 1366 Incorrect integer value: '' for column `test`.`t1`.`a` at row 5
Warning 1366 Incorrect integer value: '' for column `test`.`t1`.`a` at row 6
Warning 1366 Incorrect integer value: '' for column `test`.`t1`.`a` at row 7
Warning 1366 Incorrect integer value: '' for column `test`.`t1`.`a` at row 8
Warning 1366 Incorrect integer value: '' for column `test`.`t1`.`a` at row 9
Warning 1366 Incorrect integer value: '' for column `test`.`t1`.`a` at row 10
Warning 1265 Data truncated for column 'b' at row 10
Warning 1366 Incorrect integer value: '' for column `test`.`t1`.`a` at row 11
Warning 1265 Data truncated for column 'b' at row 11
Warning 1366 Incorrect integer value: '' for column `test`.`t1`.`a` at row 12
Warning 1265 Data truncated for column 'b' at row 12
Warning 1366 Incorrect integer value: '' for column `test`.`t1`.`a` at row 13
Warning 1265 Data truncated for column 'b' at row 13
Warning 1366 Incorrect integer value: '' for column `test`.`t1`.`a` at row 14
Warning 1265 Data truncated for column 'b' at row 14
Warning 1366 Incorrect integer value: '' for column `test`.`t1`.`a` at row 15
Warning 1265 Data truncated for column 'b' at row 15
Warning 1366 Incorrect integer value: '' for column `test`.`t1`.`a` at row 16
Warning 1265 Data truncated for column 'b' at row 16
Warning 1366 Incorrect integer value: '' for column `test`.`t1`.`a` at row 17
Warning 1265 Data truncated for column 'b' at row 17
Warning 1366 Incorrect integer value: '' for column `test`.`t1`.`a` at row 18
Warning 1265 Data truncated for column 'b' at row 18
Warning 1366 Incorrect integer value: '' for column `test`.`t1`.`a` at row 19
Warning 1265 Data truncated for column 'b' at row 19
Warning 1366 Incorrect integer value: '' for column `test`.`t1`.`a` at row 20
Warning 1265 Data truncated for column 'b' at row 20
Warning 1366 Incorrect integer value: '' for column `test`.`t1`.`a` at row 21
Warning 1265 Data truncated for column 'b' at row 21
Warning 1366 Incorrect integer value: '' for column `test`.`t1`.`a` at row 22
Warning 1265 Data truncated for column 'b' at row 22
Warning 1366 Incorrect integer value: '' for column `test`.`t1`.`a` at row 23
Warning 1265 Data truncated for column 'b' at row 23
Warning 1366 Incorrect integer value: '' for column `test`.`t1`.`a` at row 24
Warning 1265 Data truncated for column 'b' at row 24
Warning 1366 Incorrect integer value: '' for column `test`.`t1`.`a` at row 25
Warning 1265 Data truncated for column 'b' at row 25
Warning 1366 Incorrect integer value: '' for column `test`.`t1`.`a` at row 26
Warning 1265 Data truncated for column 'b' at row 26
Warning 1366 Incorrect integer value: '' for column `test`.`t1`.`a` at row 27
Warning 1265 Data truncated for column 'b' at row 27
Warning 1366 Incorrect integer value: '' for column `test`.`t1`.`a` at row 28
Warning 1265 Data truncated for column 'b' at row 28
Warning 1366 Incorrect integer value: '' for column `test`.`t1`.`a` at row 29
Warning 1265 Data truncated for column 'b' at row 29
Warning 1366 Incorrect integer value: '' for column `test`.`t1`.`a` at row 30
Warning 1265 Data truncated for column 'b' at row 30
Warning 1366 Incorrect integer value: '' for column `test`.`t1`.`a` at row 31
Warning 1265 Data truncated for column 'b' at row 31
Warning 1366 Incorrect integer value: '' for column `test`.`t1`.`a` at row 32
Warning 1265 Data truncated for column 'b' at row 32
Warning 1366 Incorrect integer value: '' for column `test`.`t1`.`a` at row 33
Warning 1265 Data truncated for column 'b' at row 33
Warning 1366 Incorrect integer value: '' for column `test`.`t1`.`a` at row 34
Warning 1265 Data truncated for column 'b' at row 34
Warning 1366 Incorrect integer value: '' for column `test`.`t1`.`a` at row 35
Warning 1265 Data truncated for column 'b' at row 35
Warning 1366 Incorrect integer value: '' for column `test`.`t1`.`a` at row 36
Warning 1265 Data truncated for column 'b' at row 36
Warning 1366 Incorrect integer value: '' for column `test`.`t1`.`a` at row 37
SET SESSION aria_repair_threads=4;
UPDATE t1 SET a=( (SELECT MAX(a) FROM t1));
drop table t1,t2;
--source include/have_innodb.inc
--source include/have_partition.inc
--source include/have_sequence.inc
SET sql_mode='';
CREATE TEMPORARY TABLE t1 (a tinyINT,b CHAR(1)) ENGINE=InnoDB ROW_FORMAT=REDUNDANT;
INSERT INTO t1 VALUES (1,1),(3,3),(2,2);
SET SESSION tmp_table_size=True;
CREATE TABLE t2 (c INT, d DATE) ENGINE=InnoDB PARTITION BY RANGE (YEAR (d)) SUBPARTITION BY HASH (TO_DAYS (d)) (PARTITION p0 VALUES LESS THAN (1990) (SUBPARTITION s0, SUBPARTITION s1), PARTITION p1 VALUES LESS THAN MAXVALUE (SUBPARTITION s4, SUBPARTITION s5));
SET SESSION aria_sort_buffer_size=CAST(-1 AS UNSIGNED INT);
INSERT INTO t1 SELECT '', SEQ FROM seq_1_to_258;
SET SESSION aria_repair_threads=4;
UPDATE t1 SET a=( (SELECT MAX(a) FROM t1));
drop table t1,t2;
...@@ -22,13 +22,13 @@ Warnings: ...@@ -22,13 +22,13 @@ Warnings:
Warning 1292 Truncated incorrect aria_sort_buffer_size value: '10' Warning 1292 Truncated incorrect aria_sort_buffer_size value: '10'
select @@global.aria_sort_buffer_size; select @@global.aria_sort_buffer_size;
@@global.aria_sort_buffer_size @@global.aria_sort_buffer_size
4096 16376
set session aria_sort_buffer_size=10; set session aria_sort_buffer_size=10;
Warnings: Warnings:
Warning 1292 Truncated incorrect aria_sort_buffer_size value: '10' Warning 1292 Truncated incorrect aria_sort_buffer_size value: '10'
select @@session.aria_sort_buffer_size; select @@session.aria_sort_buffer_size;
@@session.aria_sort_buffer_size @@session.aria_sort_buffer_size
4096 16376
set global aria_sort_buffer_size=1.1; set global aria_sort_buffer_size=1.1;
ERROR 42000: Incorrect argument type to variable 'aria_sort_buffer_size' ERROR 42000: Incorrect argument type to variable 'aria_sort_buffer_size'
set session aria_sort_buffer_size=1e1; set session aria_sort_buffer_size=1e1;
...@@ -40,9 +40,9 @@ Warnings: ...@@ -40,9 +40,9 @@ Warnings:
Warning 1292 Truncated incorrect aria_sort_buffer_size value: '0' Warning 1292 Truncated incorrect aria_sort_buffer_size value: '0'
select @@global.aria_sort_buffer_size; select @@global.aria_sort_buffer_size;
@@global.aria_sort_buffer_size @@global.aria_sort_buffer_size
4096 16376
set session aria_sort_buffer_size=cast(-1 as unsigned int); set session aria_sort_buffer_size=cast(-1 as unsigned int);
select @@session.aria_sort_buffer_size; select @@session.aria_sort_buffer_size;
@@session.aria_sort_buffer_size @@session.aria_sort_buffer_size
18446744073709551615 1152921504606846975
SET @@global.aria_sort_buffer_size = @start_global_value; SET @@global.aria_sort_buffer_size = @start_global_value;
...@@ -223,8 +223,8 @@ DEFAULT_VALUE 268434432 ...@@ -223,8 +223,8 @@ DEFAULT_VALUE 268434432
VARIABLE_SCOPE SESSION VARIABLE_SCOPE SESSION
VARIABLE_TYPE BIGINT UNSIGNED VARIABLE_TYPE BIGINT UNSIGNED
VARIABLE_COMMENT The buffer that is allocated when sorting the index when doing a REPAIR or when creating indexes with CREATE INDEX or ALTER TABLE. VARIABLE_COMMENT The buffer that is allocated when sorting the index when doing a REPAIR or when creating indexes with CREATE INDEX or ALTER TABLE.
NUMERIC_MIN_VALUE 4096 NUMERIC_MIN_VALUE 16376
NUMERIC_MAX_VALUE 18446744073709551615 NUMERIC_MAX_VALUE 1152921504606846975
NUMERIC_BLOCK_SIZE 1 NUMERIC_BLOCK_SIZE 1
ENUM_VALUE_LIST NULL ENUM_VALUE_LIST NULL
READ_ONLY NO READ_ONLY NO
......
...@@ -97,9 +97,9 @@ ...@@ -97,9 +97,9 @@
@@ -207,7 +207,7 @@ VARIABLE_SCOPE SESSION @@ -207,7 +207,7 @@ VARIABLE_SCOPE SESSION
VARIABLE_TYPE BIGINT UNSIGNED VARIABLE_TYPE BIGINT UNSIGNED
VARIABLE_COMMENT The buffer that is allocated when sorting the index when doing a REPAIR or when creating indexes with CREATE INDEX or ALTER TABLE. VARIABLE_COMMENT The buffer that is allocated when sorting the index when doing a REPAIR or when creating indexes with CREATE INDEX or ALTER TABLE.
NUMERIC_MIN_VALUE 4096 NUMERIC_MIN_VALUE 16376
-NUMERIC_MAX_VALUE 18446744073709551615 -NUMERIC_MAX_VALUE 18446744073709551615
+NUMERIC_MAX_VALUE 4294967295 +NUMERIC_MAX_VALUE 268435455
NUMERIC_BLOCK_SIZE 1 NUMERIC_BLOCK_SIZE 1
ENUM_VALUE_LIST NULL ENUM_VALUE_LIST NULL
READ_ONLY NO READ_ONLY NO
...@@ -684,8 +684,8 @@ ...@@ -684,8 +684,8 @@
VARIABLE_TYPE BIGINT UNSIGNED VARIABLE_TYPE BIGINT UNSIGNED
VARIABLE_COMMENT The buffer that is allocated when sorting the index when doing a REPAIR or when creating indexes with CREATE INDEX or ALTER TABLE VARIABLE_COMMENT The buffer that is allocated when sorting the index when doing a REPAIR or when creating indexes with CREATE INDEX or ALTER TABLE
NUMERIC_MIN_VALUE 4096 NUMERIC_MIN_VALUE 4096
-NUMERIC_MAX_VALUE 18446744073709551615 -NUMERIC_MAX_VALUE 1152921504606846975
+NUMERIC_MAX_VALUE 4294967295 +NUMERIC_MAX_VALUE 268435455
NUMERIC_BLOCK_SIZE 1 NUMERIC_BLOCK_SIZE 1
ENUM_VALUE_LIST NULL ENUM_VALUE_LIST NULL
READ_ONLY NO READ_ONLY NO
......
...@@ -216,8 +216,8 @@ VARIABLE_NAME ARIA_SORT_BUFFER_SIZE ...@@ -216,8 +216,8 @@ VARIABLE_NAME ARIA_SORT_BUFFER_SIZE
VARIABLE_SCOPE SESSION VARIABLE_SCOPE SESSION
VARIABLE_TYPE BIGINT UNSIGNED VARIABLE_TYPE BIGINT UNSIGNED
VARIABLE_COMMENT The buffer that is allocated when sorting the index when doing a REPAIR or when creating indexes with CREATE INDEX or ALTER TABLE. VARIABLE_COMMENT The buffer that is allocated when sorting the index when doing a REPAIR or when creating indexes with CREATE INDEX or ALTER TABLE.
NUMERIC_MIN_VALUE 4096 NUMERIC_MIN_VALUE 16376
NUMERIC_MAX_VALUE 18446744073709551615 NUMERIC_MAX_VALUE 1152921504606846975
NUMERIC_BLOCK_SIZE 1 NUMERIC_BLOCK_SIZE 1
ENUM_VALUE_LIST NULL ENUM_VALUE_LIST NULL
READ_ONLY NO READ_ONLY NO
...@@ -2127,7 +2127,7 @@ VARIABLE_SCOPE SESSION ...@@ -2127,7 +2127,7 @@ VARIABLE_SCOPE SESSION
VARIABLE_TYPE BIGINT UNSIGNED VARIABLE_TYPE BIGINT UNSIGNED
VARIABLE_COMMENT The buffer that is allocated when sorting the index when doing a REPAIR or when creating indexes with CREATE INDEX or ALTER TABLE VARIABLE_COMMENT The buffer that is allocated when sorting the index when doing a REPAIR or when creating indexes with CREATE INDEX or ALTER TABLE
NUMERIC_MIN_VALUE 4096 NUMERIC_MIN_VALUE 4096
NUMERIC_MAX_VALUE 18446744073709551615 NUMERIC_MAX_VALUE 1152921504606846975
NUMERIC_BLOCK_SIZE 1 NUMERIC_BLOCK_SIZE 1
ENUM_VALUE_LIST NULL ENUM_VALUE_LIST NULL
READ_ONLY NO READ_ONLY NO
......
...@@ -216,8 +216,8 @@ VARIABLE_NAME ARIA_SORT_BUFFER_SIZE ...@@ -216,8 +216,8 @@ VARIABLE_NAME ARIA_SORT_BUFFER_SIZE
VARIABLE_SCOPE SESSION VARIABLE_SCOPE SESSION
VARIABLE_TYPE BIGINT UNSIGNED VARIABLE_TYPE BIGINT UNSIGNED
VARIABLE_COMMENT The buffer that is allocated when sorting the index when doing a REPAIR or when creating indexes with CREATE INDEX or ALTER TABLE. VARIABLE_COMMENT The buffer that is allocated when sorting the index when doing a REPAIR or when creating indexes with CREATE INDEX or ALTER TABLE.
NUMERIC_MIN_VALUE 4096 NUMERIC_MIN_VALUE 16376
NUMERIC_MAX_VALUE 18446744073709551615 NUMERIC_MAX_VALUE 1152921504606846975
NUMERIC_BLOCK_SIZE 1 NUMERIC_BLOCK_SIZE 1
ENUM_VALUE_LIST NULL ENUM_VALUE_LIST NULL
READ_ONLY NO READ_ONLY NO
...@@ -2287,7 +2287,7 @@ VARIABLE_SCOPE SESSION ...@@ -2287,7 +2287,7 @@ VARIABLE_SCOPE SESSION
VARIABLE_TYPE BIGINT UNSIGNED VARIABLE_TYPE BIGINT UNSIGNED
VARIABLE_COMMENT The buffer that is allocated when sorting the index when doing a REPAIR or when creating indexes with CREATE INDEX or ALTER TABLE VARIABLE_COMMENT The buffer that is allocated when sorting the index when doing a REPAIR or when creating indexes with CREATE INDEX or ALTER TABLE
NUMERIC_MIN_VALUE 4096 NUMERIC_MIN_VALUE 4096
NUMERIC_MAX_VALUE 18446744073709551615 NUMERIC_MAX_VALUE 1152921504606846975
NUMERIC_BLOCK_SIZE 1 NUMERIC_BLOCK_SIZE 1
ENUM_VALUE_LIST NULL ENUM_VALUE_LIST NULL
READ_ONLY NO READ_ONLY NO
......
...@@ -269,7 +269,7 @@ static MYSQL_THDVAR_ULONG(repair_threads, PLUGIN_VAR_RQCMDARG, ...@@ -269,7 +269,7 @@ static MYSQL_THDVAR_ULONG(repair_threads, PLUGIN_VAR_RQCMDARG,
static MYSQL_THDVAR_ULONGLONG(sort_buffer_size, PLUGIN_VAR_RQCMDARG, static MYSQL_THDVAR_ULONGLONG(sort_buffer_size, PLUGIN_VAR_RQCMDARG,
"The buffer that is allocated when sorting the index when doing a " "The buffer that is allocated when sorting the index when doing a "
"REPAIR or when creating indexes with CREATE INDEX or ALTER TABLE.", NULL, NULL, "REPAIR or when creating indexes with CREATE INDEX or ALTER TABLE.", NULL, NULL,
SORT_BUFFER_INIT, MIN_SORT_BUFFER, SIZE_T_MAX, 1); SORT_BUFFER_INIT, MARIA_MIN_SORT_MEMORY, SIZE_T_MAX/16, 1);
static MYSQL_THDVAR_ENUM(stats_method, PLUGIN_VAR_RQCMDARG, static MYSQL_THDVAR_ENUM(stats_method, PLUGIN_VAR_RQCMDARG,
"Specifies how Aria index statistics collection code should treat " "Specifies how Aria index statistics collection code should treat "
......
...@@ -3903,6 +3903,16 @@ int maria_repair_by_sort(HA_CHECK *param, register MARIA_HA *info, ...@@ -3903,6 +3903,16 @@ int maria_repair_by_sort(HA_CHECK *param, register MARIA_HA *info,
{ {
sort_param.key_read= sort_key_read; sort_param.key_read= sort_key_read;
sort_param.key_write= sort_key_write; sort_param.key_write= sort_key_write;
/*
Limit usage of sort memory
We assume we don't need more memory than data file length * 2
(There is a pointer overhead for each key, but this is hard to
estimae as we cannot be sure how many records we have in file to
be repaired).
*/
set_if_smaller(param->sort_buffer_length, sort_info.filelength*2);
set_if_bigger(param->sort_buffer_length, MARIA_MIN_SORT_MEMORY);
} }
if (sort_info.new_info->s->data_file_type == BLOCK_RECORD) if (sort_info.new_info->s->data_file_type == BLOCK_RECORD)
...@@ -4505,6 +4515,16 @@ int maria_repair_parallel(HA_CHECK *param, register MARIA_HA *info, ...@@ -4505,6 +4515,16 @@ int maria_repair_parallel(HA_CHECK *param, register MARIA_HA *info,
DBUG_PRINT("io_cache_share", ("thread: %u read_cache: %p", DBUG_PRINT("io_cache_share", ("thread: %u read_cache: %p",
i, &sort_param[i].read_cache)); i, &sort_param[i].read_cache));
/*
Limit usage of sort memory
We assume we don't need more memory than data file length * 2
(There is a pointer overhead for each key, but this is hard to
estimae as we cannot be sure how many records we have in file to
be repaired).
*/
set_if_smaller(param->sort_buffer_length, sort_info.filelength*2);
set_if_bigger(param->sort_buffer_length, MARIA_MIN_SORT_MEMORY);
/* /*
two approaches: the same amount of memory for each thread two approaches: the same amount of memory for each thread
or the memory for the same number of keys for each thread... or the memory for the same number of keys for each thread...
...@@ -4517,6 +4537,8 @@ int maria_repair_parallel(HA_CHECK *param, register MARIA_HA *info, ...@@ -4517,6 +4537,8 @@ int maria_repair_parallel(HA_CHECK *param, register MARIA_HA *info,
#else #else
param->sort_buffer_length*sort_param[i].key_length/total_key_length; param->sort_buffer_length*sort_param[i].key_length/total_key_length;
#endif #endif
set_if_bigger(sort_param[i].sortbuff_size, MARIA_MIN_SORT_MEMORY);
if (mysql_thread_create(key_thread_find_all_keys, if (mysql_thread_create(key_thread_find_all_keys,
&sort_param[i].thr, &thr_attr, &sort_param[i].thr, &thr_attr,
_ma_thr_find_all_keys, (void *) (sort_param+i))) _ma_thr_find_all_keys, (void *) (sort_param+i)))
......
...@@ -29,12 +29,10 @@ ...@@ -29,12 +29,10 @@
/* static variables */ /* static variables */
#undef MIN_SORT_MEMORY
#undef DISK_BUFFER_SIZE #undef DISK_BUFFER_SIZE
#define MERGEBUFF 15 #define MERGEBUFF 15
#define MERGEBUFF2 31 #define MERGEBUFF2 31
#define MIN_SORT_MEMORY (4096-MALLOC_OVERHEAD)
#define DISK_BUFFER_SIZE (IO_SIZE*128) #define DISK_BUFFER_SIZE (IO_SIZE*128)
/* How many keys we can keep in memory */ /* How many keys we can keep in memory */
...@@ -145,11 +143,11 @@ int _ma_create_index_by_sort(MARIA_SORT_PARAM *info, my_bool no_messages, ...@@ -145,11 +143,11 @@ int _ma_create_index_by_sort(MARIA_SORT_PARAM *info, my_bool no_messages,
sort_keys= (uchar **) NULL; error= 1; sort_keys= (uchar **) NULL; error= 1;
maxbuffer=1; maxbuffer=1;
memavl=MY_MAX(sortbuff_size,MIN_SORT_MEMORY); memavl=MY_MAX(sortbuff_size,MARIA_MIN_SORT_MEMORY);
records= info->sort_info->max_records; records= info->sort_info->max_records;
sort_length= info->key_length; sort_length= info->key_length;
while (memavl >= MIN_SORT_MEMORY) while (memavl >= MARIA_MIN_SORT_MEMORY)
{ {
/* Check if we can fit all keys into memory */ /* Check if we can fit all keys into memory */
if (((ulonglong) (records + 1) * if (((ulonglong) (records + 1) *
...@@ -208,10 +206,10 @@ int _ma_create_index_by_sort(MARIA_SORT_PARAM *info, my_bool no_messages, ...@@ -208,10 +206,10 @@ int _ma_create_index_by_sort(MARIA_SORT_PARAM *info, my_bool no_messages,
break; break;
} }
old_memavl=memavl; old_memavl=memavl;
if ((memavl=memavl/4*3) < MIN_SORT_MEMORY && old_memavl > MIN_SORT_MEMORY) if ((memavl=memavl/4*3) < MARIA_MIN_SORT_MEMORY && old_memavl > MARIA_MIN_SORT_MEMORY)
memavl=MIN_SORT_MEMORY; memavl=MARIA_MIN_SORT_MEMORY;
} }
if (memavl < MIN_SORT_MEMORY) if (memavl < MARIA_MIN_SORT_MEMORY)
{ {
/* purecov: begin inspected */ /* purecov: begin inspected */
_ma_check_print_error(info->sort_info->param, _ma_check_print_error(info->sort_info->param,
...@@ -387,12 +385,12 @@ static my_bool _ma_thr_find_all_keys_exec(MARIA_SORT_PARAM* sort_param) ...@@ -387,12 +385,12 @@ static my_bool _ma_thr_find_all_keys_exec(MARIA_SORT_PARAM* sort_param)
bzero((char*) &sort_param->unique, sizeof(sort_param->unique)); bzero((char*) &sort_param->unique, sizeof(sort_param->unique));
sortbuff_size= sort_param->sortbuff_size; sortbuff_size= sort_param->sortbuff_size;
memavl= MY_MAX(sortbuff_size, MIN_SORT_MEMORY); memavl= MY_MAX(sortbuff_size, MARIA_MIN_SORT_MEMORY);
idx= (ha_keys) sort_param->sort_info->max_records; idx= (ha_keys) sort_param->sort_info->max_records;
sort_length= sort_param->key_length; sort_length= sort_param->key_length;
maxbuffer= 1; maxbuffer= 1;
while (memavl >= MIN_SORT_MEMORY) while (memavl >= MARIA_MIN_SORT_MEMORY)
{ {
if ((my_off_t) (idx+1)*(sort_length+sizeof(char*)) <= (my_off_t) memavl) if ((my_off_t) (idx+1)*(sort_length+sizeof(char*)) <= (my_off_t) memavl)
keys= idx+1; keys= idx+1;
...@@ -442,11 +440,11 @@ static my_bool _ma_thr_find_all_keys_exec(MARIA_SORT_PARAM* sort_param) ...@@ -442,11 +440,11 @@ static my_bool _ma_thr_find_all_keys_exec(MARIA_SORT_PARAM* sort_param)
break; break;
} }
old_memavl= memavl; old_memavl= memavl;
if ((memavl= memavl/4*3) < MIN_SORT_MEMORY && if ((memavl= memavl/4*3) < MARIA_MIN_SORT_MEMORY &&
old_memavl > MIN_SORT_MEMORY) old_memavl > MARIA_MIN_SORT_MEMORY)
memavl= MIN_SORT_MEMORY; memavl= MARIA_MIN_SORT_MEMORY;
} }
if (memavl < MIN_SORT_MEMORY) if (memavl < MARIA_MIN_SORT_MEMORY)
{ {
/* purecov: begin inspected */ /* purecov: begin inspected */
_ma_check_print_error(sort_param->sort_info->param, _ma_check_print_error(sort_param->sort_info->param,
...@@ -626,7 +624,7 @@ int _ma_thr_write_keys(MARIA_SORT_PARAM *sort_param) ...@@ -626,7 +624,7 @@ int _ma_thr_write_keys(MARIA_SORT_PARAM *sort_param)
if (!mergebuf) if (!mergebuf)
{ {
length=(size_t)param->sort_buffer_length; length=(size_t)param->sort_buffer_length;
while (length >= MIN_SORT_MEMORY) while (length >= MARIA_MIN_SORT_MEMORY)
{ {
if ((mergebuf= my_malloc((size_t) length, MYF(0)))) if ((mergebuf= my_malloc((size_t) length, MYF(0))))
break; break;
......
...@@ -424,7 +424,8 @@ static struct my_option my_long_options[] = ...@@ -424,7 +424,8 @@ static struct my_option my_long_options[] =
"Size of sort buffer. Used by --recover", "Size of sort buffer. Used by --recover",
&check_param.sort_buffer_length, &check_param.sort_buffer_length,
&check_param.sort_buffer_length, 0, GET_ULL, REQUIRED_ARG, &check_param.sort_buffer_length, 0, GET_ULL, REQUIRED_ARG,
SORT_BUFFER_INIT, MIN_SORT_BUFFER, SIZE_T_MAX, MALLOC_OVERHEAD, 1L, 0}, SORT_BUFFER_INIT, MARIA_MIN_SORT_MEMORY, SIZE_T_MAX/10, MALLOC_OVERHEAD,
1L, 0},
{ "sort_key_blocks", OPT_SORT_KEY_BLOCKS, { "sort_key_blocks", OPT_SORT_KEY_BLOCKS,
"Internal buffer for sorting keys; Don't touch :)", "Internal buffer for sorting keys; Don't touch :)",
&check_param.sort_key_blocks, &check_param.sort_key_blocks,
......
...@@ -45,6 +45,8 @@ ...@@ -45,6 +45,8 @@
#define MARIA_MAX_TREE_LEVELS 32 #define MARIA_MAX_TREE_LEVELS 32
#define MARIA_MAX_RECORD_ON_STACK 16384 #define MARIA_MAX_RECORD_ON_STACK 16384
#define MARIA_MIN_SORT_MEMORY (16384-MALLOC_OVERHEAD)
/* maria_open() flag, specific for maria_pack */ /* maria_open() flag, specific for maria_pack */
#define HA_OPEN_IGNORE_MOVED_STATE (1U << 30) #define HA_OPEN_IGNORE_MOVED_STATE (1U << 30)
...@@ -1273,7 +1275,6 @@ typedef struct st_maria_block_info ...@@ -1273,7 +1275,6 @@ typedef struct st_maria_block_info
#define PAGE_BUFFER_INIT MY_ALIGN_DOWN(1024L*1024L*256L-MALLOC_OVERHEAD, 8192) #define PAGE_BUFFER_INIT MY_ALIGN_DOWN(1024L*1024L*256L-MALLOC_OVERHEAD, 8192)
#define READ_BUFFER_INIT MY_ALIGN_DOWN(1024L*256L-MALLOC_OVERHEAD, 1024) #define READ_BUFFER_INIT MY_ALIGN_DOWN(1024L*256L-MALLOC_OVERHEAD, 1024)
#define SORT_BUFFER_INIT MY_ALIGN_DOWN(1024L*1024L*256L-MALLOC_OVERHEAD, 1024) #define SORT_BUFFER_INIT MY_ALIGN_DOWN(1024L*1024L*256L-MALLOC_OVERHEAD, 1024)
#define MIN_SORT_BUFFER 4096U
#define fast_ma_writeinfo(INFO) if (!(INFO)->s->tot_locks) (void) _ma_writeinfo((INFO),0) #define fast_ma_writeinfo(INFO) if (!(INFO)->s->tot_locks) (void) _ma_writeinfo((INFO),0)
#define fast_ma_readinfo(INFO) ((INFO)->lock_type == F_UNLCK) && _ma_readinfo((INFO),F_RDLCK,1) #define fast_ma_readinfo(INFO) ((INFO)->lock_type == F_UNLCK) && _ma_readinfo((INFO),F_RDLCK,1)
......
...@@ -80,7 +80,7 @@ static MYSQL_THDVAR_ULONG(repair_threads, PLUGIN_VAR_RQCMDARG, ...@@ -80,7 +80,7 @@ static MYSQL_THDVAR_ULONG(repair_threads, PLUGIN_VAR_RQCMDARG,
static MYSQL_THDVAR_ULONGLONG(sort_buffer_size, PLUGIN_VAR_RQCMDARG, static MYSQL_THDVAR_ULONGLONG(sort_buffer_size, PLUGIN_VAR_RQCMDARG,
"The buffer that is allocated when sorting the index when doing " "The buffer that is allocated when sorting the index when doing "
"a REPAIR or when creating indexes with CREATE INDEX or ALTER TABLE", NULL, NULL, "a REPAIR or when creating indexes with CREATE INDEX or ALTER TABLE", NULL, NULL,
SORT_BUFFER_INIT, MIN_SORT_BUFFER, SIZE_T_MAX, 1); SORT_BUFFER_INIT, MIN_SORT_BUFFER, SIZE_T_MAX/16, 1);
static MYSQL_SYSVAR_BOOL(use_mmap, opt_myisam_use_mmap, PLUGIN_VAR_NOCMDARG, static MYSQL_SYSVAR_BOOL(use_mmap, opt_myisam_use_mmap, PLUGIN_VAR_NOCMDARG,
"Use memory mapping for reading and writing MyISAM tables", NULL, NULL, FALSE); "Use memory mapping for reading and writing MyISAM tables", NULL, NULL, FALSE);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment