Hi Max,
finally some feedback...
Creating the main-memory db via xquery (declare option or pragma) did not work: declare option db:mainmem 'true'; or (# db:mainmem true #) Via command line it works: set mainmem true
Yes, this is on purpose, and for two reasons:
* All databases that are opened within a query will eventually be closed again. * If a main-memory database is created, it has no disk representation, and as soon as the query is evaluated, it gets lost.
A long time ago, BaseX started as a main-memory database, which is actually the main reason for the MAINMEM flag. Step by step, we reduced internal main memory dependencies, as we would have to implemented many things twice. If I remember right, the most important mainmem scenarios are as follows:
* In the standalone context, a main-memory database can be created (using CREATE DB), which can then be accessed by subsequent commands. * If a BaseX server instance is started, and if a database is created in its context (using CREATE DB), other BaseX client instances can access (and update) this database (using OPEN, db:open, etc.) as long as no other database is opened/created by the server. * By the way: main-memory database instances are also created by the invocation of doc(...) or collection(...), if the argument is not a database (no matter which value is set for MAINMEM). In other words: the same internal representation is used for main-memory databases and documents/collections generated via XQuery.
It may be worth adding such inormation in our Wiki articles on Databases [1]; is anyone willing to do that? ;)
Now back to the motivation of your question: We could think about extending the MAINMEM option and also open existing databases in main-memory (via OPEN or db:open) if the option is activated. This would imply that the full-text index would be ignored (currently, no main-memory representation of this index structure exists). But more importantly, updates would have to be propagated back to disk if the database is closed (or after every update). Currently, no code exists to convert main-memory instances to disk (but the data structures are at least similar), so it would be easier to simply ignore updates - but that's probably not what one would expect?
Christian