Commit graph

295 commits

Author SHA1 Message Date
Varun Gupta
b11ff3d495 MDEV-22019: Sig 11 in next_breadth_first_tab | max_sort_length setting + double GROUP BY leads to crash
No need to create a temp table for aggregation if we have encountered some error.
2020-03-30 08:03:54 +05:30
Marko Mäkelä
e99ba4ba51 Merge 10.1 into 10.2 2020-01-07 07:44:37 +02:00
Varun Gupta
1adc559370 Making group_by test stable 2020-01-03 22:54:28 +05:30
Oleksandr Byelkin
b35290e19b Merge branch '10.1' into 10.2 2020-01-03 12:40:38 +01:00
Varun Gupta
faf2a6e5f0 MDEV-20922: Adding an order by changes the query results
For Item_direct_view_ref , get value from val_* methods
instead of result* family
The val_* methods gets value from the item on which it is referred.
2020-01-02 09:49:13 +05:30
Monty
9cba6c5aa3 Updated mtr files to support different compiled in options
This allows one to run the test suite even if any of the following
options are changed:
- character-set-server
- collation-server
- join-cache-level
- log-basename
- max-allowed-packet
- optimizer-switch
- query-cache-size and query-cache-type
- skip-name-resolve
- table-definition-cache
- table-open-cache
- Some innodb options
etc

Changes:
- Don't print out the value of system variables as one can't depend on
  them to being constants.
- Don't set global variables to 'default' as the default may not
  be the same as the test was started with if there was an additional
  option file. Instead save original value and reset it at end of test.
- Test that depends on the latin1 character set should include
  default_charset.inc or set the character set to latin1
- Test that depends on the original optimizer switch, should include
  default_optimizer_switch.inc
- Test that depends on the value of a specific system variable should
  set it in the test (like optimizer_use_condition_selectivity)
- Split subselect3.test into subselect3.test and subselect3.inc to
  make it easier to set and reset system variables.
- Added .opt files for test that required specfic options that could
  be changed by external configuration files.
- Fixed result files in rockdsb & tokudb that had not been updated for
  a while.
2019-09-01 19:17:35 +03:00
Varun Gupta
a12b8ac8e9 MDEV-12575: Server crash in AGGR_OP::put_record or in JOIN_CACHE::free or Invalid write in JOIN::make_aggr_tables_info
During the optimize state of a query, we come know that the result set
would atmost contain one row, then for such a query we don't need
to compute GROUP BY, ORDER BY and DISTINCT.
2018-11-10 13:13:26 +05:30
Vicențiu Ciorbaru
985d2d393c Merge remote-tracking branch 'origin/10.1' into 10.2 2017-12-22 12:23:39 +02:00
Vicențiu Ciorbaru
e3d89652e5 Merge branch '10.0' into 10.1 2017-12-20 13:30:05 +02:00
Vicențiu Ciorbaru
042f763268 Merge remote-tracking branch '5.5' into 10.0 2017-12-20 12:51:57 +02:00
Varun Gupta
924db8b4ed MDEV-12350: Heap corruption, overrun buffer, ASAN errors, server crash in my_fill_8bit / filesort
In the function make_sortkey a tmp buffer was defined and in the absence of
param->tmp_buffer, tmp buffer used the sort_keys buffer. sort_keys buffer
has a length defined in sort_field->length, while param->tmp_buffer is
stored in param->rec_length. Make sure to use the appropriate length
based on which buffer we are using otherwise we'll overflow.

Also added a type cast to size_t during the calculation of the sort keys
buffer size to avoid an oveflow if the buffer size exceeds 32 bits.
2017-12-20 11:50:22 +02:00
Sergei Golubchik
cb1e76e4de Merge branch '10.1' into 10.2 2017-08-17 11:38:34 +02:00
Sergei Golubchik
8e8d42ddf0 Merge branch '10.0' into 10.1 2017-08-08 10:18:43 +02:00
Vicențiu Ciorbaru
786ad0a158 Merge remote-tracking branch 'origin/5.5' into 10.0 2017-07-25 00:41:54 +03:00
Sergei Golubchik
181d9d2892 MDEV-13180 Unused left join causes server crash
already fixed by be55bbc2b2
just add a test case
2017-07-12 17:46:27 +02:00
Sergei Golubchik
05b678bc8c MDEV-12489 The select stmt may fail due to "having clause is ambiguous" unexpected
only compare field references with an alias (from the SELECT clause)
when this reference doesn't specify an explicit table name part.
2017-07-12 17:46:19 +02:00
Sergei Golubchik
be55bbc2b2 MDEV-7826 Server crashes in Item_subselect::enumerate_field_refs_processor
upper->item can be NULL if we're referring to an aggregate function
2017-07-12 12:49:29 +02:00
Sergei Petrunia
e688d81444 MDEV-10694 - SIGFPE and/or huge memory allocation in maria_create ...
The issue was that JOIN::rollup_write_data() used
JOIN::tmp_table_param::[start_]recinfo, which had uninitialized data.

