Commit graph

1847 commits

Author SHA1 Message Date
Evgeny Potemkin
1f28ee8875 Bug#38195: Incorrect handling of aggregate functions when loose index scan is
used causes server crash.
      
When the loose index scan access method is used values of aggregated functions
are precomputed by it. Aggregation of such functions shouldn't be performed
in this case and functions should be treated as normal ones.
The create_tmp_table function wasn't taking this into account and this led to
a crash if a query has MIN/MAX aggregate functions and employs temporary table
and loose index scan.
Now the JOIN::exec and the create_tmp_table functions treat MIN/MAX aggregate
functions as normal ones when the loose index scan is used.
2008-08-27 17:03:17 +04:00
Georgi Kodinov
4b2dd02552 Bug#38195: Incorrect handling of aggregate functions when loose index scan
is used causes server crash.
  Revert the fix : unstable test case revealed by pushbuild
2008-08-19 13:36:24 +03:00
Evgeny Potemkin
cf28ff2616 Bug#38195: Incorrect handling of aggregate functions when loose index scan is
used causes server crash.

When the loose index scan access method is used values of aggregated functions
are precomputed by it. Aggregation of such functions shouldn't be performed
in this case and functions should be treated as normal ones.
The create_tmp_table function wasn't taking this into account and this led to
a crash if a query has MIN/MAX aggregate functions and employs temporary table
and loose index scan.
Now the JOIN::exec and the create_tmp_table functions treat MIN/MAX aggregate
functions as normal ones when the loose index scan is used.
2008-08-13 22:24:55 +04:00
Igor Babaev
47cd6462fd Merge 2008-07-28 01:24:56 -07:00
Igor Babaev
da156dde08 Fixed bug #38191.
Calling List<Cached_item>::delete_elements for the same list twice
caused a crash of the server in the function JOIN::cleaunup.
Ensured that delete_elements() in JOIN::cleanup would be called only once.
2008-07-26 13:44:07 -07:00
Georgi Kodinov
436f1dc49c Bug#37830 : ORDER BY ASC/DESC - no difference
Range scan in descending order for c <= <col> <= c type of
ranges was ignoring the DESC flag.
However some engines like InnoDB have the primary key parts 
as a suffix for every secondary key.
When such primary key suffix is used for ordering ignoring 
the DESC is not valid.
But we generally would like to do this because it's faster.
            
Fixed by performing only reverse scan if the primary key is used.
Removed some dead code in the process.
2008-07-23 14:25:00 +03:00
Sergey Petrunia
2951f00be4 BUG#35478: sort_union() returns bad data when sort_buffer_size is hit
- In QUICK_INDEX_MERGE_SELECT::read_keys_and_merge: when we got table->sort from Unique,
  tell init_read_record() not to use rr_from_cache() because a) rowids are already sorted
  and b) it might be that the the data is used by filesort(), which will need record rowids
  (which rr_from_cache() cannot provide).
