Bug #116634 | Inconsistent Comparison Behavior with JSON and Boolean Expressions | ||
---|---|---|---|
Submitted: | 12 Nov 2024 14:58 | Modified: | 13 Nov 2024 10:39 |
Reporter: | Wenqian Deng | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server | Severity: | S3 (Non-critical) |
Version: | 9.0 | OS: | Any |
Assigned to: | CPU Architecture: | Any |
[12 Nov 2024 14:58]
Wenqian Deng
[13 Nov 2024 10:39]
MySQL Verification Team
Hi Mr. Deng, Thank you for your bug report. However, this is not a bug. Here comes a full explanation why is this not a bug. Difference in your test case is that one comparison is between JSON and BOOLEAN , while in other it is between JSON and INT. Both of these are totally incompatible type combinations. Let us also inform you about the more important reasons of why this is not a bug. SQL standard is very strict that in both cases, According to SQL standard, MySQL should return a hard error, since SQL standard does not allow mixing of data types in any expression, including the comparisons. Hence, all relational databases should return a hard error, but most of them do not. Most of the databases try to accommodate user queries, although this is prohibited. Hence, MySQL does its best effort in each case. That means that in many cases, you would get inconsistent results. But, there is nothing we can do there since your attribute types and their values are completely incompatible. Comparing such vastly different domains may lead to anything ............ In case of JSON versus any other types, MySQL always tries to convert the other value into JSON, since JSON can not be converted into BOOLEAN nor to INT. Hence, when comparing with JSON, we recommend you to use the JSON_VALUE() function. That function and it's use is fully explained in our Reference Manual. Not a bug.