db: thread check, handle empty or * queries