Skip to content

Commit f7387cb

Browse files
MDEV-37784 Introduce @@new_mode variable
@@new_mode is a set of flags to control introduced features. Flags are by default off. Setting a flag in @@new_mode will introduce a new different server behaviour and/or set of features. We also introduce a new option 'hidden_values' into some system variable types to hide options that we do not wish to show as options. - Don't print hidden values in mysqld --help output. - Make get_options() use the same logic as check_new_mode_value() does. - Setting @@new_mode=ALL shouldn't give warnings.
1 parent d71b2a7 commit f7387cb

File tree

19 files changed

+351
-25
lines changed

19 files changed

+351
-25
lines changed

include/typelib.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ typedef struct st_typelib { /* Different types saved here */
2525
const char *name; /* Name of typelib */
2626
const char **type_names;
2727
unsigned int *type_lengths;
28+
const int *hidden_values;
2829
} TYPELIB;
2930

30-
#define CREATE_TYPELIB_FOR(X) { (unsigned int)(sizeof(X)/sizeof(X[0])) - 1, "", X, NULL }
31+
#define CREATE_TYPELIB_FOR(X) { (unsigned int)(sizeof(X)/sizeof(X[0])) - 1, "", X, NULL, NULL }
3132

3233
extern my_ulonglong find_typeset(const char *x, TYPELIB *typelib,
3334
int *error_position);

