Skip to content

Commit 31c950c

Browse files
committed
Merge 10.1 into 10.2
2 parents 0e937f3 + c6392d5 commit 31c950c

File tree

11 files changed

+188
-9
lines changed

11 files changed

+188
-9
lines changed

mysql-test/r/statistics.result

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,6 +1682,27 @@ set use_stat_tables=@save_use_stat_tables;
16821682
set optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
16831683
drop table t1,t2;
16841684
#
1685+
# MDEV-16507: statistics for temporary tables should not be used
1686+
#
1687+
SET
1688+
@save_optimizer_use_condition_selectivity= @@optimizer_use_condition_selectivity;
1689+
SET @@use_stat_tables = preferably ;
1690+
SET @@optimizer_use_condition_selectivity = 4;
1691+
CREATE TABLE t1 (
1692+
TIMESTAMP TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
1693+
ON UPDATE CURRENT_TIMESTAMP
1694+
);
1695+
SET @had_t1_table= @@warning_count != 0;
1696+
CREATE TEMPORARY TABLE tmp_t1 LIKE t1;
1697+
INSERT INTO tmp_t1 VALUES (now());
1698+
INSERT INTO t1 SELECT * FROM tmp_t1 WHERE @had_t1_table=0;
1699+
DROP TABLE t1;
1700+
SET
1701+
use_stat_tables=@save_use_stat_tables;
1702+
SET
1703+
optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
1704+
# End of 10.0 tests
1705+
#
16851706
# MDEV-9590: Always print "Engine-independent statistic" warnings and
16861707
# might be filtering columns unintentionally from engines
16871708
#
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#
2+
# MDEV-15953 Alter InnoDB Partitioned Table Moves Files (which were originally not in the datadir) to the datadir
3+
#
4+
CREATE TABLE t (
5+
a INT NOT NULL
6+
) ENGINE=INNODB
7+
PARTITION BY HASH (a) (
8+
PARTITION p1 DATA DIRECTORY = 'MYSQLTEST_VARDIR/tmp/partitions_here/' ENGINE = INNODB,
9+
PARTITION p2 DATA DIRECTORY = 'MYSQLTEST_VARDIR/tmp/partitions_here/' ENGINE = INNODB
10+
);
11+
INSERT INTO t VALUES (1);
12+
SHOW CREATE TABLE t;
13+
Table Create Table
14+
t CREATE TABLE `t` (
15+
`a` int(11) NOT NULL
16+
) ENGINE=InnoDB DEFAULT CHARSET=latin1
17+
PARTITION BY HASH (`a`)
18+
(PARTITION `p1` DATA DIRECTORY = 'MYSQLTEST_VARDIR/tmp/partitions_here' ENGINE = InnoDB,
19+
PARTITION `p2` DATA DIRECTORY = 'MYSQLTEST_VARDIR/tmp/partitions_here' ENGINE = InnoDB)
20+
ALTER TABLE t ADD PRIMARY KEY pk(a), ALGORITHM=INPLACE;
21+
SHOW CREATE TABLE t;
22+
Table Create Table
23+
t CREATE TABLE `t` (
24+
`a` int(11) NOT NULL,
25+
PRIMARY KEY (`a`)
26+
) ENGINE=InnoDB DEFAULT CHARSET=latin1
27+
PARTITION BY HASH (`a`)
28+
(PARTITION `p1` DATA DIRECTORY = 'MYSQLTEST_VARDIR/tmp/partitions_here' ENGINE = InnoDB,
29+
PARTITION `p2` DATA DIRECTORY = 'MYSQLTEST_VARDIR/tmp/partitions_here' ENGINE = InnoDB)
30+
ALTER TABLE t DROP PRIMARY KEY, ALGORITHM=COPY;
31+
SHOW CREATE TABLE t;
32+
Table Create Table
33+
t CREATE TABLE `t` (
34+
`a` int(11) NOT NULL
35+
) ENGINE=InnoDB DEFAULT CHARSET=latin1
36+
PARTITION BY HASH (`a`)
37+
(PARTITION `p1` DATA DIRECTORY = 'MYSQLTEST_VARDIR/tmp/partitions_here' ENGINE = InnoDB,
38+
PARTITION `p2` DATA DIRECTORY = 'MYSQLTEST_VARDIR/tmp/partitions_here' ENGINE = InnoDB)
39+
SET @TMP = @@GLOBAL.INNODB_FILE_PER_TABLE;
40+
SET GLOBAL INNODB_FILE_PER_TABLE=OFF;
41+
ALTER TABLE t ADD PRIMARY KEY pk(a), ALGORITHM=INPLACE;
42+
SHOW CREATE TABLE t;
43+
Table Create Table
44+
t CREATE TABLE `t` (
45+
`a` int(11) NOT NULL,
46+
PRIMARY KEY (`a`)
47+
) ENGINE=InnoDB DEFAULT CHARSET=latin1
48+
PARTITION BY HASH (`a`)
49+
(PARTITION `p1` DATA DIRECTORY = 'MYSQLTEST_VARDIR/tmp/partitions_here' ENGINE = InnoDB,
50+
PARTITION `p2` DATA DIRECTORY = 'MYSQLTEST_VARDIR/tmp/partitions_here' ENGINE = InnoDB)
51+
SET GLOBAL INNODB_FILE_PER_TABLE=@TMP;
52+
ALTER TABLE t REORGANIZE PARTITION p1,p2 INTO (
53+
PARTITION p1 DATA DIRECTORY = 'MYSQLTEST_VARDIR/tmp/partitions_somewhere_else/' ENGINE = INNODB,
54+
PARTITION p2 DATA DIRECTORY = 'MYSQLTEST_VARDIR/tmp/partitions_somewhere_else/' ENGINE = INNODB
55+
);
56+
SHOW CREATE TABLE t;
57+
Table Create Table
58+
t CREATE TABLE `t` (
59+
`a` int(11) NOT NULL,
60+
PRIMARY KEY (`a`)
61+
) ENGINE=InnoDB DEFAULT CHARSET=latin1
62+
PARTITION BY HASH (`a`)
63+
(PARTITION `p1` DATA DIRECTORY = 'MYSQLTEST_VARDIR/tmp/partitions_here' ENGINE = InnoDB,
64+
PARTITION `p2` DATA DIRECTORY = 'MYSQLTEST_VARDIR/tmp/partitions_here' ENGINE = InnoDB)
65+
DROP TABLE t;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
--source include/have_innodb.inc
2+
--source include/have_partition.inc
3+
4+
--echo #
5+
--echo # MDEV-15953 Alter InnoDB Partitioned Table Moves Files (which were originally not in the datadir) to the datadir
6+
--echo #
7+
8+
mkdir $MYSQLTEST_VARDIR/tmp/partitions_here;
9+
10+
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
11+
eval CREATE TABLE t (
12+
a INT NOT NULL
13+
) ENGINE=INNODB
14+
PARTITION BY HASH (a) (
15+
PARTITION p1 DATA DIRECTORY = '$MYSQLTEST_VARDIR/tmp/partitions_here/' ENGINE = INNODB,
16+
PARTITION p2 DATA DIRECTORY = '$MYSQLTEST_VARDIR/tmp/partitions_here/' ENGINE = INNODB
17+
);
18+
INSERT INTO t VALUES (1);
19+
20+
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
21+
SHOW CREATE TABLE t;
22+
ALTER TABLE t ADD PRIMARY KEY pk(a), ALGORITHM=INPLACE;
23+
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
24+
SHOW CREATE TABLE t;
25+
ALTER TABLE t DROP PRIMARY KEY, ALGORITHM=COPY;
26+
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
27+
SHOW CREATE TABLE t;
28+
SET @TMP = @@GLOBAL.INNODB_FILE_PER_TABLE;
29+
SET GLOBAL INNODB_FILE_PER_TABLE=OFF;
30+
ALTER TABLE t ADD PRIMARY KEY pk(a), ALGORITHM=INPLACE;
31+
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
32+
SHOW CREATE TABLE t;
33+
SET GLOBAL INNODB_FILE_PER_TABLE=@TMP;
34+
35+
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
36+
eval ALTER TABLE t REORGANIZE PARTITION p1,p2 INTO (
37+
PARTITION p1 DATA DIRECTORY = '$MYSQLTEST_VARDIR/tmp/partitions_somewhere_else/' ENGINE = INNODB,
38+
PARTITION p2 DATA DIRECTORY = '$MYSQLTEST_VARDIR/tmp/partitions_somewhere_else/' ENGINE = INNODB
39+
);
40+
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
41+
SHOW CREATE TABLE t;
42+
43+
DROP TABLE t;
44+
45+
rmdir $MYSQLTEST_VARDIR/tmp/partitions_here/test;
46+
rmdir $MYSQLTEST_VARDIR/tmp/partitions_here;

