在使用分片表时,请注意以下限制:
-
本地分片表和集群分片表不能共存于同一组节点上: 在参与复制集群的一组节点上,不能混用:
- 本地分片表(创建时不带集群前缀:
create table s ... shards='N' rf='1') - 集群分片表(创建时带集群前缀:
create table c:r ... shards='N' rf='M')
示例:考虑一个 2 节点集群,其中:
- 表
s是在每个节点上独立创建的本地分片表 - 表
r通过集群在两个节点之间复制
在这种配置下,在同一组节点上尝试创建集群分片表(
create table c:r ... shards='N' rf='2')会失败。 - 本地分片表(创建时不带集群前缀:
-
集群名称一致性:
- 分片子系统在首次使用时会绑定到一个集群名称;这些节点上的所有集群分片表都必须使用同一个集群名称。
- 一旦选定集群名称,它就会应用于后续所有集群分片表的创建。
示例:如果你创建的第一个集群分片表使用:
create table c:users ... shards='N' rf='M'后续所有集群分片表都必须复用集群
c:create table c:orders ... shards='N' rf='M' -- works create table d:items ... shards='N' rf='M' -- fails -
不支持表结构变更:
- 一旦创建了分片表,就不能使用
ALTER TABLE修改其结构。 - 如需更改 schema,你必须:
- 创建一个具有所需结构的新分片表
- 将数据复制到新表中
- 删除旧表
- 一旦创建了分片表,就不能使用
-
分片数量限制:
- 每个分片表最多 3,000 个分片。
- 无论集群配置或表大小如何,这个限制都适用。
- 请相应规划你的分片策略,以确保不超过此限制。
-
rf和shards必须是带引号的整数:- 这两个选项都要求使用带引号的数值(
shards='10'、rf='2');不带引号、非数字、空值或小数值都会被拒绝。 - 在独立(非集群)服务器上,
rf必须为'1'。 - 在复制集群中,
rf必须介于1和集群节点数之间。
- 这两个选项都要求使用带引号的数值(
Manticore Search 对表具有单级层次结构。
与其它数据库管理系统不同,Manticore 没有将表分组到数据库的概念。但是,为了与 SQL 方言互操作,Manticore 接受 SHOW DATABASES 语句用于与 SQL 方言互操作,但该语句不会返回任何结果。
通用语法:
SHOW TABLES [ LIKE pattern ]
SHOW TABLES 语句列出所有当前活动的表及其类型。现有的表类型有 local、distributed、rt、percolate 和 template。
- SQL
- JSON
- PHP
- Python
- Python-asyncio
- javascript
- Java
- C#
- Rust
SHOW TABLES;POST /sql?mode=raw -d "SHOW TABLES"$client->nodes()->table();utilsApi.sql('SHOW TABLES')await utilsApi.sql('SHOW TABLES')res = await utilsApi.sql('SHOW TABLES');utilsApi.sql("SHOW TABLES", true)utilsApi.Sql("SHOW TABLES", true)utils_api.sql("SHOW TABLES", Some(true)).await+----------+-------------+
| Index | Type |
+----------+-------------+
| dist | distributed |
| plain | local |
| pq | percolate |
| rt | rt |
| template | template |
+----------+-------------+
5 rows in set (0.00 sec)[
{
"columns": [
{
"Table": {
"type": "string"
}
},
{
"Type": {
"type": "string"
}
}
],
"data": [
{
"Table": "dist",
"Type": "distributed"
},
{
"Table": "plain",
"Type": "local"
},
{
"Table": "pq",
"Type": "percolate"
},{
"Table": "rt",
"Type": "rt"
},{
"Table": "template",
"Type": "template"
}
],
"total": 5,
"error": "",
"warning": ""
}
]Array
(
[dist1] => distributed
[rt] => rt
[products] => rt
){u'columns': [{u'Index': {u'type': u'string'}},
{u'Type': {u'type': u'string'}}],
u'data': [{u'Index': u'dist1', u'Type': u'distributed'},
{u'Index': u'rt', u'Type': u'rt'},
{u'Index': u'products', u'Type': u'rt'}],
u'error': u'',
u'total': 0,
u'warning': u''}{u'columns': [{u'Index': {u'type': u'string'}},
{u'Type': {u'type': u'string'}}],
u'data': [{u'Index': u'dist1', u'Type': u'distributed'},
{u'Index': u'rt', u'Type': u'rt'},
{u'Index': u'products', u'Type': u'rt'}],
u'error': u'',
u'total': 0,
u'warning': u''}{"columns":[{"Index":{"type":"string"}},{"Type":{"type":"string"}}],"data":[{"Index":"products","Type":"rt"}],"total":0,"error":"","warning":""}{columns=[{Index={type=string}}, {Type={type=string}}], data=[{Index=products, Type=rt}], total=0, error=, warning=}{columns=[{Index={type=string}}, {Type={type=string}}], data=[{Index=products, Type=rt}], total=0, error="", warning=""}{columns=[{Index={type=string}}, {Type={type=string}}], data=[{Index=products, Type=rt}], total=0, error="", warning=""}支持可选的 LIKE 子句,用于按名称过滤表。
- SQL
- JSON
- PHP
- Python
- Python-asyncio
- javascript
- Java
- C#
- Rust
SHOW TABLES LIKE 'pro%';POST /sql?mode=raw -d "SHOW TABLES LIKE 'pro%';"$client->nodes()->table(['body'=>['pattern'=>'pro%']]);utilsApi.sql('SHOW TABLES LIKE \'pro%\'');await utilsApi.sql('SHOW TABLES LIKE \'pro%\'');utilsApi.sql('SHOW TABLES LIKE \'pro%\'')utilsApi.sql("SHOW TABLES LIKE 'pro%'", true)utilsApi.Sql("SHOW TABLES LIKE 'pro%'", true)utils_api.sql("SHOW TABLES LIKE 'pro%'", Some(true)).await+----------+-------------+
| Index | Type |
+----------+-------------+
| products | distributed |
+----------+-------------+
1 row in set (0.00 sec)[
{
"columns": [
{
"Table": {
"type": "string"
}
},
{
"Type": {
"type": "string"
}
}
],
"data": [
{
"Table": "products",
"Type": "distributed"
}
],
"total": 1,
"error": "",
"warning": ""
}
]Array
(
[products] => distributed
){u'columns': [{u'Index': {u'type': u'string'}},
{u'Type': {u'type': u'string'}}],
u'data': [{u'Index': u'products', u'Type': u'rt'}],
u'error': u'',
u'total': 0,
u'warning': u''}{u'columns': [{u'Index': {u'type': u'string'}},
{u'Type': {u'type': u'string'}}],
u'data': [{u'Index': u'products', u'Type': u'rt'}],
u'error': u'',
u'total': 0,
u'warning': u''}{"columns":[{"Index":{"type":"string"}},{"Type":{"type":"string"}}],"data":[{"Index":"products","Type":"rt"}],"total":0,"error":"","warning":""}{columns=[{Index={type=string}}, {Type={type=string}}], data=[{Index=products, Type=rt}], total=0, error=, warning=}{columns=[{Index={type=string}}, {Type={type=string}}], data=[{Index=products, Type=rt}], total=0, error="", warning=""}{columns=[{Index={type=string}}, {Type={type=string}}], data=[{Index=products, Type=rt}], total=0, error="", warning=""}{DESC | DESCRIBE} table_name [ LIKE pattern ]
DESCRIBE 语句列出表的列及其相关类型。列包括文档 ID、全文字段和属性。顺序与 INSERT 和 REPLACE 语句预期的字段和属性顺序一致。列类型包括 field、integer、timestamp、ordinal、bool、float、bigint、string 和 mva。ID 列将被指定为 bigint。示例:
mysql> DESC rt;
+---------+---------+
| Field | Type |
+---------+---------+
| id | bigint |
| title | field |
| content | field |
| gid | integer |
+---------+---------+
4 rows in set (0.00 sec)
支持可选的 LIKE 子句。有关其语法细节,请参阅 SHOW META。
您还可以通过执行查询 select * from <table_name>.@table 查看表模式。此方法的优点是您可以使用 WHERE 子句进行过滤:
- SQL
- JSON
select * from tbl.@table where type='text';POST /sql?mode=raw -d "select * from tbl.@table where type='text';"+------+-------+------+----------------+
| id | field | type | properties |
+------+-------+------+----------------+
| 2 | title | text | indexed stored |
+------+-------+------+----------------+
1 row in set (0.00 sec)[{
"columns":[{"id":{"type":"long long"}},{"field":{"type":"string"}},{"type":{"type":"string"}},{"properties":{"type":"string"}}],
"data":[
{"id":2,"field":"title","type":"text","properties":"indexed stored"}
],
"total":1,
"error":"",
"warning":""
}]您还可以将 <your_table_name>.@table 视为具有整数和字符串属性列的常规 Manticore 表,执行许多其他操作。
- SQL
select field from tbl.@table;
select field, properties from tbl.@table where type in ('text', 'uint');
select * from tbl.@table where properties any ('stored');SHOW CREATE TABLE table_name [ OPTION output_words = 'list' | 'file' ]
打印用于创建指定表的 CREATE TABLE 语句。
output_words 选项允许您控制外部文件设置(如 stopwords、exceptions、wordforms、hitless_words)的显示方式:
'list'(默认):使用*_list选项(例如stopwords_list='word1; word2')以内联列表形式显示文件内容。'file':使用原始选项显示文件路径(例如stopwords='/path/to/file')。
- SQL
- JSON
SHOW CREATE TABLE tbl\GPOST /sql?mode=raw -d "SHOW CREATE TABLE tbl" Table: tbl
Create Table: CREATE TABLE tbl (
f text indexed stored
) charset_table='non_cont,cont' morphology='icu_chinese'
1 row in set (0.00 sec)[{
"columns":[{"Table":{"type":"string"}},{"Create Table":{"type":"string"}}],
"data":[
{"Table":"tbl","Create Table":"CREATE TABLE tbl (\nf text)"}
],
"total":1,
"error":"",
"warning":""
}]如果您对 percolate 表使用 DESC 语句,它将显示外层表模式,即存储查询的模式。此模式是静态的,对所有本地 percolate 表都相同:
mysql> DESC pq;
+---------+--------+
| Field | Type |
+---------+--------+
| id | bigint |
| query | string |
| tags | string |
| filters | string |
+---------+--------+
4 rows in set (0.00 sec)
如果您想查看预期的文档模式,请使用以下命令:
DESC <pq table name> table:
mysql> DESC pq TABLE;
+-------+--------+
| Field | Type |
+-------+--------+
| id | bigint |
| title | text |
| gid | uint |
+-------+--------+
3 rows in set (0.00 sec)
此外,desc pq table like ... 也受支持,其工作方式如下:
mysql> desc pq table like '%title%';
+-------+------+----------------+
| Field | Type | Properties |
+-------+------+----------------+
| title | text | indexed stored |
+-------+------+----------------+
1 row in set (0.00 sec)
删除表在内部执行分两个步骤:
- 清空表(类似于 TRUNCATE)
- 删除表文件夹中的所有表文件。所有表使用的外部表文件(例如词形变化、扩展或停用词)也会被删除。注意,当使用
CREATE TABLE时,这些外部文件会被复制到表文件夹,因此不会删除CREATE TABLE中指定的原始文件。
只有在服务器以 RT 模式运行时才可以删除表。可以删除 RT 表、PQ 表和分布式表。
- SQL
- JSON
- PHP
- Python
- Python-asyncio
- javascript
- Java
- C#
- Rust
DROP TABLE products;POST /cli -d "DROP TABLE products"$params = [ 'table' => 'products' ];
$response = $client->indices()->drop($params);utilsApi.sql('DROP TABLE products')await utilsApi.sql('DROP TABLE products')res = await utilsApi.sql('DROP TABLE products');sqlresult = utilsApi.sql("DROP TABLE products", true);sqlresult = utilsApi.Sql("DROP TABLE products", true);let sqlresult = utils_api.sql("DROP TABLE products", Some(true)).await;Query OK, 0 rows affected (0.02 sec){
"total":0,
"error":"",
"warning":""
}Array
(
[total] => 0
[error] =>
[warning] =>
){u'error': u'', u'total': 0, u'warning': u''}{u'error': u'', u'total': 0, u'warning': u''}{"total":0,"error":"","warning":""}{total=0, error=, warning=}{total=0, error="", warning=""}{total=0, error="", warning=""}以下是 SQL 中 DROP TABLE 语句的语法:
DROP TABLE [IF EXISTS] table_name
通过 SQL 删除表时,添加 IF EXISTS 可以仅在表存在时删除该表。如果尝试删除不存在的表且使用了 IF EXISTS 选项,则不会有任何操作。
通过 PHP 删除表时,可以添加可选的 silent 参数,其作用与 IF EXISTS 相同。
- SQL
- JSON
- PHP
- Python
- Python-asyncio
- javascript
- Java
- C#
- Rust
DROP TABLE IF EXISTS products;POST /cli -d "DROP TABLE IF EXISTS products"$params =
[
'table' => 'products',
'body' => ['silent' => true]
];
$client->indices()->drop($params);utilsApi.sql('DROP TABLE IF EXISTS products')await utilsApi.sql('DROP TABLE IF EXISTS products')res = await utilsApi.sql('DROP TABLE IF EXISTS products');sqlresult = utilsApi.sql("DROP TABLE IF EXISTS products", true);sqlresult = utilsApi.Sql("DROP TABLE IF EXISTS products", true);let sqlresult = utils_api.sql("DROP TABLE IF EXISTS products", Some(true)).await;{u'error': u'', u'total': 0, u'warning': u''}{u'error': u'', u'total': 0, u'warning': u''}{"total":0,"error":"","warning":""}{total=0, error=, warning=}{total=0, error="", warning=""}{total=0, error="", warning=""}表可以通过 TRUNCATE TABLE SQL 语句或 truncate() PHP 客户端函数来清空。
以下是 SQL 语句的语法:
TRUNCATE TABLE table_name [WITH RECONFIGURE]
执行此语句时,会完全清除 RT 或分布式表。它会处理内存中的数据,解除所有表数据文件的链接,并释放相关的二进制日志。
对于清空分布式表,请使用不带 with reconfigure 选项的语法。只需对您的分布式表执行标准的 TRUNCATE 语句即可。
TRUNCATE TABLE distributed_table
注意:清空分布式表需要 Manticore Buddy。如果无法使用,请确保 Buddy 已安装。
也可以使用 DELETE FROM index WHERE id>0 来清空表,但不推荐这样做,因为它比 TRUNCATE 慢。
- SQL
- JSON
- PHP
- Python
- Python-asyncio
- javascript
- Java
- C#
- Rust
TRUNCATE TABLE products;POST /cli -d "TRUNCATE TABLE products"$params = [ 'table' => 'products' ];
$response = $client->indices()->truncate($params);utilsApi.sql('TRUNCATE TABLE products')await utilsApi.sql('TRUNCATE TABLE products')res = await utilsApi.sql('TRUNCATE TABLE products');utilsApi.sql("TRUNCATE TABLE products", true);utilsApi.Sql("TRUNCATE TABLE products", true);utils_api.sql("TRUNCATE TABLE products", Some(true)).await;Query OK, 0 rows affected (0.02 sec){
"total":0,
"error":"",
"warning":""
}Array(
[total] => 0
[error] =>
[warning] =>
){u'error': u'', u'total': 0, u'warning': u''}{u'error': u'', u'total': 0, u'warning': u''}{"total":0,"error":"","warning":""}{total=0, error=, warning=}{total=0, error="", warning=""}{total=0, error="", warning=""}此命令的一个可能用途是在 附加表 之前。
当使用 RECONFIGURE 选项时,清空表后,配置中指定的新分词、形态学和其他文本处理设置将生效。如果配置中的 schema 声明 与表的 schema 不同,表清空后将应用配置中的新 schema。
注意:
RECONFIGURE选项仅在 Plain 模式 下有意义,它应用配置文件中的设置。请注意,TRUNCATE仅支持 RT 表,且RECONFIGURE选项仅能在 Manticore 以 Plain 模式运行的 RT 表上使用。
使用此选项时,清空和重新配置表将成为一个原子操作。
- SQL
- HTTP
- PHP
- Python
- Python-asyncio
- javascript
- Java
- C#
- Rust
TRUNCATE TABLE products with reconfigure;POST /cli -d "TRUNCATE TABLE products with reconfigure"$params = [ 'table' => 'products', 'with' => 'reconfigure' ];
$response = $client->indices()->truncate($params);utilsApi.sql('TRUNCATE TABLE products WITH RECONFIGURE')await utilsApi.sql('TRUNCATE TABLE products WITH RECONFIGURE')res = await utilsApi.sql('TRUNCATE TABLE products WITH RECONFIGURE');utilsApi.sql("TRUNCATE TABLE products WITH RECONFIGURE", true);utilsApi.Sql("TRUNCATE TABLE products WITH RECONFIGURE" ,true);utils_api.sql("TRUNCATE TABLE products WITH RECONFIGURE", Some(true)).await;Query OK, 0 rows affected (0.02 sec){
"total":0,
"error":"",
"warning":""
}Array(
[total] => 0
[error] =>
[warning] =>
){u'error': u'', u'total': 0, u'warning': u''}{u'error': u'', u'total': 0, u'warning': u''}{"total":0,"error":"","warning":""}{total=0, error=, warning=}{total=0, error="", warning=""}