Selectivity and Cost Estimation for Joins Based on Random Sampling