BaseXdb / basex

BaseX Main Repository.
http://basex.org
BSD 3-Clause "New" or "Revised" License
685 stars 265 forks source link

Database, Index, Full-Text Module: Relax $db argument #2143

Open ChristianGruen opened 2 years ago

ChristianGruen commented 2 years ago

Many functions in the Database, Index and Full-Text modules expect the database name as first argument. Currently, this argument must be a string, but it could be beneficial to relax this and also allow document nodes:

1. Run index queries on main-memory databases

Each main-memory database instance has internal index structures. The indexes could be addressed directly if the document nodes could be passed on to the index functions:

let $doc := document {
  <a>{
    (1 to 100) ! <b>{ . }</b>
  }</a>
} update {}
return db:text($doc, '5')

2. Improve locking

If the name of a database is supplied to a user-defined function that opens this database, and if this function cannot be inlined (e.g. because it’s too complex or recursive), local locking may fail:

declare function local:do-complex-things($name) {
  db:get($name)//do-complex-things
};
local:do-complex-things('factbook')

It’s a good idea then to open the database in advance and pass on the document nodes:

declare function local:do-complex-things($docs) {
  $docs//do-things
};
local:do-complex-things(db:get('factbook'))

However, that will only be an option if the user-defined function contains code that depends on the database names (such as db:text). It would work if the functions were allowed to also take document nodes:

declare function local:do-complex-things($docs) {
  db:text($docs, 'do-complex-things')
};
local:do-complex-things(db:get('factbook'))