rima.lua: try minimize number of selects per procedure call