CONTRIB-1698 fix uniqueness in get_records_sql