Commit graph

2591 commits

Author SHA1 Message Date
Alexander Nozdrin
3cf6345535 Fix automerge: use 'thd->query()' instead of 'thd->query'. 2009-11-05 17:51:00 +03:00
Alexander Nozdrin
26fc558319 Auto-merge from mysql-5.1. 2009-11-05 15:13:16 +03:00
Alexander Nozdrin
411a6bfeb9 Auto-merge from mysql-next-mr. 2009-11-05 15:08:37 +03:00
Alexander Nozdrin
f51d08921a Auto-merge from mysql-5.1. 2009-11-05 12:37:26 +03:00
Alexander Nozdrin
e6fffedb27 Manual merge from mysql-5.1. 2009-11-05 12:23:55 +03:00
Alexander Nozdrin
5ae8ae3a8e Manual merge from mysql-5.1. 2009-11-05 12:20:41 +03:00
Konstantin Osipov
409160e466 A fix and a test case for
Bug#41756 "Strange error messages about locks from InnoDB".
      
In JT_EQ_REF (join_read_key()) access method, 
don't try to unlock rows in the handler, unless certain that 
a) they were locked
b) they are not used.

Unlocking of rows is done by the logic of the nested join loop,
and is unaware of the possible caching that the access method may
have. This could lead to double unlocking, when a row
was unlocked first after reading into the cache, and then 
when taken from cache, as well as to unlocking of rows which
were actually used (but taken from cache).
      
Delegate part of the unlocking logic to the access method,
and in JT_EQ_REF count how many times a record was actually 
used in the join. Unlock it only if it's usage count is 0.

Implemented review comments.
2009-11-03 20:45:52 +03:00
Konstantin Osipov
d2babeaf3a A fix and a test case for
Bug#41756 "Strange error messages about locks from InnoDB".

In JT_EQ_REF (join_read_key()) access method,
don't try to unlock rows in the handler, unless certain that
a) they were locked
b) they are not used.

Unlocking of rows is done by the logic of the nested join loop,
and is unaware of the possible caching that the access method may
have. This could lead to double unlocking, when a row
was unlocked first after reading into the cache, and then
when taken from cache, as well as to unlocking of rows which
were actually used (but taken from cache).

Delegate part of the unlocking logic to the access method,
and in JT_EQ_REF count how many times a record was actually
used in the join. Unlock it only if it's usage count is 0.

Implemented review comments.
2009-11-03 19:58:54 +03:00
Alexey Botchkov
567bf9d37c Bug#41371 Select returns 1 row with condition "col is not null and col is null"
For application compatibility reasons  MySQL converts "<autoincrement_column> IS NULL"
    predicates to "<autoincrement_column> = LAST_INSERT_ID()" in the first SELECT following an
    INSERT regardless of whether they're top level predicates or not. This causes wrong and
    obscure results when these predicates are combined with others on the same columns. Fixed
    by only doing the transformation on a single top-level predicate if a special SQL mode is
    turned on (sql_auto_is_null).
    Also made sql_auto_is_null off by default.

per-file comments:
  mysql-test/r/func_isnull.result
Bug#41371      Select returns 1 row with condition "col is not null and col is null"
    test result updated

  mysql-test/t/func_isnull.test
Bug#41371      Select returns 1 row with condition "col is not null and col is null"
    test case added

  sql/mysqld.cc
Bug#41371      Select returns 1 row with condition "col is not null and col is null"
    sql_auto_is_null now is OFF by default.

  sql/sql_select.cc
Bug#41371      Select returns 1 row with condition "col is not null and col is null"
    remove_eq_conds() split in two parts - one only checks the upper condition,
    the req_remove_eq_conds() recursively checks all the condition tree.

  mysql-test/extra/rpl_tests/rpl_insert_id.test
Bug#41371      Select returns 1 row with condition "col is not null and col is null"
        test fixed (set the sql_auto_is_null variable)

  mysql-test/r/mysqlbinlog.result
Bug#41371      Select returns 1 row with condition "col is not null and col is null"
        result updated

  mysql-test/r/mysqlbinlog2.result
Bug#41371      Select returns 1 row with condition "col is not null and col is null"
        result updated

  mysql-test/r/odbc.result
Bug#41371      Select returns 1 row with condition "col is not null and col is null"
        result updated

  mysql-test/r/query_cache.result
Bug#41371      Select returns 1 row with condition "col is not null and col is null"
        result updated

  mysql-test/r/user_var-binlog.result
Bug#41371      Select returns 1 row with condition "col is not null and col is null"
        result updated

  mysql-test/suite/binlog/r/binlog_row_ctype_ucs.result
Bug#41371      Select returns 1 row with condition "col is not null and col is null"
        result updated

  mysql-test/suite/binlog/r/binlog_stm_ctype_ucs.result
Bug#41371      Select returns 1 row with condition "col is not null and col is null"
        result updated

  mysql-test/suite/rpl/r/rpl_insert_id.result
Bug#41371      Select returns 1 row with condition "col is not null and col is null"
        result updated

  mysql-test/suite/rpl/r/rpl_row_mysqlbinlog.result
Bug#41371      Select returns 1 row with condition "col is not null and col is null"
        result updated

  mysql-test/suite/rpl/r/rpl_sp.result
Bug#41371      Select returns 1 row with condition "col is not null and col is null"
        result updated

  mysql-test/t/odbc.test
Bug#41371      Select returns 1 row with condition "col is not null and col is null"
        test fixed (set the sql_auto_is_null variable)
2009-11-03 17:54:41 +04:00
Davi Arnaut
9a08362897 Bug#48370: Absolutely wrong calculations with GROUP BY and decimal fields when using IF
Bug#45261: Crash, stored procedure + decimal

Revert fix for Bug#45261 due to unforeseen bugs.
2009-11-02 09:21:39 -02:00
Alexander Nozdrin
8c95f3c53b Manual merge from mysql-next-mr. 2009-11-02 14:10:04 +03:00
Sergei Golubchik
6eaf0b5acb backport of dbug extensions from 6.0:
function/ syntax
  glob(7) wildcards
  unit tests
2009-10-30 19:13:58 +01:00
Alexey Kopytov
695a6d41e2 Automerge. 2009-10-30 19:16:29 +03:00
Alexey Kopytov
b68ca5e88c Automerge. 2009-10-30 18:59:06 +03:00
Alexey Kopytov
23b05d0002 Bug #48131: crash group by with rollup, distinct, filesort,
with temporary tables

There were two problems the test case from this bug was
triggering:

1. JOIN::rollup_init() was supposed to wrap all constant Items
into another object for queries with the WITH ROLLUP modifier
to ensure they are never considered as constants and therefore
are written into temporary tables if the optimizer chooses to
employ them for DISTINCT/GROUP BY handling.

However, JOIN::rollup_init() was called before
make_join_statistics(), so Items corresponding to fields in
const tables could not be handled as intended, which was
causing all kinds of problems later in the query execution. In
particular, create_tmp_table() assumed all constant items
except "hidden" ones to be removed earlier by remove_const()
which led to improperly initialized Field objects for the
temporary table being created. This is what was causing crashes
and valgrind errors in storage engines.

2. Even when the above problem had been fixed, the query from
the test case produced incorrect results due to some
DISTINCT/GROUP BY optimizations being performed by the
optimizer that are inapplicable in the WITH ROLLUP case.

Fixed by disabling inapplicable DISTINCT/GROUP BY optimizations
when the WITH ROLLUP modifier is present, and splitting the
const-wrapping part of JOIN::rollup_init() into a separate
method which is now invoked after make_join_statistics() when
the const tables are already known.
2009-10-30 18:54:53 +03:00
Georgi Kodinov
a765de73fe merge 2009-10-30 16:13:13 +02:00
Georgi Kodinov
a0bea5eeb1 Bug #48291 : crash with row() operator,select into @var, and
subquery returning multiple rows

Error handling was missing when handling subqueires in WHERE 
and when assigning a SELECT result to a @variable.
This caused crash(es). 

