query using composite database giving a memory error