Commit graph

108 commits

Author SHA1 Message Date
vasil
69a2345cbb Implement INFORMATION_SCHEMA tables innodb_trx, innodb_locks,
innodb_lock_waits. See
https://svn.innodb.com/innobase/InformationSchema/TransactionsAndLocks
for design notes.

Things that need to be resolved before this goes live:
* MySQL must add thd_get_thread_id() function to their code
  http://bugs.mysql.com/30930
* Allocate memory from mem_heap instead of using mem_alloc()
* Copy table name and index name into the cache because they may be
  freed later which will result in referencing freed memory

Approved by:	Marko
2007-09-20 11:23:44 +00:00
marko
4a1d105a31 branches/zip: Merge 1830:1862 from trunk. 2007-09-20 08:36:22 +00:00
marko
5de8acee56 branches/zip: ha_innobase::add_index(): Translate DB_TOO_BIG_RECORD
via my_error().  Add a test case to innodb-index.test.
2007-09-17 10:43:51 +00:00
marko
21d303fed2 branches/zip: Move the code related to fast index creation
(smart ALTER TABLE) from ha_innodb.cc to a separate module, handler0alter.cc.
2007-09-13 09:31:54 +00:00
marko
e9276f80bc branches/zip: ha_innobase::add_index(): Fix a race condition that
existed before the fast-index-creation code was merged, in r1414.

Do not call row_prebuilt_table_obsolete(innodb_table) until after
the table has been renamed to a temporary name.  Otherwise, the
following could happen when creating a clustered index on table T:

(a1) copy T to T#1
(a2) mark T obsolete
(b1) add the name of T to the background drop list
(a3) rename T to T#2 and T#1 to T
(b2) drop the table on the background

These steps are executed by two threads, a and b.

If b1 is executed after a3, all is fine: the name T#2 will be added
to the background drop list.  If b1 is executed before a3, the name
T will be added, and T#2 will survive.
2007-09-11 06:20:19 +00:00
inaam
40381aed20 branches/zip: Undo changes commited in r1832.
These should have gone to branches/fts.

Spotted by: Marko and Ken
2007-09-11 00:41:02 +00:00
inaam
538665bc2e branches/zip: Enabled group commit functionality with XA.
Reviewed by: Heikki
2007-09-10 17:06:44 +00:00
marko
57afe1d5d2 branches/zip: Merge 1809:1830 from trunk. 2007-09-10 10:09:01 +00:00
marko
45b97e559f branches/zip: Decode table names when displaying error messages in
fast index creation.

innobase_convert_tablename(): New function, to remove the filename
encoding of a database and table name.

ha_innobase::add_index(): Invoke innobase_convert_tablename() before
calling my_error().

innodb-index.result: Update the error messages.
2007-09-07 09:05:52 +00:00
marko
c10625308b branches/zip: ha_innobase::add_index(): Allocate a new transaction for
the dictionary operations.

TODO: ha_innobase::final_drop_index() should do the same, and set
trx->dict_operation as well.
2007-09-06 12:43:29 +00:00
marko
462c911fe8 branches/zip: Merge 1792:1809 from trunk. 2007-09-06 07:12:12 +00:00
marko
ffe9a4c52e branches/zip: ha_innobase:add_index(): Report HA_ERR_TABLE_EXIST when the
temporary table cannot be created or renamed.

innodb-index.test,result: Add test cases where a temporary table already
exists.
2007-09-05 11:27:41 +00:00
marko
84ff578142 branches/zip: Simplify crash recovery in fast index creation.
trx_t: Remove dict_undo_list and dict_redo_list.

innobase_create_temporary_tablename(): Replace TEMP_TABLE_PREFIX with
a table name suffix "#1" or "#2".  In this way, the user can restore
precious data, should anything go wrong.  It is possible to reach an
inconsistent state, because the creation, deletion and renaming of
single-table tablespaces are not transactional.

ut_print_namel(), fil_make_ibd_name(), innobase_rename_table(): Remove
the special treatment of TEMP_TABLE_PREFIX.

Introduce TEMP_INDEX_PREFIX == 0xff for temporary indexes.  This byte
cannot occur in index names since MySQL 4.1.  However, it might have
been possible to use this byte in MySQL 4.0.

recv_recovery_from_checkpoint_finish(): Call the new function
row_merge_drop_temp_indexes(), to drop all indexes whose name starts
with the byte 0xff.

row_merge_rename_indexes(): Renamed from row_merge_rename_index().
Remove the parameter "index".

row_drop_table_for_mysql(): Unconditionally call trx_commit_for_mysql().