Fixed by adding error handling code to both the WHERE 
condition evaluation and to assignment to an @variable.
2009-10-30 15:15:43 +02:00
Georgi Kodinov
e8c608fe72 merge 2009-10-30 11:56:32 +02:00
Georgi Kodinov
7ba875d6e6 Bug #48293: crash with procedure analyse, view with > 10 columns,
having clause...

The fix for bug 46184 was not very complete. It was not covering
views using temporary tables and multiple tables in a FROM clause.
Fixed by reverting the fix for 46184 and making a more general
check that is checking at the right execution stage and for all
of the non-supported cases.
Now PROCEDURE ANALYZE on non-top level SELECT is also forbidden.
Updated the analyse.test and subselect.test accordingly.
2009-10-30 11:40:44 +02:00
Georgi Kodinov
0dea5a630b merge 2009-10-30 10:03:18 +02:00
Georgi Kodinov
1d8cceae2b Bug #42116 : Mysql crash on specific query
Queries with nested outer joins may lead to crashes or 
bad results because an internal data structure is not handled
correctly.
The optimizer uses bitmaps of nested JOINs to determine
if certain table can be placed at a certain place in the
JOIN order.
It does maintain a bitmap describing in which JOINs 
last placed table is nested.
When it puts a table it makes sure the bit of every JOIN that
contains the table in question is set (because JOINs can be nested).
It does that by recursively setting the bit for the next enclosing
JOIN when this is the first table in the JOIN and recursively 
resetting the bit if it's the last table in the JOIN.
When it removes a table from the join order it should do the
opposite : recursively unset the bit if it's the only remaining 
table in this join and and recursively set the bit if it's removing
the last table of a JOIN.
There was an error in how the bits was set for the upper levels :
when removing a table it was setting the bit for all the enclosing 
nested JOINs even if there were more tables left in the current JOIN
(which practically means that the upper nested JOINs were not affected).
Fixed by stopping the recursion at the relevant level.
2009-10-29 17:24:29 +02:00
Tor Didriksen
dc2e363e57 Bug#48060 Memory leak - Item::val_bool() (item.cc:184) from optimizer_subquery grammar
Item_sum::set_aggregator() may be called multiple times during query preparation.
On subsequent calls: verify that the aggregator type is the same,
and re-use the existing Aggregator.
2009-10-28 11:07:30 +01:00
Georgi Kodinov
1bbd709725 merge 2009-11-10 12:59:02 +02:00
Georgi Kodinov
bb6b57043f merge 2009-11-10 10:58:43 +02:00
Alexey Kopytov
9674ef6809 Automerge. 2009-11-06 17:54:19 +03:00
Alexander Nozdrin
069d78c067 Merge from mysql-next-mr. 2009-10-23 15:22:21 +04:00
Sergey Glukhov
676c12e2d4 Bug#35428 When selecting from INFORMATION_SCHEMA tables, incomplete metadata
backport to Betony
2009-10-23 14:19:54 +05:00
Alexander Nozdrin
cec638b590 Automerge from mysql-next-mr. 2009-10-22 22:06:01 +04:00
Konstantin Osipov
d4632dff5a Backport of revno 2630.28.10, 2630.28.31, 2630.28.26, 2630.33.1,
2630.39.1, 2630.28.29, 2630.34.3, 2630.34.2, 2630.34.1, 2630.29.29,
2630.29.28, 2630.31.1, 2630.28.13, 2630.28.10, 2617.23.14 and
some other minor revisions.

This patch implements: 

WL#4264 "Backup: Stabilize Service Interface" -- all the
server prerequisites except si_objects.{h,cc} themselves (they can
be just copied over, when needed).

WL#4435: Support OUT-parameters in prepared statements.

(and all issues in the initial patches for these two
tasks, that were discovered in pushbuild and during testing).

Bug#39519: mysql_stmt_close() should flush all data
associated with the statement.

After execution of a prepared statement, send OUT parameters of the invoked
stored procedure, if any, to the client.

When using the binary protocol, send the parameters in an additional result
set over the wire.  When using the text protocol, assign out parameters to
the user variables from the CALL(@var1, @var2, ...) specification.

The following refactoring has been made:
  - Protocol::send_fields() was renamed to Protocol::send_result_set_metadata();
  - A new Protocol::send_result_set_row() was introduced to incapsulate
    common functionality for sending row data.
  - Signature of Protocol::prepare_for_send() was changed: this operation
    does not need a list of items, the number of items is fully sufficient.

The following backward incompatible changes have been made:
  - CLIENT_MULTI_RESULTS is now enabled by default in the client;
  - CLIENT_PS_MULTI_RESUTLS is now enabled by default in the client.
2009-10-22 00:02:06 +04:00
Ramil Kalimullin
256e3ec03b Fix for bug#47019: Assertion failed: 0, file .\rt_mbr.c,
line 138 when forcing a spatial index

Problem: "Spatial indexes can be involved in the search 
for queries that use a function such as MBRContains() 
or MBRWithin() in the WHERE clause".
Using spatial indexes for JOINs with =, <=> etc.
predicates is incorrect.

Fix: disable spatial indexes for such queries.
2009-10-21 14:04:08 +05:00
Ramil Kalimullin
51ff23f0f0 Autopush 2009-10-22 14:40:15 +05:00
Alexander Nozdrin
3fd2f50b6c Merge from mysql-trunk-merge. 2009-10-19 17:36:19 +04:00
Alexander Nozdrin
f3457a73d6 Merge from mysql-5.1. 2009-10-19 17:17:08 +04:00
Guilhem Bichot
b1f6a8e72f Back-port from 6.0 of the fix for
BUG#38049 "incorrect rows estimations with references from preceding table"
(from revid:sergefp@mysql.com-20090126194259-ue20il3qro529l4d).
Compared to 6.0 where EXPLAIN indicates "Using index condition", here in join_optimizer.result
we see "Using where"; it's normal; 6.0 shows the same if disabling Index Condition Pushdown.
2009-10-19 15:14:43 +02:00
Sergei Golubchik
ed8aaec764 Bug#34374 mysql generates incorrect warning
backport to next-mr
2009-10-19 15:13:45 +02:00
Evgeny Potemkin
14994d2148 Bug#30302: Tables that were optimized away are printed in the
EXPLAIN EXTENDED warning.

Query optimizer searches for the constant tables and optimizes them away. This
means that fields of such tables are substituted for their values and on later
phases they are treated as constants. After this constant tables are removed
from the query execution plan. Nevertheless constant tables were shown in 
the EXPLAIN EXTENDED warning thus producing query that might be not an
equivalent of the original query.
        
Now the print_join function skips all tables that were optimized away from
printing to the EXPLAIN EXTENDED warning. If all tables were optimized away it
produces the 'FROM dual' clause.
2009-10-19 15:13:26 +04:00
Konstantin Osipov
2b91a639cc Backport of:
----------------------------------------------------------
revno: 2630.22.11
committer: Konstantin Osipov <konstantin@mysql.com>
branch nick: mysql-6.0-records
timestamp: Mon 2008-08-11 16:40:09 +0400
message:
  Move read_record related functions to a new header - records.h
2009-10-16 19:58:26 +04:00
Konstantin Osipov
2ae359db4a Backport of:
----------------------------------------------------------
revno: 2630.13.6
committer: Konstantin Osipov <konstantin@mysql.com>
branch nick: mysql-6.0-3288
timestamp: Fri 2008-07-11 20:22:44 +0400
message:
  WL#3288, step 1: ensure that the SQL layer always closes an open
  cursor (rnd or index read) before closing a handler.
2009-10-16 18:37:43 +04:00
Konstantin Osipov
64dbe379d7 Backport of:
----------------------------------------------------------
revno: 2617.22.5
committer: Konstantin Osipov <kostja@sun.com>
branch nick: mysql-6.0-runtime
timestamp: Tue 2009-01-27 05:08:48 +0300
message:
  Remove non-prefixed use of HASH.
  Always use my_hash_init(), my_hash_inited(), my_hash_search(),
  my_hash_element(), my_hash_delete(), my_hash_free() rather
  than non-prefixed counterparts (hash_init(), etc).
  Remove the backward-compatible defines.
2009-10-14 20:37:38 +04:00
Jorgen Loland
a91b18262c Followup patch for BUG#47280
Temporary tables may set join->group to 0 even though there is 
grouping. Also need to test if sum_func_count>0 when JOIN::exec() 
decides whether to present results in a grouped manner.
2009-10-14 18:20:01 +02:00
Jorgen Loland
bf0aa2bd34 Bug#47280 - strange results from count(*) with order by multiple
columns without where/group
                     
Simple SELECT with implicit grouping used to return many rows if
the query was ordered by the aggregated column in the SELECT
list. This was incorrect because queries with implicit grouping
should only return a single record.
                              
The problem was that when JOIN:exec() decided if execution needed
to handle grouping, it was assumed that sum_func_count==0 meant
that there were no aggregate functions in the query. This
assumption was not correct in JOIN::exec() because the aggregate
functions might have been optimized away during JOIN::optimize().
                  
The reason why queries without ordering behaved correctly was
that sum_func_count is only recalculated if the optimizer chooses
to use temporary tables (which it does in the ordered case).
Hence, non-ordered queries were correctly treated as grouped.
                  
The fix for this bug was to remove the assumption that
sum_func_count==0 means that there is no need for grouping. This
was done by introducing variable "bool implicit_grouping" in the
JOIN object.
2009-10-14 10:46:50 +02:00
Alexander Nozdrin
ca08f10ccd Manual merge from mysql-trunk-merge. 2009-10-14 12:25:39 +04:00
Konstantin Osipov
ea6a22bfa8 Introduce thd->query_cache_tls (thread
local storage for query cache). 
We need more than one pointer in a thread to
represent the query cache and net->query_cache_query can not be used
any more (due to ABI compatibility issues and to different life
time of NET and THD).
This is a backport of the following patch from 6.0:
----------------------------------------------------------
revno: 2476.1157.2
committer: kostja@bodhi.(none)
timestamp: Sat 2007-06-16 13:29:24 +0400
2009-10-13 22:18:48 +04:00
Alexander Nozdrin
0f51423532 Merge from mysql-5.1. 2009-10-13 13:42:38 +04:00
Georgi Kodinov
5faf23bf55 Bug #43029: FORCE INDEX FOR ORDER BY is ignored when join
buffering is used

FORCE INDEX FOR ORDER BY now prevents the optimizer from 
using join buffering. As a result the optimizer can use
indexed access on the first table and doesn't need to 
sort the complete resultset at the end of the statement.
2009-10-07 18:03:42 +03:00
Alexey Kopytov
406e680b25 Automerge. 2009-10-30 19:16:25 +03:00
Georgi Kodinov
0213cd7976 merge 2009-09-28 16:48:40 +03:00
Georgi Kodinov
7aa8cd7a11 Ported WL#3220 to mysql-next-mr. 2009-09-28 10:21:25 +03:00
Sergey Glukhov
185698530e Bug#45989 memory leak after explain encounters an error in the query
the fix is reverted from 5.1, mysql-pe as 
unnecessary(no valgrind warnings there).
2009-09-23 13:40:33 +05:00
Georgi Kodinov
a31f655d82 Bug #47106: Crash / segfault on adding EXPLAIN to a non-crashing
query
      
