1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

MDEV-30544 Deprecate innodb_defragment and related parameters

There is a little used option innodb_defragment that would make
OPTIMIZE TABLE not rebuild the table as usual for InnoDB, but
instead cause the index B-trees to be optimized in place.

This option uses excessive locking (exclusively locking index trees).
It never covered SPATIAL INDEX or FULLTEXT INDEX. Storage space
was never reclaimed.

Because this option is not particularly useful and causes a
maintenance burden (most recently in
commit de4030e4d4),
it is best to deprecate it, to prepare for its removal.
This commit is contained in:
Marko Mäkelä
2023-02-02 07:46:08 +02:00
parent 2b13ae1a31
commit d5d7c8ba96
16 changed files with 96 additions and 8 deletions

View File

@ -1,2 +1 @@
--default-storage-engine=MyISAM
--innodb-defragment=0

View File

@ -1,4 +1,6 @@
set global innodb_defragment=1;
Warnings:
Warning 1287 '@@innodb_defragment' is deprecated and will be removed in a future release
create table t1 (a int not null primary key auto_increment, b varchar(256), key second(a, b)) engine=innodb;
insert t1 select null, repeat('a', 256) from seq_1_to_100;
select count(*) from t1;
@ -16,3 +18,5 @@ test.t1 optimize status OK
connection con1;
drop table t1;
set global innodb_defragment=default;
Warnings:
Warning 1287 '@@innodb_defragment' is deprecated and will be removed in a future release

View File

@ -3,6 +3,8 @@ SET @accuracy= @@GLOBAL.innodb_defragment_stats_accuracy;
SET @sp= @@GLOBAL.innodb_stats_persistent;
SET GLOBAL innodb_stats_persistent = 0;
set global innodb_defragment_stats_accuracy = 80;
Warnings:
Warning 1287 '@@innodb_defragment_stats_accuracy' is deprecated and will be removed in a future release
CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
b VARCHAR(256),
c INT,
@ -18,6 +20,8 @@ connect con3,localhost,root,,test,$MASTER_MYPORT,$MASTER_MYSOCK;
connect con4,localhost,root,,test,$MASTER_MYPORT,$MASTER_MYSOCK;
connection default;
SET @@global.innodb_defragment_n_pages = 20;
Warnings:
Warning 1287 '@@innodb_defragment_n_pages' is deprecated and will be removed in a future release
CREATE TEMPORARY TABLE tt (a INT, KEY(a)) ENGINE=InnoDB ROW_FORMAT=REDUNDANT;
INSERT INTO tt SELECT 0 FROM seq_1_to_180;
INSERT INTO tt SELECT 5 FROM seq_1_to_160;
@ -98,5 +102,9 @@ count(stat_value) > 0
1
drop table t1;
SET GLOBAL innodb_defragment_n_pages = @n_pages;
Warnings:
Warning 1287 '@@innodb_defragment_n_pages' is deprecated and will be removed in a future release
SET GLOBAL innodb_defragment_stats_accuracy = @accuracy;
Warnings:
Warning 1287 '@@innodb_defragment_stats_accuracy' is deprecated and will be removed in a future release
SET GLOBAL innodb_stats_persistent = @sp;

View File

@ -1,4 +1,6 @@
SET GLOBAL innodb_defragment_stats_accuracy = 20;
Warnings:
Warning 1287 '@@innodb_defragment_stats_accuracy' is deprecated and will be removed in a future release
DELETE FROM mysql.innodb_index_stats;
# Create table.
CREATE TABLE t1 (a INT PRIMARY KEY AUTO_INCREMENT, b VARCHAR(256),
@ -77,6 +79,8 @@ t1 SECOND n_leaf_pages_reserved
t1 SECOND n_page_split
t1 SECOND n_pages_freed
set global innodb_defragment_stats_accuracy = 40;
Warnings:
Warning 1287 '@@innodb_defragment_stats_accuracy' is deprecated and will be removed in a future release
INSERT INTO t1 (b) SELECT b from t1;
SELECT table_name, index_name, stat_name FROM mysql.innodb_index_stats;
table_name index_name stat_name
@ -116,6 +120,8 @@ drop index SECOND on t2;
# MDEV-26636: Statistics must not be written for temporary tables
#
SET GLOBAL innodb_defragment_stats_accuracy = 1;
Warnings:
Warning 1287 '@@innodb_defragment_stats_accuracy' is deprecated and will be removed in a future release
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;

View File

@ -5,6 +5,8 @@ SET @start_flush_log_at_trx_commit = @@global.innodb_flush_log_at_trx_commit;
SET @@global.innodb_flush_log_at_trx_commit=2;
SET @start_innodb_defragment_stats_accuracy = @@global.innodb_defragment_stats_accuracy;
SET @@global.innodb_defragment_stats_accuracy = 80;
Warnings:
Warning 1287 '@@innodb_defragment_stats_accuracy' is deprecated and will be removed in a future release
CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY AUTO_INCREMENT, b VARCHAR(256), KEY SECOND(a, b)) ENGINE=INNODB;
INSERT INTO t1 VALUES(1, REPEAT('A', 256));
INSERT INTO t1 (b) SELECT b from t1;
@ -34,5 +36,7 @@ sleep(15)
select stat_value > 0 from mysql.innodb_index_stats where table_name like '%t1%' and stat_name = 'n_page_split';
stat_value > 0
SET @@global.innodb_defragment_stats_accuracy = @start_innodb_defragment_stats_accuracy;
Warnings:
Warning 1287 '@@innodb_defragment_stats_accuracy' is deprecated and will be removed in a future release
SET @@global.table_definition_cache = @start_table_definition_cache;
DROP TABLE t1;