row_drop_table_for_mysql_no_commit(): Correct the function commit,
based on the corrected comment of row_drop_table_for_mysql().  Rely on
table->to_be_dropped instead of TEMP_TABLE_PREFIX.

ha_innobase::add_index(): Simplify the control flow.
2007-09-05 10:18:03 +00:00
marko
140a706079 branches/zip: Merge 1783:1792 from trunk. 2007-09-03 08:44:39 +00:00
marko
a2943ec761 branches/zip: Enclose the definition of dict_index_t::trx_id in
#ifdef ROW_MERGE_IS_INDEX_USABLE, to avoid growing the memory
footprint until MySQL implements and calls the virtual method
handler::is_index_available() or something equivalent.
2007-09-03 07:13:59 +00:00
marko
c056d2c3f5 branches/zip: Introduce TEMP_INDEX_PREFIX == 0xff for indexes being populated
in fast index creation.  The prefix was previously TEMP_TABLE_PREFIX == '/',
which may occur in index names.

ut_print_namel(): Do not assume that all '/' are separators between
database and table names.
2007-08-31 09:58:22 +00:00
marko
31d63cd08f branches/zip: Merge 1664:1783 from trunk. 2007-08-30 09:21:25 +00:00
marko
8462fba615 branches/zip: ha_innobase::add_index(): Remove a remark about row0mysql.c
in a comment about latching the data dictionary.  The data dictionary may
be latched elsewhere too.
2007-08-29 08:53:29 +00:00
marko
e7d302e786 branches/zip: Remove trx->sync_cb. Call dict_rename_indexes() directly
from ha_innobase::add_index().

dict_rename_indexes(): Remove the redundant parameter commit_flag.
2007-08-21 12:36:13 +00:00
marko
7274fd95af branches/zip: Fix a memory leak in fast index creation.
ha_innobase::add_index(): Add assertions about !trx->sync_cb and
!trx->dict_redo_list.  Remove a bogus comment.  Replace
row_lock_table_for_merge() with row_merge_lock_table().

row_merge_lock_table(): Renamed from row_lock_table_for_merge()
and moved from row0mysql.c to row0merge.c.  Always lock the table in
the mode LOCK_X.  Call que_graph_free() in order not to leak memory.
2007-08-21 12:10:14 +00:00
marko
4dfa0cc981 branches/zip: ha_innobase::add_index(): Remove the mem_heap_empty() call.
The index[] array that is allocated from the heap is still live.
2007-08-21 09:42:20 +00:00
marko
885212294d branches/zip: Preserve FOREIGN KEY constraints when creating a PRIMARY KEY.
innodb-index.test: Add some test cases for FOREIGN KEY constraints.

row_merge_rename_tables(): New function,
adapted from row_rename_table_for_mysql().

ha_innobase::add_index(): Use row_merge_rename_tables().
2007-08-20 11:40:00 +00:00
marko
9ce78f52ea branches/zip: Refuse fast index creation if newraw or innodb_force_recovery
have been set.

ha_innobase::add_index(), ha_innobase::prepare_drop_index(),
ha_innobase::final_drop_index(): Return HA_ERR_WRONG_COMMAND if
newraw or innodb_force_recovery have been set.
2007-08-20 09:13:26 +00:00
marko
d4568988fd branches/zip: ha_innobase::write_row(): Remove an unreachable break statement. 2007-08-20 06:54:31 +00:00
marko
66f6a5acc8 branches/zip: Fix bugs in the creation or dropping of the clustered index
(PRIMARY KEY or UNIQUE INDEX on NOT NULL columns).

innodb-index.test: Remove the --replace_regex directives.  Replace correct
values to the "Duplicate entry" messages.  This will cause the test to
fail until we somehow return the duplicate key values to MySQL.
Add test cases for creating or dropping UNIQUE INDEX or PRIMARY KEY.

innobase_copy_index_def(): Allow the function to copy a clustered index
definition to a secondary one (UNIQUE INDEX).

innobase_create_key_def(): Check the NOT NULL flag from the correct
place.  Copy the clustered index if it is a UNIQUE INDEX.

ha_innobase::prepare_drop_index(): Refuse to drop the clustered index.
2007-08-16 13:13:25 +00:00
marko
c541324b21 branches/zip: Minor cleanup.
ha_innobase::add_index(), ha_innobase::prepare_drop_index():
Remove the redundant thd_test_options() calls.
The options are tested in check_trx_exists().

ha_innobase::prepare_drop_index(): key cannot be NULL; remove the tests.
Move the condition for checking foreign keys outside of the loop.
Remove the redundant error log printout about foreign key dependency.
2007-08-16 09:19:48 +00:00
marko
91ee8176f6 branches/zip: Remove the error code DB_CANNOT_DROP_FOREIGN_INDEX.
It was only set by ha_innobase::prepare_drop_index(), which can return
the appropriate MySQL error code (HA_ERR_DROP_INDEX_FK) directly.