These fields have uninitialized data, because JOIN::tmp_table_param
currently only stores some grouping-related data fields.  The data about
the work (temporary) tables themselves is stored in
join->join_tab[...].tmp_table_param.

The fix is to make JOIN::rollup_write_data follow this convention
and look at the right TMP_TABLE_PARAM object
2017-02-15 13:47:41 -08:00
Sergei Golubchik
4a5d25c338 Merge branch '10.1' into 10.2 2016-12-29 13:23:18 +01:00
Sergei Golubchik
180065ebb0 Item::print(): remove redundant parentheses
by introducing new Item::precedence() method and using it
to decide whether parentheses are required
2016-12-12 20:44:41 +01:00
Sergei Golubchik
2f20d297f8 Merge branch '10.0' into 10.1 2016-12-11 09:53:42 +01:00
Sergei Golubchik
3e8155c637 Merge branch '5.5' into 10.0 2016-12-09 16:33:48 +01:00
Oleksandr Byelkin
d67ef7a2fb MDEV-10663: Use of Inline table columns in HAVING clause throws 1463 Error
check for VIEW/DERIVED fields
2016-12-06 19:34:25 +01:00
Sergei Golubchik
06b7fce9f2 Merge branch '10.1' into 10.2 2016-09-09 08:33:08 +02:00
Sergei Petrunia
95c286cedf MDEV-10324: Server crash in get_sel_arg_for_keypart or Assertion
The crash was caused by this problem:
get_best_group_min_max() tries to construct query plans for keys that
are not processed by the range optimizer. This wasn't a problem as long
as SEL_TREE::keys was an array of MAX_KEY elements.
However, now it is a Mem_root_array and only has elements for the used
keys, and get_best_group_min_max attempts to address beyond the end of
the array.

The obvious way to fix the crash was to port (and improve) a part of
96fcfcbd7b5120e8f64fd45985001eca8d36fbfb from mysql-5.7. This makes
get_best_group_min_max not to consider indexes that Mem_root_arrays
have no element for.

After that, I got non-sensical query plans (see MDEV-10325 for details).
Fixed that by making get_best_group_min_max to check if the index is in
table->keys_in_use_for_group_by bitmap.
2016-07-05 16:55:11 +03:00
Galina Shalygina
be1d06c8a5 Merge branch '10.2' into 10.2-mdev9864 2016-05-08 23:04:41 +03:00
Monty
48f02af761 MDEV-9602 crash in st_key::actual_rec_per_key when group by constant
Problem was that cost_group_min_max() could not handle if group by was optimized away.
2016-04-28 13:39:55 +03:00
Sergei Petrunia
b05158cc10 MDEV-8988: Apparently valid SQL query gives wrong result (nested WHERE)
- "Early NULLs filtering" optimization used to "peel off" Item_ref and
  Item_direct_ref wrappers from an outside column reference before
  adding "outer_table_col IS NOT NULL" into JOIN::outer_ref_cond.
- When this happened in a subquery that was evaluated in a post-GROUP-BY
  context, attempt to evaluate JOIN::outer_ref_cond would fetch an
  incorrect value of outer_table_col.
2016-02-24 17:18:53 +03:00
Alexander Barkov
c108019a48 MDEV-8747 Wrong result for SELECT..WHERE derived_table_column='a' AND derived_table_column<>_latin1'A' COLLATE latin1_bin
MDEV-8749 Wrong result for SELECT..WHERE derived_table_enum_column='number' AND derived_table_enum_column OP number
2015-09-06 01:30:46 +04:00
Monty
86377d078e Fixes done while working on MDEV-4119:
Fixed several optimizer issues relatied to GROUP BY:

a) Refering to a SELECT column in HAVING sometimes calculated it twice, which caused problems with non determinstic functions

b) Removing duplicate fields and constants from GROUP BY was done too late for "using index for group by" optimization to work

c) EXPLAIN SELECT ... GROUP BY did wrongly show 'Using filesort' in some cases involving "Using index for group-by"


a) was fixed by:
- Changed last argument to Item::split_sum_func2() from bool to int to allow more flags
- Added flag argument to Item::split_sum_func() to allow on to specify if the item was in the SELECT part
- Mark all split_sum_func() calls from SELECT with SPLIT_SUM_SELECT
- Changed split_sum_func2() to do nothing if called with an argument that is not a sum function and doesn't include sum functions, if we are not an argument to SELECT.

This ensures that in a case like
select a*sum(b) as f1 from t1 where a=1 group by c having f1 <= 10;

That 'a' in the SELECT part is stored as a reference in the temporary table togeher with sum(b) while the 'a' in having isn't (not needed as 'a' is already a reference to a column in the result)

b) was fixed by:
- Added an extra remove_const() pass for GROUP BY arguments before make_join_statistics() in case of one table SELECT.

This allowes get_best_group_min_max() to optimize things better.

c) was fixed by:
- Added test for group by optimization in JOIN::exec_inner for
  select->quick->get_type() == QUICK_SELECT_I::QS_TYPE_GROUP_MIN_MAX

item.cc:
- Simplifed Item::split_sum_func2()
  - Split test to make them faster and easier to read
  - Changed last argument to Item::split_sum_func2() from bool to int to allow more flags
  - Added flag argument to Item::split_sum_func() to allow on to specify if the item was in the SELECT part
  - Changed split_sum_func2() to do nothing if called with an argument that is not a sum function and doesn't include sum functions, if we are not an argument to SELECT.

opt_range.cc:
- Simplified get_best_group_min_max() by calcuating first how many group_by elements.
- Use join->group instead of join->group_list to test if group by, as join->group_list may be NULL if everything was optimized away.

sql_select.cc:
- Added an extra remove_const() pass for GROUP BY arguments before make_join_statistics() in case of one table SELECT.
- Use group instead of group_list to test if group by, as group_list may be NULL if everything was optimized away.
- Moved printing of "Error in remove_const" to remove_const() instead of having it in caller.
- Simplified some if tests by re-ordering code.
- update_depend_map_for_order() and remove_const() fixed to handle the case where make_join_statistics() has not yet been called (join->join_tab is 0 in this case)
2015-07-05 12:39:46 +03:00
Sergei Golubchik
810cf362ea Merge branch '5.5' into 10.0 2015-06-11 20:20:35 +02:00
Sergei Golubchik
c79e98e491 MDEV-8085 main.group_by failed in buildbot
change the test case to be deterministic
(while still sufficient to test a bug)
2015-06-03 18:45:08 +02:00
Sergei Golubchik
49c853fb94 Merge branch '5.5' into 10.0 2015-05-04 22:00:24 +02:00
Sergei Golubchik
fbab0685a7 post-merge changes, fixes, and tests 2015-04-28 13:57:21 +02:00
Sergei Golubchik
d9c01e4b4a 5.5 merge 2015-01-21 12:03:02 +01:00
Michael Widenius
5257d71e0e MDEV-6855 Assertion `cond_type == Item::FUNC_ITEM' failed in check_group_min_max_predicates with GROUP BY, aggregate in WHERE SQ, multi-part key
mysql-test/r/group_by.result:
  Test for MDEV-6855
mysql-test/t/group_by.test:
  Test for MDEV-6855
sql/item.h:
  Fixed spelling error
sql/opt_range.cc:
  Added handling of cond_type == Item::CACHE_ITEM in WHERE clauses for MIN/MAX optimization.
  Fixed indentation
2014-12-15 17:13:47 +02:00
Sergei Golubchik
2160646c1d 5.5 merge 2014-11-03 17:47:37 +01:00
Sergey Petrunya
b261ec393a MDEV-6484: Assertion `tab->ref.use_count' failed on query with joins, constant table, multi-part key
- test_if_skip_sort_order()/create_ref_for_key() may change table 
  access from EQ_REF(index1) to REF(index2). 
- Doing so doesn't make much sense from optimization POV, but since 
  they are doing it, they should update tab->read_record.unlock_row
  accordingly.