View File

@ -1,4 +1,6 @@
set global innodb_defragment_stats_accuracy = 80;
Warnings:
Warning 1287 '@@innodb_defragment_stats_accuracy' is deprecated and will be removed in a future release
CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY AUTO_INCREMENT, b VARCHAR(256), KEY SECOND(a, b)) ENGINE=INNODB;
optimize table t1;
Table Op Msg_type Msg_text
@ -66,6 +68,8 @@ select count(stat_value) = 0 from mysql.innodb_index_stats where table_name like
count(stat_value) = 0
1
SET @@global.innodb_defragment_n_pages = 3;
Warnings:
Warning 1287 '@@innodb_defragment_n_pages' is deprecated and will be removed in a future release
optimize table t1;
Table Op Msg_type Msg_text
test.t1 optimize status OK
@ -104,6 +108,8 @@ select count(stat_value) = 0 from mysql.innodb_index_stats where table_name like
count(stat_value) = 0
1
SET @@global.innodb_defragment_n_pages = 10;
Warnings:
Warning 1287 '@@innodb_defragment_n_pages' is deprecated and will be removed in a future release
optimize table t1;
Table Op Msg_type Msg_text
test.t1 optimize status OK

View File

@ -1,6 +1,8 @@
SET @innodb_defragment_orig=@@GLOBAL.innodb_defragment;
SET @innodb_optimize_fulltext_orig=@@GLOBAL.innodb_optimize_fulltext_only;
SET GLOBAL innodb_defragment = 1;
Warnings:
Warning 1287 '@@innodb_defragment' is deprecated and will be removed in a future release
SET GLOBAL innodb_optimize_fulltext_only = 0;
#
# MDEV-12198 innodb_defragment=1 crashes server on
@ -27,6 +29,8 @@ OPTIMIZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 optimize status OK
SET GLOBAL innodb_defragment = 0;
Warnings:
Warning 1287 '@@innodb_defragment' is deprecated and will be removed in a future release
OPTIMIZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 optimize status OK
@ -37,4 +41,6 @@ Table Op Msg_type Msg_text
test.t1 optimize status OK
DROP TABLE t1;
SET GLOBAL innodb_defragment = @innodb_defragment_orig;
Warnings:
Warning 1287 '@@innodb_defragment' is deprecated and will be removed in a future release
SET GLOBAL innodb_optimize_fulltext_only = @innodb_optimize_fulltext_orig;

View File

@ -279,10 +279,14 @@ SET GLOBAL innodb_limit_optimistic_insert_debug = @old_limit;
ALTER TABLE t1 ADD COLUMN b INT, ALGORITHM=INSTANT;
SET @old_defragment = @@innodb_defragment;
SET GLOBAL innodb_defragment = 1;
Warnings:
Warning 1287 '@@innodb_defragment' is deprecated and will be removed in a future release
OPTIMIZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 optimize status OK
SET GLOBAL innodb_defragment = @old_defragment;
Warnings:
Warning 1287 '@@innodb_defragment' is deprecated and will be removed in a future release
ALTER TABLE t1 ADD vb INT AS (b) VIRTUAL;
CHECK TABLE t1;
Table Op Msg_type Msg_text

View File

@ -1 +0,0 @@
--innodb-defragment=0

View File

