Changes

Jump to navigation Jump to search
807 bytes added ,  13:55, 20 July 2022
no edit summary
With {{Announce|Version 10}}, [[BaseX 10#Compilation|lock detection was improved]] by splitting compilation into multiple steps.
Local locks can be applied if it is possible at after compile time to associate names of databases with all database operationswith static databases names:
{| class="wikitable"
! Description
|-
| {{Code|<code>//item}}</code>
| Read lock of the currently opened database
|-
| {{Code|<code>doc('factbook')}}</code>
| Read lock of the {{Code|factbook}} database
|-
| {{Code|<code>collection('documents/path/to/docs')}}</code>
| Read lock of the {{Code|documents}} database
|-
| {{Code|<code>delete nodes db:get('test')//*[string-length(local-name(.)) @type = 'misc']</code> 5]}}
| Write lock of the {{Code|test}} database
|-
| <code>declare variables $db external;<br/>db:get($db)</code>| Read lock of the database externally bound to {{Code|fn:sum(1 to 100)$db}}| ''no lock''.
|-
| {{Code|<code>for $db in ('db1', 'db2') <br/>return db:get($db)}}</code>
| Read lock of {{Code|db1}} and {{Code|db2}}, as query is [[XQuery Optimization#Loop Unrolling|unrolled at compile time]].
|-
| <code>let $db := 'test'<br/>return insert nodes <test/> into db:get($db)</code>| Read lock of {{Code|test}}, as the [[XQuery Optimizations#Variable_Inlining|variable is inlined]] at compile time.|-| <code>sum(1 to 100)</code>| No lock required|-| <code>declare variables variable $db externalSIMULATE := true(); <br/>if($SIMULATE) then <doc/> else db:get($db'doc')}}</code>| Read No lock of required, as the database externally bound query is simplified to {{Code|$db<doc/>}}at compile time.
|}
A global lock will be assigned if the static detection fails: {| class="wikitable"|-! Query! Description|-| <code>db:get(doc('test')/reference/text())</code>| The name of the database is not a static stringto be opened will only be known at evaluation time.|-| <code>(1 to 100) ! db:get(concat($db, .))</code>| The {{Option|UNROLLLIMIT}} can be increased to generate 100 {{Code|db:get}} function calls and corresponding locks.|}
* The functions {{Code|fn:doc(doc('test')/reference/text())}}* <code>let $db and {{Code|fn:= 'test' return insert nodes <test/> into db:getcollection}} can be used for both accessing databases resources and fetching resources at the specified URI ($dbsee [[Databases#Access Resources|Access Resources]] for more details)</code>. There are two ways to reduce the number of locks:
The functions {{Code|fn:doc}} and {{Code|fn:collection}} can also be used to address that are not stored in a database. However, this may lead to unwanted locks, and you have two options to reduce # Turn off the number of locks: No database lookups will take place if {{Option|WITHDB}} option is disabled, to prevent the functions from accessing databases; or if # use {{Function|Fetch|fetch:doc}} is used instead of for fetching resources from URIs, and use {{CodeFunction|fnDatabase|db:docget}}for accessing databases.
You can consult the query info output (which you find in via the [[GUI#Visualizations|Info View]] of the GUI or which you can turn on by setting , via {{OptionCode|QUERYINFO-V}} to on [[Command-Line]] or via turning on the {{CodeOption|trueQUERYINFO}}option) to find out which databases have been are locked by a query, and if local locks or a global lock is applied.
=XQuery Locks=
By default, access to external resources (files on hard disk, HTTP requests, ...) is not controlled by the transaction monitor of BaseX. Custom locks can be assigned via annotations, pragmas or options:
* A lock string may consist of a single key or multiple keys separated with commas.
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu