Skip to content

Instantly share code, notes, and snippets.

@RhodiumToad
Created July 1, 2013 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RhodiumToad/5901567 to your computer and use it in GitHub Desktop.
Save RhodiumToad/5901567 to your computer and use it in GitHub Desktop.
suggested fix for boolean selectivity
diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c
index da66f34..4e8f3f2 100644
--- a/src/backend/utils/adt/selfuncs.c
+++ b/src/backend/utils/adt/selfuncs.c
@@ -1549,11 +1549,17 @@ booltestsel(PlannerInfo *root, BoolTestType booltesttype, Node *arg,
selec = 1.0 - freq_null;
break;
case IS_TRUE:
- case IS_NOT_TRUE:
case IS_FALSE:
- case IS_NOT_FALSE:
selec = (1.0 - freq_null) / 2.0;
break;
+ case IS_NOT_TRUE:
+ case IS_NOT_FALSE:
+ /*
+ * include the null values plus half of the non-null ones.
+ * equiv. to freq_null + (1.0 - freq_null)/2.0
+ */
+ selec = (freq_null + 1.0) / 2.0;
+ break;
default:
elog(ERROR, "unrecognized booltesttype: %d",
(int) booltesttype);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment