Commit graph

27268 commits

Author SHA1 Message Date
Jon Olav Hauglid
5050cd7c89 Bug #37521 Row inserted through view not always visible in base
table immediately after

The problem was that rows inserted in a table by one connection was
not immediately visible if another connection queried the table,
even if the insert had committed.

The reason for the problem was that the server sent a status reply
to the client before it actually did the commit. Therefore it was
possible to get an OK from the server before the changes were made
permanent and visible to other connections.

This patch fixes the problem by not sending status messages to the
server until any changes made have been committed. No test case added
as reproducing the error requires very specific timing betweeen the
server and two or more clients.

This patch also fixes the following (duplicate) bugs:
Bug #29334 pseudo-finished SHOW GLOBAL STATUS
Bug #36618 myisam insert not immediately visible to select from another client
Bug #45864 insert on one connection, immediate query on another produces no result
Bug #51329 Inserts from one connection not immediately visible in second
           connection
Bug #41516 Assertion fails when error returned from
           handler::external_lock(thd, F_UNLCK)
2010-07-07 15:20:07 +02:00
Jon Olav Hauglid
ecfd9958a1 Bug #54401 assert in Diagnostics_area::set_eof_status , HANDLER
This assert checks that the server does not try to send EOF to the
client if there has been some error during processing. This to make
sure that the error is in fact sent to the client.

The problem was that any errors during processing of WHERE conditions
in HANDLER ... READ statements where not detected by the handler code.
The handler code therefore still tried to send EOF to the client,
triggering the assert. The bug was only noticeable in debug builds.

This patch fixes the problem by making sure that the handler code
checks for errors during condition processing and acts accordingly.
2010-07-05 13:59:34 +02:00
Dmitry Lenev
f84ec55e08 Another follow-up for 5.5 version of fix for bug#54360
"Deadlock DROP/ALTER/CREATE DATABASE with open HANDLER".

Fixes production build which was broken by the fix for
bug#54360 due to missing instantiation of some Hash_set 
template's methods.

Circumvent requirement of explicit instantiation of 
non-inline methods by making all Hash_set methods
inline.
2010-07-01 19:48:56 +04:00
Dmitry Lenev
8ad1aa562f A follow-up for 5.5 version of fix for bug#54360 "Deadlock
DROP/ALTER/CREATE DATABASE with open HANDLER".

Remove wait_for_condition() which became unused after 
database locks were replaced with MDL scoped locks.
If one needs functionality provided by this call one can 
always use THD::enter_cond()/exit_cond() methods.

Also removed an unused include from sql_db.cc and updated 
comment describing one of used includes to reflect current
situation.
2010-07-01 18:58:47 +04:00
Jon Olav Hauglid
41a3dfe490 A 5.5 version of the fix for Bug #54360 "Deadlock DROP/ALTER/CREATE
DATABASE with open HANDLER"

Remove LOCK_create_db, database name locks, and use metadata locks instead.
This exposes CREATE/DROP/ALTER DATABASE statements to the graph-based
deadlock detector in MDL, and paves the way for a safe, deadlock-free
implementation of RENAME DATABASE.

Database DDL statements will now take exclusive metadata locks on
the database name, while table/view/routine DDL statements take
intention exclusive locks on the database name. This prevents race
conditions between database DDL and table/view/routine DDL.
(e.g. DROP DATABASE with concurrent CREATE/ALTER/DROP TABLE)

By adding database name locks, this patch implements
WL#4450 "DDL locking: CREATE/DROP DATABASE must use database locks" and
WL#4985 "DDL locking: namespace/hierarchical locks".

The patch also changes code to use init_one_table() where appropriate.
The new lock_table_names() function requires TABLE_LIST::db_length to
be set correctly, and this is taken care of by init_one_table().

This patch also adds a simple template to help work with 
the mysys HASH data structure.

Most of the patch was written by Konstantin Osipov.
2010-07-01 15:53:46 +02:00
Jon Olav Hauglid
2fe246329f merge from mysql-trunk-bugfixing 2010-06-30 08:47:49 +02:00
Konstantin Osipov
cace7d3038 Salvage comments added by Ingo while working on
Bug#52114 and Bug#50788.
The bugs themselves are regressions that are introduced
by an incomplete fix for Bug#36171 and will not be pushed.
2010-06-29 18:28:36 +04:00
Konstantin Osipov
02599d659a A fix for Bug#54811 "Assert in mysql_lock_have_duplicate()".
Remove mysql_lock_have_duplicate(), since now we always
have TABLE_LIST objects for MyISAMMRG children
in lex->query_tables and keep it till the end of the
statement (sub-statement).
2010-06-29 18:01:33 +04:00
Gleb Shchepa
6941da5107 gcc warnings removal (after bugfix for bug 36569) 2010-06-26 02:06:53 +04:00
Alexander Nozdrin
514b9b25d2 Backport of revid:ingo.struewing@sun.com-20091223200354-r2uzbdkj2v6yv111
Bug#47633 - assert in ha_myisammrg::info during OPTIMIZE
 
   The server crashed on an attempt to optimize a MERGE table with
   non-existent child table.
 
   mysql_admin_table() relied on the table to be successfully open
   if a table object had been allocated.
 
   Changed code to check return value of the open function before
   calling a handler:: function on it.
2010-06-25 19:32:59 +04:00
Konstantin Osipov
e4557d6da6 Merge trunk -> trunk-runtime 2010-06-25 17:46:27 +04:00
Jon Olav Hauglid
80af13189f Bug #50124 Rpl failure on DROP table with concurrent txn/non-txn
DML flow and SAVEPOINT

The problem was that replication could break if a transaction involving
both transactional and non-transactional tables was rolled back to a
savepoint. It broke if a concurrent connection tried to drop a
transactional table which was locked after the savepoint was set.
This DROP TABLE completed when ROLLBACK TO SAVEPOINT was executed as the
lock on the table was dropped by the transaction. When the slave later
tried to apply the binlog, it would fail as the table would already
have been dropped.

The reason for the problem is that transactions involving both
transactional and non-transactional tables are written fully to the
binlog during ROLLBACK TO SAVEPOINT. At the same time, metadata locks
acquired after a savepoint, were released during ROLLBACK TO SAVEPOINT.
This allowed a second connection to drop a table only used between
SAVEPOINT and ROLLBACK TO SAVEPOINT. Which caused the transaction binlog
to refer to a non-existing table when it was written during ROLLBACK
TO SAVEPOINT.

This patch fixes the problem by not releasing metadata locks when
ROLLBACK TO SAVEPOINT is executed if binlogging is enabled.
2010-06-25 09:32:24 +02:00
Jon Olav Hauglid
9702d53ff8 Bug #53757 assert in mysql_truncate_by_delete
The assert was triggered if a connection executing TRUNCATE
on a InnoDB table was killed during open_tables.

This bug was fixed in the scope of Bug #45643
"InnoDB does not support replication of TRUNCATE TABLE".

This patch adds test coverage to innodb_mysql_sync.test.
2010-06-25 09:07:18 +02:00
Jon Olav Hauglid
be3005d9e7 Backport from mysql-6.0-codebase of:
------------------------------------------------------------
revno: 3672
committer: lars-erik.bjork@sun.com
branch nick: 48067-mysql-6.0-codebase-bugfixing
timestamp: Mon 2009-10-26 13:51:43 +0100
message:
  This is a patch for bug#48067
  "A temp table with the same name as an existing table, makes drop
  database fail"
        
  When dropping the database, mysql_rm_known_files() reads the contents
  of the database directory, and creates a TABLE_LIST object, for each
  .frm file encountered. Temporary tables, however, are not associated 
  with any .frm file.
        
  The list of tables to drop are passed to mysql_rm_table_part2().
  This method prefers temporary tables over regular tables, so if
  there is a temporary table with the same name as a regular, the
  temporary is removed, leaving the regular table intact.
  Regular tables are only deleted if there are no temporary tables
  with the same name.
        
  This fix ensures, that for all TABLE_LIST objects that are created
  by mysql_rm_known_files(), 'open_type' is set to 'OT_BASE_ONLY', to
  indicate that this is a regular table. In all cases in
  mysql_rm_table_part2() where we prefer a temporary table to a
  non-temporary table, we chek if 'open_type' equals 'OT_BASE_ONLY'.
2010-06-23 13:34:40 +02:00
Tor Didriksen
545d8a5b40 Backport of Bug#53236 Segfault in DTCollation::set(DTCollation&)
Don't call member functions for a NIL pointer.
2010-06-23 08:13:34 +02:00
Gleb Shchepa
da4d23277f Bug #30584: delete with order by and limit clauses does not
use limit efficiently
Bug #36569: UPDATE ... WHERE ... ORDER BY... always does a
            filesort even if not required

