Skip to content

Commit 3d56adb

Browse files
committed
Merge 10.2 into 10.3
2 parents b7d22a8 + 796486d commit 3d56adb

File tree

10 files changed

+179
-3
lines changed

10 files changed

+179
-3
lines changed

client/mysqlimport.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ static char *add_load_option(char *ptr,const char *object,
4848
const char *statement);
4949

5050
static my_boolverbose=0,lock_tables=0,ignore_errors=0,opt_delete=0,
51-
replace=0,silent=0,ignore=0,opt_compress=0,
52-
opt_low_priority= 0, tty_password= 0;
51+
replace, silent, ignore, ignore_foreign_keys,
52+
opt_compress, opt_low_priority, tty_password;
5353
static my_bool debug_info_flag= 0, debug_check_flag= 0;
5454
static uint opt_use_threads=0, opt_local_file=0, my_end_arg= 0;
5555
static char*opt_password=0, *current_user=0,
@@ -123,6 +123,10 @@ static struct my_option my_long_options[] =
123123
&current_host, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
124124
{"ignore", 'i', "If duplicate unique key was found, keep old row.",
125125
&ignore, &ignore, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
126+
{"ignore-foreign-keys", 'k',
127+
"Disable foreign key checks while importing the data.",
128+
&ignore_foreign_keys, &ignore_foreign_keys, 0, GET_BOOL, NO_ARG,
129+
0, 0, 0, 0, 0, 0},
126130
{"ignore-lines", OPT_IGN_LINES, "Ignore first n lines of data infile.",
127131
&opt_ignore_lines, &opt_ignore_lines, 0, GET_LL,
128132
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
@@ -489,6 +493,9 @@ static MYSQL *db_connect(char *host, char *database,
489493
ignore_errors=0;
490494
db_error(mysql);
491495
}
496+
if (ignore_foreign_keys)
497+
mysql_query(mysql, "set foreign_key_checks= 0;");
498+
492499
return mysql;
493500
}
494501

mysql-test/main/mysqldump.result

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5639,6 +5639,24 @@ DROP FUNCTION f;
56395639
DROP VIEW v1;
56405640
DROP FUNCTION f;
56415641
#
5642+
# MDEV-788 New option to ignore foreign key contraints in mysqlimport
5643+
#
5644+
create table t1 (
5645+
id int primary key
5646+
) engine=InnoDB;
5647+
create table t2 (
5648+
t1_id int,
5649+
CONSTRAINT fk
5650+
FOREIGN KEY (t1_id) REFERENCES t1 (id)
5651+
) ENGINE = InnoDB;
5652+
select count(*) from t2;
5653+
count(*)
5654+
1
5655+
select count(*) from t2;
5656+
count(*)
5657+
2
5658+
drop tables t2, t1;
5659+
#
56425660
# Test for --add-drop-trigger
56435661
#
56445662
use test;

mysql-test/main/mysqldump.test

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2500,6 +2500,7 @@ DROP TABLE t1;
25002500
DROP TABLE t2;
25012501
DROP DATABASE db_20772273;
25022502
USE test;
2503+
--remove_file $MYSQLTEST_VARDIR/tmp/t2.txt
25032504

25042505
--echo #
25052506
--echo # Bug #25717383: MYSQLDUMP MAY EXECUTE ANY ARBITRARY QUERY
@@ -2668,6 +2669,34 @@ DROP FUNCTION f;
26682669
DROP VIEW v1;
26692670
DROP FUNCTION f;
26702671

2672+
--echo #
2673+
--echo # MDEV-788 New option to ignore foreign key contraints in mysqlimport
2674+
--echo #
2675+
create table t1 (
2676+
id int primary key
2677+
) engine=InnoDB;
2678+
2679+
create table t2 (
2680+
t1_id int,
2681+
CONSTRAINT fk
2682+
FOREIGN KEY (t1_id) REFERENCES t1 (id)
2683+
) ENGINE = InnoDB;
2684+
2685+
--write_file $MYSQLTEST_VARDIR/tmp/t2.txt
2686+
0
2687+
EOF
2688+
2689+
--error 1
2690+
--exec $MYSQL_IMPORT --silent test $MYSQLTEST_VARDIR/tmp/t2.txt
2691+
--exec $MYSQL_IMPORT --silent -k test $MYSQLTEST_VARDIR/tmp/t2.txt
2692+
select count(*) from t2;
2693+
2694+
--exec $MYSQL_IMPORT --silent --ignore-foreign-keys test $MYSQLTEST_VARDIR/tmp/t2.txt
2695+
select count(*) from t2;
2696+
2697+
--remove_file $MYSQLTEST_VARDIR/tmp/t2.txt
2698+
drop tables t2, t1;
2699+
26712700
--echo #
26722701
--echo # Test for --add-drop-trigger
26732702
--echo #

mysql-test/main/stat_tables.result

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,8 +707,38 @@ ERROR 42S02: Table 'test.x' doesn't exist
707707
select * from information_schema.tables where table_name='v';
708708
TABLE_CATALOG TABLE_SCHEMA TABLE_NAME TABLE_TYPE ENGINE VERSION ROW_FORMAT TABLE_ROWS AVG_ROW_LENGTH DATA_LENGTH MAX_DATA_LENGTH INDEX_LENGTH DATA_FREE AUTO_INCREMENT CREATE_TIME UPDATE_TIME CHECK_TIME TABLE_COLLATION CHECKSUM CREATE_OPTIONS TABLE_COMMENT MAX_INDEX_LENGTH TEMPORARY
709709
def test v VIEW NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL VIEW NULL NULL
710+
set @@optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
710711
drop table t1,t2;
711712
drop view v;
713+
#
714+
# MDEV-19407: Assertion `field->table->stats_is_read' failed in is_eits_usable
715+
#
716+
set @save_optimizer_use_condition_selectivity= @@optimizer_use_condition_selectivity;
717+
set @@optimizer_use_condition_selectivity= 1;
718+
set @@use_stat_tables='never';
719+
create table t1(pk int);
720+
insert into t1 values (4),(3);
721+
set @@optimizer_use_condition_selectivity= 4;
722+
set use_stat_tables='preferably';
723+
INSERT INTO t1 SELECT * FROM x;
724+
ERROR 42S02: Table 'test.x' doesn't exist
725+
CREATE TABLE t2 SELECT pk FROM t1 WHERE pk>2;
726+
select * from t2;
727+
pk
728+
4
729+
3
730+
drop table t1,t2;
731+
create table t1(a int,b int, key k1(a) );
732+
insert into t1 values(1,1),(2,2),(3,3);
733+
analyze table t1;
734+
Table Op Msg_type Msg_text
735+
test.t1 analyze status Engine-independent statistics collected
736+
test.t1 analyze status OK
737+
select * from mysql.index_stats, t1 where index_name='k1' and t1.a > 1 and t1.b > 1;
738+
db_name table_name index_name prefix_arity avg_frequency a b
739+
test t1 k1 1 1.0000 2 2
740+
test t1 k1 1 1.0000 3 3
741+
drop table t1;
712742
set @@optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
713743
set @save_optimizer_switch=@@optimizer_switch;
714744
set use_stat_tables=@save_use_stat_tables;

mysql-test/main/stat_tables.test

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,9 +469,35 @@ CREATE VIEW v AS SELECT * FROM t1 JOIN t2;
469469
INSERT INTO t2 SELECT * FROM x;
470470

471471
select * from information_schema.tables where table_name='v';
472+
set @@optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
472473

473474
drop table t1,t2;
474475
drop view v;
476+
477+
--echo #
478+
--echo # MDEV-19407: Assertion `field->table->stats_is_read' failed in is_eits_usable
479+
--echo #
480+
481+
set @save_optimizer_use_condition_selectivity= @@optimizer_use_condition_selectivity;
482+
set @@optimizer_use_condition_selectivity= 1;
483+
set @@use_stat_tables='never';
484+
create table t1(pk int);
485+
insert into t1 values (4),(3);
486+
set @@optimizer_use_condition_selectivity= 4;
487+
set use_stat_tables='preferably';
488+
489+
--error ER_NO_SUCH_TABLE
490+
INSERT INTO t1 SELECT * FROM x;
491+
CREATE TABLE t2 SELECT pk FROM t1 WHERE pk>2;
492+
select * from t2;
493+
drop table t1,t2;
494+
495+
create table t1(a int,b int, key k1(a) );
496+
insert into t1 values(1,1),(2,2),(3,3);
497+
analyze table t1;
498+
select * from mysql.index_stats, t1 where index_name='k1' and t1.a > 1 and t1.b > 1;
499+
drop table t1;
500+
475501
set @@optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
476502

477503
set @save_optimizer_switch=@@optimizer_switch;

mysql-test/main/stat_tables_innodb.result

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,8 +734,38 @@ ERROR 42S02: Table 'test.x' doesn't exist
734734
select * from information_schema.tables where table_name='v';
735735
TABLE_CATALOG TABLE_SCHEMA TABLE_NAME TABLE_TYPE ENGINE VERSION ROW_FORMAT TABLE_ROWS AVG_ROW_LENGTH DATA_LENGTH MAX_DATA_LENGTH INDEX_LENGTH DATA_FREE AUTO_INCREMENT CREATE_TIME UPDATE_TIME CHECK_TIME TABLE_COLLATION CHECKSUM CREATE_OPTIONS TABLE_COMMENT MAX_INDEX_LENGTH TEMPORARY
736736
def test v VIEW NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL VIEW NULL NULL
737+
set @@optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
737738
drop table t1,t2;
738739
drop view v;
740+
#
741+
# MDEV-19407: Assertion `field->table->stats_is_read' failed in is_eits_usable
742+
#
743+
set @save_optimizer_use_condition_selectivity= @@optimizer_use_condition_selectivity;
744+
set @@optimizer_use_condition_selectivity= 1;
745+
set @@use_stat_tables='never';
746+
create table t1(pk int);
747+
insert into t1 values (4),(3);
748+
set @@optimizer_use_condition_selectivity= 4;
749+
set use_stat_tables='preferably';
750+
INSERT INTO t1 SELECT * FROM x;
751+
ERROR 42S02: Table 'test.x' doesn't exist
752+
CREATE TABLE t2 SELECT pk FROM t1 WHERE pk>2;
753+
select * from t2;
754+
pk
755+
4
756+
3
757+
drop table t1,t2;
758+
create table t1(a int,b int, key k1(a) );
759+
insert into t1 values(1,1),(2,2),(3,3);
760+
analyze table t1;
761+
Table Op Msg_type Msg_text
762+
test.t1 analyze status Engine-independent statistics collected
763+
test.t1 analyze status OK
764+
select * from mysql.index_stats, t1 where index_name='k1' and t1.a > 1 and t1.b > 1;
765+
db_name table_name index_name prefix_arity avg_frequency a b
766+
test t1 k1 1 1.0000 2 2
767+
test t1 k1 1 1.0000 3 3
768+
drop table t1;
739769
set @@optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
740770
set @save_optimizer_switch=@@optimizer_switch;
741771
set use_stat_tables=@save_use_stat_tables;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
SET @saved_frequency = @@GLOBAL.innodb_purge_rseg_truncate_frequency;
2+
SET GLOBAL innodb_purge_rseg_truncate_frequency = 1;
3+
CREATE TABLE t1 (g MULTIPOINT NOT NULL) ENGINE=InnoDB;
4+
INSERT INTO t1 VALUES ('');
5+
connect purge_control,localhost,root;
6+
START TRANSACTION WITH CONSISTENT SNAPSHOT;
7+
connection default;
8+
DELETE FROM t1;
9+
ALTER TABLE t1 ADD SPATIAL INDEX (g);
10+
disconnect purge_control;
11+
InnoDB 0 transactions not purged
12+
DROP TABLE t1;
13+
SET GLOBAL innodb_purge_rseg_truncate_frequency = @saved_frequency;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--source include/have_innodb.inc
2+
3+
SET @saved_frequency = @@GLOBAL.innodb_purge_rseg_truncate_frequency;
4+
SET GLOBAL innodb_purge_rseg_truncate_frequency = 1;
5+
6+
CREATE TABLE t1 (g MULTIPOINT NOT NULL) ENGINE=InnoDB;
7+
INSERT INTO t1 VALUES ('');
8+
9+
connect purge_control,localhost,root;
10+
START TRANSACTION WITH CONSISTENT SNAPSHOT;
11+
connection default;
12+
13+
DELETE FROM t1;
14+
15+
ALTER TABLE t1 ADD SPATIAL INDEX (g);
16+
17+
disconnect purge_control;
18+
--source ../../innodb/include/wait_all_purged.inc
19+
DROP TABLE t1;
20+
SET GLOBAL innodb_purge_rseg_truncate_frequency = @saved_frequency;

sql/opt_range.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3045,7 +3045,7 @@ bool calculate_cond_selectivity_for_table(THD *thd, TABLE *table, Item **cond)
30453045

30463046
if (thd->variables.optimizer_use_condition_selectivity > 2 &&
30473047
!bitmap_is_clear_all(used_fields) &&
3048-
thd->variables.use_stat_tables > 0)
3048+
thd->variables.use_stat_tables > 0 && table->stats_is_read)
30493049
{
30503050
PARAM param;
30513051
MEM_ROOT alloc;

sql/sql_statistics.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2199,6 +2199,9 @@ inline bool statistics_for_command_is_needed(THD *thd)
21992199
case SQLCOM_DELETE_MULTI:
22002200
case SQLCOM_REPLACE:
22012201
case SQLCOM_REPLACE_SELECT:
2202+
case SQLCOM_CREATE_TABLE:
2203+
case SQLCOM_SET_OPTION:
2204+
case SQLCOM_DO:
22022205
break;
22032206
default:
22042207
return FALSE;

0 commit comments

Comments
 (0)