Commit graph

40 commits

Author SHA1 Message Date
Rucha Deodhar
a6f7c8edc9 MDEV-28762: recursive call of some json functions without stack control
Fixup to MDEV-28762. Fixes warnings about unused variable "stack_used_up"
during building with RelWithDebInfo
2022-07-29 15:58:38 +05:30
Rucha Deodhar
e94902c062 MDEV-28762: recursive call of some json functions without stack control
This commit is a fixup for MDEV-28762

Analysis: Some recursive json functions dont check for stack control
Fix: Add check_stack_overrun(). The last argument is NULL because it is not
used
2022-07-26 10:05:37 +05:30
Rucha Deodhar
0ea221e12b MDEV-28762: recursive call of some json functions without stack control
Analysis: Some recursive json functions dont check for stack control
Fix: Add check_stack_overrun(). The last argument is NULL because it is not
used
2022-07-20 19:37:29 +05:30
Rucha Deodhar
a61603562e MDEV-25875: JSON_TABLE: extract document fragment into JSON column
Fixup
2022-05-31 12:09:29 +05:30
Alexey Botchkov
a9f6abedde MDEV-25875: JSON_TABLE: extract document fragment into JSON column
Accept JSON values for the JSON fields.
2022-05-31 12:09:11 +05:30
Alexander Barkov
2a0962f39b MDEV-27696 Json table columns accept redundant COLLATE syntax 2022-01-31 21:18:43 +04:00
Monty
a206658b98 Change CHARSET_INFO character set and collaction names to LEX_CSTRING
This change removed 68 explict strlen() calls from the code.

The following renames was done to ensure we don't use the old names
when merging code from earlier releases, as using the new variables
for print function could result in crashes:
- charset->csname renamed to charset->cs_name
- charset->name renamed to charset->coll_name

Almost everything where mechanical changes except:
- Changed to use the new Protocol::store(LEX_CSTRING..) when possible
- Changed to use field->store(LEX_CSTRING*, CHARSET_INFO*) when possible
- Changed to use String->append(LEX_CSTRING&) when possible

Other things:
- There where compiler issues with ensuring that all character set names
  points to the same string: gcc doesn't allow one to use integer constants
  when defining global structures (constant char * pointers works fine).
  To get around this, I declared defines for each character set name
  length.
2021-05-19 22:54:07 +02:00
Monty
b6ff139aa3 Reduce usage of strlen()
Changes:
- To detect automatic strlen() I removed the methods in String that
  uses 'const char *' without a length:
  - String::append(const char*)
  - Binary_string(const char *str)
  - String(const char *str, CHARSET_INFO *cs)
  - append_for_single_quote(const char *)
  All usage of append(const char*) is changed to either use
  String::append(char), String::append(const char*, size_t length) or
  String::append(LEX_CSTRING)
- Added STRING_WITH_LEN() around constant string arguments to
  String::append()
- Added overflow argument to escape_string_for_mysql() and
  escape_quotes_for_mysql() instead of returning (size_t) -1 on overflow.
  This was needed as most usage of the above functions never tested the
  result for -1 and would have given wrong results or crashes in case
  of overflows.
- Added Item_func_or_sum::func_name_cstring(), which returns LEX_CSTRING.
  Changed all Item_func::func_name()'s to func_name_cstring()'s.
  The old Item_func_or_sum::func_name() is now an inline function that
  returns func_name_cstring().str.
- Changed Item::mode_name() and Item::func_name_ext() to return
  LEX_CSTRING.
- Changed for some functions the name argument from const char * to
  to const LEX_CSTRING &:
  - Item::Item_func_fix_attributes()
  - Item::check_type_...()
  - Type_std_attributes::agg_item_collations()
  - Type_std_attributes::agg_item_set_converter()
  - Type_std_attributes::agg_arg_charsets...()
  - Type_handler_hybrid_field_type::aggregate_for_result()
  - Type_handler_geometry::check_type_geom_or_binary()
  - Type_handler::Item_func_or_sum_illegal_param()
  - Predicant_to_list_comparator::add_value_skip_null()
  - Predicant_to_list_comparator::add_value()
  - cmp_item_row::prepare_comparators()
  - cmp_item_row::aggregate_row_elements_for_comparison()
  - Cursor_ref::print_func()
- Removes String_space() as it was only used in one cases and that
  could be simplified to not use String_space(), thanks to the fixed
  my_vsnprintf().
- Added some const LEX_CSTRING's for common strings:
  - NULL_clex_str, DATA_clex_str, INDEX_clex_str.
- Changed primary_key_name to a LEX_CSTRING
- Renamed String::set_quick() to String::set_buffer_if_not_allocated() to
  clarify what the function really does.
- Rename of protocol function:
  bool store(const char *from, CHARSET_INFO *cs) to
  bool store_string_or_null(const char *from, CHARSET_INFO *cs).
  This was done to both clarify the difference between this 'store' function
  and also to make it easier to find unoptimal usage of store() calls.
- Added Protocol::store(const LEX_CSTRING*, CHARSET_INFO*)
- Changed some 'const char*' arrays to instead be of type LEX_CSTRING.
- class Item_func_units now used LEX_CSTRING for name.

Other things:
- Fixed a bug in mysql.cc:construct_prompt() where a wrong escape character
  in the prompt would cause some part of the prompt to be duplicated.
- Fixed a lot of instances where the length of the argument to
  append is known or easily obtain but was not used.
- Removed some not needed 'virtual' definition for functions that was
  inherited from the parent. I added override to these.
- Fixed Ordered_key::print() to preallocate needed buffer. Old code could
  case memory overruns.
- Simplified some loops when adding char * to a String with delimiters.
2021-05-19 22:27:48 +02:00
Alexey Botchkov
502b769561 MDEV-17399 JSON_TABLE.
Aftermerge fixes.
2021-04-21 10:21:48 +04:00
Alexey Botchkov
41e368f22d MDEV-25149 JSON_TABLE: Inconsistency in implicit data type conversion.
Only return the error if field->store produced errors, not warnings.
2021-04-21 10:21:48 +04:00
Sergei Petrunia
0a09525625 MDEV-25202: JSON_TABLE: Early table reference leads to unexpected result set
Followup part#2: allocate the List object on the right mem-root, too.
2021-04-21 10:21:48 +04:00
Alexey Botchkov
a4353c25ca MDEV-25420 JSON_TABLE: ASAN heap-buffer-overflow in Protocol::net_store_data or consequent failur es.
fixed changed.
2021-04-21 10:21:48 +04:00
Sergei Petrunia
b0817ff8de MDEV-25202: JSON_TABLE: Early table reference leads to unexpected result set
Address review input: switch Name_resolution_context::ignored_tables from
table_map to a list of TABLE_LIST objects. The rationale is that table
bits may be changed due to query rewrites, etc, which may potentially
require updating ignored_tables.
2021-04-21 10:21:48 +04:00
Alexey Botchkov
91cd3c8f5b MDEV-25353 JSON_TABLE: Illegal mix of collations upon executing PS once, or SP/function twice.
Do not adapt to the argument charset anymore. Just use the utf8mb4 as
the default cherset.
2021-04-21 10:21:47 +04:00
Alexey Botchkov
277aa532f3 MDEV-25408 JSON_TABLE: AddressSanitizer CHECK failed in Binary_string::realloc_raw
We need to update default values if we change the column's charsets.
2021-04-21 10:21:47 +04:00
Alexey Botchkov
991bfebe8f MDEV-25379 JSON_TABLE: ERROR ON clauses are ignored if a column is not on select list.
If a field is not in the read set - read it in the local buffer anyway to check for errors.
2021-04-21 10:21:47 +04:00
Sergei Petrunia
1eda21be1f Code cleanup: thd->lex->current_select->context == s_lex here, so use s_lex 2021-04-21 10:21:47 +04:00
Sergei Petrunia
a96408092c MDEV-25397: JSON_TABLE: Unexpected ER_MIX_OF_GROUP_FUNC_AND_FIELDS
When doing name resolution, do the same what WHERE/ON clauses do:
they don't count in select_lex->non_agg_field_used().
2021-04-21 10:21:47 +04:00
Alexey Botchkov
f82947e48d MDEV-17399 JSON_TABLE.
atch to get rid of duplicating code of the Create_tmp_table.
2021-04-21 10:21:47 +04:00
Alexey Botchkov
a5b454f98a MDEV-25259 JSON_TABLE: Illegal mix of collations upon executing query with combination of charsets via view.
now the ::print printed too much. Limit it for fields with no CHARSET
possible.
2021-04-21 10:21:47 +04:00
Alexey Botchkov
a2ce788f02 MDEV-25259 JSON_TABLE: Illegal mix of collations upon executing query with combination of charsets via view.
The ::print method didn't print the explicitly specified charset.
2021-04-21 10:21:47 +04:00
Sergei Petrunia
6bac48d0cf MDEV-25381: JSON_TABLE: ER_WRONG_OUTER_JOIN upon query with LEFT and RIGHT joins and view
Table_function_json_table::m_dep_tables attempts to cache the value of
m_json->used_tables(), poorly. Remove the cache and use the value
directly.
2021-04-21 10:21:46 +04:00
Sergei Petrunia
4a10dd0253 MDEV-25380: JSON_TABLE: Assertion `join->best_read < double(1.797...) fails
The query used a subquery of this form:

SELECT ...
WHERE
   EXISTS( SELECT ...
           FROM JSON_TABLE(outer_ref, ..) as JT
           WHERE trivial_correlation_cond)

EXISTS-to-IN conversion code was unable to see that the subquery will
still be correlated after the trivial_correlation is removed, which
eventually caused a crash due to inability to construct a query plan.

Fixed by making Item_subselect::walk() also walk arguments of Table
Functions.
2021-04-21 10:21:46 +04:00
Sergei Petrunia
1be9c51beb MDEV-25202: JSON_TABLE: Early table reference leads to unexpected result set
- Address review input. No functional changes.
2021-04-21 10:21:45 +04:00
Sergei Petrunia
84cf9c2e11 MDEV-25202: JSON_TABLE: Early table reference leads to unexpected result set
(Also fixes MDEV-25254).
Re-work Name Resolution for the argument of JSON_TABLE(json_doc, ....)
function. The json_doc argument can refer to other tables, but it can
only refer to the tables that precede[*] the JSON_TABLE(...) call.

[*] - For queries with RIGHT JOINs, the "preceding" is determined after
the query is normalized by converting RIGHT JOIN into left one.

The implementation is as follows:
- Table function arguments use their own Name_resolution_context.

- The Name_resolution_context now has a bitmap of tables that should be
  ignored when searching for a field.

- get_disallowed_table_deps() walks the TABLE_LIST::nested_join tree
  and computes a bitmap of tables that do not "precede" the given
  JSON_TABLE(...) invocation  (according the above definition of
  "preceding").
2021-04-21 10:21:45 +04:00
Alexey Botchkov
13390a70e2 MDEV-25255 JSON_TABLE: CREATE TABLE ignores NULL ON ERROR (implicit or explicit) and fails.
should not abort on field::set().
2021-04-21 10:21:45 +04:00
Alexey Botchkov
d2e2219e46 MDEV-25146 JSON_TABLE: Non-descriptive + wrong error messages upon trying to store array or object.
More informative messages added.
Do not issue additional messages if already handled.
2021-04-21 10:21:45 +04:00
Alexey Botchkov
e2d5eb67a1 MDEV-25263 JSON_TABLE: json_table test fails with valgrind.
Field reset added.
2021-04-21 10:21:45 +04:00
Alexey Botchkov
0cea1ea7d3 MDEV-25183 JSON_TABLE: CREATE VIEW involving NESTED PATH ends up with invalid frm.
calling members of NULL object crashes on some platforms.
2021-04-21 10:21:44 +04:00
Alexey Botchkov
3edc4a0998 MDEV-25229 SON_TABLE: Server crashes in hton_name upon MATCH .. AGAINST.
No plugin for the JSON_TABLE so get the storage type name directly.
2021-04-21 10:21:44 +04:00
Alexey Botchkov
6a5f86bf59 MDEV-25230 JSON_TABLE: CREATE VIEW with 2nd level NESTED PATH ends up with invalid frm, Assertion `m_status == DA_ERROR || m_status == DA_OK || m_status == DA_OK_BULK' failed.
Handle multiple NESTED paths.
2021-04-21 10:21:44 +04:00
Alexey Botchkov
46d592a047 MDEV-25188 JSON_TABLE: ASAN use-after-poison in Field_long::reset / Table_function_json_table::setup or malloc(): invalid size.
MDEV-25192 JSON_TABLE: ASAN use-after-poison in field_conv_memcpy / Create_tmp_table::finalize upon query with derived table.
2021-04-21 10:21:44 +04:00
Alexey Botchkov
90c4dff5ab MDEV-25178 JSON_TABLE: ASAN use-after-poison in my_fill_8bit Json_table_column::On_response::respond.
table record buffer size was smaller than required when the charset
changes.
2021-04-21 10:21:44 +04:00
Alexey Botchkov
6f56458a76 MDEV-25183 JSON_TABLE: CREATE VIEW involving NESTED PATH ends up with invalid frm.
Wrong comma was added after the single column.
2021-04-21 10:21:44 +04:00
Alexey Botchkov
51ac57fbbe MDEV-25151 JSON_TABLE: Unexpectedly padded values in a PATH column.
Field length can increase after the change_charset(), so need to
set field->ptr properly.

also sensitive parts of the test moved to json_not_embedded.test.
2021-04-21 10:21:44 +04:00
Alexey Botchkov
abdc39b0a7 MDEV-25143 JSON_TABLE: Server crashes in handler::print_error / hton_name upon ERROR ON EMPTY.
should return some error code from ha_json_table::rnd_pos() not just 1.
2021-04-21 10:21:44 +04:00
Sergei Petrunia
98556ef84a MDEV-25142: JSON_TABLE: CREATE VIEW involving EXISTS PATH ends up with invalid frm 2021-04-21 10:21:43 +04:00
Sergei Petrunia
93daad3a1e MDEV-17399: JSON_TABLE: cleanup table dependency code
- Don't touch simplify_joins()
- All dependencies caused by JSON_TABLE(...) are now added by
  add_table_function_dependencies().
2021-04-21 10:21:43 +04:00
Sergei Petrunia
2f650fb955 MDEV-17399: JSON_TABLE: Fix the problem with cross-nested-join dependency
Fix for for the problem with
- Cross-outer-join dependency
- dead-end join prefix
- join order pruning

See the comments in the patch for detailed description
2021-04-21 10:21:43 +04:00
Alexey Botchkov
e9fd327ee3 MDEV-17399 Add support for JSON_TABLE.
The specific table handler for the table functions was introduced,
and used to implement JSON_TABLE.
2021-04-21 10:21:43 +04:00