ha_innobase::add_index(): Correct the function comment.

ha_innobase::prepare_drop_index(): Correct the function comment.
Return MySQL error codes directly.

ha_innobase::final_drop_index(): Correct the function comment.
2007-08-15 15:49:58 +00:00
marko
6b7c6cb398 branches/zip: Minor cleanup.
trx_t: Change the type of error_info from void* to const dict_index_t*.

trx_get_error_info(): Add const qualifier to trx_t*.  Make this an
inline function.
2007-08-15 06:53:34 +00:00
marko
04ae127d2d branches/zip: ha_innobase::add_index(): Do not merely check for a
key name "PRIMARY".  If the table has a generated clustered index,
also check for a UNIQUE INDEX containing no NULL columns.

innobase_create_index_def(): Add the parameter key_primary.

innobase_create_key_def(): Check if the first index is a UNIQUE index
consisting of NOT NULL columns.

Fixing this bug revealed another one: FOREIGN KEY constraints
will be lost when a PRIMARY KEY is created.  This is the reason why
innodb.test will fail.
2007-08-13 16:34:00 +00:00
marko
2cf5070fda branches/zip: ha_innobase::change_active_index(): Write to the error log
when the index could not be found.
2007-08-13 16:05:23 +00:00
marko
e0009cd4db branches/zip: Add some const qualifiers to dict_index_t* and dict_table_t*.
innobase_create_key_def(), row_table_got_default_clust_index(),
row_get_mysql_key_number_for_index(): Add a const qualifier.

dict_table_get_first_index(), dict_table_get_next_index(): Define
as a const-preserving macro.  Preserve the old function for UNIV_DEBUG,
but add a const qualifier to the parameter and cast away the constness.
2007-08-13 15:57:28 +00:00
marko
845bd0914c branches/zip: ha_innobase::add_index(): Remove the unused variable new_unique. 2007-08-13 12:23:21 +00:00
marko
5f42eea7cc branches/zip: ha_innobase::add_index(): Fix an ut_ad() assertion that
was broken in r1685.
2007-08-13 07:37:53 +00:00
marko
e2052eba27 branches/zip: When creating a PRIMARY KEY, flag all its columns NOT NULL.
row_merge_create_temporary_table(): Add the parameter index_defs.

DB_PRIMARY_KEY_IS_NULL: New error code, mapped to ER_PRIMARY_CANT_HAVE_NULL.

row_merge_read_clustered_index(): Replace the parameter "table" with the
two parameters "old_table" and "new_table".  Detect NULL values of columns
that are supposed to be NOT NULL.

row_merge_col_prtype(): New auxiliary function, used by
row_merge_create_temporary_table() to flag NOT NULL any columns
contained in an added PRIMARY KEY.
2007-08-10 15:52:09 +00:00
marko
f304ce109c branches/zip: Minor cleanup.
innobase_copy_index_field_def(): Remove parameter heap.  The field->name
will not be deallocated before the copied index has been added to the
data dictionary cache.

innobase_copy_index_def(): Add const qualifier to dict_index_t*.
Add an assertion !dict_index_is_clust(index).

ha_innobase::add_index(): Add the missing user_thd parameter to the
convert_error_code_to_mysql() call that was forgotten from r1686.

merge_index_field_struct: Add const qualifier to field_name.

merge_index_def_struct: Add const qualifier to name.

row_merge_build_indexes(): Improve the function comment.

row_merge_drop_table(): Remove bogus assertion ut_a(table->to_be_dropped).
2007-08-10 15:22:47 +00:00
marko
992f5be17f branches/zip: ha_innobase::add_index(): Convert the error code before
goto err_exit.  The error handling should be rewritten.  Many of the
error messages contain parameters, but this code is only returning
the error number to MySQL.
2007-08-08 14:23:14 +00:00
marko
77e01ec982 branches/zip: innobase_check_index_keys(): return 0 instead of DB_SUCCESS,
as documented.  Do not translate the error code.

