Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ChristianGruen opened this issue Oct 7, 2022 · 0 comments
Open

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

ChristianGruen opened this issue Oct 7, 2022 · 0 comments
Labels

Comments

@ChristianGruen
Copy link
Member

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'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant