Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correctly handle null_frac in LIKE #179

Merged
merged 1 commit into from
May 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
);
}
}
Loading