op:and 与多个 op:where 子句

问题描述 投票:0回答:1

使用 Optic API,您可以使用多个

op:where
子句或嵌套
op:and
来表达三个条件。查看计划,第一种方法使用多个
FILTER
语句,而第二种方法则在单个
FILTER
语句中对条件进行 AND 运算。这些之间的效率有区别吗?

查询:

op:from-view("stuff", "table")
  => op:where($cond1)
  => op:where($cond2)
  => op:where($cond3)

计划(为了易读而重新格式化):

<map:entry key="_plan">
  <map:value xsi:type="plan:query" xmlns:plan="http://marklogic.com/plan">
    plan:sparql(
      "{ SELECT field1 field2 field3 {  <http://marklogic.com/templateview>  . } }
         FILTER (field1 eq Q{http://www.w3.org/2001/XMLSchema}string(&quot;value1&quot;)) 
         FILTER (field2 eq Q{http://www.w3.org/2001/XMLSchema}string(&quot;value2&quot;)) 
         FILTER (field3 eq Q{http://www.w3.org/2001/XMLSchema}string(&quot;value3&quot;))"
    )
  </map:value>
</map:entry>

查询:

op:from-view("stuff", "table")
  => op:where(op:and(op:and($cond1, $cond2), $cond3))

计划:

<map:entry key="_plan">
  <map:value xsi:type="plan:query" xmlns:plan="http://marklogic.com/plan">
    plan:sparql(
      "{ SELECT field1 field2 field3 {  <http://marklogic.com/templateview>  . } } 
         FILTER (
           field1 eq Q{http://www.w3.org/2001/XMLSchema}string(&quot;value1&quot;) and 
           field2 eq Q{http://www.w3.org/2001/XMLSchema}string(&quot;value2&quot;) and 
           field3 eq Q{http://www.w3.org/2001/XMLSchema}string(&quot;value3&quot;)
         )"
    )
  </map:value>
</map:entry>
marklogic marklogic-optic-api
1个回答
1
投票

它们的行为相同 - 没有理由选择其中之一。

© www.soinside.com 2019 - 2024. All rights reserved.