1.6. 分区数据库¶
分区数据库允许在集群中进行数据托管,这为约束到单个分区的查询提供了显著的性能改进。
请参阅指南 getting started with partitioned databases
1.6.1. /db/_partition/partition
¶
-
GET
/{db}/_partition/{partition}
¶ 此终结点返回描述所提供分区的信息。它包括文档和已删除文档计数以及外部和活动数据大小。
状态代码: - 200 OK -- 请求已成功完成
请求 :
GET /db/_partition/sensor-260 HTTP/1.1 Accept: application/json Host: localhost:5984
响应 :
HTTP/1.1 200 OK Cache-Control: must-revalidate Content-Length: 119 Content-Type: application/json Date: Thu, 24 Jan 2019 17:19:59 GMT Server: CouchDB/2.3.0-a1e11cea9 (Erlang OTP/21) { "db_name": "my_new_db", "doc_count": 1, "doc_del_count": 0, "partition": "sensor-260", "sizes": { "active": 244, "external": 347 } }
1.6.2. /db/_partition/partition/_all_docs
¶
-
GET
/{db}/_partition/{partition}/_all_docs
¶ 参数: - db -- 数据库名称
- partition -- 分区名称
这个端点是一个方便的端点,可以自动在提供的分区范围上设置边界。使用
/db/_all_docs
具有适当配置值的终结点start_key
和end_key
.参考 view endpoint 有关可用查询参数和返回数据格式的完整说明的文档。
请求 :
GET /db/_partition/sensor-260/_all_docs HTTP/1.1 Accept: application/json Host: localhost:5984
响应 :
HTTP/1.1 200 OK Cache-Control: must-revalidate Content-Type: application/json Date: Sat, 10 Aug 2013 16:22:56 GMT ETag: "1W2DJUZFZSZD9K78UFA3GZWB4" Server: CouchDB (Erlang/OTP) Transfer-Encoding: chunked { "offset": 0, "rows": [ { "id": "sensor-260:sensor-reading-ca33c748-2d2c-4ed1-8abf-1bca4d9d03cf", "key": "sensor-260:sensor-reading-ca33c748-2d2c-4ed1-8abf-1bca4d9d03cf", "value": { "rev": "1-05ed6f7abf84250e213fcb847387f6f5" } } ], "total_rows": 1 }
1.6.3. /db/_partition/partition/_design/design-doc/_view/view-name
¶
-
GET
/{db}/_partition/{partition}/_design/{ddoc}/_view/{view}
¶ 参数: - db -- 数据库名称
- partition -- 分区名称
- ddoc -- 设计文件id
- view -- 视图名称
此端点负责执行分区查询。返回的视图结果将只包含具有指定分区名的行。
参考 view endpoint 有关可用查询参数和返回数据格式的完整说明的文档。
GET /db/_partition/sensor-260/_design/sensor-readings/_view/by_sensor HTTP/1.1 Accept: application/json Host: localhost:5984
响应 :
HTTP/1.1 200 OK Cache-Control: must-revalidate Content-Type: application/json Date: Wed, 21 Aug 2013 09:12:06 GMT ETag: "2FOLSBSW4O6WB798XU4AQYA9B" Server: CouchDB (Erlang/OTP) Transfer-Encoding: chunked { "offset": 0, "rows": [ { "id": "sensor-260:sensor-reading-ca33c748-2d2c-4ed1-8abf-1bca4d9d03cf", "key": [ "sensor-260", "0" ], "value": null }, { "id": "sensor-260:sensor-reading-ca33c748-2d2c-4ed1-8abf-1bca4d9d03cf", "key": [ "sensor-260", "1" ], "value": null }, { "id": "sensor-260:sensor-reading-ca33c748-2d2c-4ed1-8abf-1bca4d9d03cf", "key": [ "sensor-260", "2" ], "value": null }, { "id": "sensor-260:sensor-reading-ca33c748-2d2c-4ed1-8abf-1bca4d9d03cf", "key": [ "sensor-260", "3" ], "value": null } ], "total_rows": 4 }
1.6.4. /db/_partition/partition_id/_find
¶
-
POST
/{db}/_partition/{partition_id}/_find
¶ 参数: - db -- 数据库名称
- id (partition) -- 要查询的分区的名称
此终结点负责按其ID查找分区查询。返回的视图结果将只包含具有指定分区ID的行。
参考 find endpoint 有关可用参数和返回数据格式的完整说明的文档。
1.6.5. /db/_partition/partition_id/_explain
¶
-
POST
/{db}/_partition/{partition_id}/_explain
¶ 参数: - db -- 数据库名称
分区id: 要查询的分区的名称
此端点显示查询正在使用哪个索引。
参考 explain endpoint 有关可用参数和返回数据格式的完整说明的文档。