Skip to content

Commit

Permalink
Set rocksdb_large_prefix to ON and deprecate this system variable (pe…
Browse files Browse the repository at this point in the history
…rcona#1322)

Upstream commit ID: facebook/mysql-5.6@e4751ca
PS-8951: Merge percona-202305 (https://jira.percona.com/browse/PS-8951)

Summary:
This variable was introduced to mirror innodb_large_prefix, which was deprecated in 5.7 and removed in 8.0, and no longer serves any real purpose, nor there is anything to gain with its 'OFF' setting, which is also incompatible with the data dictionary schema. Thus 1) change the default to 'ON'; 2) deprecate it.

Squash with 749f1dc5ef0327e55616441b399000510db9a54d

Pull Request resolved: facebook/mysql-5.6#1322

Differential Revision: D46773511

fbshipit-source-id: f7b43bc6db767baa8803fa6932e3592d23464fd3
  • Loading branch information
laurynas-biveinis authored and inikep committed Oct 28, 2024
1 parent aa0f8af commit c51d80a
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 30 deletions.
3 changes: 0 additions & 3 deletions mysql-test/suite/rocksdb/r/dup_key_update.result
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,6 @@ id1 id2 id3
9 17 9
DROP TABLE t1;
DROP TABLE t2;
set @orig_rocksdb_large_prefix=@@global.rocksdb_large_prefix;
set @@global.rocksdb_large_prefix=1;
CREATE TABLE t1 (id1 varchar(128) CHARACTER SET latin1 COLLATE latin1_bin,
id2 varchar(256) CHARACTER SET utf8mb3 COLLATE utf8mb3_bin,
id3 varchar(200) CHARACTER SET latin1 COLLATE latin1_swedish_ci,
Expand All @@ -194,7 +192,6 @@ UNIQUE KEY (id3, id1) COMMENT 'cfname=rev:cf') ENGINE=ROCKSDB;
Warnings:
Warning 1287 'utf8mb3' is deprecated and will be removed in a future release. Please use utf8mb4 instead
Warning 3778 'utf8mb3_bin' is a collation of the deprecated character set UTF8MB3. Please consider using UTF8MB4 with an appropriate collation instead.
set @@global.rocksdb_large_prefix=@orig_rocksdb_large_prefix;
INSERT INTO t1 VALUES (1, 1, 1) ON DUPLICATE KEY UPDATE id2 = 9;
SELECT * FROM t1 WHERE id1 = 1;
id1 id2 id3
Expand Down
6 changes: 6 additions & 0 deletions mysql-test/suite/rocksdb/r/index.result
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ ALTER TABLE t1 DROP KEY a;
DROP TABLE t1;
set @orig_rocksdb_large_prefix=@@global.rocksdb_large_prefix;
set @@global.rocksdb_large_prefix=0;
Warnings:
Warning 131 using rocksdb_large_prefix is deprecated and it will be removed in a future release
CREATE TABLE t1 (
a BLOB(1024),
KEY (a(767))
Expand All @@ -54,6 +56,8 @@ KEY (a(768))
) ENGINE=ROCKSDB;
ERROR 42000: Specified key was too long; max key length is 767 bytes
set @@global.rocksdb_large_prefix=1;
Warnings:
Warning 131 using rocksdb_large_prefix is deprecated and it will be removed in a future release
CREATE TABLE t1 (
a BLOB(4096),
KEY (a(3072))
Expand All @@ -65,6 +69,8 @@ KEY (a(3073))
) ENGINE=ROCKSDB;
ERROR 42000: Specified key was too long; max key length is 3072 bytes
set @@global.rocksdb_large_prefix=@orig_rocksdb_large_prefix;
Warnings:
Warning 131 using rocksdb_large_prefix is deprecated and it will be removed in a future release
#
# Issue #376: MyRocks: ORDER BY optimizer is unable to use the index extension
#
Expand Down
6 changes: 6 additions & 0 deletions mysql-test/suite/rocksdb/r/index_primary.result
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ t1 0 PRIMARY 1 b A # NULL NULL SE_SPECIFIC YES NULL
DROP TABLE t1;
set @orig_rocksdb_large_prefix=@@global.rocksdb_large_prefix;
set @@global.rocksdb_large_prefix=0;
Warnings:
Warning 131 using rocksdb_large_prefix is deprecated and it will be removed in a future release
CREATE TABLE t1 (
a BLOB(1024),
PRIMARY KEY (a(767))
Expand All @@ -58,6 +60,8 @@ PRIMARY KEY (a(768))
) ENGINE=ROCKSDB;
ERROR 42000: Specified key was too long; max key length is 767 bytes
set @@global.rocksdb_large_prefix=1;
Warnings:
Warning 131 using rocksdb_large_prefix is deprecated and it will be removed in a future release
CREATE TABLE t1 (
a BLOB(4096),
PRIMARY KEY (a(3072))
Expand All @@ -69,3 +73,5 @@ PRIMARY KEY (a(3073))
) ENGINE=ROCKSDB;
ERROR 42000: Specified key was too long; max key length is 3072 bytes
set @@global.rocksdb_large_prefix=@orig_rocksdb_large_prefix;
Warnings:
Warning 131 using rocksdb_large_prefix is deprecated and it will be removed in a future release
6 changes: 6 additions & 0 deletions mysql-test/suite/rocksdb/r/index_type_btree.result
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ ALTER TABLE t1 DROP KEY a;
DROP TABLE t1;
set @orig_rocksdb_large_prefix=@@global.rocksdb_large_prefix;
set @@global.rocksdb_large_prefix=0;
Warnings:
Warning 131 using rocksdb_large_prefix is deprecated and it will be removed in a future release
CREATE TABLE t1 (
a BLOB(1024),
KEY (a(767))
Expand All @@ -62,6 +64,8 @@ KEY (a(768))
) ENGINE=ROCKSDB;
ERROR 42000: Specified key was too long; max key length is 767 bytes
set @@global.rocksdb_large_prefix=1;
Warnings:
Warning 131 using rocksdb_large_prefix is deprecated and it will be removed in a future release
CREATE TABLE t1 (
a BLOB(4096),
KEY (a(3072))
Expand All @@ -73,3 +77,5 @@ KEY (a(3073))
) ENGINE=ROCKSDB;
ERROR 42000: Specified key was too long; max key length is 3072 bytes
set @@global.rocksdb_large_prefix=@orig_rocksdb_large_prefix;
Warnings:
Warning 131 using rocksdb_large_prefix is deprecated and it will be removed in a future release
6 changes: 6 additions & 0 deletions mysql-test/suite/rocksdb/r/index_type_hash.result
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ ALTER TABLE t1 DROP KEY a;
DROP TABLE t1;
set @orig_rocksdb_large_prefix=@@global.rocksdb_large_prefix;
set @@global.rocksdb_large_prefix=0;
Warnings:
Warning 131 using rocksdb_large_prefix is deprecated and it will be removed in a future release
CREATE TABLE t1 (
a BLOB(1024),
KEY (a(767))
Expand All @@ -62,6 +64,8 @@ KEY (a(768))
) ENGINE=ROCKSDB;
ERROR 42000: Specified key was too long; max key length is 767 bytes
set @@global.rocksdb_large_prefix=1;
Warnings:
Warning 131 using rocksdb_large_prefix is deprecated and it will be removed in a future release
CREATE TABLE t1 (
a BLOB(4096),
KEY (a(3072))
Expand All @@ -73,3 +77,5 @@ KEY (a(3073))
) ENGINE=ROCKSDB;
ERROR 42000: Specified key was too long; max key length is 3072 bytes
set @@global.rocksdb_large_prefix=@orig_rocksdb_large_prefix;
Warnings:
Warning 131 using rocksdb_large_prefix is deprecated and it will be removed in a future release
12 changes: 1 addition & 11 deletions mysql-test/suite/rocksdb/r/rocksdb.result
Original file line number Diff line number Diff line change
Expand Up @@ -2489,17 +2489,10 @@ id
select * from t1 where id=9 for update;
id
drop table t1;
#Index on blob column
SET @old_mode = @@sql_mode;
SET sql_mode = 'strict_all_tables';
Warnings:
Warning 3135 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
# Index on blob column
create table t1 (a int, b text, c varchar(255), Primary Key(a), Key(c, b(255))) engine=rocksdb;
drop table t1;
set @orig_rocksdb_large_prefix=@@global.rocksdb_large_prefix;
set @@global.rocksdb_large_prefix=1;
create table t1 (a int, b text, c varchar(255), Primary Key(a), Key(b(255))) engine=rocksdb;
set @@global.rocksdb_large_prefix=@orig_rocksdb_large_prefix;
insert into t1 values (1, '1abcde', '1abcde'), (2, '2abcde', '2abcde'), (3, '3abcde', '3abcde');
select * from t1;
a b c
Expand All @@ -2523,9 +2516,6 @@ a b c
2 12345 2abcde
3 3abcde 3abcde
drop table t1;
create table t1 (a int, b text, c varchar(400), Primary Key(a), Key(b(2255))) engine=rocksdb;
ERROR 42000: Specified key was too long; max key length is 3072 bytes
SET sql_mode = @old_mode;
drop table t0;
#
# Fix assertion failure (attempt to overrun the key buffer) for prefix indexes
Expand Down
4 changes: 0 additions & 4 deletions mysql-test/suite/rocksdb/t/dup_key_update.test
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@ CREATE TABLE t2 (id1 INT, id2 INT, id3 INT,
PRIMARY KEY (id1, id2, id3),
UNIQUE KEY (id3, id1) COMMENT 'cfname=rev:cf') ENGINE=ROCKSDB;


