haggholm: (Default)
[personal profile] haggholm

Please help me. MySQL is telling me that in a given join, there are roughly (but not exactly) twice as many values that are either true or false, as the sum of the number of values that are true, and the number of values that are false. This quite defies my notions of Boolean logic.

SELECT COUNT(*)
    FROM current_res_ents
    INNER JOIN current_applicants
    ON check_requirements(r_id, p_id)=TRUE;
+----------+
| count(*) |
+----------+
|     3997 |
+----------+
1 row in set (5.13 sec)

SELECT COUNT(*)
    FROM current_res_ents
    INNER JOIN current_applicants
    ON check_requirements(r_id, p_id)=FALSE;
+----------+
| count(*) |
+----------+
|     3348 |
+----------+
1 row in set (3.27 sec)

SELECT COUNT(*)
    FROM current_res_ents
    INNER JOIN current_applicants
    ON check_requirements(r_id, p_id) IN (TRUE,FALSE);
+----------+
| count(*) |
+----------+
|    14677 |
+----------+
1 row in set (6.58 sec)

Never mind the internals of the function in question—how is this logically possible?

Update: It turns out that if I rewrite the query with a WHERE clause instead of the ON condition, the result is…exactly the same; if, however, I rewrite it to filter the results with a HAVING clause, it gives the expected results, where one plus one equals two instead of approximately four. I have no idea why.

Profile

haggholm: (Default)
Petter Häggholm

July 2025

S M T W T F S
  12 345
6789101112
13141516171819
20212223242526
2728293031  

Most Popular Tags