mysql-test/main/mysqld--help.result

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,9 @@ The following specify which files/extra groups are read (specified before remain
774774
--net-write-timeout=#
775775
Number of seconds to wait for a block to be written to a
776776
connection before aborting the write
777+
--new-mode=name Used to introduce new behavior to existing MariaDB
778+
versions. Any combination of: FIX_DISK_TMPTABLE_COSTS, or
779+
ALL to set all combinations
777780
--note-verbosity=name
778781
Verbosity level for note-warnings given to the user. See
779782
also @@sql_notes. Any combination of: basic,
@@ -1861,6 +1864,7 @@ net-buffer-length 16384
18611864
net-read-timeout 30
18621865
net-retry-count 10
18631866
net-write-timeout 60
1867+
new-mode
18641868
note-verbosity basic,explain
18651869
old FALSE
18661870
old-mode UTF8_IS_UTF8MB3
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
SET @global_start_value = @@global.new_mode;
2+
SELECT @global_start_value;
3+
@global_start_value
4+
5+
SET @session_start_value = @@session.new_mode;
6+
SELECT @session_start_value;
7+
@session_start_value
8+
9+
SET @@global.new_mode = "FIX_DISK_TMPTABLE_COSTS";
10+
SELECT @@global.new_mode;
11+
@@global.new_mode
12+
FIX_DISK_TMPTABLE_COSTS
13+
SELECT @@session.new_mode;
14+
@@session.new_mode
15+
16+
SET @@global.new_mode = DEFAULT;
17+
SELECT @@global.new_mode;
18+
@@global.new_mode
19+
20+
SELECT @@session.new_mode;
21+
@@session.new_mode
22+
23+
SET @@session.new_mode = "FIX_DISK_TMPTABLE_COSTS,TEST_WARNING1";
24+
Warnings:
25+
Warning 4209 'TEST_WARNING1' is default and ignored
26+
SET @@session.new_mode = "FIX_DISK_TMPTABLE_COSTS,TEST_WARNING1,TEST_WARNING2";
27+
Warnings:
28+
Warning 4209 'TEST_WARNING1' is default and ignored
29+
Warning 4209 'TEST_WARNING2' is default and ignored
30+
SET @@session.new_mode = "FIX_DISK_TMPTABLE_COSTS,TEST_WARNING1,TEST_WARNING2,TEST_WARNING3";
31+
ERROR 42000: Variable 'new_mode' can't be set to the value of 'TEST_WARNING3'
32+
SET @@session.new_mode = "ALL";
33+
select @@session.new_mode;
34+
@@session.new_mode
35+
FIX_DISK_TMPTABLE_COSTS
36+
SET @@global.new_mode = NULL;
37+
ERROR 42000: Variable 'new_mode' can't be set to the value of 'NULL'
38+
SET @@global.new_mode = '';
39+
SELECT @@global.new_mode;
40+
@@global.new_mode
41+
42+
SET @@global.new_mode = ' ';
43+
SELECT @@global.new_mode;
44+
@@global.new_mode
45+
46+
SET @@session.new_mode = NULL;
47+
ERROR 42000: Variable 'new_mode' can't be set to the value of 'NULL'
48+
SET @@session.new_mode = '';
49+
SELECT @@session.new_mode;
50+
@@session.new_mode
51+
52+
SET @@session.new_mode = ' ';
53+
SELECT @@session.new_mode;
54+
@@session.new_mode
55+
56+
SET @@global.new_mode = OFF;
57+
ERROR 42000: Variable 'new_mode' can't be set to the value of 'OFF'
58+
SET @@session.new_mode = OFF;
59+
ERROR 42000: Variable 'new_mode' can't be set to the value of 'OFF'
60+
SET @debug_dbug_safe = @@global.debug_dbug;
61+
SET @@global.debug_dbug = 'd,check_new_mode_mdev_37784';
62+
create table t1 (a int);
63+
insert into t1 values (1), (2);
64+
create table t2 (b int);
65+
insert into t2 values (3), (4);
66+
select * from t1 where a in (select b from t2);
67+
a
68+
SET @@new_mode = "FIX_DISK_TMPTABLE_COSTS";
69+
select * from t1 where a in (select b from t2);
70+
a
71+
Warnings:
72+
Note 1003 YES
73+
Note 1003 YES
74+
drop table t1, t2;
75+
SET @@global.debug_dbug = @debug_dbug_safe;
76+
SET @@global.new_mode = @global_start_value;
77+
SELECT @@global.new_mode;
78+
@@global.new_mode
79+
80+
SET @@session.new_mode = @session_start_value;
81+
SELECT @@session.new_mode;
82+
@@session.new_mode
83+

mysql-test/suite/sys_vars/r/sysvars_server_embedded.result

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2392,6 +2392,16 @@ NUMERIC_BLOCK_SIZE 1
23922392
ENUM_VALUE_LIST NULL
23932393
READ_ONLY NO
23942394
COMMAND_LINE_ARGUMENT REQUIRED
2395+
VARIABLE_NAME NEW_MODE
2396+
VARIABLE_SCOPE SESSION
2397+
VARIABLE_TYPE SET
2398+
VARIABLE_COMMENT Used to introduce new behavior to existing MariaDB versions
2399+
NUMERIC_MIN_VALUE NULL
2400+
NUMERIC_MAX_VALUE NULL
2401+
NUMERIC_BLOCK_SIZE NULL
2402+
ENUM_VALUE_LIST FIX_DISK_TMPTABLE_COSTS
2403+
READ_ONLY NO
2404+
COMMAND_LINE_ARGUMENT REQUIRED
23952405
VARIABLE_NAME NOTE_VERBOSITY
23962406
VARIABLE_SCOPE SESSION
23972407
VARIABLE_TYPE SET

mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2602,6 +2602,16 @@ NUMERIC_BLOCK_SIZE 1
26022602
ENUM_VALUE_LIST NULL
26032603
READ_ONLY NO
26042604
COMMAND_LINE_ARGUMENT REQUIRED
2605+
VARIABLE_NAME NEW_MODE
2606+
VARIABLE_SCOPE SESSION
2607+
VARIABLE_TYPE SET
2608+
VARIABLE_COMMENT Used to introduce new behavior to existing MariaDB versions
2609+
NUMERIC_MIN_VALUE NULL
2610+
NUMERIC_MAX_VALUE NULL
2611+
NUMERIC_BLOCK_SIZE NULL
2612+
ENUM_VALUE_LIST FIX_DISK_TMPTABLE_COSTS
2613+
READ_ONLY NO
2614+
COMMAND_LINE_ARGUMENT REQUIRED
26052615
VARIABLE_NAME NOTE_VERBOSITY
26062616
VARIABLE_SCOPE SESSION
26072617
VARIABLE_TYPE SET
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
--source include/load_sysvars.inc
2+
--source include/have_debug.inc
3+
4+
SET @global_start_value = @@global.new_mode;
5+
SELECT @global_start_value;
6+
7+
SET @session_start_value = @@session.new_mode;
8+
SELECT @session_start_value;
9+
10+
SET @@global.new_mode = "FIX_DISK_TMPTABLE_COSTS";
11+
SELECT @@global.new_mode;
12+
SELECT @@session.new_mode;
13+
SET @@global.new_mode = DEFAULT;
14+
SELECT @@global.new_mode;
15+
SELECT @@session.new_mode;
16+
17+
SET @@session.new_mode = "FIX_DISK_TMPTABLE_COSTS,TEST_WARNING1";
18+
SET @@session.new_mode = "FIX_DISK_TMPTABLE_COSTS,TEST_WARNING1,TEST_WARNING2";
19+
--Error ER_WRONG_VALUE_FOR_VAR
20+
SET @@session.new_mode = "FIX_DISK_TMPTABLE_COSTS,TEST_WARNING1,TEST_WARNING2,TEST_WARNING3";
21+
22+
SET @@session.new_mode = "ALL";
23+
select @@session.new_mode;
24+
25+
--Error ER_WRONG_VALUE_FOR_VAR
26+
SET @@global.new_mode = NULL;
27+
28+
SET @@global.new_mode = '';
29+
SELECT @@global.new_mode;
30+
31+
SET @@global.new_mode = ' ';
32+
SELECT @@global.new_mode;
33+
34+
--Error ER_WRONG_VALUE_FOR_VAR
35+
SET @@session.new_mode = NULL;
36+
37+
SET @@session.new_mode = '';
38+
SELECT @@session.new_mode;
39+
40+
SET @@session.new_mode = ' ';
41+
SELECT @@session.new_mode;
42+
43+
--Error ER_WRONG_VALUE_FOR_VAR
44+
SET @@global.new_mode = OFF;
45+
46+
--Error ER_WRONG_VALUE_FOR_VAR
47+
SET @@session.new_mode = OFF;
48+
49+
SET @debug_dbug_safe = @@global.debug_dbug;
50+
SET @@global.debug_dbug = 'd,check_new_mode_mdev_37784';
51+
52+
create table t1 (a int);
53+
insert into t1 values (1), (2);
54+
create table t2 (b int);
55+
insert into t2 values (3), (4);
56+
select * from t1 where a in (select b from t2);
57+
SET @@new_mode = "FIX_DISK_TMPTABLE_COSTS";
58+
select * from t1 where a in (select b from t2);
59+
drop table t1, t2;
60+
61+
SET @@global.debug_dbug = @debug_dbug_safe;
62+
63+
SET @@global.new_mode = @global_start_value;
64+
SELECT @@global.new_mode;
65+
66+
SET @@session.new_mode = @session_start_value;
67+
SELECT @@session.new_mode;

mysys/my_getopt.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,6 +1684,22 @@ void my_print_help(const struct my_option *options)
16841684
col= print_comment(optp->typelib->type_names[0], col, name_space, comment_space);
16851685
for (i= 1; i < count; i++)
16861686
{
1687+
my_bool skip_value= 0;
1688+
/* Do not print the value if it is listed in hidden_values */
1689+
if (optp->typelib->hidden_values)
1690+
{
1691+
for (const int *value= optp->typelib->hidden_values;
1692+
*value >= 0; value++)
1693+
{
1694+
if (*value == (int)i)
1695+
{
1696+
skip_value= 1;
1697+
break;
1698+
}
1699+
}
1700+
}
1701+
if (skip_value)
1702+
continue;
16871703
col= print_comment(", ", col, name_space, comment_space);
16881704
col= print_comment(optp->typelib->type_names[i], col, name_space, comment_space);
16891705
}

sql/handler.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ const char *tx_isolation_names[]=
155155
NullS};
156156
TYPELIB tx_isolation_typelib= CREATE_TYPELIB_FOR(tx_isolation_names);
157157