- Fully de-initialize the table->sort read in QUICK_INDEX_MERGE_SELECT::get_next(). This fixes BUG#35477.
(bk trigger: file as fix for BUG#35478).
2008-07-15 18:13:21 +04:00
gkodinov/kgeorge@magare.gmz
df3341a764 Bug #36011: server crash with explain extended on query
with dependent subqueries
An IN subquery is executed on EXPLAIN when it's not correlated.
If the subquery required a temporary table for its execution
not all the internal structures were restored from pointing to
the items of the temporary table to point back to the items of
the subquery.
Fixed by restoring the ref array when a temp tables were used in
executing the IN subquery during EXPLAIN EXTENDED.
2008-05-16 17:05:55 +03:00
gshchepa/uchum@host.loc
a0c5b495cb Fixed bug#36005: server crashes inside NOT IN clause subquery with
impossible WHERE/HAVING clause
                 (subselect_single_select_engine::exec).

Allocation and initialization of joined table list t1, t2... of
subqueries like:

    NOT IN (SELECT ... FROM t1,t2,... WHERE 0)

is optimized out, however server tries to traverse this list.
2008-04-23 02:27:23 +05:00
iggy@amd64.(none)
b9877b84ac Merge amd64.(none):/src/mysql-5.0-bugteam
into  amd64.(none):/src/bug26243/my50-bug26243
2008-03-28 16:01:05 -04:00
iggy@amd64.(none)
79e434bc67 Bug#26243 mysql command line crash after control-c
- Backported the 5.1 DBUG to 5.0.
- Avoid memory cleanup race on Windows client for CTRL-C
2008-03-28 14:02:27 -04:00
evgen@moonbone.local
0bce8e6f9b Merge epotemkin@bk-internal.mysql.com:/home/bk/mysql-5.0-bugteam
into  moonbone.local:/work/27219-5.0-opt-mysql
2008-03-28 14:31:52 +03:00
evgen@moonbone.local
21c6145a6e Bug#27219: Aggregate functions in ORDER BY.
Mixing aggregate functions and non-grouping columns is not allowed in the
ONLY_FULL_GROUP_BY mode. However in some cases the error wasn't thrown because
of insufficient check.

In order to check more thoroughly the new algorithm employs a list of outer
fields used in a sum function and a SELECT_LEX::full_group_by_flag.
Each non-outer field checked to find out whether it's aggregated or not and
the current select is marked accordingly.
All outer fields that are used under an aggregate function are added to the
Item_sum::outer_fields list and later checked by the Item_sum::check_sum_func
function.
2008-03-27 19:49:32 +03:00
gshchepa/uchum@host.loc
2dcec449e0 Fixed bug #35193.
View definition as SELECT ... FROM DUAL WHERE ... has
valid syntax, but use of such view in SELECT or
SHOW CREATE VIEW syntax causes unexpected syntax error.

Server omits FROM DUAL clause when storing view body
string in a .frm file for further evaluation.
However, syntax of SELECT-witout-FROM query is more
restrictive than SELECT FROM DUAL syntax, and doesn't
allow the WHERE clause.

NOTE: this syntax difference is not documented.


View registration procedure has been modified to
preserve original structure of view's body.
2008-03-26 22:43:12 +04:00
sergefp@mysql.com
b779af5503 BUG#34945: "ref_or_null queries that are null_rejecting and have a null value crash mysql"
- Apply Eric Bergen's patch: in join_read_always_key(), move ha_index_init() call
  to before the late NULLs filtering code.
- Backport function comments from 6.0.
2008-03-03 20:35:44 +03:00
gshchepa/uchum@host.loc
3bf9c7edf1 Fixed bug #34830: mixed table and field names in Item_ref
and Item_direct_ref constructor calls.

Order of ref->field_name and ref->table_name arguments
is of Item_ref and Item_direct_ref in the fix_inner_refs
function is inverted.
2008-02-29 15:11:11 +04:00
holyfoot/hf@hfmain.(none)
652b7099ca Merge bk@192.168.21.1:mysql-5.0-opt
into  mysql.com:/home/hf/work/32942/my50-32942
2008-02-18 19:18:44 +04:00
holyfoot/hf@mysql.com/hfmain.(none)
7abba3b021 Bug #32942 now() - interval '7200' second NOT pre-calculated, causing "full table scan"
Problem is not about intervals and doesn't actually cause 'full table scan'.
We have an optimization for DISTINCT when we have
'DISTINCT field_from_first_join_table' we don't need to read all the
rows from the JOIN-ed table if we found one conforming row.
It stopped working in 5.0 as we return NESTED_LOOP_OK if we came upon
that case in the evaluate_join_record() and that doesn't break the
recordreading loop in sub_select().

Fixed by returning NESTED_LOOP_NO_MORE_ROWS in this case.
2008-02-17 15:48:17 +04:00
igor@olga.mysql.com
5e14047e23 Fixed bug #33833.
Two disjuncts containing equalities of the form key=const1 and key=const2 can
be merged into one if const1 is equal to const2. To check it the common 
collation of the constants were used rather than the collation of the field key.
For example when the default collation of the constants was cases insensitive
while the collation of the field was case sensitive, then two or-ed equality 
predicates key='b' and key='B' incorrectly were merged into one f='b'. As a 
result ref access was used instead of range access and wrong result sets were 
returned in many cases. 
Fixed the problem by comparing constant in the or-ed predicate with collation of
the key field.
2008-01-26 21:45:35 -08:00
sergefp@mysql.com
d56ac2f37b BUG#33794 "MySQL crashes executing specific query":
The problem occurred when one had a subquery that had an equality X=Y where 
Y referred to a named select list expression from the parent select. MySQL 
crashed when trying to use the X=Y equality for ref-based access. 

Fixed by allowing non-Item_field items in the described case.
2008-01-18 22:50:36 +03:00
mhansson/martin@linux-st28.site
284d8c71ee Merge mhansson@bk-internal:/home/bk/mysql-5.0-opt
into  linux-st28.site:/home/martin/mysql/src/bug32848/my50-bug32848
2007-12-20 11:24:42 +01:00
mhansson/martin@linux-st28.site
6f6e18809a Bug#32848: Data type conversion bug in union subselects in MySQL 5.0.38
Warnings elimination
2007-12-20 10:58:21 +01:00
mhansson/martin@linux-st28.site
0004b99b58 Merge mhansson@bk-internal:/home/bk/mysql-5.0-opt
into  linux-st28.site:/home/martin/mysql/src/bug32848/my50-bug32848
2007-12-19 15:59:05 +01:00
gluh@eagle.(none)
e039595029 Merge mysql.com:/home/gluh/MySQL/Merge/5.0
into  mysql.com:/home/gluh/MySQL/Merge/5.0-opt
2007-12-13 14:52:49 +04:00
mhansson/martin@linux-st28.site
867a786549 Bug#32848: Data type conversion bug in union subselects in MySQL 5.0.38
There were two problems when inferring the correct field types resulting from
UNION queries.
- If the type is NULL for all corresponding fields in the UNION, the resulting 
  type would be NULL, while the type is BINARY(0) if there is just a single 
  SELECT NULL.
- If one SELECT in the UNION uses a subselect, a temporary table is created
  to represent the subselect, and the result type defaults to a STRING type,
  hiding the fact that the type was unknown(just a NULL value).
Fixed by remembering whenever a field was created from a NULL value and pass
type NULL to the type coercion if that is the case, and creating a string field
as result of UNION only if the type would otherwise be NULL.
2007-12-11 20:15:03 +01:00
igor@olga.mysql.com
c394dbe14a Fixed bug #32815.
The index (key_part_1, key_part-2) was erroneously considered as compatible
with the required ordering in the function test_test_if_order_by_key when 
a query with an ORDER BY clause contained a condition of the form
  key_part_1=const OR key_part_1 IS NULL 
and the order list contained only key_part_2. This happened because the value
of the const_key_parts field in the KEYUSE structure was not formed correctly
for the keys that could be used for ref_or_null access. 
This was fixed in the code of the update_ref_and_keys function.
The problem could not manifest itself for MyISAM databases because the
implementation of the keys_to_use_for_scanning() handler function always
returns an empty bitmap for the MyISAM engine.
2007-12-07 17:14:59 -08:00
tsmith@ramayana.hindu.god
b922c9646c Fix compiler warning about wrong integer size (probably harmless) 2007-12-06 16:11:26 -07:00
tsmith@ramayana.hindu.god
10cab933b2 Merge tsmith@bk-internal.mysql.com:/home/bk/mysql-5.0
into  ramayana.hindu.god:/home/tsmith/m/bk/maint/50
2007-12-04 20:58:21 -07:00
gkodinov/kgeorge@magare.gmz
7b1f0820b8 Merge gkodinov@bk-internal.mysql.com:/home/bk/mysql-5.0-opt
into  magare.gmz:/home/kgeorge/mysql/autopush/B32268-5.0-opt
2007-11-26 13:35:38 +02:00
gkodinov/kgeorge@magare.gmz
430157e666 Merge gkodinov@bk-internal.mysql.com:/home/bk/mysql-5.0-opt
into  magare.gmz:/home/kgeorge/mysql/autopush/B30788-5.0-opt
2007-11-21 11:46:15 +02:00
gkodinov/kgeorge@magare.gmz
2e2ac428ae Bug #30788: Inconsistent retrieval of char/varchar
Index lookup does not always guarantee that we can
simply remove the relevant conditions from the WHERE
clause. Reasons can be e.g. conversion errors, 
partial indexes etc. 
The optimizer was removing these parts of the WHERE 
condition without any further checking.
This leads to "false positives" when using indexes.
Fixed by checking the index reference conditions
(using WHERE) when using indexes with sub-queries.
2007-11-21 11:40:05 +02:00
evgen@moonbone.local
12516abe61 sql_select.cc:
Additional stack check for the bug#31048.
2007-11-21 02:48:01 +03:00
gkodinov/kgeorge@magare.gmz
50d8511136 Bug #32268: Indexed queries give bogus MIN and MAX results
Loose index scan does the grouping so the temp table does 
not need to do it, even when sorting.
Fixed by checking if the grouping is already done before
doing sorting and grouping in a temp table and do only 
sorting.
2007-11-20 16:07:24 +02:00
tnurnberg@white.intern.koehntopp.de
3c0f1ef341 Merge tnurnberg@bk-internal.mysql.com:/home/bk/mysql-5.0-maint
into  mysql.com:/misc/mysql/24907/50-24907
2007-11-17 19:13:27 +01:00
tnurnberg@mysql.com/white.intern.koehntopp.de
6889c82997 Bug#24907: unpredictable (display) precission, if input precission increases
Server failed in assert() when we tried to create a DECIMAL() temp field
with a scale of more than the allowed 30. Now we limit the scale to the
allowed maximum. A truncation warning is thrown as necessary.
2007-11-17 19:05:31 +01:00
kaa@polly.(none)
7b38492a4c Merge polly.(none):/home/kaa/src/opt/bug32241/my50-bug29131
into  polly.(none):/home/kaa/src/opt/mysql-5.0-opt
2007-11-16 14:24:06 +03:00
kaa@polly.(none)
82125f281f Fix for bug #32241: memory corruption due to large index map in 'Range
checked for each record'

The problem was in incorrectly calculated length of the buffer used to
store a hexadecimal representation of an index map in
select_describe(). This could result in buffer overrun and stack
corruption under some circumstances.

Fixed by correcting the calculation.
2007-11-16 13:58:09 +03:00
gkodinov/kgeorge@magare.gmz
eea70871f1 Merge gkodinov@bk-internal.mysql.com:/home/bk/mysql-5.0-opt
into  magare.gmz:/home/kgeorge/mysql/autopush/B31562-5.0-opt
2007-11-13 19:00:45 +02:00
gkodinov/kgeorge@magare.gmz
3384d3e96c Bug #31562: HAVING and lower case
The columns in HAVING can reference the GROUP BY and 
SELECT columns. There can be "table" prefixes when
referencing these columns. And these "table" prefixes
in HAVING use the table alias if available.
This means that table aliases are subject to the same
storage rules as table names and are dependent on 
lower_case_table_names in the same way as the table 
names are.
Fixed by :
1. Treating table aliases as table names
and make them lowercase when printing out the SQL
statement for view persistence.
2. Using case insensitive comparison for table 
aliases when requested by lower_case_table_names
2007-11-13 11:39:52 +02:00
kaa@polly.(none)
bf2a90f14b Merge polly.(none):/home/kaa/src/opt/bug30666/my50-bug29131
into  polly.(none):/home/kaa/src/opt/mysql-5.0-opt
2007-11-12 12:29:20 +03:00
tnurnberg@white.intern.koehntopp.de
3847b1b2eb Merge tnurnberg@bk-internal.mysql.com:/home/bk/mysql-5.0-opt
into  mysql.com:/misc/mysql/31700/50-31700
2007-11-10 21:53:54 +01:00
kaa@polly.(none)
b745305b20 Merge polly.(none):/home/kaa/src/opt/bug32202/my50-bug26215
into  polly.(none):/home/kaa/src/opt/mysql-5.0-opt
2007-11-10 22:46:25 +03:00
tnurnberg@white.intern.koehntopp.de
4c1ff7b54b Merge tnurnberg@bk-internal.mysql.com:/home/bk/mysql-5.0-opt
into  mysql.com:/misc/mysql/31700/50-31700
2007-11-10 19:18:47 +01:00
tnurnberg@mysql.com/white.intern.koehntopp.de
8a5e621ff2 Bug#31700: thd->examined_row_count not incremented for 'const' type queries
UNIQUE (eq-ref) lookups result in table being considered as a "constant" table.
Queries that consist of only constant tables are processed in do_select() in a
special way that doesn't invoke evaluate_join_record(), and therefore doesn't
increase the counters join->examined_rows and join->thd->row_count.

The patch increases these counters in this special case.

NOTICE:
This behavior seems to contradict what the documentation says in Sect. 5.11.4:
"Queries handled by the query cache are not added to the slow query log, nor
are queries that would not benefit from the presence of an index because the
table has zero rows or one row."

No test case in 5.0 as issue shows only in slow query log, and other counters
can give subtly different values (with regard to counting in create_sort_index(),
synthetic rows in ROLLUP, etc.).
2007-11-10 18:29:13 +01:00
kaa@polly.(none)
8c19367881 Fix for bug #32202: ORDER BY not working with GROUP BY
The bug is a regression introduced by the fix for bug30596. The problem
was that in cases when groups in GROUP BY correspond to only one row,
and there is ORDER BY, the GROUP BY was removed and the ORDER BY
rewritten to ORDER BY <group_by_columns> without checking if the
columns in GROUP BY and ORDER BY are compatible. This led to
incorrect ordering of the result set as it was sorted using the
GROUP BY columns. Additionaly, the code discarded ASC/DESC modifiers
from ORDER BY even if its columns were compatible with the GROUP BY
ones.

This patch fixes the regression by checking if ORDER BY columns form a
prefix of the GROUP BY ones, and rewriting ORDER BY only in that case,
preserving the ASC/DESC modifiers. That check is sufficient, since the
GROUP BY columns contain a unique index.
2007-11-09 19:12:12 +03:00
kaa@polly.(none)
4aa0402224 Fix for bug #30666: Incorrect order when using range conditions on 2
tables or more

The problem was that the optimizer used the join buffer in cases when
the result set is ordered by filesort. This resulted in the ORDER BY
clause being ignored, and the records being returned in the order
determined by the order of matching records in the last table in join.

Fixed by relaxing the condition in make_join_readinfo() to take
filesort-ordered result sets into account, not only index-ordered ones.
2007-11-07 14:00:45 +03:00
gkodinov/kgeorge@magare.gmz
92a5605d43 Bug #31794: no syntax error on SELECT id FROM t HAVING count(*)>2
The HAVING clause is subject to the same rules as the SELECT list
about using aggregated and non-aggregated columns.
But this was not enforced when processing implicit grouping from
using aggregate functions.
Fixed by performing the same checks for HAVING as for SELECT.
2007-11-01 18:36:24 +02:00
gluh@eagle.(none)
237383f0fe Merge mysql.com:/home/gluh/MySQL/Merge/5.0
into  mysql.com:/home/gluh/MySQL/Merge/5.0-opt
2007-10-23 18:51:43 +05:00
holyfoot/hf@mysql.com/hfmain.(none)
9f323e1a3a type conversions fixed to avoid warnings on Windows 2007-10-23 14:27:11 +05:00
kaa@polly.(none)
3af902ec47 Merge polly.(none):/home/kaa/src/maint/bug31207/my50-bug31174
into  polly.(none):/home/kaa/src/maint/mysql-5.0-maint
2007-10-18 13:47:35 +04:00