Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Optimizing XQuery interogation with XPath predicate

So, I was optimizing a query I carried over from SQL, and I ran into a bit of a performance issue when compared to how it used to work in sql.

Basically, my php script is sending between 2 and 5 sets of two (numeric) values.

These have to be compare against id and doc from my collection's elements. Of course, the fewer elements in the predicate, the faster the query My for with predicate looks like this right now:

for $p in collection("/db/col1")//set1/page[(id eq val1 and doc eq altval1) or (id eq val2 and doc eq altval2) or (id eq val3 and doc eq altval3) or (id eq val4 and doc eq altval4) or (id eq val5 and doc eq altval5)]

I need to somehow write a predicate that changes depending on the number of values. I tried writing a function that writes the conditions and calling it in the predicate, depending on how many values are passed, but that didn't seem to work.

I would really appreciate if someone knows a workaround for this.

Edit: Removed a typo in the code.

like image 402
Den Avatar asked Mar 26 '26 02:03

Den


1 Answers

If $val and $altval are two sequences of values, then you can write the generic predicate

SOMETHING[some $i in 1 to count($val) satisfies (id=$val[$i] and doc=$altval[$i]] 

But I've no idea how well it will perform.

like image 136
Michael Kay Avatar answered Mar 27 '26 19:03

Michael Kay



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!