1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 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 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
|
--source include/have_debug.inc
--source include/have_debug_sync.inc
--echo # Testing of histogram statistics that uses DEBUG functionality.
--echo #
--echo # Simulate a failure due to dropping histograms during DROP TABLE
--echo #
CREATE TABLE t1 (col1 INT, col2 INT);
ANALYZE TABLE t1 UPDATE HISTOGRAM ON col1, col2 WITH 10 BUCKETS;
SELECT schema_name, table_name, column_name
FROM information_schema.COLUMN_STATISTICS;
SELECT schema_name, table_name, column_name
FROM information_schema.COLUMN_STATISTICS;
SELECT COUNT(*) FROM information_schema.TABLES
WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME = 't1';
SET DEBUG='+d,fail_after_drop_histograms';
--error ER_UNABLE_TO_DROP_COLUMN_STATISTICS
DROP TABLE t1;
SELECT schema_name, table_name, column_name
FROM information_schema.COLUMN_STATISTICS;
SELECT COUNT(*) FROM information_schema.TABLES
WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME = 't1';
SET DEBUG='-d,fail_after_drop_histograms';
--echo #
--echo # Simulate a failure due to dropping histograms during ALTER TABLE
--echo #
SELECT schema_name, table_name, column_name
FROM information_schema.COLUMN_STATISTICS;
SELECT COUNT(*) FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME = 't1' AND COLUMN_NAME = 'col2';
SET DEBUG='+d,fail_after_drop_histograms';
--error ER_UNABLE_TO_DROP_COLUMN_STATISTICS
ALTER TABLE t1 DROP COLUMN col2;
SELECT schema_name, table_name, column_name
FROM information_schema.COLUMN_STATISTICS;
SELECT COUNT(*) FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME = 't1' AND COLUMN_NAME = 'col2';
SET DEBUG='-d,fail_after_drop_histograms';
--echo #
--echo # Simulate a failure due to renaming histograms during ALTER TABLE RENAME
--echo #
SELECT schema_name, table_name, column_name
FROM information_schema.COLUMN_STATISTICS;
SELECT COUNT(*) FROM information_schema.TABLES
WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME = 't1';
SET DEBUG='+d,fail_after_rename_histograms';
--error ER_UNABLE_TO_UPDATE_COLUMN_STATISTICS
ALTER TABLE t1 RENAME TO t2;
SELECT schema_name, table_name, column_name
FROM information_schema.COLUMN_STATISTICS;
SELECT COUNT(*) FROM information_schema.TABLES
WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME = 't1';
SET DEBUG='-d,fail_after_rename_histograms';
DROP TABLE t1;
--echo #
--echo # Check that histogram with sampling works as expected
--echo #
SET DEBUG='+d,histogram_force_sampling';
CREATE TABLE t1 (col1 DOUBLE);
INSERT INTO t1 SELECT RAND(1);
INSERT INTO t1 SELECT RAND(2) FROM t1;
INSERT INTO t1 SELECT RAND(3) FROM t1;
INSERT INTO t1 SELECT RAND(4) FROM t1;
INSERT INTO t1 SELECT RAND(5) FROM t1;
INSERT INTO t1 SELECT RAND(6) FROM t1;
INSERT INTO t1 SELECT RAND(7) FROM t1;
INSERT INTO t1 SELECT RAND(8) FROM t1;
INSERT INTO t1 SELECT RAND(9) FROM t1;
INSERT INTO t1 SELECT RAND(10) FROM t1;
ANALYZE TABLE t1 UPDATE HISTOGRAM ON col1 WITH 4 BUCKETS;
SELECT schema_name, table_name, column_name,
JSON_REMOVE(histogram, '$."last-updated"')
FROM information_schema.COLUMN_STATISTICS;
SET DEBUG='-d,histogram_force_sampling';
DROP TABLE t1;
--echo #
--echo # Bug#26020352 WL8943:ASSERTION `M_THD->GET_TRANSACTION()->IS_EMPTY(
--echo # TRANSACTION_CTX::STMT) && M
--echo #
CREATE TABLE t1 (col1 INT);
ANALYZE TABLE t1 UPDATE HISTOGRAM ON col1 WITH 10 BUCKETS;
SELECT schema_name, table_name, column_name
FROM information_schema.COLUMN_STATISTICS;
SET DEBUG='+d,histogram_fail_after_open_table';
ANALYZE TABLE t1 UPDATE HISTOGRAM ON col1 WITH 10 BUCKETS;
SELECT schema_name, table_name, column_name
FROM information_schema.COLUMN_STATISTICS;
SET DEBUG='-d,histogram_fail_after_open_table';
DROP TABLE t1;
--echo #
--echo # Bug#26027240 WL8943:VIRTUAL BOOL SQL_CMD_ANALYZE_TABLE::EXECUTE(THD*):
--echo # ASSERTION `FALSE' FAIL
--echo #
CREATE TABLE t1 (col1 INT);
ANALYZE TABLE t1 UPDATE HISTOGRAM ON col1 WITH 10 BUCKETS;
SET DEBUG='+d,histogram_fail_during_lock_for_write';
ANALYZE TABLE t1 DROP HISTOGRAM ON col1;
--echo # Since we have simulated a fail, the histogram should still be present.
--echo # However, since this is a simulation of failure no error is reported.
SELECT schema_name, table_name, column_name
FROM information_schema.COLUMN_STATISTICS;
SET DEBUG='-d,histogram_fail_during_lock_for_write';
ANALYZE TABLE t1 DROP HISTOGRAM ON col1;
--echo # The histogram should now be gone.
SELECT schema_name, table_name, column_name
FROM information_schema.COLUMN_STATISTICS;
DROP TABLE t1;
--echo #
--echo # Bug#26772858 MDL FOR COLUMN STATISTICS IS NOT PROPERLY REFLECTED IN
--echo # P_S.METADATA_LOCKS
--echo #
connect(con1, localhost, root,,);
CREATE TABLE t1 (col1 INT);
SET DEBUG_SYNC='store_histogram_after_write_lock SIGNAL histogram_1_waiting WAIT_FOR continue_store_histogram';
--send ANALYZE TABLE t1 UPDATE HISTOGRAM ON col1 WITH 2 BUCKETS;
# The connection 'con1' will now wait on the debug sync point
# "store_histogram_after_write_lock", where it has acquired an exclusive lock
# on the histogram object. Switch connection, and inspect the metadata locks
# table in performance schema in order to verify that OBJECT_TYPE is properly
# reflected. Wait until 'con1' has signaled that it actually is waiting
--connection default
SET DEBUG_SYNC='now WAIT_FOR histogram_1_waiting';
SELECT OBJECT_TYPE, OBJECT_SCHEMA, OBJECT_NAME, COLUMN_NAME
FROM performance_schema.metadata_locks
WHERE LOCK_TYPE = "EXCLUSIVE"
AND OBJECT_TYPE = "COLUMN STATISTICS"
ORDER BY OBJECT_TYPE, OBJECT_SCHEMA, OBJECT_NAME, COLUMN_NAME;
# While 'con1' still is waiting on the sync point right after the exclusive lock
# is aquired, open a new connection and create a histogram for the same column.
# The effect we want is a wait on the same MDL, so that we can inspect that
# the lock is fully reflected in performance_schema.events_waits_*
connect(con2, localhost, root,,);
SET DEBUG_SYNC='mdl_acquire_lock_wait SIGNAL histogram_2_lock_waiting';
--send ANALYZE TABLE t1 UPDATE HISTOGRAM ON col1 WITH 2 BUCKETS;
# Go back to the default connection, and verify the contents of
# performance_schema.events_waits_*. Wait until 'con2' has signaled that it is
# actually waiting for the lock.
--connection default
SET DEBUG_SYNC='now WAIT_FOR histogram_2_lock_waiting';
SELECT OBJECT_TYPE, OBJECT_SCHEMA, OBJECT_NAME, INDEX_NAME
FROM performance_schema.events_waits_current
WHERE OBJECT_TYPE = "COLUMN STATISTICS"
ORDER BY OBJECT_TYPE, OBJECT_SCHEMA, OBJECT_NAME, INDEX_NAME;
# Finally let 'con1' finish building the histogram. Once 'con1' has released the
# MDL on the column statistics object, 'con2' will continue and do its work.
SET DEBUG_SYNC='now SIGNAL continue_store_histogram';
--connection con1
--reap
--disconnect con1
--source include/wait_until_disconnected.inc
--connection con2
--reap
--disconnect con2
--source include/wait_until_disconnected.inc
--connection default
DROP TABLE t1;
--echo #
--echo # Bug#27672693 HISTOGRAMS: ASSERTION FAILED: !THD->TX_READ_ONLY
--echo #
CREATE TABLE t1(col1 INT);
SET LOCAL TRANSACTION READ ONLY;
--error ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION
INSERT INTO t1 (col1) VALUES (1);
ANALYZE TABLE t1 UPDATE HISTOGRAM ON col1 WITH 16 BUCKETS;
SET LOCAL TRANSACTION READ WRITE;
INSERT INTO t1 (col1) VALUES (1);
ANALYZE TABLE t1 UPDATE HISTOGRAM ON col1 WITH 16 BUCKETS;
DROP TABLE t1;
--echo #
--echo # Additional tests for bug#29634540 "DROP DATABASE OF 1 MILLION
--echo # TABLES ...".
--echo #
--echo # Check that DROP DATABASE statement doesn't acquire metadata locks
--echo # on column statistics while dropping it.
--echo #
--enable_connect_log
CREATE DATABASE mysqltest;
CREATE TABLE mysqltest.t1 (i INT);
INSERT INTO mysqltest.t1 VALUES (1), (2), (3);
ANALYZE TABLE mysqltest.t1 UPDATE HISTOGRAM ON i WITH 10 BUCKETS;
CREATE TABLE mysqltest.t2 (j INT);
--echo # Run DROP DATABASE which will be paused near its end.
SET DEBUG_SYNC = 'rm_table_no_locks_before_binlog SIGNAL drop_waiting WAIT_FOR drop_resume';
--send DROP DATABASE mysqltest
--connect(con1, localhost, root,,)
--echo # Wait until DROP DATABASE gets paused and check what MDL
--echo # it has acquired. There should be X locks on both tables
--echo # and no locks on column statistics.
SET DEBUG_SYNC = 'now WAIT_FOR drop_waiting';
SELECT object_type, object_schema, object_name, column_name, lock_type
FROM performance_schema.metadata_locks
WHERE object_schema = "mysqltest"
ORDER BY object_type, object_schema, object_name, column_name, lock_type;
--echo #
--echo # Run concurrent ANALYZE TABLE ... DROP HISTOGRAM on table from
--echo # database being dropped.
--send ANALYZE TABLE mysqltest.t1 DROP HISTOGRAM ON i
--connect(con2, localhost, root,,)
--echo # Check that it will be blocked thanks to table MDL.
let $wait_condition=
SELECT COUNT(*) = 1 FROM information_schema.processlist
WHERE state = "Waiting for table metadata lock" and
info = "ANALYZE TABLE mysqltest.t1 DROP HISTOGRAM ON i";
--source include/wait_condition.inc
--echo # Unpause DROP DATABASE.
SET DEBUG_SYNC = 'now SIGNAL drop_resume';
--disconnect con2
--source include/wait_until_disconnected.inc
--connection con1
--echo # Reap ANALYZE TABLE ... DROP HISTOGRAM, which should not have
--echo # found any histograms since database has been dropped.
--reap
--disconnect con1
--source include/wait_until_disconnected.inc
--connection default
--echo # Reap DROP DATABASE
--reap
--echo # Clean-up.
SET DEBUG_SYNC = 'RESET';
--disable_connect_log
|