Hi Andy,
The current behavior is correct indeed – but it might not be what one expects. Currently, we are…
a) collecting all static database references in the query and b) assigning either read or write locks to these databases, depending if the overall query is updating or not.
The reason is that it’s often tricky to determine statically (i.e., while parsing the query and before compiling and optimizing it) which databases will be accessed for read or write operations without analyzing the query in more detail. An arbitrary example:
let $db := db:open('db1') return insert node <new/> into $db/*
We would need to follow the variable reference in order to find out if db1 will be updated. In simple queries such as yours, however, this might be possible; I’ll have some more thoughts on that.
Cheers Christian
On Fri, Feb 8, 2019 at 5:45 PM Andy Bunce bunce.andy@gmail.com wrote:
sorry typo there, should be: I expected BEP to appear only in the Read locking, as it does if I remove the db:create call
On Fri, 8 Feb 2019 at 16:03, Andy Bunce bunce.andy@gmail.com wrote:
Using 9.1.2
let $d:=db:open(``[BEP]``) return db:create(``[BEP-staging]``,$d,$d!base-uri(.))
The GUI query info reports:
- Read Locking: (none)
- Write Locking: BEP,BEP-staging
I expected BEP-staging to appear only in the Read locking, as it does if I remove the db:create call Is this correct?
/Andy
On Thu, 21 Sep 2017 at 16:26, Christian Grün christian.gruen@gmail.com wrote:
The use of String Constructor does not avoid the global read lock
Good to know, thanks. It now does [1], provided that the constructor consists of a single static strings.
[1] http://files.basex.org/releases/latest/
<job id="job13" type="ScheduledXQuery" state="cached" user="admin" duration="PT0.007S" reads="(global)" writes="(none)">count(collection(``[BEP]``))</job>
On 20 September 2017 at 23:28, Christian Grün christian.gruen@gmail.com wrote:
bxcode:inline-variables($xqcode-uri) as xs:string @returns xquery code that is the source code from $xqcode-uri but with inlining "constant" variables and operations applied
This could be used as a preprocessor. Is this something that could be created from the bits and pieces in the current BaseX Java code?
This reminds me of the discussion with Omar [1]: There is currently no way to generate a correct string representation for compiled code. In the GUI Info View, we output a string representation of the optimized query. In simple cases, this string is a valid and equivalent to the original query string, but it’s fairly easy to generate invalid results.
If it’s an option for you to generate code in XQuery, something like the following could be done:
_ bxcode.xqm _______
module namespace bxcode = 'bxcode'; declare function bxcode:bind-external-variables( $uri as xs:string, $vars as map(xs:string, xs:string) ) as xs:string { let $xqcode := unparsed-text($uri) return fold-left( map:keys($vars), $xqcode, function($string, $name) { let $value := replace($vars($name), ']``', '`{"]``"}`', 'q') return $string => replace('declare variable $' || $name || ' external;', '', 'q') => replace('$' || $name, '``[' || $value || ']``', 'q') } ) };
_ example.xq _______
declare variable $db external; count(collection($db))
_ run-bxcode.xq _______
import module namespace bxcode = 'bxcode' at 'bxcode.xqm'; bxcode:bind-external-variables('query.xq', map { 'db': 'BEP' })
_ output _______
count(collection(``[BEP]``))
Cheers, Christian
[1] https://www.mail-archive.com/basex-talk@mailman.uni-konstanz.de/msg09863.htm...