This function is still broken; we should probably use my_error() for
reporting errors.
2007-08-08 13:57:04 +00:00
marko
b532e5059c branches/zip: convert_error_code_to_mysql(): replace if-else with switch-case 2007-08-08 13:43:44 +00:00
marko
92f615ae30 branches/zip: merge_index_field_struct: Remove the unused field col_type. 2007-08-08 08:49:33 +00:00
marko
b67e98ad20 branches/zip: ha_innobase::add_index(): When creating a clustered index,
do not release and relock the data dictionary during initial preparations.
2007-08-03 11:42:37 +00:00
marko
c99c5c240a branches/zip: Add const qualifiers to the functions that read MySQL data.
row_mysql_read_true_varchar(), row_mysql_read_blob_ref(),
row_mysql_store_col_in_innobase_format(),
row_sel_convert_mysql_key_to_innobase(): Add const qualifiers.

row_sel_convert_mysql_key_to_innobase(): Document that the first parameter
is in/out.
2007-08-03 07:09:29 +00:00
marko
60c44c3a5f branches/zip: Ensure that the dictionary updates are atomic by keeping
the data dictionary locked across the operations.

dict_table_decrement_handle_count(), row_prebuilt_free(): Add the flag
dict_locked, to prevent the acquisition of dict_sys->mutex.

innobase_rename_table(): Rename commit_flag to lock_and_commit,
and do not acquire dict_sys->mutex or flush the log unless the flag is set.
Remove bogus comment about utility threads, because the threads will
be waken up by the upper-level function ha_innobase::rename_table().

ha_innobase::add_index(): After creating a primary key, hold dict_sys->mutex
across all dictionary operations.
2007-08-02 10:55:25 +00:00
marko
b2ae834f95 branches/zip: Declare schema_table_store_record(), because MySQL strangely
does not declare it unless MYSQL_SERVER is defined.
2007-08-01 11:49:19 +00:00
marko
0a780db994 branches/zip: Merge 1575:1664 from trunk. 2007-08-01 11:18:43 +00:00
marko
8519302258 branches/zip: Declare innobase_mysql_print_thd() in ha_prototypes.h. 2007-06-21 13:27:22 +00:00
marko
632ec54002 branches/zip: Make merge sort handle externally stored columns.
Some things still fail in innodb-index.test, and there seems to be
a race condition (data dictionary lock wait) when running with --valgrind.

dfield_t: Add an "external storage" flag, dfield->ext.

dfield_is_null(), dfield_is_ext(), dfield_set_ext(), dfield_set_null():
New functions.

dfield_copy(), dfield_copy_data(): Add const qualifiers, fix in/out comments.

data_write_sql_null(): Use memset().

big_rec_field_t: Replace byte* data with const void* data.

ut_ulint_sort(): Remove.

upd_field_t: Remove extern_storage.

upd_node_t: Replace ext_vec, n_ext_vec with n_ext.

row_merge_copy_blobs(): New function.

row_ins_index_entry(): Add the parameter "ibool foreign" for suppressing
foreign key checks during fast index creation or when inserting into
secondary indexes.

btr_page_insert_fits(): Add const qualifiers.

btr_cur_add_ext(), upd_ext_vec_contains(): Remove.

dfield_print_also_hex(), dfield_print(): Replace if...else if with switch.
Observe dfield_is_ext().
2007-06-21 09:43:15 +00:00
marko
1531d7329f branches/zip: Restore the transaction commit that was removed in r1583.
ha_innobase::add_index(): Do commit the transaction, because the error
handler (label err1) in mysql_alter_table() won't commit it as of now.
This was detected in a failure of type_bit_innodb.
2007-06-20 13:58:16 +00:00
marko
8b40a79c64 branches/zip: Enable calls to inlined InnoDB functions in ha_innodb.cc,
now that all of InnoDB code is built from a single Makefile and it should
not be possible to build the modules with mutually incompatible options.

#define INSIDE_HA_INNOBASE_CC: Remove.

srv_sizeof_trx_t_in_ha_innodb_cc: Remove.

dict_table_get_low_noninlined(): Remove.  This function was unused.

Remove all _noninline functions.  Remove the _noninline suffix from
all function calls in ha_innodb.cc.
2007-06-20 08:26:26 +00:00
marko
b3b01c1cee branches/zip: ha_innobase::add_index(): Split some assertions.
Remove the variable parent_trx.

Call innobase_register_stmt() in order to work around a MySQL bug
in mysql_alter_table(), which, as of

ChangeSet@1.2482.61.2, 2007-06-07 16:37:15+02:00, joerg@trift2. +8 -0

commits the transaction before calling ha_innobase::add_index().
Without re-registering the statement, the ha_commit_stmt(thd)
in mysql_alter_table() would not invoke innobase_commit.
2007-06-18 11:46:42 +00:00
marko
73feaa11bd branches/zip: ha_innobase::add_index(): Do not commit the transaction.
It should be committed by MySQL after all.  The error in mysql_alter_table()
will be worked around in r1584.
2007-06-18 11:01:30 +00:00