Commit aa052eeb authored by Igor Babaev's avatar Igor Babaev

Merge mwl253 -> 10.0-base

parents 30b2c64c b12b3cae
......@@ -208,6 +208,13 @@ The following options may be given as the first argument:
use a distinct domain_id. For simple tree-shaped
replication topologies, it can be left at its default, 0.
-?, --help Display this help and exit.
--histogram-size=# Number of bytes used for a histogram. If set to 0, no
histograms are created by ANALYZE.
--histogram-type=name
Specifies type of the histograms created by ANALYZE.
Possible values are: SINGLE_PREC_HB - single precision
height-balanced, DOUBLE_PREC_HB - double precision
height-balanced.
--ignore-builtin-innodb
Disable initialization of builtin InnoDB plugin
--ignore-db-dirs=name
......@@ -506,6 +513,21 @@ The following options may be given as the first argument:
partial_match_table_scan, semijoin, semijoin_with_cache,
subquery_cache, table_elimination, extended_keys,
exists_to_in } and val is one of {on, off, default}
--optimizer-use-condition-selectivity=#
Controls selectivity of which conditions the optimizer
takes into account to calculate cardinality of a partial
join when it searches for the best execution plan
Meaning: 1 - use selectivity of index backed range
conditions to calculate the cardinality of a partial join
if the last joined table is accessed by full table scan
or an index scan, 2 - use selectivity of index backed
range conditions to calculate the cardinality of a
partial join in any case, 3 - additionally always use
selectivity of range conditions that are not backed by
any index to calculate the cardinality of a partial join,
4 - use histograms to calculate selectivity of range
conditions that are not backed by any index to calculate
the cardinality of a partial join.
--performance-schema
Enable the performance schema.
--performance-schema-events-waits-history-long-size=#
......@@ -940,6 +962,8 @@ general-log FALSE
group-concat-max-len 1024
gtid-domain-id 0
help TRUE
histogram-size 0
histogram-type SINGLE_PREC_HB
ignore-builtin-innodb FALSE
ignore-db-dirs
init-connect
......@@ -1030,6 +1054,7 @@ old-style-user-limits FALSE
optimizer-prune-level 1
optimizer-search-depth 62
optimizer-switch index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on
optimizer-use-condition-selectivity 1
performance-schema FALSE
performance-schema-events-waits-history-long-size 10000
performance-schema-events-waits-history-size 10
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -287,6 +287,9 @@ column_stats CREATE TABLE `column_stats` (
`nulls_ratio` decimal(12,4) DEFAULT NULL,
`avg_length` decimal(12,4) DEFAULT NULL,
`avg_frequency` decimal(12,4) DEFAULT NULL,
`hist_size` tinyint(3) unsigned DEFAULT NULL,
`hist_type` enum('SINGLE_PREC_HB','DOUBLE_PREC_HB') COLLATE utf8_bin DEFAULT NULL,
`histogram` varbinary(255) DEFAULT NULL,
PRIMARY KEY (`db_name`,`table_name`,`column_name`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Statistics on Columns'
show create table index_stats;
......
......@@ -13,6 +13,9 @@ def mysql column_stats avg_frequency 8 NULL YES decimal NULL NULL 12 4 NULL NULL
def mysql column_stats avg_length 7 NULL YES decimal NULL NULL 12 4 NULL NULL NULL decimal(12,4) select,insert,update,references
def mysql column_stats column_name 3 NULL NO varchar 64 192 NULL NULL NULL utf8 utf8_bin varchar(64) PRI select,insert,update,references
def mysql column_stats db_name 1 NULL NO varchar 64 192 NULL NULL NULL utf8 utf8_bin varchar(64) PRI select,insert,update,references
def mysql column_stats histogram 11 NULL YES varbinary 255 255 NULL NULL NULL NULL NULL varbinary(255) select,insert,update,references
def mysql column_stats hist_size 9 NULL YES tinyint NULL NULL 3 0 NULL NULL NULL tinyint(3) unsigned select,insert,update,references
def mysql column_stats hist_type 10 NULL YES enum 14 42 NULL NULL NULL utf8 utf8_bin enum('SINGLE_PREC_HB','DOUBLE_PREC_HB') select,insert,update,references
def mysql column_stats max_value 5 NULL YES varchar 255 765 NULL NULL NULL utf8 utf8_bin varchar(255) select,insert,update,references
def mysql column_stats min_value 4 NULL YES varchar 255 765 NULL NULL NULL utf8 utf8_bin varchar(255) select,insert,update,references
def mysql column_stats nulls_ratio 6 NULL YES decimal NULL NULL 12 4 NULL NULL NULL decimal(12,4) select,insert,update,references
......@@ -260,6 +263,7 @@ ORDER BY CHARACTER_SET_NAME, COLLATION_NAME, COL_CML;
COL_CML DATA_TYPE CHARACTER_SET_NAME COLLATION_NAME
1.0000 blob NULL NULL
1.0000 longblob NULL NULL
1.0000 varbinary NULL NULL
1.0000 char latin1 latin1_bin
1.0000 char latin1 latin1_swedish_ci
1.0000 varchar latin1 latin1_swedish_ci
......@@ -332,6 +336,9 @@ NULL mysql columns_priv Timestamp timestamp NULL NULL NULL NULL timestamp
NULL mysql column_stats nulls_ratio decimal NULL NULL NULL NULL decimal(12,4)
NULL mysql column_stats avg_length decimal NULL NULL NULL NULL decimal(12,4)
NULL mysql column_stats avg_frequency decimal NULL NULL NULL NULL decimal(12,4)
NULL mysql column_stats hist_size tinyint NULL NULL NULL NULL tinyint(3) unsigned
3.0000 mysql column_stats hist_type enum 14 42 utf8 utf8_bin enum('SINGLE_PREC_HB','DOUBLE_PREC_HB')
1.0000 mysql column_stats histogram varbinary 255 255 NULL NULL varbinary(255)
3.0000 mysql db Host char 60 180 utf8 utf8_bin char(60)
3.0000 mysql db Db char 64 192 utf8 utf8_bin char(64)
3.0000 mysql db User char 16 48 utf8 utf8_bin char(16)
......
......@@ -13,6 +13,9 @@ def mysql column_stats avg_frequency 8 NULL YES decimal NULL NULL 12 4 NULL NULL
def mysql column_stats avg_length 7 NULL YES decimal NULL NULL 12 4 NULL NULL NULL decimal(12,4)
def mysql column_stats column_name 3 NULL NO varchar 64 192 NULL NULL NULL utf8 utf8_bin varchar(64) PRI
def mysql column_stats db_name 1 NULL NO varchar 64 192 NULL NULL NULL utf8 utf8_bin varchar(64) PRI
def mysql column_stats histogram 11 NULL YES varbinary 255 255 NULL NULL NULL NULL NULL varbinary(255)
def mysql column_stats hist_size 9 NULL YES tinyint NULL NULL 3 0 NULL NULL NULL tinyint(3) unsigned
def mysql column_stats hist_type 10 NULL YES enum 14 42 NULL NULL NULL utf8 utf8_bin enum('SINGLE_PREC_HB','DOUBLE_PREC_HB')
def mysql column_stats max_value 5 NULL YES varchar 255 765 NULL NULL NULL utf8 utf8_bin varchar(255)
def mysql column_stats min_value 4 NULL YES varchar 255 765 NULL NULL NULL utf8 utf8_bin varchar(255)
def mysql column_stats nulls_ratio 6 NULL YES decimal NULL NULL 12 4 NULL NULL NULL decimal(12,4)
......@@ -260,6 +263,7 @@ ORDER BY CHARACTER_SET_NAME, COLLATION_NAME, COL_CML;
COL_CML DATA_TYPE CHARACTER_SET_NAME COLLATION_NAME
1.0000 blob NULL NULL
1.0000 longblob NULL NULL
1.0000 varbinary NULL NULL
1.0000 char latin1 latin1_bin
1.0000 char latin1 latin1_swedish_ci
1.0000 varchar latin1 latin1_swedish_ci
......@@ -332,6 +336,9 @@ NULL mysql columns_priv Timestamp timestamp NULL NULL NULL NULL timestamp
NULL mysql column_stats nulls_ratio decimal NULL NULL NULL NULL decimal(12,4)
NULL mysql column_stats avg_length decimal NULL NULL NULL NULL decimal(12,4)
NULL mysql column_stats avg_frequency decimal NULL NULL NULL NULL decimal(12,4)
NULL mysql column_stats hist_size tinyint NULL NULL NULL NULL tinyint(3) unsigned
3.0000 mysql column_stats hist_type enum 14 42 utf8 utf8_bin enum('SINGLE_PREC_HB','DOUBLE_PREC_HB')
1.0000 mysql column_stats histogram varbinary 255 255 NULL NULL varbinary(255)
3.0000 mysql db Host char 60 180 utf8 utf8_bin char(60)
3.0000 mysql db Db char 64 192 utf8 utf8_bin char(64)
3.0000 mysql db User char 16 48 utf8 utf8_bin char(16)
......
SET @start_global_value = @@global.histogram_size;
SELECT @start_global_value;
@start_global_value
0
SET @start_session_value = @@session.histogram_size;
SELECT @start_session_value;
@start_session_value
0
'#--------------------FN_DYNVARS_053_01-------------------------#'
SET @@global.histogram_size = DEFAULT;
SELECT @@global.histogram_size;
@@global.histogram_size
0
SET @@session.histogram_size = DEFAULT;
SELECT @@session.histogram_size;
@@session.histogram_size
0
'#--------------------FN_DYNVARS_053_03-------------------------#'
SET @@global.histogram_size = 1;
SELECT @@global.histogram_size;
@@global.histogram_size
1
SET @@global.histogram_size = 31;
SELECT @@global.histogram_size;
@@global.histogram_size
31
SET @@global.histogram_size = 255;
SELECT @@global.histogram_size;
@@global.histogram_size
255
'#--------------------FN_DYNVARS_053_04-------------------------#'
SET @@session.histogram_size = 1;
SELECT @@session.histogram_size;
@@session.histogram_size
1
SET @@session.histogram_size = 31;
SELECT @@session.histogram_size;
@@session.histogram_size
31
SET @@session.histogram_size = 255;
SELECT @@session.histogram_size;
@@session.histogram_size
255
'#------------------FN_DYNVARS_053_05-----------------------#'
SET @@global.histogram_size = -1;
Warnings:
Warning 1292 Truncated incorrect histogram_size value: '-1'
SELECT @@global.histogram_size;
@@global.histogram_size
0
SET @@global.histogram_size = 256;
Warnings:
Warning 1292 Truncated incorrect histogram_size value: '256'
SELECT @@global.histogram_size;
@@global.histogram_size
255
SET @@global.histogram_size = 1024;
Warnings:
Warning 1292 Truncated incorrect histogram_size value: '1024'
SELECT @@global.histogram_size;
@@global.histogram_size
255
SET @@global.histogram_size = 4.5;
ERROR 42000: Incorrect argument type to variable 'histogram_size'
SELECT @@global.histogram_size;
@@global.histogram_size
255
SET @@global.histogram_size = test;
ERROR 42000: Incorrect argument type to variable 'histogram_size'
SELECT @@global.histogram_size;
@@global.histogram_size
255
SET @@session.histogram_size = -1;
Warnings:
Warning 1292 Truncated incorrect histogram_size value: '-1'
SELECT @@session.histogram_size;
@@session.histogram_size
0
SET @@session.histogram_size = 256;
Warnings:
Warning 1292 Truncated incorrect histogram_size value: '256'
SELECT @@session.histogram_size;
@@session.histogram_size
255
SET @@session.histogram_size = 1024;
Warnings:
Warning 1292 Truncated incorrect histogram_size value: '1024'
SELECT @@session.histogram_size;
@@session.histogram_size
255
SET @@session.histogram_size = 4.5;
ERROR 42000: Incorrect argument type to variable 'histogram_size'
SELECT @@session.histogram_size;
@@session.histogram_size
255
SET @@session.histogram_size = test;
ERROR 42000: Incorrect argument type to variable 'histogram_size'
SELECT @@session.histogram_size;
@@session.histogram_size
255
'#------------------FN_DYNVARS_053_06-----------------------#'
SELECT @@global.histogram_size = VARIABLE_VALUE
FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
WHERE VARIABLE_NAME='histogram_size';
@@global.histogram_size = VARIABLE_VALUE
1
'#------------------FN_DYNVARS_053_07-----------------------#'
SELECT @@session.histogram_size = VARIABLE_VALUE
FROM INFORMATION_SCHEMA.SESSION_VARIABLES
WHERE VARIABLE_NAME='histogram_size';
@@session.histogram_size = VARIABLE_VALUE
1
'#------------------FN_DYNVARS_053_08-----------------------#'
SET @@global.histogram_size = TRUE;
SET @@global.histogram_size = FALSE;
'#---------------------FN_DYNVARS_001_09----------------------#'
SET @@global.histogram_size = 10;
SELECT @@histogram_size = @@global.histogram_size;
@@histogram_size = @@global.histogram_size
0
'#---------------------FN_DYNVARS_001_10----------------------#'
SET @@histogram_size = 100;
SELECT @@histogram_size = @@local.histogram_size;
@@histogram_size = @@local.histogram_size
1
SELECT @@local.histogram_size = @@session.histogram_size;
@@local.histogram_size = @@session.histogram_size
1
SET @@global.histogram_size = @start_global_value;
SELECT @@global.histogram_size;
@@global.histogram_size
0
SET @@session.histogram_size = @start_session_value;
SELECT @@session.histogram_size;
@@session.histogram_size
0
SET @start_global_value = @@global.histogram_type;
SELECT @start_global_value;
@start_global_value
SINGLE_PREC_HB
SET @start_session_value = @@session.histogram_type;
SELECT @start_session_value;
@start_session_value
SINGLE_PREC_HB
SET @@global.histogram_type = 1;
SET @@global.histogram_type = DEFAULT;
SELECT @@global.histogram_type;
@@global.histogram_type
SINGLE_PREC_HB
SET @@global.histogram_type = 0;
SELECT @@global.histogram_type;
@@global.histogram_type
SINGLE_PREC_HB
SET @@global.histogram_type = 1;
SELECT @@global.histogram_type;
@@global.histogram_type
DOUBLE_PREC_HB
SET @@global.histogram_type = SINGLE_PREC_HB;
SELECT @@global.histogram_type;
@@global.histogram_type
SINGLE_PREC_HB
SET @@global.histogram_type = DOUBLE_PREC_HB;
SELECT @@global.histogram_type;
@@global.histogram_type
DOUBLE_PREC_HB
SET @@session.histogram_type = 0;
SELECT @@session.histogram_type;
@@session.histogram_type
SINGLE_PREC_HB
SET @@session.histogram_type = 1;
SELECT @@session.histogram_type;
@@session.histogram_type
DOUBLE_PREC_HB
SET @@session.histogram_type = SINGLE_PREC_HB;
SELECT @@session.histogram_type;
@@session.histogram_type
SINGLE_PREC_HB
SET @@session.histogram_type = DOUBLE_PREC_HB;
SELECT @@session.histogram_type;
@@session.histogram_type
DOUBLE_PREC_HB
set sql_mode=TRADITIONAL;
SET @@global.histogram_type = 10;
ERROR 42000: Variable 'histogram_type' can't be set to the value of '10'
SET @@global.histogram_type = -1024;
ERROR 42000: Variable 'histogram_type' can't be set to the value of '-1024'
SET @@global.histogram_type = 2.4;
ERROR 42000: Incorrect argument type to variable 'histogram_type'
SET @@global.histogram_type = OFF;
ERROR 42000: Variable 'histogram_type' can't be set to the value of 'OFF'
SET @@session.histogram_type = 10;
ERROR 42000: Variable 'histogram_type' can't be set to the value of '10'
SET @@session.histogram_type = -2;
ERROR 42000: Variable 'histogram_type' can't be set to the value of '-2'
SET @@session.histogram_type = 1.2;
ERROR 42000: Incorrect argument type to variable 'histogram_type'
SET @@session.histogram_type = ON;
ERROR 42000: Variable 'histogram_type' can't be set to the value of 'ON'
SELECT * FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
WHERE VARIABLE_NAME='histogram_type';
VARIABLE_NAME VARIABLE_VALUE
HISTOGRAM_TYPE DOUBLE_PREC_HB
SELECT * FROM INFORMATION_SCHEMA.SESSION_VARIABLES
WHERE VARIABLE_NAME='histogram_type';
VARIABLE_NAME VARIABLE_VALUE
HISTOGRAM_TYPE DOUBLE_PREC_HB
SET @@global.histogram_type = @start_global_value;
SELECT @@global.histogram_type;
@@global.histogram_type
SINGLE_PREC_HB
SET @@session.histogram_type = @start_session_value;
SELECT @@session.histogram_type;
@@session.histogram_type
SINGLE_PREC_HB
set sql_mode='';
SET @start_global_value = @@global.optimizer_use_condition_selectivity;
SELECT @start_global_value;
@start_global_value
1
SET @start_session_value = @@session.optimizer_use_condition_selectivity;
SELECT @start_session_value;
@start_session_value
1
'#--------------------FN_DYNVARS_115_01-------------------------#'
SET @@global.optimizer_use_condition_selectivity = DEFAULT;
SELECT @@global.optimizer_use_condition_selectivity;
@@global.optimizer_use_condition_selectivity
1
SET @@session.optimizer_use_condition_selectivity = DEFAULT;
SELECT @@session.optimizer_use_condition_selectivity;
@@session.optimizer_use_condition_selectivity
1
'#--------------------FN_DYNVARS_115_02-------------------------#'
SET @@global.optimizer_use_condition_selectivity = DEFAULT;
SELECT @@global.optimizer_use_condition_selectivity = 1;
@@global.optimizer_use_condition_selectivity = 1
1
SET @@session.optimizer_use_condition_selectivity = DEFAULT;
SELECT @@session.optimizer_use_condition_selectivity = 1;
@@session.optimizer_use_condition_selectivity = 1
1
'#--------------------FN_DYNVARS_115_03-------------------------#'
SELECT @@global.optimizer_use_condition_selectivity;
@@global.optimizer_use_condition_selectivity
1
SET @@global.optimizer_use_condition_selectivity = 1;
SELECT @@global.optimizer_use_condition_selectivity;
@@global.optimizer_use_condition_selectivity
1
SET @@global.optimizer_use_condition_selectivity = 2;
SELECT @@global.optimizer_use_condition_selectivity;
@@global.optimizer_use_condition_selectivity
2
SET @@global.optimizer_use_condition_selectivity = 3;
SELECT @@global.optimizer_use_condition_selectivity;
@@global.optimizer_use_condition_selectivity
3
SET @@global.optimizer_use_condition_selectivity = 4;
SELECT @@global.optimizer_use_condition_selectivity;
@@global.optimizer_use_condition_selectivity
4
'#--------------------FN_DYNVARS_115_04-------------------------#'
SELECT @@session.optimizer_use_condition_selectivity;
@@session.optimizer_use_condition_selectivity
1
SET @@session.optimizer_use_condition_selectivity = 1;
SELECT @@session.optimizer_use_condition_selectivity;
@@session.optimizer_use_condition_selectivity
1
SET @@session.optimizer_use_condition_selectivity = 2;
SELECT @@session.optimizer_use_condition_selectivity;
@@session.optimizer_use_condition_selectivity
2
SET @@session.optimizer_use_condition_selectivity = 3;
SELECT @@session.optimizer_use_condition_selectivity;
@@session.optimizer_use_condition_selectivity
3
SET @@session.optimizer_use_condition_selectivity = 4;
SELECT @@session.optimizer_use_condition_selectivity;
@@session.optimizer_use_condition_selectivity
4
'#------------------FN_DYNVARS_115_05-----------------------#'
SET @@global.optimizer_use_condition_selectivity = ON;
ERROR 42000: Incorrect argument type to variable 'optimizer_use_condition_selectivity'
SET @@global.optimizer_use_condition_selectivity = OFF;
ERROR 42000: Incorrect argument type to variable 'optimizer_use_condition_selectivity'
SET @@session.optimizer_use_condition_selectivity = 65530.34;
ERROR 42000: Incorrect argument type to variable 'optimizer_use_condition_selectivity'
SET @@session.optimizer_use_condition_selectivity = test;
ERROR 42000: Incorrect argument type to variable 'optimizer_use_condition_selectivity'
'#------------------FN_DYNVARS_115_06-----------------------#'
SELECT @@global.optimizer_use_condition_selectivity = VARIABLE_VALUE
FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
WHERE VARIABLE_NAME='optimizer_use_condition_selectivity';
@@global.optimizer_use_condition_selectivity = VARIABLE_VALUE
1
'#------------------FN_DYNVARS_115_07-----------------------#'
SELECT @@session.optimizer_use_condition_selectivity = VARIABLE_VALUE
FROM INFORMATION_SCHEMA.SESSION_VARIABLES
WHERE VARIABLE_NAME='optimizer_use_condition_selectivity';
@@session.optimizer_use_condition_selectivity = VARIABLE_VALUE
1
'#---------------------FN_DYNVARS_115_08----------------------#'
SET @@optimizer_use_condition_selectivity = 1;
SET @@global.optimizer_use_condition_selectivity = 3;
SELECT @@optimizer_use_condition_selectivity = @@global.optimizer_use_condition_selectivity;
@@optimizer_use_condition_selectivity = @@global.optimizer_use_condition_selectivity
0
'#---------------------FN_DYNVARS_115_09----------------------#'
SET @@optimizer_use_condition_selectivity = 2;
SELECT @@optimizer_use_condition_selectivity = @@local.optimizer_use_condition_selectivity;
@@optimizer_use_condition_selectivity = @@local.optimizer_use_condition_selectivity
1
SELECT @@local.optimizer_use_condition_selectivity = @@session.optimizer_use_condition_selectivity;
@@local.optimizer_use_condition_selectivity = @@session.optimizer_use_condition_selectivity
1
SET @@global.optimizer_use_condition_selectivity = @start_global_value;
SELECT @@global.optimizer_use_condition_selectivity;
@@global.optimizer_use_condition_selectivity
1
SET @@session.optimizer_use_condition_selectivity = @start_session_value;
SELECT @@session.optimizer_use_condition_selectivity;
@@session.optimizer_use_condition_selectivity
1
--source include/load_sysvars.inc
##############################################################
# START OF histogram_size TESTS #
##############################################################
#############################################################
# Save initial value #
#############################################################
SET @start_global_value = @@global.histogram_size;
SELECT @start_global_value;
SET @start_session_value = @@session.histogram_size;
SELECT @start_session_value;
--echo '#--------------------FN_DYNVARS_053_01-------------------------#'
################################################################
# Display the DEFAULT value of histogram_size #
################################################################
SET @@global.histogram_size = DEFAULT;
SELECT @@global.histogram_size;
SET @@session.histogram_size = DEFAULT;
SELECT @@session.histogram_size;
--echo '#--------------------FN_DYNVARS_053_03-------------------------#'
########################################################################
# Change the value of histogram_size to a valid value for GLOBAL Scope #
########################################################################
SET @@global.histogram_size = 1;
SELECT @@global.histogram_size;
SET @@global.histogram_size = 31;
SELECT @@global.histogram_size;
SET @@global.histogram_size = 255;
SELECT @@global.histogram_size;
--echo '#--------------------FN_DYNVARS_053_04-------------------------#'
#########################################################################
# Change the value of histogram_size to a valid value for SESSION Scope #
#########################################################################
SET @@session.histogram_size = 1;
SELECT @@session.histogram_size;
SET @@session.histogram_size = 31;
SELECT @@session.histogram_size;
SET @@session.histogram_size = 255;
SELECT @@session.histogram_size;
--echo '#------------------FN_DYNVARS_053_05-----------------------#'
##########################################################
# Change the value of histogram_size to an invalid value #
###########################################################
SET @@global.histogram_size = -1;
SELECT @@global.histogram_size;
SET @@global.histogram_size = 256;
SELECT @@global.histogram_size;
SET @@global.histogram_size = 1024;
SELECT @@global.histogram_size;
--Error ER_WRONG_TYPE_FOR_VAR
SET @@global.histogram_size = 4.5;
SELECT @@global.histogram_size;
--Error ER_WRONG_TYPE_FOR_VAR
SET @@global.histogram_size = test;
SELECT @@global.histogram_size;
SET @@session.histogram_size = -1;
SELECT @@session.histogram_size;
SET @@session.histogram_size = 256;
SELECT @@session.histogram_size;
SET @@session.histogram_size = 1024;
SELECT @@session.histogram_size;
--Error ER_WRONG_TYPE_FOR_VAR
SET @@session.histogram_size = 4.5;
SELECT @@session.histogram_size;
--Error ER_WRONG_TYPE_FOR_VAR
SET @@session.histogram_size = test;
SELECT @@session.histogram_size;
--echo '#------------------FN_DYNVARS_053_06-----------------------#'
####################################################################
# Check if the value in GLOBAL Table matches value in variable #
####################################################################
SELECT @@global.histogram_size = VARIABLE_VALUE
FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
WHERE VARIABLE_NAME='histogram_size';
--echo '#------------------FN_DYNVARS_053_07-----------------------#'
####################################################################
# Check if the value in SESSION Table matches value in variable #
####################################################################
SELECT @@session.histogram_size = VARIABLE_VALUE
FROM INFORMATION_SCHEMA.SESSION_VARIABLES
WHERE VARIABLE_NAME='histogram_size';
--echo '#------------------FN_DYNVARS_053_08-----------------------#'
####################################################################
# Check if TRUE and FALSE values can be used on variable #
####################################################################
SET @@global.histogram_size = TRUE;
SET @@global.histogram_size = FALSE;
--echo '#---------------------FN_DYNVARS_001_09----------------------#'
#################################################################################
# Check if accessing variable with and without GLOBAL point to same variable #
#################################################################################
SET @@global.histogram_size = 10;
SELECT @@histogram_size = @@global.histogram_size;
--echo '#---------------------FN_DYNVARS_001_10----------------------#'
########################################################################################################
# Check if accessing variable with SESSION,LOCAL and without SCOPE points to same session variable #
########################################################################################################
SET @@histogram_size = 100;
SELECT @@histogram_size = @@local.histogram_size;
SELECT @@local.histogram_size = @@session.histogram_size;
####################################
# Restore initial value #
####################################
SET @@global.histogram_size = @start_global_value;
SELECT @@global.histogram_size;
SET @@session.histogram_size = @start_session_value;
SELECT @@session.histogram_size;
###################################################
# END OF histogram_size TESTS #
###################################################
--source include/load_sysvars.inc
#############################################################
# Save initial value #
#############################################################
SET @start_global_value = @@global.histogram_type;
SELECT @start_global_value;
SET @start_session_value = @@session.histogram_type;
SELECT @start_session_value;
##############################################################
# Display the DEFAULT value of histogram_type #
##############################################################
SET @@global.histogram_type = 1;
SET @@global.histogram_type = DEFAULT;
SELECT @@global.histogram_type;
#################################################################################
# Change the value of histogram_type to a valid value for GLOBAL Scope #
#################################################################################
SET @@global.histogram_type = 0;
SELECT @@global.histogram_type;
SET @@global.histogram_type = 1;
SELECT @@global.histogram_type;
SET @@global.histogram_type = SINGLE_PREC_HB;
SELECT @@global.histogram_type;
SET @@global.histogram_type = DOUBLE_PREC_HB;
SELECT @@global.histogram_type;
###################################################################################
# Change the value of histogram_type to a valid value for SESSION Scope #
###################################################################################
SET @@session.histogram_type = 0;
SELECT @@session.histogram_type;
SET @@session.histogram_type = 1;
SELECT @@session.histogram_type;
SET @@session.histogram_type = SINGLE_PREC_HB;
SELECT @@session.histogram_type;
SET @@session.histogram_type = DOUBLE_PREC_HB;
SELECT @@session.histogram_type;
####################################################################
# Change the value of histogram_type to an invalid value #
####################################################################
set sql_mode=TRADITIONAL;
--Error ER_WRONG_VALUE_FOR_VAR
SET @@global.histogram_type = 10;
--Error ER_WRONG_VALUE_FOR_VAR
SET @@global.histogram_type = -1024;
--Error ER_WRONG_TYPE_FOR_VAR
SET @@global.histogram_type = 2.4;
--Error ER_WRONG_VALUE_FOR_VAR
SET @@global.histogram_type = OFF;
--Error ER_WRONG_VALUE_FOR_VAR
SET @@session.histogram_type = 10;
--Error ER_WRONG_VALUE_FOR_VAR
SET @@session.histogram_type = -2;
--Error ER_WRONG_TYPE_FOR_VAR
SET @@session.histogram_type = 1.2;
--Error ER_WRONG_VALUE_FOR_VAR
SET @@session.histogram_type = ON;
###############################################################################
# Check if the value in GLOBAL & SESSION Tables matches value in variable #
###############################################################################
SELECT * FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
WHERE VARIABLE_NAME='histogram_type';
SELECT * FROM INFORMATION_SCHEMA.SESSION_VARIABLES
WHERE VARIABLE_NAME='histogram_type';
####################################
# Restore initial value #
####################################
SET @@global.histogram_type = @start_global_value;
SELECT @@global.histogram_type;
SET @@session.histogram_type = @start_session_value;
SELECT @@session.histogram_type;
set sql_mode='';
#####################################################
# END OF histogram_type TESTS #
#####################################################
\ No newline at end of file
--source include/load_sysvars.inc
#################################################################
# START OF optimizer_use_condition_selectivity TESTS #
#################################################################
#############################################################
# Save initial value #
#############################################################
SET @start_global_value = @@global.optimizer_use_condition_selectivity;
SELECT @start_global_value;
SET @start_session_value = @@session.optimizer_use_condition_selectivity;
SELECT @start_session_value;
--echo '#--------------------FN_DYNVARS_115_01-------------------------#'
#########################################################################
# Display the DEFAULT value of optimizer_use_condition_selectivity #
#########################################################################
SET @@global.optimizer_use_condition_selectivity = DEFAULT;
SELECT @@global.optimizer_use_condition_selectivity;
SET @@session.optimizer_use_condition_selectivity = DEFAULT;
SELECT @@session.optimizer_use_condition_selectivity;
--echo '#--------------------FN_DYNVARS_115_02-------------------------#'
#########################################################################
# Check the DEFAULT value of optimizer_use_condition_selectivity #
#########################################################################
SET @@global.optimizer_use_condition_selectivity = DEFAULT;
SELECT @@global.optimizer_use_condition_selectivity = 1;
SET @@session.optimizer_use_condition_selectivity = DEFAULT;
SELECT @@session.optimizer_use_condition_selectivity = 1;
--echo '#--------------------FN_DYNVARS_115_03-------------------------#'
#############################################################################################
# Change the value of optimizer_use_condition_selectivity to a valid value for GLOBAL Scope #
#############################################################################################
SELECT @@global.optimizer_use_condition_selectivity;
SET @@global.optimizer_use_condition_selectivity = 1;
SELECT @@global.optimizer_use_condition_selectivity;
SET @@global.optimizer_use_condition_selectivity = 2;
SELECT @@global.optimizer_use_condition_selectivity;
SET @@global.optimizer_use_condition_selectivity = 3;
SELECT @@global.optimizer_use_condition_selectivity;
SET @@global.optimizer_use_condition_selectivity = 4;
SELECT @@global.optimizer_use_condition_selectivity;
--echo '#--------------------FN_DYNVARS_115_04-------------------------#'
#############################################################################################
# Change the value of optimizer_use_condition_selectivity to a valid value for SESSION Scope#
#############################################################################################
SELECT @@session.optimizer_use_condition_selectivity;
SET @@session.optimizer_use_condition_selectivity = 1;
SELECT @@session.optimizer_use_condition_selectivity;
SET @@session.optimizer_use_condition_selectivity = 2;
SELECT @@session.optimizer_use_condition_selectivity;
SET @@session.optimizer_use_condition_selectivity = 3;
SELECT @@session.optimizer_use_condition_selectivity;
SET @@session.optimizer_use_condition_selectivity = 4;
SELECT @@session.optimizer_use_condition_selectivity;
--echo '#------------------FN_DYNVARS_115_05-----------------------#'
###############################################################################
# Change the value of optimizer_use_condition_selectivity to an invalid value #
##############################################################################
--Error ER_WRONG_TYPE_FOR_VAR
SET @@global.optimizer_use_condition_selectivity = ON;
--Error ER_WRONG_TYPE_FOR_VAR
SET @@global.optimizer_use_condition_selectivity = OFF;
--Error ER_WRONG_TYPE_FOR_VAR
SET @@session.optimizer_use_condition_selectivity = 65530.34;
--Error ER_WRONG_TYPE_FOR_VAR
SET @@session.optimizer_use_condition_selectivity = test;
--echo '#------------------FN_DYNVARS_115_06-----------------------#'
####################################################################
# Check if the value in GLOBAL Table matches value in variable #
####################################################################
SELECT @@global.optimizer_use_condition_selectivity = VARIABLE_VALUE
FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
WHERE VARIABLE_NAME='optimizer_use_condition_selectivity';
--echo '#------------------FN_DYNVARS_115_07-----------------------#'
####################################################################
# Check if the value in SESSION Table matches value in variable #
####################################################################
SELECT @@session.optimizer_use_condition_selectivity = VARIABLE_VALUE
FROM INFORMATION_SCHEMA.SESSION_VARIABLES
WHERE VARIABLE_NAME='optimizer_use_condition_selectivity';
--echo '#---------------------FN_DYNVARS_115_08----------------------#'
###############################################################################
# Check if global and session variable are independent of each other #
###############################################################################
SET @@optimizer_use_condition_selectivity = 1;
SET @@global.optimizer_use_condition_selectivity = 3;
SELECT @@optimizer_use_condition_selectivity = @@global.optimizer_use_condition_selectivity;
--echo '#---------------------FN_DYNVARS_115_09----------------------#'
###############################################################################
# Check if accessing variable with SESSION,LOCAL and without SCOPE points #
# to same session variable #
###############################################################################
SET @@optimizer_use_condition_selectivity = 2;
SELECT @@optimizer_use_condition_selectivity = @@local.optimizer_use_condition_selectivity;
SELECT @@local.optimizer_use_condition_selectivity = @@session.optimizer_use_condition_selectivity;
####################################
# Restore initial value #
####################################
SET @@global.optimizer_use_condition_selectivity = @start_global_value;
SELECT @@global.optimizer_use_condition_selectivity;
SET @@session.optimizer_use_condition_selectivity = @start_session_value;
SELECT @@session.optimizer_use_condition_selectivity;
########################################################################
# END OF optimizer_use_condition_selectivity TESTS #
########################################################################
This diff is collapsed.
--source include/have_innodb.inc
SET SESSION STORAGE_ENGINE='InnoDB';
set @save_optimizer_switch_for_selectivity_test=@@optimizer_switch;
set optimizer_switch='extended_keys=on';
--source selectivity.test
set optimizer_switch=@save_optimizer_switch_for_selectivity_test;
SET SESSION STORAGE_ENGINE=DEFAULT;
......@@ -165,6 +165,37 @@ SELECT
WHERE t1.e IS NOT NULL AND t1.b IS NOT NULL AND t1.d IS NOT NULL)
AS 'ARITY 3';
DELETE FROM mysql.column_stats;
set histogram_size=4;
ANALYZE TABLE t1;
SELECT db_name, table_name, column_name,
min_value, max_value,
nulls_ratio, avg_frequency,
hist_size, hist_type, HEX(histogram)
FROM mysql.column_stats;
DELETE FROM mysql.column_stats;
set histogram_size=8;
set histogram_type='DOUBLE_PREC_HB';
ANALYZE TABLE t1;
SELECT db_name, table_name, column_name,
min_value, max_value,
nulls_ratio, avg_frequency,
hist_size, hist_type, HEX(histogram)
FROM mysql.column_stats;
DELETE FROM mysql.column_stats;
set histogram_size= 0;
set histogram_type=default;
ANALYZE TABLE t1;
CREATE TABLE t3 (
a int NOT NULL PRIMARY KEY,
b varchar(32),
......@@ -559,6 +590,96 @@ DELETE FROM mysql.table_stats;
DELETE FROM mysql.column_stats;
DELETE FROM mysql.index_stats;
set use_stat_tables=@save_use_stat_tables;
--echo #
--echo # Bug mdev-4357: empty string as a value of the HIST_SIZE column
--echo # from mysql.column_stats
--echo #
create table t1 (a int);
insert into t1 values (1),(2),(3);
set histogram_size=10;
analyze table t1 persistent for all;
select db_name, table_name, column_name,
min_value, max_value,
nulls_ratio, avg_frequency,
hist_size, hist_type, HEX(histogram)
FROM mysql.column_stats;
set histogram_size=default;
drop table t1;
--echo #
--echo # Bug mdev-4359: wrong setting of the HIST_SIZE column
--echo # (see also mdev-4357) from mysql.column_stats
--echo #
create table t1 ( a int);
insert into t1 values (1),(2),(3),(4),(5);
set histogram_size=10;
set histogram_type='double_prec_hb';
show variables like 'histogram%';
analyze table t1 persistent for all;
select db_name, table_name, column_name,
min_value, max_value,
nulls_ratio, avg_frequency,
hist_size, hist_type, HEX(histogram)
FROM mysql.column_stats;
set histogram_size=default;
set histogram_type=default;
drop table t1;
--echo #
--echo # Bug mdev-4369: histogram for a column with many distinct values
--echo #
CREATE TABLE t1 (id int);
CREATE TABLE t2 (id int);
INSERT INTO t1 (id) VALUES (1), (1), (1),(1);
INSERT INTO t1 (id) SELECT id FROM t1;
INSERT INTO t1 SELECT id+1 FROM t1;
INSERT INTO t1 SELECT id+2 FROM t1;
INSERT INTO t1 SELECT id+4 FROM t1;
INSERT INTO t1 SELECT id+8 FROM t1;
INSERT INTO t1 SELECT id+16 FROM t1;
INSERT INTO t1 SELECT id+32 FROM t1;
INSERT INTO t1 SELECT id+64 FROM t1;
INSERT INTO t1 SELECT id+128 FROM t1;
INSERT INTO t1 SELECT id+256 FROM t1;
INSERT INTO t1 SELECT id+512 FROM t1;
INSERT INTO t2 SELECT id FROM t1 ORDER BY id*rand();
SELECT COUNT(*) FROM t2;
SELECT COUNT(DISTINCT id) FROM t2;
set @@tmp_table_size=1024*16;
set @@max_heap_table_size=1024*16;
set histogram_size=63;
analyze table t2 persistent for all;
select db_name, table_name, column_name,
min_value, max_value,
nulls_ratio, avg_frequency,
hist_size, hist_type, HEX(histogram)
FROM mysql.column_stats;
set histogram_size=default;
drop table t1, t2;
set use_stat_tables=@save_use_stat_tables;
......@@ -114,6 +114,6 @@ set @had_proxies_priv_table= @@warning_count != 0;
CREATE TABLE IF NOT EXISTS table_stats (db_name varchar(64) NOT NULL, table_name varchar(64) NOT NULL, cardinality bigint(21) unsigned DEFAULT NULL, PRIMARY KEY (db_name,table_name) ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Statistics on Tables';
CREATE TABLE IF NOT EXISTS column_stats (db_name varchar(64) NOT NULL, table_name varchar(64) NOT NULL, column_name varchar(64) NOT NULL, min_value varchar(255) DEFAULT NULL, max_value varchar(255) DEFAULT NULL, nulls_ratio decimal(12,4) DEFAULT NULL, avg_length decimal(12,4) DEFAULT NULL, avg_frequency decimal(12,4) DEFAULT NULL, PRIMARY KEY (db_name,table_name,column_name) ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Statistics on Columns';
CREATE TABLE IF NOT EXISTS column_stats (db_name varchar(64) NOT NULL, table_name varchar(64) NOT NULL, column_name varchar(64) NOT NULL, min_value varchar(255) DEFAULT NULL, max_value varchar(255) DEFAULT NULL, nulls_ratio decimal(12,4) DEFAULT NULL, avg_length decimal(12,4) DEFAULT NULL, avg_frequency decimal(12,4) DEFAULT NULL, hist_size tinyint unsigned, hist_type enum('SINGLE_PREC_HB','DOUBLE_PREC_HB'), histogram varbinary(255), PRIMARY KEY (db_name,table_name,column_name) ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Statistics on Columns';
CREATE TABLE IF NOT EXISTS index_stats (db_name varchar(64) NOT NULL, table_name varchar(64) NOT NULL, index_name varchar(64) NOT NULL, prefix_arity int(11) unsigned NOT NULL, avg_frequency decimal(12,4) DEFAULT NULL, PRIMARY KEY (db_name,table_name,index_name,prefix_arity) ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Statistics on Indexes';
......@@ -1273,6 +1273,37 @@ out_of_range:
return 1;
}
/**
@brief
Determine the relative position of the field value in a numeric interval
@details
The function returns a double number between 0.0 and 1.0 as the relative
position of the value of the this field in the numeric interval of [min,max].
If the value is not in the interval the the function returns 0.0 when
the value is less than min, and, 1.0 when the value is greater than max.
@param min value of the left end of the interval
@param max value of the right end of the interval
@return
relative position of the field value in the numeric interval [min,max]
*/
double Field_num::pos_in_interval(Field *min, Field *max)
{
double n, d;
n= val_real() - min->val_real();
if (n < 0)
return 0.0;
d= max->val_real() - min->val_real();
if (d <= 0)
return 1.0;
return min(n/d, 1.0);
}
/**
Process decimal library return codes and issue warnings for overflow and
truncation.
......@@ -1344,6 +1375,8 @@ Field::Field(uchar *ptr_arg,uint32 length_arg,uchar *null_ptr_arg,
comment.length=0;
field_index= 0;
is_stat_field= FALSE;
cond_selectivity= 1.0;
next_equal_field= NULL;
}
......@@ -6167,6 +6200,79 @@ int Field_str::store(double nr)
return store(buff, length, &my_charset_numeric);
}
static
inline ulonglong char_prefix_to_ulonglong(uchar *src)
{
uint sz= sizeof(ulonglong);
for (uint i= 0; i < sz/2; i++)
{
uchar tmp= src[i];
src[i]= src[sz-1-i];
src[sz-1-i]= tmp;
}
return uint8korr(src);
}
/**
@brief
Determine the relative position of the field value in a string interval
@details
The function returns a double number between 0.0 and 1.0 as the relative
position of the value of the this field in the string interval of [min,max].
If the value is not in the interval the the function returns 0.0 when
the value is less than min, and, 1.0 when the value is greater than max.
@note
To calculate the relative position of the string value v in the interval
[min, max] the function first converts the beginning of these three
strings v, min, max into the strings that are used for byte comparison.
For each string not more sizeof(ulonglong) first bytes are taken
from the result of conversion. Then these bytes are interpreted as the
big-endian representation of an ulonglong integer. The values of these
integer numbers obtained for the strings v, min, max are used to calculate
the position of v in [min,max] in the same way is it's done for numeric
fields (see Field_num::pos_in_interval).
@todo
Improve the procedure for the case when min and max have the same
beginning
@param min value of the left end of the interval
@param max value of the right end of the interval
@return
relative position of the field value in the string interval [min,max]
*/
double Field_str::pos_in_interval(Field *min, Field *max)
{
uchar mp_prefix[sizeof(ulonglong)];
uchar minp_prefix[sizeof(ulonglong)];
uchar maxp_prefix[sizeof(ulonglong)];
ulonglong mp, minp, maxp;
my_strnxfrm(charset(), mp_prefix, sizeof(mp),
ptr + length_size(),
data_length());
my_strnxfrm(charset(), minp_prefix, sizeof(minp),
min->ptr + length_size(),
min->data_length());
my_strnxfrm(charset(), maxp_prefix, sizeof(maxp),
max->ptr + length_size(),
max->data_length());
mp= char_prefix_to_ulonglong(mp_prefix);
minp= char_prefix_to_ulonglong(minp_prefix);
maxp= char_prefix_to_ulonglong(maxp_prefix);
double n, d;
n= mp - minp;
if (n < 0)
return 0.0;
d= maxp - minp;
if (d <= 0)
return 1.0;
return min(n/d, 1.0);
}
uint Field::is_equal(Create_field *new_field)
{
......@@ -8378,6 +8484,36 @@ my_decimal *Field_bit::val_decimal(my_decimal *deciaml_value)
}
/**
@brief
Determine the relative position of the field value in a bit interval
@details
The function returns a double number between 0.0 and 1.0 as the relative
position of the value of the this field in the bit interval of [min,max].
If the value is not in the interval the the function returns 0.0 when
the value is less than min, and, 1.0 when the value is greater than max.
@param min value of the left end of the interval
@param max value of the right end of the interval
@return
relative position of the field value in the bit interval [min,max]
*/
double Field_bit::pos_in_interval(Field *min, Field *max)
{
double n, d;
n= val_real() - min->val_real();
if (n < 0)
return 0.0;
d= max->val_real() - min->val_real();
if (d <= 0)
return 1.0;
return min(n/d, 1.0);
}
/*
Compare two bit fields using pointers within the record.
SYNOPSIS
......
......@@ -220,7 +220,23 @@ public:
*/
bool is_created_from_null_item;
bool is_stat_field; /* TRUE in Field objects created for column min/max values */
/* TRUE in Field objects created for column min/max values */
bool is_stat_field;
/*
Selectivity of the range condition over this field.
When calculating this selectivity a range predicate
is taken into account only if:
- it is extracted from the WHERE clause
- it depends only on the table the field belongs to
*/
double cond_selectivity;
/*
The next field in the class of equal fields at the top AND level
of the WHERE clause
*/
Field *next_equal_field;
/*
This structure is used for statistical data on the column
......@@ -456,6 +472,10 @@ public:
}
return update_fl;
}
virtual void store_field_value(uchar *val, uint len)
{
memcpy(ptr, val, len);
}
virtual uint decimals() const { return 0; }
/*
Caller beware: sql_type can change str.Ptr, so check
......@@ -703,6 +723,12 @@ public:
virtual bool hash_join_is_possible() { return TRUE; }
virtual bool eq_cmp_as_binary() { return TRUE; }
/* Position of the field value within the interval of [min, max] */
virtual double pos_in_interval(Field *min, Field *max)
{
return (double) 0.5;
}
friend int cre_myisam(char * name, register TABLE *form, uint options,
ulonglong auto_increment_value);
friend class Copy_field;
......@@ -821,6 +847,7 @@ public:
bool get_int(CHARSET_INFO *cs, const char *from, uint len,
longlong *rnd, ulonglong unsigned_max,
longlong signed_min, longlong signed_max);
double pos_in_interval(Field *min, Field *max);
};
......@@ -866,6 +893,8 @@ public:
virtual bool str_needs_quotes() { return TRUE; }
uint is_equal(Create_field *new_field);
bool eq_cmp_as_binary() { return test(flags & BINARY_FLAG); }
virtual uint length_size() { return 0; }
double pos_in_interval(Field *min, Field *max);
};
/* base class for Field_string, Field_varstring and Field_blob */
......@@ -1894,6 +1923,7 @@ public:
uint new_null_bit);
uint is_equal(Create_field *new_field);
void hash(ulong *nr, ulong *nr2);
uint length_size() { return length_bytes; }
private:
int do_save_field_metadata(uchar *first_byte);
};
......@@ -2275,6 +2305,11 @@ public:
}
return update_fl;
}
void store_field_value(uchar *val, uint len)
{
store(*((longlong *)val), TRUE);
}
double pos_in_interval(Field *min, Field *max);
void get_image(uchar *buff, uint length, CHARSET_INFO *cs)
{ get_key_image(buff, length, itRAW); }
void set_image(const uchar *buff,uint length, CHARSET_INFO *cs)
......
......@@ -5568,7 +5568,8 @@ Item *Item_bool_rowready_func2::negated_item()
*/
Item_equal::Item_equal(Item *f1, Item *f2, bool with_const_item)
: Item_bool_func(), eval_item(0), cond_false(0), context_field(NULL)
: Item_bool_func(), eval_item(0), cond_false(0), context_field(NULL),
link_equal_fields(FALSE)
{
const_item_cache= 0;
with_const= with_const_item;
......@@ -5592,7 +5593,8 @@ Item_equal::Item_equal(Item *f1, Item *f2, bool with_const_item)
*/
Item_equal::Item_equal(Item_equal *item_equal)
: Item_bool_func(), eval_item(0), cond_false(0), context_field(NULL)
: Item_bool_func(), eval_item(0), cond_false(0), context_field(NULL),
link_equal_fields(FALSE)
{
const_item_cache= 0;
List_iterator_fast<Item> li(item_equal->equal_items);
......@@ -5918,6 +5920,9 @@ bool Item_equal::fix_fields(THD *thd, Item **ref)
DBUG_ASSERT(fixed == 0);
Item_equal_fields_iterator it(*this);
Item *item;
Field *first_equal_field;
Field *last_equal_field;
Field *prev_equal_field= NULL;
not_null_tables_cache= used_tables_cache= 0;
const_item_cache= 0;
while ((item= it++))
......@@ -5931,7 +5936,18 @@ bool Item_equal::fix_fields(THD *thd, Item **ref)
maybe_null= 1;
if (!item->get_item_equal())
item->set_item_equal(this);
if (link_equal_fields && item->real_item()->type() == FIELD_ITEM)
{
last_equal_field= ((Item_field *) (item->real_item()))->field;
if (!prev_equal_field)
first_equal_field= last_equal_field;
else
prev_equal_field->next_equal_field= last_equal_field;
prev_equal_field= last_equal_field;
}
}
if (prev_equal_field && last_equal_field != first_equal_field)
last_equal_field->next_equal_field= first_equal_field;
fix_length_and_dec();
fixed= 1;
return FALSE;
......
......@@ -1737,6 +1737,8 @@ class Item_equal: public Item_bool_func
*/
Item_field *context_field;
bool link_equal_fields;
public:
COND_EQUAL *upper_levels; /* multiple equalities of upper and levels */
......@@ -1774,6 +1776,8 @@ public:
CHARSET_INFO *compare_collation();
void set_context_field(Item_field *ctx_field) { context_field= ctx_field; }
void set_link_equal_fields(bool flag) { link_equal_fields= flag; }
friend class Item_equal_fields_iterator;
friend class Item_equal_iterator<List_iterator_fast,Item>;
friend class Item_equal_iterator<List_iterator,Item>;
friend Item *eliminate_item_equal(COND *cond, COND_EQUAL *upper_levels,
......
This diff is collapsed.
......@@ -1042,6 +1042,8 @@ SQL_SELECT *make_select(TABLE *head, table_map const_tables,
table_map read_tables, COND *conds,
bool allow_null_cond, int *error);
bool calculate_cond_selectivity_for_table(THD *thd, TABLE *table, Item *cond);
#ifdef WITH_PARTITION_STORAGE_ENGINE
bool prune_partitions(THD *thd, TABLE *table, Item *pprune_cond);
void store_key_image_to_rec(Field *field, uchar *ptr, uint len);
......
......@@ -268,8 +268,10 @@ walk_up_n_right:
range->end_key.keypart_map= make_prev_keypart_map(cur->max_key_parts);
if (!(cur->min_key_flag & ~NULL_RANGE) && !cur->max_key_flag &&
(uint)key_tree->part+1 == seq->param->table->key_info[seq->real_keyno].key_parts &&
(seq->param->table->key_info[seq->real_keyno].flags & HA_NOSAME) &&
(seq->real_keyno == MAX_KEY ||
((uint)key_tree->part+1 ==
seq->param->table->key_info[seq->real_keyno].key_parts &&
(seq->param->table->key_info[seq->real_keyno].flags & HA_NOSAME))) &&
range->start_key.length == range->end_key.length &&
!memcmp(seq->param->min_key,seq->param->max_key,range->start_key.length))
range->range_flag= UNIQUE_RANGE | (cur->min_key_flag & NULL_RANGE);
......
......@@ -3908,7 +3908,7 @@ SJ_TMP_TABLE::create_sj_weedout_tmp_table(THD *thd)
&tmpname, (uint) strlen(path)+1,
&group_buff, (!using_unique_constraint ?
uniq_tuple_length_arg : 0),
&bitmaps, bitmap_buffer_size(1)*3,
&bitmaps, bitmap_buffer_size(1)*5,
NullS))
{
if (temp_pool_slot != MY_BIT_NONE)
......
......@@ -283,6 +283,7 @@ public:
{
pos->records_read= best_loose_scan_records;
pos->key= best_loose_scan_start_key;
pos->cond_selectivity= 1.0;
pos->loosescan_picker.loosescan_key= best_loose_scan_key;
pos->loosescan_picker.loosescan_parts= best_max_loose_keypart + 1;
pos->use_join_buffer= FALSE;
......
......@@ -504,7 +504,10 @@ typedef struct system_variables
ulong net_write_timeout;
ulong optimizer_prune_level;
ulong optimizer_search_depth;
ulong optimizer_use_condition_selectivity;
ulong use_stat_tables;
ulong histogram_size;
ulong histogram_type;
ulong preload_buff_size;
ulong profiling_history_size;
ulong read_buff_size;
......@@ -4017,6 +4020,7 @@ class Unique :public Sql_alloc
uint size;
uint full_size;
uint min_dupl_count; /* always 0 for unions, > 0 for intersections */
bool with_counters;
bool merge(TABLE *table, uchar *buff, bool without_last_merge);
......
......@@ -228,6 +228,7 @@ template <class T> bool valid_buffer_range(T jump,
#define OPTIMIZER_SWITCH_TABLE_ELIMINATION (1ULL << 26)
#define OPTIMIZER_SWITCH_EXTENDED_KEYS (1ULL << 27)
#define OPTIMIZER_SWITCH_EXISTS_TO_IN (1ULL << 28)
#define OPTIMIZER_SWITCH_USE_CONDITION_SELECTIVITY (1ULL << 29)
#define OPTIMIZER_SWITCH_DEFAULT (OPTIMIZER_SWITCH_INDEX_MERGE | \
OPTIMIZER_SWITCH_INDEX_MERGE_UNION | \
......
This diff is collapsed.
......@@ -292,6 +292,9 @@ typedef struct st_join_table {
/* psergey-todo: make the below have type double, like POSITION::records_read? */
ha_rows records_read;
/* The selectivity of the conditions that can be pushed to the table */
double cond_selectivity;
/* Startup cost for execution */
double startup_cost;
......@@ -772,6 +775,9 @@ typedef struct st_position :public Sql_alloc
*/
double records_read;
/* The selectivity of the pushed down conditions */
double cond_selectivity;
/*
Cost accessing the table in course of the entire complete join execution,
i.e. cost of one access method use (e.g. 'range' or 'ref' scan ) times
......@@ -1820,6 +1826,8 @@ void eliminate_tables(JOIN *join);
/* Index Condition Pushdown entry point function */
void push_index_cond(JOIN_TAB *tab, uint keyno);
#define OPT_LINK_EQUAL_FIELDS 1
/****************************************************************************
Temporary table support for SQL Runtime
***************************************************************************/
......
This diff is collapsed.
This diff is collapsed.
......@@ -1533,6 +1533,25 @@ static Sys_var_ulong Sys_optimizer_prune_level(
SESSION_VAR(optimizer_prune_level), CMD_LINE(REQUIRED_ARG),
VALID_RANGE(0, 1), DEFAULT(1), BLOCK_SIZE(1));
static Sys_var_ulong Sys_optimizer_use_condition_selectivity(
"optimizer_use_condition_selectivity",
"Controls selectivity of which conditions the optimizer takes into "
"account to calculate cardinality of a partial join when it searches "
"for the best execution plan "
"Meaning: "
"1 - use selectivity of index backed range conditions to calculate "
"the cardinality of a partial join if the last joined table is "
"accessed by full table scan or an index scan, "
"2 - use selectivity of index backed range conditions to calculate "
"the cardinality of a partial join in any case, "
"3 - additionally always use selectivity of range conditions that are "
"not backed by any index to calculate the cardinality of a partial join, "
"4 - use histograms to calculate selectivity of range conditions that "
"are not backed by any index to calculate the cardinality of "
"a partial join.",
SESSION_VAR(optimizer_use_condition_selectivity), CMD_LINE(REQUIRED_ARG),
VALID_RANGE(1, 4), DEFAULT(1), BLOCK_SIZE(1));
/** Warns about deprecated value 63 */
static bool fix_optimizer_search_depth(sys_var *self, THD *thd,
enum_var_type type)
......@@ -3876,6 +3895,24 @@ static Sys_var_enum Sys_optimizer_use_stat_tables(
SESSION_VAR(use_stat_tables), CMD_LINE(REQUIRED_ARG),
use_stat_tables_modes, DEFAULT(0));
static Sys_var_ulong Sys_histogram_size(
"histogram_size",
"Number of bytes used for a histogram. "
"If set to 0, no histograms are created by ANALYZE.",
SESSION_VAR(histogram_size), CMD_LINE(REQUIRED_ARG),
VALID_RANGE(0, 255), DEFAULT(0), BLOCK_SIZE(1));
const char *histogram_types[] =
{"SINGLE_PREC_HB", "DOUBLE_PREC_HB", 0};
static Sys_var_enum Sys_histogram_type(
"histogram_type",
"Specifies type of the histograms created by ANALYZE. "
"Possible values are: "
"SINGLE_PREC_HB - single precision height-balanced, "
"DOUBLE_PREC_HB - double precision height-balanced.",
SESSION_VAR(histogram_type), CMD_LINE(REQUIRED_ARG),
histogram_types, DEFAULT(0));
static Sys_var_mybool Sys_no_thread_alarm(
"debug_no_thread_alarm",
"Disable system thread alarm calls. Disabling it may be useful "
......
......@@ -425,6 +425,8 @@ void TABLE_SHARE::destroy()
free_root(&stats_cb.mem_root, MYF(0));
stats_cb.stats_can_be_read= FALSE;
stats_cb.stats_is_read= FALSE;
stats_cb.histograms_can_be_read= FALSE;
stats_cb.histograms_are_read= FALSE;
if (tmp_table == NO_TMP_TABLE)
mysql_mutex_unlock(&LOCK_ha_data);
......@@ -2749,7 +2751,7 @@ partititon_err:
/* Allocate bitmaps */
bitmap_size= share->column_bitmap_size;
if (!(bitmaps= (uchar*) alloc_root(&outparam->mem_root, bitmap_size*5)))
if (!(bitmaps= (uchar*) alloc_root(&outparam->mem_root, bitmap_size*6)))
goto err;
bitmap_init(&outparam->def_read_set,
(my_bitmap_map*) bitmaps, share->fields, FALSE);
......@@ -2761,8 +2763,12 @@ partititon_err:
(my_bitmap_map*) (bitmaps+bitmap_size*3), share->fields, FALSE);
bitmap_init(&outparam->eq_join_set,
(my_bitmap_map*) (bitmaps+bitmap_size*4), share->fields, FALSE);
bitmap_init(&outparam->cond_set,
(my_bitmap_map*) (bitmaps+bitmap_size*5), share->fields, FALSE);
outparam->default_column_bitmaps();
outparam->cond_selectivity= 1.0;
/* The table struct is now initialized; Open the table */
if (db_stat)
{
......@@ -3884,6 +3890,7 @@ void TABLE::init(THD *thd, TABLE_LIST *tl)
file->ha_start_of_new_statement();
reginfo.impossible_range= 0;
created= TRUE;
cond_selectivity= 1.0;
/* Catch wrong handling of the auto_increment_field_not_null. */
DBUG_ASSERT(!auto_increment_field_not_null);
......@@ -3892,6 +3899,11 @@ void TABLE::init(THD *thd, TABLE_LIST *tl)
pos_in_table_list= tl;
clear_column_bitmaps();
for (Field **f_ptr= field ; *f_ptr ; f_ptr++)
{
(*f_ptr)->next_equal_field= NULL;
(*f_ptr)->cond_selectivity= 1.0;
}
DBUG_ASSERT(key_read == 0);
......
......@@ -587,6 +587,8 @@ struct TABLE_STATISTICS_CB
bool stats_can_be_read; /* Memory for statistical data is allocated */
bool stats_is_read; /* Statistical data for table has been read
from statistical tables */
bool histograms_can_be_read;
bool histograms_are_read;
};
......@@ -1107,6 +1109,7 @@ public:
my_bitmap_map *bitmap_init_value;
MY_BITMAP def_read_set, def_write_set, def_vcol_set, tmp_set;
MY_BITMAP eq_join_set; /* used to mark equi-joined fields */
MY_BITMAP cond_set; /* used to mark fields from sargable conditions*/
MY_BITMAP *read_set, *write_set, *vcol_set; /* Active column sets */
/*
The ID of the query that opened and is using this table. Has different
......@@ -1159,6 +1162,8 @@ public:
*/
ha_rows quick_condition_rows;
double cond_selectivity;
table_map map; /* ID bit of table (1,2,4,8,16...) */
uint lock_position; /* Position in MYSQL_LOCK.table */
......@@ -1278,6 +1283,7 @@ public:
#endif
uint max_keys; /* Size of allocated key_info array. */
bool stats_is_read; /* Persistent statistics is read for the table */
bool histograms_are_read;
MDL_ticket *mdl_ticket;
void init(THD *thd, TABLE_LIST *tl);
......
This diff is collapsed.
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