MDEV-30677: Incorrect result for "SELECT JSON_SCHEMA_VALID('{}', NULL)"

Analysis: null_value is not set if any one of the arguments is NULL. So it
returns 1.
Fix: when either argument is NULL, set null_value to true, so that null can
be returned
This commit is contained in:
Rucha Deodhar 2023-05-02 16:34:07 +05:30
parent 97675570ca
commit 4e5b771e98
4 changed files with 33 additions and 6 deletions

View file

@ -4704,4 +4704,16 @@ JSON_SCHEMA_VALID(json_object(), repeat('[', 10000000))
0
Warnings:
Warning 4040 Limit of 32 on JSON nested structures depth is reached in argument 2 to function 'json_schema_valid' at position 32
#
# MDEV-30677: Incorrect result for "SELECT JSON_SCHEMA_VALID('{}', NULL)"
#
SELECT JSON_SCHEMA_VALID('{}', NULL);
JSON_SCHEMA_VALID('{}', NULL)
NULL
SELECT JSON_SCHEMA_VALID(NULL, '{}');
JSON_SCHEMA_VALID(NULL, '{}')
NULL
SELECT JSON_SCHEMA_VALID(NULL, NULL);
JSON_SCHEMA_VALID(NULL, NULL)
NULL
# End of 11.1 test

View file

@ -3586,4 +3586,11 @@ SELECT JSON_SCHEMA_VALID(repeat('[', 100000), json_object());
SELECT JSON_SCHEMA_VALID(json_object(), repeat('[', 10000000));
--echo #
--echo # MDEV-30677: Incorrect result for "SELECT JSON_SCHEMA_VALID('{}', NULL)"
--echo #
SELECT JSON_SCHEMA_VALID('{}', NULL);
SELECT JSON_SCHEMA_VALID(NULL, '{}');
SELECT JSON_SCHEMA_VALID(NULL, NULL);
--echo # End of 11.1 test

View file

@ -4729,18 +4729,22 @@ longlong Item_func_json_schema_valid::val_int()
int is_valid= 1;
if (!schema_parsed)
{
null_value= 1;
return 0;
}
val= args[1]->val_json(&tmp_val);
if (!val)
{
null_value= 1;
return 0;
}
null_value= 0;
val= args[1]->val_json(&tmp_val);
if (!val || !val->length())
{
null_value= 0;
if (!val->length())
return 1;
}
json_scan_start(&ve, val->charset(), (const uchar *) val->ptr(),
(const uchar *) val->end());
@ -4799,7 +4803,10 @@ bool Item_func_json_schema_valid::fix_length_and_dec(THD *thd)
String *js= args[0]->val_json(&tmp_js);
if ((null_value= args[0]->null_value))
{
null_value= 1;
return 0;
}
json_scan_start(&je, js->charset(), (const uchar *) js->ptr(),
(const uchar *) js->ptr() + js->length());
if (!create_object_and_handle_keyword(thd, &je, &keyword_list,

View file

@ -807,6 +807,7 @@ public:
{
val= NULL;
schema_parsed= false;
set_maybe_null();
}
LEX_CSTRING func_name_cstring() const override
{