MariaDB 11.1.0 预览版现已推出
我们很高兴宣布 MariaDB 11.1 预览版 MariaDB 11.1.0 现已推出。
MariaDB 11.1 的候选功能
预览版旨在更快地让用户体验到新功能,不应用于生产环境。预览版中的所有功能可能不会都包含在正式发布 (GA) 版本中 – 只有通过测试的功能才会合入 MariaDB Server 11.1.1。
11.1 版本正在考虑的功能包括
YEAR 和 DATE 的索引使用
通过 MDEV-8320,一些使用 DATE 或 YEAR 函数的查询将大大加快,因为优化器现在能够在某些情况下利用索引。以下是一个示例(首先创建一个包含 1000 个日期的表 t3)。
create table t0(a int);
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t1(a int);
insert into t1 select A.a + B.a* 10 from t0 A, t0 B;
create table t2 (pk int primary key, a datetime, b date, key(a), key(b));
insert into t2
select
A.a*10+B.a,
date_add(date_add('2017-01-01', interval A.a*8 day), interval B.a hour),
date_add('2017-01-01', interval A.a*7 day)
from t1 A, t0 B;
SELECT * FROM t2 LIMIT 3;
+----+---------------------+------------+
| pk | a | b |
+----+---------------------+------------+
| 0 | 2017-01-01 00:00:00 | 2017-01-01 |
| 1 | 2017-01-01 01:00:00 | 2017-01-01 |
| 2 | 2017-01-01 02:00:00 | 2017-01-01 |
...
| 997 | 2019-03-04 07:00:00 | 2018-11-25 |
| 998 | 2019-03-04 08:00:00 | 2018-11-25 |
| 999 | 2019-03-04 09:00:00 | 2018-11-25 |
+-----+---------------------+------------+
explain select * from t2 where date(a) <= '2017-01-01'\G
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: t2
type: range
possible_keys: a
key: a
key_len: 6
ref: NULL
rows: 10
Extra: Using index condition
直到 MariaDB 11.0 版本,优化器都不会使用该索引
explain select * from t2 where date(a) <= '2017-01-01'\G
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: t2
type: ALL
possible_keys: NULL
key: NULL
key_len: NULL
ref: NULL
rows: 1000
Extra: Using where
该索引可用于 YEAR 和 DATE 函数,并可与任何 >, <, >=, <= 或 = 运算符一起使用
explain select * from t2 where year(a) < 2017\G
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: t2
type: range
possible_keys: a
key: a
key_len: 6
ref: NULL
rows: 1
Extra: Using index condition
explain select * from t2 where year(a) = 2019\G
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: t2
type: range
possible_keys: a
key: a
key_len: 6
ref: NULL
rows: 80
Extra: Using index condition
UPDATE/DELETE 的半连接优化
MariaDB 有许多半连接优化。以前,单表 UPDATE/DELETE 语句无法利用这些优化,因为半连接优化属于不能用于单表 UPDATE/DELETE 的子查询优化类型。现在,优化器可以自动将单表 UPDATE 和 DELETE 转换为多表 UPDATE/DELETE,从而为其启用半连接优化。如果您在 UPDATE 或 DELETE 中使用子查询,这些语句可能会快很多 (MDEV-7487) 例如,比较一个示例数据集的两个 EXPLAIN 结果。首先,在 MariaDB 11.1 之前
explain delete from partsupp where (ps_partkey, ps_suppkey) in (select p_partkey, s_suppkey from part, supplier where p_retailprice between 901 and 910 and s_nationkey in (select n_nationkey from nation where n_name='PERU'))\G
*************************** 1. row ***************************
id: 1
select_type: PRIMARY
table: partsupp
type: ALL
possible_keys: NULL
key: NULL
key_len: NULL
ref: NULL
rows: 700
Extra: Using where
*************************** 2. row ***************************
id: 2
select_type: DEPENDENT SUBQUERY
table: nation
type: ref
possible_keys: PRIMARY,i_n_regionkey,i_n_name
key: i_n_name
key_len: 26
ref: const
rows: 1
Extra: Using where; Using index
*************************** 3. row ***************************
id: 2
select_type: DEPENDENT SUBQUERY
table: part
type: eq_ref
possible_keys: PRIMARY
key: PRIMARY
key_len: 4
ref: func
rows: 1
Extra: Using where
*************************** 4. row ***************************
id: 2
select_type: DEPENDENT SUBQUERY
table: supplier
type: eq_ref
possible_keys: PRIMARY,i_s_nationkey
key: PRIMARY
key_len: 4
ref: func
rows: 1
Extra: Using where
然后,MariaDB 11.1 对等效查询的 EXPLAIN 结果
explain delete from partsupp where (ps_partkey, ps_suppkey) in (select p_partkey, s_suppkey from part, supplier where p_retailprice between 901 and 910 and s_nationkey in (select n_nationkey from nation where n_name='PERU'))\G
*************************** 1. row ***************************
id: 1
select_type: PRIMARY
table: nation
type: ref
possible_keys: PRIMARY,i_n_name
key: i_n_name
key_len: 26
ref: const
rows: 1
Extra: Using where; Using index
*************************** 2. row ***************************
id: 1
select_type: PRIMARY
table: supplier
type: ref
possible_keys: PRIMARY,i_s_nationkey
key: i_s_nationkey
key_len: 5
ref: test.nation.n_nationkey
rows: 1
Extra: Using index
*************************** 3. row ***************************
id: 1
select_type: PRIMARY
table: partsupp
type: ref
possible_keys: PRIMARY,i_ps_partkey,i_ps_suppkey
key: i_ps_suppkey
key_len: 4
ref: test.supplier.s_suppkey
rows: 1
Extra:
*************************** 4. row ***************************
id: 1
select_type: PRIMARY
table: part
type: eq_ref
possible_keys: PRIMARY
key: PRIMARY
key_len: 4
ref: test.partsupp.ps_partkey
rows: 1
Extra: Using where
JSON schema 验证
JSON_SCHEMA_VALID 函数已根据JSON Schema Draft 2020 实现 (MDEV-27128)。如果给定的 json 对 schema 有效,函数返回 true,否则返回 false。
SET @schema= '{
"properties" : {
"number1":{ "maximum":10 },
"string1" : { "maxLength": 3}
}
}';
SELECT JSON_SCHEMA_VALID(@schema, '{ "number1":25, "string1":"ab" }');
+----------------------------------------------------------------+
| JSON_SCHEMA_VALID(@schema, '{ "number1":25, "string1":"ab" }') |
+----------------------------------------------------------------+
| 0 |
+----------------------------------------------------------------+
SELECT JSON_SCHEMA_VALID(@schema, '{ "number1":10, "string1":"ab" }');
+----------------------------------------------------------------+
| JSON_SCHEMA_VALID(@schema, '{ "number1":10, "string1":"ab" }') |
+----------------------------------------------------------------+
| 1 |
+----------------------------------------------------------------+
InnoDB 碎片整理
InnoDB 碎片整理是一个很少使用的功能,旨在让 OPTIMIZE TABLE 不像往常那样重建表,而是对索引 B-tree 进行原地优化。然而,该选项会使用过度锁定(独占锁定索引树),从不支持 SPATIAL INDEXes 或 FULLTEXT INDEXes,且从未回收存储空间。由于它不太有用,在许多情况下不起作用,并增加了维护负担,因此已被移除 (MDEV-30545)。
其他功能
- MDEV-16329 ALTER ONLINE TABLE 已在存储引擎层之上实现,模仿了 InnoDB 自 MariaDB 10.0 版本以来的做法。关于此主题的单独文章可能会随后发布。
- Mariabackup 是用于执行物理在线备份的工具。它最初是 Xtrabackup 的一个分支,该分支不支持 MariaDB 10.1 的静态数据加密。然而,文件仍然被命名为
xtrabackup_*
。现在它们被命名为mariadb_backup_*
(MDEV-18931)
我们期待收到您的评论!
链接