80 changed files with 1557 additions and 271 deletions
-
78mysql-test/include/have_dbi_dbd-mysql.inc
-
16mysql-test/include/mysqlhotcopy.inc
-
10mysql-test/mysql-test-run.pl
-
97mysql-test/std_data/checkDBI_DBD-mysql.pl
-
95mysql-test/suite/innodb/r/innodb_bug30423.result
-
211mysql-test/suite/innodb/t/innodb_bug30423.test
-
5mysql-test/suite/innodb/t/innodb_bug56143.test
-
95mysql-test/suite/innodb_plugin/r/innodb_bug30423.result
-
211mysql-test/suite/innodb_plugin/t/innodb_bug30423.test
-
5mysql-test/suite/innodb_plugin/t/innodb_bug56143.test
-
4mysql-test/suite/parts/inc/partition_check_drop.inc
-
13mysql-test/suite/parts/inc/partition_layout_check1.inc
-
7mysql-test/suite/parts/inc/partition_layout_check2.inc
-
2mysql-test/suite/parts/r/partition_recover_myisam.result
-
2mysql-test/suite/parts/t/partition_debug_sync_innodb.test
-
6mysql-test/suite/parts/t/partition_recover_myisam.test
-
4mysql-test/suite/parts/t/partition_special_innodb.test
-
2mysql-test/suite/sys_vars/r/general_log_file_basic.result
-
2mysql-test/suite/sys_vars/r/log_output_func.result
-
2mysql-test/suite/sys_vars/r/slow_query_log_file_basic.result
-
2mysql-test/suite/sys_vars/t/div_precision_increment_func.test
-
1mysql-test/suite/sys_vars/t/general_log_file_basic.test
-
1mysql-test/suite/sys_vars/t/log_output_func.test
-
1mysql-test/suite/sys_vars/t/slow_query_log_file_basic.test
-
2mysql-test/t/disabled.def
-
2sql/item.h
-
2sql/item_func.h
-
2sql/item_timefunc.h
-
2sql/sql_partition.cc
-
2sql/table.cc
-
156storage/innobase/btr/btr0cur.c
-
10storage/innobase/dict/dict0dict.c
-
95storage/innobase/handler/ha_innodb.cc
-
5storage/innobase/include/btr0cur.h
-
6storage/innobase/include/dict0mem.h
-
5storage/innobase/include/dict0types.h
-
4storage/innobase/include/rem0cmp.h
-
2storage/innobase/include/rem0cmp.ic
-
18storage/innobase/include/srv0srv.h
-
3storage/innobase/include/sync0rw.h
-
4storage/innobase/include/trx0rseg.h
-
5storage/innobase/include/trx0trx.h
-
14storage/innobase/rem/rem0cmp.c
-
10storage/innobase/row/row0vers.c
-
5storage/innobase/srv/srv0srv.c
-
4storage/innobase/sync/sync0arr.c
-
19storage/innobase/sync/sync0rw.c
-
26storage/innobase/trx/trx0trx.c
-
51storage/innodb_plugin/ChangeLog
-
2storage/innodb_plugin/btr/btr0btr.c
-
165storage/innodb_plugin/btr/btr0cur.c
-
2storage/innodb_plugin/btr/btr0sea.c
-
2storage/innodb_plugin/buf/buf0buddy.c
-
14storage/innodb_plugin/buf/buf0buf.c
-
44storage/innodb_plugin/buf/buf0lru.c
-
10storage/innodb_plugin/dict/dict0dict.c
-
95storage/innodb_plugin/handler/ha_innodb.cc
-
5storage/innodb_plugin/include/btr0cur.h
-
6storage/innodb_plugin/include/buf0buf.h
-
8storage/innodb_plugin/include/buf0buf.ic
-
14storage/innodb_plugin/include/buf0lru.h
-
6storage/innodb_plugin/include/dict0mem.h
-
5storage/innodb_plugin/include/dict0types.h
-
4storage/innodb_plugin/include/rem0cmp.h
-
2storage/innodb_plugin/include/rem0cmp.ic
-
18storage/innodb_plugin/include/srv0srv.h
-
3storage/innodb_plugin/include/sync0rw.h
-
4storage/innodb_plugin/include/trx0rseg.h
-
4storage/innodb_plugin/include/trx0trx.h
-
2storage/innodb_plugin/include/univ.i
-
2storage/innodb_plugin/mem/mem0mem.c
-
2storage/innodb_plugin/mtr/mtr0log.c
-
2storage/innodb_plugin/page/page0zip.c
-
14storage/innodb_plugin/rem/rem0cmp.c
-
4storage/innodb_plugin/row/row0upd.c
-
10storage/innodb_plugin/row/row0vers.c
-
5storage/innodb_plugin/srv/srv0srv.c
-
4storage/innodb_plugin/sync/sync0arr.c
-
19storage/innodb_plugin/sync/sync0rw.c
-
25storage/innodb_plugin/trx/trx0trx.c
@ -0,0 +1,78 @@ |
|||
# |
|||
# Originally created by John Embretsen, 2011-01-26. |
|||
# |
|||
# Checks for the existence of Perl modules DBI and DBD::mysql as seen from the |
|||
# perl installation used by "external" executable perl scripts, i.e. scripts |
|||
# that are executed as standalone scripts interpreted by the perl installation |
|||
# specified by the "shebang" line in the top of these scripts. |
|||
# |
|||
# If either module is not found, the test will be skipped. |
|||
# |
|||
# For use in tests that call perl scripts that require these modules. |
|||
# |
|||
# This file is intended to work on Unix. Windows may need different treatment. |
|||
# Reasoning: |
|||
# - "shebangs" are not relevant on Windows, but need to be handled here. |
|||
# - Perl scripts cannot be made executable on Windows, interpreter must be |
|||
# specified. |
|||
# |
|||
# Note that if there are multiple perl installations and not all have the |
|||
# required modules, this check may fail even if the perl in path does have |
|||
# the modules available. This may happen if the perl specified by the script's |
|||
# shebang (e.g. #!/usr/bin/perl) does not have these modules, and script is |
|||
# called without specifying the perl interpreter. However, this will be |
|||
# a correct result in cases where a test calls a script with a similar shebang. |
|||
# |
|||
################################################################################ |
|||
|
|||
--source include/not_windows.inc |
|||
|
|||
# We jump through some hoops since there is no direct way to check if an |
|||
# external command went OK or not from a mysql-test file: |
|||
# |
|||
# - In theory, we could do as simple as "exec perl -MDBI -MDBD::mysql -e 1", |
|||
# however we cannot check the result (exit code) from within a test script. |
|||
# Also, this may not yield the same result as other uses of perl due to the |
|||
# shebang issue mentioned above. |
|||
# - Instead we use a separate helper perl script that checks for the modules. |
|||
# - If the modules are found, the perl script leaves a file which sets a |
|||
# variable that can be read by this file. |
|||
# If the modules are not found, the perl script does not set this variable, |
|||
# but leaves an empty file instead. |
|||
# |
|||
# This is done because there is apparently no direct way to transfer |
|||
# information from perl to the test script itself. |
|||
|
|||
--disable_query_log |
|||
--disable_result_log |
|||
--disable_warnings |
|||
|
|||
# We do not use embedded perl in this script because that would not have yielded |
|||
# correct results for a situation where an external Perl script is called like |
|||
# "scriptname" instead of "perl scriptname" and the shebang in the script points |
|||
# to a specific perl that may be different than the perl in PATH. |
|||
# |
|||
# Instead, we call a separate helper script which checks for the modules in its |
|||
# own environment. We call it without "perl" in front. |
|||
|
|||
--let $perlChecker= $MYSQLTEST_VARDIR/std_data/checkDBI_DBD-mysql.pl |
|||
--let $resultFile= $MYSQL_TMP_DIR/dbidbd-mysql.txt |
|||
|
|||
# Make the script executable and execute it. |
|||
--chmod 0755 $perlChecker |
|||
--exec $perlChecker |
|||
|
|||
# Source the resulting temporary file and look for a variable being set. |
|||
--source $resultFile |
|||
|
|||
if (!$dbidbd) { |
|||
--skip Test needs Perl modules DBI and DBD::mysql |
|||
} |
|||
|
|||
# Clean up |
|||
--remove_file $resultFile |
|||
|
|||
--enable_query_log |
|||
--enable_result_log |
|||
--enable_warnings |
|||
|
|||
@ -0,0 +1,97 @@ |
|||
#!/usr/bin/perl |
|||
|
|||
# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. |
|||
# |
|||
# This program is free software; you can redistribute it and/or |
|||
# modify it under the terms of the GNU Library General Public |
|||
# License as published by the Free Software Foundation; version 2 |
|||
# of the License. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|||
# Library General Public License for more details. |
|||
# |
|||
# You should have received a copy of the GNU General Public License |
|||
# along with this program; if not, write to the Free Software |
|||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|||
|
|||
|
|||
################################################################################ |
|||
# |
|||
# This perl script checks for availability of the Perl modules DBI and |
|||
# DBD::mysql using the "current" perl interpreter. |
|||
# |
|||
# Useful for test environment checking before testing executable perl scripts |
|||
# in the MySQL Server distribution. |
|||
# |
|||
# NOTE: The "shebang" on the first line of this script should always point to |
|||
# /usr/bin/perl, so that we can use this script to check whether or not we |
|||
# support running perl scripts with such a shebang without specifying the |
|||
# perl interpreter on the command line. Such a script is mysqlhotcopy. |
|||
# |
|||
# When run as "checkDBI_DBD-mysql.pl" the shebang line will be evaluated |
|||
# and used. When run as "perl checkDBI_DBD-mysql.pl" the shebang line is |
|||
# not used. |
|||
# |
|||
# NOTE: This script will create a temporary file in MTR's tmp dir. |
|||
# If modules are found, a mysql-test statement which sets a special |
|||
# variable is written to this file. If one of the modules is not found |
|||
# (or cannot be loaded), the file will remain empty. |
|||
# A test (or include file) which sources that file can then easily do |
|||
# an if-check on the special variable to determine success or failure. |
|||
# |
|||
# Example: |
|||
# |
|||
# --let $perlChecker= $MYSQLTEST_VARDIR/std_data/checkDBI_DBD-mysql.pl |
|||
# --let $resultFile= $MYSQL_TMP_DIR/dbidbd-mysql.txt |
|||
# --chmod 0755 $perlChecker |
|||
# --exec $perlChecker |
|||
# --source $resultFile |
|||
# if (!$dbidbd) { |
|||
# --skip Test needs Perl modules DBI and DBD::mysql |
|||
# } |
|||
# |
|||
# The calling script is also responsible for cleaning up after use: |
|||
# |
|||
# --remove_file $resultFile |
|||
# |
|||
# Windows notes: |
|||
# - shebangs may work differently - call this script with "perl " in front. |
|||
# |
|||
# See mysql-test/include/have_dbi_dbd-mysql.inc for example use of this script. |
|||
# This script should be executable for the user running MTR. |
|||
# |
|||
################################################################################ |
|||
|
|||
BEGIN { |
|||
# By using eval inside BEGIN we can suppress warnings and continue after. |
|||
# We need to catch "Can't locate" as well as "Can't load" errors. |
|||
eval{ |
|||
$FOUND_DBI=0; |
|||
$FOUND_DBD_MYSQL=0; |
|||
|
|||
# Check for DBI module: |
|||
$FOUND_DBI=1 if require DBI; |
|||
|
|||
# Check for DBD::mysql module |
|||
$FOUND_DBD_MYSQL=1 if require DBD::mysql; |
|||
}; |
|||
}; |
|||
|
|||
# Open a file to be used for transfer of result back to mysql-test. |
|||
# The file must be created whether we write to it or not, otherwise mysql-test |
|||
# will complain if trying to source it. |
|||
# An empty file indicates failure to load modules. |
|||
open(FILE, ">", $ENV{'MYSQL_TMP_DIR'}.'/dbidbd-mysql.txt'); |
|||
|
|||
if ($FOUND_DBI && $FOUND_DBD_MYSQL) { |
|||
# write a mysql-test command setting a variable to indicate success |
|||
print(FILE 'let $dbidbd= FOUND_DBI_DBD-MYSQL;'."\n"); |
|||
} |
|||
|
|||
# close the file. |
|||
close(FILE); |
|||
|
|||
1; |
|||
|
|||
@ -0,0 +1,95 @@ |
|||
set global innodb_stats_method = default; |
|||
select @@innodb_stats_method; |
|||
@@innodb_stats_method |
|||
nulls_equal |
|||
select count(*) from bug30243_3 where org_id is not NULL; |
|||
count(*) |
|||
20 |
|||
select count(*) from bug30243_3 where org_id is NULL; |
|||
count(*) |
|||
16384 |
|||
select count(*) from bug30243_2 where org_id is not NULL; |
|||
count(*) |
|||
224 |
|||
select count(*) from bug30243_2 where org_id is NULL; |
|||
count(*) |
|||
65536 |
|||
select @@innodb_stats_method; |
|||
@@innodb_stats_method |
|||
nulls_equal |
|||
analyze table bug30243_1; |
|||
Table Op Msg_type Msg_text |
|||
test.bug30243_1 analyze status OK |
|||
analyze table bug30243_2; |
|||
Table Op Msg_type Msg_text |
|||
test.bug30243_2 analyze status OK |
|||
analyze table bug30243_3; |
|||
Table Op Msg_type Msg_text |
|||
test.bug30243_3 analyze status OK |
|||
set global innodb_stats_method = "NULL"; |
|||
ERROR 42000: Variable 'stats_method' can't be set to the value of 'NULL' |
|||
set global innodb_stats_method = "nulls_ignored"; |
|||
select @@innodb_stats_method; |
|||
@@innodb_stats_method |
|||
nulls_ignored |
|||
analyze table bug30243_1; |
|||
Table Op Msg_type Msg_text |
|||
test.bug30243_1 analyze status OK |
|||
analyze table bug30243_2; |
|||
Table Op Msg_type Msg_text |
|||
test.bug30243_2 analyze status OK |
|||
analyze table bug30243_3; |
|||
Table Op Msg_type Msg_text |
|||
test.bug30243_3 analyze status OK |
|||
explain SELECT COUNT(*), 0 |
|||
FROM bug30243_1 orgs |
|||
LEFT JOIN bug30243_3 sa_opportunities |
|||
ON orgs.org_id=sa_opportunities.org_id |
|||
LEFT JOIN bug30243_2 contacts |
|||
ON orgs.org_id=contacts.org_id ; |
|||
id select_type table type possible_keys key key_len ref rows Extra |
|||
1 SIMPLE orgs index NULL org_id 4 NULL 128 Using index |
|||
1 SIMPLE sa_opportunities ref org_id org_id 5 test.orgs.org_id 1 Using index |
|||
1 SIMPLE contacts ref contacts$org_id contacts$org_id 5 test.orgs.org_id 1 Using index |
|||
select @@innodb_stats_method; |
|||
@@innodb_stats_method |
|||
nulls_ignored |
|||
set global innodb_stats_method = "nulls_unequal"; |
|||
select @@innodb_stats_method; |
|||
@@innodb_stats_method |
|||
nulls_unequal |
|||
analyze table bug30243_1; |
|||
Table Op Msg_type Msg_text |
|||
test.bug30243_1 analyze status OK |
|||
analyze table bug30243_2; |
|||
Table Op Msg_type Msg_text |
|||
test.bug30243_2 analyze status OK |
|||
analyze table bug30243_3; |
|||
Table Op Msg_type Msg_text |
|||
test.bug30243_3 analyze status OK |
|||
explain SELECT COUNT(*), 0 |
|||
FROM bug30243_1 orgs |
|||
LEFT JOIN bug30243_3 sa_opportunities |
|||
ON orgs.org_id=sa_opportunities.org_id |
|||
LEFT JOIN bug30243_2 contacts |
|||
ON orgs.org_id=contacts.org_id; |
|||
id select_type table type possible_keys key key_len ref rows Extra |
|||
1 SIMPLE orgs index NULL org_id 4 NULL 128 Using index |
|||
1 SIMPLE sa_opportunities ref org_id org_id 5 test.orgs.org_id 1 Using index |
|||
1 SIMPLE contacts ref contacts$org_id contacts$org_id 5 test.orgs.org_id 1 Using index |
|||
SELECT COUNT(*) FROM table_bug30423 WHERE org_id IS NULL; |
|||
COUNT(*) |
|||
1024 |
|||
set global innodb_stats_method = "nulls_unequal"; |
|||
analyze table table_bug30423; |
|||
Table Op Msg_type Msg_text |
|||
test.table_bug30423 analyze status OK |
|||
set global innodb_stats_method = "nulls_ignored"; |
|||
analyze table table_bug30423; |
|||
Table Op Msg_type Msg_text |
|||
test.table_bug30423 analyze status OK |
|||
set global innodb_stats_method = nulls_equal; |
|||
drop table bug30243_2; |
|||
drop table bug30243_1; |
|||
drop table bug30243_3; |
|||
drop table table_bug30423; |
|||
@ -0,0 +1,211 @@ |
|||
# Test for Bug #30423, InnoDBs treatment of NULL in index stats causes |
|||
# bad "rows examined" estimates. |
|||
# Implemented InnoDB system variable "innodb_stats_method" with |
|||
# "nulls_equal" (default), "nulls_unequal", and "nulls_ignored" options. |
|||
|
|||
-- source include/have_innodb.inc |
|||
|
|||
let $innodb_stats_method_orig = `select @@innodb_stats_method`; |
|||
|
|||
# default setting for innodb_stats_method is "nulls_equal" |
|||
set global innodb_stats_method = default; |
|||
|
|||
select @@innodb_stats_method; |
|||
|
|||
# create three tables, bug30243_1, bug30243_2 and bug30243_3. |
|||
# The test scenario is adopted from original bug #30423 report. |
|||
# table bug30243_1 and bug30243_3 have many NULL values |
|||
|
|||
-- disable_result_log |
|||
-- disable_query_log |
|||
|
|||
DROP TABLE IF EXISTS bug30243_1; |
|||
CREATE TABLE bug30243_1 ( |
|||
org_id int(11) NOT NULL default '0', |
|||
UNIQUE KEY (org_id) |
|||
) ENGINE=InnoDB DEFAULT CHARSET=latin1; |
|||
|
|||
LOCK TABLES bug30243_1 WRITE; |
|||
INSERT INTO bug30243_1 VALUES (11),(15),(16),(17),(19),(20),(21),(23),(24), |
|||
(25),(26),(27),(28),(29),(30),(31),(32),(33),(34),(35),(37),(38),(40),(41), |
|||
(42),(43),(44),(45),(46),(47),(48),(49),(50),(51),(52),(53),(54),(55),(56), |
|||
(57),(58),(59),(60),(61),(62),(63),(64),(65),(66),(67),(68),(69),(70),(71), |
|||
(72),(73),(74),(75),(76),(77),(78),(79),(80),(81),(82),(83),(84),(85),(86), |
|||
(87),(88),(89),(90),(91),(92),(93),(94),(95),(96),(97),(98),(99),(100),(101), |
|||
(102),(103),(104),(105),(106),(107),(108),(109),(110),(111),(112),(113),(114), |
|||
(115),(116),(117),(118),(119),(120),(121),(122),(123),(124),(125),(126),(127), |
|||
(128),(129),(130),(131),(132),(133),(134),(135),(136),(137),(138),(139),(140), |
|||
(141),(142),(143),(144),(145); |
|||
UNLOCK TABLES; |
|||
|
|||
DROP TABLE IF EXISTS bug30243_3; |
|||
CREATE TABLE bug30243_3 ( |
|||
org_id int(11) default NULL, |
|||
KEY (org_id) |
|||
) ENGINE=InnoDB DEFAULT CHARSET=latin1; |
|||
|
|||
INSERT INTO bug30243_3 VALUES (NULL); |
|||
|
|||
begin; |
|||
let $i=14; |
|||
while ($i) |
|||
{ |
|||
INSERT INTO bug30243_3 SELECT NULL FROM bug30243_3; |
|||
dec $i; |
|||
} |
|||
|
|||
INSERT INTO bug30243_3 VALUES (34),(34),(35),(56),(58),(62),(62),(64),(65),(66),(80),(135),(137),(138),(139),(140),(142),(143),(144),(145); |
|||
commit; |
|||
|
|||
DROP TABLE IF EXISTS bug30243_2; |
|||
CREATE TABLE bug30243_2 ( |
|||
org_id int(11) default NULL, |
|||
KEY `contacts$org_id` (org_id) |
|||
) ENGINE=InnoDB DEFAULT CHARSET=latin1; |
|||
|
|||
INSERT INTO bug30243_2 VALUES (NULL); |
|||
|
|||
begin; |
|||
let $i=16; |
|||
while ($i) |
|||
{ |
|||
INSERT INTO bug30243_2 SELECT NULL FROM bug30243_2; |
|||
dec $i; |
|||
} |
|||
|
|||
INSERT INTO bug30243_2 VALUES (11),(15),(16),(17),(20),(21),(23),(24),(25), |
|||
(26),(27),(28),(29),(30),(31),(32),(33),(34),(37),(38),(40),(41),(42),(43), |
|||
(44),(45),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46), |
|||
(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46), |
|||
(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46), |
|||
(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46), |
|||
(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46), |
|||
(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(48), |
|||
(48),(50),(51),(52),(52),(53),(54),(55),(57),(60),(61),(62),(62),(62),(62), |
|||
(62),(63),(64),(64),(65),(66),(66),(67),(68),(69),(70),(71),(72),(73),(74), |
|||
(75),(76),(77),(78),(79),(80),(80),(81),(82),(83),(84),(85),(86),(87),(88), |
|||
(89),(90),(91),(92),(93),(94),(95),(96),(97),(98),(99),(100),(101),(102), |
|||
(103),(104),(105),(106),(107),(108),(109),(110),(111),(112),(113),(114), |
|||
(115),(116),(117),(118),(119),(120),(121),(122),(123),(124),(125),(126), |
|||
(127),(128),(129),(130),(131),(132),(133),(133),(135),(135),(135),(135), |
|||
(136),(136),(138),(138),(139),(139),(139),(140),(141),(141),(142),(143), |
|||
(143),(145),(145); |
|||
commit; |
|||
|
|||
|
|||
-- enable_result_log |
|||
-- enable_query_log |
|||
|
|||
# check tables's value |
|||
select count(*) from bug30243_3 where org_id is not NULL; |
|||
select count(*) from bug30243_3 where org_id is NULL; |
|||
|
|||
select count(*) from bug30243_2 where org_id is not NULL; |
|||
select count(*) from bug30243_2 where org_id is NULL; |
|||
|
|||
select @@innodb_stats_method; |
|||
|
|||
analyze table bug30243_1; |
|||
analyze table bug30243_2; |
|||
analyze table bug30243_3; |
|||
|
|||
# Following query plan shows that we over estimate the rows per |
|||
# unique value (since there are many NULLs). |
|||
# Skip this query log since the stats estimate could vary from runs |
|||
-- disable_query_log |
|||
-- disable_result_log |
|||
explain SELECT COUNT(*), 0 |
|||
FROM bug30243_1 orgs |
|||
LEFT JOIN bug30243_3 sa_opportunities |
|||
ON orgs.org_id=sa_opportunities.org_id |
|||
LEFT JOIN bug30243_2 contacts |
|||
ON orgs.org_id=contacts.org_id ; |
|||
-- enable_query_log |
|||
-- enable_result_log |
|||
|
|||
# following set operation will fail |
|||
#--error ER_WRONG_VALUE_FOR_VAR |
|||
--error 1231 |
|||
set global innodb_stats_method = "NULL"; |
|||
|
|||
set global innodb_stats_method = "nulls_ignored"; |
|||
|
|||
select @@innodb_stats_method; |
|||
|
|||
# Regenerate the stats with "nulls_ignored" option |
|||
|
|||
analyze table bug30243_1; |
|||
analyze table bug30243_2; |
|||
analyze table bug30243_3; |
|||
|
|||
# Following query plan shows that we get the correct rows per |
|||
# unique value (should be approximately 1 row per value) |
|||
explain SELECT COUNT(*), 0 |
|||
FROM bug30243_1 orgs |
|||
LEFT JOIN bug30243_3 sa_opportunities |
|||
ON orgs.org_id=sa_opportunities.org_id |
|||
LEFT JOIN bug30243_2 contacts |
|||
ON orgs.org_id=contacts.org_id ; |
|||
|
|||
select @@innodb_stats_method; |
|||
|
|||
# Try the "nulls_unequal" option |
|||
set global innodb_stats_method = "nulls_unequal"; |
|||
|
|||
select @@innodb_stats_method; |
|||
|
|||
analyze table bug30243_1; |
|||
analyze table bug30243_2; |
|||
analyze table bug30243_3; |
|||
|
|||
# Following query plan shows that we get the correct rows per |
|||
# unique value (~1) |
|||
explain SELECT COUNT(*), 0 |
|||
FROM bug30243_1 orgs |
|||
LEFT JOIN bug30243_3 sa_opportunities |
|||
ON orgs.org_id=sa_opportunities.org_id |
|||
LEFT JOIN bug30243_2 contacts |
|||
ON orgs.org_id=contacts.org_id; |
|||
|
|||
|
|||
# Create a table with all NULL values, make sure the stats calculation |
|||
# does not crash with table of all NULL values |
|||
-- disable_query_log |
|||
CREATE TABLE table_bug30423 ( |
|||
org_id int(11) default NULL, |
|||
KEY(org_id) |
|||
) ENGINE=InnoDB DEFAULT CHARSET=latin1; |
|||
|
|||
INSERT INTO `table_bug30423` VALUES (NULL); |
|||
|
|||
begin; |
|||
let $i=10; |
|||
while ($i) |
|||
{ |
|||
INSERT INTO table_bug30423 SELECT NULL FROM table_bug30423; |
|||
dec $i; |
|||
} |
|||
commit; |
|||
|
|||
-- enable_query_log |
|||
|
|||
SELECT COUNT(*) FROM table_bug30423 WHERE org_id IS NULL; |
|||
|
|||
# calculate the statistics for the table for "nulls_ignored" and |
|||
# "nulls_unequal" option |
|||
set global innodb_stats_method = "nulls_unequal"; |
|||
analyze table table_bug30423; |
|||
|
|||
set global innodb_stats_method = "nulls_ignored"; |
|||
analyze table table_bug30423; |
|||
|
|||
|
|||
eval set global innodb_stats_method = $innodb_stats_method_orig; |
|||
|
|||
drop table bug30243_2; |
|||
|
|||
drop table bug30243_1; |
|||
|
|||
drop table bug30243_3; |
|||
|
|||
drop table table_bug30423; |
|||
@ -0,0 +1,95 @@ |
|||
set global innodb_stats_method = default; |
|||
select @@innodb_stats_method; |
|||
@@innodb_stats_method |
|||
nulls_equal |
|||
select count(*) from bug30243_3 where org_id is not NULL; |
|||
count(*) |
|||
20 |
|||
select count(*) from bug30243_3 where org_id is NULL; |
|||
count(*) |
|||
16384 |
|||
select count(*) from bug30243_2 where org_id is not NULL; |
|||
count(*) |
|||
224 |
|||
select count(*) from bug30243_2 where org_id is NULL; |
|||
count(*) |
|||
65536 |
|||
select @@innodb_stats_method; |
|||
@@innodb_stats_method |
|||
nulls_equal |
|||
analyze table bug30243_1; |
|||
Table Op Msg_type Msg_text |
|||
test.bug30243_1 analyze status OK |
|||
analyze table bug30243_2; |
|||
Table Op Msg_type Msg_text |
|||
test.bug30243_2 analyze status OK |
|||
analyze table bug30243_3; |
|||
Table Op Msg_type Msg_text |
|||
test.bug30243_3 analyze status OK |
|||
set global innodb_stats_method = "NULL"; |
|||
ERROR 42000: Variable 'stats_method' can't be set to the value of 'NULL' |
|||
set global innodb_stats_method = "nulls_ignored"; |
|||
select @@innodb_stats_method; |
|||
@@innodb_stats_method |
|||
nulls_ignored |
|||
analyze table bug30243_1; |
|||
Table Op Msg_type Msg_text |
|||
test.bug30243_1 analyze status OK |
|||
analyze table bug30243_2; |
|||
Table Op Msg_type Msg_text |
|||
test.bug30243_2 analyze status OK |
|||
analyze table bug30243_3; |
|||
Table Op Msg_type Msg_text |
|||
test.bug30243_3 analyze status OK |
|||
explain SELECT COUNT(*), 0 |
|||
FROM bug30243_1 orgs |
|||
LEFT JOIN bug30243_3 sa_opportunities |
|||
ON orgs.org_id=sa_opportunities.org_id |
|||
LEFT JOIN bug30243_2 contacts |
|||
ON orgs.org_id=contacts.org_id ; |
|||
id select_type table type possible_keys key key_len ref rows Extra |
|||
1 SIMPLE orgs index NULL org_id 4 NULL 128 Using index |
|||
1 SIMPLE sa_opportunities ref org_id org_id 5 test.orgs.org_id 1 Using index |
|||
1 SIMPLE contacts ref contacts$org_id contacts$org_id 5 test.orgs.org_id 1 Using index |
|||
select @@innodb_stats_method; |
|||
@@innodb_stats_method |
|||
nulls_ignored |
|||
set global innodb_stats_method = "nulls_unequal"; |
|||
select @@innodb_stats_method; |
|||
@@innodb_stats_method |
|||
nulls_unequal |
|||
analyze table bug30243_1; |
|||
Table Op Msg_type Msg_text |
|||
test.bug30243_1 analyze status OK |
|||
analyze table bug30243_2; |
|||
Table Op Msg_type Msg_text |
|||
test.bug30243_2 analyze status OK |
|||
analyze table bug30243_3; |
|||
Table Op Msg_type Msg_text |
|||
test.bug30243_3 analyze status OK |
|||
explain SELECT COUNT(*), 0 |
|||
FROM bug30243_1 orgs |
|||
LEFT JOIN bug30243_3 sa_opportunities |
|||
ON orgs.org_id=sa_opportunities.org_id |
|||
LEFT JOIN bug30243_2 contacts |
|||
ON orgs.org_id=contacts.org_id; |
|||
id select_type table type possible_keys key key_len ref rows Extra |
|||
1 SIMPLE orgs index NULL org_id 4 NULL 128 Using index |
|||
1 SIMPLE sa_opportunities ref org_id org_id 5 test.orgs.org_id 1 Using index |
|||
1 SIMPLE contacts ref contacts$org_id contacts$org_id 5 test.orgs.org_id 1 Using index |
|||
SELECT COUNT(*) FROM table_bug30423 WHERE org_id IS NULL; |
|||
COUNT(*) |
|||
1024 |
|||
set global innodb_stats_method = "nulls_unequal"; |
|||
analyze table table_bug30423; |
|||
Table Op Msg_type Msg_text |
|||
test.table_bug30423 analyze status OK |
|||
set global innodb_stats_method = "nulls_ignored"; |
|||
analyze table table_bug30423; |
|||
Table Op Msg_type Msg_text |
|||
test.table_bug30423 analyze status OK |
|||
set global innodb_stats_method = nulls_equal; |
|||
drop table bug30243_2; |
|||
drop table bug30243_1; |
|||
drop table bug30243_3; |
|||
drop table table_bug30423; |
|||
@ -0,0 +1,211 @@ |
|||
# Test for Bug #30423, InnoDBs treatment of NULL in index stats causes |
|||
# bad "rows examined" estimates. |
|||
# Implemented InnoDB system variable "innodb_stats_method" with |
|||
# "nulls_equal" (default), "nulls_unequal", and "nulls_ignored" options. |
|||
|
|||
-- source include/have_innodb_plugin.inc |
|||
|
|||
let $innodb_stats_method_orig = `select @@innodb_stats_method`; |
|||
|
|||
# default setting for innodb_stats_method is "nulls_equal" |
|||
set global innodb_stats_method = default; |
|||
|
|||
select @@innodb_stats_method; |
|||
|
|||
# create three tables, bug30243_1, bug30243_2 and bug30243_3. |
|||
# The test scenario is adopted from original bug #30423 report. |
|||
# table bug30243_1 and bug30243_3 have many NULL values |
|||
|
|||
-- disable_result_log |
|||
-- disable_query_log |
|||
|
|||
DROP TABLE IF EXISTS bug30243_1; |
|||
CREATE TABLE bug30243_1 ( |
|||
org_id int(11) NOT NULL default '0', |
|||
UNIQUE KEY (org_id) |
|||
) ENGINE=InnoDB DEFAULT CHARSET=latin1; |
|||
|
|||
LOCK TABLES bug30243_1 WRITE; |
|||
INSERT INTO bug30243_1 VALUES (11),(15),(16),(17),(19),(20),(21),(23),(24), |
|||
(25),(26),(27),(28),(29),(30),(31),(32),(33),(34),(35),(37),(38),(40),(41), |
|||
(42),(43),(44),(45),(46),(47),(48),(49),(50),(51),(52),(53),(54),(55),(56), |
|||
(57),(58),(59),(60),(61),(62),(63),(64),(65),(66),(67),(68),(69),(70),(71), |
|||
(72),(73),(74),(75),(76),(77),(78),(79),(80),(81),(82),(83),(84),(85),(86), |
|||
(87),(88),(89),(90),(91),(92),(93),(94),(95),(96),(97),(98),(99),(100),(101), |
|||
(102),(103),(104),(105),(106),(107),(108),(109),(110),(111),(112),(113),(114), |
|||
(115),(116),(117),(118),(119),(120),(121),(122),(123),(124),(125),(126),(127), |
|||
(128),(129),(130),(131),(132),(133),(134),(135),(136),(137),(138),(139),(140), |
|||
(141),(142),(143),(144),(145); |
|||
UNLOCK TABLES; |
|||
|
|||
DROP TABLE IF EXISTS bug30243_3; |
|||
CREATE TABLE bug30243_3 ( |
|||
org_id int(11) default NULL, |
|||
KEY (org_id) |
|||
) ENGINE=InnoDB DEFAULT CHARSET=latin1; |
|||
|
|||
INSERT INTO bug30243_3 VALUES (NULL); |
|||
|
|||
begin; |
|||
let $i=14; |
|||
while ($i) |
|||
{ |
|||
INSERT INTO bug30243_3 SELECT NULL FROM bug30243_3; |
|||
dec $i; |
|||
} |
|||
|
|||
INSERT INTO bug30243_3 VALUES (34),(34),(35),(56),(58),(62),(62),(64),(65),(66),(80),(135),(137),(138),(139),(140),(142),(143),(144),(145); |
|||
commit; |
|||
|
|||
DROP TABLE IF EXISTS bug30243_2; |
|||
CREATE TABLE bug30243_2 ( |
|||
org_id int(11) default NULL, |
|||
KEY `contacts$org_id` (org_id) |
|||
) ENGINE=InnoDB DEFAULT CHARSET=latin1; |
|||
|
|||
INSERT INTO bug30243_2 VALUES (NULL); |
|||
|
|||
begin; |
|||
let $i=16; |
|||
while ($i) |
|||
{ |
|||
INSERT INTO bug30243_2 SELECT NULL FROM bug30243_2; |
|||
dec $i; |
|||
} |
|||
|
|||
INSERT INTO bug30243_2 VALUES (11),(15),(16),(17),(20),(21),(23),(24),(25), |
|||
(26),(27),(28),(29),(30),(31),(32),(33),(34),(37),(38),(40),(41),(42),(43), |
|||
(44),(45),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46), |
|||
(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46), |
|||
(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46), |
|||
(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46), |
|||
(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46), |
|||
(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(48), |
|||
(48),(50),(51),(52),(52),(53),(54),(55),(57),(60),(61),(62),(62),(62),(62), |
|||
(62),(63),(64),(64),(65),(66),(66),(67),(68),(69),(70),(71),(72),(73),(74), |
|||
(75),(76),(77),(78),(79),(80),(80),(81),(82),(83),(84),(85),(86),(87),(88), |
|||
(89),(90),(91),(92),(93),(94),(95),(96),(97),(98),(99),(100),(101),(102), |
|||
(103),(104),(105),(106),(107),(108),(109),(110),(111),(112),(113),(114), |
|||
(115),(116),(117),(118),(119),(120),(121),(122),(123),(124),(125),(126), |
|||
(127),(128),(129),(130),(131),(132),(133),(133),(135),(135),(135),(135), |
|||
(136),(136),(138),(138),(139),(139),(139),(140),(141),(141),(142),(143), |
|||
(143),(145),(145); |
|||
commit; |
|||
|
|||
|
|||
-- enable_result_log |
|||
-- enable_query_log |
|||
|
|||
# check tables's value |
|||
select count(*) from bug30243_3 where org_id is not NULL; |
|||
select count(*) from bug30243_3 where org_id is NULL; |
|||
|
|||
select count(*) from bug30243_2 where org_id is not NULL; |
|||
select count(*) from bug30243_2 where org_id is NULL; |
|||
|
|||
select @@innodb_stats_method; |
|||
|
|||
analyze table bug30243_1; |
|||
analyze table bug30243_2; |
|||
analyze table bug30243_3; |
|||
|
|||
# Following query plan shows that we over estimate the rows per |
|||
# unique value (since there are many NULLs). |
|||
# Skip this query log since the stats estimate could vary from runs |
|||
-- disable_query_log |
|||
-- disable_result_log |
|||
explain SELECT COUNT(*), 0 |
|||
FROM bug30243_1 orgs |
|||
LEFT JOIN bug30243_3 sa_opportunities |
|||
ON orgs.org_id=sa_opportunities.org_id |
|||
LEFT JOIN bug30243_2 contacts |
|||
ON orgs.org_id=contacts.org_id ; |
|||
-- enable_query_log |
|||
-- enable_result_log |
|||
|
|||
# following set operation will fail |
|||
#--error ER_WRONG_VALUE_FOR_VAR |
|||
--error 1231 |
|||
set global innodb_stats_method = "NULL"; |
|||
|
|||
set global innodb_stats_method = "nulls_ignored"; |
|||
|
|||
select @@innodb_stats_method; |
|||
|
|||
# Regenerate the stats with "nulls_ignored" option |
|||
|
|||
analyze table bug30243_1; |
|||
analyze table bug30243_2; |
|||
analyze table bug30243_3; |
|||
|
|||
# Following query plan shows that we get the correct rows per |
|||
# unique value (should be approximately 1 row per value) |
|||
explain SELECT COUNT(*), 0 |
|||
FROM bug30243_1 orgs |
|||
LEFT JOIN bug30243_3 sa_opportunities |
|||
ON orgs.org_id=sa_opportunities.org_id |
|||
LEFT JOIN bug30243_2 contacts |
|||
ON orgs.org_id=contacts.org_id ; |
|||
|
|||
select @@innodb_stats_method; |
|||
|
|||
# Try the "nulls_unequal" option |
|||
set global innodb_stats_method = "nulls_unequal"; |
|||
|
|||
select @@innodb_stats_method; |
|||
|
|||
analyze table bug30243_1; |
|||
analyze table bug30243_2; |
|||
analyze table bug30243_3; |
|||
|
|||
# Following query plan shows that we get the correct rows per |
|||
# unique value (~1) |
|||
explain SELECT COUNT(*), 0 |
|||
FROM bug30243_1 orgs |
|||
LEFT JOIN bug30243_3 sa_opportunities |
|||
ON orgs.org_id=sa_opportunities.org_id |
|||
LEFT JOIN bug30243_2 contacts |
|||
ON orgs.org_id=contacts.org_id; |
|||
|
|||
|
|||
# Create a table with all NULL values, make sure the stats calculation |
|||
# does not crash with table of all NULL values |
|||
-- disable_query_log |
|||
CREATE TABLE table_bug30423 ( |
|||
org_id int(11) default NULL, |
|||
KEY(org_id) |
|||
) ENGINE=InnoDB DEFAULT CHARSET=latin1; |
|||
|
|||
INSERT INTO `table_bug30423` VALUES (NULL); |
|||
|
|||
begin; |
|||
let $i=10; |
|||
while ($i) |
|||
{ |
|||
INSERT INTO table_bug30423 SELECT NULL FROM table_bug30423; |
|||
dec $i; |
|||
} |
|||
commit; |
|||
|
|||
-- enable_query_log |
|||
|
|||
SELECT COUNT(*) FROM table_bug30423 WHERE org_id IS NULL; |
|||
|
|||
# calculate the statistics for the table for "nulls_ignored" and |
|||
# "nulls_unequal" option |
|||
set global innodb_stats_method = "nulls_unequal"; |
|||
analyze table table_bug30423; |
|||
|
|||
set global innodb_stats_method = "nulls_ignored"; |
|||
analyze table table_bug30423; |
|||
|
|||
|
|||
eval set global innodb_stats_method = $innodb_stats_method_orig; |
|||
|
|||
drop table bug30243_2; |
|||
|
|||
drop table bug30243_1; |
|||
|
|||
drop table bug30243_3; |
|||
|
|||
drop table table_bug30423; |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue