Skip to content

Commit

Permalink
fix: correctly handle null_frac in LIKE (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gun9niR committed May 1, 2024
1 parent cd9132c commit 182b052
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions optd-datafusion-repr/src/cost/base_cost/filter/like.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,15 @@ impl<
(0.0, 0.0)
};

// Postgres clamps the result after histogram and before MCV. See Postgres `patternsel_common`.
let result = ((non_mcv_sel + mcv_freq) * (1.0 - null_frac)).clamp(0.0001, 0.9999);
let result = non_mcv_sel + mcv_freq;

if like_expr.negated() {
1.0 - result - null_frac
} else {
result
}
// Postgres clamps the result after histogram and before MCV. See Postgres `patternsel_common`.
.clamp(0.0001, 0.9999)
} else {
UNIMPLEMENTED_SEL
}
Expand Down Expand Up @@ -170,13 +171,12 @@ mod tests {
)];
assert_approx_eq::assert_approx_eq!(
cost_model.get_like_selectivity(&like(0, "%abcd%", false), &column_refs),
(0.1 + FULL_WILDCARD_SEL_FACTOR.powi(2) * FIXED_CHAR_SEL_FACTOR.powi(4)) * null_frac
0.1 + FULL_WILDCARD_SEL_FACTOR.powi(2) * FIXED_CHAR_SEL_FACTOR.powi(4)
);
assert_approx_eq::assert_approx_eq!(
cost_model.get_like_selectivity(&like(0, "%abcd%", true), &column_refs),
1.0 - (0.1 + FULL_WILDCARD_SEL_FACTOR.powi(2) * FIXED_CHAR_SEL_FACTOR.powi(4))
* null_frac
- 0.5
- null_frac
);
}
}

0 comments on commit 182b052

Please sign in to comment.