Changes

Jump to navigation Jump to search
1,369 bytes added ,  13:59, 20 July 2022
===Commands===
Database All commands come with a detector for local locks. Global locking works with all commands unless is applied if the glob syntax is used, such as in the following command call:
* {{Code|DROP DB new*}}: drop Drop all databases starting with "the prefix string {{Code|new"}}.
===XQuery===
Deciding which databases will be accessed With {{Announce|Version 10}}, the [[BaseX 10#Compilation|lock detection has been fundamentally improved]], by a complex XQuery expression is a non-trivial tasksplitting compilation into multiple steps. Database detection works for the following types of queries:
* {{Code|//item}}, read-locking of the Local locks can be applied if it is possible after compile time to associate all database opened by a client* {{Code|doc('factbook')}}, read-locking of "factbook"* {{Code|collection('db/path/to/docs')}}, read-locking of "db"* {{Code|delete nodes db:pre('test')//*[string-length(local-name(.)) > 5]}}, write-locking of "test"* {{Code|fnoperations with static databases names:sum(1 to 100)}} (no lock)
A global {| class="wikitable"|-! Query! Description|-| <code>//item</code>| Read lock will be assigned if of the currently opened database|-| <code>doc('factbook')</code>| Read lock of the {{Code|factbook}} database|-| <code>collection('documents/path/to/docs')</code>| Read lock of the {{Code|documents}} database|-| <code>delete nodes db:get('test')//*[@type = 'misc']</code>| Write lock of the name {{Code|test}} database|-| <code>declare variables $db external;<br/>db:get($db)</code>| Read lock of the database externally bound to {{Code|$db}}.|-| <code>for $db in ('db1', 'db2')<br/>return db:get($db)</code>| Read lock of {{Code|db1}} and {{Code|db2}}, as the query is not a static string[[XQuery Optimizations#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 variable $SIMULATE := true();<br/>if($SIMULATE) then <doc/> else db:get('doc')</code>| No lock required, as the query is simplified to {{Code|<doc/>}} at compile time.|}
* {{Code|for $db in ('db1', 'db2') return dbA global lock will be assigned if the static detection fails:pre($db)}}* {{Code|doc(doc('test')/reference/text())}}* <code>let $db := 'test' return insert nodes <test/> into db:pre($db)</code>
The functions [[Databases#XML Documents{| class="wikitable"|-! Query! Description|-|fn<code>db:get(doc]] and [[Databases#XML Documents('test')/reference/text())</code>|fn:collection]] can also The name of the database to be opened will only be used to address that are not stored in a databaseknown at evaluation time. However, this may lead |-| <code>(1 to unwanted locks100) ! db:get(concat('db', and you have two options to reduce the number of locks: No database lookups will take place if .))</code>| The {{Option|WITHDBUNROLLLIMIT}} option is disabled, or if can be increased to generate 100 {{Function|FetchCode|fetchdb:xmlget}} is used instead of [[Databases#XML Documentsfunction calls and corresponding locks.|fn:doc]].}
The functions {{Code|fn:doc}} and {{Code|fn:collection}} can be used for both accessing databases resources and fetching resources at the specified URI (see [[Databases#Access Resources|Access Resources]] for more details). There are two ways to reduce the number of locks: # Turn off the {{Option|WITHDB}} option to prevent the functions from accessing databases; or# use {{Function|Fetch|fetch:doc}} for fetching resources from URIs, and use {{Function|Database|db:get}} 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.
=Changelog=
 
;Version 10.0
* Updated: Lock detection was improved by splitting compilation into multiple steps.
;Version 9.4
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu