fix a crasher when running in threaded mode, also add support for $onlycount query hint.