optimization: memoize query construction using ets