mysql-test/t/statistics.test

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,32 @@ set use_stat_tables=@save_use_stat_tables;
818818
set optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
819819
drop table t1,t2;
820820

821+
--echo #
822+
--echo # MDEV-16507: statistics for temporary tables should not be used
823+
--echo #
824+
825+
SET
826+
@save_optimizer_use_condition_selectivity= @@optimizer_use_condition_selectivity;
827+
SET @@use_stat_tables = preferably ;
828+
SET @@optimizer_use_condition_selectivity = 4;
829+
830+
CREATE TABLE t1 (
831+
TIMESTAMP TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
832+
ON UPDATE CURRENT_TIMESTAMP
833+
);
834+
835+
SET @had_t1_table= @@warning_count != 0;
836+
CREATE TEMPORARY TABLE tmp_t1 LIKE t1;
837+
INSERT INTO tmp_t1 VALUES (now());
838+
INSERT INTO t1 SELECT * FROM tmp_t1 WHERE @had_t1_table=0;
839+
DROP TABLE t1;
840+
841+
SET
842+
use_stat_tables=@save_use_stat_tables;
843+
SET
844+
optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
845+
--echo # End of 10.0 tests
846+
821847
--echo #
822848
--echo # MDEV-9590: Always print "Engine-independent statistic" warnings and
823849
--echo # might be filtering columns unintentionally from engines

