merge_tables function for merging tables according to broadcasts.