The fix for bug 46749 removed the check for OUTER_REF_TABLE_BIT 
and substituted it for a check on the presence of 
Item_ident::depended_from.
Removing it altogether was wrong : OUTER_REF_TABLE_BIT should 
still be checked in addition to depended_from (because it's not 
set in all cases and doesn't contradict to the check of depended_from).
Fixed by returning the old condition back as a compliment to the 
new one.
2009-09-18 12:34:08 +03:00
Marc Alff
08ffe21317 Merge mysql-next-mr --> mysql-trunk-signal 2009-09-17 03:20:11 -06:00
Alexander Nozdrin
df0dcab437 Merge from mysql-5.1-bugteam. 2009-09-16 10:52:43 +04:00
Staale Smedseng
38b6d49e82 Bug #43414 Parenthesis (and other) warnings compiling MySQL
with gcc 4.3.2
      
This is the fifth patch cleaning up more GCC warnings about
variables used before initialized using the new macro
UNINIT_VAR().
2009-09-17 17:10:30 +02:00
Marc Alff
d5fd452d7c WL#2110 (SIGNAL)
WL#2265 (RESIGNAL)

Manual merge of SIGNAL and RESIGNAL to mysql-trunk-signal,
plus required dependencies.
2009-09-10 03:18:29 -06:00
Georgi Kodinov
3ec517416b automerge 2009-09-08 12:37:09 +03:00
Alexey Kopytov
97920d3ad9 Automerge. 2009-09-08 12:36:40 +04:00
Alexey Kopytov
f161723821 Bug #46159: simple query that never returns
The external 'for' loop in remove_dup_with_compare() handled 
HA_ERR_RECORD_DELETED by just starting over without advancing 
to the next record which caused an infinite loop. 
 
This condition could be triggered on certain data by a SELECT 
query containing DISTINCT, GROUP BY and HAVING clauses. 

Fixed remove_dup_with_compare() so that we always advance to 
the next record when receiving HA_ERR_RECORD_DELETED from 
rnd_next().
2009-09-06 00:42:17 +04:00
Sergey Glukhov
510eac6ec1 5.0-bugteam->5.1-bugteam merge 2009-09-04 12:39:56 +05:00
Sergey Glukhov
e1d49b8143 Bug#45989 memory leak after explain encounters an error in the query
Memory allocated in TMP_TABLE_PARAM::copy_field is not cleaned up.
The fix is to clean up TMP_TABLE_PARAM::copy_field array in JOIN::destroy.
2009-09-04 12:20:53 +05:00
Georgi Kodinov
acc76a97a0 Bug #46791: Assertion failed:(table->key_read==0),function unknown
function,file sql_base.cc

When uncacheable queries are written to a temp table the optimizer must 
preserve the original JOIN structure, because it is re-using the JOIN 
structure to read from the resulting temporary table.
This was done only for uncacheable sub-queries. 
But top level queries can also benefit from this mechanism, specially if 
they're using index access and need a reset.
Fixed by not limiting the saving of JOIN structure to subqueries
exclusively.
Added a new test file to extend the existing (large) subquery.test.
2009-09-03 18:03:46 +03:00
Georgi Kodinov
4adb05e282 automerge 2009-08-31 16:40:35 +03:00
Georgi Kodinov
8ca8f70daa Bug #46749: Segfault in add_key_fields() with outer subquery level
field references

This error requires a combination of factors : 
1. An "impossible where" in the outermost SELECT
2. An aggregate in the outermost SELECT
3. A correlated subquery with a WHERE clause that includes an outer 
field reference as a top level WHERE sargable predicate

When JOIN::optimize detects an "impossible WHERE" it will bail out
without doing the rest of the work and initializations. It will not
call make_join_statistics() as well.  And make_join_statistics fills 
in various structures for each table referenced.
When processing the result of the "impossible WHERE" the query must
send a single row of data if there are aggregate functions in it.
In this case the server marks all the aggregates as having received 
no rows and calls the relevant Item::val_xxx() method on the SELECT
list. However if this SELECT list happens to contain a correlated 
subquery this subquery is evaluated in a normal evaluation mode.
And if this correlated subquery has a reference to a field from the 
outermost "impossible where" SELECT the add_key_fields will mistakenly
consider the outer field reference as a "local" field reference when 
looking for sargable predicates.
But since the SELECT where the outer field reference refers to is not
completely initialized due to the "impossible WHERE" in this level
we'll get a NULL pointer reference.
Fixed by making a better condition for discovering if a field is "local"
to the SELECT level being processed. 
It's not enough to look for OUTER_REF_TABLE_BIT in this case since 
for outer references to constant tables the Item_field::used_tables() 
will return 0 regardless of whether the field reference is from the 
local SELECT or not.
2009-08-27 14:40:42 +03:00
Alexander Nozdrin
37072db77b Merge from mysql-5.1-bugteam 2009-08-26 19:43:32 +04:00
Davi Arnaut
31afccc407 Bug#45261: Crash, stored procedure + decimal
The problem was that creating a DECIMAL column from a decimal
value could lead to a failed assertion as decimal values can
have a higher precision than those attached to a table. The
assert could be triggered by creating a table from a decimal
with a large (> 30) scale. Also, there was a problem in
calculating the number of digits in the integral and fractional
parts if both exceeded the maximum number of digits permitted
by the new decimal type.

The solution is to ensure that truncation procedure is executed
when deducing a DECIMAL column from a decimal value of higher
precision. If the integer part is equal to or bigger than the
maximum precision for the DECIMAL type (65), the integer part
is truncated to fit and the fractional becomes zero. Otherwise,
the fractional part is truncated to fit into the space left
after the integer part is copied.

This patch borrows code and ideas from Martin Hansson's patch.
2009-08-24 16:47:08 -03:00
Guilhem Bichot
8d1fdf09bb merge of 5.1-main into mysql-trunk.
Changes to ha_innodb.cc are not propagated to plugin, they will come back
via Oracle/Innobase if needed.
2009-08-12 15:44:34 +02:00
Martin Hansson
5421a8e858 Bug#46454: MySQL wrong index optimisation leads to incorrect result & crashes
Problem 1:
When the 'Using index' optimization is used, the optimizer may still - after
cost-based optimization - decide to use another index in order to avoid using
a temporary table. But when this happens, the flag to the storage engine to 
read index only (not table) was still set. Fixed by resetting the flag in the 
storage engine and TABLE structure in the above scenario, unless the new index
allows for the same optimization.
Problem 2:
When a 'ref' access method was employed by cost-based optimizer, (when the column
is non-NULLable), it was assumed that it needed no initialization if 'quick' access
methods (since they are based on range scan). When ORDER BY optimization overrides 
the decision, however, it expects to have this initialized and hence crashes. 
Fixed in 5.1 (was fixed in 6.0 already) by initializing 'quick' even when there's 
'ref' access.
2009-08-07 13:51:40 +02:00
Guilhem Bichot
c5ab943afe Creation of mysql-trunk = {summit + "Innodb plugin replacing the builtin"}:
bzr branch mysql-5.1-performance-version mysql-trunk # Summit
cd mysql-trunk
bzr merge mysql-5.1-innodb_plugin # which is 5.1 + Innodb plugin 
bzr rm innobase # remove the builtin
Next step: build, test fixes.
2009-08-04 13:25:19 +02:00
Alexey Kopytov
97069a8154 Automerge. 2009-07-24 16:14:14 +04:00
Alexey Kopytov
ec7ea44541 Automerge. 2009-07-24 16:13:31 +04:00
Alexey Kopytov
64f6fb7c8f Manual merge. 2009-07-24 16:09:35 +04:00
Alexey Kopytov
c76f98a5f0 Bug #46075: Assertion failed: 0, file .\protocol.cc, line 416
In create_myisam_from_heap() mark all errors as fatal except 
HA_ERR_RECORD_FILE_FULL for a HEAP table.

Not doing so could lead to problems, e.g. in a case when a
temporary MyISAM table gets overrun due to its MAX_ROWS limit
while executing INSERT/REPLACE IGNORE ... SELECT. 
The SELECT execution was aborted, but the error was 
converted to a warning due to IGNORE clause, so neither 'ok' 
nor 'error' packet could be sent back to the client. This 
condition led to hanging client when using 5.0 server, or 
assertion failure in 5.1.
2009-07-24 15:50:45 +04:00
Georgi Kodinov
a304517894 automerge 2009-07-16 16:17:47 +03:00
Georgi Kodinov
127296601d Bug #46003 and bug #46034: backported the fixes from azalea. 2009-07-16 15:19:22 +03:00
Georgi Kodinov
d9e82ba86c Bug #36259 (Optimizing with ORDER BY) and bug#45828 (Optimizer won't
use partial primary key if another index can prevent filesort

The fix for bug #28404 causes the covering ordering indexes to be 
preferred unconditionally over non-covering and ref indexes.

Fixed by comparing the cost of using a covering index to the cost of
using a ref index even for covering ordering indexes.
Added an assertion to clarify the condition the local variables should
be in.
2009-07-07 15:52:34 +03:00
Alexey Kopytov
0c5207f52f Automerge. 2009-07-03 14:43:54 +04:00
Alexey Kopytov
c936b6444a Manual merge. 2009-07-03 14:36:04 +04:00
Alexey Kopytov
4692566f9e Bug #45262: Bad effects with CREATE TABLE and DECIMAL
Using DECIMAL constants with more than 65 digits in CREATE 
TABLE ... SELECT led to bogus errors in release builds or 
assertion failures in debug builds. 
 
The problem was in inconsistency in how DECIMAL constants and 
fields are handled internally. We allow arbitrarily long 
DECIMAL constants, whereas DECIMAL(M,D) columns are limited to 
M<=65 and D<=30. my_decimal_precision_to_length() was used in 
both Item and Field code and truncated precision to 
DECIMAL_MAX_PRECISION when calculating value length without 
adjusting precision and decimals. As a result, a DECIMAL 
constant with more than 65 digits ended up having length less 
than precision or decimals which led to assertion failures. 
 
Fixed by modifying my_decimal_precision_to_length() so that 
precision is truncated to DECIMAL_MAX_PRECISION only for Field 
object which is indicated by the new 'truncate' parameter. 
 
Another inconsistency fixed by this patch is how DECIMAL 
constants and expressions are handled for CREATE ... SELECT. 
create_tmp_field_from_item() (which is used for constants) was 
changed as a part of the bugfix for bug #24907 to handle long 
DECIMAL constants gracefully. Item_func::tmp_table_field() 
(which is used for expressions) on the other hand was still 
using a simplistic approach when creating a Field_new_decimal 
from a DECIMAL expression.
2009-07-03 11:41:19 +04:00
Evgeny Potemkin
0e64988a5e Bug#45266: Uninitialized variable lead to an empty result.
The TABLE::reginfo.impossible_range is used by the optimizer to indicate
that the condition applied to the table is impossible. It wasn't initialized
at table opening and this might lead to an empty result on complex queries:
a query might set the impossible_range flag on a table and when the query finishes,
all tables are returned back to the table cache. The next query that uses the table
with the impossible_range flag set and an index over the table will see the flag
and thus return an empty result.

The open_table function now initializes the TABLE::reginfo.impossible_range
variable.
2009-06-26 19:57:42 +00:00
Staale Smedseng
c429fac63c Merge from 5.0-bugteam 2009-06-17 16:56:44 +02:00
Staale Smedseng
30fccdaaae Bug #43414 Parenthesis (and other) warnings compiling MySQL
with gcc 4.3.2
      
Compiling MySQL with gcc 4.3.2 and later produces a number of 
warnings, many of which are new with the recent compiler
versions.
                  
This bug will be resolved in more than one patch to limit the
size of changesets. This is the second patch, fixing more
of the warnings.
2009-06-17 15:54:01 +02:00
Georgi Kodinov
3fe572dd06 automerge 2009-06-15 17:36:51 +03:00
Georgi Kodinov
b1560b9f2f Bug #44810: index merge and order by with low sort_buffer_size
crashes server!

The problem affects the scenario when index merge is followed by a filesort
and the sort buffer is not big enough for all the sort keys.
In this case the filesort function will read the data to the end through the 
index merge quick access method (and thus closing the cursor etc), 
but will leave the pointer to the quick select method in place.
It will then create a temporary file to hold the results of the filesort and
will add it as a sort output file (in sort.io_cache).
Note that filesort will copy the original 'sort' structure in an automatic
variable and restore it after it's done.
As a result at exiting filesort() we have a sort.io_cache filled in and 
nothing else (as a result of close of the cursors at end of reading data 
through index merge).
Now create_sort_index() will note that there is a select and will clean it up
(as it's been used already by filesort() reading the data in). While doing that
a special case in the index merge destructor will clean up the sort.io_cache,
assuming it's an output of the index merge method and is not needed anymore.
As a result the code that tries to read the data back from the filesort output 
will get no data in both memory and disk and will crash.
      
Fixed similarly to how filesort() does it : by copying the sort.io_cache structure
to a local variable, removing the pointer to the io_cache (so that it's not freed 
by QUICK_INDEX_MERGE_SELECT::~QUICK_INDEX_MERGE_SELECT) and restoring the original 
structure (together with the valid pointer) after the cleanup is done.
This is a safe thing to do because all the structures are already cleaned up by
hitting the end of the index merge's read method (QUICK_INDEX_MERGE_SELECT::get_next()) 
and the cleanup code being written in a way that tolerates repeating cleanups.
2009-06-15 16:38:15 +03:00
Mikael Ronstrom
506c7fd47d Merge MySQL 5.1.35 into MySQL 5.4 2009-06-11 12:07:59 +02:00
Staale Smedseng
e6e1f4ac84 Bug #43414 Parenthesis (and other) warnings compiling MySQL
with gcc 4.3.2

Compiling MySQL with gcc 4.3.2 and later produces a number of 
warnings, many of which are new with the recent compiler
versions.
            
This bug will be resolved in more than one patch to limit the
size of changesets. This is the second patch, fixing more
of the warnings.
2009-06-10 16:04:07 +02:00
Gleb Shchepa
eecf06873e Bug #44886: SIGSEGV in test_if_skip_sort_order() -
uninitialized variable used as subscript

Grouping select from a "constant" InnoDB table (a table
of a single row) joined with other tables caused a crash.
2009-06-08 01:40:53 +05:00
Tatiana A. Nurnberg
640b7cd6e2 auto-merge 2009-06-05 01:30:08 +02:00
Tatiana A. Nurnberg
b89d2fce58 Bug#32149: Long semaphore wait for adaptive hash latch
Holding on to the temporary inno hash index latch is an optimization in
many cases, but a pessimization in some others.

Release temporary latches for those corner cases we (or rather, or customers,
thanks!) have identified, that is, when we are about to do something that
might take a really long time, like REPAIR or filesort.
2009-06-05 00:23:08 +02:00
Georgi Kodinov
8fb82e3fe0 Bug #44399 : crash with statement using TEXT columns, aggregates, GROUP BY, and
HAVING
            
When calculating GROUP BY the server caches some expressions. It does
that by allocating a string slot (Item_copy_string) and assigning the 
value of the expression to it. This effectively means that the result
type of the expression can be changed from whatever it was to a string.
As this substitution takes place after the compile-time result type 
calculation for IN but before the run-time type calculations, 
it causes the type calculations in the IN function done at run time 
to get unexpected results different from what was prepared at compile time.
                  
In the CASE ... WHEN ... THEN ... statement there was a similar problem
and it was solved by artificially adding a STRING argument to the set of 
types of the IN/CASE arguments at compile time, so if any of the 
arguments of the CASE function changes its type to a string it will 
still be covered by the information prepared at compile time.
2009-05-25 11:00:40 +03:00
Georgi Kodinov
803ce846a3 merged 5.0-main -> 5.0-bugteam 2009-05-15 12:29:41 +03:00
Gleb Shchepa
fbb96b339a Bug #44290: explain crashes for subquery with distinct in
SQL_SELECT::test_quick_select

The crash was caused by an incomplete cleanup of JOIN_TAB::select
during the filesort of rows for GROUP BY clause inside a subquery.
Queries where a quick index access is replaced with filesort was
was affected. For example:

  SELECT 1 FROM
    (SELECT COUNT(DISTINCT c1) FROM t1
       WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x

Quick index access related data in the SQL_SELECT::test_quick_select
function was inconsistent after an incomplete cleanup.
This function has been completed to prevent crashes in the
SQL_SELECT::test_quick_select function.
2009-05-13 12:51:39 +05:00
Gleb Shchepa
2121599d38 Bug #44290: explain crashes for subquery with distinct in
SQL_SELECT::test_quick_select

The crash was caused by an incomplete cleanup of JOIN_TAB::select
during the filesort of rows for GROUP BY clause inside a subquery.
Queries where a quick index access is replaced with filesort was
was affected. For example:

  SELECT 1 FROM
    (SELECT COUNT(DISTINCT c1) FROM t1
       WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x

Quick index access related data in the SQL_SELECT::test_quick_select
function was inconsistent after an incomplete cleanup.
This function has been completed to prevent crashes in the
SQL_SELECT::test_quick_select function.
2009-05-12 22:42:31 +05:00
Chad MILLER
128afdc3e5 Merge community up to enterprise, thus ending the community-server
adventure.
2009-05-06 09:06:32 -04:00
Martin Hansson
ce10b71bc9 Bug#44306: Assertion fail on duplicate key error in
'INSERT ... SELECT' statements

Merge
2009-05-04 14:57:42 +02:00
Martin Hansson
8fa68f5719 Bug#44306: Assertion fail on duplicate key error in
'INSERT ... SELECT' statements
            
The code that produces result rows expected that a duplicate row
error could not occur in INSERT ... SELECT statements with 
unfulfilled WHERE conditions. This may happen, however, if the 
SELECT list contains only aggregate functions.
Fixed by checking if an error occured before trying to send EOF
to the client.
2009-05-04 14:45:36 +02:00
Gleb Shchepa
0fc6777ce7 auto-upmerge 5.0-bugteam --> 5.1-bugteam (bug 37362) 2009-05-01 00:27:10 +05:00
Gleb Shchepa
480fac6107 Bug #37362: Crash in do_field_eq
EXPLAIN EXTENDED of nested query containing a error:

   1054 Unknown column '...' in 'field list'

may cause a server crash.


Parse error like described above forces a call to
JOIN::destroy() on malformed subquery.
That JOIN::destroy function closes and frees temporary
tables. However, temporary fields of these tables
may be listed in st_select_lex::group_list of outer
query, and that st_select_lex may not cleanup them
properly. So, after the JOIN::destroy call that
st_select_lex::group_list may have Item_field
objects with dangling pointers to freed temporary
table Field objects. That caused a crash.
2009-05-01 00:20:37 +05:00
Alexey Botchkov
08690ef254 merging 2009-04-29 07:59:10 +05:00
Alexey Botchkov
8dafd2b95d merging 2009-04-28 14:48:54 +05:00
Chad MILLER
978e8e06b0 Merge 5.0.80 release and 5.0 community. Version left at 5.0.80. 2009-04-14 13:20:13 -04:00
Gleb Shchepa
323609688b Backport bug #37348 fix 5.1 --> 5.0.
Original commentary:

Bug #37348: Crash in or immediately after JOIN::make_sum_func_list
            
The optimizer pulls up aggregate functions which should be aggregated in
an outer select. At some point it may substitute such a function for a field
in the temporary table. The setup_copy_fields function doesn't take this
into account and may overrun the copy_field buffer.
            
Fixed by filtering out the fields referenced through the specialized
reference for aggregates (Item_aggregate_ref).
Added an assertion to make sure bugs that cause similar discrepancy 
don't go undetected.
2009-04-01 16:02:26 +05:00
Ignacio Galarza
e82390130e auto-merge 2009-03-19 09:44:58 -04:00
Tatiana A. Nurnberg
333d4d6c4f auto-merge 2009-03-18 13:31:35 +01:00
Ramil Kalimullin
7178e47a3c Code clean-up. 2009-03-17 11:04:15 +04:00
Ramil Kalimullin
0a05053593 Fix for bug #42957: no results from
select where .. (col=col and col=col) or ... (false expression)

Problem: optimizer didn't take into account a singular case 
when we eliminated all the predicates at the AND level of WHERE.
That may lead to wrong results.

Fix: replace (a=a AND a=a...) with TRUE if we eliminated all the
predicates.
2009-03-16 09:02:10 +04:00
Tatiana A. Nurnberg
727cad6c2a Bug#36751: Segmentation fault in ctype-bin.c:308; Linux 86_64, with-max-indexes=128
mysqld is optimized for the default
case (up to 64-indices); for a greater
number of indices it goes through a
different code path. As that code-path
is a compile-time option and can not
easily be covered in standard tests,
bitrot occurred. key-fields need an
explicit initialization in the non-
optimized case; this setup was
presumably not added when a new key-
vector was added.

Changeset adds the necessary
initialisations.

No test case added due to dependence
on compile-time option.
2009-03-11 19:09:56 +01:00
Georgi Kodinov
40619ea311 merged 5.0-bugteam -> 5.1-bugteam 2009-02-19 20:30:05 +02:00
Georgi Kodinov
b2c161c192 Bug #42419: Server crash with "Pure virtual method called" on two concurrent
connections
The problem is that tables can enter open table cache for a thread without 
being properly cleaned up. This can happen if make_join_statistics() fails 
to read a const table because of e.g. a deadlock. It does set a member of 
TABLE structure to a value it allocates, but doesn't clean-up this setting 
on error nor does it set the rest of the members in JOIN to allow for 
automatic cleanup.
As a result when such an error occurs and the next statement depends re-uses 
the table from the open tables cache it will get it with this 
TABLE::reginfo.join_tab pointing to a memory area that's freed.
Fixed by making sure make_join_statistics() cleans up TABLE::reginfo.join_tab 
on error.
2009-02-19 17:30:03 +02:00
Mikael Ronstrom
dd9119be20 Merged Performance Version 0.2.1 with latest 5.1 tree (last push 11 feb 14.01.13 2009) 2009-02-17 13:24:09 +01:00
Ignacio Galarza
2b85c64d65 Bug#29125 Windows Server X64: so many compiler warnings
- Remove bothersome warning messages.  This change focuses on the warnings 
that are covered by the ignore file: support-files/compiler_warnings.supp.
- Strings are guaranteed to be max uint in length
2009-02-10 17:47:54 -05:00
Gleb Shchepa
49a35c6678 automerge 5.0-bugteam --> 5.1-bugteam (bug 42037) 2009-02-05 13:37:06 +04:00
Gleb Shchepa
23fb47a3ad Bug #42037: Queries containing a subquery with DISTINCT and
ORDER BY could cause a server crash

Dependent subqueries like

  SELECT COUNT(*) FROM t1, t2 WHERE t2.b
   IN (SELECT DISTINCT t2.b FROM t2 WHERE t2.b = t1.a)

caused a memory leak proportional to the
number of outer rows.


The make_simple_join() function has been modified to
JOIN class method to store join_tab_reexec and
table_reexec values in the parent join only
(make_simple_join of tmp_join may access these values
via 'this' pointer of the parent JOIN).

NOTE: this patch doesn't include standard test case (this is
"out of memory" bug). See bug #42037 page for test cases.
2009-02-05 13:30:39 +04:00
Gleb Shchepa
64c0951fde automerge 5.0-bugteam --> 5.1-bugteam (bug 39069) 2009-01-28 22:48:41 +04:00
Gleb Shchepa
b41c1a45f1 Bug #39069: <row constructor> IN <table-subquery> seriously
messed up

"ROW(...) IN (SELECT ... FROM DUAL)" always returned TRUE.

Item_in_subselect::row_value_transformer rewrites "ROW(...)
IN SELECT" conditions into the "EXISTS (SELECT ... HAVING ...)"
form.
For a subquery from the DUAL pseudotable resulting HAVING
condition is an expression on constant values, so further
transformation with optimize_cond() eliminates this HAVING
condition and resets JOIN::having to NULL.
Then JOIN::exec treated that NULL as an always-true-HAVING
and that caused a bug.

To distinguish an optimized out "HAVING TRUE" clause from
"HAVING FALSE" we already have the JOIN::having_value flag.
However, JOIN::exec() ignored JOIN::having_value as described
above as if it always set to COND_TRUE.

The JOIN::exec method has been modified to take into account
the value of the JOIN::having_value field.
2009-01-28 22:46:45 +04:00
Chad MILLER
f68ccd024a Merge from Tim's 5.0.76-release tree to make 5.0.77 . 2009-01-21 13:45:23 -05:00
Georgi Kodinov
e5dd9c5a1d merged 5.0-bugteam -> 5.1-bugtteam 2009-01-16 12:45:17 +02:00
Georgi Kodinov
7a6dda5077 merged Bug 38795 to 5.0-bugteam 2009-01-15 16:15:38 +02:00
Georgi Kodinov
83823a1477 Bug #38795: Automatic search depth and nested join's results in server crash
The greedy optimizer tracks the current level of nested joins and the position
inside these by setting and maintaining a state that's global for the whole FROM
clause.
This state was correctly maintained inside the selection of the next partial plan
table (in best_extension_by_limited_search()). 
greedy_search() also moves the current position by adding the last partial match 
table when there's not enough tables in the partial plan found by 
best_extension_by_limited_search().
This may require update of the global state variables that describe the current
position in the plan if the last table placed by greedy_search is not a top-level 
join table.
Fixed by updating the state after placing the partial plan table in greedy_search()
in the same way this is done on entering the best_extension_by_limited_search().
Fixed the signature of the function called to update the state : 
check_interleaving_with_nj
2009-01-13 13:09:12 +02:00
Georgi Kodinov
8c25823f94 merged 5.1-main -> 5.1-bugteam 2009-01-05 18:10:20 +02:00
Sergey Glukhov
5ac5774977 5.0-bugteam->5.1-bugteam merge 2008-12-24 19:26:48 +04:00
Sergey Glukhov
a31795b82d Bug#40953 SELECT query throws "ERROR 1062 (23000): Duplicate entry..." error
Table could be marked dependent because it is
either 1) an inner table of an outer join, or 2) it is a part of
STRAIGHT_JOIN. In case of STRAIGHT_JOIN table->maybe_null should not
be assigned. The fix is to set st_table::maybe_null to 'true' only
for those tables which are used in outer join.
2008-12-24 19:24:11 +04:00
Mikael Ronstrom
460cde4c6e Merge dtrace patch with latest performance version 2008-12-20 11:53:27 +01:00
Mikael Ronstrom
16a024c486 Backport of DTrace patches from 6.0 2008-12-20 11:01:41 +01:00
Chad MILLER
1c73da70ce Merged from 5.0 (enterprise). 2008-12-17 15:01:34 -05:00
Mikael Ronstrom
cb52ac91da Merge latest 5.1 into performance version 2008-12-15 09:47:39 +01:00
Joerg Bruehe
c7d03ca35b Merge main 5.1 into 5.1-build 2008-12-10 21:14:50 +01:00
Sergey Glukhov
50f4e85720 5.0-bugteam->5.1-bugteam merge 2008-12-10 18:16:21 +04:00
Sergey Glukhov
2b64acde8b Bug#37956 memory leak and / or crash with geometry and prepared statements!
Bug#37671 crash on prepared statement + cursor + geometry + too many open files!
if mysql_execute_command() returns error then free materialized_cursor object.
is_rnd_inited is added to satisfy rnd_end() assertion
(handler may be uninitialized in some cases)
2008-12-10 18:13:11 +04:00
Georgi Kodinov
d506265f2c backported the fix for bug #34773 to 5.0 2008-12-09 20:35:02 +02:00
Sergey Glukhov
ed61dee680 5.0-bugteam->5.1-bugteam merge 2008-12-09 17:31:22 +04:00
Sergey Glukhov
c5c64a30d4 Bug#31399 Wrong query result when doing join buffering over BIT fields
if table has bit fields then uneven bits(if exist) are stored into null bits place.
So we need to copy null bits in case of uneven bit field presence.
2008-12-09 16:59:47 +04:00
Mikael Ronstrom
2ed1383f6b call ha_release_temporary_latches to fix bug 32149 2008-12-04 16:03:02 +01:00
timothy.smith@sun.com
abd8574914 Merge from mysql-5.1.30-release 2008-11-27 00:02:10 +01:00
Georgi Kodinov
9eec8375f6 merged bug 39656 to 5.1-bugteam 2008-11-24 18:00:09 +02:00
Georgi Kodinov
f0d5f30ccf Bug #39656: Behaviour different for agg functions with & without where -
ONLY_FULL_GROUP_BY

The check for non-aggregated columns in queries with aggregate function, but without
GROUP BY was treating all the parts of the query as if they are in the SELECT list.
Fixed by ignoring the non-aggregated fields in the WHERE clause.
2008-11-24 17:30:47 +02:00
Alexey Botchkov
52989c445f Bug#25058 ignored return codes in memory allocation functions
memory allocation error checks added for functions
   calling insert_dynamic()

per-file messages:
  myisam/mi_delete.c
Bug#25058 ignored return codes in memory allocation functions
    out-of-memory errors handled
  myisam/mi_write.c
Bug#25058 ignored return codes in memory allocation functions
    out-of-memory errors handled
  server-tools/instance-manager/instance_options.cc
Bug#25058 ignored return codes in memory allocation functions
    out-of-memory errors handled
  sql/slave.cc
Bug#25058 ignored return codes in memory allocation functions
    out-of-memory errors handled
  sql/sp_head.cc
Bug#25058 ignored return codes in memory allocation functions
    out-of-memory errors handled
  sql/sp_head.h
Bug#25058 ignored return codes in memory allocation functions
    out-of-memory errors handled
  sql/sp_pcontext.cc
Bug#25058 ignored return codes in memory allocation functions
    out-of-memory errors handled
  sql/sp_pcontext.h
Bug#25058 ignored return codes in memory allocation functions
    out-of-memory errors handled
  sql/sql_select.cc
Bug#25058 ignored return codes in memory allocation functions
    out-of-memory errors handled
  sql/sql_yacc.yy
Bug#25058 ignored return codes in memory allocation functions
    out-of-memory errors handled
2008-11-21 17:38:42 +04:00
Build Team
366adeab08 Added "Sun Microsystems, Inc." to copyright headers on files modified
since Oct 1st
2008-11-10 21:21:49 +01:00
Georgi Kodinov
34d993ac49 merged 5.0 bug 33811 -> 5.1 bug 33811 working tree 2008-11-03 12:40:58 +02:00
Georgi Kodinov
ccef156af4 merged 5.0-bugteam -> bug 33811-5.0-bugteam working tree 2008-11-03 11:50:32 +02:00
Georgi Kodinov
a0e3001cdb Bug #33811: Call to stored procedure with SELECT * / RIGHT JOIN
fails after the first time
  
Two separate problems : 
  1. When flattening joins the linked list used for name resolution 
  (next_name_resolution_table) was not updated.
  Fixed by updating the pointers when extending the table list
  
  2. The items created by expanding a * (star) as a column reference
  were marked as fixed, but no cached table was assigned to them 
  (unlike what Item_field::fix_fields does).
  Fixed by assigning a cached table (so the re-preparation is done
  faster).
  
Note that the fix for #2 hides the fix for #1 in most cases
(except when a table reference cannot be cached).
2008-10-17 17:55:06 +03:00
Gleb Shchepa
56aa88b346 merge 5.0-bugteam --> 5.1-bugteam (bug 39844) 2008-10-16 23:04:31 +05:00
Gleb Shchepa
c411a11e5c Bug #39844: Query Crash Mysql Server 5.0.67
Server crashed during a sort order optimization
of a dependent subquery:

SELECT
    (SELECT t1.a FROM t1, t2
      WHERE t1.a = t2.b AND t2.a = t3.c
      ORDER BY t1.a)
  FROM t3;


Bitmap of tables, that the reference to outer table
column uses, in addition to the regular table bit
has the OUTER_REF_TABLE_BIT bit set.
The only_eq_ref_tables function traverses this map
bit by bit simultaneously with join->map2table list.
Obviously join->map2table never contains an entry
for the OUTER_REF_TABLE_BIT pseudo-table, so the
server crashed there.


The only_eq_ref_tables function has been modified
to traverse regular table bits only like the
update_depend_map function (resetting of the
OUTER_REF_TABLE_BIT there is enough, but
resetting of the whole set of PSEUDO_TABLE_BITS
is used there for sure).
2008-10-16 21:37:17 +05:00
Georgi Kodinov
e142ffdea1 merged 5.1-bugteam -> bug 34773 tree 2008-10-10 16:07:53 +03:00
Gleb Shchepa
fe3aee301d automerge 5.0-bugteam --> 5.1-bugteam 2008-10-10 16:44:10 +05:00
Gleb Shchepa
e7520c4b7e Bug #39283: Date returned as VARBINARY to client for queries
with COALESCE and JOIN

The server returned to a client the VARBINARY column type
instead of the DATE type for a result of the COALESCE,
IFNULL, IF, CASE, GREATEST or LEAST functions if that result
was filesorted in an anonymous temporary table during
the query execution.

For example:
  SELECT COALESCE(t1.date1, t2.date2) AS result
    FROM t1 JOIN t2 ON t1.id = t2.id ORDER BY result;


To create a column of various date/time types in a
temporary table the create_tmp_field_from_item() function
uses the Item::tmp_table_field_from_field_type() method
call. However, fields of the MYSQL_TYPE_NEWDATE type were
missed there, and the VARBINARY columns were created
by default.
Necessary condition has been added.
2008-10-10 15:13:12 +05:00
Georgi Kodinov
b5f152dcd8 Bug#34773: query with explain extended and derived table / other table
crashes server

When creating temporary table that contains aggregate functions a 
non-reversible source transformation was performed to redirect aggregate
function arguments towards temporary table columns.
This caused EXPLAIN EXTENDED to fail because it was trying to resolve
references to the (freed) temporary table.
Fixed by preserving the original aggregate function arguments and
using them (instead of the transformed ones) for EXPLAIN EXTENDED.
2008-10-06 17:17:25 +03:00
Georgi Kodinov
452fed70eb Bug #37348: Crash in or immediately after JOIN::make_sum_func_list
The optimizer pulls up aggregate functions which should be aggregated in
an outer select. At some point it may substitute such a function for a field
in the temporary table. The setup_copy_fields function doesn't take this
into account and may overrun the copy_field buffer.
      
Fixed by filtering out the fields referenced through the specialized
reference for aggregates (Item_aggregate_ref).
Added an assertion to make sure bugs that cause similar discrepancy 
don't go undetected.
2008-10-02 17:44:49 +03:00
Georgi Kodinov
4c318bf6e8 merge 5.0-bugteam -> 5.1-bugteam 2008-08-28 12:54:50 +03:00
Georgi Kodinov
a320e8676e merged 5.1-bugteam into B37548 tree 2008-08-27 18:39:09 +03:00
Georgi Kodinov
3468f4b4b3 Bug#37548: result value erronously reported being NULL in certain subqueries
When switching to indexed ORDER BY we must be sure to reset the index read
flag if we are switching from a covering index to non-covering.
2008-08-27 18:19:22 +03:00
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
967586934c merged 5.0-bugteam to 5.1-bugteam 2008-08-19 15:21:18 +03: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
Chad MILLER
572a356617 Merge from 5.0-bugteam. 2008-08-15 15:30:17 -04: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
Georgi Kodinov
3d215551bb merged 34159 and 37662 5.0-bugteam->5.1-bugteam 2008-07-31 12:50:24 +03: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
19e2ed7642 Automerge 2008-07-17 22:28:42 +04:00
Georgi Kodinov
7f16afccfb merge of bug #37830 to 5.1 2008-07-17 18:51:24 +03:00
Georgi Kodinov
66d12592cb auto merged 5.0-bugteam to /Users/kgeorge/B37830-5.0-bugteam 2008-07-17 15:14:35 +03:00
Georgi Kodinov
59ab9a0872 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-16 12:31:50 +03:00
Sergey Petrunia
eb8d8d3e3a Merge fix for BUG#35478 into 5.1 2008-07-15 21:46:02 +04: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
Chad MILLER
dae4c823e9 Merge from 5.0 trunk. 2008-07-14 16:16:37 -04:00
Chad MILLER
c94a46240a Merge chunk from trunk. 2008-07-10 14:50:07 -04:00
Chad MILLER
06756c19c5 Merge chunk from trunk. 2008-07-10 14:47:53 -04:00
Gleb Shchepa
9d84892b23 auto merge from local tree 2008-06-27 23:54:16 +05:00
Gleb Shchepa
fc827ae387 Fixed bug #36632: SELECT DISTINCT from a simple view on an
InnoDB table, where all selected columns
                  belong to the same unique index key, returns
                  incorrect results

Server executes some queries via QUICK_GROUP_MIN_MAX_SELECT
(MIN/MAX optimization for queries with GROUP BY or DISTINCT
clause) and that optimization implies loose index scan, so all
grouping is done by the QUICK_GROUP_MIN_MAX_SELECT::get_next
method.

The server does not set the precomputed_group_by flag for some
QUICK_GROUP_MIN_MAX_SELECT queries and duplicates grouping by
call to the end_send_group function.

Fix: when the test_if_skip_sort_order function selects loose 
index scan as a best way to satisfy an ORDER BY/GROUP BY type
of query, the precomputed_group_by flag has been set to use 
end_send/end_write functions instead of end_send_group/
end_write_group functions.
2008-06-27 23:50:53 +05:00
Tatiana A. Nurnberg
d6c476b8c8 Fixed bug #37004.
The value of JOIN::tables must be set to 0 when there
is no matching min/max row.
2008-06-19 05:08:41 +02:00
gkodinov/kgeorge@magare.gmz
b98922b7cc Merge magare.gmz:/home/kgeorge/mysql/work/B36011-take2-5.0-bugteam
into  magare.gmz:/home/kgeorge/mysql/work/B36011-5.1-bugteam
2008-05-16 19:03:50 +03: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
sergefp@mysql.com
c21dbf27cf BUG#35850 "Performance regression in 5.1.23/5.1.24"
- Disable the "prefer full scan on clustered primary key over full scan
  of any secondary key" rule introduced by BUG#35850.
- Update test results accordingly 
(bk trigger: file this for BUG#35850)
2008-05-07 09:58:21 +04:00
igor@olga.mysql.com
cb9e855d9f Merge olga.mysql.com:/home/igor/mysql-5.1-bugteam
into  olga.mysql.com:/home/igor/dev-opt/mysql-5.1-bug35844
2008-04-24 14:19:44 -07:00
gshchepa/uchum@host.loc
cdd0428ac8 Merge host.loc:/home/uchum/work/5.0-bugteam
into  host.loc:/home/uchum/work/5.1-bugteam
2008-04-23 11:06:26 +05:00
igor@olga.mysql.com
b210e5df6d Fixed bug#35844.
The function test_if_skip_sort_order ignored any covering index used for ref
access of a table in a query with ORDER BY if this index was incompatible 
with the ORDER BY list and there was another covering index compatible with
this list. 
As a result sub-optimal execution plans were chosen for some queries with
ORDER BY clause.
2008-04-22 21:49:39 -07: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
gkodinov/kgeorge@magare.gmz
dd62320d0e Merge bk-internal:/home/bk/mysql-5.1
into  magare.gmz:/home/kgeorge/mysql/work/merge-build-5.1-bugteam
2008-03-31 10:40:39 +03: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
8fe48b6875 Merge moonbone.local:/work/27219-5.0-opt-mysql
into  moonbone.local:/work/27219-bug-5.1
2008-03-28 18:09:14 +03: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
jani@a88-113-38-195.elisa-laajakaista.fi
090d1396cf Merge a88-113-38-195.elisa-laajakaista.fi:/home/my/bk/mysql-5.1-main
into  a88-113-38-195.elisa-laajakaista.fi:/home/my/bk/mysql-5.1-marvel
2008-03-28 12:14:27 +02:00
gkodinov/kgeorge@magare.gmz
aab53be5c0 Merge gkodinov@bk-internal.mysql.com:/home/bk/mysql-5.1
into  magare.gmz:/home/kgeorge/mysql/work/merge-5.1-bugteam
2008-03-28 11:27:03 +02:00
gkodinov/kgeorge@magare.gmz
faaf239f87 Merge gkodinov@bk-internal.mysql.com:/home/bk/mysql-5.1-bugteam
into  magare.gmz:/home/kgeorge/mysql/autopush/B35206-5.1-bugteam
2008-03-28 09:51:06 +02:00
gkodinov/kgeorge@magare.gmz
cde380ea50 Bug #35206: select query result different if the key is indexed or not
The code for executing indexed ORDER BY was not setting all the 
internal fields correctly when selecting to execute ORDER BY over
and index.
Fixed by change the access method to one that will use the 
quick indexed access if one is selected while selecting indexed
ORDER BY.
2008-03-27 19:39:21 +02: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
57afe19c8b Merge host.loc:/home/uchum/work/5.0-opt
into  host.loc:/home/uchum/work/5.1-opt
2008-03-27 00:51:29 +04: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
kaa@kaamos.(none)
b753e4a02e Fix for bug #34928: Confusion by having Primary Key and Index
The bug is a regression introduced in 5.1 by the patch for bug28404.

Under some circumstances test_if_skip_sort_order() could leave some
data structures in an inconsistent state so that some parts of code
could assume the selected execution strategy for GROUP BY/DISTINCT as
a loose index scan (e.g. JOIN_TAB::is_using_loose_index_scan()), while
the actual strategy chosen was an ordered index scan, which led to
wrong data being returned.

Fixed test_if_skip_sort_order() so that when changing the type for a
join table, select->quick is reset not only for EXPLAIN, but for the 
actual join execution as well, to not confuse code that depends on its
value to determine the chosen GROUP BY/DISTINCT strategy.
2008-03-26 19:37:36 +03:00
jani@a88-113-38-195.elisa-laajakaista.fi
74cbd71e94 Merge a88-113-38-195.elisa-laajakaista.fi:/home/my/bk/mysql-5.1-main
into  a88-113-38-195.elisa-laajakaista.fi:/home/my/bk/mysql-5.1-marvel
2008-03-13 23:35:52 +02:00
kaa@kaamos.(none)
0a7052e4d3 Merge kaamos.(none):/data/src/mysql-5.1
into  kaamos.(none):/data/src/opt/mysql-5.1-opt
2008-03-12 11:19:46 +03:00
kaa@kaamos.(none)
7e365efa30 Merge kaamos.(none):/data/src/opt/mysql-5.0-opt
into  kaamos.(none):/data/src/opt/mysql-5.1-opt
2008-03-11 15:47:16 +03:00
jani@a88-113-38-195.elisa-laajakaista.fi
ab013df080 Merge a88-113-38-195.elisa-laajakaista.fi:/home/my/bk/mysql-5.1-main
into  a88-113-38-195.elisa-laajakaista.fi:/home/my/bk/mysql-5.1-marvel
2008-03-07 11:25:47 +02: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
6d24220689 Merge host.loc:/home/uchum/work/5.0-opt-34830
into  host.loc:/home/uchum/work/5.1-opt
2008-03-01 12:24:00 +04: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
anozdrin/alik@quad.
340906f46d Fix for Bug#30217: Views: changes in metadata behaviour
between 5.0 and 5.1.
  
The problem was that in the patch for Bug#11986 it was decided
to store original query in UTF8 encoding for the INFORMATION_SCHEMA.
This approach however turned out to be quite difficult to implement
properly. The main problem is to preserve the same IS-output after
dump/restore.
  
So, the fix is to rollback to the previous functionality, but also
to fix it to support multi-character-set-queries properly. The idea
is to generate INFORMATION_SCHEMA-query from the item-tree after
parsing view declaration. The IS-query should:
  - be completely in UTF8;
  - not contain character set introducers.
  
For more information, see WL4052.
2008-02-22 13:30:33 +03: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@hfmain.(none)
0c8df13cda Merge bk@192.168.21.1:mysql-5.1-opt
into  mysql.com:/home/hf/work/32942/my51-32942
2008-02-18 19:08:35 +04:00