Commit graph

35 commits

Author SHA1 Message Date
Robin Newhouse
dc38d8ea80 Minimize unsafe C functions with safe_strcpy()
Similar to #2480.
567b681 introduced safe_strcpy() to minimize the use of C with
potentially unsafe memory overflow with strcpy() whose use is
discouraged.
Replace instances of strcpy() with safe_strcpy() where possible, limited
here to files in the `sql/` directory.

All new code of the whole pull request, including one or several files
that are either new files or modified ones, are contributed under the
BSD-new license. I am contributing on behalf of my employer
Amazon Web Services, Inc.
2024-05-17 13:33:16 +01:00
Marko Mäkelä
09205a1c9a Merge 10.4 into 10.5 2021-11-16 14:26:13 +02:00
Sergei Krivonos
e9b76b896a MDEV-23766: fix by my_json_writer test 2021-11-09 12:06:49 +02:00
Sergei Petrunia
5e988ff80f MDEV-23766: Make Json_writer assert when one tries to author invalid JSON
- Add unit test.
2021-11-09 12:06:49 +02:00
Sergei Petrunia
c9b5b9321f MDEV-23766: Make Json_writer assert when one tries to author invalid JSON
Code cleanup: Remove Json_writer::is_on_fmt_helper_call. We already
maintain this state in fmt_helper.
2021-11-09 12:06:49 +02:00
Sergei Krivonos
b17576322b MDEV-23766: add Json_writer consistency asserts to check array/object sequence 2021-11-09 12:06:49 +02:00
Sergei Krivonos
052dda61bb Made optional Json_writer_object / Json_writer_array consistency check 2021-10-17 13:20:49 +03:00
Sergei Krivonos
cf8e78a401 Implemented Json_writer_array & Json_writer_object subitems name presence control 2021-10-16 02:35:16 +03:00
Marko Mäkelä
1a4846dedc MDEV-22690 MSAN use-of-uninitialized-value in optimizer_trace
This was actually fixed in commit e843033d02
and all that we need to do is to remove an unnecessary work-around.
2020-07-01 16:11:58 +03:00
Monty
27d9986c1b Added more digits to JSON output of double
sprintf() format of double changed from '%lg' to '%-.11lg'

The change was to make it easier to read optimizer trace output
with tables that has millions of records.
2020-04-19 17:33:52 +03:00
Marko Mäkelä
94d0bb4dbe MDEV-20377: Make WITH_MSAN more usable
MemorySanitizer (clang -fsanitize=memory) requires that all code
be compiled with instrumentation enabled. The C runtime library
is an exception. Failure to use instrumented libraries will cause
bogus messages about memory being uninitialized.

In WITH_MSAN builds, we must avoid calling getservbyname(),
because even though it is a standard library function, it is
not instrumented, not even in clang 10.

The following cmake options were tested:

-DCMAKE_C_FLAGS='-march=native -O2'
-DCMAKE_CXX_FLAGS='-stdlib=libc++ -march=native -O2'
-DWITH_EMBEDDED_SERVER=OFF -DWITH_UNIT_TESTS=OFF -DCMAKE_BUILD_TYPE=Debug
-DWITH_INNODB_{BZIP2,LZ4,LZMA,LZO,SNAPPY}=OFF
-DPLUGIN_{ARCHIVE,TOKUDB,MROONGA,OQGRAPH,ROCKSDB,CONNECT,SPIDER}=NO
-DWITH_SAFEMALLOC=OFF
-DWITH_{ZLIB,SSL,PCRE}=bundled
-DHAVE_LIBAIO_H=0
-DWITH_MSAN=ON

MEM_MAKE_DEFINED(): An alias for VALGRIND_MAKE_MEM_DEFINED()
and in the future, __msan_unpoison().

For now, neither MEM_MAKE_DEFINED() nor MEM_UNDEFINED()
perform any action under MSAN. Enabling them will catch more bugs, but
will also require some more fixes or work-arounds.

Json_writer::add_double(): Work around a frequently occurring
failure in optimizer tests, related to EXPLAIN FORMAT=JSON.

dtoa(): Disable MSAN altogether. For some reason, this function
is triggering a lot of trouble, especially when invoked for
DBUG functions. The MDL default timeout is dd=86400 seconds,
and for some reason it is claimed to be uninitialized.

InnoDB: Define UNIV_DEBUG_VALGRIND also WITH_MSAN.

ut_crc32_8_hw(), ut_crc32_64_low_hw(): Use the compiler built-in
functions instead of inline assembler when building WITH_MSAN.
This will require at least -msse4.2 when building for IA-32 or AMD64.
The inline assembler would not be instrumented, and would thus cause
bogus failures.
2020-03-28 21:36:30 +02:00
Monty
a24d0926b9 Second stage of optimizer_trace optimizations
- Move testing of my_writer to inline functions to avoid calls
- Made more functions inline. Especially thd->thread_started()
  is now very optimized!
- Moved Opt_trace_stmt classe to opt_trace_context.h to get critical
  functions inline
2020-03-09 13:52:40 +02:00
Monty
940fcbe73b Improved speed of optimizer trace
- Added unlikely() to optimize for not having optimizer trace enabled
- Made THD::trace_started() inline
- Added 'if (trace_enabled())' around some potentially expensive code
  (not many found)
- Added ASSERT's to ensure we don't call expensive optimizer trace calls
  if optimizer trace is not enabled
- Added length to Json_writer functions to speed up buffer writes
  when optimizer trace is enabled.
- Changed LEX_CSTRING argument handling to not send full struct to writer
  function on_add_str() functions now trusts length arguments