@ -3,10 +3,14 @@ SELECT @orig;
@orig
0
SET GLOBAL innodb_defragment = OFF;
Warnings:
Warning 1287 '@@innodb_defragment' is deprecated and will be removed in a future release
SELECT @@global.innodb_defragment;
@@global.innodb_defragment
0
SET GLOBAL innodb_defragment = ON;
Warnings:
Warning 1287 '@@innodb_defragment' is deprecated and will be removed in a future release
SELECT @@global.innodb_defragment;
@@global.innodb_defragment
1
@ -16,3 +20,5 @@ SELECT @@global.innodb_defragment;
@@global.innodb_defragment
1
SET GLOBAL innodb_defragment = @orig;
Warnings:
Warning 1287 '@@innodb_defragment' is deprecated and will be removed in a future release

View File

@ -6,25 +6,33 @@ SELECT COUNT(@@global.innodb_defragment_fill_factor);
COUNT(@@global.innodb_defragment_fill_factor)
1
SET @@global.innodb_defragment_fill_factor = 0.77777777777777;
Warnings:
Warning 1287 '@@innodb_defragment_fill_factor' is deprecated and will be removed in a future release
SELECT @@global.innodb_defragment_fill_factor;
@@global.innodb_defragment_fill_factor
0.777778
SET @@global.innodb_defragment_fill_factor = 1;
Warnings:
Warning 1287 '@@innodb_defragment_fill_factor' is deprecated and will be removed in a future release
SELECT @@global.innodb_defragment_fill_factor;
@@global.innodb_defragment_fill_factor
1.000000
SET @@global.innodb_defragment_fill_factor = 0.7;
Warnings:
Warning 1287 '@@innodb_defragment_fill_factor' is deprecated and will be removed in a future release
SELECT @@global.innodb_defragment_fill_factor;
@@global.innodb_defragment_fill_factor
0.700000
SET @@global.innodb_defragment_fill_factor = -1;
Warnings:
Warning 1287 '@@innodb_defragment_fill_factor' is deprecated and will be removed in a future release
Warning 1292 Truncated incorrect innodb_defragment_fill_factor value: '-1'
SELECT @@global.innodb_defragment_fill_factor;
@@global.innodb_defragment_fill_factor
0.700000
SET @@global.innodb_defragment_fill_factor = 2;
Warnings:
Warning 1287 '@@innodb_defragment_fill_factor' is deprecated and will be removed in a future release
Warning 1292 Truncated incorrect innodb_defragment_fill_factor value: '2'
SELECT @@global.innodb_defragment_fill_factor;
@@global.innodb_defragment_fill_factor
@ -35,3 +43,5 @@ SELECT @@global.innodb_defragment_fill_factor;
@@global.innodb_defragment_fill_factor
1.000000
SET @@global.innodb_defragment_fill_factor = @start_innodb_defragment_fill_factor;
Warnings:
Warning 1287 '@@innodb_defragment_fill_factor' is deprecated and will be removed in a future release

View File

@ -6,25 +6,33 @@ SELECT COUNT(@@global.innodb_defragment_fill_factor_n_recs);
COUNT(@@global.innodb_defragment_fill_factor_n_recs)
1
SET @@global.innodb_defragment_fill_factor_n_recs = 50;
Warnings:
Warning 1287 '@@innodb_defragment_fill_factor_n_recs' is deprecated and will be removed in a future release
SELECT @@global.innodb_defragment_fill_factor_n_recs;
@@global.innodb_defragment_fill_factor_n_recs
50
SET @@global.innodb_defragment_fill_factor_n_recs = 100;
Warnings:
Warning 1287 '@@innodb_defragment_fill_factor_n_recs' is deprecated and will be removed in a future release
SELECT @@global.innodb_defragment_fill_factor_n_recs;
@@global.innodb_defragment_fill_factor_n_recs
100
SET @@global.innodb_defragment_fill_factor_n_recs = 1;
Warnings:
Warning 1287 '@@innodb_defragment_fill_factor_n_recs' is deprecated and will be removed in a future release
SELECT @@global.innodb_defragment_fill_factor_n_recs;
@@global.innodb_defragment_fill_factor_n_recs
1
SET @@global.innodb_defragment_fill_factor_n_recs = -1;
Warnings:
Warning 1287 '@@innodb_defragment_fill_factor_n_recs' is deprecated and will be removed in a future release
Warning 1292 Truncated incorrect innodb_defragment_fill_factor... value: '-1'
SELECT @@global.innodb_defragment_fill_factor_n_recs;
@@global.innodb_defragment_fill_factor_n_recs
1
SET @@global.innodb_defragment_fill_factor_n_recs = 10000;
Warnings:
Warning 1287 '@@innodb_defragment_fill_factor_n_recs' is deprecated and will be removed in a future release
Warning 1292 Truncated incorrect innodb_defragment_fill_factor... value: '10000'
SELECT @@global.innodb_defragment_fill_factor_n_recs;
@@global.innodb_defragment_fill_factor_n_recs
@ -40,3 +48,5 @@ SELECT @@global.innodb_defragment_fill_factor_n_recs;
@@global.innodb_defragment_fill_factor_n_recs
100
SET @@global.innodb_defragment_fill_factor_n_recs = @start_innodb_defragment_fill_factor_n_recs;
Warnings:
Warning 1287 '@@innodb_defragment_fill_factor_n_recs' is deprecated and will be removed in a future release

