optimise counting expression
fetch typeval using database instead of DAO

extension DAO does not expose an extension's typeval