manual/chinese/Listing_tables.md
Manticore Search 对表具有单级层次结构。
与其它数据库管理系统不同,Manticore 没有将表分组到数据库的概念。但是,为了与 SQL 方言互操作,Manticore 接受 SHOW DATABASES 语句用于与 SQL 方言互操作,但该语句不会返回任何结果。
通用语法:
SHOW TABLES [ LIKE pattern ]
SHOW TABLES 语句列出所有当前活动的表及其类型。现有的表类型有 local、distributed、rt、percolate 和 template。
SHOW TABLES;
+----------+-------------+
| Index | Type |
+----------+-------------+
| dist | distributed |
| plain | local |
| pq | percolate |
| rt | rt |
| template | template |
+----------+-------------+
5 rows in set (0.00 sec)
POST /sql?mode=raw -d "SHOW TABLES"
[
{
"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": ""
}
]
$client->nodes()->table();
Array
(
[dist1] => distributed
[rt] => rt
[products] => rt
)
utilsApi.sql('SHOW TABLES')
{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''}
await utilsApi.sql('SHOW TABLES')
{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''}
res = await utilsApi.sql('SHOW TABLES');
{"columns":[{"Index":{"type":"string"}},{"Type":{"type":"string"}}],"data":[{"Index":"products","Type":"rt"}],"total":0,"error":"","warning":""}
utilsApi.sql("SHOW TABLES", true)
{columns=[{Index={type=string}}, {Type={type=string}}], data=[{Index=products, Type=rt}], total=0, error=, warning=}
utilsApi.Sql("SHOW TABLES", true)
{columns=[{Index={type=string}}, {Type={type=string}}], data=[{Index=products, Type=rt}], total=0, error="", warning=""}
utils_api.sql("SHOW TABLES", Some(true)).await
{columns=[{Index={type=string}}, {Type={type=string}}], data=[{Index=products, Type=rt}], total=0, error="", warning=""}
支持可选的 LIKE 子句,用于按名称过滤表。
<!-- intro -->SHOW TABLES LIKE 'pro%';
+----------+-------------+
| Index | Type |
+----------+-------------+
| products | distributed |
+----------+-------------+
1 row in set (0.00 sec)
POST /sql?mode=raw -d "SHOW TABLES LIKE 'pro%';"
[
{
"columns": [
{
"Table": {
"type": "string"
}
},
{
"Type": {
"type": "string"
}
}
],
"data": [
{
"Table": "products",
"Type": "distributed"
}
],
"total": 1,
"error": "",
"warning": ""
}
]
$client->nodes()->table(['body'=>['pattern'=>'pro%']]);
Array
(
[products] => distributed
)
utilsApi.sql('SHOW TABLES LIKE \'pro%\'');
{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''}
await utilsApi.sql('SHOW TABLES LIKE \'pro%\'');
{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''}
utilsApi.sql('SHOW TABLES LIKE \'pro%\'')
{"columns":[{"Index":{"type":"string"}},{"Type":{"type":"string"}}],"data":[{"Index":"products","Type":"rt"}],"total":0,"error":"","warning":""}
utilsApi.sql("SHOW TABLES LIKE 'pro%'", true)
{columns=[{Index={type=string}}, {Type={type=string}}], data=[{Index=products, Type=rt}], total=0, error=, warning=}
utilsApi.Sql("SHOW TABLES LIKE 'pro%'", true)
{columns=[{Index={type=string}}, {Type={type=string}}], data=[{Index=products, Type=rt}], total=0, error="", warning=""}
utils_api.sql("SHOW TABLES LIKE 'pro%'", Some(true)).await
{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 子句进行过滤:
select * from tbl.@table where type='text';
+------+-------+------+----------------+
| id | field | type | properties |
+------+-------+------+----------------+
| 2 | title | text | indexed stored |
+------+-------+------+----------------+
1 row in set (0.00 sec)
POST /sql?mode=raw -d "select * from tbl.@table where type='text';"
[{
"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 表,执行许多其他操作。
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')。SHOW CREATE TABLE tbl\G
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)
POST /sql?mode=raw -d "SHOW CREATE TABLE tbl"
[{
"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)