Commit graph

47 commits

Author SHA1 Message Date
Igor Babaev
954a6decd4 MDEV-32351 Significant slowdown for query with many outer joins
This patch fixes a performance regression introduced in the patch for the
bug MDEV-21104. The performance regression could affect queries for which
join buffer was used for an outer join such that its on expression from
which a conjunctive condition depended only on outer tables can be
extracted. If the number of records in the join buffer for which this
condition was false greatly exceeded the number of other records the
slowdown could be significant.

If there is a conjunctive condition extracted from the ON expression
depending only on outer tables this condition is evaluated when interesting
fields of each survived record of outer tables are put into the join buffer.
Each such set of fields for any join operation is supplied with a match
flag field used to generate null complemented rows. If the result of the
evaluation of the condition is false the flag is set to MATCH_IMPOSSIBLE.
When looking in the join buffer for records matching a record of the
right operand of the outer join operation the records with such flags
are not needed to be unpacked into record buffers for evaluation of on
expressions.

The patch for MDEV-21104 fixing some problem of wrong results when
'not exists' optimization by mistake broke the code that allowed to
ignore records with the match flag set to MATCH_IMPOSSIBLE when looking
for matching records. As a result such records were unpacked for each
record of the right operand of the outer join operation. This caused
significant execution penalty in some cases.

