Repository navigation
Description
Description
MatrixOne's function parameter validation is overly strict in some boundary cases, causing valid boundary values to be rejected with "invalid argument" errors. This affects various functions including mathematical functions, type conversion functions, and string functions.
Error Messages
Multiple error patterns observed:
ERROR 20203 (HY000): invalid argument ln, bad value 0
ERROR 20203 (HY000): invalid argument cast to int, bad value <value>
ERROR 20203 (HY000): invalid argument Sqrt, bad value -1
Affected Cases
This issue affects 13 test cases from our boundary testing on the industry_radar_test database.
Failing SQL Statements
Example 1: Mathematical Function with Boundary Value
SELECT SQRT(POWER(2, 100)) as nested_math, EXP(LOG(0)) as exp_log_zero;Error: ERROR 20203 (HY000): invalid argument ln, bad value 0
Issue: LOG(0) is mathematically undefined, but the error handling could be improved to return NULL or a more descriptive error.
Example 2: Type Conversion with Invalid String
SELECT CAST('invalid' AS INT) as cast_invalid_int, CAST('invalid' AS DATE) as cast_invalid_date;Error: ERROR 20203 (HY000): invalid argument cast to int, bad value invalid
Issue: Invalid type conversion should return a more descriptive error message indicating which conversion failed.
Example 3: CASE WHEN with Mixed Types
SELECT CASE WHEN id > 0 THEN 'string' WHEN id > 100 THEN 123 ELSE 'mixed' END as case_mixed
FROM company LIMIT 10;Error: ERROR 20203 (HY000): invalid argument cast to int, bad value string
Issue: CASE WHEN with mixed return types should either be supported (with type coercion) or provide a clearer error message.
Example 4: COALESCE with Mixed Types
SELECT COALESCE(NULL, 1, 'string', 1.5) as mixed_types;Error: ERROR 20203 (HY000): invalid argument cast to int, bad value string
Issue: COALESCE with mixed types should handle type coercion or provide clearer error messages.
Example 5: UNION with Type Mismatch
SELECT id FROM company UNION SELECT full_name FROM company LIMIT 10;Error: ERROR 20203 (HY000): invalid argument cast to int, bad value <company_name>
Issue: UNION with incompatible types should provide a clearer error message about type mismatch.
Example 6: Date Functions with NULL
SELECT YEAR(NULL) as year_null, MONTH(NULL) as month_null, DAY(NULL) as day_null;Error: ERROR 20203 (HY000): invalid argument ln, bad value 0
Issue: Date functions with NULL should return NULL, not an error.
Example 7: WHERE Condition with Integer Overflow
SELECT * FROM company WHERE id + 2147483647 = 0;Error: ERROR 20203 (HY000): invalid argument cast to int, bad value string
Issue: Integer overflow in WHERE conditions should be handled gracefully.
Expected Behavior
- Mathematical Functions: Functions like LOG(0) should return NULL or a more descriptive error
- Type Conversion: Invalid conversions should provide clear error messages indicating the source and target types
- Mixed Types: CASE WHEN and COALESCE should handle type coercion or provide clear type mismatch errors
- NULL Handling: Functions should properly handle NULL values (return NULL) rather than throwing errors
- Type Mismatch: UNION and other operations with type mismatches should provide clear error messages
Impact
- User Experience: Error messages are not descriptive enough to help users understand what went wrong
- MySQL Compatibility: Some valid MySQL queries fail with unclear errors
- Debugging: Difficult to debug issues due to generic error messages
- Functionality: Some boundary cases that should work (like NULL handling) fail unexpectedly
Test Context
This issue was discovered during boundary testing using the industry_radar_test database. The test cases covered:
- Mathematical function boundary values
- Type conversion boundary cases
- NULL value handling
- Type mixing scenarios
- Integer overflow cases
Suggested Fix
-
Improve Error Messages: Provide more descriptive error messages that indicate:
- Which function/operation failed
- What the problematic value was
- What the expected type/range was
- Suggestions for fixing the issue
-
NULL Handling: Ensure all functions properly handle NULL values:
- Date functions with NULL should return NULL
- Mathematical functions with NULL should return NULL
- Type conversion with NULL should return NULL
-
Type Coercion: Consider supporting type coercion in:
- CASE WHEN expressions
- COALESCE expressions
- UNION operations (with clear rules)
-
Boundary Value Handling: Improve handling of:
- Mathematical boundary values (LOG(0), SQRT(-1))
- Integer overflow cases
- Type conversion edge cases
-
Error Classification: Distinguish between:
- True errors (invalid input)
- Boundary cases (should return NULL or special value)
- Type mismatches (should provide clear guidance)
Activity
VioletQwQ-0 commentedon May 22, 2026
fixed by #24519