Skip to content

Commit

Permalink
[mysql-5.6][PR] FB8-78: Add filesort_max_file_size option
Browse files Browse the repository at this point in the history
Summary:
Jira issue: https://jira.percona.com/browse/FB8-78

Reference Patch: 11ef068

Add the filesort_max_file_size variable setting which specifies the maximum number of bytes a filesort file can take. If it is exceeded, then the query fails.

This is very similar to the tmp_table_max_file_size variable.
Pull Request resolved: #993
GitHub Author: Manuel Ung <[email protected]>

Test Plan: main.max_filesort_size

Reviewers:

Subscribers: butterflybot, vinaybhat, [email protected]

Differential Revision: https://phabricator.intern.facebook.com/D14652353

Tasks:

Tags:

Blame Revision:
  • Loading branch information
facebook-github-bot authored and Herman Lee committed Apr 17, 2019
1 parent cc474d7 commit 7f595e0
Show file tree
Hide file tree
Showing 12 changed files with 503 additions and 8 deletions.
8 changes: 4 additions & 4 deletions mysql-test/r/all_persisted_variables.result
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ include/assert.inc ['Expect 500+ variables in the table. Due to open Bugs, we ar

# Test SET PERSIST

include/assert.inc ['Expect 397 persisted variables in the table. Due to open Bugs, we are checking for 391']
include/assert.inc ['Expect 398 persisted variables in the table. Due to open Bugs, we are checking for 392']

************************************************************
* 3. Restart server, it must preserve the persisted variable
* settings. Verify persisted configuration.
************************************************************
# restart

include/assert.inc ['Expect 391 persisted variables in persisted_variables table.']
include/assert.inc ['Expect 391 persisted variables shown as PERSISTED in variables_info table.']
include/assert.inc ['Expect 391 persisted variables with matching peristed and global values.']
include/assert.inc ['Expect 392 persisted variables in persisted_variables table.']
include/assert.inc ['Expect 392 persisted variables shown as PERSISTED in variables_info table.']
include/assert.inc ['Expect 392 persisted variables with matching peristed and global values.']

************************************************************
* 4. Test RESET PERSIST IF EXISTS. Verify persisted variable
Expand Down
90 changes: 90 additions & 0 deletions mysql-test/r/max_filesort_size.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
set @save_filesort_max_file_size = @@global.filesort_max_file_size;
create table t1 (i int, c char(255));
insert into t1 values (0, lpad('a', 250, 'b'));
insert into t1 select i+1,c from t1;
insert into t1 select i+2,c from t1;
insert into t1 select i+4,c from t1;
insert into t1 select i+8,c from t1;
insert into t1 select i+16,c from t1;
insert into t1 select i+32,c from t1;
insert into t1 select i+64,c from t1;
insert into t1 select i+128,c from t1;
insert into t1 select i+256,c from t1;
insert into t1 select i+512,c from t1;
insert into t1 select i+1024,c from t1;
insert into t1 select i+2048,c from t1;
Query is OK when there is no limit
show variables like "filesort_max_file_size";
Variable_name Value
filesort_max_file_size 0
show session variables like "filesort_max_file_size";
Variable_name Value
filesort_max_file_size 0
show global variables like "filesort_max_file_size";
Variable_name Value
filesort_max_file_size 0
explain select i, c from t1 order by hex(c) limit 1 offset 4000;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 4096 100.00 Using filesort
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`i` AS `i`,`test`.`t1`.`c` AS `c` from `test`.`t1` order by hex(`test`.`t1`.`c`) limit 4000,1
select i, c from t1 order by hex(c) limit 1 offset 4000;
i c
2102 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbba
select /*+ SET_VAR(filesort_max_file_size = 1000000) */ i, c from t1 order by hex(c) limit 1 offset 4000;
ERROR HY000: Filesort file is too big
Query fails with a limit
set session filesort_max_file_size=1000000;
show variables like "filesort_max_file_size";
Variable_name Value
filesort_max_file_size 1000000
show session variables like "filesort_max_file_size";
Variable_name Value
filesort_max_file_size 1000000
show global variables like "filesort_max_file_size";
Variable_name Value
filesort_max_file_size 0
select i, c from t1 order by hex(c) limit 1 offset 4000;
ERROR HY000: Filesort file is too big
Query is OK when another session has a limit
show variables like "filesort_max_file_size";
Variable_name Value
filesort_max_file_size 0
show session variables like "filesort_max_file_size";
Variable_name Value
filesort_max_file_size 0
show global variables like "filesort_max_file_size";
Variable_name Value
filesort_max_file_size 0
select i, c from t1 order by hex(c) limit 1 offset 4000;
i c
2102 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbba
Query is OK when session limit is reset
set session filesort_max_file_size=0;
show variables like "filesort_max_file_size";
Variable_name Value
filesort_max_file_size 0
show session variables like "filesort_max_file_size";
Variable_name Value
filesort_max_file_size 0
show global variables like "filesort_max_file_size";
Variable_name Value
filesort_max_file_size 0
select i, c from t1 order by hex(c) limit 1 offset 4000;
i c
2102 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbba
Query fails when global limit is set
set global filesort_max_file_size=1000000;
show variables like "filesort_max_file_size";
Variable_name Value
filesort_max_file_size 1000000
show session variables like "filesort_max_file_size";
Variable_name Value
filesort_max_file_size 1000000
show global variables like "filesort_max_file_size";
Variable_name Value
filesort_max_file_size 1000000
select i, c from t1 order by hex(c) limit 1 offset 4000;
ERROR HY000: Filesort file is too big
drop table t1;
set @@global.filesort_max_file_size = @save_filesort_max_file_size;
4 changes: 4 additions & 0 deletions mysql-test/r/mysqld--help-notwin.result
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,9 @@ The following options may be given as the first argument:
With this option enabled you can run myisamchk to test
(not repair) tables while the MySQL server is running.
Disable with --skip-external-locking.
--filesort-max-file-size=#
The max size of a file to use for filesort. Raise an
error when this is exceeded. 0 means no limit.
--flush Flush MyISAM tables to disk between SQL commands
--flush-time=# A dedicated thread is created to flush all tables at the
given interval
Expand Down Expand Up @@ -1496,6 +1499,7 @@ event-scheduler ON
expire-logs-days 0
explicit-defaults-for-timestamp TRUE
external-locking FALSE
filesort-max-file-size 0
flush FALSE
flush-time 0
ft-boolean-syntax + -><()~*:""&|
Expand Down
118 changes: 118 additions & 0 deletions mysql-test/suite/sys_vars/r/filesort_max_file_size_basic.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
SET @start_global_value = @@global.filesort_max_file_size;
'#--------------------FN_DYNVARS_005_01-------------------------#'
SET @@global.filesort_max_file_size = 100;
SET @@global.filesort_max_file_size = DEFAULT;
SET @@session.filesort_max_file_size = 200;
SET @@session.filesort_max_file_size = DEFAULT;
'#--------------------FN_DYNVARS_005_02-------------------------#'
SELECT @@global.filesort_max_file_size = 0;
@@global.filesort_max_file_size = 0
1
SELECT @@session.filesort_max_file_size = 0;
@@session.filesort_max_file_size = 0
1
'#--------------------FN_DYNVARS_005_03-------------------------#'
SET @@global.filesort_max_file_size = 1024;
SELECT @@global.filesort_max_file_size;
@@global.filesort_max_file_size
1024
SET @@global.filesort_max_file_size = 60020;
SELECT @@global.filesort_max_file_size;
@@global.filesort_max_file_size
60020
SET @@global.filesort_max_file_size = 4294967295;
SELECT @@global.filesort_max_file_size;
@@global.filesort_max_file_size
4294967295
'#--------------------FN_DYNVARS_005_04-------------------------#'
SET @@session.filesort_max_file_size = 1024;
SELECT @@session.filesort_max_file_size;
@@session.filesort_max_file_size
1024
SET @@session.filesort_max_file_size = 4294967295;
SELECT @@session.filesort_max_file_size;
@@session.filesort_max_file_size
4294967295
SET @@session.filesort_max_file_size = 65535;
SELECT @@session.filesort_max_file_size;
@@session.filesort_max_file_size
65535
'#------------------FN_DYNVARS_005_05-----------------------#'
SET @@global.filesort_max_file_size = -1024;
Warnings:
Warning 1292 Truncated incorrect filesort_max_file_size value: '-1024'
SELECT @@global.filesort_max_file_size;
@@global.filesort_max_file_size
0
SET @@global.filesort_max_file_size = ON;
ERROR 42000: Incorrect argument type to variable 'filesort_max_file_size'
SET @@global.filesort_max_file_size = OFF;
ERROR 42000: Incorrect argument type to variable 'filesort_max_file_size'
SET @@global.filesort_max_file_size = True;
SELECT @@global.filesort_max_file_size;
@@global.filesort_max_file_size
1
SET @@global.filesort_max_file_size = False;
SELECT @@global.filesort_max_file_size;
@@global.filesort_max_file_size
0
SET @@global.filesort_max_file_size = 65530.34;
ERROR 42000: Incorrect argument type to variable 'filesort_max_file_size'
SET @@global.filesort_max_file_size ="Test";
ERROR 42000: Incorrect argument type to variable 'filesort_max_file_size'
SET @@session.filesort_max_file_size = ON;
ERROR 42000: Incorrect argument type to variable 'filesort_max_file_size'
SET @@session.filesort_max_file_size = OFF;
ERROR 42000: Incorrect argument type to variable 'filesort_max_file_size'
SET @@session.filesort_max_file_size = True;
SELECT @@session.filesort_max_file_size;
@@session.filesort_max_file_size
1
SET @@session.filesort_max_file_size = False;
SELECT @@session.filesort_max_file_size;
@@session.filesort_max_file_size
0
SET @@session.filesort_max_file_size = "Test";
ERROR 42000: Incorrect argument type to variable 'filesort_max_file_size'
SET @@session.filesort_max_file_size = 12345678901;
SELECT @@session.filesort_max_file_size IN (12345678901,4294967295);
@@session.filesort_max_file_size IN (12345678901,4294967295)
1
'#------------------FN_DYNVARS_005_06-----------------------#'
SELECT @@global.filesort_max_file_size = VARIABLE_VALUE
FROM performance_schema.global_variables
WHERE VARIABLE_NAME='filesort_max_file_size';
@@global.filesort_max_file_size = VARIABLE_VALUE
1
'#------------------FN_DYNVARS_005_07-----------------------#'
SELECT @@session.filesort_max_file_size = VARIABLE_VALUE
FROM performance_schema.session_variables
WHERE VARIABLE_NAME='filesort_max_file_size';
@@session.filesort_max_file_size = VARIABLE_VALUE
1
'#---------------------FN_DYNVARS_001_09----------------------#'
SET @@global.filesort_max_file_size = 1024;
SET @@filesort_max_file_size = 4294967295;
SELECT @@filesort_max_file_size = @@global.filesort_max_file_size;
@@filesort_max_file_size = @@global.filesort_max_file_size
0
'#---------------------FN_DYNVARS_001_10----------------------#'
SET @@filesort_max_file_size = 100;
SELECT @@filesort_max_file_size = @@local.filesort_max_file_size;
@@filesort_max_file_size = @@local.filesort_max_file_size
1
SELECT @@local.filesort_max_file_size = @@session.filesort_max_file_size;
@@local.filesort_max_file_size = @@session.filesort_max_file_size
1
'#---------------------FN_DYNVARS_001_11----------------------#'
SET filesort_max_file_size = 1027;
SELECT @@filesort_max_file_size;
@@filesort_max_file_size
1027
SELECT local.filesort_max_file_size;
ERROR 42S02: Unknown table 'local' in field list
SELECT global.filesort_max_file_size;
ERROR 42S02: Unknown table 'global' in field list
SELECT filesort_max_file_size = @@session.filesort_max_file_size;
ERROR 42S22: Unknown column 'filesort_max_file_size' in 'field list'
SET @@global.filesort_max_file_size = @start_global_value;
Loading

0 comments on commit 7f595e0

Please sign in to comment.