We are refactoring a very large system and looking at many of the xQuery's we have written and wondering if using and including an xQuery that declares many global variables would not help.
But the question is for the architects ... are these loaded on reference or only loaded when used?
Meaning lets say I have some xQuery ... _global.xq like this:
module namespace g="global/variables";
declare variable $g:col.build := '/db/foo/data/Build';
declare variable $g:doc.langmap := doc(concat($g:col.build,'/','langmap.xml'));
declare variable $g:doc.easymap := doc(concat($g:col.build,'/','easymap.xml'));
declare variable $g:doc.foomap := doc(concat($g:col.build,'/','foomap.xml'));
And then I reference this in my xQuery:
import module namespace g='global/variables' at '_global.xq';
Then I use only $g:doc.langmap
in my xQuery. Are the other two ($g:doc.easymap
and $g:doc.foomap
) evaluated and loaded in memory also even though I do not use them?
Is $g:doc.langmap
populated on the import
or only when I actually use it in the query? Like if I write an xQuery that does not ever reference $g:doc.langmap
but imports that module, is it still created in memory and populated or not?
I wonder because if I have dozens of other declare variables in _global.xq
to be used in many, many other xQueries. And of course I do not use but only a few of the references in each. The question is then simple ... does the import module
command cause them all to be evaluated at the time of import, or do they only have values when they are used?
I suspect this will be a very short answer.