158-
static TYPELIB known_extensions= {0,"known_exts", NULL, NULL};
158+
static TYPELIB known_extensions= {0,"known_exts", NULL, NULL, NULL};
159159
uint known_extensions_id= 0;
160160

161161

sql/mysqld.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ static const char *tc_heuristic_recover_names[]=
301301
static TYPELIB tc_heuristic_recover_typelib=
302302
{
303303
array_elements(tc_heuristic_recover_names)-1,"",
304-
tc_heuristic_recover_names, NULL
304+
tc_heuristic_recover_names, NULL, NULL
305305
};
306306

307307
const char *first_keyword= "first";
@@ -8755,6 +8755,9 @@ static void option_error_reporter(enum loglevel level, const char *format, ...)
87558755

87568756
C_MODE_END
87578757

8758+
extern const char **new_mode_default_names;
8759+
8760+
87588761
/**
87598762
Get server options from the command line,
87608763
and perform related server initializations.
@@ -8813,6 +8816,8 @@ static int get_options(int *argc_ptr, char ***argv_ptr)
88138816
OLD_MODE_COMPAT_5_1_CHECKSUM);
88148817
}
88158818

8819+
check_new_mode_value(NULL, &global_system_variables.new_behavior);
8820+
88168821
if (global_system_variables.net_buffer_length >
88178822
global_system_variables.max_allowed_packet)
88188823
{

sql/opt_subselect.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2767,6 +2767,15 @@ get_tmp_table_costs(THD *thd, double row_count, uint row_size, bool blobs_used,
27672767
row_size+= sizeof(char*)*2;
27682768
row_size= MY_ALIGN(MY_MAX(row_size, sizeof(char*)) + 1, sizeof(char*));
27692769

2770+
/* remove this once TEST_NEW_MODE_FLAG is used elsewhere */
2771+
DBUG_EXECUTE_IF("check_new_mode_mdev_37784",
2772+
{
2773+
if (TEST_NEW_MODE_FLAG(thd, NEW_MODE_FIX_DISK_TMPTABLE_COSTS))
2774+
{
2775+
push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, ER_YES, "YES" );
2776+
}
2777+
});
2778+
27702779
if (row_count > thd->variables.max_heap_table_size / (double) row_size ||
27712780
blobs_used)
27722781
{

0 commit comments

Comments
 (0)