causing odd caching issues when the selected object was not statically
known (eg unreferenced tables could show up in the query if they were
cached by a previous call through this function. I replaced this code
with a non-destructive variant which should solve this.