sql/ha_partition.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5079,7 +5079,8 @@ int ha_partition::rnd_pos_by_record(uchar *record)
50795079
if (unlikely(get_part_for_delete(record, m_rec0, m_part_info, &m_last_part)))
50805080
DBUG_RETURN(1);
50815081

5082-
DBUG_RETURN(handler::rnd_pos_by_record(record));
5082+
int err= m_file[m_last_part]->rnd_pos_by_record(record);
5083+
DBUG_RETURN(err);
50835084
}
50845085

50855086

sql/handler.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3230,9 +3230,17 @@ class handler :public Sql_alloc
32303230
*/
32313231
virtual int rnd_pos_by_record(uchar *record)
32323232
{
3233+
int error;
32333234
DBUG_ASSERT(table_flags() & HA_PRIMARY_KEY_REQUIRED_FOR_POSITION);
3235+
3236+
error = ha_rnd_init(false);
3237+
if (error != 0)
3238+
return error;
3239+
32343240
position(record);
3235-
return rnd_pos(record, ref);
3241+
error = ha_rnd_pos(record, ref);
3242+
ha_rnd_end();
3243+
return error;
32363244
}
32373245
virtual int read_first_row(uchar *buf, uint primary_key);
32383246
public:

sql/log_event.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13109,10 +13109,6 @@ int Rows_log_event::find_row(rpl_group_info *rgi)
1310913109
int error;
1311013110
DBUG_PRINT("info",("locating record using primary key (position)"));
1311113111

13112-
if (!table->file->inited &&
13113-
(error= table->file->ha_rnd_init_with_error(0)))
13114-
DBUG_RETURN(error);
13115-
1311613112
error= table->file->ha_rnd_pos_by_record(table->record[0]);
1311713113
if (error)
1311813114
{

sql/sql_statistics.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3101,7 +3101,7 @@ bool statistics_for_tables_is_needed(THD *thd, TABLE_LIST *tables)
31013101

31023102
for (TABLE_LIST *tl= tables; tl; tl= tl->next_global)
31033103
{
3104-
if (!tl->is_view_or_derived() && tl->table)
3104+
if (!tl->is_view_or_derived() && !is_temporary_table(tl) && tl->table)
31053105
{
31063106
TABLE_SHARE *table_share= tl->table->s;
31073107
if (table_share &&
@@ -3113,7 +3113,7 @@ bool statistics_for_tables_is_needed(THD *thd, TABLE_LIST *tables)
31133113

31143114
for (TABLE_LIST *tl= tables; tl; tl= tl->next_global)
31153115
{
3116-
if (!tl->is_view_or_derived() && tl->table)
3116+
if (!tl->is_view_or_derived() && !is_temporary_table(tl) && tl->table)
31173117
{
31183118
TABLE_SHARE *table_share= tl->table->s;
31193119
if (table_share &&
@@ -3242,7 +3242,7 @@ int read_statistics_for_tables_if_needed(THD *thd, TABLE_LIST *tables)
32423242

32433243
for (TABLE_LIST *tl= tables; tl; tl= tl->next_global)
32443244
{
3245-
if (!tl->is_view_or_derived() && tl->table)
3245+
if (!tl->is_view_or_derived() && !is_temporary_table(tl) && tl->table)
32463246
{
32473247
TABLE_SHARE *table_share= tl->table->s;
32483248
if (table_share &&

storage/innobase/handler/ha_innodb.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,9 @@ class create_table_info_t
745745
ulint flags() const
746746
{ return(m_flags); }
747747

748+
/** Update table flags. */
749+
void flags_set(ulint flags) { m_flags |= flags; }
750+
748751
/** Get table flags2. */
749752
ulint flags2() const
750753
{ return(m_flags2); }

storage/innobase/handler/handler0alter.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5727,6 +5727,13 @@ ha_innobase::prepare_inplace_alter_table(
57275727
goto err_exit_no_heap;
57285728
}
57295729

5730+
if (info.flags2() & DICT_TF2_USE_FILE_PER_TABLE) {
5731+
/* Preserve the DATA DIRECTORY attribute, because it
5732+
currently cannot be changed during ALTER TABLE. */
5733+
info.flags_set(m_prebuilt->table->flags
5734+
& 1U << DICT_TF_POS_DATA_DIR);
5735+
}
5736+
57305737
max_col_len = DICT_MAX_FIELD_LEN_BY_FORMAT_FLAG(info.flags());
57315738

57325739
/* Check each index's column length to make sure they do not

0 commit comments

Comments
 (0)