Reorder length check to potentially fix an empty-query bug.