Algorithm that designs aggregate tables