Also two bugs reported after QA review (before the commit
of bugs above to public trees, no documentation needed):

Bug #53737: Performance regressions after applying patch
            for bug 36569
Bug #53742: UPDATEs have no effect after applying patch
            for bug 36569


Execution of single-table UPDATE and DELETE statements did not use the 
same optimizer as was used in the compilation of SELECT statements. 
Instead, it had an optimizer of its own that did not take into account 
that you can omit sorting by retrieving rows using an index.

Extra optimization has been added: when applicable, single-table 
UPDATE/DELETE statements use an existing index instead of filesort. A 
corresponding SELECT query would do the former.

Also handling of the DESC ordering expression has been added when
reverse index scan is applicable.

From now on most single table UPDATE and DELETE statements show the 
same disk access patterns as the corresponding SELECT query. We verify 
this by comparing the result of SHOW STATUS LIKE 'Sort%

Currently the get_index_for_order function 
a) checks quick select index (if any) for compatibility with the
   ORDER expression list or
b) chooses the cheapest available compatible index, but only if 
   the index scan is cheaper than filesort.
Second way is implemented by the new test_if_cheaper_ordering
function (extracted part the test_if_skip_sort_order()).
2010-06-23 00:32:29 +04:00
Vladislav Vaintroub
1ef39ee2d1 Fix ~1000 warnings class/struct mismatch.
Handle this warning in the future as error, this will prevent pushing to main trees.
2010-06-22 18:40:14 +02:00
Alexander Nozdrin
bba0a92d03 Auto-merge from mysql-trunk-stage. 2010-06-21 17:08:16 +04:00
Konstantin Osipov
94174db16b A new implementation for the TABLE_SHARE cache in MDL
subsystem. Fix a number of caveates that the previous
implementation suffered from, including unprotected
access to shared data and lax resource accounting
(share->ref_count) that could lead to deadlocks.

The new implementation still suffers from a number
of potential deadlocks in some edge cases, and this is 
still not enabled by default. Especially since performance
testing has shown that it gives only marginable (not even 
exceeding measuring accuracy) improvements.

@todo: 
- Remove calls to close_cached_tables() with REFRESH_FAST,
and have_lock, because they break the MDL cache. 
- rework FLUSH TABLES <list> to not use close_cached_tables()
- make sure that whenever we set TABLE_SHARE::version to
0 we free MDL cache references to it.
2010-06-18 20:14:10 +04:00
Daniel Fischer
9891642e77 merge 2010-06-18 17:04:15 +02:00
Magne Mahre
3ac6a4b451 WL#5349 Change default storage engine to InnoDB
The default storage engine is changed from MyISAM to
InnoDB, in all builds except for the embedded server.

In addition, the following system variables are 
changed:

  * innodb_file_per_table is enabled
  * innodb_strict_mode is enabled
  * innodb_file_format_name_update is changed
    to 'Barracuda'

The test suite is changed so that tests that do not
explicitly include the have_innodb.inc are run with
--default-storage-engine=MyISAM.  This is to ease the
transition, so that most regression tests are run
with the same engine as before.

Some tests are disabled for the embedded server
regression test, as the output of certain statements
will be different that for the regular server
(i.e SELECT @@default_storage_engine).  This is to
ease transition.
2010-06-17 22:51:35 +02:00
Konstantin Osipov
95c86d14b5 Merge. 2010-06-17 17:55:00 +04:00
Konstantin Osipov
484351d108 Merge trunk-bugfixing -> trunk-runtime 2010-06-17 17:31:51 +04:00
Dmitry Lenev
451a3810ee Small clean-up and pre-requisite for making
TABLE_SHARE a class.

Remove unused members in TABLE_SHARE.
2010-06-16 13:04:30 +04:00
Alexey Kopytov
48c07a39c4 Bug#52208: gis fails on some platforms (Solaris, HP-UX, Linux)
On [Open]Solaris/x86 the FPU was not switched to 64-bit double
precision mode when the server binary was built with Sun
Studio. That caused GIS test failures due to differences in
expected and actual results.
2010-06-15 18:52:47 +04:00
Alexey Kopytov
6497bd3784 Backport of the patch for bug52208 to 5.1 since the
root cause of 52208 resulted in another test failure
in 5.1.
2010-06-15 18:29:53 +04:00
Alexey Kopytov
982c026282 Manual merge from mysql-5.1-bugteam.
conflicts:
   conflict      sql/sql_prepare.cc
2010-06-12 09:56:28 +04:00
Alexey Kopytov
13a43a1aac Addendum for the fix for bug #42064:
In Prepared_statement::prepare() bail out as soon as
parser_state.init() fails, trying to continue leads to crashes.
2010-06-12 09:52:31 +04:00
Alexey Kopytov
61aaf4edbb Fixed ha_ndbcluster_binlog.cc to use Parser_state::init(). 2010-06-12 00:35:28 +04:00
Alexey Kopytov
08f3b0ab92 Automerge. 2010-06-11 23:44:01 +04:00
Ramil Kalimullin
20e0a9ab8f Automerge. 2010-06-11 19:36:57 +04:00
Konstantin Osipov
b140456601 WL#5419 "LOCK_open scalability: make tdc_refresh_version
an atomic counter"

Split the large LOCK_open section in open_table(). 
Do not call open_table_from_share() under LOCK_open.
Remove thd->version.

This fixes
Bug#50589 "Server hang on a query evaluated using a temporary 
table"
Bug#51557 "LOCK_open and kernel_mutex are not happy together"
Bug#49463 "LOCK_table and innodb are not nice when handler 
instances are created".

This patch has effect on storage engines that rely on
ha_open() PSEA method being called under LOCK_open.
In particular:

1) NDB is broken and left unfixed. NDB relies on LOCK_open
being kept as part of ha_open(), since it uses auto-discovery.
While previously the NDB open code was race-prone, now
it simply fails on asserts.

2) HEAP engine had a race in ha_heap::open() when
a share for the same table could be added twice
to the list of shares, or a dangling reference to a share
stored in HEAP handler. This patch aims to address this
problem by 'pinning' the newly created share in the 
internal HEAP engine share list until at least one
handler instance is created using that share.
2010-06-11 19:28:18 +04:00
Ramil Kalimullin
d4746b8e84 Automerge. 2010-06-11 18:43:36 +04:00
Alexey Kopytov
eae3b4fe76 Manual merge from mysql-5.1-bugteam to mysql-trunk-merge.
conflicts:
   conflict      mysys/safemalloc.c
   conflict      sql/mysqld.cc
   conflict      sql/sp.cc
   conflict      sql/sql_lex.cc
   conflict      sql/sql_lex.h
   conflict      sql/sql_parse.cc
   conflict      sql/sql_prepare.cc
2010-06-11 17:48:24 +04:00
Alexey Kopytov
162e426238 Manual merge from the bugfix tree.
conflicts:
   conflict      sql/sql_parse.cc
2010-06-11 16:52:06 +04:00
Alexey Kopytov
b497e2c6b2 Manual merge from the bugfix tree.
conflicts:
   conflict      sql/sql_parse.cc
2010-06-11 14:51:21 +04:00
Martin Hansson
6d38a625c1 Merge of fix for bug#53859. 2010-06-11 10:15:55 +02:00
Martin Hansson
5bace3f049 Bug#53859: Valgrind: opt_sum_query(TABLE_LIST*, List<Item>&,
Item*) at opt_sum.cc:305
      
Queries applying MIN/MAX functions to indexed columns are
optimized to read directly from the index if all key parts
of the index preceding the aggregated key part are bound to
constants by the WHERE clause. A prefix length is also
produced, equal to the total length of the bound key
parts. If the aggregated column itself is bound to a
constant, however, it is also included in the prefix.

Such full search keys are read as closed intervals for
reasons beyond the scope of this bug. However, the procedure
missed one case where a key part meant for use as range
endpoint was being overwritten with a NULL value destined
for equality checking. In this case the key part was
overwritten but the range flag remained, causing open
interval reading to be performed.

Bug was fixed by adding more stringent checking to the
search key building procedure (matching_cond) and never
allow overwrites of range predicates with non-range
predicates.

An assertion was added to make sure open intervals are never
used with full search keys.
2010-06-11 09:38:29 +02:00
Davi Arnaut
d6e003545a Merge of mysql-5.1-bugteam into mysql-trunk-merge. 2010-06-10 22:30:49 -03:00
Davi Arnaut
53b8829682 Bug#42733: Type-punning warnings when compiling MySQL --
strict aliasing violations.

One somewhat major source of strict-aliasing violations and
related warnings is the SQL_LIST structure. For example,
consider its member function `link_in_list` which takes
a pointer to pointer of type T (any type) as a pointer to
pointer to unsigned char. Dereferencing this pointer, which
is done to reset the next field, violates strict-aliasing
rules and might cause problems for surrounding code that
uses the next field of the object being added to the list.