2014-10-14 15:11:06 +04:00
Sergei Golubchik
d3e2e1243b 5.5 merge 2014-05-09 12:35:11 +02:00
Igor Babaev
3e0f63c18f Fixed the problem of mdev-5947.
Back-ported from the mysql 5.6 code line the patch with
the following comment:

  Fix for Bug#11757108 CHANGE IN EXECUTION PLAN FOR COUNT_DISTINCT_GROUP_ON_KEY
                       CAUSES PEFORMANCE REGRESSION

  The cause for the performance regression is that the access strategy for the
  GROUP BY query is changed form using "index scan" in mysql-5.1 to use "loose
  index scan" in mysql-5.5. The index used for group by is unique and thus each
  "loose scan" group will only contain one record. Since loose scan needs to
  re-position on each "loose scan" group this query will do a re-position for
  each index entry. Compared to just reading the next index entry as a normal
  index scan does, the use of loose scan for this query becomes more expensive.

  The cause for selecting to use loose scan for this query is that in the current
  code when the size of the "loose scan" group is one, the formula for
  calculating the cost estimates becomes almost identical to the cost of using
  normal index scan. Differences in use of integer versus floating point arithmetic
  can cause one or the other access strategy to be selected.

  The main issue with the formula for estimating the cost of using loose scan is
  that it does not take into account that it is more costly to do a re-position
  for each "loose scan" group compared to just reading the next index entry.
  Both index scan and loose scan estimates the cpu cost as:

    "number of entries needed too read/scan" * ROW_EVALUATE_COST

  The results from testing with the query in this bug indicates that the real
  cost for doing re-position four to eight times higher than just reading the
  next index entry. Thus, the cpu cost estimate for loose scan should be increased.
  To account for the extra work to re-position in the index we increase the
  cost for loose index scan to include the cost of navigating the index.
  This is modelled as a function of the height of the b-tree:

    navigation cost= ceil(log(records in table)/log(indexes per block))
                   * ROWID_COMPARE_COST;

  This will avoid loose index scan being used for indexes where the "loose scan"
  group contains very few index entries.
2014-04-22 14:39:57 -07:00
Michael Widenius
b17a053cc9 MDEV-6129: Server crashes during UNION with ORDER BY field IS NULL
Fixed crashing bug for union queries where there was no real tables.


mysql-test/r/group_by.result:
  Added test case
mysql-test/t/group_by.test:
  Added test case
sql/db.opt:
  Removed genrated file
sql/item.cc:
  Handled case when table_list->pos_in_tables is not set. Can only happens when there is no real tables in query
2014-04-24 18:20:57 +03:00
Sergei Golubchik
72c20282db 10.0-base merge 2014-02-03 15:22:39 +01:00
Sergei Golubchik
59d9d08e2b 5.5 merge 2014-02-01 00:54:03 +01:00
Sergei Golubchik
3f2f9c36b1 move innodb specific test from group_by.test to group_by_innodb.test 2014-01-26 21:49:11 +01:00
Michael Widenius
c050b5fdf9 Fixed MDEV-5424: SELECT using ORDER BY DESC and LIMIT produces unexpected results (InnoDB/XtraDB)
This only happend when using an ORDER BY on a primary key part, where all other key parts where constant.
Remove of duplicated expressions in ORDER BY (as the old code did this in some strange cases)


mysql-test/r/group_by.result:
  Fixed results to take into account that duplicate order by parts are now deleted
mysql-test/r/group_by_innodb.result:
  Ensure extended keys are on
mysql-test/r/innodb_ext_key.result:
  More tests
mysql-test/r/order_by.result:
  More tests
mysql-test/t/group_by.test:
  Fixed results to take into account that duplicate order by parts are now deleted
mysql-test/t/group_by_innodb.test:
  Ensure extended keys are on
mysql-test/t/innodb_ext_key.test:
  More tests
mysql-test/t/order_by.test:
  More tests
sql/sql_select.cc:
  Fixed bug where we looked at extended key parts when we shouldn't
  Remove of duplicated expressions in ORDER BY
sql/table.cc:
  Indentation fixes
2014-01-02 15:51:02 +02:00
unknown
97ecffc8ee merge 10.0-base -> 10.0 2013-10-29 22:20:45 +02:00
unknown
f4d5d849fd merge 5.5->10.0-base 2013-10-29 20:53:05 +02:00
unknown
52dea41052 Merge 5.3->5.5 2013-10-29 18:50:36 +02:00
timour@askmonty.org
883af99e7d MDEV-5104 crash in Item_field::used_tables with broken order by
Analysis:
st_select_lex_unit::prepare() computes can_skip_order_by as TRUE.
As a result join->prepare() gets called with order == NULL, and
doesn't do name resolution for the inner ORDER clause. Due to this
the prepare phase doesn't detect that the query references non-exiting
function and field.
  
Later join->optimize() calls update_used_tables() for a non-resolved
Item_field, which understandably has no Field object. This call results
in a crash.

Solution:
Resolve unnecessary ORDER BY clauses to detect if they reference non-exising
objects. Then remove such clauses from the JOIN object.
2013-10-29 12:39:03 +02:00
Sergei Golubchik
9af177042e 10.0-base merge.
Partitioning/InnoDB changes are *not* merged (they'll come from 5.6)
TokuDB does not compile (not updated to 10.0 SE API)
2013-09-21 10:14:42 +02:00