根据 MarkLogic 文档,“MarkLogic 的集合实现旨在优化针对大量文档的查询性能。”。因此,这意味着您只能在庞大的数据库上识别差异。
我试图通过实际来识别这一点,因此我创建了两个 XQuery,一个带有集合,一个带有元素,正如您所建议的那样。但是,我将xdmp:query-trace(fn:true()) 放在两个XQuery 的顶部。我一一运行查询并分析了我的 MarkLogic 日志文件。
如果是元素 XQuery:
2018-11-12 15:16:58.448 Info: App-Services: at 5:12: xdmp:eval("declare namespace sem = "http://marklogic.com/semantics&quo...", (), <options xmlns="xdmp:eval"><database>5310618057872024096</database>...</options>)
2018-11-12 15:16:58.448 Info: App-Services: at 5:12: Analyzing path for search: fn:collection()/sem:triples
2018-11-12 15:16:58.448 Info: App-Services: at 5:12: Step 1 is searchable: fn:collection()
2018-11-12 15:16:58.448 Info: App-Services: at 5:12: Step 2 is searchable: sem:triples
2018-11-12 15:16:58.448 Info: App-Services: at 5:12: Path is fully searchable.
2018-11-12 15:16:58.448 Info: App-Services: at 5:12: Gathering constraints.
2018-11-12 15:16:58.448 Info: App-Services: at 5:12: Step 2 contributed 1 constraint: sem:triples
2018-11-12 15:16:58.449 Info: App-Services: at 5:12: Search query contributed 1 constraint: cts:element-value-query(xs:QName("sem:object"), "taxonomy", ("lang=en"), 1)
2018-11-12 15:16:58.449 Info: App-Services: at 5:12: Executing search.
2018-11-12 15:16:58.464 Info: App-Services: at 5:12: Selected 65964 fragments to filter
如果是 XQuery 集合:
2018-11-12 15:20:07.871 Info: App-Services: at 5:11: xdmp:eval("declare namespace sem = "http://marklogic.com/semantics&quo...", (), <options xmlns="xdmp:eval"><database>5310618057872024096</database>...</options>)
2018-11-12 15:20:07.871 Info: App-Services: at 5:11: Analyzing path for search: fn:collection("/triples")
2018-11-12 15:20:07.871 Info: App-Services: at 5:11: Step 1 is searchable: fn:collection("/triples")
2018-11-12 15:20:07.871 Info: App-Services: at 5:11: Path is fully searchable.
2018-11-12 15:20:07.871 Info: App-Services: at 5:11: Gathering constraints.
2018-11-12 15:20:07.871 Info: App-Services: at 5:11: Step 1 contributed 1 constraint: fn:collection("/triples")
2018-11-12 15:20:07.875 Info: App-Services: at 5:11: Search query contributed 1 constraint: cts:element-value-query(xs:QName("sem:object"), "taxonomy", ("lang=en"), 1)
2018-11-12 15:20:07.875 Info: App-Services: at 5:11: Executing search.
2018-11-12 15:20:07.891 Info: App-Services: at 5:11: Selected 65964 fragments to filter
差异很明显。如果我们使用集合查询,MarkLogic 几乎在单步“1”中完成所有事情,但如果是元素查询,MarkLogic 正在执行两步过程。