fixed bug when a function has alias. added query2