I believe there is a problem with the $q() function when globals are mapped in the global directory at the subscript level. Here's why.
I have two databases, which I'll call database A (DB-A) and database B (DB-B). They each contain a set of VistA FileMan files stored in a global named ^WEB, and the structure of these files is the same in both databases. We needed DB-B to look to DB-A for all nodes in ^WEB except for ^WEB(3309,*) and ^WEB(3315,*). For these two, DB-B needed to have its own local copy, which resulted in the following [partial] global directory layout for DB-B.
WEB WEB(3309) REG = DBA
SEG = DBA
FILE = /yottadb/dba/mumps.dat
WEB(3309) WEB(3309)++ REG = DEFAULT
SEG = DEFAULT
FILE = /yottadb/dbb/mumps.dat
WEB(3309)++ WEB(3315) REG = DBA
SEG = DBA
FILE = /yottadb/dba/mumps.dat
WEB(3315) WEB(3315)++ REG = DEFAULT
SEG = DEFAULT
FILE = /yottadb/dbb/mumps.dat
WEB(3315)++ WEBERROR REG = DBA
SEG = DBA
FILE = /yottadb/dba/mumps.dat
Here is a partial listing of ^WEB(3315,*) from DB-A:
DB-A>zwrite ^WEB(3315,*)
^WEB(3315,0)="Web System Profile^3315^19^18"
...snip...
^WEB(3315,"IP","
pdd17.mycompany.edu",15)=""
^WEB(3315,"IP","
wam.mycompany.edu",19)=""
Here is a partial listing of ^WEB(3315,*) in DB-B:
DB-B>zwrite ^WEB(3315,*)
^WEB(3315,0)="Web System Profile^3315^1^1"
...snip...
^WEB(3315,"IP","
wam.mycompany.edu",1)=""
Using $q() on this final node in DB-B should return null (or a node in ^WEB that has a first subscript that is greater than 3315). Instead, it is returning the next node in ^WEB(3315,*) from DB-A.
DB-B>w $q(^WEB(3315,"IP","
wam.mycompany.edu",1))
^WEB(3315,"IP","
wam.mycompany.edu",19)
But that node does not exist in DB-B.
DB-B>w ^WEB(3315,"IP","
wam.mycompany.edu",19)
%GTM-E-GVUNDEF, Global variable undefined: ^WEB(3315,"IP","
wam.mycompany.edu",19)
Put another way, I would never expect the following line of MUMPS code to fail under any circumstance, yet as you'll see, it does.
DB-B>s g=$na(^WEB(3315)) f s g=$q(@g) q:g="" s x=@g
%GTM-E-GVUNDEF, Global variable undefined: ^WEB(3315,"IP","
wam.mycompany.edu",19)