the tcl code is executed and when database calls are made the query
dispatcher substitutes the query from the .xql file
and if it does not find anything to substitute it will use the
query you see in the .tcl file. This is how it supports
multiple databases. Ultimately I think the intent is to remove the
query text from the tcl files (although I don't know when that will
happen).
You can read more in this thread...
https://openacs.org/bboard/q-and-a-fetch-msg.tcl?msg_id=0005OL&topic_id=12