mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
Merge 10.8 into 10.9
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2016, 2020, MariaDB Corporation.
|
||||
/* Copyright (c) 2016, 2022, MariaDB Corporation.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -1864,132 +1864,6 @@ int json_get_path_next(json_engine_t *je, json_path_t *p)
|
||||
}
|
||||
|
||||
|
||||
int json_path_parts_compare(
|
||||
const json_path_step_t *a, const json_path_step_t *a_end,
|
||||
const json_path_step_t *b, const json_path_step_t *b_end,
|
||||
enum json_value_types vt, const int *array_sizes)
|
||||
{
|
||||
int res, res2;
|
||||
const json_path_step_t *temp_b= b;
|
||||
|
||||
while (a <= a_end)
|
||||
{
|
||||
if (b > b_end)
|
||||
{
|
||||
while (vt != JSON_VALUE_ARRAY &&
|
||||
(a->type & JSON_PATH_ARRAY_WILD) == JSON_PATH_ARRAY &&
|
||||
a->n_item == 0)
|
||||
{
|
||||
if (++a > a_end)
|
||||
return 0;
|
||||
}
|
||||
return -2;
|
||||
}
|
||||
|
||||
DBUG_ASSERT((b->type & (JSON_PATH_WILD | JSON_PATH_DOUBLE_WILD)) == 0);
|
||||
|
||||
if (a->type & JSON_PATH_ARRAY)
|
||||
{
|
||||
if (b->type & JSON_PATH_ARRAY)
|
||||
{
|
||||
int res= 0, corrected_n_item_a= 0;
|
||||
if (array_sizes)
|
||||
corrected_n_item_a= a->n_item < 0 ?
|
||||
array_sizes[b-temp_b] + a->n_item : a->n_item;
|
||||
if (a->type & JSON_PATH_ARRAY_RANGE)
|
||||
{
|
||||
int corrected_n_item_end_a= 0;
|
||||
if (array_sizes)
|
||||
corrected_n_item_end_a= a->n_item_end < 0 ?
|
||||
array_sizes[b-temp_b] + a->n_item_end :
|
||||
a->n_item_end;
|
||||
res= b->n_item >= corrected_n_item_a &&
|
||||
b->n_item <= corrected_n_item_end_a;
|
||||
}
|
||||
else
|
||||
res= corrected_n_item_a == b->n_item;
|
||||
|
||||
if ((a->type & JSON_PATH_WILD) || res)
|
||||
goto step_fits;
|
||||
goto step_failed;
|
||||
}
|
||||
if ((a->type & JSON_PATH_WILD) == 0 && a->n_item == 0)
|
||||
goto step_fits_autowrap;
|
||||
goto step_failed;
|
||||
}
|
||||
else /* JSON_PATH_KEY */
|
||||
{
|
||||
if (!(b->type & JSON_PATH_KEY))
|
||||
goto step_failed;
|
||||
|
||||
if (!(a->type & JSON_PATH_WILD) &&
|
||||
(a->key_end - a->key != b->key_end - b->key ||
|
||||
memcmp(a->key, b->key, a->key_end - a->key) != 0))
|
||||
goto step_failed;
|
||||
|
||||
goto step_fits;
|
||||
}
|
||||
step_failed:
|
||||
if (!(a->type & JSON_PATH_DOUBLE_WILD))
|
||||
return -1;
|
||||
b++;
|
||||
continue;
|
||||
|
||||
step_fits:
|
||||
b++;
|
||||
if (!(a->type & JSON_PATH_DOUBLE_WILD))
|
||||
{
|
||||
a++;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Double wild handling needs recursions. */
|
||||
res= json_path_parts_compare(a+1, a_end, b, b_end, vt,
|
||||
array_sizes ? array_sizes + (b - temp_b) :
|
||||
NULL);
|
||||
if (res == 0)
|
||||
return 0;
|
||||
|
||||
res2= json_path_parts_compare(a, a_end, b, b_end, vt,
|
||||
array_sizes ? array_sizes + (b - temp_b) :
|
||||
NULL);
|
||||
|
||||
return (res2 >= 0) ? res2 : res;
|
||||
|
||||
step_fits_autowrap:
|
||||
if (!(a->type & JSON_PATH_DOUBLE_WILD))
|
||||
{
|
||||
a++;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Double wild handling needs recursions. */
|
||||
res= json_path_parts_compare(a+1, a_end, b+1, b_end, vt,
|
||||
array_sizes ? array_sizes + (b - temp_b) :
|
||||
NULL);
|
||||
if (res == 0)
|
||||
return 0;
|
||||
|
||||
res2= json_path_parts_compare(a, a_end, b+1, b_end, vt,
|
||||
array_sizes ? array_sizes + (b - temp_b) :
|
||||
NULL);
|
||||
|
||||
return (res2 >= 0) ? res2 : res;
|
||||
|
||||
}
|
||||
|
||||
return b <= b_end;
|
||||
}
|
||||
|
||||
|
||||
int json_path_compare(const json_path_t *a, const json_path_t *b,
|
||||
enum json_value_types vt, const int *array_size)
|
||||
{
|
||||
return json_path_parts_compare(a->steps+1, a->last_step,
|
||||
b->steps+1, b->last_step, vt, array_size);
|
||||
}
|
||||
|
||||
|
||||
static enum json_types smart_read_value(json_engine_t *je,
|
||||
const char **value, int *value_len)
|
||||
{
|
||||
|
Reference in New Issue
Block a user