With the Optic API, you can express three conditions using multiple op:where
clauses or by nesting op:and
s. Looking at the plans, the first approach uses multiple FILTER
statements, while the second ANDs the conditions in a single FILTER
statement. Is there a difference in efficiency between these?
Query:
op:from-view("stuff", "table")
=> op:where($cond1)
=> op:where($cond2)
=> op:where($cond3)
Plan (reformatted for legibility):
<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("value1"))
FILTER (field2 eq Q{http://www.w3.org/2001/XMLSchema}string("value2"))
FILTER (field3 eq Q{http://www.w3.org/2001/XMLSchema}string("value3"))"
)
</map:value>
</map:entry>
Query:
op:from-view("stuff", "table")
=> op:where(op:and(op:and($cond1, $cond2), $cond3))
Plan:
<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("value1") and
field2 eq Q{http://www.w3.org/2001/XMLSchema}string("value2") and
field3 eq Q{http://www.w3.org/2001/XMLSchema}string("value3")
)"
)
</map:value>
</map:entry>
They'll behave identically - there's no reason to choose one over the other.