Bug 1068752 - Use artinsal SQL queries to speed up data retrieval

we need only generate the where condition string once.