View File

@ -6,25 +6,33 @@ SELECT COUNT(@@global.innodb_defragment_frequency);
COUNT(@@global.innodb_defragment_frequency)
1
SET @@global.innodb_defragment_frequency = 200;
Warnings:
Warning 1287 '@@innodb_defragment_frequency' is deprecated and will be removed in a future release
SELECT @@global.innodb_defragment_frequency;
@@global.innodb_defragment_frequency
200
SET @@global.innodb_defragment_frequency = 1;
Warnings:
Warning 1287 '@@innodb_defragment_frequency' is deprecated and will be removed in a future release
SELECT @@global.innodb_defragment_frequency;
@@global.innodb_defragment_frequency
1
SET @@global.innodb_defragment_frequency = 1000;
Warnings:
Warning 1287 '@@innodb_defragment_frequency' is deprecated and will be removed in a future release
SELECT @@global.innodb_defragment_frequency;
@@global.innodb_defragment_frequency
1000
SET @@global.innodb_defragment_frequency = -1;
Warnings:
Warning 1287 '@@innodb_defragment_frequency' is deprecated and will be removed in a future release
Warning 1292 Truncated incorrect innodb_defragment_frequency value: '-1'
SELECT @@global.innodb_defragment_frequency;
@@global.innodb_defragment_frequency
1
SET @@global.innodb_defragment_frequency = 10000;
Warnings:
Warning 1287 '@@innodb_defragment_frequency' is deprecated and will be removed in a future release
Warning 1292 Truncated incorrect innodb_defragment_frequency value: '10000'
SELECT @@global.innodb_defragment_frequency;
@@global.innodb_defragment_frequency
@ -40,3 +48,5 @@ SELECT @@global.innodb_defragment_frequency;
@@global.innodb_defragment_frequency
1000
SET @@global.innodb_defragment_frequency = @start_innodb_defragment_frequency;
Warnings:
Warning 1287 '@@innodb_defragment_frequency' is deprecated and will be removed in a future release

View File

@ -7,22 +7,30 @@ COUNT(@@global.innodb_defragment_n_pages)
1
SET @@global.innodb_defragment_n_pages = 1;
Warnings:
Warning 1287 '@@innodb_defragment_n_pages' is deprecated and will be removed in a future release
Warning 1292 Truncated incorrect innodb_defragment_n_pages value: '1'
SELECT @@global.innodb_defragment_n_pages;
@@global.innodb_defragment_n_pages
2
SET @@global.innodb_defragment_n_pages = 2;
Warnings:
Warning 1287 '@@innodb_defragment_n_pages' is deprecated and will be removed in a future release
SELECT @@global.innodb_defragment_n_pages;
@@global.innodb_defragment_n_pages
2
SET @@global.innodb_defragment_n_pages = 32;
Warnings:
Warning 1287 '@@innodb_defragment_n_pages' is deprecated and will be removed in a future release
SELECT @@global.innodb_defragment_n_pages;
@@global.innodb_defragment_n_pages
32
SET @@global.innodb_defragment_n_pages = 64;
Warnings:
Warning 1287 '@@innodb_defragment_n_pages' is deprecated and will be removed in a future release
Warning 1292 Truncated incorrect innodb_defragment_n_pages value: '64'
SELECT @@global.innodb_defragment_n_pages;
@@global.innodb_defragment_n_pages
32
SET @@global.innodb_defragment_n_pages = @start_innodb_defragment_n_pages;
Warnings:
Warning 1287 '@@innodb_defragment_n_pages' is deprecated and will be removed in a future release

View File

