# Manticore Search 4.2.0: 10x faster SELECT, major bugs fixed,  Debian Bullseye support

Manticore团队很高兴宣布[Manticore Search 4.2.0版本](https://manticoresearch.com/downloads/)。本次发布的新功能包括：

### 重大新功能
- **实时索引和全文查询的伪分片支持**。在上一版本中我们添加了有限的伪分片支持。从本版本开始，只需启用[searchd.pseudo_sharding](https://manual.manticoresearch.com/Server_settings/Searchd#pseudo_sharding)即可获得伪分片的所有优势以及多核处理器的性能。最棒的是，你无需对索引或查询做任何更改，只需启用它，如果CPU有空闲，它将被用来降低响应时间。它支持普通索引和实时索引的全文、过滤和分析查询。例如，启用伪分片后，大多数查询的**平均响应时间可降低约10倍**，在[Hacker news精选评论数据集](https://zenodo.org/record/45901/)上乘以100倍（普通索引中包含1.16亿文档）。
    ![4.2.0伪分片开启与关闭](./manticore-search-4-2-0-10x-faster-select-major-bugs-fixed-debian-bullseye-support/4.2.0_ps_on_vs_off-1.png)
- **[Debian Bullseye](https://manticoresearch.com/downloads/)**现已支持。
- PQ事务现在是原子性和隔离的。之前PQ事务支持有限。这使得**批量替换大量规则时的REPLACE into PQ操作显著加快**。性能详情：



#### 上一版本4.0.2

插入100万条PQ规则需要**48秒**，以1万为批次替换4万条需要**406秒**。

```bash
root@perf3 ~ # mysql -P9306 -h0 -e "drop table if exists pq; create table pq (f text, f2 text, j json, s string) type='percolate';"; date; for m in `seq 1 1000`; do (echo -n "insert into pq (id,query,filters,tags) values "; for n in `seq 1 1000`; do echo -n "(0,'@f (cat | ( angry dog ) | (cute mouse)) @f2 def', 'j.json.language=\"en\"', '{\"tag1\":\"tag1\",\"tag2\":\"tag2\"}')"; [ $n != 1000 ] && echo -n ","; done; echo ";")|mysql -P9306 -h0; done; date; mysql -P9306 -h0 -e "select count(*) from pq"

Wed Dec 22 10:24:30 AM CET 2021
Wed Dec 22 10:25:18 AM CET 2021
+----------+
| count(*) |
+----------+
|  1000000 |
+----------+

root@perf3 ~ # date; (echo "begin;"; for offset in `seq 0 10000 30000`; do n=0; echo "replace into pq (id,query,filters,tags) values "; for id in `mysql -P9306 -h0 -NB -e "select id from pq limit $offset, 10000 option max_matches=1000000"`; do echo "($id,'@f (tiger | ( angry bear ) | (cute panda)) @f2 def', 'j.json.language=\"de\"', '{\"tag1\":\"tag1\",\"tag2\":\"tag2\"}')"; n=$((n+1)); [ $n != 10000 ] && echo -n ","; done; echo ";"; done; echo "commit;") > /tmp/replace.sql; date
Wed Dec 22 10:26:23 AM CET 2021
Wed Dec 22 10:26:27 AM CET 2021
root@perf3 ~ # time mysql -P9306 -h0 < /tmp/replace.sql

real    6m46.195s
user    0m0.035s
sys     0m0.008s
```  

#### 新版本4.2.0

插入100万条PQ规则需要**34秒**，以1万为批次替换它们需要**23秒**。

```bash
root@perf3 ~ # mysql -P9306 -h0 -e "drop table if exists pq; create table pq (f text, f2 text, j json, s string) type='percolate';"; date; for m in `seq 1 1000`; do (echo -n "insert into pq (id,query,filters,tags) values "; for n in `seq 1 1000`; do echo -n "(0,'@f (cat | ( angry dog ) | (cute mouse)) @f2 def', 'j.json.language=\"en\"', '{\"tag1\":\"tag1\",\"tag2\":\"tag2\"}')"; [ $n != 1000 ] && echo -n ","; done; echo ";")|mysql -P9306 -h0; done; date; mysql -P9306 -h0 -e "select count(*) from pq"

Wed Dec 22 10:06:38 AM CET 2021
Wed Dec 22 10:07:12 AM CET 2021
+----------+
| count(*) |
+----------+
|  1000000 |
+----------+

root@perf3 ~ # date; (echo "begin;"; for offset in `seq 0 10000 990000`; do n=0; echo "replace into pq (id,query,filters,tags) values "; for id in `mysql -P9306 -h0 -NB -e "select id from pq limit $offset, 10000 option max_matches=1000000"`; do echo "($id,'@f (tiger | ( angry bear ) | (cute panda)) @f2 def', 'j.json.language=\"de\"', '{\"tag1\":\"tag1\",\"tag2\":\"tag2\"}')"; n=$((n+1)); [ $n != 10000 ] && echo -n ","; done; echo ";"; done; echo "commit;") > /tmp/replace.sql; date
Wed Dec 22 10:12:31 AM CET 2021
Wed Dec 22 10:14:00 AM CET 2021
root@perf3 ~ # time mysql -P9306 -h0 < /tmp/replace.sql

real    0m23.248s
user    0m0.891s
sys     0m0.047s
```

### 小型变更
- [optimize_cutoff](https://manual.manticoresearch.com/Server_settings/Searchd#optimize_cutoff)现在作为配置选项在`searchd`部分可用。当你希望全局限制所有索引中的RT块数量到特定数值时，这很有用。
- [提交00874743](https://github.com/manticoresoftware/manticoresearch/commit/00874743823eaf43e2a09a088392fd7e0a617f47)准确计算多个本地物理索引（实时/普通）在相同字段集/顺序下的[count(distinct ...)](https://manual.manticoresearch.com/Searching/Grouping#COUNT%28DISTINCT-field%29)和[FACET ... distinct](https://manual.manticoresearch.com/Searching/Faceted_search#Faceting-without-duplicates)。
- [PR #598](https://github.com/manticoresoftware/manticoresearch/pull/598)为`YEAR()`和其他时间戳函数添加bigint支持。
- [提交8e85d4bc](https://github.com/manticoresoftware/manticoresearch/commit/8e85d4bce596cc88f9d9615ea243a27e4afde0f7)自适应[rt_mem_limit](https://manual.manticoresearch.com/Creating_a_table/Local_indexes/Plain_and_real-time_index_settings#rt_mem_limit)。之前Manticore Search在保存新磁盘块到磁盘前会收集正好达到`rt_mem_limit`的数据，而在保存期间仍会收集最多10%更多（即双缓冲）以尽量减少可能的插入暂停。如果该限制也被耗尽，添加新文档将被阻塞直到磁盘块完全保存到磁盘。新的自适应限制基于我们现在有[auto-optimize](https://manual.manticoresearch.com/Server_settings/Searchd#auto_optimize)的事实，因此磁盘块不完全遵守`rt_mem_limit`并提前开始刷新磁盘块并不是大问题。因此，我们现在收集最多`rt_mem_limit`的50%并将其保存为磁盘块。在保存时，我们查看统计信息（已保存多少，保存期间到达了多少新文档）并重新计算下次使用的初始速率。例如，如果我们保存了9000万文档，而在保存期间又到达了1000万文档，速率是90%，因此我们知道下次可以收集最多`rt_mem_limit`的90%后再开始刷新另一个磁盘块。速率值会自动从33.3%到95%之间计算。
- [问题#628](https://github.com/manticoresoftware/manticoresearch/issues/628)为PostgreSQL源添加[unpack_zlib](https://manual.manticoresearch.com/Adding_data_from_external_storages/Fetching_from_databases/Database_connection#unpack_zlib)。感谢[Dmitry Voronin](https://github.com/dimv36)的[贡献](https://github.com/manticoresoftware/manticoresearch/pull/630)。
- [提交6d54cf2b](https://github.com/manticoresoftware/manticoresearch/commit/6d54cf2b319b131970c29410cc21abcbdf8083b1) `indexer -v`和`--version`。之前你仍然可以看到indexer的版本，但`-v`/`--version`不被支持。
- [问题#662](https://github.com/manticoresoftware/manticoresearch/issues/662)默认情况下通过systemd启动Manticore时无限mlock限制。
- [提交63c8cd05](https://github.com/manticoresoftware/manticoresearch/commit/63c8cd05cf399e705c2c14939411a92cb784735a)将coro rwlock的spinlock改为op队列。
- [提交41130ce3](https://github.com/manticoresoftware/manticoresearch/commit/41130ce30d1734bbf8e6b8b63c4e815caf9464f2)环境变量`MANTICORE_TRACK_RT_ERRORS`对调试RT段损坏很有用。



### 突破性变更
- 二进制日志版本已提升，旧版本的二进制日志不会被重放，因此升级时请确保在停止Manticore Search时干净停止：在停止旧实例后，`/var/lib/manticore/binlog/`目录下除了`binlog.meta`外不应有其他二进制日志文件。
- [提交3f659f36](https://github.com/manticoresoftware/manticoresearch/commit/3f659f36e87d99ee262205a8eae4663a255be630)`show threads option format=all`中的新列"chain"。它显示某些任务信息票据的堆栈，对性能分析最有用，因此如果你正在解析`show threads`输出，请注意新列。
- `searchd.workers`自3.5.0版本起已被弃用，现在标记为已弃用，如果你的配置文件中仍有该设置，启动时会触发警告。Manticore Search将启动，但会带有警告。

### 错误修复
- ❗[Issue #650](https://github.com/manticoresoftware/manticoresearch/issues/650) Manticore 4.0.2 比 Manticore 3.6.3 更慢。4.0.2 在批量插入方面比之前版本更快，但在单文档插入方面显著更慢。此问题已在 4.2.0 中修复。
- ❗[Commit 22f4141b](https://github.com/manticoresoftware/manticoresearch/commit/22f4141bed1411c83684ae6e0bae832071cce3df) RT 索引在高强度 REPLACE 负载下可能会损坏，或者导致崩溃
- [Commit 03be91e4](https://github.com/manticoresoftware/manticoresearch/commit/03be91e4f720a3f20bee0278dd8f0d44abd3ef0e) 修复了合并分组器和分组 N 排序器的平均值计算；修复了聚合的合并
- [Commit 2ea575d3](https://github.com/manticoresoftware/manticoresearch/commit/2ea575d34efe38661f14d858f2b552456f29fe42) `indextool --check` 可能会崩溃
- [Commit 7ec76d4a](https://github.com/manticoresoftware/manticoresearch/commit/7ec76d4abf01b5fca6f10a0000fe64d5d8e5fa52) 由 UPDATE 操作引起的内存耗尽问题
- [Commit 658a727e](https://github.com/manticoresoftware/manticoresearch/commit/658a727e41f3c3fbcde9754149528f34ed76ba19) 守护进程在 INSERT 操作时可能挂起
- [Commit 46e42b9b](https://github.com/manticoresoftware/manticoresearch/commit/46e42b9b386e31e53247ed634e158b533e28063e) 守护进程在关闭时可能挂起
- [Commit f8d7d517](https://github.com/manticoresoftware/manticoresearch/commit/f8d7d5177cc83d250b493b4cfc619732b29cf072) 守护进程在关闭时可能崩溃
- [Commit 733accf1](https://github.com/manticoresoftware/manticoresearch/commit/733accf165142a1d1574689525ccca8907971158) 守护进程在崩溃时可能挂起
- [Commit f7f8bd8c](https://github.com/manticoresoftware/manticoresearch/commit/f7f8bd8c0dbb23a59a88502dcba16b0918fb2330) 守护进程在启动时尝试使用无效节点列表重新加入集群时可能崩溃
- [Commit 14015561](https://github.com/manticoresoftware/manticoresearch/commit/140155613821ecaddcd1a3dfc4f7369b0df6aef7) 在 RT 模式下，如果无法解析其代理之一，分布式索引可能会被完全遗忘
- [Issue #683](https://github.com/manticoresoftware/manticoresearch/issues/683) attr bit(N) engine='columnar' 失败
- [Issue #682](https://github.com/manticoresoftware/manticoresearch/issues/682) 创建表失败，但会留下目录
- [Issue #663](https://github.com/manticoresoftware/manticoresearch/issues/663) 配置失败：未知键名 'attr\_update\_reserve'
- [Issue #632](https://github.com/manticoresoftware/manticoresearch/issues/632) Manticore 在批量查询时崩溃
- [Issue #679](https://github.com/manticoresoftware/manticoresearch/issues/679) 批量查询在 v4.0.3 中再次导致崩溃
- [Commit f7f8bd8c](https://github.com/manticoresoftware/manticoresearch/commit/f7f8bd8c0dbb23a59a88502dcba16b0918fb2330) 修复了守护进程在启动时尝试使用无效节点列表重新加入集群时崩溃的问题
- [Issue #643](https://github.com/manticoresoftware/manticoresearch/issues/643) Manticore 4.0.2 在批量插入后无法接受连接
- [Issue #635](https://github.com/manticoresoftware/manticoresearch/issues/635) 使用 ORDER BY JSON.field 或字符串属性的 FACET 查询可能导致崩溃
- [Issue #634](https://github.com/manticoresoftware/manticoresearch/issues/634) 在带有 packedfactors 的查询中发生 SIGSEGV 崩溃
