Commit 742b37a3 authored by Marko Mäkelä's avatar Marko Mäkelä

Merge 10.2 into 10.3

parents 4e9366df b2a5e0f2
......@@ -6777,6 +6777,49 @@ sum(z)
DROP TABLE t1;
DROP VIEW v1;
#
# MDEV-24454: Crash at change_item_tree
#
CREATE TABLE t1(f0 INT);
CREATE VIEW v1 AS
SELECT
f0 AS f1
FROM t1;
CREATE VIEW v2 AS
SELECT
(SELECT GROUP_CONCAT(v1.f1 SEPARATOR ', ')
FROM v1 n) AS f2,
GROUP_CONCAT('' SEPARATOR ', ') AS f3
FROM v1;
CREATE VIEW v3 AS
SELECT 1 as f4 FROM v2;
CREATE PROCEDURE p1()
SELECT * FROM v3;
CALL p1();
f4
1
CALL p1();
f4
1
drop procedure p1;
drop view v1,v2,v3;
drop table t1;
#
# MDEV-25631: Crash in st_select_lex::mark_as_dependent with
# VIEW, aggregate and subquery
#
CREATE TABLE t1 (i1 int);
insert into t1 values (1),(2),(3);
CREATE VIEW v1 AS
SELECT t1.i1 FROM (t1 a JOIN t1 ON (t1.i1 = (SELECT t1.i1 FROM t1 b)));
SELECT 1 FROM (SELECT count(((SELECT i1 FROM v1))) FROM v1) dt ;
ERROR 21000: Subquery returns more than 1 row
delete from t1 where i1 > 1;
SELECT 1 FROM (SELECT count(((SELECT i1 FROM v1))) FROM v1) dt ;
1
1
drop view v1;
drop table t1;
#
# End of 10.2 tests
#
#
......
......@@ -6499,6 +6499,55 @@ SELECT sum(z) FROM v1;
DROP TABLE t1;
DROP VIEW v1;
--echo #
--echo # MDEV-24454: Crash at change_item_tree
--echo #
CREATE TABLE t1(f0 INT);
CREATE VIEW v1 AS
SELECT
f0 AS f1
FROM t1;
CREATE VIEW v2 AS
SELECT
(SELECT GROUP_CONCAT(v1.f1 SEPARATOR ', ')
FROM v1 n) AS f2,
GROUP_CONCAT('' SEPARATOR ', ') AS f3
FROM v1;
CREATE VIEW v3 AS
SELECT 1 as f4 FROM v2;
CREATE PROCEDURE p1()
SELECT * FROM v3;
CALL p1();
CALL p1();
drop procedure p1;
drop view v1,v2,v3;
drop table t1;
--echo #
--echo # MDEV-25631: Crash in st_select_lex::mark_as_dependent with
--echo # VIEW, aggregate and subquery
--echo #
CREATE TABLE t1 (i1 int);
insert into t1 values (1),(2),(3); #not important
CREATE VIEW v1 AS
SELECT t1.i1 FROM (t1 a JOIN t1 ON (t1.i1 = (SELECT t1.i1 FROM t1 b)));
--error ER_SUBQUERY_NO_1_ROW
SELECT 1 FROM (SELECT count(((SELECT i1 FROM v1))) FROM v1) dt ;
delete from t1 where i1 > 1;
SELECT 1 FROM (SELECT count(((SELECT i1 FROM v1))) FROM v1) dt ;
drop view v1;
drop table t1;
--echo #
--echo # End of 10.2 tests
--echo #
......
......@@ -34,31 +34,3 @@ COUNT(f1) = 1000
1
DROP TABLE t1;
DROP TABLE ten;
connection node_1;
SET @value=REPEAT (1,5001);
CREATE TABLE t (a VARCHAR(5000),FULLTEXT (a)) engine=innodb DEFAULT CHARSET=utf8;
INSERT IGNORE INTO t VALUES(@value);
Warnings:
Warning 1265 Data truncated for column 'a' at row 1
SELECT COUNT(*) FROM t;
COUNT(*)
1
connection node_2;
SELECT COUNT(*) FROM t;
COUNT(*)
1
connection node_1;
DROP TABLE t;
CREATE TABLE t (a VARCHAR(5000)) engine=innodb DEFAULT CHARSET=utf8;
INSERT IGNORE INTO t VALUES(@value);
Warnings:
Warning 1265 Data truncated for column 'a' at row 1
SELECT COUNT(*) FROM t;
COUNT(*)
1
connection node_2;
SELECT COUNT(*) FROM t;
COUNT(*)
1
connection node_1;
DROP TABLE t;
--source include/big_test.inc
--source include/galera_cluster.inc
--source include/have_innodb.inc
#
# InnoDB FULLTEXT indexes
......@@ -63,24 +61,25 @@ DROP TABLE ten;
#
# Case 2: UTF-8
# TODO: MDEV-24978
#
--connection node_1
SET @value=REPEAT (1,5001);
CREATE TABLE t (a VARCHAR(5000),FULLTEXT (a)) engine=innodb DEFAULT CHARSET=utf8;
INSERT IGNORE INTO t VALUES(@value);
SELECT COUNT(*) FROM t;
--connection node_2
SELECT COUNT(*) FROM t;
--connection node_1
DROP TABLE t;
CREATE TABLE t (a VARCHAR(5000)) engine=innodb DEFAULT CHARSET=utf8;
INSERT IGNORE INTO t VALUES(@value);
SELECT COUNT(*) FROM t;
--connection node_2
SELECT COUNT(*) FROM t;
--connection node_1
DROP TABLE t;
#--connection node_1
#SET @value=REPEAT (1,5001);
#CREATE TABLE t (a VARCHAR(5000),FULLTEXT (a)) engine=innodb DEFAULT CHARSET=utf8;
#INSERT IGNORE INTO t VALUES(@value);
#SELECT COUNT(*) FROM t;
#
#--connection node_2
#SELECT COUNT(*) FROM t;
#
#--connection node_1
#DROP TABLE t;
#CREATE TABLE t (a VARCHAR(5000)) engine=innodb DEFAULT CHARSET=utf8;
#INSERT IGNORE INTO t VALUES(@value);
#SELECT COUNT(*) FROM t;
#
#--connection node_2
#SELECT COUNT(*) FROM t;
#
#--connection node_1
#DROP TABLE t;
SET GLOBAL innodb_defragment_stats_accuracy = 20;
DELETE FROM mysql.innodb_index_stats;
# Create table.
CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY AUTO_INCREMENT, b VARCHAR(256), KEY SECOND(a, b)) ENGINE=INNODB;
INSERT INTO t1 SELECT seq, REPEAT('A', 256) FROM seq_1_to_1024;
CREATE TABLE t1 (a INT PRIMARY KEY AUTO_INCREMENT, b VARCHAR(256),
KEY SECOND(a, b)) ENGINE=INNODB STATS_PERSISTENT=0;
INSERT INTO t1 SELECT 100*FLOOR(seq/70)+seq%70, REPEAT('A', 256)
FROM seq_1_to_1024;
# Not enough page splits to trigger persistent stats write yet.
select count(stat_value) = 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_page_split');
count(stat_value) = 0
1
select count(stat_value) = 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_pages_freed');
count(stat_value) = 0
1
select count(stat_value) = 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_leaf_pages_defrag');
count(stat_value) = 0
1
INSERT INTO t1 SELECT seq, REPEAT('A', 256) FROM seq_1025_to_2048;
# Persistent stats recorded.
select count(stat_value) > 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_page_split');
count(stat_value) > 0
1
select count(stat_value) = 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_pages_freed');
count(stat_value) = 0
1
select count(stat_value) > 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_leaf_pages_defrag');
count(stat_value) > 0
1
# Delete some rows.
SELECT * FROM mysql.innodb_index_stats;
database_name table_name index_name last_update stat_name stat_value sample_size stat_description
INSERT INTO t1 SELECT 100*FLOOR(seq/70)+seq%70, REPEAT('A', 256)
FROM seq_1025_to_1433;
BEGIN;
delete from t1 where a between 100 * 20 and 100 * 20 + 30;
delete from t1 where a between 100 * 19 and 100 * 19 + 30;
delete from t1 where a between 100 * 18 and 100 * 18 + 30;
delete from t1 where a between 100 * 17 and 100 * 17 + 30;
delete from t1 where a between 100 * 16 and 100 * 16 + 30;
delete from t1 where a between 100 * 15 and 100 * 15 + 30;
delete from t1 where a between 100 * 14 and 100 * 14 + 30;
delete from t1 where a between 100 * 13 and 100 * 13 + 30;
delete from t1 where a between 100 * 12 and 100 * 12 + 30;
delete from t1 where a between 100 * 11 and 100 * 11 + 30;
delete from t1 where a between 100 * 10 and 100 * 10 + 30;
delete from t1 where a between 100 * 9 and 100 * 9 + 30;
delete from t1 where a between 100 * 8 and 100 * 8 + 30;
delete from t1 where a between 100 * 7 and 100 * 7 + 30;
delete from t1 where a between 100 * 6 and 100 * 6 + 30;
delete from t1 where a between 100 * 5 and 100 * 5 + 30;
delete from t1 where a between 100 * 4 and 100 * 4 + 30;
delete from t1 where a between 100 * 3 and 100 * 3 + 30;
delete from t1 where a between 100 * 2 and 100 * 2 + 30;
delete from t1 where a between 100 * 1 and 100 * 1 + 30;
COMMIT;
select count(stat_value) > 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_page_split');
count(stat_value) > 0
1
select count(stat_value) = 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_pages_freed');
count(stat_value) = 0
1
select count(stat_value) > 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_leaf_pages_defrag');
count(stat_value) > 0
1
INSERT INTO t1 SELECT 100*20+seq, REPEAT('A', 256)
FROM seq_70_to_99;
INSERT INTO t1 SELECT 100*19+seq, REPEAT('A', 256)
FROM seq_70_to_99;
INSERT INTO t1 SELECT 100*18+seq, REPEAT('A', 256)
FROM seq_70_to_99;
INSERT INTO t1 SELECT 100*17+seq, REPEAT('A', 256)
FROM seq_70_to_99;
INSERT INTO t1 SELECT 100*16+seq, REPEAT('A', 256)
FROM seq_70_to_99;
INSERT INTO t1 SELECT 100*15+seq, REPEAT('A', 256)
FROM seq_70_to_99;
INSERT INTO t1 SELECT 100*14+seq, REPEAT('A', 256)
FROM seq_70_to_99;
INSERT INTO t1 SELECT 100*13+seq, REPEAT('A', 256)
FROM seq_70_to_99;
INSERT INTO t1 SELECT 100*12+seq, REPEAT('A', 256)
FROM seq_70_to_99;
INSERT INTO t1 SELECT 100*11+seq, REPEAT('A', 256)
FROM seq_70_to_99;
INSERT INTO t1 SELECT 100*10+seq, REPEAT('A', 256)
FROM seq_70_to_99;
INSERT INTO t1 SELECT 100*9+seq, REPEAT('A', 256)
FROM seq_70_to_99;
INSERT INTO t1 SELECT 100*8+seq, REPEAT('A', 256)
FROM seq_70_to_99;
INSERT INTO t1 SELECT 100*7+seq, REPEAT('A', 256)
FROM seq_70_to_99;
INSERT INTO t1 SELECT 100*6+seq, REPEAT('A', 256)
FROM seq_70_to_99;
INSERT INTO t1 SELECT 100*5+seq, REPEAT('A', 256)
FROM seq_70_to_99;
INSERT INTO t1 SELECT 100*4+seq, REPEAT('A', 256)
FROM seq_70_to_99;
INSERT INTO t1 SELECT 100*3+seq, REPEAT('A', 256)
FROM seq_70_to_99;
INSERT INTO t1 SELECT 100*2+seq, REPEAT('A', 256)
FROM seq_70_to_99;
INSERT INTO t1 SELECT 100*1+seq, REPEAT('A', 256)
FROM seq_70_to_99;
ROLLBACK;
SELECT @@GLOBAL.innodb_force_recovery<2 "have background defragmentation";
have background defragmentation
1
SELECT table_name, index_name, stat_name FROM mysql.innodb_index_stats;
table_name index_name stat_name
t1 PRIMARY n_leaf_pages_defrag
t1 PRIMARY n_leaf_pages_reserved
t1 PRIMARY n_page_split
t1 SECOND n_leaf_pages_defrag
t1 SECOND n_leaf_pages_reserved
t1 SECOND n_page_split
optimize table t1;
Table Op Msg_type Msg_text
test.t1 optimize status OK
select count(stat_value) > 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_page_split');
count(stat_value) > 0
1
select count(stat_value) > 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_pages_freed');
count(stat_value) > 0
1
select count(stat_value) > 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_leaf_pages_defrag');
count(stat_value) > 0
1
SELECT table_name, index_name, stat_name FROM mysql.innodb_index_stats;
table_name index_name stat_name
t1 PRIMARY n_leaf_pages_defrag
t1 PRIMARY n_leaf_pages_reserved
t1 PRIMARY n_page_split
t1 PRIMARY n_pages_freed
t1 SECOND n_leaf_pages_defrag
t1 SECOND n_leaf_pages_reserved
t1 SECOND n_page_split
t1 SECOND n_pages_freed
set global innodb_defragment_stats_accuracy = 40;
INSERT INTO t1 (b) SELECT b from t1;
select count(stat_value) > 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_page_split');
count(stat_value) > 0
1
select count(stat_value) > 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_pages_freed');
count(stat_value) > 0
1
select count(stat_value) > 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_leaf_pages_defrag');
count(stat_value) > 0
1
SELECT table_name, index_name, stat_name FROM mysql.innodb_index_stats;
table_name index_name stat_name
t1 PRIMARY n_leaf_pages_defrag
t1 PRIMARY n_leaf_pages_reserved
t1 PRIMARY n_page_split
t1 PRIMARY n_pages_freed
t1 SECOND n_leaf_pages_defrag
t1 SECOND n_leaf_pages_reserved
t1 SECOND n_page_split
t1 SECOND n_pages_freed
INSERT INTO t1 (b) SELECT b from t1;
select count(stat_value) > 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_page_split');
count(stat_value) > 0
1
select count(stat_value) > 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_pages_freed');
count(stat_value) > 0
1
select count(stat_value) > 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_leaf_pages_defrag');
count(stat_value) > 0
1
SELECT stat_name FROM mysql.innodb_index_stats WHERE table_name='t1';
stat_name
n_leaf_pages_defrag
n_leaf_pages_defrag
n_leaf_pages_reserved
n_leaf_pages_reserved
n_page_split
n_page_split
n_pages_freed
n_pages_freed
# Table rename should cause stats rename.
rename table t1 to t2;
select count(stat_value) = 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_page_split');
count(stat_value) = 0
1
select count(stat_value) = 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_pages_freed');
count(stat_value) = 0
1
select count(stat_value) = 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_leaf_pages_defrag');
count(stat_value) = 0
1
select count(stat_value) > 0 from mysql.innodb_index_stats where table_name like '%t2%' and stat_name in ('n_page_split');
count(stat_value) > 0
1
select count(stat_value) > 0 from mysql.innodb_index_stats where table_name like '%t2%' and stat_name in ('n_pages_freed');
count(stat_value) > 0
1
select count(stat_value) > 0 from mysql.innodb_index_stats where table_name like '%t2%' and stat_name in ('n_leaf_pages_defrag');
count(stat_value) > 0
1
SELECT table_name, index_name, stat_name FROM mysql.innodb_index_stats;
table_name index_name stat_name
t2 PRIMARY n_leaf_pages_defrag
t2 PRIMARY n_leaf_pages_reserved
t2 PRIMARY n_page_split
t2 PRIMARY n_pages_freed
t2 SECOND n_leaf_pages_defrag
t2 SECOND n_leaf_pages_reserved
t2 SECOND n_page_split
t2 SECOND n_pages_freed
# Drop index should cause stats drop, but will not.
drop index SECOND on t2;
SELECT stat_name, stat_value>0 FROM mysql.innodb_index_stats
WHERE table_name like '%t2%' AND index_name='SECOND';
stat_name stat_value>0
n_leaf_pages_defrag 1
n_leaf_pages_reserved 1
n_page_split 1
n_pages_freed 1
#
# MDEV-26636: Statistics must not be written for temporary tables
#
......@@ -125,20 +120,18 @@ SET GLOBAL innodb_defragment_stats_accuracy = 1;
CREATE TEMPORARY TABLE t (a INT PRIMARY KEY, c CHAR(255) NOT NULL)
ENGINE=InnoDB;
INSERT INTO t SELECT seq, '' FROM seq_1_to_100;
SELECT * FROM mysql.innodb_index_stats where table_name like '%t1%';
database_name table_name index_name last_update stat_name stat_value sample_size stat_description
SELECT table_name, index_name, stat_name, stat_value>0
FROM mysql.innodb_index_stats;
table_name index_name stat_name stat_value>0
t2 PRIMARY n_leaf_pages_defrag 1
t2 PRIMARY n_leaf_pages_reserved 1
t2 PRIMARY n_page_split 1
t2 PRIMARY n_pages_freed 1
t2 SECOND n_leaf_pages_defrag 1
t2 SECOND n_leaf_pages_reserved 1
t2 SECOND n_page_split 1
t2 SECOND n_pages_freed 1
SELECT table_name, index_name, stat_name FROM mysql.innodb_index_stats;
table_name index_name stat_name
t2 PRIMARY n_leaf_pages_defrag
t2 PRIMARY n_leaf_pages_reserved
t2 PRIMARY n_page_split
t2 PRIMARY n_pages_freed
t2 SECOND n_leaf_pages_defrag
t2 SECOND n_leaf_pages_reserved
t2 SECOND n_page_split
t2 SECOND n_pages_freed
# Clean up
ALTER TABLE t2 STATS_PERSISTENT=1;
DROP TABLE t2;
SELECT * FROM mysql.innodb_index_stats;
database_name table_name index_name last_update stat_name stat_value sample_size stat_description
......@@ -8,77 +8,65 @@ SET GLOBAL innodb_defragment_stats_accuracy = 20;
DELETE FROM mysql.innodb_index_stats;
--echo # Create table.
CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY AUTO_INCREMENT, b VARCHAR(256), KEY SECOND(a, b)) ENGINE=INNODB;
CREATE TABLE t1 (a INT PRIMARY KEY AUTO_INCREMENT, b VARCHAR(256),
KEY SECOND(a, b)) ENGINE=INNODB STATS_PERSISTENT=0;
INSERT INTO t1 SELECT seq, REPEAT('A', 256) FROM seq_1_to_1024;
INSERT INTO t1 SELECT 100*FLOOR(seq/70)+seq%70, REPEAT('A', 256)
FROM seq_1_to_1024;
--echo # Not enough page splits to trigger persistent stats write yet.
select count(stat_value) = 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_page_split');
select count(stat_value) = 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_pages_freed');
select count(stat_value) = 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_leaf_pages_defrag');
INSERT INTO t1 SELECT seq, REPEAT('A', 256) FROM seq_1025_to_2048;
SELECT * FROM mysql.innodb_index_stats;
--echo # Persistent stats recorded.
select count(stat_value) > 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_page_split');
select count(stat_value) = 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_pages_freed');
select count(stat_value) > 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_leaf_pages_defrag');
INSERT INTO t1 SELECT 100*FLOOR(seq/70)+seq%70, REPEAT('A', 256)
FROM seq_1025_to_1433;
--echo # Delete some rows.
BEGIN;
let $num_delete = 20;
while ($num_delete)
{
let $j = 100 * $num_delete;
eval delete from t1 where a between $j and $j + 30;
eval INSERT INTO t1 SELECT 100*$num_delete+seq, REPEAT('A', 256)
FROM seq_70_to_99;
dec $num_delete;
}
COMMIT;
ROLLBACK;
SELECT @@GLOBAL.innodb_force_recovery<2 "have background defragmentation";
# Wait for defrag_pool to be processed.
select count(stat_value) > 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_page_split');
select count(stat_value) = 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_pages_freed');
select count(stat_value) > 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_leaf_pages_defrag');
let $wait_timeout=30;
let $wait_condition = SELECT COUNT(*)>0 FROM mysql.innodb_index_stats;
--source include/wait_condition.inc
--sorted_result
SELECT table_name, index_name, stat_name FROM mysql.innodb_index_stats;
optimize table t1;
select count(stat_value) > 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_page_split');
select count(stat_value) > 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_pages_freed');
select count(stat_value) > 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_leaf_pages_defrag');
--sorted_result
SELECT table_name, index_name, stat_name FROM mysql.innodb_index_stats;
set global innodb_defragment_stats_accuracy = 40;
INSERT INTO t1 (b) SELECT b from t1;
select count(stat_value) > 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_page_split');
select count(stat_value) > 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_pages_freed');
select count(stat_value) > 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_leaf_pages_defrag');
--sorted_result
SELECT table_name, index_name, stat_name FROM mysql.innodb_index_stats;
INSERT INTO t1 (b) SELECT b from t1;
select count(stat_value) > 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_page_split');
select count(stat_value) > 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_pages_freed');
select count(stat_value) > 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_leaf_pages_defrag');
--sorted_result
SELECT stat_name FROM mysql.innodb_index_stats WHERE table_name='t1';
--echo # Table rename should cause stats rename.
rename table t1 to t2;
select count(stat_value) = 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_page_split');
select count(stat_value) = 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_pages_freed');
select count(stat_value) = 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name in ('n_leaf_pages_defrag');
select count(stat_value) > 0 from mysql.innodb_index_stats where table_name like '%t2%' and stat_name in ('n_page_split');
select count(stat_value) > 0 from mysql.innodb_index_stats where table_name like '%t2%' and stat_name in ('n_pages_freed');
select count(stat_value) > 0 from mysql.innodb_index_stats where table_name like '%t2%' and stat_name in ('n_leaf_pages_defrag');
--sorted_result
SELECT table_name, index_name, stat_name FROM mysql.innodb_index_stats;
--echo # Drop index should cause stats drop, but will not.
drop index SECOND on t2;
--sorted_result
SELECT stat_name, stat_value>0 FROM mysql.innodb_index_stats
WHERE table_name like '%t2%' AND index_name='SECOND';
--echo #
--echo # MDEV-26636: Statistics must not be written for temporary tables
--echo #
......@@ -89,13 +77,13 @@ INSERT INTO t SELECT seq, '' FROM seq_1_to_100;
--source include/restart_mysqld.inc
SELECT * FROM mysql.innodb_index_stats where table_name like '%t1%';
--sorted_result
SELECT table_name, index_name, stat_name, stat_value>0
FROM mysql.innodb_index_stats;
SELECT table_name, index_name, stat_name FROM mysql.innodb_index_stats;
--echo # Clean up
# Starting with 10.6, DROP TABLE will not touch persistent statistics
# (not defragmentation statistics either) if the table has none!
ALTER TABLE t2 STATS_PERSISTENT=1;
DROP TABLE t2;
SELECT * FROM mysql.innodb_index_stats;
......@@ -24,3 +24,19 @@ VARIABLE_VALUE>0 VARIABLE_NAME
1 Collation used latin1_swedish_ci
1 Collation used utf8_bin
1 Collation used utf8_general_ci
prepare stmt from "SELECT VARIABLE_VALUE>0, VARIABLE_NAME FROM INFORMATION_SCHEMA.FEEDBACK WHERE VARIABLE_NAME LIKE 'Collation used %' ORDER BY VARIABLE_NAME";
execute stmt;
VARIABLE_VALUE>0 VARIABLE_NAME
1 Collation used binary
1 Collation used latin1_bin
1 Collation used latin1_swedish_ci
1 Collation used utf8_bin
1 Collation used utf8_general_ci
execute stmt;
VARIABLE_VALUE>0 VARIABLE_NAME
1 Collation used binary
1 Collation used latin1_bin
1 Collation used latin1_swedish_ci
1 Collation used utf8_bin
1 Collation used utf8_general_ci
deallocate prepare stmt;
......@@ -42,3 +42,10 @@ if (`SELECT VERSION() LIKE '%embedded%'`)
SELECT VARIABLE_VALUE>0, VARIABLE_NAME FROM INFORMATION_SCHEMA.FEEDBACK
WHERE VARIABLE_NAME LIKE 'Collation used %'
ORDER BY VARIABLE_NAME;
prepare stmt from "SELECT VARIABLE_VALUE>0, VARIABLE_NAME FROM INFORMATION_SCHEMA.FEEDBACK WHERE VARIABLE_NAME LIKE 'Collation used %' ORDER BY VARIABLE_NAME";
execute stmt;
execute stmt;
deallocate prepare stmt;
......@@ -92,16 +92,18 @@ static COND * const OOM= (COND*)1;
static COND* make_cond(THD *thd, TABLE_LIST *tables, LEX_STRING *filter)
{
Item_cond_or *res= NULL;
Name_resolution_context nrc;
/* A reference to this context will be stored in Item_field */
Name_resolution_context *nrc= new (thd->mem_root) Name_resolution_context;
const char *db= tables->db.str, *table= tables->alias.str;
LEX_CSTRING *field= &tables->table->field[0]->field_name;
CHARSET_INFO *cs= &my_charset_latin1;
if (!filter->str)
if (!filter->str || !nrc)
return 0;
nrc.init();
nrc.resolve_in_table_list_only(tables);
nrc->init();
nrc->resolve_in_table_list_only(tables);
nrc->select_lex= tables->select_lex;
res= new (thd->mem_root) Item_cond_or(thd);
if (!res)
......@@ -109,7 +111,7 @@ static COND* make_cond(THD *thd, TABLE_LIST *tables, LEX_STRING *filter)
for (; filter->str; filter++)
{
Item_field *fld= new (thd->mem_root) Item_field(thd, &nrc, db, table,
Item_field *fld= new (thd->mem_root) Item_field(thd, nrc, db, table,
field);
Item_string *pattern= new (thd->mem_root) Item_string(thd, filter->str,
(uint) filter->length, cs);
......
......@@ -70,11 +70,12 @@ bool cmp_items(Item *a, Item *b)
/**
Set max_sum_func_level if it is needed
*/
inline void set_max_sum_func_level(THD *thd, SELECT_LEX *select)
inline void set_max_sum_func_level(SELECT_LEX *select)
{
if (thd->lex->in_sum_func &&
thd->lex->in_sum_func->nest_level >= select->nest_level)
set_if_bigger(thd->lex->in_sum_func->max_sum_func_level,
LEX *lex_s= select->parent_lex;
if (lex_s->in_sum_func &&
lex_s->in_sum_func->nest_level >= select->nest_level)
set_if_bigger(lex_s->in_sum_func->max_sum_func_level,
select->nest_level - 1);
}
......@@ -768,6 +769,7 @@ Item_ident::Item_ident(THD *thd, Name_resolution_context *context_arg,
cached_table(0), depended_from(0), can_be_depended(TRUE)
{
name= *field_name_arg;
DBUG_ASSERT(!context || context->select_lex);
}
......@@ -783,6 +785,7 @@ Item_ident::Item_ident(THD *thd, TABLE_LIST *view_arg,
cached_table(NULL), depended_from(NULL), can_be_depended(TRUE)
{
name= *field_name_arg;
DBUG_ASSERT(!context || context->select_lex);
}
......@@ -804,7 +807,9 @@ Item_ident::Item_ident(THD *thd, Item_ident *item)
cached_table(item->cached_table),
depended_from(item->depended_from),
can_be_depended(item->can_be_depended)
{}
{
DBUG_ASSERT(!context || context->select_lex);
}
void Item_ident::cleanup()
{
......@@ -5727,7 +5732,14 @@ Item_field::fix_outer_field(THD *thd, Field **from_field, Item **reference)
*/
Name_resolution_context *last_checked_context= context;
Item **ref= (Item **) not_found_item;
SELECT_LEX *current_sel= thd->lex->current_select;
/*
There are cases when name resolution context is absent (when we are not
doing name resolution), but here the name resolution context should
be present because we are doing name resolution
*/
DBUG_ASSERT(context);
SELECT_LEX *current_sel= context->select_lex;
LEX *lex_s= context->select_lex->parent_lex;
Name_resolution_context *outer_context= 0;
SELECT_LEX *select= 0;
/* Currently derived tables cannot be correlated */
......@@ -5828,18 +5840,18 @@ Item_field::fix_outer_field(THD *thd, Field **from_field, Item **reference)
return -1;
thd->change_item_tree(reference, rf);
select->inner_refs_list.push_back(rf, thd->mem_root);
rf->in_sum_func= thd->lex->in_sum_func;
rf->in_sum_func= lex_s->in_sum_func;
}
/*
A reference is resolved to a nest level that's outer or the same as
the nest level of the enclosing set function : adjust the value of
max_arg_level for the function if it's needed.
*/
if (thd->lex->in_sum_func &&
thd->lex->in_sum_func->nest_level >= select->nest_level)
if (lex_s->in_sum_func &&
lex_s->in_sum_func->nest_level >= select->nest_level)
{
Item::Type ref_type= (*reference)->type();
set_if_bigger(thd->lex->in_sum_func->max_arg_level,
set_if_bigger(lex_s->in_sum_func->max_arg_level,
select->nest_level);
set_field(*from_field);
fixed= 1;
......@@ -5860,10 +5872,10 @@ Item_field::fix_outer_field(THD *thd, Field **from_field, Item **reference)
((ref_type == REF_ITEM || ref_type == FIELD_ITEM) ?
(Item_ident*) (*reference) :
0), false);
if (thd->lex->in_sum_func &&
thd->lex->in_sum_func->nest_level >= select->nest_level)
if (lex_s->in_sum_func &&
lex_s->in_sum_func->nest_level >= select->nest_level)
{
set_if_bigger(thd->lex->in_sum_func->max_arg_level,
set_if_bigger(lex_s->in_sum_func->max_arg_level,
select->nest_level);
}
/*
......@@ -5955,7 +5967,7 @@ Item_field::fix_outer_field(THD *thd, Field **from_field, Item **reference)
{
outer_context->select_lex->inner_refs_list.push_back((Item_outer_ref*)rf,
thd->mem_root);
((Item_outer_ref*)rf)->in_sum_func= thd->lex->in_sum_func;
((Item_outer_ref*)rf)->in_sum_func= lex_s->in_sum_func;
}
thd->change_item_tree(reference, rf);
/*
......@@ -5970,7 +5982,7 @@ Item_field::fix_outer_field(THD *thd, Field **from_field, Item **reference)
We can not "move" aggregate function in the place where
its arguments are not defined.
*/
set_max_sum_func_level(thd, select);
set_max_sum_func_level(select);
mark_as_dependent(thd, last_checked_context->select_lex,
context->select_lex, rf,
rf, false);
......@@ -5983,7 +5995,7 @@ Item_field::fix_outer_field(THD *thd, Field **from_field, Item **reference)
We can not "move" aggregate function in the place where
its arguments are not defined.
*/
set_max_sum_func_level(thd, select);
set_max_sum_func_level(select);
mark_as_dependent(thd, last_checked_context->select_lex,
context->select_lex,
this, (Item_ident*)*reference, false);
......@@ -6061,7 +6073,20 @@ bool Item_field::fix_fields(THD *thd, Item **reference)
DBUG_ASSERT(fixed == 0);
Field *from_field= (Field *)not_found_field;
bool outer_fixed= false;
SELECT_LEX *select= thd->lex->current_select;
SELECT_LEX *select;
LEX *lex_s;
if (context)
{
select= context->select_lex;
lex_s= context->select_lex->parent_lex;
}
else
{
// No real name resolution, used somewhere in SP
DBUG_ASSERT(field);
select= NULL;
lex_s= NULL;
}
if (select && select->in_tvc)
{
......@@ -6129,7 +6154,7 @@ bool Item_field::fix_fields(THD *thd, Item **reference)
We can not "move" aggregate function in the place where
its arguments are not defined.
*/
set_max_sum_func_level(thd, select);
set_max_sum_func_level(select);
set_field(new_field);
depended_from= (*((Item_field**)res))->depended_from;
return 0;
......@@ -6157,7 +6182,7 @@ bool Item_field::fix_fields(THD *thd, Item **reference)
We can not "move" aggregate function in the place where
its arguments are not defined.
*/
set_max_sum_func_level(thd, select);
set_max_sum_func_level(select);
return FALSE;
}
}
......@@ -6194,10 +6219,11 @@ bool Item_field::fix_fields(THD *thd, Item **reference)
goto mark_non_agg_field;
}
if (thd->lex->in_sum_func &&
thd->lex->in_sum_func->nest_level ==
if (lex_s &&
lex_s->in_sum_func &&
lex_s->in_sum_func->nest_level ==
select->nest_level)
set_if_bigger(thd->lex->in_sum_func->max_arg_level,
set_if_bigger(lex_s->in_sum_func->max_arg_level,
select->nest_level);
/*
if it is not expression from merged VIEW we will set this field.
......@@ -6263,8 +6289,9 @@ bool Item_field::fix_fields(THD *thd, Item **reference)
if (field->vcol_info)
fix_session_vcol_expr_for_read(thd, field, field->vcol_info);
if (thd->variables.sql_mode & MODE_ONLY_FULL_GROUP_BY &&
!outer_fixed && !thd->lex->in_sum_func &&
!outer_fixed &&
select &&
!lex_s->in_sum_func &&
select->cur_pos_in_select_list != UNDEF_POS &&
select->join)
{
......@@ -6299,13 +6326,13 @@ bool Item_field::fix_fields(THD *thd, Item **reference)
*/
select_lex= context->select_lex;
}
if (!thd->lex->in_sum_func)
if (!lex_s || !lex_s->in_sum_func)
select_lex->set_non_agg_field_used(true);
else
{
if (outer_fixed)
thd->lex->in_sum_func->outer_fields.push_back(this, thd->mem_root);
else if (thd->lex->in_sum_func->nest_level !=
lex_s->in_sum_func->outer_fields.push_back(this, thd->mem_root);
else if (lex_s->in_sum_func->nest_level !=
select->nest_level)
select_lex->set_non_agg_field_used(true);
}
......@@ -7582,6 +7609,12 @@ Item *get_field_item_for_having(THD *thd, Item *item, st_select_lex *sel)
return NULL;
}
Item *Item_ident::derived_field_transformer_for_having(THD *thd, uchar *arg)
{
st_select_lex *sel= (st_select_lex *)arg;
context= &sel->context;
return this;
}
Item *Item_field::derived_field_transformer_for_having(THD *thd, uchar *arg)
{
......@@ -7601,12 +7634,13 @@ Item *Item_field::derived_field_transformer_for_having(THD *thd, uchar *arg)
Item *Item_direct_view_ref::derived_field_transformer_for_having(THD *thd,
uchar *arg)
{
st_select_lex *sel= (st_select_lex *)arg;
context= &sel->context;
if ((*ref)->marker & SUBSTITUTION_FL)
{
this->marker|= SUBSTITUTION_FL;
return this;
}
st_select_lex *sel= (st_select_lex *)arg;
table_map tab_map= sel->master_unit()->derived->table->map;
if ((item_equal && !(item_equal->used_tables() & tab_map)) ||
!item_equal)
......@@ -7903,7 +7937,9 @@ bool Item_ref::fix_fields(THD *thd, Item **reference)
{
enum_parsing_place place= NO_MATTER;
DBUG_ASSERT(fixed == 0);
SELECT_LEX *current_sel= thd->lex->current_select;
SELECT_LEX *current_sel= context->select_lex;
LEX *lex_s= context->select_lex->parent_lex;
if (set_properties_only)
{
......@@ -8064,10 +8100,10 @@ bool Item_ref::fix_fields(THD *thd, Item **reference)
the nest level of the enclosing set function : adjust the value of
max_arg_level for the function if it's needed.
*/
if (thd->lex->in_sum_func &&
thd->lex->in_sum_func->nest_level >=
if (lex_s->in_sum_func &&
lex_s->in_sum_func->nest_level >=
last_checked_context->select_lex->nest_level)
set_if_bigger(thd->lex->in_sum_func->max_arg_level,
set_if_bigger(lex_s->in_sum_func->max_arg_level,
last_checked_context->select_lex->nest_level);
return FALSE;
}
......@@ -8087,10 +8123,10 @@ bool Item_ref::fix_fields(THD *thd, Item **reference)
the nest level of the enclosing set function : adjust the value of
max_arg_level for the function if it's needed.
*/
if (thd->lex->in_sum_func &&
thd->lex->in_sum_func->nest_level >=
if (lex_s->in_sum_func &&
lex_s->in_sum_func->nest_level >=
last_checked_context->select_lex->nest_level)
set_if_bigger(thd->lex->in_sum_func->max_arg_level,
set_if_bigger(lex_s->in_sum_func->max_arg_level,
last_checked_context->select_lex->nest_level);
}
}
......
......@@ -2967,6 +2967,7 @@ class Item_ident :public Item_result_field
Collect outer references
*/
virtual bool collect_outer_ref_processor(void *arg);
Item *derived_field_transformer_for_having(THD *thd, uchar *arg);
friend bool insert_fields(THD *thd, Name_resolution_context *context,
const char *db_name,
const char *table_name, List_iterator<Item> *it,
......
......@@ -5186,8 +5186,9 @@ bool subselect_hash_sj_engine::make_semi_join_conds()
tmp_table_ref->init_one_table(&empty_clex_str, &table_name, NULL, TL_READ);
tmp_table_ref->table= tmp_table;
context= new Name_resolution_context;
context= new (thd->mem_root) Name_resolution_context;
context->init();
context->select_lex= item_in->unit->first_select();
context->first_name_resolution_table=
context->last_name_resolution_table= tmp_table_ref;
semi_join_conds_context= context;
......
......@@ -72,6 +72,7 @@ size_t Item_sum::ram_limitation(THD *thd)
bool Item_sum::init_sum_func_check(THD *thd)
{
SELECT_LEX *curr_sel= thd->lex->current_select;
LEX *lex_s= (curr_sel ? curr_sel->parent_lex : thd->lex);
if (curr_sel && curr_sel->name_visibility_map.is_clear_all())
{
for (SELECT_LEX *sl= curr_sel; sl; sl= sl->context.outer_select())
......@@ -87,9 +88,9 @@ bool Item_sum::init_sum_func_check(THD *thd)
return TRUE;
}
/* Set a reference to the nesting set function if there is any */
in_sum_func= thd->lex->in_sum_func;
in_sum_func= lex_s->in_sum_func;
/* Save a pointer to object to be used in items for nested set functions */
thd->lex->in_sum_func= this;
lex_s->in_sum_func= this;
nest_level= thd->lex->current_select->nest_level;
ref_by= 0;
aggr_level= -1;
......@@ -156,6 +157,7 @@ bool Item_sum::init_sum_func_check(THD *thd)
bool Item_sum::check_sum_func(THD *thd, Item **ref)
{
SELECT_LEX *curr_sel= thd->lex->current_select;
LEX *lex_s= curr_sel->parent_lex;
nesting_map allow_sum_func(thd->lex->allow_sum_func);
allow_sum_func.intersect(curr_sel->name_visibility_map);
bool invalid= FALSE;
......@@ -318,7 +320,7 @@ bool Item_sum::check_sum_func(THD *thd, Item **ref)
if (sum_func() == SP_AGGREGATE_FUNC)
aggr_sel->set_custom_agg_func_used(true);
update_used_tables();
thd->lex->in_sum_func= in_sum_func;
lex_s->in_sum_func= in_sum_func;
return FALSE;
}
......
......@@ -6736,6 +6736,7 @@ set_new_item_local_context(THD *thd, Item_ident *item, TABLE_LIST *table_ref)
if (!(context= new (thd->mem_root) Name_resolution_context))
return TRUE;
context->init();
context->select_lex= table_ref->select_lex;
context->first_name_resolution_table=
context->last_name_resolution_table= table_ref;
item->context= context;
......
......@@ -3027,6 +3027,7 @@ void reinit_stmt_before_use(THD *thd, LEX *lex)
}
for (; sl; sl= sl->next_select_in_list())
{
sl->parent_lex->in_sum_func= NULL;
if (sl->changed_elements & TOUCHED_SEL_COND)
{
/* remove option which was put by mysql_explain_union() */
......@@ -3157,7 +3158,6 @@ void reinit_stmt_before_use(THD *thd, LEX *lex)
lex->result->set_thd(thd);
}
lex->allow_sum_func.clear_all();
lex->in_sum_func= NULL;
DBUG_VOID_RETURN;
}
......
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