public double?EstSelectivity(string op, Value val) { int whichValue(Value val) => Array.IndexOf(values_, val); if (!new List <String>() { "=", ">", ">=", "<", "<=" }.Contains(op)) { return(null); } if (op == "=") { int which = whichValue(val); if (which == -1) { return(otherfreq_); } return(freqs_[which]); } double selectivity = calcTotalFreq(val, op); Estimator.validateSelectivity(selectivity); return(selectivity); }
public double EstSelectivity(string op, Value val) { if (!new List <String>() { "=", ">", ">=", "<", "<=" }.Contains(op)) { return(StatConst.sel_one); } int which = whichValue(val); if (which == -1) { return(StatConst.sel_zero); } double selectivity = 0.0; switch (op) { case "=": selectivity = freqs_[which]; break; case ">": case ">=": int start = which; for (int i = start; i < nvalues_; i++) { selectivity += freqs_[i]; } break; case "<": case "<=": int end = which; for (int i = 0; i <= end; i++) { selectivity += freqs_[i]; } break; } if (selectivity == 0) { selectivity = StatConst.sel_zero; } Estimator.validateSelectivity(selectivity); return(selectivity); }
public double EstSelectivity(string op, Value val) { double selectivity = StatConst.sel_one; if (!new List <String>() { "=", ">", ">=", "<", "<=" }.Contains(op)) { return(selectivity); } int which = whichBucket(val); switch (op) { case "=": selectivity = 1.0 / (nbuckets_ * distincts_[which]); break; case ">": case ">=": selectivity = 1.0 * (nbuckets_ - which) / nbuckets_; break; case "<": case "<=": selectivity = 1.0 * which / nbuckets_; break; } if (selectivity == 0) { selectivity = StatConst.sel_zero; } Estimator.validateSelectivity(selectivity); return(selectivity); }
public double EstSelectivity(string op, Value val) { var selectivity = StatConst.one_; if (op == "like") { selectivity = EstLikeSelectivity(val); } else if (!new List <String>() { "=", ">", ">=", "<", "<=" }.Contains(op)) { selectivity = StatConst.one_; } else { if (mcv_ is null) { if (hist_ is null) { selectivity = StatConst.one_; } else if (op == "=") // unique { selectivity = 1.0 / n_rows_; } else { selectivity = hist_.EstSelectivity(op, val) ?? StatConst.one_; } } else { if (op == "=") { selectivity = mcv_.EstSelectivity(op, val) ?? StatConst.one_; } else { var mcvest = mcv_.EstSelectivity(op, val); var histest = hist_?.EstSelectivity(op, val); if (mcvest is null) { // only use histgram if avaliable selectivity = hist_ is null ? StatConst.one_ : (histest ?? StatConst.one_); } else { if (histest is null) { selectivity = (double)mcvest; } else { selectivity = (double)mcvest + ((1 - mcv_.totalfreq_) * ((double)histest)); } } } } } Estimator.validateSelectivity(selectivity); return(selectivity); }
public double?EstSelectivity(string op, Value val) { // return the selectivity respect to only the histogram double selectivity = StatConst.one_; Debug.Assert(new List <String>() { ">", ">=", "<", "<=" }.Contains(op)); int which = whichBucketLargerThan(val); switch (op) { case ">": case ">=": if (which == 0) { selectivity = 1.0; } else if (which == nbuckets_ + 1) { selectivity = 0.0; } else { var basefraction = nbuckets_ - which; var deltadjust = 0.0; // for non-string data, we can further adjust within the bucket fraction by assuming // data are continuous within the bucket if (!(val is string)) { deltadjust = 1.0 - getFraction(buckets_[which - 1], buckets_[which], val); } selectivity = (basefraction + deltadjust) / nbuckets_; } break; case "<": case "<=": if (which == 0) { selectivity = 0.0; } else if (which == nbuckets_ + 1) { selectivity = 1.0; } else { var basefraction = which; var deltadjust = 0.0; if (!(val is string)) { deltadjust = 1.0 - getFraction(buckets_[which - 1], buckets_[which], val); } selectivity = (basefraction - deltadjust) / nbuckets_; } break; } Estimator.validateSelectivity(selectivity); return(selectivity); }