SQL result set construction