Optimize inbox SQL queries

construct_inbox_row_count_sql ?