The solution is to use templates to parametrize the SQL_LIST
structure in order to deference the pointers with compatible
types. As a side bonus, it becomes possible to remove quite
a few casts related to acessing data members of SQL_LIST.
2010-06-10 17:45:22 -03:00
Davi Arnaut
bb036c93b4 Bug#42733: Type-punning warnings when compiling MySQL --
strict aliasing violations.

Essentially, the problem is that large parts of the server were
developed in simpler times (last decades, pre C99 standard) when
strict aliasing and compilers supporting such optimizations were
rare to non-existent. Thus, when compiling the server with a modern
compiler that uses strict aliasing rules to perform optimizations,
there are several places in the code that might trigger undefined
behavior.

As evinced by some recent bugs, GCC does a somewhat good of job
misoptimizing such code, but on the other hand also gives warnings
about suspicious code. One problem is that the warnings aren't
always accurate, yet we can't afford to just shut them off as we
might miss real cases. False-positive cases are aggravated mostly
by casts that are likely to trigger undefined behavior.

The solution is to start a cleanup process focused on fixing and
reducing the amount of strict-aliasing related warnings produced
by GCC and others compilers. A good deal of noise reduction can
be achieved by just removing useless casts that are product of
historical cruft and are likely to trigger undefined behavior if
dereferenced.
2010-06-10 17:16:43 -03:00
Konstantin Osipov
41d95c5049 A pre-requisite for WL#5419 "LOCK_open scalability:
make tdc_refresh_version an 
atomic counter".
Backport the trivial changes from mysql-trunk-iplus.
2010-06-10 15:43:32 +04:00
Konstantin Osipov
df9ab0ffea A pre-requisite patch for WL#5419 "LOCK_open scalability:
make tdc_refresh_version an atomic counter".

To avoid orphaned TABLE_SHARE objects left in the
cache, make sure that wherever we set table->s->version
we take care of removing all unused table share objects
from the table cache. 

Always set table->s->version under LOCK_open, to make sure
that no other connection sees an old value of the
version and adds the table to unused_tables list.

Add an assert to table_def_unuse_table() that we never
'unuse' a talbe of a share that has an old version.

With this patch, only three places are left in the code
that manipulate with table->s->version:
- tdc_remove_table(). In most cases we have an X mdl lock
in tdc_remove_table(), the two remaining cases when we
don't are 'FLUSH TABLE' and mysql_admin_table().
- sql_view.cc - a crude hack that needs a separate fix
- initial assignment from refresh_version in table.cc.
2010-06-10 15:31:19 +04:00
Ramil Kalimullin
3058f4a136 Fix for bug #54007: assert in ha_myisam::index_next, HANDLER
Problem: the server missed the fact that one can read from 
2 indexes alternately using HANDLER interface.

Fix: check if the same (initialized) index is involved
reading next/prev values from the index.
2010-06-09 14:45:04 +04:00
Georgi Kodinov
fdbef84347 merge 2010-06-09 11:41:24 +03:00
Konstantin Osipov
b976fb1444 A review comment for WL#4441 " LOCK_open: Remove requirement of
mutex protecting thd->open_tables".

We should not manipulate with table->s->version outside the 
table definition cache code, but use the TDC API
to achieve the desired result.

Fix one violation: close_all_tables_for_name().
2010-06-09 12:39:09 +04:00
Georgi Kodinov
5932330839 Merge 2010-06-09 11:29:27 +03:00
Magne Mahre
0cb90edfe5 Bug#20837 Apparent change of isolation level during transaction
Bug#46527 COMMIT AND CHAIN RELEASE does not make sense
Bug#53343 completion_type=1, COMMIT/ROLLBACK AND CHAIN don't 
          preserve the isolation level
Bug#53346 completion_type has strange effect in a stored 
          procedure/prepared statement

Added test cases to verify the expected behaviour of :
 SET SESSION TRANSACTION ISOLATION LEVEL, 
 SET TRANSACTION ISOLATION LEVEL,
 @@completion_type,
 COMMIT AND CHAIN,
 ROLLBACK AND CHAIN
 ..and some combinations of the above
2010-06-08 19:47:10 +02:00
Konstantin Osipov
85391c90ea Merge with trunk-runtime. 2010-06-08 16:20:15 +04:00
Kristofer Pettersson
8f4a33732a automerge 2010-06-08 13:50:54 +02:00