Add query->cleanCopy().

I found a few duplicated blocks of code related to clearing query state when subqueries are created. Having a function will help prevent code getting out of sync in the future.