2020-03-09 13:49:06 +02:00
Oleksandr Byelkin
f66d1850ac Merge branch '10.3' into 10.4 2019-06-14 22:10:50 +02:00
Oleksandr Byelkin
4a3d51c76c Merge branch '10.2' into 10.3 2019-06-14 07:36:47 +02:00
Oleksandr Byelkin
5b65d61d93 Merge branch '5.5' into 10.1 2019-06-12 22:54:46 +02:00
Oleksandr Byelkin
c07325f932 Merge branch '10.3' into 10.4 2019-05-19 20:55:37 +02:00
Marko Mäkelä
be85d3e61b Merge 10.2 into 10.3 2019-05-14 17:18:46 +03:00
Vicențiu Ciorbaru
cb248f8806 Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
Varun Gupta
9cb55143ac Minor cleanup in the optimizer trace code.
More test coverage added for the optimizer trace.
2019-02-18 17:11:20 +05:30
Varun Gupta
be8709eb7b MDEV-6111 Optimizer Trace
This task involves the implementation for the optimizer trace.

This feature produces a trace for any SELECT/UPDATE/DELETE/,
which contains information about decisions taken by the optimizer during
the optimization phase (choice of table access method, various costs,
transformations, etc). This feature would help to tell why some decisions were
taken by the optimizer and why some were rejected.

Trace is session-local, controlled by the @@optimizer_trace variable.
To enable optimizer trace we need to write:
   set @@optimizer_trace variable= 'enabled=on';

To display the trace one can run:
   SELECT trace FROM INFORMATION_SCHEMA.OPTIMIZER_TRACE;

This task also involves:
    MDEV-18489: Limit the memory used by the optimizer trace
    introduces a switch optimizer_trace_max_mem_size which limits
    the memory used by the optimizer trace. This was implemented by
    Sergei Petrunia.
2019-02-13 11:52:36 +05:30
Varun Gupta
6b979416e0 Extending the API for json_writer by introdcing
classes for Json_writer_object and Json_writer_array.
These classes will be used for the implementation
of the optimizer trace.
2019-02-13 11:52:35 +05:30
Vladislav Vaintroub
6c279ad6a7 MDEV-15091 : Windows, 64bit: reenable and fix warning C4267 (conversion from 'size_t' to 'type', possible loss of data)
Handle string length as size_t, consistently (almost always:))
Change function prototypes to accept size_t, where in the past
ulong or uint were used. change local/member variables to size_t
when appropriate.

This fix excludes rocksdb, spider,spider, sphinx and connect for now.
2018-02-06 12:55:58 +00:00
Michael Widenius
4aaa38d26e Enusure that my_global.h is included first
- Added sql/mariadb.h file that should be included first by files in sql
  directory, if sql_plugin.h is not used (sql_plugin.h adds SHOW variables
  that must be done before my_global.h is included)
- Removed a lot of include my_global.h from include files
- Removed include's of some files that my_global.h automatically includes
- Removed duplicated include's of my_sys.h
- Replaced include my_config.h with my_global.h
2017-08-24 01:05:44 +02:00
iangilfillan
f0ec34002a Correct FSF address 2017-03-10 18:21:29 +01:00
Vicențiu Ciorbaru
6560e9c3a8 MDEV-11711: ArmHF EXPLAIN JSON garbage longlong values printed
Make sure printing with snprintf uses the correct typed parameters.
2017-01-16 12:50:12 +02:00
Sergei Petrunia
2d65679384 MDEV-10665: Json_writer produces extra members in output
Fix an issue in Single_line_formatting_helper: flush_on_one_line()
didn't clean up the buffered items which could cause them to be
printed for the second time.

This can't be ever observed by a user (see MDEV text for details).
2016-08-25 19:47:38 +03:00
Sergei Petrunia
4938b82263 MDEV-7836: ANALYZE FORMAT=JSON should provide info about GROUP/ORDER BY
Provide basic info about sorting/grouping done by the queries.
2015-04-12 04:48:42 +03:00
Sergei Petrunia
eeef80d09f EXPLAIN FORMAT=JSON : Fix MDEV-7266, bug in pretty-printer
- Single_line_formatting_helper should not accidentally exit the
  DISABLED state. No JSON construct should be able to move the
  Single_line_formatting_helper from DISABLED state.
2014-12-06 20:13:38 +03:00
Sergei Petrunia
8722b6de4d Code cleanup 2014-12-02 02:14:17 +03:00
Sergei Petrunia
e235bb864d ANALYZE FORMAT=JSON: better output and tests
- Print r_loops
- Always print r_* members. Print NULL values if no scans took place
- Added testcases.
2014-11-29 03:07:24 +03:00
Sergei Petrunia
37c444e1a0 EXPLAIN FORMAT=JSON: further development
Writing JSON:
- Fix a bug in Single_line_formatting_helper
- Add Json_writer_nesting_guard - safety class

EXPLAIN JSON support
- Add basic subquery support
- Add tests for UNION/UNION ALL.
2014-11-27 19:32:48 +03:00
Sergei Petrunia
84485dbe7c MDEV-6109: EXPLAIN JSON
Add pretty-printing of possible_keys column.
2014-08-12 15:02:09 +04:00
Sergei Petrunia
33d53c4c24 MDEV-6109: EXPLAIN JSON
- Add first testcases
- Don't overquote when printing conditions
- Other small output fixes
2014-08-09 06:37:56 +04:00
Sergei Petrunia
5cfd3270ec MDEV-6109: EXPLAIN JSON
- First code, "EXPLAIN FORMAT=JSON stmt" and "ANALYZE FORMAT=JSON stmt"
  work for basic queries.  Complex constructs (e.g subqueries, etc) not
  yet supported.
- No test infrastructure yet
2014-05-27 21:04:45 +04:00