add precondition to prevent bugs for nil query
insert query view doesn't have leftover tag
expand type to its tags in queries