@ -6,21 +6,27 @@ SELECT COUNT(@@global.innodb_defragment_stats_accuracy);
COUNT(@@global.innodb_defragment_stats_accuracy)
1
SET @@global.innodb_defragment_stats_accuracy = 1;
Warnings:
Warning 1287 '@@innodb_defragment_stats_accuracy' is deprecated and will be removed in a future release
SELECT @@global.innodb_defragment_stats_accuracy;
@@global.innodb_defragment_stats_accuracy
1
SET @@global.innodb_defragment_stats_accuracy = 1000;
Warnings:
Warning 1287 '@@innodb_defragment_stats_accuracy' is deprecated and will be removed in a future release
SELECT @@global.innodb_defragment_stats_accuracy;
@@global.innodb_defragment_stats_accuracy
1000
SET @@global.innodb_defragment_stats_accuracy = -1;
Warnings:
Warning 1287 '@@innodb_defragment_stats_accuracy' is deprecated and will be removed in a future release
Warning 1292 Truncated incorrect innodb_defragment_stats_accuracy value: '-1'
SELECT @@global.innodb_defragment_stats_accuracy;
@@global.innodb_defragment_stats_accuracy
0
SET @@global.innodb_defragment_stats_accuracy = 1000000000000;
Warnings:
Warning 1287 '@@innodb_defragment_stats_accuracy' is deprecated and will be removed in a future release
Warning 1292 Truncated incorrect innodb_defragment_stats_accuracy value: '1000000000000'
SELECT @@global.innodb_defragment_stats_accuracy;
@@global.innodb_defragment_stats_accuracy
@ -31,3 +37,5 @@ SELECT @@global.innodb_defragment_stats_accuracy;
@@global.innodb_defragment_stats_accuracy
4294967295
SET @@global.innodb_defragment_stats_accuracy = @start_innodb_defragment_stats_accuracy;
Warnings:
Warning 1287 '@@innodb_defragment_stats_accuracy' is deprecated and will be removed in a future release

View File

@ -19092,7 +19092,7 @@ static MYSQL_SYSVAR_BOOL(buffer_pool_load_at_startup, srv_buffer_pool_load_at_st
NULL, NULL, TRUE);
static MYSQL_SYSVAR_BOOL(defragment, srv_defragment,
PLUGIN_VAR_RQCMDARG,
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_DEPRECATED,
"Enable/disable InnoDB defragmentation (default FALSE). When set to FALSE, all existing "
"defragmentation will be paused. And new defragmentation command will fail."
"Paused defragmentation commands will resume when this variable is set to "
@ -19100,14 +19100,14 @@ static MYSQL_SYSVAR_BOOL(defragment, srv_defragment,
NULL, NULL, FALSE);
static MYSQL_SYSVAR_UINT(defragment_n_pages, srv_defragment_n_pages,
PLUGIN_VAR_RQCMDARG,
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_DEPRECATED,
"Number of pages considered at once when merging multiple pages to "
"defragment",
NULL, NULL, 7, 2, 32, 0);
static MYSQL_SYSVAR_UINT(defragment_stats_accuracy,
srv_defragment_stats_accuracy,
PLUGIN_VAR_RQCMDARG,
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_DEPRECATED,
"How many defragment stats changes there are before the stats "
"are written to persistent storage. Set to 0 meaning disable "
"defragment stats tracking.",
@ -19115,7 +19115,7 @@ static MYSQL_SYSVAR_UINT(defragment_stats_accuracy,
static MYSQL_SYSVAR_UINT(defragment_fill_factor_n_recs,
srv_defragment_fill_factor_n_recs,
PLUGIN_VAR_RQCMDARG,
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_DEPRECATED,
"How many records of space defragmentation should leave on the page. "
"This variable, together with innodb_defragment_fill_factor, is introduced "
"so defragmentation won't pack the page too full and cause page split on "
@ -19124,7 +19124,7 @@ static MYSQL_SYSVAR_UINT(defragment_fill_factor_n_recs,
NULL, NULL, 20, 1, 100, 0);
static MYSQL_SYSVAR_DOUBLE(defragment_fill_factor, srv_defragment_fill_factor,
PLUGIN_VAR_RQCMDARG,
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_DEPRECATED,
"A number between [0.7, 1] that tells defragmentation how full it should "
"fill a page. Default is 0.9. Number below 0.7 won't make much sense."
"This variable, together with innodb_defragment_fill_factor_n_recs, is "
@ -19134,7 +19134,7 @@ static MYSQL_SYSVAR_DOUBLE(defragment_fill_factor, srv_defragment_fill_factor,
NULL, NULL, 0.9, 0.7, 1, 0);
static MYSQL_SYSVAR_UINT(defragment_frequency, srv_defragment_frequency,
PLUGIN_VAR_RQCMDARG,
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_DEPRECATED,
"Do not defragment a single index more than this number of time per second."
"This controls the number of time defragmentation thread can request X_LOCK "
"on an index. Defragmentation thread will check whether "