Optimal method to retrieve Lookup Data

I am having a document that contains all my lookup data ( I mean by lookup data, those having ID/Name fields only). For example, I have



Additionally, I have a Element in my Employees.xml document that references the element in .

The problem is that I am having a lot of those lookup data referenced in my Employees document (Bank, Department, …etc.) . Therefore, when I perform my xquery, and add so many statements in my FLWR statement, lots of tuples are generated and thus the query would become tremendously slow. I am talking about Employees.xml containing 300 record (Element). So the data inside my xml file is not many, and the indeces are set on each of the reference keys (BankID and DepartmentID…) inside my Employees Document.

The question:
What is the optimal method to refernce Lookup Data from within an XQuery FLWR Statement? Should I use XPointer?
Please Suggest.

Just to make sure, you’re worried about the performance of a query like this:

for $bank in input()/banks/bank, $employee in input()/employees/employee
where $bank/ID = $employee/BankID
return <emp-with-bank>{$employee/name, $bank/name}</emp-with-bank>

Is that right?

The main way to make sure a query like this runs efficiently is to properly define the indices in your schema. In particular, if you have defined both /banks/bank/ID and /employees/employee/BankID as standard indices, then Tamino will not in fact generate any unnecessary tuples at execution time.