diff --git a/mysql-test/main/json_debug_nonembedded.result b/mysql-test/main/json_debug_nonembedded.result index da4ea54e30c..313dc2c1eb4 100644 --- a/mysql-test/main/json_debug_nonembedded.result +++ b/mysql-test/main/json_debug_nonembedded.result @@ -4,8 +4,8 @@ # SET @saved_dbug = @@debug_dbug; SET debug_dbug='+d,json_check_min_stack_requirement'; -SET @json1= '{"key1":"val1"}'; -SET @json2= '{"key1":"val1"}'; +SET @json1= '{"key1":{"key1":"val1"}}'; +SET @json2= '{"key1":{"key1":"val1"}}'; SELECT JSON_CONTAINS(@json1, @json2); ERROR HY000: Thread stack overrun: 'used bytes' used of a 'available' byte stack, and 'X' bytes needed. Use 'mysqld --thread_stack=#' to specify a bigger stack SET debug_dbug='+d,temp'; diff --git a/mysql-test/main/json_debug_nonembedded.test b/mysql-test/main/json_debug_nonembedded.test index 1fbbc05f3b2..021abd8c602 100644 --- a/mysql-test/main/json_debug_nonembedded.test +++ b/mysql-test/main/json_debug_nonembedded.test @@ -9,8 +9,8 @@ SET @saved_dbug = @@debug_dbug; SET debug_dbug='+d,json_check_min_stack_requirement'; -SET @json1= '{"key1":"val1"}'; -SET @json2= '{"key1":"val1"}'; +SET @json1= '{"key1":{"key1":"val1"}}'; +SET @json2= '{"key1":{"key1":"val1"}}'; --replace_regex /overrun: [0-9]* bytes used of a [0-9]* byte stack, and [0-9]* bytes needed/overrun: 'used bytes' used of a 'available' byte stack, and 'X' bytes needed/ --error ER_STACK_OVERRUN_NEED_MORE diff --git a/sql/item_jsonfunc.cc b/sql/item_jsonfunc.cc index ff6013d5eb6..b502db0d867 100644 --- a/sql/item_jsonfunc.cc +++ b/sql/item_jsonfunc.cc @@ -20,7 +20,6 @@ #include "item.h" #include "sql_parse.h" // For check_stack_overrun - /* Compare ASCII string against the string with the specified character set. @@ -136,9 +135,11 @@ int json_path_parts_compare( { int res, res2; + long arbitrary_var; + long stack_used_up= (available_stack_size(current_thd->thread_stack, &arbitrary_var)); DBUG_EXECUTE_IF("json_check_min_stack_requirement", - {alloca(my_thread_stack_size-(STACK_MIN_SIZE));}); - if (check_stack_overrun(current_thd, STACK_MIN_SIZE, NULL)) + {alloca(my_thread_stack_size-stack_used_up-STACK_MIN_SIZE);}); + if (check_stack_overrun(current_thd, STACK_MIN_SIZE , NULL)) return 1; while (a <= a_end) { @@ -1135,6 +1136,12 @@ static int check_contains(json_engine_t *js, json_engine_t *value) { json_engine_t loc_js; bool set_js; + long arbitrary_var; + long stack_used_up= (available_stack_size(current_thd->thread_stack, &arbitrary_var)); + DBUG_EXECUTE_IF("json_check_min_stack_requirement", + {alloca(my_thread_stack_size-stack_used_up-STACK_MIN_SIZE);}); + if (check_stack_overrun(current_thd, STACK_MIN_SIZE , NULL)) + return 1; DBUG_EXECUTE_IF("json_check_min_stack_requirement", {alloca(my_thread_stack_size-(STACK_MIN_SIZE));}); @@ -2030,10 +2037,12 @@ err_return: static int do_merge(String *str, json_engine_t *je1, json_engine_t *je2) { + long arbitrary_var; + long stack_used_up= (available_stack_size(current_thd->thread_stack, &arbitrary_var)); DBUG_EXECUTE_IF("json_check_min_stack_requirement", - {alloca(my_thread_stack_size-(STACK_MIN_SIZE));}); - if (check_stack_overrun(current_thd, STACK_MIN_SIZE, NULL)) - return 1; + {alloca(my_thread_stack_size-stack_used_up-STACK_MIN_SIZE);}); + if (check_stack_overrun(current_thd, STACK_MIN_SIZE , NULL)) + return 1; if (json_read_value(je1) || json_read_value(je2)) return 1; @@ -2367,9 +2376,11 @@ static int copy_value_patch(String *str, json_engine_t *je) static int do_merge_patch(String *str, json_engine_t *je1, json_engine_t *je2, bool *empty_result) { + long arbitrary_var; + long stack_used_up= (available_stack_size(current_thd->thread_stack, &arbitrary_var)); DBUG_EXECUTE_IF("json_check_min_stack_requirement", - {alloca(my_thread_stack_size-(STACK_MIN_SIZE));}); - if (check_stack_overrun(current_thd, STACK_MIN_SIZE, NULL)) + {alloca(my_thread_stack_size-stack_used_up-STACK_MIN_SIZE);}); + if (check_stack_overrun(current_thd, STACK_MIN_SIZE , NULL)) return 1; if (json_read_value(je1) || json_read_value(je2))