简体   繁体   English

在Cosmos DB中优化gremlin查询

[英]Optimize gremlin queries in Cosmos DB

I run the queries likes the following in gremlin in Cosmos Graph: 我在Cosmos Graph的gremlin中运行如下查询:

g.V().hasLabel('vertex_label').limit(1)

This query is problematic in concern of size of data which returned from DB as this query returns all inE and outE of the selected vertex. 该查询涉及从DB返回的数据大小,因为该查询返回所选顶点的所有inEoutE The question is how can I optimize this query in notion of size of query result? 问题是如何根据查询结果的大小优化此查询?

As mentioned, the mentioned query returns a vertex with all its dependencies and connections. 如前所述,提到的查询返回一个具有所有依赖关系和连接的顶点。 Therefore, it can be problematic in high volume of data (when there are a lot of connection with the specified vertex). 因此,在大量数据中(与指定顶点的连接很多时)可能会出现问题。 Hence, We can optimize our queries using something likes properties , properyMap , values ,and valueMap . 因此,我们可以使用诸如propertiesproperyMapvaluesvalueMap查询优化查询。 In sum, valueMap(true) in the end of related queries can be useful and minimize the size of the transferred data from Cosmos. 总而言之,相关查询末尾的valueMap(true)可能有用,并且可以最大程度地减少从Cosmos传输的数据的大小。 For example: 例如:

g.V().hasLabel('play').limit(1).valueMap(true)

The boolean value is for getting id and label of the vertex in addition to vertex properties. 布尔值除了用于获取顶点属性外,还用于获取顶点的idlabel

Also, If there is any notion of optimization in the structure of a query, you can find more in this link . 另外,如果查询的结构中有优化的概念,则可以在此链接中找到更多信息。

How are you using CosmosDB Graph, via Microsoft.Azure.Graphs SDK or Gremlin server? 您如何通过Microsoft.Azure.Graphs SDK或Gremlin服务器使用CosmosDB Graph?

If you are using Microsoft.Azure.Graphs, the latest version ( 0.2.4-preview as of posting) supports specifying the GraphSONFormat as a parameter on DocumentClient.CreateGremlinRequest(..) . 如果您使用的是Microsoft.Azure.Graphs,则最新版本(发布时为0.2.4-preview )支持将GraphSONFormat指定为DocumentClient.CreateGremlinRequest(..)上的参数。 You can choose from either GraphSONFormat.Normal or GraphSONFormat.Compact and Compact should be the default if it is not supplied. 如果未提供,则可以从GraphSONFormat.NormalGraphSONFormat.CompactCompact中选择默认值。

For the CosmosDB Gremlin server, Compact is also the default behavior. 对于CosmosDB Gremlin服务器,“ Compact也是默认行为。

With GraphSONFormat.Compact , vertex results won't include edges and as a result, outE and inE fetches can be skipped when fetching the vertex. 使用GraphSONFormat.Compact ,顶点结果将不包括边,因此,在提取顶点时,可以跳过outEinE提取。 GraphSONFormat.Normal will return the full GraphSON response if this is desired. 如果需要, GraphSONFormat.Normal将返回完整的GraphSON响应。

Additional Note : There are optimizations on limit() that will be included in the next release of SDK/server, so I would expect additional perf gains on the traversal example that you provided when the release becomes available. 附加说明 :在下一个版本的SDK /服务器中将包含对limit()优化,因此,我希望在发行版本可用时,您提供的遍历示例会带来额外的性能提升。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM