• 列出表

Manticore Search 只有一个层级的表结构。

与其他数据库管理系统不同,Manticore 中没有将表分组到数据库中的概念。然而,为了与 SQL 方言的互操作性,Manticore 接受 SHOW DATABASES 语句,但该语句不会返回任何结果。

SHOW TABLES

通用语法:

SHOW TABLES [ LIKE pattern ]

SHOW TABLES 语句会列出所有当前活跃的表及其类型。现有的表类型包括 local(本地表)、distributed(分布式表)、rt(实时表)、percolate(过滤表)和 template(模板表)。

SQL:

SHOW TABLES;
+----------+-------------+
| Index    | Type        |
+----------+-------------+
| dist     | distributed |
| plain    | local       |
| pq       | percolate   |
| rt       | rt          |
| template | template    |
+----------+-------------+
5 rows in set (0.00 sec)
$client->nodes()->table();
Array
(
    [dist1] => distributed
    [rt] => rt
    [products] => rt
)

Python:

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''}

Javascript:

res = await utilsApi.sql('SHOW TABLES');
{"columns":[{"Index":{"type":"string"}},{"Type":{"type":"string"}}],"data":[{"Index":"products","Type":"rt"}],"total":0,"error":"","warning":""}

java:

utilsApi.sql("SHOW TABLES")
{columns=[{Index={type=string}}, {Type={type=string}}], data=[{Index=products, Type=rt}], total=0, error=, warning=}

C#:

utilsApi.Sql("SHOW TABLES")
{columns=[{Index={type=string}}, {Type={type=string}}], data=[{Index=products, Type=rt}], total=0, error="", warning=""}

Optional LIKE clause is supported for filtering tables by name.

SQL:

SHOW TABLES LIKE 'pro%';
+----------+-------------+
| Index    | Type        |
+----------+-------------+
| products | distributed |
+----------+-------------+
1 row in set (0.00 sec)
$client->nodes()->table(['body'=>['pattern'=>'pro%']]);
Array
(
    [products] => distributed
)

Python:

res = 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''}

Javascript:

utilsApi.sql('SHOW TABLES LIKE \'pro%\'')
{"columns":[{"Index":{"type":"string"}},{"Type":{"type":"string"}}],"data":[{"Index":"products","Type":"rt"}],"total":0,"error":"","warning":""}

java:

utilsApi.sql("SHOW TABLES LIKE 'pro%'")
{columns=[{Index={type=string}}, {Type={type=string}}], data=[{Index=products, Type=rt}], total=0, error=, warning=}

C#:

utilsApi.Sql("SHOW TABLES LIKE 'pro%'")
{columns=[{Index={type=string}}, {Type={type=string}}], data=[{Index=products, Type=rt}], total=0, error="", warning=""}

DESCRIBE

{DESC | DESCRIBE} table_name [ LIKE pattern ]

DESCRIBE 语句列出了表的列及其关联的类型。列包括文档 ID、全文字段和属性。列的顺序与 INSERTREPLACE 语句中预期的字段和属性顺序相匹配。列类型包括 fieldintegertimestampordinalboolfloatbigintstringmva。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 name.@table

您还可以通过执行查询 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)

您还可以将 <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

SHOW CREATE TABLE table_name

打印用于创建指定表的 CREATE TABLE 语句。

SQL:

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)

Percolate table schemas

如果您在一个 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)

最后更新于