--source suite/rocksdb/include/dup_key_update.inc

# Cleanup
DROP TABLE t1;
DROP TABLE t2;

set @orig_rocksdb_large_prefix=@@global.rocksdb_large_prefix;
set @@global.rocksdb_large_prefix=1;
CREATE TABLE t1 (id1 varchar(128) CHARACTER SET latin1 COLLATE latin1_bin,
id2 varchar(256) CHARACTER SET utf8mb3 COLLATE utf8mb3_bin,
id3 varchar(200) CHARACTER SET latin1 COLLATE latin1_swedish_ci,
Expand All @@ -30,7 +27,6 @@ CREATE TABLE t2 (id1 varchar(128) CHARACTER SET latin1 COLLATE latin1_bin,
id3 varchar(200) CHARACTER SET latin1 COLLATE latin1_swedish_ci,
PRIMARY KEY (id1, id2, id3),
UNIQUE KEY (id3, id1) COMMENT 'cfname=rev:cf') ENGINE=ROCKSDB;
set @@global.rocksdb_large_prefix=@orig_rocksdb_large_prefix;

--source suite/rocksdb/include/dup_key_update.inc

Expand Down
10 changes: 1 addition & 9 deletions mysql-test/suite/rocksdb/t/rocksdb.test
Original file line number Diff line number Diff line change
Expand Up @@ -1729,15 +1729,10 @@ select * from t1 where id=9 for update;
-- disconnect con1
drop table t1;

--echo #Index on blob column
SET @old_mode = @@sql_mode;
SET sql_mode = 'strict_all_tables';
--echo # Index on blob column
create table t1 (a int, b text, c varchar(255), Primary Key(a), Key(c, b(255))) engine=rocksdb;
drop table t1;
set @orig_rocksdb_large_prefix=@@global.rocksdb_large_prefix;
set @@global.rocksdb_large_prefix=1;
create table t1 (a int, b text, c varchar(255), Primary Key(a), Key(b(255))) engine=rocksdb;
set @@global.rocksdb_large_prefix=@orig_rocksdb_large_prefix;
insert into t1 values (1, '1abcde', '1abcde'), (2, '2abcde', '2abcde'), (3, '3abcde', '3abcde');
select * from t1;
--replace_column 10 #
Expand All @@ -1747,9 +1742,6 @@ explain select b, a from t1 where b like '1%';
update t1 set b= '12345' where b = '2abcde';
select * from t1;
drop table t1;
--error ER_TOO_LONG_KEY
create table t1 (a int, b text, c varchar(400), Primary Key(a), Key(b(2255))) engine=rocksdb;
SET sql_mode = @old_mode;

drop table t0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,43 @@ SELECT @start_global_value;
'# Setting to valid values in global scope#'
"Trying to set variable @@global.ROCKSDB_LARGE_PREFIX to 1"
SET @@global.ROCKSDB_LARGE_PREFIX = 1;
Warnings:
Warning 131 using rocksdb_large_prefix is deprecated and it will be removed in a future release
SELECT @@global.ROCKSDB_LARGE_PREFIX;
@@global.ROCKSDB_LARGE_PREFIX
1
"Setting the global scope variable back to default"
SET @@global.ROCKSDB_LARGE_PREFIX = DEFAULT;
Warnings:
Warning 131 using rocksdb_large_prefix is deprecated and it will be removed in a future release
SELECT @@global.ROCKSDB_LARGE_PREFIX;
@@global.ROCKSDB_LARGE_PREFIX
1
"Trying to set variable @@global.ROCKSDB_LARGE_PREFIX to 0"
SET @@global.ROCKSDB_LARGE_PREFIX = 0;
Warnings:
Warning 131 using rocksdb_large_prefix is deprecated and it will be removed in a future release
SELECT @@global.ROCKSDB_LARGE_PREFIX;
@@global.ROCKSDB_LARGE_PREFIX
0
"Setting the global scope variable back to default"
SET @@global.ROCKSDB_LARGE_PREFIX = DEFAULT;
Warnings:
Warning 131 using rocksdb_large_prefix is deprecated and it will be removed in a future release
SELECT @@global.ROCKSDB_LARGE_PREFIX;
@@global.ROCKSDB_LARGE_PREFIX
1
"Trying to set variable @@global.ROCKSDB_LARGE_PREFIX to on"
SET @@global.ROCKSDB_LARGE_PREFIX = on;
Warnings:
Warning 131 using rocksdb_large_prefix is deprecated and it will be removed in a future release
SELECT @@global.ROCKSDB_LARGE_PREFIX;
@@global.ROCKSDB_LARGE_PREFIX
1
"Setting the global scope variable back to default"
SET @@global.ROCKSDB_LARGE_PREFIX = DEFAULT;
Warnings:
Warning 131 using rocksdb_large_prefix is deprecated and it will be removed in a future release
SELECT @@global.ROCKSDB_LARGE_PREFIX;
@@global.ROCKSDB_LARGE_PREFIX
1
Expand All @@ -57,6 +69,8 @@ SELECT @@global.ROCKSDB_LARGE_PREFIX;
@@global.ROCKSDB_LARGE_PREFIX
1
SET @@global.ROCKSDB_LARGE_PREFIX = @start_global_value;
Warnings:
Warning 131 using rocksdb_large_prefix is deprecated and it will be removed in a future release
SELECT @@global.ROCKSDB_LARGE_PREFIX;
@@global.ROCKSDB_LARGE_PREFIX
1
Expand Down
51 changes: 48 additions & 3 deletions storage/rocksdb/ha_rocksdb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
#include "sql/sql_thd_internal_api.h"
#include "sql/strfunc.h"
#include "sql/table.h"
#include "sql/strfunc.h"

/* RocksDB includes */
#include "monitoring/histogram.h"
Expand Down Expand Up @@ -1206,6 +1207,50 @@ static TYPELIB index_type_typelib = {array_elements(index_type_names) - 1,
"index_type_typelib", index_type_names,
nullptr};

static constexpr char large_prefix_deprecated_msg[] =
"using rocksdb_large_prefix is deprecated and it will be removed in a "
"future release";

// Copied over from InnoDB with minor changes. Returns false on success, true on
// failure.
static bool check_func_bool(void *save, st_mysql_value *value) {
int result;
if (value->value_type(value) == MYSQL_VALUE_TYPE_STRING) {
char buff[STRING_BUFFER_USUAL_SIZE];
int length = sizeof(buff);

const auto *const str = value->val_str(value, buff, &length);

if (str == nullptr) return true;

result = find_type(&bool_typelib, str, length, true) - 1;

if (result < 0) return true;
} else {
long long tmp;
if (value->val_int(value, &tmp) < 0) return true;
if (tmp > 1 || tmp < 0) return true;
result = static_cast<int>(tmp);
}
*(bool *)save = result != 0;
return false;
}

static int rocksdb_large_prefix_check(THD *, SYS_VAR *, void *save,
st_mysql_value *value) {
if (check_func_bool(save, value)) return HA_EXIT_FAILURE;

return HA_EXIT_SUCCESS;
}

static void rocksdb_large_prefix_update(THD *thd, SYS_VAR *, void *var_ptr,
const void *save) {
push_warning(thd, Sql_condition::SL_WARNING, HA_ERR_WRONG_COMMAND,
large_prefix_deprecated_msg);

*static_cast<bool *>(var_ptr) = *static_cast<const bool *>(save);
}

// TODO: 0 means don't wait at all, and we don't support it yet?
static MYSQL_THDVAR_ULONG(lock_wait_timeout,
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_HINTUPDATEABLE,
Expand Down Expand Up @@ -2482,9 +2527,9 @@ static MYSQL_SYSVAR_BOOL(table_stats_use_table_scan,

static MYSQL_SYSVAR_BOOL(
large_prefix, rocksdb_large_prefix, PLUGIN_VAR_RQCMDARG,
"Support large index prefix length of 3072 bytes. If off, the maximum "
"index prefix length is 767.",
nullptr, nullptr, true);
"Deprecated: support large index prefix length of 3072 bytes. If off, the "
"maximum index prefix length is 767.",
rocksdb_large_prefix_check, rocksdb_large_prefix_update, true);

static MYSQL_SYSVAR_BOOL(
allow_to_start_after_corruption, rocksdb_allow_to_start_after_corruption,
Expand Down

0 comments on commit c51d80a

Please sign in to comment.