One of the test cases added in the patch can be used only for demonstration
of the restored performance for the reported query. The second test case is
needed to demonstrate the validity of the fix.
2023-10-27 15:44:46 +02:00
Monty
e9333ff03c MDEV-31893 Valgrind reports issues in main.join_cache_notasan
This is also related to
MDEV-31348 Assertion `last_key_entry >= end_pos' failed in virtual bool
           JOIN_CACHE_HASHED::put_record()

Valgrind exposed a problem with the join_cache for hash joins:
=25636== Conditional jump or move depends on uninitialised value(s)
==25636== at 0xA8FF4E: JOIN_CACHE_HASHED::init_hash_table()
          (sql_join_cache.cc:2901)

The reason for this was that avg_record_length contained a random value
if one had used SET optimizer_switch='optimize_join_buffer_size=off'.

This causes either 'random size' memory to be allocated (up to
join_buffer_size) which can increase memory usage or, if avg_record_length
is less than the row size, memory overwrites in thd->mem_root, which is
bad.

Fixed by setting avg_record_length in JOIN_CACHE_HASHED::init()
before it's used.

There is no test case for MDEV-31893 as valgrind of join_cache_notasan
checks that.
I added a test case for MDEV-31348.
2023-08-10 17:35:37 +03:00
Monty
e74390d94f Cleanup of sql_join_cache code (no logic changes)
- Remove virtual from get_min_join_buffer_size() and
  get_max_join_buffer_size().
- Avoid some calls to get_min_buffer_size()
- Simply cache usage in get_..._join_buffer_size()
- Simplify get_max_join_buffer_size() when using optimize_buff_size
- Reindented some long comments

Reviewer: Sergei Petrunia <sergey@mariadb.com>
2023-05-05 13:15:08 +03:00
Monty
5fd46be5a7 Fixed calculation of JOIN_CACHE::max_records
The old code did set max_records to either number_of_rows
(partial_join_cardinality) or memory size (join_buffer_space_limit)
which did not make sense.

Fixed by setting max_records to number of rows that fits into
join_buffer_size.

Other things:
- Initialize buffer cache values in JOIN_CACHE constructors (safety)

Reviewer: Sergei Petrunia <sergey@mariadb.com>
2023-05-05 12:50:05 +03:00
Vicențiu Ciorbaru
08c852026d Apply clang-tidy to remove empty constructors / destructors
This patch is the result of running
run-clang-tidy -fix -header-filter=.* -checks='-*,modernize-use-equals-default' .

Code style changes have been done on top. The result of this change
leads to the following improvements:

1. Binary size reduction.
* For a -DBUILD_CONFIG=mysql_release build, the binary size is reduced by
  ~400kb.
* A raw -DCMAKE_BUILD_TYPE=Release reduces the binary size by ~1.4kb.

2. Compiler can better understand the intent of the code, thus it leads
   to more optimization possibilities. Additionally it enabled detecting
   unused variables that had an empty default constructor but not marked
   so explicitly.

   Particular change required following this patch in sql/opt_range.cc

   result_keys, an unused template class Bitmap now correctly issues
   unused variable warnings.

   Setting Bitmap template class constructor to default allows the compiler
   to identify that there are no side-effects when instantiating the class.
   Previously the compiler could not issue the warning as it assumed Bitmap
   class (being a template) would not be performing a NO-OP for its default
   constructor. This prevented the "unused variable warning".
2023-02-09 16:09:08 +02:00
Marko Mäkelä
19052b6deb Merge 10.2 into 10.3 2021-03-18 12:34:48 +02:00
Igor Babaev
90780bb5a9 MDEV-21104 Wrong result (extra rows and wrong values) with incremental BNLH
This bug could affect multi-way join queries with embedded outer joins that
contained a conjunctive IS NULL predicate over a non-nullable column from
inner table of an outer join. The predicate could occur in WHERE condition
or in ON condition. Due to this bug a wrong result set could be returned by
the query. The bug manifested itself only when join buffers were employed
for join operations.

The problem appeared because
- a bug in the function JOIN_CACHE::get_match_flag_by_pos that not always
  returned proper match flags for embedding outer joins stored together
  with table rows put a join buffer.
- bug in the function JOIN_CACHE::join_matching_records that not always
  correctly determined that a row from the buffer could be skipped due
  to applied 'not_exists' optimization.
Example:
  SELECT * FROM t1 LEFT JOIN ((t2 LEFT JOIN t3 ON c = d) JOIN t4) ON b = e
    WHERE e IS NULL;

The patch introduces a new function that finds the match flag for a record
from join buffer specifying the buffer where this flag has to be found.
The function is called JOIN_CACHE::get_match_flag_by_pos_from_join_buffer().
Now this function rather than JOIN_CACHE::get_match_flag_by_pos() is used
in JOIN_CACHE::skip_if_matched() to check whether a record from the join
buffer must be ignored when extending the record by null complements.
Also the code of the function JOIN_CACHE::skip_if_not_needed_match() has
been changed. The function checks whether a record from the join buffer
still may produce some useful extensions.
Also some clarifying comments has been added.

Approved by monty@mariadb.com.
2021-03-10 17:28:40 -08:00
Marko Mäkelä
be85d3e61b Merge 10.2 into 10.3 2019-05-14 17:18:46 +03:00
Vicențiu Ciorbaru
f177f125d4 Merge branch '5.5' into 10.1 2019-05-11 19:15:57 +03:00
Michal Schorm
17b4f99928 Update FSF address
This commit is based on the work of Michal Schorm, rebased on the
earliest MariaDB version.

Th command line used to generate this diff was:

find ./ -type f \
  -exec sed -i -e 's/Foundation, Inc., 59 Temple Place, Suite 330, Boston, /Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, /g' {} \; \
  -exec sed -i -e 's/Foundation, Inc. 59 Temple Place.* Suite 330, Boston, /Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, /g' {} \; \
  -exec sed -i -e 's/MA.*.....-1307.*USA/MA 02110-1335 USA/g' {} \; \
  -exec sed -i -e 's/Foundation, Inc., 59 Temple/Foundation, Inc., 51 Franklin/g' {} \; \
  -exec sed -i -e 's/Place, Suite 330, Boston, MA.*02111-1307.*USA/Street, Fifth Floor, Boston, MA 02110-1335 USA/g' {} \; \
  -exec sed -i -e 's/MA.*.....-1307/MA 02110-1335/g' {} \;
2019-05-10 20:52:00 +03:00
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
Monty
8eeb689e9f Adding multi_range_read support to partitions
Other things:
- Cleanup of allocated bitmaps done in open(), which
  simplifies init_partition_bitmaps()
- Add needed defines in ha_spider.cc to enable new spider code
- Fixed some DBUG_PRINT() to be consistent with normal code
- Removed end space
- The changes in test cases partition_innodb, partition_range,
  partition_pruning etc are becasue partitions can now more exactly
  calculate the number of rows in a range.

Contains spider patches:
014,015,023,033,035,037,040,042,044,045,049,050,051,053,059
2017-12-03 13:58:34 +02:00
Michael Widenius
87933d5261 Handle failures from malloc
Most "new" failures fixed in the following files:
- sql_select.cc
- item.cc
- item_func.cc
- opt_subselect.cc

Other things:
- Allocate udf_handler strings in mem_root
  - Required changes in sql_string.h
- Add mem_root as argument to some new [] calls
- Mark udf_handler strings as thread specific
- Removed some comment blocks with code
2017-11-17 07:30:05 +02:00
iangilfillan
f0ec34002a Correct FSF address 2017-03-10 18:21:29 +01:00
Sergei Golubchik
7f5e51b940 MDEV-34 delete storage/ndb and sql/*ndb* (and collateral changes)
remove:
* NDB from everywhere
* IM from mtr-v1
* packaging/rpm-oel and packaging/rpm-uln
* few unused spec files
* plug.in file
* .bzrignore
2014-10-11 18:53:06 +02:00
Sergei Petrunia
424d5de89d Merge bb-10.1-explain-analyze into 10.1 2014-06-25 16:46:42 +04:00
Sergei Petrunia
7711999d8b MDEV-406: ANALYZE $stmt: add support for BNL join buffering 2014-06-25 15:15:38 +04:00
Igor Babaev
d42e6d3a99 Fixed bug mdev-6071.
The method JOIN_CACHE::init may fail (return 1) if some conditions on the
used join buffer is not satisfied. For example it fails if join_buffer_size
is greater than join_buffer_space_limit. The conditions should be checked
when running the EXPLAIN command for the query. That's why the method
JOIN_CACHE::init has to be called for EXPLAIN commands as well.
2014-06-10 10:34:58 -07:00
Sergey Petrunya
e5d13c1567 Merge 10.0-base -> 10.0 2013-10-16 13:38:42 +04:00
Sergey Petrunya
72bc6d7364 MDEV-3798: EXPLAIN UPDATE/DELETE
- Address review feedback: more renames
2013-10-05 13:19:45 +04:00
Sergey Petrunya
fedf769f0b MDEV-3798: EXPLAIN UPDATE/DELETE
- Address review feedback: rename nearly any name used by the new EXPLAIN code.
2013-10-05 09:58:22 +04:00
Sergey Petrunya
a3d79f2e58 Merge 10.0-serg -> 10.0 2013-08-07 17:21:37 +04:00
Sergey Petrunya
8e36dde7e1 Better comments 2013-08-07 17:20:22 +04:00
Sergey Petrunya
befacafd73 [SHOW] EXPLAIN UPDATE/DELETE, code re-structuring
- Let Query Plan Footprint store join buffer type 
  in binary form, not string.
- Same for LooseScan type.
2013-06-27 17:56:49 +04:00
Michael Widenius
068c61978e Temporary commit of 10.0-merge 2013-03-26 00:03:13 +02:00
Sergei Golubchik
edab37cd68 5.3 merge 2012-02-21 20:51:56 +01:00
Sergei Golubchik
5bf311e1e8 fix the include guards and add missing gplv2 headers 2012-02-17 12:19:38 +01:00
unknown
607aab9c1d Counters for Index Condition Pushdown added (MDEV-130). 2012-02-16 08:49:10 +02:00
Vladislav Vaintroub
24e7faa54f Various fixes for Solaris compiler.
Also, restrict symbol visibility in statically
built plugins, to minimize the chance for symbol 
name clashes with dynamic plugins.
2012-02-03 11:46:40 +01:00
Sergei Golubchik
76f0b94bb0 merge with 5.3
sql/sql_insert.cc:
  CREATE ... IF NOT EXISTS may do nothing, but
  it is still not a failure. don't forget to my_ok it.
  ******
  CREATE ... IF NOT EXISTS may do nothing, but
  it is still not a failure. don't forget to my_ok it.
sql/sql_table.cc:
  small cleanup
  ******
  small cleanup
2011-10-19 21:45:18 +02:00
Igor Babaev
31edda66fd Fixed LP bug #802860.
This crashing bug could manifest itself at execution of join queries
over materialized derived tables with IN subquery predicates in the
where clause. If for such a query the optimizer chose to use duplicate
weed-out with duplicates in a materialized derived table and chose to
employ join cache the the execution could cause a crash of the server.
It happened because the JOIN_CACHE::init method assumed  that the value
of TABLE::file::ref is set at the moment when the method was called 
for the employed join cache. It's true for regular tables, but it's 
not true for materialized derived tables that are filled now at the
first access to them, i.e. after the JOIN_CACHE::init has done its job.

To fix this problem for any ROWID field of materialized derived table
the procedure that copies fields from record buffers into the employed
join buffer first checks whether the value of TABLE::file::ref has 
been set for the table, and if it's not so the procedure sets this value.
2011-06-28 18:31:54 -07:00
Sergey Petrunya
3098c21b8f Merge MWL#90 into 5.3-main 2011-04-30 04:59:05 +04:00
Sergey Petrunya
8fb724281e Merge MWL#90 with main 5.3 tree 2011-04-02 14:09:00 +04:00
Sergey Petrunya
997445bc8e Make EXPLAIN better at displaying MRR/BKA:
- "Using MRR" is no longer shown with range access.
- Instead, both range and BKA accesses will show one of the following:
  = "Rowid-ordered scan"
  = "Key-ordered scan"
  = "Key-ordered Rowid-ordered scan"
depending on whether DS-MRR implementation will do scan keys in order, rowids in order,
or both.
- The patch also introduces a way for other storage engines/MRR implementations to
  pass information to EXPLAIN output about the properties of employed MRR scans.
2011-04-02 14:04:45 +04:00
Sergey Petrunya
792c67ff61 MWL#90: Address review feedback part #1 2011-03-19 12:27:08 +03:00
Sergey Petrunya
e6bd643c75 MRR interface: change range_info's type from char* to range_id_t typedef. The goals are:
- cleaner code
- ability to change from using pointers to offsets at some point
2011-03-04 12:06:03 +03:00
Sergey Petrunya
cb147b3965 Merge 5.3 -> 5.3-subqueries-mwl90 2011-03-01 13:21:48 +03:00
Vladislav Vaintroub
70a7e97e3c Fixed high-impact Windows 64bit warnings (at least 4000 of them) 2011-02-19 13:43:01 +01:00
Vladislav Vaintroub
019256c9fc Fix numerous warnings introduced in the last pushes on Windows 2011-02-18 23:31:01 +01:00
Sergey Petrunya
e7aa18fb9c Code cleanup (1) 2011-02-19 00:22:38 +03:00
Sergey Petrunya
cdccdea951 MWL#90: Merge (4) 2011-02-15 22:25:10 +03:00
Sergey Petrunya
e4325ff60b MWL#90: Subqueries: Inside-out execution for materialized non-sj subqueries
- Merge with 5.3 (3)
2011-02-15 20:29:57 +03:00
Igor Babaev
4b24105df8 Introduced optimizer switch flag 'optimize_join_buffer_size'.
When this flag is 'off' the size of the used join buffer 
is taken directly from the system variable 'join_buffer_size'.
When this flag is 'on' then the size of the buffer depends
on the estimated number of rows in the partial join whose
records are to be stored in the buffer.
By default this flag is set 'on'.
2011-02-04 19:06:35 -08:00
Igor Babaev
1eb5e0e603 Merge 2010-12-24 16:24:20 -08:00
Igor Babaev
a095346a9d Fixed LP bug #670380.
Lifted the limitation that hash join could not be used over 
varchar fields with non-binary collation.
2010-12-22 00:37:35 -08:00
Sergey Petrunya
d1afc20e13 Merge maria-5.3-mwl128 -> maria-5.2-mwl128-dsmrr-cpk 2010-11-29 19:00:32 +03:00
Igor Babaev
4e05898f53 Got the declarations related to the class JOIN_CACHE, its derivatives and
companions out of sql_select.h into a separate file sql_join_cache.h.
2010-11-19 11:03:03 -08:00