2005-05-06 10:39:30 +02:00
|
|
|
/* Copyright (C) 2000-2003 MySQL AB
|
2004-04-15 09:14:14 +02:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2005-02-17 22:52:40 +01:00
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2004-04-15 09:14:14 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
This file defines the NDB Cluster handler: the interface between MySQL and
|
|
|
|
NDB Cluster
|
|
|
|
*/
|
|
|
|
|
2005-05-26 12:09:14 +02:00
|
|
|
#ifdef USE_PRAGMA_IMPLEMENTATION
|
2005-06-03 22:46:03 +02:00
|
|
|
#pragma implementation // gcc: Class implementation
|
2004-04-15 09:14:14 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "mysql_priv.h"
|
|
|
|
|
|
|
|
#include <my_dir.h>
|
2006-04-13 22:49:29 +02:00
|
|
|
#ifdef WITH_NDBCLUSTER_STORAGE_ENGINE
|
2004-04-15 09:14:14 +02:00
|
|
|
#include "ha_ndbcluster.h"
|
|
|
|
#include <ndbapi/NdbApi.hpp>
|
|
|
|
#include <ndbapi/NdbScanFilter.hpp>
|
2005-11-07 12:19:28 +01:00
|
|
|
#include <../util/Bitmask.hpp>
|
2005-09-15 02:33:28 +02:00
|
|
|
#include <ndbapi/NdbIndexStat.hpp>
|
2004-04-15 09:14:14 +02:00
|
|
|
|
2006-01-12 19:51:02 +01:00
|
|
|
#include "ha_ndbcluster_binlog.h"
|
2006-02-16 00:30:56 +01:00
|
|
|
#include "ha_ndbcluster_tables.h"
|
2006-01-12 19:51:02 +01:00
|
|
|
|
2006-04-13 22:49:29 +02:00
|
|
|
#include <mysql/plugin.h>
|
|
|
|
|
2006-01-25 22:22:50 +01:00
|
|
|
#ifdef ndb_dynamite
|
|
|
|
#undef assert
|
|
|
|
#define assert(x) do { if(x) break; ::printf("%s %d: assert failed: %s\n", __FILE__, __LINE__, #x); ::fflush(stdout); ::signal(SIGABRT,SIG_DFL); ::abort(); ::kill(::getpid(),6); ::kill(::getpid(),9); } while (0)
|
|
|
|
#endif
|
|
|
|
|
2004-12-20 12:36:14 +01:00
|
|
|
// options from from mysqld.cc
|
|
|
|
extern my_bool opt_ndb_optimized_node_selection;
|
|
|
|
extern const char *opt_ndbcluster_connectstring;
|
2006-08-15 14:22:47 +02:00
|
|
|
extern ulong opt_ndb_cache_check_time;
|
2004-12-20 12:36:14 +01:00
|
|
|
|
2006-08-30 11:41:21 +02:00
|
|
|
// ndb interface initialization/cleanup
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
extern void ndb_init_internal();
|
|
|
|
extern void ndb_end_internal();
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-11-07 16:25:06 +01:00
|
|
|
const char *ndb_distribution_names[]= {"KEYHASH", "LINHASH", NullS};
|
|
|
|
TYPELIB ndb_distribution_typelib= { array_elements(ndb_distribution_names)-1,
|
|
|
|
"", ndb_distribution_names, NULL };
|
|
|
|
const char *opt_ndb_distribution= ndb_distribution_names[ND_KEYHASH];
|
|
|
|
enum ndb_distribution opt_ndb_distribution_id= ND_KEYHASH;
|
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
// Default value for parallelism
|
2004-12-06 09:05:30 +01:00
|
|
|
static const int parallelism= 0;
|
2004-04-15 09:14:14 +02:00
|
|
|
|
2004-05-24 12:35:39 +02:00
|
|
|
// Default value for max number of transactions
|
|
|
|
// createable against NDB from this handler
|
2005-06-17 16:07:54 +02:00
|
|
|
static const int max_transactions= 3; // should really be 2 but there is a transaction to much allocated when loch table is used
|
2004-07-23 15:46:56 +02:00
|
|
|
|
2006-01-17 08:40:00 +01:00
|
|
|
static uint ndbcluster_partition_flags();
|
|
|
|
static uint ndbcluster_alter_table_flags(uint flags);
|
2006-09-15 19:28:00 +02:00
|
|
|
static int ndbcluster_init(void *);
|
2006-09-30 21:49:46 +02:00
|
|
|
static int ndbcluster_end(handlerton *hton, ha_panic_function flag);
|
|
|
|
static bool ndbcluster_show_status(handlerton *hton, THD*,
|
|
|
|
stat_print_fn *,
|
|
|
|
enum ha_stat_type);
|
|
|
|
static int ndbcluster_alter_tablespace(handlerton *hton,
|
|
|
|
THD* thd,
|
|
|
|
st_alter_tablespace *info);
|
|
|
|
static int ndbcluster_fill_files_table(handlerton *hton,
|
|
|
|
THD *thd,
|
|
|
|
TABLE_LIST *tables,
|
|
|
|
COND *cond);
|
2005-02-17 22:52:40 +01:00
|
|
|
|
2006-10-01 20:17:59 +02:00
|
|
|
handlerton *ndbcluster_hton;
|
2005-02-17 22:52:40 +01:00
|
|
|
|
2006-09-30 02:19:02 +02:00
|
|
|
static handler *ndbcluster_create_handler(handlerton *hton,
|
|
|
|
TABLE_SHARE *table,
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
MEM_ROOT *mem_root)
|
2005-11-07 16:25:06 +01:00
|
|
|
{
|
2006-09-30 02:19:02 +02:00
|
|
|
return new (mem_root) ha_ndbcluster(hton, table);
|
2005-11-07 16:25:06 +01:00
|
|
|
}
|
|
|
|
|
2006-01-17 08:40:00 +01:00
|
|
|
static uint ndbcluster_partition_flags()
|
|
|
|
{
|
|
|
|
return (HA_CAN_PARTITION | HA_CAN_UPDATE_PARTITION_KEY |
|
|
|
|
HA_CAN_PARTITION_UNIQUE | HA_USE_AUTO_PARTITION);
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint ndbcluster_alter_table_flags(uint flags)
|
|
|
|
{
|
|
|
|
if (flags & ALTER_DROP_PARTITION)
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return (HA_ONLINE_ADD_INDEX | HA_ONLINE_DROP_INDEX |
|
|
|
|
HA_ONLINE_ADD_UNIQUE_INDEX | HA_ONLINE_DROP_UNIQUE_INDEX |
|
|
|
|
HA_PARTITION_FUNCTION_SUPPORTED);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2005-04-15 16:14:08 +02:00
|
|
|
#define NDB_AUTO_INCREMENT_RETRIES 10
|
2004-04-15 09:14:14 +02:00
|
|
|
|
|
|
|
#define ERR_PRINT(err) \
|
2004-09-13 14:46:38 +02:00
|
|
|
DBUG_PRINT("error", ("%d message: %s", err.code, err.message))
|
2004-04-15 09:14:14 +02:00
|
|
|
|
2005-02-16 14:18:32 +01:00
|
|
|
#define ERR_RETURN(err) \
|
|
|
|
{ \
|
2004-11-17 10:07:52 +01:00
|
|
|
const NdbError& tmp= err; \
|
2005-02-16 14:18:32 +01:00
|
|
|
ERR_PRINT(tmp); \
|
2004-11-17 10:07:52 +01:00
|
|
|
DBUG_RETURN(ndb_to_mysql_error(&tmp)); \
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
|
2005-09-15 02:33:28 +02:00
|
|
|
#define ERR_BREAK(err, code) \
|
|
|
|
{ \
|
|
|
|
const NdbError& tmp= err; \
|
|
|
|
ERR_PRINT(tmp); \
|
|
|
|
code= ndb_to_mysql_error(&tmp); \
|
|
|
|
break; \
|
|
|
|
}
|
|
|
|
|
2005-11-06 00:20:37 +01:00
|
|
|
static int ndbcluster_inited= 0;
|
2006-01-12 19:51:02 +01:00
|
|
|
int ndbcluster_util_inited= 0;
|
2004-04-15 09:14:14 +02:00
|
|
|
|
2004-05-11 13:59:22 +02:00
|
|
|
static Ndb* g_ndb= NULL;
|
2006-01-12 19:51:02 +01:00
|
|
|
Ndb_cluster_connection* g_ndb_cluster_connection= NULL;
|
2006-06-19 11:45:34 +02:00
|
|
|
uchar g_node_id_map[max_ndb_nodes];
|
2004-05-11 13:59:22 +02:00
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
// Handler synchronization
|
|
|
|
pthread_mutex_t ndbcluster_mutex;
|
|
|
|
|
|
|
|
// Table lock handling
|
2006-01-12 19:51:02 +01:00
|
|
|
HASH ndbcluster_open_tables;
|
2004-04-15 09:14:14 +02:00
|
|
|
|
|
|
|
static byte *ndbcluster_get_key(NDB_SHARE *share,uint *length,
|
|
|
|
my_bool not_used __attribute__((unused)));
|
2006-01-12 19:51:02 +01:00
|
|
|
#ifdef HAVE_NDB_BINLOG
|
|
|
|
static int rename_share(NDB_SHARE *share, const char *new_key);
|
|
|
|
#endif
|
2005-11-06 00:20:37 +01:00
|
|
|
static void ndb_set_fragmentation(NDBTAB &tab, TABLE *table, uint pk_len);
|
2004-04-15 09:14:14 +02:00
|
|
|
|
2006-05-04 13:58:17 +02:00
|
|
|
static int ndb_get_table_statistics(Ndb*, const NDBTAB *,
|
2005-02-16 14:18:32 +01:00
|
|
|
struct Ndb_statistics *);
|
2004-09-14 10:52:21 +02:00
|
|
|
|
2005-11-06 00:20:37 +01:00
|
|
|
|
2005-02-11 22:33:52 +01:00
|
|
|
// Util thread variables
|
2006-01-12 19:51:02 +01:00
|
|
|
pthread_t ndb_util_thread;
|
2005-02-11 22:33:52 +01:00
|
|
|
pthread_mutex_t LOCK_ndb_util_thread;
|
|
|
|
pthread_cond_t COND_ndb_util_thread;
|
2005-10-08 16:39:55 +02:00
|
|
|
pthread_handler_t ndb_util_thread_func(void *arg);
|
2005-02-11 22:33:52 +01:00
|
|
|
ulong ndb_cache_check_time;
|
2004-09-03 13:55:40 +02:00
|
|
|
|
2004-10-20 19:22:58 +02:00
|
|
|
/*
|
|
|
|
Dummy buffer to read zero pack_length fields
|
|
|
|
which are mapped to 1 char
|
|
|
|
*/
|
2004-12-10 16:55:04 +01:00
|
|
|
static uint32 dummy_buf;
|
2004-10-20 19:22:58 +02:00
|
|
|
|
2005-01-13 18:24:19 +01:00
|
|
|
/*
|
|
|
|
Stats that can be retrieved from ndb
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct Ndb_statistics {
|
|
|
|
Uint64 row_count;
|
|
|
|
Uint64 commit_count;
|
|
|
|
Uint64 row_size;
|
|
|
|
Uint64 fragment_memory;
|
|
|
|
};
|
|
|
|
|
2005-01-14 12:32:33 +01:00
|
|
|
/* Status variables shown with 'show status like 'Ndb%' */
|
|
|
|
|
|
|
|
static long ndb_cluster_node_id= 0;
|
|
|
|
static const char * ndb_connected_host= 0;
|
|
|
|
static long ndb_connected_port= 0;
|
|
|
|
static long ndb_number_of_replicas= 0;
|
2006-08-11 09:18:40 +02:00
|
|
|
long ndb_number_of_data_nodes= 0;
|
|
|
|
long ndb_number_of_ready_data_nodes= 0;
|
2006-05-19 12:54:12 +02:00
|
|
|
long ndb_connect_count= 0;
|
2005-01-14 12:32:33 +01:00
|
|
|
|
|
|
|
static int update_status_variables(Ndb_cluster_connection *c)
|
|
|
|
{
|
|
|
|
ndb_cluster_node_id= c->node_id();
|
|
|
|
ndb_connected_port= c->get_connected_port();
|
|
|
|
ndb_connected_host= c->get_connected_host();
|
|
|
|
ndb_number_of_replicas= 0;
|
2006-08-11 09:18:40 +02:00
|
|
|
ndb_number_of_ready_data_nodes= c->get_no_ready();
|
2006-08-11 12:01:46 +02:00
|
|
|
ndb_number_of_data_nodes= c->no_db_nodes();
|
2006-05-19 12:54:12 +02:00
|
|
|
ndb_connect_count= c->get_connect_count();
|
2005-01-14 12:32:33 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-01-07 16:27:40 +01:00
|
|
|
SHOW_VAR ndb_status_variables[]= {
|
2005-01-14 12:32:33 +01:00
|
|
|
{"cluster_node_id", (char*) &ndb_cluster_node_id, SHOW_LONG},
|
2006-06-26 15:31:10 +02:00
|
|
|
{"config_from_host", (char*) &ndb_connected_host, SHOW_CHAR_PTR},
|
|
|
|
{"config_from_port", (char*) &ndb_connected_port, SHOW_LONG},
|
2005-01-14 12:32:33 +01:00
|
|
|
// {"number_of_replicas", (char*) &ndb_number_of_replicas, SHOW_LONG},
|
2006-08-11 09:10:08 +02:00
|
|
|
{"number_of_data_nodes",(char*) &ndb_number_of_data_nodes, SHOW_LONG},
|
2005-01-14 12:32:33 +01:00
|
|
|
{NullS, NullS, SHOW_LONG}
|
|
|
|
};
|
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
/*
|
|
|
|
Error handling functions
|
|
|
|
*/
|
|
|
|
|
2005-11-06 00:20:37 +01:00
|
|
|
/* Note for merge: old mapping table, moved to storage/ndb/ndberror.c */
|
2004-04-15 09:14:14 +02:00
|
|
|
|
2005-11-06 00:20:37 +01:00
|
|
|
static int ndb_to_mysql_error(const NdbError *ndberr)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
2005-11-06 00:20:37 +01:00
|
|
|
/* read the mysql mapped error code */
|
|
|
|
int error= ndberr->mysql_code;
|
2004-11-17 09:15:53 +01:00
|
|
|
|
2005-11-06 00:20:37 +01:00
|
|
|
switch (error)
|
|
|
|
{
|
|
|
|
/* errors for which we do not add warnings, just return mapped error code
|
|
|
|
*/
|
|
|
|
case HA_ERR_NO_SUCH_TABLE:
|
|
|
|
case HA_ERR_KEY_NOT_FOUND:
|
|
|
|
case HA_ERR_FOUND_DUPP_KEY:
|
|
|
|
return error;
|
|
|
|
|
|
|
|
/* Mapping missing, go with the ndb error code*/
|
|
|
|
case -1:
|
|
|
|
error= ndberr->code;
|
|
|
|
break;
|
2004-04-15 09:14:14 +02:00
|
|
|
|
2005-11-06 00:20:37 +01:00
|
|
|
/* Mapping exists, go with the mapped code */
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2004-04-15 09:14:14 +02:00
|
|
|
|
2005-11-06 00:20:37 +01:00
|
|
|
/*
|
|
|
|
Push the NDB error message as warning
|
|
|
|
- Used to be able to use SHOW WARNINGS toget more info on what the error is
|
|
|
|
- Used by replication to see if the error was temporary
|
|
|
|
*/
|
|
|
|
if (ndberr->status == NdbError::TemporaryError)
|
2004-11-17 09:15:53 +01:00
|
|
|
push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
|
2005-11-06 00:20:37 +01:00
|
|
|
ER_GET_TEMPORARY_ERRMSG, ER(ER_GET_TEMPORARY_ERRMSG),
|
|
|
|
ndberr->code, ndberr->message, "NDB");
|
|
|
|
else
|
|
|
|
push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
|
|
|
|
ER_GET_ERRMSG, ER(ER_GET_ERRMSG),
|
|
|
|
ndberr->code, ndberr->message, "NDB");
|
|
|
|
return error;
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
|
2005-11-06 00:20:37 +01:00
|
|
|
int execute_no_commit_ignore_no_key(ha_ndbcluster *h, NdbTransaction *trans)
|
|
|
|
{
|
|
|
|
int res= trans->execute(NdbTransaction::NoCommit,
|
|
|
|
NdbTransaction::AO_IgnoreError,
|
|
|
|
h->m_force_send);
|
|
|
|
if (res == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
const NdbError &err= trans->getNdbError();
|
|
|
|
if (err.classification != NdbError::ConstraintViolation &&
|
|
|
|
err.classification != NdbError::NoDataFound)
|
|
|
|
return res;
|
2004-04-15 09:14:14 +02:00
|
|
|
|
2005-11-06 00:20:37 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2004-09-17 16:58:08 +02:00
|
|
|
|
|
|
|
inline
|
2006-08-15 14:31:21 +02:00
|
|
|
int execute_no_commit(ha_ndbcluster *h, NdbTransaction *trans,
|
2006-08-07 14:48:54 +02:00
|
|
|
bool force_release)
|
2004-09-17 16:58:08 +02:00
|
|
|
{
|
2004-10-14 17:03:46 +02:00
|
|
|
#ifdef NOT_USED
|
2005-01-11 17:00:31 +01:00
|
|
|
int m_batch_execute= 0;
|
2004-10-14 17:03:46 +02:00
|
|
|
if (m_batch_execute)
|
2004-09-17 16:58:08 +02:00
|
|
|
return 0;
|
2004-10-14 17:03:46 +02:00
|
|
|
#endif
|
2006-08-07 14:48:54 +02:00
|
|
|
h->release_completed_operations(trans, force_release);
|
2005-11-06 00:20:37 +01:00
|
|
|
return h->m_ignore_no_key ?
|
|
|
|
execute_no_commit_ignore_no_key(h,trans) :
|
|
|
|
trans->execute(NdbTransaction::NoCommit,
|
|
|
|
NdbTransaction::AbortOnError,
|
|
|
|
h->m_force_send);
|
2004-09-28 21:11:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
2005-01-04 13:47:16 +01:00
|
|
|
int execute_commit(ha_ndbcluster *h, NdbTransaction *trans)
|
2004-09-28 21:11:50 +02:00
|
|
|
{
|
2004-10-14 17:03:46 +02:00
|
|
|
#ifdef NOT_USED
|
2005-01-11 17:00:31 +01:00
|
|
|
int m_batch_execute= 0;
|
2004-10-14 17:03:46 +02:00
|
|
|
if (m_batch_execute)
|
2004-09-28 21:11:50 +02:00
|
|
|
return 0;
|
2004-10-14 17:03:46 +02:00
|
|
|
#endif
|
2005-01-05 17:59:24 +01:00
|
|
|
return trans->execute(NdbTransaction::Commit,
|
2005-02-16 14:18:32 +01:00
|
|
|
NdbTransaction::AbortOnError,
|
|
|
|
h->m_force_send);
|
2004-11-17 09:15:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
2005-01-04 13:47:16 +01:00
|
|
|
int execute_commit(THD *thd, NdbTransaction *trans)
|
2004-11-17 09:15:53 +01:00
|
|
|
{
|
|
|
|
#ifdef NOT_USED
|
2005-01-11 17:00:31 +01:00
|
|
|
int m_batch_execute= 0;
|
2004-11-17 09:15:53 +01:00
|
|
|
if (m_batch_execute)
|
|
|
|
return 0;
|
|
|
|
#endif
|
2005-01-05 17:59:24 +01:00
|
|
|
return trans->execute(NdbTransaction::Commit,
|
2005-02-16 14:18:32 +01:00
|
|
|
NdbTransaction::AbortOnError,
|
|
|
|
thd->variables.ndb_force_send);
|
2004-09-28 21:11:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
2006-08-15 14:31:21 +02:00
|
|
|
int execute_no_commit_ie(ha_ndbcluster *h, NdbTransaction *trans,
|
2006-08-07 14:48:54 +02:00
|
|
|
bool force_release)
|
2004-09-28 21:11:50 +02:00
|
|
|
{
|
2004-10-14 17:03:46 +02:00
|
|
|
#ifdef NOT_USED
|
2005-01-11 17:00:31 +01:00
|
|
|
int m_batch_execute= 0;
|
2004-10-14 17:03:46 +02:00
|
|
|
if (m_batch_execute)
|
2004-09-28 21:11:50 +02:00
|
|
|
return 0;
|
2004-10-14 17:03:46 +02:00
|
|
|
#endif
|
2006-08-07 14:48:54 +02:00
|
|
|
h->release_completed_operations(trans, force_release);
|
2005-01-05 17:59:24 +01:00
|
|
|
return trans->execute(NdbTransaction::NoCommit,
|
2005-02-16 14:18:32 +01:00
|
|
|
NdbTransaction::AO_IgnoreError,
|
|
|
|
h->m_force_send);
|
2004-09-17 16:58:08 +02:00
|
|
|
}
|
|
|
|
|
2004-12-17 21:13:22 +01:00
|
|
|
/*
|
|
|
|
Place holder for ha_ndbcluster thread specific data
|
|
|
|
*/
|
2006-04-19 18:29:25 +02:00
|
|
|
static
|
|
|
|
byte *thd_ndb_share_get_key(THD_NDB_SHARE *thd_ndb_share, uint *length,
|
|
|
|
my_bool not_used __attribute__((unused)))
|
|
|
|
{
|
|
|
|
*length= sizeof(thd_ndb_share->key);
|
2006-06-16 12:29:04 +02:00
|
|
|
return (byte*) &thd_ndb_share->key;
|
2006-04-19 18:29:25 +02:00
|
|
|
}
|
|
|
|
|
2004-09-14 10:52:21 +02:00
|
|
|
Thd_ndb::Thd_ndb()
|
|
|
|
{
|
2004-09-14 14:47:34 +02:00
|
|
|
ndb= new Ndb(g_ndb_cluster_connection, "");
|
2004-09-14 10:52:21 +02:00
|
|
|
lock_count= 0;
|
|
|
|
count= 0;
|
2005-02-17 22:52:40 +01:00
|
|
|
all= NULL;
|
|
|
|
stmt= NULL;
|
2004-09-14 18:17:01 +02:00
|
|
|
error= 0;
|
2006-08-07 14:48:54 +02:00
|
|
|
query_state&= NDB_QUERY_NORMAL;
|
2006-01-12 19:51:02 +01:00
|
|
|
options= 0;
|
2006-04-19 23:49:51 +02:00
|
|
|
(void) hash_init(&open_tables, &my_charset_bin, 5, 0, 0,
|
2006-04-19 18:29:25 +02:00
|
|
|
(hash_get_key)thd_ndb_share_get_key, 0, 0);
|
2004-09-14 10:52:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Thd_ndb::~Thd_ndb()
|
|
|
|
{
|
2004-09-14 14:47:34 +02:00
|
|
|
if (ndb)
|
2005-11-17 12:45:23 +01:00
|
|
|
{
|
|
|
|
#ifndef DBUG_OFF
|
2006-01-05 23:47:49 +01:00
|
|
|
Ndb::Free_list_usage tmp;
|
|
|
|
tmp.m_name= 0;
|
2005-11-17 12:45:23 +01:00
|
|
|
while (ndb->get_free_list_usage(&tmp))
|
|
|
|
{
|
|
|
|
uint leaked= (uint) tmp.m_created - tmp.m_free;
|
|
|
|
if (leaked)
|
|
|
|
fprintf(stderr, "NDB: Found %u %s%s that %s not been released\n",
|
|
|
|
leaked, tmp.m_name,
|
|
|
|
(leaked == 1)?"":"'s",
|
|
|
|
(leaked == 1)?"has":"have");
|
|
|
|
}
|
|
|
|
#endif
|
2004-09-14 14:47:34 +02:00
|
|
|
delete ndb;
|
2006-01-05 23:47:49 +01:00
|
|
|
ndb= NULL;
|
2005-11-17 12:45:23 +01:00
|
|
|
}
|
2005-03-15 15:03:25 +01:00
|
|
|
changed_tables.empty();
|
2006-04-19 18:29:25 +02:00
|
|
|
hash_free(&open_tables);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Thd_ndb::init_open_tables()
|
|
|
|
{
|
2006-04-20 03:05:50 +02:00
|
|
|
count= 0;
|
|
|
|
error= 0;
|
2006-04-19 18:29:25 +02:00
|
|
|
my_hash_reset(&open_tables);
|
|
|
|
}
|
|
|
|
|
|
|
|
THD_NDB_SHARE *
|
|
|
|
Thd_ndb::get_open_table(THD *thd, const void *key)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("Thd_ndb::get_open_table");
|
2006-04-19 21:30:22 +02:00
|
|
|
HASH_SEARCH_STATE state;
|
2006-04-19 18:29:25 +02:00
|
|
|
THD_NDB_SHARE *thd_ndb_share=
|
2006-06-16 12:29:04 +02:00
|
|
|
(THD_NDB_SHARE*)hash_first(&open_tables, (byte *)&key, sizeof(key), &state);
|
2006-04-19 21:30:22 +02:00
|
|
|
while (thd_ndb_share && thd_ndb_share->key != key)
|
2006-06-16 12:29:04 +02:00
|
|
|
thd_ndb_share= (THD_NDB_SHARE*)hash_next(&open_tables, (byte *)&key, sizeof(key), &state);
|
2006-04-19 18:29:25 +02:00
|
|
|
if (thd_ndb_share == 0)
|
|
|
|
{
|
|
|
|
thd_ndb_share= (THD_NDB_SHARE *) alloc_root(&thd->transaction.mem_root,
|
|
|
|
sizeof(THD_NDB_SHARE));
|
|
|
|
thd_ndb_share->key= key;
|
2006-04-20 03:05:50 +02:00
|
|
|
thd_ndb_share->stat.last_count= count;
|
|
|
|
thd_ndb_share->stat.no_uncommitted_rows_count= 0;
|
2006-04-21 13:51:58 +02:00
|
|
|
thd_ndb_share->stat.records= ~(ha_rows)0;
|
2006-04-19 18:29:25 +02:00
|
|
|
my_hash_insert(&open_tables, (byte *)thd_ndb_share);
|
|
|
|
}
|
2006-04-20 03:05:50 +02:00
|
|
|
else if (thd_ndb_share->stat.last_count != count)
|
|
|
|
{
|
|
|
|
thd_ndb_share->stat.last_count= count;
|
|
|
|
thd_ndb_share->stat.no_uncommitted_rows_count= 0;
|
2006-04-21 13:51:58 +02:00
|
|
|
thd_ndb_share->stat.records= ~(ha_rows)0;
|
2006-04-20 03:05:50 +02:00
|
|
|
}
|
2006-04-19 21:30:22 +02:00
|
|
|
DBUG_PRINT("exit", ("thd_ndb_share: 0x%x key: 0x%x", thd_ndb_share, key));
|
2006-04-19 18:29:25 +02:00
|
|
|
DBUG_RETURN(thd_ndb_share);
|
2004-09-14 10:52:21 +02:00
|
|
|
}
|
|
|
|
|
2004-12-30 19:56:09 +01:00
|
|
|
inline
|
|
|
|
Ndb *ha_ndbcluster::get_ndb()
|
|
|
|
{
|
2005-02-18 12:53:43 +01:00
|
|
|
return get_thd_ndb(current_thd)->ndb;
|
2004-09-14 10:52:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* manage uncommitted insert/deletes during transactio to get records correct
|
|
|
|
*/
|
|
|
|
|
2004-10-04 01:20:05 +02:00
|
|
|
void ha_ndbcluster::set_rec_per_key()
|
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_ndbcluster::get_status_const");
|
2006-01-17 08:40:00 +01:00
|
|
|
for (uint i=0 ; i < table_share->keys ; i++)
|
2004-10-04 01:20:05 +02:00
|
|
|
{
|
|
|
|
table->key_info[i].rec_per_key[table->key_info[i].key_parts-1]= 1;
|
|
|
|
}
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
2006-06-27 17:07:44 +02:00
|
|
|
ha_rows ha_ndbcluster::records()
|
|
|
|
{
|
|
|
|
ha_rows retval;
|
|
|
|
DBUG_ENTER("ha_ndbcluster::records");
|
|
|
|
struct Ndb_local_table_statistics *info= m_table_info;
|
|
|
|
DBUG_PRINT("info", ("id=%d, no_uncommitted_rows_count=%d",
|
|
|
|
((const NDBTAB *)m_table)->getTableId(),
|
|
|
|
info->no_uncommitted_rows_count));
|
|
|
|
|
|
|
|
Ndb *ndb= get_ndb();
|
|
|
|
ndb->setDatabaseName(m_dbname);
|
|
|
|
struct Ndb_statistics stat;
|
|
|
|
if (ndb_get_table_statistics(ndb, m_table, &stat) == 0)
|
|
|
|
{
|
|
|
|
retval= stat.row_count;
|
|
|
|
}
|
2006-06-27 17:28:07 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Be consistent with BUG#19914 until we fix it properly
|
|
|
|
*/
|
|
|
|
DBUG_RETURN(-1);
|
|
|
|
}
|
2006-06-27 17:07:44 +02:00
|
|
|
|
|
|
|
THD *thd= current_thd;
|
|
|
|
if (get_thd_ndb(thd)->error)
|
|
|
|
info->no_uncommitted_rows_count= 0;
|
|
|
|
|
|
|
|
DBUG_RETURN(retval + info->no_uncommitted_rows_count);
|
|
|
|
}
|
|
|
|
|
2004-09-14 10:52:21 +02:00
|
|
|
void ha_ndbcluster::records_update()
|
|
|
|
{
|
2004-11-17 09:15:53 +01:00
|
|
|
if (m_ha_not_exact_count)
|
|
|
|
return;
|
2004-09-14 10:52:21 +02:00
|
|
|
DBUG_ENTER("ha_ndbcluster::records_update");
|
2006-04-19 18:29:25 +02:00
|
|
|
struct Ndb_local_table_statistics *info= m_table_info;
|
2004-09-14 10:52:21 +02:00
|
|
|
DBUG_PRINT("info", ("id=%d, no_uncommitted_rows_count=%d",
|
2005-02-16 14:18:32 +01:00
|
|
|
((const NDBTAB *)m_table)->getTableId(),
|
|
|
|
info->no_uncommitted_rows_count));
|
2004-09-20 17:52:19 +02:00
|
|
|
// if (info->records == ~(ha_rows)0)
|
2004-09-14 10:52:21 +02:00
|
|
|
{
|
2004-12-30 19:56:09 +01:00
|
|
|
Ndb *ndb= get_ndb();
|
2005-01-13 18:24:19 +01:00
|
|
|
struct Ndb_statistics stat;
|
2006-06-29 20:55:21 +02:00
|
|
|
ndb->setDatabaseName(m_dbname);
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
if (ndb_get_table_statistics(ndb, m_table, &stat) == 0)
|
|
|
|
{
|
|
|
|
stats.mean_rec_length= stat.row_size;
|
|
|
|
stats.data_file_length= stat.fragment_memory;
|
2005-01-13 18:24:19 +01:00
|
|
|
info->records= stat.row_count;
|
2004-09-14 10:52:21 +02:00
|
|
|
}
|
|
|
|
}
|
2004-09-14 18:17:01 +02:00
|
|
|
{
|
|
|
|
THD *thd= current_thd;
|
2005-02-17 22:52:40 +01:00
|
|
|
if (get_thd_ndb(thd)->error)
|
2004-09-14 18:17:01 +02:00
|
|
|
info->no_uncommitted_rows_count= 0;
|
|
|
|
}
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
stats.records= info->records+ info->no_uncommitted_rows_count;
|
2004-09-14 10:52:21 +02:00
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
2004-09-14 17:51:57 +02:00
|
|
|
void ha_ndbcluster::no_uncommitted_rows_execute_failure()
|
|
|
|
{
|
2004-11-17 09:15:53 +01:00
|
|
|
if (m_ha_not_exact_count)
|
|
|
|
return;
|
2004-09-14 17:51:57 +02:00
|
|
|
DBUG_ENTER("ha_ndbcluster::no_uncommitted_rows_execute_failure");
|
2005-02-18 12:53:43 +01:00
|
|
|
get_thd_ndb(current_thd)->error= 1;
|
2004-09-14 17:51:57 +02:00
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
2004-09-14 10:52:21 +02:00
|
|
|
void ha_ndbcluster::no_uncommitted_rows_update(int c)
|
|
|
|
{
|
2004-11-17 09:15:53 +01:00
|
|
|
if (m_ha_not_exact_count)
|
|
|
|
return;
|
2004-09-14 10:52:21 +02:00
|
|
|
DBUG_ENTER("ha_ndbcluster::no_uncommitted_rows_update");
|
2006-04-19 18:29:25 +02:00
|
|
|
struct Ndb_local_table_statistics *info= m_table_info;
|
2004-09-14 10:52:21 +02:00
|
|
|
info->no_uncommitted_rows_count+= c;
|
|
|
|
DBUG_PRINT("info", ("id=%d, no_uncommitted_rows_count=%d",
|
2005-02-16 14:18:32 +01:00
|
|
|
((const NDBTAB *)m_table)->getTableId(),
|
|
|
|
info->no_uncommitted_rows_count));
|
2004-09-14 10:52:21 +02:00
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ha_ndbcluster::no_uncommitted_rows_reset(THD *thd)
|
|
|
|
{
|
2004-11-17 09:15:53 +01:00
|
|
|
if (m_ha_not_exact_count)
|
|
|
|
return;
|
2004-09-14 10:52:21 +02:00
|
|
|
DBUG_ENTER("ha_ndbcluster::no_uncommitted_rows_reset");
|
2005-02-17 22:52:40 +01:00
|
|
|
Thd_ndb *thd_ndb= get_thd_ndb(thd);
|
|
|
|
thd_ndb->count++;
|
|
|
|
thd_ndb->error= 0;
|
2004-09-14 10:52:21 +02:00
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
2005-01-04 13:47:16 +01:00
|
|
|
int ha_ndbcluster::ndb_err(NdbTransaction *trans)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
2004-08-31 12:07:48 +02:00
|
|
|
int res;
|
2005-04-04 12:26:05 +02:00
|
|
|
NdbError err= trans->getNdbError();
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_ENTER("ndb_err");
|
|
|
|
|
|
|
|
ERR_PRINT(err);
|
|
|
|
switch (err.classification) {
|
|
|
|
case NdbError::SchemaError:
|
2006-04-07 11:18:45 +02:00
|
|
|
{
|
2006-05-04 13:58:17 +02:00
|
|
|
// TODO perhaps we need to do more here, invalidate also in the cache
|
|
|
|
m_table->setStatusInvalid();
|
2006-01-10 11:35:21 +01:00
|
|
|
/* Close other open handlers not used by any thread */
|
|
|
|
TABLE_LIST table_list;
|
|
|
|
bzero((char*) &table_list,sizeof(table_list));
|
|
|
|
table_list.db= m_dbname;
|
|
|
|
table_list.alias= table_list.table_name= m_tabname;
|
|
|
|
close_cached_tables(current_thd, 0, &table_list);
|
2004-04-15 09:14:14 +02:00
|
|
|
break;
|
2006-04-07 11:18:45 +02:00
|
|
|
}
|
2004-04-15 09:14:14 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2004-08-31 12:07:48 +02:00
|
|
|
res= ndb_to_mysql_error(&err);
|
|
|
|
DBUG_PRINT("info", ("transformed ndbcluster error %d to mysql error %d",
|
2005-02-16 14:18:32 +01:00
|
|
|
err.code, res));
|
2004-08-31 12:07:48 +02:00
|
|
|
if (res == HA_ERR_FOUND_DUPP_KEY)
|
2005-06-17 14:45:54 +02:00
|
|
|
{
|
|
|
|
if (m_rows_to_insert == 1)
|
2006-01-17 08:40:00 +01:00
|
|
|
m_dupkey= table_share->primary_key;
|
2005-06-17 14:45:54 +02:00
|
|
|
else
|
2005-06-27 15:46:41 +02:00
|
|
|
{
|
|
|
|
/* We are batching inserts, offending key is not available */
|
2005-06-17 14:45:54 +02:00
|
|
|
m_dupkey= (uint) -1;
|
2005-06-27 15:46:41 +02:00
|
|
|
}
|
2005-06-17 14:45:54 +02:00
|
|
|
}
|
2004-08-31 12:07:48 +02:00
|
|
|
DBUG_RETURN(res);
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-05-11 13:59:22 +02:00
|
|
|
/*
|
2004-05-13 11:56:45 +02:00
|
|
|
Override the default get_error_message in order to add the
|
2004-05-11 13:59:22 +02:00
|
|
|
error message of NDB
|
|
|
|
*/
|
|
|
|
|
2004-05-24 12:35:39 +02:00
|
|
|
bool ha_ndbcluster::get_error_message(int error,
|
2005-02-16 14:18:32 +01:00
|
|
|
String *buf)
|
2004-05-11 13:59:22 +02:00
|
|
|
{
|
2004-05-13 11:56:45 +02:00
|
|
|
DBUG_ENTER("ha_ndbcluster::get_error_message");
|
2004-05-24 12:35:39 +02:00
|
|
|
DBUG_PRINT("enter", ("error: %d", error));
|
2004-05-11 13:59:22 +02:00
|
|
|
|
2004-12-30 19:56:09 +01:00
|
|
|
Ndb *ndb= get_ndb();
|
2004-09-15 14:44:21 +02:00
|
|
|
if (!ndb)
|
2004-10-14 17:03:46 +02:00
|
|
|
DBUG_RETURN(FALSE);
|
2004-05-13 11:56:45 +02:00
|
|
|
|
2004-09-15 14:44:21 +02:00
|
|
|
const NdbError err= ndb->getNdbError(error);
|
2004-05-24 12:35:39 +02:00
|
|
|
bool temporary= err.status==NdbError::TemporaryError;
|
|
|
|
buf->set(err.message, strlen(err.message), &my_charset_bin);
|
|
|
|
DBUG_PRINT("exit", ("message: %s, temporary: %d", buf->ptr(), temporary));
|
|
|
|
DBUG_RETURN(temporary);
|
2004-05-11 13:59:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-06-20 07:53:53 +02:00
|
|
|
#ifndef DBUG_OFF
|
2004-07-22 12:38:09 +02:00
|
|
|
/*
|
|
|
|
Check if type is supported by NDB.
|
|
|
|
*/
|
|
|
|
|
2005-06-20 07:53:53 +02:00
|
|
|
static bool ndb_supported_type(enum_field_types type)
|
2004-07-22 12:38:09 +02:00
|
|
|
{
|
|
|
|
switch (type) {
|
2004-07-23 13:21:39 +02:00
|
|
|
case MYSQL_TYPE_TINY:
|
|
|
|
case MYSQL_TYPE_SHORT:
|
|
|
|
case MYSQL_TYPE_LONG:
|
|
|
|
case MYSQL_TYPE_INT24:
|
|
|
|
case MYSQL_TYPE_LONGLONG:
|
|
|
|
case MYSQL_TYPE_FLOAT:
|
|
|
|
case MYSQL_TYPE_DOUBLE:
|
2005-02-16 21:19:42 +01:00
|
|
|
case MYSQL_TYPE_DECIMAL:
|
|
|
|
case MYSQL_TYPE_NEWDECIMAL:
|
2004-07-23 13:21:39 +02:00
|
|
|
case MYSQL_TYPE_TIMESTAMP:
|
|
|
|
case MYSQL_TYPE_DATETIME:
|
|
|
|
case MYSQL_TYPE_DATE:
|
|
|
|
case MYSQL_TYPE_NEWDATE:
|
|
|
|
case MYSQL_TYPE_TIME:
|
|
|
|
case MYSQL_TYPE_YEAR:
|
|
|
|
case MYSQL_TYPE_STRING:
|
|
|
|
case MYSQL_TYPE_VAR_STRING:
|
2005-01-07 11:55:20 +01:00
|
|
|
case MYSQL_TYPE_VARCHAR:
|
2004-07-23 13:21:39 +02:00
|
|
|
case MYSQL_TYPE_TINY_BLOB:
|
|
|
|
case MYSQL_TYPE_BLOB:
|
|
|
|
case MYSQL_TYPE_MEDIUM_BLOB:
|
|
|
|
case MYSQL_TYPE_LONG_BLOB:
|
|
|
|
case MYSQL_TYPE_ENUM:
|
|
|
|
case MYSQL_TYPE_SET:
|
2004-12-23 15:28:41 +01:00
|
|
|
case MYSQL_TYPE_BIT:
|
2005-10-25 08:20:39 +02:00
|
|
|
case MYSQL_TYPE_GEOMETRY:
|
2004-10-14 17:03:46 +02:00
|
|
|
return TRUE;
|
2004-07-22 12:38:09 +02:00
|
|
|
case MYSQL_TYPE_NULL:
|
2004-07-23 13:21:39 +02:00
|
|
|
break;
|
2004-07-22 12:38:09 +02:00
|
|
|
}
|
2004-10-14 17:03:46 +02:00
|
|
|
return FALSE;
|
2004-07-22 12:38:09 +02:00
|
|
|
}
|
2005-06-20 07:53:53 +02:00
|
|
|
#endif /* !DBUG_OFF */
|
2004-07-22 12:38:09 +02:00
|
|
|
|
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
/*
|
|
|
|
Instruct NDB to set the value of the hidden primary key
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool ha_ndbcluster::set_hidden_key(NdbOperation *ndb_op,
|
2005-02-16 14:18:32 +01:00
|
|
|
uint fieldnr, const byte *field_ptr)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
|
|
|
DBUG_ENTER("set_hidden_key");
|
2005-11-07 12:19:28 +01:00
|
|
|
DBUG_RETURN(ndb_op->equal(fieldnr, (char*)field_ptr) != 0);
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Instruct NDB to set the value of one primary key attribute
|
|
|
|
*/
|
|
|
|
|
|
|
|
int ha_ndbcluster::set_ndb_key(NdbOperation *ndb_op, Field *field,
|
|
|
|
uint fieldnr, const byte *field_ptr)
|
|
|
|
{
|
|
|
|
uint32 pack_len= field->pack_length();
|
|
|
|
DBUG_ENTER("set_ndb_key");
|
|
|
|
DBUG_PRINT("enter", ("%d: %s, ndb_type: %u, len=%d",
|
|
|
|
fieldnr, field->field_name, field->type(),
|
|
|
|
pack_len));
|
|
|
|
DBUG_DUMP("key", (char*)field_ptr, pack_len);
|
|
|
|
|
2005-06-20 07:53:53 +02:00
|
|
|
DBUG_ASSERT(ndb_supported_type(field->type()));
|
|
|
|
DBUG_ASSERT(! (field->flags & BLOB_FLAG));
|
|
|
|
// Common implementation for most field types
|
|
|
|
DBUG_RETURN(ndb_op->equal(fieldnr, (char*) field_ptr, pack_len) != 0);
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Instruct NDB to set the value of one attribute
|
|
|
|
*/
|
|
|
|
|
|
|
|
int ha_ndbcluster::set_ndb_value(NdbOperation *ndb_op, Field *field,
|
2005-11-06 00:20:37 +01:00
|
|
|
uint fieldnr, int row_offset,
|
|
|
|
bool *set_blob_value)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
2005-11-06 00:20:37 +01:00
|
|
|
const byte* field_ptr= field->ptr + row_offset;
|
|
|
|
uint32 pack_len= field->pack_length();
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_ENTER("set_ndb_value");
|
2005-11-06 00:20:37 +01:00
|
|
|
DBUG_PRINT("enter", ("%d: %s type: %u len=%d is_null=%s",
|
2004-04-15 09:14:14 +02:00
|
|
|
fieldnr, field->field_name, field->type(),
|
2005-11-06 00:20:37 +01:00
|
|
|
pack_len, field->is_null(row_offset) ? "Y" : "N"));
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_DUMP("value", (char*) field_ptr, pack_len);
|
2004-07-22 12:38:09 +02:00
|
|
|
|
2005-06-20 07:53:53 +02:00
|
|
|
DBUG_ASSERT(ndb_supported_type(field->type()));
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
2004-10-20 19:22:58 +02:00
|
|
|
// ndb currently does not support size 0
|
2004-12-10 16:55:04 +01:00
|
|
|
uint32 empty_field;
|
2004-10-20 19:22:58 +02:00
|
|
|
if (pack_len == 0)
|
|
|
|
{
|
2004-12-10 16:55:04 +01:00
|
|
|
pack_len= sizeof(empty_field);
|
|
|
|
field_ptr= (byte *)&empty_field;
|
2005-11-06 00:20:37 +01:00
|
|
|
if (field->is_null(row_offset))
|
2005-02-16 14:18:32 +01:00
|
|
|
empty_field= 0;
|
2004-12-10 16:55:04 +01:00
|
|
|
else
|
2005-02-16 14:18:32 +01:00
|
|
|
empty_field= 1;
|
2004-10-20 19:22:58 +02:00
|
|
|
}
|
2004-07-22 12:38:09 +02:00
|
|
|
if (! (field->flags & BLOB_FLAG))
|
|
|
|
{
|
2004-12-23 15:28:41 +01:00
|
|
|
if (field->type() != MYSQL_TYPE_BIT)
|
|
|
|
{
|
2005-11-06 00:20:37 +01:00
|
|
|
if (field->is_null(row_offset))
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("field is NULL"));
|
2005-02-16 14:18:32 +01:00
|
|
|
// Set value to NULL
|
2005-11-07 12:19:28 +01:00
|
|
|
DBUG_RETURN((ndb_op->setValue(fieldnr, (char*)NULL) != 0));
|
2005-11-06 00:20:37 +01:00
|
|
|
}
|
2005-02-16 14:18:32 +01:00
|
|
|
// Common implementation for most field types
|
2005-11-07 12:19:28 +01:00
|
|
|
DBUG_RETURN(ndb_op->setValue(fieldnr, (char*)field_ptr) != 0);
|
2004-12-23 15:28:41 +01:00
|
|
|
}
|
|
|
|
else // if (field->type() == MYSQL_TYPE_BIT)
|
|
|
|
{
|
2005-02-16 14:18:32 +01:00
|
|
|
longlong bits= field->val_int();
|
2004-12-23 15:28:41 +01:00
|
|
|
|
2005-02-16 14:18:32 +01:00
|
|
|
// Round up bit field length to nearest word boundry
|
|
|
|
pack_len= ((pack_len + 3) >> 2) << 2;
|
2004-12-23 15:28:41 +01:00
|
|
|
DBUG_ASSERT(pack_len <= 8);
|
2005-11-06 00:20:37 +01:00
|
|
|
if (field->is_null(row_offset))
|
2004-12-23 15:28:41 +01:00
|
|
|
// Set value to NULL
|
2005-11-07 12:19:28 +01:00
|
|
|
DBUG_RETURN((ndb_op->setValue(fieldnr, (char*)NULL) != 0));
|
2004-12-23 15:28:41 +01:00
|
|
|
DBUG_PRINT("info", ("bit field"));
|
2005-01-03 14:29:27 +01:00
|
|
|
DBUG_DUMP("value", (char*)&bits, pack_len);
|
2005-01-20 15:50:56 +01:00
|
|
|
#ifdef WORDS_BIGENDIAN
|
2005-02-16 14:18:32 +01:00
|
|
|
if (pack_len < 5)
|
|
|
|
{
|
2005-11-07 12:19:28 +01:00
|
|
|
DBUG_RETURN(ndb_op->setValue(fieldnr, ((char*)&bits)+4) != 0);
|
2005-02-16 14:18:32 +01:00
|
|
|
}
|
2005-01-20 15:50:56 +01:00
|
|
|
#endif
|
2005-11-07 12:19:28 +01:00
|
|
|
DBUG_RETURN(ndb_op->setValue(fieldnr, (char*)&bits) != 0);
|
2004-12-23 15:28:41 +01:00
|
|
|
}
|
2004-07-22 12:38:09 +02:00
|
|
|
}
|
|
|
|
// Blob type
|
2004-07-23 15:46:56 +02:00
|
|
|
NdbBlob *ndb_blob= ndb_op->getBlobHandle(fieldnr);
|
2004-07-22 12:38:09 +02:00
|
|
|
if (ndb_blob != NULL)
|
|
|
|
{
|
2005-11-06 00:20:37 +01:00
|
|
|
if (field->is_null(row_offset))
|
2004-07-22 12:38:09 +02:00
|
|
|
DBUG_RETURN(ndb_blob->setNull() != 0);
|
|
|
|
|
|
|
|
Field_blob *field_blob= (Field_blob*)field;
|
|
|
|
|
|
|
|
// Get length and pointer to data
|
|
|
|
uint32 blob_len= field_blob->get_length(field_ptr);
|
|
|
|
char* blob_ptr= NULL;
|
|
|
|
field_blob->get_ptr(&blob_ptr);
|
|
|
|
|
2004-09-02 12:42:03 +02:00
|
|
|
// Looks like NULL ptr signals length 0 blob
|
|
|
|
if (blob_ptr == NULL) {
|
|
|
|
DBUG_ASSERT(blob_len == 0);
|
2004-09-15 17:31:15 +02:00
|
|
|
blob_ptr= (char*)"";
|
2004-09-02 12:42:03 +02:00
|
|
|
}
|
2004-07-22 12:38:09 +02:00
|
|
|
|
2005-07-19 22:04:43 +02:00
|
|
|
DBUG_PRINT("value", ("set blob ptr=%p len=%u",
|
|
|
|
blob_ptr, blob_len));
|
2004-07-22 12:38:09 +02:00
|
|
|
DBUG_DUMP("value", (char*)blob_ptr, min(blob_len, 26));
|
|
|
|
|
2004-10-01 13:16:49 +02:00
|
|
|
if (set_blob_value)
|
2005-02-16 14:18:32 +01:00
|
|
|
*set_blob_value= TRUE;
|
2004-07-22 12:38:09 +02:00
|
|
|
// No callback needed to write value
|
|
|
|
DBUG_RETURN(ndb_blob->setValue(blob_ptr, blob_len) != 0);
|
|
|
|
}
|
|
|
|
DBUG_RETURN(1);
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
2004-07-22 12:38:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Callback to read all blob values.
|
|
|
|
- not done in unpack_record because unpack_record is valid
|
|
|
|
after execute(Commit) but reading blobs is not
|
|
|
|
- may only generate read operations; they have to be executed
|
|
|
|
somewhere before the data is available
|
|
|
|
- due to single buffer for all blobs, we let the last blob
|
|
|
|
process all blobs (last so that all are active)
|
|
|
|
- null bit is still set in unpack_record
|
|
|
|
- TODO allocate blob part aligned buffers
|
|
|
|
*/
|
|
|
|
|
2004-07-29 10:44:53 +02:00
|
|
|
NdbBlob::ActiveHook g_get_ndb_blobs_value;
|
2004-07-22 12:38:09 +02:00
|
|
|
|
2004-07-29 10:44:53 +02:00
|
|
|
int g_get_ndb_blobs_value(NdbBlob *ndb_blob, void *arg)
|
2004-07-22 12:38:09 +02:00
|
|
|
{
|
2004-07-29 10:44:53 +02:00
|
|
|
DBUG_ENTER("g_get_ndb_blobs_value");
|
2004-07-22 12:38:09 +02:00
|
|
|
if (ndb_blob->blobsNextBlob() != NULL)
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
ha_ndbcluster *ha= (ha_ndbcluster *)arg;
|
2006-01-25 22:22:50 +01:00
|
|
|
int ret= get_ndb_blobs_value(ha->table, ha->m_value,
|
|
|
|
ha->m_blobs_buffer, ha->m_blobs_buffer_size,
|
2006-06-21 09:42:15 +02:00
|
|
|
ha->m_blobs_offset);
|
2006-01-25 22:22:50 +01:00
|
|
|
DBUG_RETURN(ret);
|
2004-07-22 12:38:09 +02:00
|
|
|
}
|
|
|
|
|
2006-01-25 22:22:50 +01:00
|
|
|
/*
|
|
|
|
This routine is shared by injector. There is no common blobs buffer
|
|
|
|
so the buffer and length are passed by reference. Injector also
|
|
|
|
passes a record pointer diff.
|
|
|
|
*/
|
|
|
|
int get_ndb_blobs_value(TABLE* table, NdbValue* value_array,
|
|
|
|
byte*& buffer, uint& buffer_size,
|
|
|
|
my_ptrdiff_t ptrdiff)
|
2004-07-22 12:38:09 +02:00
|
|
|
{
|
|
|
|
DBUG_ENTER("get_ndb_blobs_value");
|
|
|
|
|
|
|
|
// Field has no field number so cannot use TABLE blob_field
|
|
|
|
// Loop twice, first only counting total buffer size
|
|
|
|
for (int loop= 0; loop <= 1; loop++)
|
|
|
|
{
|
|
|
|
uint32 offset= 0;
|
2006-01-25 22:22:50 +01:00
|
|
|
for (uint i= 0; i < table->s->fields; i++)
|
2004-07-22 12:38:09 +02:00
|
|
|
{
|
|
|
|
Field *field= table->field[i];
|
2006-01-25 22:22:50 +01:00
|
|
|
NdbValue value= value_array[i];
|
2006-02-05 19:11:11 +01:00
|
|
|
if (! (field->flags & BLOB_FLAG))
|
|
|
|
continue;
|
|
|
|
if (value.blob == NULL)
|
2004-07-22 12:38:09 +02:00
|
|
|
{
|
2006-02-05 19:11:11 +01:00
|
|
|
DBUG_PRINT("info",("[%u] skipped", i));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
Field_blob *field_blob= (Field_blob *)field;
|
|
|
|
NdbBlob *ndb_blob= value.blob;
|
|
|
|
int isNull;
|
|
|
|
if (ndb_blob->getNull(isNull) != 0)
|
|
|
|
ERR_RETURN(ndb_blob->getNdbError());
|
|
|
|
if (isNull == 0) {
|
|
|
|
Uint64 len64= 0;
|
|
|
|
if (ndb_blob->getLength(len64) != 0)
|
|
|
|
ERR_RETURN(ndb_blob->getNdbError());
|
|
|
|
// Align to Uint64
|
|
|
|
uint32 size= len64;
|
|
|
|
if (size % 8 != 0)
|
|
|
|
size+= 8 - size % 8;
|
|
|
|
if (loop == 1)
|
2006-01-27 20:27:10 +01:00
|
|
|
{
|
2006-02-05 19:11:11 +01:00
|
|
|
char *buf= buffer + offset;
|
|
|
|
uint32 len= 0xffffffff; // Max uint32
|
|
|
|
if (ndb_blob->readData(buf, len) != 0)
|
|
|
|
ERR_RETURN(ndb_blob->getNdbError());
|
|
|
|
DBUG_PRINT("info", ("[%u] offset=%u buf=%p len=%u [ptrdiff=%d]",
|
|
|
|
i, offset, buf, len, (int)ptrdiff));
|
|
|
|
DBUG_ASSERT(len == len64);
|
|
|
|
// Ugly hack assumes only ptr needs to be changed
|
|
|
|
field_blob->ptr+= ptrdiff;
|
|
|
|
field_blob->set_ptr(len, buf);
|
|
|
|
field_blob->ptr-= ptrdiff;
|
2006-01-27 20:27:10 +01:00
|
|
|
}
|
2006-02-05 19:11:11 +01:00
|
|
|
offset+= size;
|
|
|
|
}
|
|
|
|
else if (loop == 1) // undefined or null
|
|
|
|
{
|
|
|
|
// have to set length even in this case
|
|
|
|
char *buf= buffer + offset; // or maybe NULL
|
|
|
|
uint32 len= 0;
|
|
|
|
field_blob->ptr+= ptrdiff;
|
|
|
|
field_blob->set_ptr(len, buf);
|
|
|
|
field_blob->ptr-= ptrdiff;
|
|
|
|
DBUG_PRINT("info", ("[%u] isNull=%d", i, isNull));
|
2004-07-22 12:38:09 +02:00
|
|
|
}
|
|
|
|
}
|
2006-01-25 22:22:50 +01:00
|
|
|
if (loop == 0 && offset > buffer_size)
|
2004-07-22 12:38:09 +02:00
|
|
|
{
|
2006-01-25 22:22:50 +01:00
|
|
|
my_free(buffer, MYF(MY_ALLOW_ZERO_PTR));
|
|
|
|
buffer_size= 0;
|
|
|
|
DBUG_PRINT("info", ("allocate blobs buffer size %u", offset));
|
|
|
|
buffer= my_malloc(offset, MYF(MY_WME));
|
|
|
|
if (buffer == NULL)
|
2004-07-22 12:38:09 +02:00
|
|
|
DBUG_RETURN(-1);
|
2006-01-25 22:22:50 +01:00
|
|
|
buffer_size= offset;
|
2004-07-22 12:38:09 +02:00
|
|
|
}
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
2004-07-22 12:38:09 +02:00
|
|
|
DBUG_RETURN(0);
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Instruct NDB to fetch one field
|
2004-07-22 12:38:09 +02:00
|
|
|
- data is read directly into buffer provided by field
|
|
|
|
if field is NULL, data is read into memory provided by NDBAPI
|
2004-04-15 09:14:14 +02:00
|
|
|
*/
|
|
|
|
|
2004-07-22 12:38:09 +02:00
|
|
|
int ha_ndbcluster::get_ndb_value(NdbOperation *ndb_op, Field *field,
|
2004-09-20 12:40:53 +02:00
|
|
|
uint fieldnr, byte* buf)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
|
|
|
DBUG_ENTER("get_ndb_value");
|
2004-07-22 12:38:09 +02:00
|
|
|
DBUG_PRINT("enter", ("fieldnr: %d flags: %o", fieldnr,
|
|
|
|
(int)(field != NULL ? field->flags : 0)));
|
|
|
|
|
|
|
|
if (field != NULL)
|
|
|
|
{
|
2005-06-20 07:53:53 +02:00
|
|
|
DBUG_ASSERT(buf);
|
|
|
|
DBUG_ASSERT(ndb_supported_type(field->type()));
|
2004-07-22 12:38:09 +02:00
|
|
|
DBUG_ASSERT(field->ptr != NULL);
|
|
|
|
if (! (field->flags & BLOB_FLAG))
|
2005-02-16 14:18:32 +01:00
|
|
|
{
|
2004-12-23 15:28:41 +01:00
|
|
|
if (field->type() != MYSQL_TYPE_BIT)
|
|
|
|
{
|
2005-02-16 14:18:32 +01:00
|
|
|
byte *field_buf;
|
|
|
|
if (field->pack_length() != 0)
|
|
|
|
field_buf= buf + (field->ptr - table->record[0]);
|
|
|
|
else
|
|
|
|
field_buf= (byte *)&dummy_buf;
|
|
|
|
m_value[fieldnr].rec= ndb_op->getValue(fieldnr,
|
|
|
|
field_buf);
|
|
|
|
}
|
2004-12-23 15:28:41 +01:00
|
|
|
else // if (field->type() == MYSQL_TYPE_BIT)
|
|
|
|
{
|
|
|
|
m_value[fieldnr].rec= ndb_op->getValue(fieldnr);
|
|
|
|
}
|
2004-07-22 12:38:09 +02:00
|
|
|
DBUG_RETURN(m_value[fieldnr].rec == NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Blob type
|
|
|
|
NdbBlob *ndb_blob= ndb_op->getBlobHandle(fieldnr);
|
|
|
|
m_value[fieldnr].blob= ndb_blob;
|
|
|
|
if (ndb_blob != NULL)
|
|
|
|
{
|
|
|
|
// Set callback
|
2006-06-21 09:36:50 +02:00
|
|
|
m_blobs_offset= buf - (byte*) table->record[0];
|
2004-07-22 12:38:09 +02:00
|
|
|
void *arg= (void *)this;
|
2004-07-29 10:44:53 +02:00
|
|
|
DBUG_RETURN(ndb_blob->setActiveHook(g_get_ndb_blobs_value, arg) != 0);
|
2004-07-22 12:38:09 +02:00
|
|
|
}
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Used for hidden key only
|
2006-02-10 17:40:22 +01:00
|
|
|
m_value[fieldnr].rec= ndb_op->getValue(fieldnr, m_ref);
|
2004-07-22 12:38:09 +02:00
|
|
|
DBUG_RETURN(m_value[fieldnr].rec == NULL);
|
|
|
|
}
|
|
|
|
|
2006-03-14 15:27:38 +01:00
|
|
|
/*
|
|
|
|
Instruct NDB to fetch the partition id (fragment id)
|
|
|
|
*/
|
|
|
|
int ha_ndbcluster::get_ndb_partition_id(NdbOperation *ndb_op)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("get_ndb_partition_id");
|
2006-03-18 10:04:39 +01:00
|
|
|
DBUG_RETURN(ndb_op->getValue(NdbDictionary::Column::FRAGMENT,
|
|
|
|
(char *)&m_part_id) == NULL);
|
2006-03-14 15:27:38 +01:00
|
|
|
}
|
2004-07-22 12:38:09 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
Check if any set or get of blob value in current query.
|
|
|
|
*/
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
|
2005-04-28 14:45:27 +02:00
|
|
|
bool ha_ndbcluster::uses_blob_value()
|
2004-07-22 12:38:09 +02:00
|
|
|
{
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
uint blob_fields;
|
|
|
|
MY_BITMAP *bitmap;
|
|
|
|
uint *blob_index, *blob_index_end;
|
2006-01-17 08:40:00 +01:00
|
|
|
if (table_share->blob_fields == 0)
|
2004-10-14 17:03:46 +02:00
|
|
|
return FALSE;
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
|
|
|
|
bitmap= m_write_op ? table->write_set : table->read_set;
|
|
|
|
blob_index= table_share->blob_field;
|
|
|
|
blob_index_end= blob_index + table_share->blob_fields;
|
|
|
|
do
|
2004-07-22 12:38:09 +02:00
|
|
|
{
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
if (bitmap_is_set(table->write_set,
|
|
|
|
table->field[*blob_index]->field_index))
|
|
|
|
return TRUE;
|
|
|
|
} while (++blob_index != blob_index_end);
|
2004-10-14 17:03:46 +02:00
|
|
|
return FALSE;
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Get metadata for this table from NDB
|
|
|
|
|
|
|
|
IMPLEMENTATION
|
|
|
|
- check that frm-file on disk is equal to frm-file
|
|
|
|
of table accessed in NDB
|
2005-11-23 21:45:02 +01:00
|
|
|
|
|
|
|
RETURN
|
|
|
|
0 ok
|
|
|
|
-2 Meta data has changed; Re-read data and try again
|
2004-04-15 09:14:14 +02:00
|
|
|
*/
|
|
|
|
|
2006-02-13 11:23:13 +01:00
|
|
|
int cmp_frm(const NDBTAB *ndbtab, const void *pack_data,
|
|
|
|
uint pack_length)
|
2005-11-06 00:20:37 +01:00
|
|
|
{
|
|
|
|
DBUG_ENTER("cmp_frm");
|
|
|
|
/*
|
|
|
|
Compare FrmData in NDB with frm file from disk.
|
|
|
|
*/
|
|
|
|
if ((pack_length != ndbtab->getFrmLength()) ||
|
|
|
|
(memcmp(pack_data, ndbtab->getFrmData(), pack_length)))
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
int ha_ndbcluster::get_metadata(const char *path)
|
|
|
|
{
|
2004-12-30 19:56:09 +01:00
|
|
|
Ndb *ndb= get_ndb();
|
|
|
|
NDBDICT *dict= ndb->getDictionary();
|
2004-04-15 09:14:14 +02:00
|
|
|
const NDBTAB *tab;
|
|
|
|
int error;
|
|
|
|
DBUG_ENTER("get_metadata");
|
|
|
|
DBUG_PRINT("enter", ("m_tabname: %s, path: %s", m_tabname, path));
|
|
|
|
|
2006-05-04 13:58:17 +02:00
|
|
|
DBUG_ASSERT(m_table == NULL);
|
|
|
|
DBUG_ASSERT(m_table_info == NULL);
|
2004-09-24 18:58:25 +02:00
|
|
|
|
2006-05-04 13:58:17 +02:00
|
|
|
const void *data, *pack_data;
|
|
|
|
uint length, pack_length;
|
|
|
|
|
|
|
|
/*
|
|
|
|
Compare FrmData in NDB with frm file from disk.
|
|
|
|
*/
|
|
|
|
error= 0;
|
|
|
|
if (readfrm(path, &data, &length) ||
|
|
|
|
packfrm(data, length, &pack_data, &pack_length))
|
|
|
|
{
|
|
|
|
my_free((char*)data, MYF(MY_ALLOW_ZERO_PTR));
|
|
|
|
my_free((char*)pack_data, MYF(MY_ALLOW_ZERO_PTR));
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
2004-04-15 09:14:14 +02:00
|
|
|
|
2006-05-04 13:58:17 +02:00
|
|
|
Ndb_table_guard ndbtab_g(dict, m_tabname);
|
|
|
|
if (!(tab= ndbtab_g.get_table()))
|
|
|
|
ERR_RETURN(dict->getNdbError());
|
|
|
|
|
|
|
|
if (get_ndb_share_state(m_share) != NSS_ALTERED
|
|
|
|
&& cmp_frm(tab, pack_data, pack_length))
|
|
|
|
{
|
|
|
|
DBUG_PRINT("error",
|
|
|
|
("metadata, pack_length: %d getFrmLength: %d memcmp: %d",
|
|
|
|
pack_length, tab->getFrmLength(),
|
|
|
|
memcmp(pack_data, tab->getFrmData(), pack_length)));
|
|
|
|
DBUG_DUMP("pack_data", (char*)pack_data, pack_length);
|
|
|
|
DBUG_DUMP("frm", (char*)tab->getFrmData(), tab->getFrmLength());
|
|
|
|
error= HA_ERR_TABLE_DEF_CHANGED;
|
|
|
|
}
|
|
|
|
my_free((char*)data, MYF(0));
|
|
|
|
my_free((char*)pack_data, MYF(0));
|
2004-09-24 18:58:25 +02:00
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
if (error)
|
2006-05-04 13:58:17 +02:00
|
|
|
goto err;
|
|
|
|
|
|
|
|
DBUG_PRINT("info", ("fetched table %s", tab->getName()));
|
|
|
|
m_table= tab;
|
|
|
|
if ((error= open_indexes(ndb, table, FALSE)) == 0)
|
|
|
|
{
|
|
|
|
ndbtab_g.release();
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
err:
|
|
|
|
ndbtab_g.invalidate();
|
|
|
|
m_table= NULL;
|
|
|
|
DBUG_RETURN(error);
|
2004-05-24 12:35:39 +02:00
|
|
|
}
|
2004-04-15 09:14:14 +02:00
|
|
|
|
2005-01-26 11:31:46 +01:00
|
|
|
static int fix_unique_index_attr_order(NDB_INDEX_DATA &data,
|
2005-02-16 14:18:32 +01:00
|
|
|
const NDBINDEX *index,
|
|
|
|
KEY *key_info)
|
2005-01-26 11:31:46 +01:00
|
|
|
{
|
|
|
|
DBUG_ENTER("fix_unique_index_attr_order");
|
|
|
|
unsigned sz= index->getNoOfIndexColumns();
|
|
|
|
|
|
|
|
if (data.unique_index_attrid_map)
|
|
|
|
my_free((char*)data.unique_index_attrid_map, MYF(0));
|
2006-06-19 11:45:34 +02:00
|
|
|
data.unique_index_attrid_map= (uchar*)my_malloc(sz,MYF(MY_WME));
|
2005-01-26 11:31:46 +01:00
|
|
|
|
|
|
|
KEY_PART_INFO* key_part= key_info->key_part;
|
|
|
|
KEY_PART_INFO* end= key_part+key_info->key_parts;
|
|
|
|
DBUG_ASSERT(key_info->key_parts == sz);
|
|
|
|
for (unsigned i= 0; key_part != end; key_part++, i++)
|
|
|
|
{
|
|
|
|
const char *field_name= key_part->field->field_name;
|
|
|
|
#ifndef DBUG_OFF
|
|
|
|
data.unique_index_attrid_map[i]= 255;
|
|
|
|
#endif
|
|
|
|
for (unsigned j= 0; j < sz; j++)
|
|
|
|
{
|
2005-03-22 17:42:08 +01:00
|
|
|
const NDBCOL *c= index->getColumn(j);
|
2005-05-18 20:50:29 +02:00
|
|
|
if (strcmp(field_name, c->getName()) == 0)
|
2005-01-26 11:31:46 +01:00
|
|
|
{
|
2005-02-16 14:18:32 +01:00
|
|
|
data.unique_index_attrid_map[i]= j;
|
|
|
|
break;
|
2005-01-26 11:31:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
DBUG_ASSERT(data.unique_index_attrid_map[i] != 255);
|
|
|
|
}
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
2004-08-19 11:10:35 +02:00
|
|
|
|
2006-01-11 12:35:28 +01:00
|
|
|
/*
|
|
|
|
Create all the indexes for a table.
|
|
|
|
If any index should fail to be created,
|
|
|
|
the error is returned immediately
|
|
|
|
*/
|
|
|
|
int ha_ndbcluster::create_indexes(Ndb *ndb, TABLE *tab)
|
2004-05-24 12:35:39 +02:00
|
|
|
{
|
2004-09-25 14:35:27 +02:00
|
|
|
uint i;
|
2004-08-19 11:10:35 +02:00
|
|
|
int error= 0;
|
2005-01-11 17:00:31 +01:00
|
|
|
const char *index_name;
|
2004-08-19 11:10:35 +02:00
|
|
|
KEY* key_info= tab->key_info;
|
2005-01-06 12:00:13 +01:00
|
|
|
const char **key_name= tab->s->keynames.type_names;
|
2005-03-22 17:42:08 +01:00
|
|
|
NDBDICT *dict= ndb->getDictionary();
|
2006-01-11 12:35:28 +01:00
|
|
|
DBUG_ENTER("ha_ndbcluster::create_indexes");
|
2004-05-24 12:35:39 +02:00
|
|
|
|
2005-01-06 12:00:13 +01:00
|
|
|
for (i= 0; i < tab->s->keys; i++, key_info++, key_name++)
|
2004-04-30 12:25:31 +02:00
|
|
|
{
|
2004-08-19 11:10:35 +02:00
|
|
|
index_name= *key_name;
|
2004-05-24 12:35:39 +02:00
|
|
|
NDB_INDEX_TYPE idx_type= get_index_type_from_table(i);
|
2006-01-11 12:35:28 +01:00
|
|
|
error= create_index(index_name, key_info, idx_type, i);
|
|
|
|
if (error)
|
2004-04-30 12:25:31 +02:00
|
|
|
{
|
2006-01-11 12:35:28 +01:00
|
|
|
DBUG_PRINT("error", ("Failed to create index %u", i));
|
|
|
|
break;
|
2004-04-30 12:25:31 +02:00
|
|
|
}
|
2006-01-11 12:35:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
DBUG_RETURN(error);
|
|
|
|
}
|
|
|
|
|
2006-05-04 15:55:38 +02:00
|
|
|
static void ndb_init_index(NDB_INDEX_DATA &data)
|
2006-01-11 12:35:28 +01:00
|
|
|
{
|
2006-05-04 15:55:38 +02:00
|
|
|
data.type= UNDEFINED_INDEX;
|
|
|
|
data.status= UNDEFINED;
|
|
|
|
data.unique_index= NULL;
|
|
|
|
data.index= NULL;
|
|
|
|
data.unique_index_attrid_map= NULL;
|
|
|
|
data.index_stat=NULL;
|
|
|
|
data.index_stat_cache_entries=0;
|
|
|
|
data.index_stat_update_freq=0;
|
|
|
|
data.index_stat_query_count=0;
|
2006-01-11 12:35:28 +01:00
|
|
|
}
|
|
|
|
|
2006-05-04 15:55:38 +02:00
|
|
|
static void ndb_clear_index(NDB_INDEX_DATA &data)
|
2006-01-11 12:35:28 +01:00
|
|
|
{
|
2006-05-04 15:55:38 +02:00
|
|
|
if (data.unique_index_attrid_map)
|
|
|
|
{
|
|
|
|
my_free((char*)data.unique_index_attrid_map, MYF(0));
|
|
|
|
}
|
|
|
|
if (data.index_stat)
|
|
|
|
{
|
|
|
|
delete data.index_stat;
|
|
|
|
}
|
|
|
|
ndb_init_index(data);
|
2006-01-11 12:35:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Associate a direct reference to an index handle
|
|
|
|
with an index (for faster access)
|
|
|
|
*/
|
|
|
|
int ha_ndbcluster::add_index_handle(THD *thd, NDBDICT *dict, KEY *key_info,
|
|
|
|
const char *index_name, uint index_no)
|
|
|
|
{
|
|
|
|
int error= 0;
|
|
|
|
NDB_INDEX_TYPE idx_type= get_index_type_from_table(index_no);
|
|
|
|
m_index[index_no].type= idx_type;
|
2006-04-19 14:54:39 +02:00
|
|
|
DBUG_ENTER("ha_ndbcluster::add_index_handle");
|
|
|
|
DBUG_PRINT("enter", ("table %s", m_tabname));
|
2006-01-11 12:35:28 +01:00
|
|
|
|
|
|
|
if (idx_type != PRIMARY_KEY_INDEX && idx_type != UNIQUE_INDEX)
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("Get handle to index %s", index_name));
|
2006-04-19 14:54:39 +02:00
|
|
|
const NDBINDEX *index;
|
|
|
|
do
|
|
|
|
{
|
2006-05-04 13:58:17 +02:00
|
|
|
index= dict->getIndexGlobal(index_name, *m_table);
|
2006-04-19 14:54:39 +02:00
|
|
|
if (!index)
|
|
|
|
ERR_RETURN(dict->getNdbError());
|
|
|
|
DBUG_PRINT("info", ("index: 0x%x id: %d version: %d.%d status: %d",
|
|
|
|
index,
|
|
|
|
index->getObjectId(),
|
|
|
|
index->getObjectVersion() & 0xFFFFFF,
|
|
|
|
index->getObjectVersion() >> 24,
|
|
|
|
index->getObjectStatus()));
|
2006-05-04 13:58:17 +02:00
|
|
|
DBUG_ASSERT(index->getObjectStatus() ==
|
|
|
|
NdbDictionary::Object::Retrieved);
|
2006-04-19 14:54:39 +02:00
|
|
|
break;
|
|
|
|
} while (1);
|
2006-05-04 13:58:17 +02:00
|
|
|
m_index[index_no].index= index;
|
2006-01-11 12:35:28 +01:00
|
|
|
// ordered index - add stats
|
|
|
|
NDB_INDEX_DATA& d=m_index[index_no];
|
|
|
|
delete d.index_stat;
|
|
|
|
d.index_stat=NULL;
|
|
|
|
if (thd->variables.ndb_index_stat_enable)
|
2004-08-19 11:10:35 +02:00
|
|
|
{
|
2006-01-11 12:35:28 +01:00
|
|
|
d.index_stat=new NdbIndexStat(index);
|
|
|
|
d.index_stat_cache_entries=thd->variables.ndb_index_stat_cache_entries;
|
|
|
|
d.index_stat_update_freq=thd->variables.ndb_index_stat_update_freq;
|
|
|
|
d.index_stat_query_count=0;
|
|
|
|
d.index_stat->alloc_cache(d.index_stat_cache_entries);
|
|
|
|
DBUG_PRINT("info", ("index %s stat=on cache_entries=%u update_freq=%u",
|
|
|
|
index->getName(),
|
|
|
|
d.index_stat_cache_entries,
|
|
|
|
d.index_stat_update_freq));
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("index %s stat=off", index->getName()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (idx_type == UNIQUE_ORDERED_INDEX || idx_type == UNIQUE_INDEX)
|
|
|
|
{
|
|
|
|
char unique_index_name[FN_LEN];
|
|
|
|
static const char* unique_suffix= "$unique";
|
2006-03-24 10:42:55 +01:00
|
|
|
m_has_unique_index= TRUE;
|
2006-01-11 12:35:28 +01:00
|
|
|
strxnmov(unique_index_name, FN_LEN, index_name, unique_suffix, NullS);
|
|
|
|
DBUG_PRINT("info", ("Get handle to unique_index %s", unique_index_name));
|
2006-04-19 14:54:39 +02:00
|
|
|
const NDBINDEX *index;
|
|
|
|
do
|
|
|
|
{
|
2006-05-04 13:58:17 +02:00
|
|
|
index= dict->getIndexGlobal(unique_index_name, *m_table);
|
2006-04-19 14:54:39 +02:00
|
|
|
if (!index)
|
|
|
|
ERR_RETURN(dict->getNdbError());
|
|
|
|
DBUG_PRINT("info", ("index: 0x%x id: %d version: %d.%d status: %d",
|
|
|
|
index,
|
|
|
|
index->getObjectId(),
|
|
|
|
index->getObjectVersion() & 0xFFFFFF,
|
|
|
|
index->getObjectVersion() >> 24,
|
|
|
|
index->getObjectStatus()));
|
2006-05-04 13:58:17 +02:00
|
|
|
DBUG_ASSERT(index->getObjectStatus() ==
|
|
|
|
NdbDictionary::Object::Retrieved);
|
2006-04-19 14:54:39 +02:00
|
|
|
break;
|
|
|
|
} while (1);
|
2006-05-04 13:58:17 +02:00
|
|
|
m_index[index_no].unique_index= index;
|
2006-01-11 12:35:28 +01:00
|
|
|
error= fix_unique_index_attr_order(m_index[index_no], index, key_info);
|
|
|
|
}
|
|
|
|
if (!error)
|
|
|
|
m_index[index_no].status= ACTIVE;
|
|
|
|
|
|
|
|
DBUG_RETURN(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Associate index handles for each index of a table
|
|
|
|
*/
|
2006-02-17 09:44:12 +01:00
|
|
|
int ha_ndbcluster::open_indexes(Ndb *ndb, TABLE *tab, bool ignore_error)
|
2006-01-11 12:35:28 +01:00
|
|
|
{
|
|
|
|
uint i;
|
|
|
|
int error= 0;
|
|
|
|
THD *thd=current_thd;
|
|
|
|
NDBDICT *dict= ndb->getDictionary();
|
|
|
|
const char *index_name;
|
|
|
|
KEY* key_info= tab->key_info;
|
|
|
|
const char **key_name= tab->s->keynames.type_names;
|
|
|
|
DBUG_ENTER("ha_ndbcluster::open_indexes");
|
2006-03-24 10:42:55 +01:00
|
|
|
m_has_unique_index= FALSE;
|
2006-01-11 12:35:28 +01:00
|
|
|
for (i= 0; i < tab->s->keys; i++, key_info++, key_name++)
|
|
|
|
{
|
|
|
|
if ((error= add_index_handle(thd, dict, key_info, *key_name, i)))
|
2006-02-17 09:44:12 +01:00
|
|
|
if (ignore_error)
|
|
|
|
m_index[i].index= m_index[i].unique_index= NULL;
|
|
|
|
else
|
|
|
|
break;
|
2006-01-11 12:35:28 +01:00
|
|
|
}
|
2006-05-04 13:58:17 +02:00
|
|
|
|
|
|
|
if (error && !ignore_error)
|
|
|
|
{
|
|
|
|
while (i > 0)
|
|
|
|
{
|
|
|
|
i--;
|
|
|
|
if (m_index[i].index)
|
|
|
|
{
|
|
|
|
dict->removeIndexGlobal(*m_index[i].index, 1);
|
|
|
|
m_index[i].index= NULL;
|
|
|
|
}
|
|
|
|
if (m_index[i].unique_index)
|
|
|
|
{
|
|
|
|
dict->removeIndexGlobal(*m_index[i].unique_index, 1);
|
|
|
|
m_index[i].unique_index= NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DBUG_ASSERT(error == 0 || error == 4243);
|
|
|
|
|
2006-01-11 12:35:28 +01:00
|
|
|
DBUG_RETURN(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Renumber indexes in index list by shifting out
|
|
|
|
indexes that are to be dropped
|
|
|
|
*/
|
2006-01-27 17:23:14 +01:00
|
|
|
void ha_ndbcluster::renumber_indexes(Ndb *ndb, TABLE *tab)
|
2006-01-11 12:35:28 +01:00
|
|
|
{
|
|
|
|
uint i;
|
|
|
|
const char *index_name;
|
|
|
|
KEY* key_info= tab->key_info;
|
|
|
|
const char **key_name= tab->s->keynames.type_names;
|
|
|
|
NDBDICT *dict= ndb->getDictionary();
|
|
|
|
DBUG_ENTER("ha_ndbcluster::renumber_indexes");
|
|
|
|
|
|
|
|
for (i= 0; i < tab->s->keys; i++, key_info++, key_name++)
|
|
|
|
{
|
|
|
|
index_name= *key_name;
|
|
|
|
NDB_INDEX_TYPE idx_type= get_index_type_from_table(i);
|
|
|
|
m_index[i].type= idx_type;
|
|
|
|
if (m_index[i].status == TO_BE_DROPPED)
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("Shifting index %s(%i) out of the list",
|
|
|
|
index_name, i));
|
|
|
|
NDB_INDEX_DATA tmp;
|
|
|
|
uint j= i + 1;
|
|
|
|
// Shift index out of list
|
|
|
|
while(j != MAX_KEY && m_index[j].status != UNDEFINED)
|
2004-08-19 11:10:35 +02:00
|
|
|
{
|
2006-01-11 12:35:28 +01:00
|
|
|
tmp= m_index[j - 1];
|
|
|
|
m_index[j - 1]= m_index[j];
|
|
|
|
m_index[j]= tmp;
|
|
|
|
j++;
|
2004-08-19 11:10:35 +02:00
|
|
|
}
|
|
|
|
}
|
2006-01-11 12:35:28 +01:00
|
|
|
}
|
|
|
|
|
2006-01-27 17:23:14 +01:00
|
|
|
DBUG_VOID_RETURN;
|
2006-01-11 12:35:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Drop all indexes that are marked for deletion
|
|
|
|
*/
|
|
|
|
int ha_ndbcluster::drop_indexes(Ndb *ndb, TABLE *tab)
|
|
|
|
{
|
|
|
|
uint i;
|
|
|
|
int error= 0;
|
|
|
|
const char *index_name;
|
|
|
|
KEY* key_info= tab->key_info;
|
|
|
|
NDBDICT *dict= ndb->getDictionary();
|
|
|
|
DBUG_ENTER("ha_ndbcluster::drop_indexes");
|
|
|
|
|
2006-03-09 17:42:35 +01:00
|
|
|
for (i= 0; i < tab->s->keys; i++, key_info++)
|
2006-01-11 12:35:28 +01:00
|
|
|
{
|
|
|
|
NDB_INDEX_TYPE idx_type= get_index_type_from_table(i);
|
|
|
|
m_index[i].type= idx_type;
|
|
|
|
if (m_index[i].status == TO_BE_DROPPED)
|
2004-08-18 19:13:39 +02:00
|
|
|
{
|
2006-05-04 13:58:17 +02:00
|
|
|
const NdbDictionary::Index *index= m_index[i].index;
|
|
|
|
const NdbDictionary::Index *unique_index= m_index[i].unique_index;
|
2006-01-11 12:35:28 +01:00
|
|
|
|
|
|
|
if (index)
|
2005-09-15 02:33:28 +02:00
|
|
|
{
|
2006-01-11 12:35:28 +01:00
|
|
|
index_name= index->getName();
|
|
|
|
DBUG_PRINT("info", ("Dropping index %u: %s", i, index_name));
|
|
|
|
// Drop ordered index from ndb
|
2006-05-04 13:58:17 +02:00
|
|
|
error= dict->dropIndexGlobal(*index);
|
|
|
|
if (!error)
|
|
|
|
{
|
|
|
|
dict->removeIndexGlobal(*index, 1);
|
|
|
|
m_index[i].index= NULL;
|
|
|
|
}
|
2006-01-11 12:35:28 +01:00
|
|
|
}
|
|
|
|
if (!error && unique_index)
|
2005-09-15 02:33:28 +02:00
|
|
|
{
|
2006-03-09 17:42:35 +01:00
|
|
|
index_name= unique_index->getName();
|
|
|
|
DBUG_PRINT("info", ("Dropping unique index %u: %s", i, index_name));
|
2006-01-11 12:35:28 +01:00
|
|
|
// Drop unique index from ndb
|
2006-05-04 13:58:17 +02:00
|
|
|
error= dict->dropIndexGlobal(*unique_index);
|
|
|
|
if (!error)
|
|
|
|
{
|
|
|
|
dict->removeIndexGlobal(*unique_index, 1);
|
|
|
|
m_index[i].unique_index= NULL;
|
|
|
|
}
|
2005-09-15 02:33:28 +02:00
|
|
|
}
|
2006-01-11 12:35:28 +01:00
|
|
|
if (error)
|
|
|
|
DBUG_RETURN(error);
|
2006-05-04 15:55:38 +02:00
|
|
|
ndb_clear_index(m_index[i]);
|
2006-01-11 12:35:28 +01:00
|
|
|
continue;
|
2005-01-26 11:31:46 +01:00
|
|
|
}
|
2004-08-18 19:13:39 +02:00
|
|
|
}
|
2004-08-19 11:10:35 +02:00
|
|
|
|
|
|
|
DBUG_RETURN(error);
|
2004-08-18 19:13:39 +02:00
|
|
|
}
|
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
/*
|
|
|
|
Decode the type of an index from information
|
|
|
|
provided in table object
|
|
|
|
*/
|
2004-05-24 12:35:39 +02:00
|
|
|
NDB_INDEX_TYPE ha_ndbcluster::get_index_type_from_table(uint inx) const
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
2006-03-09 13:41:11 +01:00
|
|
|
return get_index_type_from_key(inx, table_share->key_info,
|
|
|
|
inx == table_share->primary_key);
|
2006-01-11 12:35:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
NDB_INDEX_TYPE ha_ndbcluster::get_index_type_from_key(uint inx,
|
2006-03-09 13:41:11 +01:00
|
|
|
KEY *key_info,
|
|
|
|
bool primary) const
|
2006-01-11 12:35:28 +01:00
|
|
|
{
|
|
|
|
bool is_hash_index= (key_info[inx].algorithm ==
|
2005-11-23 21:45:02 +01:00
|
|
|
HA_KEY_ALG_HASH);
|
2006-03-09 13:41:11 +01:00
|
|
|
if (primary)
|
2004-05-24 12:35:39 +02:00
|
|
|
return is_hash_index ? PRIMARY_KEY_INDEX : PRIMARY_KEY_ORDERED_INDEX;
|
2006-01-11 12:35:28 +01:00
|
|
|
|
|
|
|
return ((key_info[inx].flags & HA_NOSAME) ?
|
2005-01-06 12:00:13 +01:00
|
|
|
(is_hash_index ? UNIQUE_INDEX : UNIQUE_ORDERED_INDEX) :
|
|
|
|
ORDERED_INDEX);
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
2004-05-24 12:35:39 +02:00
|
|
|
|
2004-11-22 10:35:03 +01:00
|
|
|
int ha_ndbcluster::check_index_fields_not_null(uint inx)
|
|
|
|
{
|
|
|
|
KEY* key_info= table->key_info + inx;
|
|
|
|
KEY_PART_INFO* key_part= key_info->key_part;
|
|
|
|
KEY_PART_INFO* end= key_part+key_info->key_parts;
|
2004-12-20 15:12:42 +01:00
|
|
|
DBUG_ENTER("ha_ndbcluster::check_index_fields_not_null");
|
2004-11-22 10:35:03 +01:00
|
|
|
|
|
|
|
for (; key_part != end; key_part++)
|
|
|
|
{
|
|
|
|
Field* field= key_part->field;
|
|
|
|
if (field->maybe_null())
|
|
|
|
{
|
2005-02-16 14:18:32 +01:00
|
|
|
my_printf_error(ER_NULL_COLUMN_IN_INDEX,ER(ER_NULL_COLUMN_IN_INDEX),
|
|
|
|
MYF(0),field->field_name);
|
|
|
|
DBUG_RETURN(ER_NULL_COLUMN_IN_INDEX);
|
2004-11-22 10:35:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
2004-04-15 09:14:14 +02:00
|
|
|
|
2006-05-04 13:58:17 +02:00
|
|
|
void ha_ndbcluster::release_metadata(THD *thd, Ndb *ndb)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
2004-05-24 12:35:39 +02:00
|
|
|
uint i;
|
2004-04-30 12:25:31 +02:00
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_ENTER("release_metadata");
|
|
|
|
DBUG_PRINT("enter", ("m_tabname: %s", m_tabname));
|
|
|
|
|
2006-05-04 13:58:17 +02:00
|
|
|
NDBDICT *dict= ndb->getDictionary();
|
|
|
|
int invalidate_indexes= 0;
|
|
|
|
if (thd && thd->lex && thd->lex->sql_command == SQLCOM_FLUSH)
|
|
|
|
{
|
|
|
|
invalidate_indexes = 1;
|
|
|
|
}
|
|
|
|
if (m_table != NULL)
|
|
|
|
{
|
|
|
|
if (m_table->getObjectStatus() == NdbDictionary::Object::Invalid)
|
|
|
|
invalidate_indexes= 1;
|
|
|
|
dict->removeTableGlobal(*m_table, invalidate_indexes);
|
|
|
|
}
|
|
|
|
// TODO investigate
|
|
|
|
DBUG_ASSERT(m_table_info == NULL);
|
2004-09-21 14:52:56 +02:00
|
|
|
m_table_info= NULL;
|
2004-04-15 09:14:14 +02:00
|
|
|
|
2004-05-24 12:35:39 +02:00
|
|
|
// Release index list
|
2004-04-30 12:25:31 +02:00
|
|
|
for (i= 0; i < MAX_KEY; i++)
|
|
|
|
{
|
2006-05-04 13:58:17 +02:00
|
|
|
if (m_index[i].unique_index)
|
|
|
|
{
|
|
|
|
DBUG_ASSERT(m_table != NULL);
|
|
|
|
dict->removeIndexGlobal(*m_index[i].unique_index, invalidate_indexes);
|
|
|
|
}
|
|
|
|
if (m_index[i].index)
|
|
|
|
{
|
|
|
|
DBUG_ASSERT(m_table != NULL);
|
|
|
|
dict->removeIndexGlobal(*m_index[i].index, invalidate_indexes);
|
|
|
|
}
|
2006-05-04 15:55:38 +02:00
|
|
|
ndb_clear_index(m_index[i]);
|
2004-04-30 12:25:31 +02:00
|
|
|
}
|
|
|
|
|
2006-05-04 13:58:17 +02:00
|
|
|
m_table= NULL;
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
2004-07-22 12:38:09 +02:00
|
|
|
int ha_ndbcluster::get_ndb_lock_type(enum thr_lock_type type)
|
2004-05-10 14:12:28 +02:00
|
|
|
{
|
2004-10-13 10:08:18 +02:00
|
|
|
if (type >= TL_WRITE_ALLOW_WRITE)
|
2004-09-29 01:42:34 +02:00
|
|
|
return NdbOperation::LM_Exclusive;
|
2006-06-12 14:23:21 +02:00
|
|
|
if (type == TL_READ_WITH_SHARED_LOCKS ||
|
|
|
|
uses_blob_value())
|
2004-10-05 13:51:32 +02:00
|
|
|
return NdbOperation::LM_Read;
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
return NdbOperation::LM_CommittedRead;
|
2004-05-10 14:12:28 +02:00
|
|
|
}
|
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
static const ulong index_type_flags[]=
|
|
|
|
{
|
|
|
|
/* UNDEFINED_INDEX */
|
|
|
|
0,
|
|
|
|
|
|
|
|
/* PRIMARY_KEY_INDEX */
|
2004-06-24 12:04:22 +02:00
|
|
|
HA_ONLY_WHOLE_INDEX,
|
2004-05-24 12:35:39 +02:00
|
|
|
|
|
|
|
/* PRIMARY_KEY_ORDERED_INDEX */
|
2004-05-10 14:46:06 +02:00
|
|
|
/*
|
2004-06-24 14:49:34 +02:00
|
|
|
Enable HA_KEYREAD_ONLY when "sorted" indexes are supported,
|
2004-05-10 14:46:06 +02:00
|
|
|
thus ORDERD BY clauses can be optimized by reading directly
|
|
|
|
through the index.
|
|
|
|
*/
|
2004-06-24 14:49:34 +02:00
|
|
|
// HA_KEYREAD_ONLY |
|
2004-09-03 13:55:40 +02:00
|
|
|
HA_READ_NEXT |
|
2004-12-20 15:12:42 +01:00
|
|
|
HA_READ_PREV |
|
2004-09-03 13:55:40 +02:00
|
|
|
HA_READ_RANGE |
|
|
|
|
HA_READ_ORDER,
|
2004-04-15 09:14:14 +02:00
|
|
|
|
|
|
|
/* UNIQUE_INDEX */
|
2004-06-24 12:04:22 +02:00
|
|
|
HA_ONLY_WHOLE_INDEX,
|
2004-04-15 09:14:14 +02:00
|
|
|
|
2004-05-24 12:35:39 +02:00
|
|
|
/* UNIQUE_ORDERED_INDEX */
|
2004-09-03 13:55:40 +02:00
|
|
|
HA_READ_NEXT |
|
2004-12-20 15:12:42 +01:00
|
|
|
HA_READ_PREV |
|
2004-09-03 13:55:40 +02:00
|
|
|
HA_READ_RANGE |
|
|
|
|
HA_READ_ORDER,
|
2004-05-24 12:35:39 +02:00
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
/* ORDERED_INDEX */
|
2004-09-03 13:55:40 +02:00
|
|
|
HA_READ_NEXT |
|
2004-12-20 15:12:42 +01:00
|
|
|
HA_READ_PREV |
|
2004-09-03 13:55:40 +02:00
|
|
|
HA_READ_RANGE |
|
|
|
|
HA_READ_ORDER
|
2004-04-15 09:14:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static const int index_flags_size= sizeof(index_type_flags)/sizeof(ulong);
|
|
|
|
|
|
|
|
inline NDB_INDEX_TYPE ha_ndbcluster::get_index_type(uint idx_no) const
|
|
|
|
{
|
|
|
|
DBUG_ASSERT(idx_no < MAX_KEY);
|
2004-08-18 19:13:39 +02:00
|
|
|
return m_index[idx_no].type;
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Get the flags for an index
|
|
|
|
|
|
|
|
RETURN
|
|
|
|
flags depending on the type of the index.
|
|
|
|
*/
|
|
|
|
|
2004-07-08 14:45:25 +02:00
|
|
|
inline ulong ha_ndbcluster::index_flags(uint idx_no, uint part,
|
|
|
|
bool all_parts) const
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
2004-12-20 15:12:42 +01:00
|
|
|
DBUG_ENTER("ha_ndbcluster::index_flags");
|
2005-11-23 21:45:02 +01:00
|
|
|
DBUG_PRINT("enter", ("idx_no: %u", idx_no));
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_ASSERT(get_index_type_from_table(idx_no) < index_flags_size);
|
2005-09-30 12:20:15 +02:00
|
|
|
DBUG_RETURN(index_type_flags[get_index_type_from_table(idx_no)] |
|
|
|
|
HA_KEY_SCAN_NOT_ROR);
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
|
2005-01-07 11:55:20 +01:00
|
|
|
static void shrink_varchar(Field* field, const byte* & ptr, char* buf)
|
|
|
|
{
|
2005-09-01 14:12:48 +02:00
|
|
|
if (field->type() == MYSQL_TYPE_VARCHAR && ptr != NULL) {
|
2005-01-07 11:55:20 +01:00
|
|
|
Field_varstring* f= (Field_varstring*)field;
|
2005-04-21 12:53:40 +02:00
|
|
|
if (f->length_bytes == 1) {
|
2005-01-07 11:55:20 +01:00
|
|
|
uint pack_len= field->pack_length();
|
|
|
|
DBUG_ASSERT(1 <= pack_len && pack_len <= 256);
|
|
|
|
if (ptr[1] == 0) {
|
|
|
|
buf[0]= ptr[0];
|
|
|
|
} else {
|
2005-05-06 10:39:30 +02:00
|
|
|
DBUG_ASSERT(FALSE);
|
2005-01-07 11:55:20 +01:00
|
|
|
buf[0]= 255;
|
|
|
|
}
|
|
|
|
memmove(buf + 1, ptr + 2, pack_len - 1);
|
|
|
|
ptr= buf;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-04-15 09:14:14 +02:00
|
|
|
|
|
|
|
int ha_ndbcluster::set_primary_key(NdbOperation *op, const byte *key)
|
|
|
|
{
|
2006-01-17 08:40:00 +01:00
|
|
|
KEY* key_info= table->key_info + table_share->primary_key;
|
2004-04-15 09:14:14 +02:00
|
|
|
KEY_PART_INFO* key_part= key_info->key_part;
|
|
|
|
KEY_PART_INFO* end= key_part+key_info->key_parts;
|
|
|
|
DBUG_ENTER("set_primary_key");
|
|
|
|
|
|
|
|
for (; key_part != end; key_part++)
|
|
|
|
{
|
|
|
|
Field* field= key_part->field;
|
2005-01-07 11:55:20 +01:00
|
|
|
const byte* ptr= key;
|
|
|
|
char buf[256];
|
|
|
|
shrink_varchar(field, ptr, buf);
|
2004-04-15 09:14:14 +02:00
|
|
|
if (set_ndb_key(op, field,
|
2005-02-16 14:18:32 +01:00
|
|
|
key_part->fieldnr-1, ptr))
|
2004-04-15 09:14:14 +02:00
|
|
|
ERR_RETURN(op->getNdbError());
|
2005-01-07 11:55:20 +01:00
|
|
|
key += key_part->store_length;
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-06 11:23:36 +02:00
|
|
|
int ha_ndbcluster::set_primary_key_from_record(NdbOperation *op, const byte *record)
|
2004-05-17 09:51:02 +02:00
|
|
|
{
|
2006-01-17 08:40:00 +01:00
|
|
|
KEY* key_info= table->key_info + table_share->primary_key;
|
2004-05-17 09:51:02 +02:00
|
|
|
KEY_PART_INFO* key_part= key_info->key_part;
|
|
|
|
KEY_PART_INFO* end= key_part+key_info->key_parts;
|
2005-06-29 16:13:50 +02:00
|
|
|
DBUG_ENTER("set_primary_key_from_record");
|
2004-05-17 09:51:02 +02:00
|
|
|
|
|
|
|
for (; key_part != end; key_part++)
|
|
|
|
{
|
|
|
|
Field* field= key_part->field;
|
|
|
|
if (set_ndb_key(op, field,
|
2005-07-06 11:23:36 +02:00
|
|
|
key_part->fieldnr-1, record+key_part->offset))
|
2004-04-15 09:14:14 +02:00
|
|
|
ERR_RETURN(op->getNdbError());
|
|
|
|
}
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
2006-03-24 10:42:55 +01:00
|
|
|
int ha_ndbcluster::set_index_key_from_record(NdbOperation *op,
|
|
|
|
const byte *record, uint keyno)
|
|
|
|
{
|
|
|
|
KEY* key_info= table->key_info + keyno;
|
|
|
|
KEY_PART_INFO* key_part= key_info->key_part;
|
|
|
|
KEY_PART_INFO* end= key_part+key_info->key_parts;
|
|
|
|
uint i;
|
|
|
|
DBUG_ENTER("set_index_key_from_record");
|
|
|
|
|
|
|
|
for (i= 0; key_part != end; key_part++, i++)
|
|
|
|
{
|
|
|
|
Field* field= key_part->field;
|
|
|
|
if (set_ndb_key(op, field, m_index[keyno].unique_index_attrid_map[i],
|
|
|
|
record+key_part->offset))
|
|
|
|
ERR_RETURN(m_active_trans->getNdbError());
|
|
|
|
}
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
2004-11-30 13:37:03 +01:00
|
|
|
int
|
|
|
|
ha_ndbcluster::set_index_key(NdbOperation *op,
|
2005-02-16 14:18:32 +01:00
|
|
|
const KEY *key_info,
|
|
|
|
const byte * key_ptr)
|
2004-11-30 13:37:03 +01:00
|
|
|
{
|
2004-12-20 15:12:42 +01:00
|
|
|
DBUG_ENTER("ha_ndbcluster::set_index_key");
|
2004-11-30 13:37:03 +01:00
|
|
|
uint i;
|
|
|
|
KEY_PART_INFO* key_part= key_info->key_part;
|
|
|
|
KEY_PART_INFO* end= key_part+key_info->key_parts;
|
|
|
|
|
|
|
|
for (i= 0; key_part != end; key_part++, i++)
|
|
|
|
{
|
2005-01-07 11:55:20 +01:00
|
|
|
Field* field= key_part->field;
|
|
|
|
const byte* ptr= key_part->null_bit ? key_ptr + 1 : key_ptr;
|
|
|
|
char buf[256];
|
|
|
|
shrink_varchar(field, ptr, buf);
|
2005-01-26 13:22:07 +01:00
|
|
|
if (set_ndb_key(op, field, m_index[active_index].unique_index_attrid_map[i], ptr))
|
2004-11-30 13:37:03 +01:00
|
|
|
ERR_RETURN(m_active_trans->getNdbError());
|
|
|
|
key_ptr+= key_part->store_length;
|
|
|
|
}
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
2004-04-15 09:14:14 +02:00
|
|
|
|
2005-01-18 16:31:05 +01:00
|
|
|
inline
|
|
|
|
int ha_ndbcluster::define_read_attrs(byte* buf, NdbOperation* op)
|
|
|
|
{
|
|
|
|
uint i;
|
|
|
|
DBUG_ENTER("define_read_attrs");
|
|
|
|
|
|
|
|
// Define attributes to read
|
2006-01-17 08:40:00 +01:00
|
|
|
for (i= 0; i < table_share->fields; i++)
|
2005-01-18 16:31:05 +01:00
|
|
|
{
|
|
|
|
Field *field= table->field[i];
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
if (bitmap_is_set(table->read_set, i) ||
|
2005-04-28 14:45:27 +02:00
|
|
|
((field->flags & PRI_KEY_FLAG)))
|
2005-01-18 16:31:05 +01:00
|
|
|
{
|
|
|
|
if (get_ndb_value(op, field, i, buf))
|
2005-02-16 14:18:32 +01:00
|
|
|
ERR_RETURN(op->getNdbError());
|
2005-01-18 16:31:05 +01:00
|
|
|
}
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
else
|
2005-01-18 16:31:05 +01:00
|
|
|
{
|
|
|
|
m_value[i].ptr= NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-17 08:40:00 +01:00
|
|
|
if (table_share->primary_key == MAX_KEY)
|
2005-01-18 16:31:05 +01:00
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("Getting hidden key"));
|
|
|
|
// Scanning table with no primary key
|
2006-01-17 08:40:00 +01:00
|
|
|
int hidden_no= table_share->fields;
|
2005-01-18 16:31:05 +01:00
|
|
|
#ifndef DBUG_OFF
|
|
|
|
const NDBTAB *tab= (const NDBTAB *) m_table;
|
|
|
|
if (!tab->getColumn(hidden_no))
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
#endif
|
|
|
|
if (get_ndb_value(op, NULL, hidden_no, NULL))
|
|
|
|
ERR_RETURN(op->getNdbError());
|
|
|
|
}
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
2005-07-12 20:01:22 +02:00
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
/*
|
|
|
|
Read one record from NDB using primary key
|
|
|
|
*/
|
|
|
|
|
2005-07-18 13:31:02 +02:00
|
|
|
int ha_ndbcluster::pk_read(const byte *key, uint key_len, byte *buf,
|
|
|
|
uint32 part_id)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
2006-01-17 08:40:00 +01:00
|
|
|
uint no_fields= table_share->fields;
|
2004-04-15 09:14:14 +02:00
|
|
|
NdbConnection *trans= m_active_trans;
|
|
|
|
NdbOperation *op;
|
2005-01-11 17:00:31 +01:00
|
|
|
|
2004-11-17 10:07:52 +01:00
|
|
|
int res;
|
|
|
|
DBUG_ENTER("pk_read");
|
|
|
|
DBUG_PRINT("enter", ("key_len: %u", key_len));
|
|
|
|
DBUG_DUMP("key", (char*)key, key_len);
|
2005-04-28 14:45:27 +02:00
|
|
|
m_write_op= FALSE;
|
2004-04-15 09:14:14 +02:00
|
|
|
|
2004-09-28 19:35:07 +02:00
|
|
|
NdbOperation::LockMode lm=
|
|
|
|
(NdbOperation::LockMode)get_ndb_lock_type(m_lock.type);
|
2004-09-07 21:53:59 +02:00
|
|
|
if (!(op= trans->getNdbOperation((const NDBTAB *) m_table)) ||
|
2004-09-28 19:35:07 +02:00
|
|
|
op->readTuple(lm) != 0)
|
2004-07-23 10:33:51 +02:00
|
|
|
ERR_RETURN(trans->getNdbError());
|
2004-11-17 10:07:52 +01:00
|
|
|
|
2006-01-17 08:40:00 +01:00
|
|
|
if (table_share->primary_key == MAX_KEY)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
|
|
|
// This table has no primary key, use "hidden" primary key
|
|
|
|
DBUG_PRINT("info", ("Using hidden key"));
|
|
|
|
DBUG_DUMP("key", (char*)key, 8);
|
|
|
|
if (set_hidden_key(op, no_fields, key))
|
2004-07-23 10:33:51 +02:00
|
|
|
ERR_RETURN(trans->getNdbError());
|
2004-11-17 10:07:52 +01:00
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
// Read key at the same time, for future reference
|
2004-09-20 12:40:53 +02:00
|
|
|
if (get_ndb_value(op, NULL, no_fields, NULL))
|
2004-07-23 10:33:51 +02:00
|
|
|
ERR_RETURN(trans->getNdbError());
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((res= set_primary_key(op, key)))
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2005-07-04 02:42:33 +02:00
|
|
|
if ((res= define_read_attrs(buf, op)))
|
2004-11-17 10:07:52 +01:00
|
|
|
DBUG_RETURN(res);
|
2006-03-14 15:27:38 +01:00
|
|
|
|
|
|
|
if (m_use_partition_function)
|
|
|
|
{
|
|
|
|
op->setPartitionId(part_id);
|
|
|
|
// If table has user defined partitioning
|
|
|
|
// and no indexes, we need to read the partition id
|
|
|
|
// to support ORDER BY queries
|
|
|
|
if (table_share->primary_key == MAX_KEY &&
|
|
|
|
get_ndb_partition_id(op))
|
|
|
|
ERR_RETURN(trans->getNdbError());
|
|
|
|
}
|
|
|
|
|
2006-08-07 14:48:54 +02:00
|
|
|
if (execute_no_commit_ie(this,trans,false) != 0)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
|
|
|
table->status= STATUS_NOT_FOUND;
|
|
|
|
DBUG_RETURN(ndb_err(trans));
|
|
|
|
}
|
|
|
|
|
|
|
|
// The value have now been fetched from NDB
|
|
|
|
unpack_record(buf);
|
|
|
|
table->status= 0;
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
2004-07-22 18:35:51 +02:00
|
|
|
/*
|
|
|
|
Read one complementing record from NDB using primary key from old_data
|
2006-03-01 15:24:46 +01:00
|
|
|
or hidden key
|
2004-07-22 18:35:51 +02:00
|
|
|
*/
|
|
|
|
|
2006-03-01 15:24:46 +01:00
|
|
|
int ha_ndbcluster::complemented_read(const byte *old_data, byte *new_data,
|
|
|
|
uint32 old_part_id)
|
2004-07-22 18:35:51 +02:00
|
|
|
{
|
2006-01-17 08:40:00 +01:00
|
|
|
uint no_fields= table_share->fields, i;
|
2005-01-04 13:47:16 +01:00
|
|
|
NdbTransaction *trans= m_active_trans;
|
2004-07-22 18:35:51 +02:00
|
|
|
NdbOperation *op;
|
2006-03-01 15:24:46 +01:00
|
|
|
DBUG_ENTER("complemented_read");
|
2005-04-28 14:45:27 +02:00
|
|
|
m_write_op= FALSE;
|
2004-07-22 18:35:51 +02:00
|
|
|
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
if (bitmap_is_set_all(table->read_set))
|
2005-04-28 14:45:27 +02:00
|
|
|
{
|
2004-07-22 18:35:51 +02:00
|
|
|
// We have allready retrieved all fields, nothing to complement
|
|
|
|
DBUG_RETURN(0);
|
2005-04-28 14:45:27 +02:00
|
|
|
}
|
2004-07-22 18:35:51 +02:00
|
|
|
|
2004-09-28 19:35:07 +02:00
|
|
|
NdbOperation::LockMode lm=
|
|
|
|
(NdbOperation::LockMode)get_ndb_lock_type(m_lock.type);
|
2004-09-07 21:53:59 +02:00
|
|
|
if (!(op= trans->getNdbOperation((const NDBTAB *) m_table)) ||
|
2004-09-28 19:35:07 +02:00
|
|
|
op->readTuple(lm) != 0)
|
2004-07-23 10:33:51 +02:00
|
|
|
ERR_RETURN(trans->getNdbError());
|
2006-03-01 15:24:46 +01:00
|
|
|
if (table_share->primary_key != MAX_KEY)
|
|
|
|
{
|
|
|
|
if (set_primary_key_from_record(op, old_data))
|
|
|
|
ERR_RETURN(trans->getNdbError());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// This table has no primary key, use "hidden" primary key
|
|
|
|
if (set_hidden_key(op, table->s->fields, m_ref))
|
|
|
|
ERR_RETURN(op->getNdbError());
|
|
|
|
}
|
2005-07-18 13:31:02 +02:00
|
|
|
|
|
|
|
if (m_use_partition_function)
|
|
|
|
op->setPartitionId(old_part_id);
|
|
|
|
|
2004-07-22 18:35:51 +02:00
|
|
|
// Read all unreferenced non-key field(s)
|
|
|
|
for (i= 0; i < no_fields; i++)
|
|
|
|
{
|
|
|
|
Field *field= table->field[i];
|
2004-12-01 12:43:30 +01:00
|
|
|
if (!((field->flags & PRI_KEY_FLAG) ||
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
bitmap_is_set(table->read_set, i)) &&
|
|
|
|
!bitmap_is_set(table->write_set, i))
|
2004-07-22 18:35:51 +02:00
|
|
|
{
|
2004-09-20 12:40:53 +02:00
|
|
|
if (get_ndb_value(op, field, i, new_data))
|
2005-02-16 14:18:32 +01:00
|
|
|
ERR_RETURN(trans->getNdbError());
|
2004-07-22 18:35:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-07 14:48:54 +02:00
|
|
|
if (execute_no_commit(this,trans,false) != 0)
|
2004-07-22 18:35:51 +02:00
|
|
|
{
|
|
|
|
table->status= STATUS_NOT_FOUND;
|
|
|
|
DBUG_RETURN(ndb_err(trans));
|
|
|
|
}
|
|
|
|
|
|
|
|
// The value have now been fetched from NDB
|
|
|
|
unpack_record(new_data);
|
|
|
|
table->status= 0;
|
2004-12-01 12:43:30 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* restore m_value
|
|
|
|
*/
|
|
|
|
for (i= 0; i < no_fields; i++)
|
|
|
|
{
|
|
|
|
Field *field= table->field[i];
|
|
|
|
if (!((field->flags & PRI_KEY_FLAG) ||
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
bitmap_is_set(table->read_set, i)))
|
2004-12-01 12:43:30 +01:00
|
|
|
{
|
|
|
|
m_value[i].ptr= NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-22 18:35:51 +02:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
2004-11-18 12:11:56 +01:00
|
|
|
/*
|
2006-03-24 10:42:55 +01:00
|
|
|
* Check that all operations between first and last all
|
|
|
|
* have gotten the errcode
|
|
|
|
* If checking for HA_ERR_KEY_NOT_FOUND then update m_dupkey
|
|
|
|
* for all succeeding operations
|
|
|
|
*/
|
|
|
|
bool ha_ndbcluster::check_all_operations_for_error(NdbTransaction *trans,
|
|
|
|
const NdbOperation *first,
|
|
|
|
const NdbOperation *last,
|
|
|
|
uint errcode)
|
|
|
|
{
|
|
|
|
const NdbOperation *op= first;
|
|
|
|
DBUG_ENTER("ha_ndbcluster::check_all_operations_for_error");
|
|
|
|
|
|
|
|
while(op)
|
|
|
|
{
|
|
|
|
NdbError err= op->getNdbError();
|
|
|
|
if (err.status != NdbError::Success)
|
|
|
|
{
|
|
|
|
if (ndb_to_mysql_error(&err) != (int) errcode)
|
|
|
|
DBUG_RETURN(false);
|
|
|
|
if (op == last) break;
|
|
|
|
op= trans->getNextCompletedOperation(op);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// We found a duplicate
|
|
|
|
if (op->getType() == NdbOperation::UniqueIndexAccess)
|
|
|
|
{
|
|
|
|
if (errcode == HA_ERR_KEY_NOT_FOUND)
|
|
|
|
{
|
|
|
|
NdbIndexOperation *iop= (NdbIndexOperation *) op;
|
|
|
|
const NDBINDEX *index= iop->getIndex();
|
|
|
|
// Find the key_no of the index
|
|
|
|
for(uint i= 0; i<table->s->keys; i++)
|
|
|
|
{
|
|
|
|
if (m_index[i].unique_index == index)
|
|
|
|
{
|
|
|
|
m_dupkey= i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Must have been primary key access
|
|
|
|
DBUG_ASSERT(op->getType() == NdbOperation::PrimaryKeyAccess);
|
|
|
|
if (errcode == HA_ERR_KEY_NOT_FOUND)
|
|
|
|
m_dupkey= table->s->primary_key;
|
|
|
|
}
|
|
|
|
DBUG_RETURN(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DBUG_RETURN(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Peek to check if any rows already exist with conflicting
|
|
|
|
* primary key or unique index values
|
2004-11-18 12:11:56 +01:00
|
|
|
*/
|
|
|
|
|
2006-03-24 10:42:55 +01:00
|
|
|
int ha_ndbcluster::peek_indexed_rows(const byte *record)
|
2004-11-18 12:11:56 +01:00
|
|
|
{
|
2005-01-04 13:47:16 +01:00
|
|
|
NdbTransaction *trans= m_active_trans;
|
2004-11-18 12:11:56 +01:00
|
|
|
NdbOperation *op;
|
2006-03-24 10:42:55 +01:00
|
|
|
const NdbOperation *first, *last;
|
|
|
|
uint i;
|
2004-11-18 12:11:56 +01:00
|
|
|
int res;
|
2006-03-24 10:42:55 +01:00
|
|
|
DBUG_ENTER("peek_indexed_rows");
|
2004-12-08 00:36:40 +01:00
|
|
|
|
2006-03-24 10:42:55 +01:00
|
|
|
NdbOperation::LockMode lm= NdbOperation::LM_Read;
|
|
|
|
first= NULL;
|
|
|
|
if (table->s->primary_key != MAX_KEY)
|
2005-07-18 13:31:02 +02:00
|
|
|
{
|
2006-03-24 10:42:55 +01:00
|
|
|
/*
|
|
|
|
* Fetch any row with colliding primary key
|
|
|
|
*/
|
|
|
|
if (!(op= trans->getNdbOperation((const NDBTAB *) m_table)) ||
|
|
|
|
op->readTuple(lm) != 0)
|
|
|
|
ERR_RETURN(trans->getNdbError());
|
|
|
|
|
|
|
|
first= op;
|
|
|
|
if ((res= set_primary_key_from_record(op, record)))
|
|
|
|
ERR_RETURN(trans->getNdbError());
|
|
|
|
|
|
|
|
if (m_use_partition_function)
|
2005-07-18 13:31:02 +02:00
|
|
|
{
|
2006-03-24 10:42:55 +01:00
|
|
|
uint32 part_id;
|
|
|
|
int error;
|
|
|
|
longlong func_value;
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
|
|
|
|
error= m_part_info->get_partition_id(m_part_info, &part_id, &func_value);
|
|
|
|
dbug_tmp_restore_column_map(table->read_set, old_map);
|
|
|
|
if (error)
|
2006-03-24 10:42:55 +01:00
|
|
|
DBUG_RETURN(error);
|
|
|
|
op->setPartitionId(part_id);
|
2005-07-18 13:31:02 +02:00
|
|
|
}
|
|
|
|
}
|
2006-03-24 10:42:55 +01:00
|
|
|
/*
|
|
|
|
* Fetch any rows with colliding unique indexes
|
|
|
|
*/
|
|
|
|
KEY* key_info;
|
|
|
|
KEY_PART_INFO *key_part, *end;
|
|
|
|
for (i= 0, key_info= table->key_info; i < table->s->keys; i++, key_info++)
|
|
|
|
{
|
|
|
|
if (i != table->s->primary_key &&
|
|
|
|
key_info->flags & HA_NOSAME)
|
|
|
|
{
|
|
|
|
// A unique index is defined on table
|
|
|
|
NdbIndexOperation *iop;
|
2006-05-04 13:58:17 +02:00
|
|
|
const NDBINDEX *unique_index = m_index[i].unique_index;
|
2006-03-24 10:42:55 +01:00
|
|
|
key_part= key_info->key_part;
|
|
|
|
end= key_part + key_info->key_parts;
|
2006-05-04 13:58:17 +02:00
|
|
|
if (!(iop= trans->getNdbIndexOperation(unique_index, m_table)) ||
|
2006-03-24 10:42:55 +01:00
|
|
|
iop->readTuple(lm) != 0)
|
|
|
|
ERR_RETURN(trans->getNdbError());
|
2005-07-18 13:31:02 +02:00
|
|
|
|
2006-03-24 10:42:55 +01:00
|
|
|
if (!first)
|
|
|
|
first= iop;
|
|
|
|
if ((res= set_index_key_from_record(iop, record, i)))
|
|
|
|
ERR_RETURN(trans->getNdbError());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
last= trans->getLastDefinedOperation();
|
|
|
|
if (first)
|
2006-08-07 14:48:54 +02:00
|
|
|
res= execute_no_commit_ie(this,trans,false);
|
2006-03-24 10:42:55 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// Table has no keys
|
|
|
|
table->status= STATUS_NOT_FOUND;
|
|
|
|
DBUG_RETURN(HA_ERR_KEY_NOT_FOUND);
|
|
|
|
}
|
|
|
|
if (check_all_operations_for_error(trans, first, last,
|
|
|
|
HA_ERR_KEY_NOT_FOUND))
|
2004-12-08 00:36:40 +01:00
|
|
|
{
|
|
|
|
table->status= STATUS_NOT_FOUND;
|
|
|
|
DBUG_RETURN(ndb_err(trans));
|
|
|
|
}
|
2006-03-24 10:42:55 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("m_dupkey %d", m_dupkey));
|
|
|
|
}
|
2004-11-18 12:11:56 +01:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
2004-07-22 18:35:51 +02:00
|
|
|
|
2006-03-24 10:42:55 +01:00
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
/*
|
|
|
|
Read one record from NDB using unique secondary index
|
|
|
|
*/
|
|
|
|
|
|
|
|
int ha_ndbcluster::unique_index_read(const byte *key,
|
2005-02-16 14:18:32 +01:00
|
|
|
uint key_len, byte *buf)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
2004-11-17 10:07:52 +01:00
|
|
|
int res;
|
2005-01-04 13:47:16 +01:00
|
|
|
NdbTransaction *trans= m_active_trans;
|
2004-04-15 09:14:14 +02:00
|
|
|
NdbIndexOperation *op;
|
2004-12-20 15:12:42 +01:00
|
|
|
DBUG_ENTER("ha_ndbcluster::unique_index_read");
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_PRINT("enter", ("key_len: %u, index: %u", key_len, active_index));
|
|
|
|
DBUG_DUMP("key", (char*)key, key_len);
|
|
|
|
|
2004-09-28 19:35:07 +02:00
|
|
|
NdbOperation::LockMode lm=
|
|
|
|
(NdbOperation::LockMode)get_ndb_lock_type(m_lock.type);
|
2006-05-04 13:58:17 +02:00
|
|
|
if (!(op= trans->getNdbIndexOperation(m_index[active_index].unique_index,
|
|
|
|
m_table)) ||
|
2004-09-28 19:35:07 +02:00
|
|
|
op->readTuple(lm) != 0)
|
2004-04-15 09:14:14 +02:00
|
|
|
ERR_RETURN(trans->getNdbError());
|
|
|
|
|
|
|
|
// Set secondary index key(s)
|
2005-07-04 02:42:33 +02:00
|
|
|
if ((res= set_index_key(op, table->key_info + active_index, key)))
|
2004-11-30 13:37:03 +01:00
|
|
|
DBUG_RETURN(res);
|
|
|
|
|
2005-07-04 02:42:33 +02:00
|
|
|
if ((res= define_read_attrs(buf, op)))
|
2004-11-17 10:07:52 +01:00
|
|
|
DBUG_RETURN(res);
|
2004-04-15 09:14:14 +02:00
|
|
|
|
2006-08-07 14:48:54 +02:00
|
|
|
if (execute_no_commit_ie(this,trans,false) != 0)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
|
|
|
table->status= STATUS_NOT_FOUND;
|
|
|
|
DBUG_RETURN(ndb_err(trans));
|
|
|
|
}
|
|
|
|
// The value have now been fetched from NDB
|
|
|
|
unpack_record(buf);
|
|
|
|
table->status= 0;
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
2004-12-08 00:36:40 +01:00
|
|
|
inline int ha_ndbcluster::fetch_next(NdbScanOperation* cursor)
|
2004-12-07 15:15:49 +01:00
|
|
|
{
|
|
|
|
DBUG_ENTER("fetch_next");
|
2004-05-10 14:12:28 +02:00
|
|
|
int check;
|
2005-01-04 13:47:16 +01:00
|
|
|
NdbTransaction *trans= m_active_trans;
|
2004-12-07 15:15:49 +01:00
|
|
|
|
2006-06-12 14:23:21 +02:00
|
|
|
if (m_lock_tuple)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Lock level m_lock.type either TL_WRITE_ALLOW_WRITE
|
|
|
|
(SELECT FOR UPDATE) or TL_READ_WITH_SHARED_LOCKS (SELECT
|
|
|
|
LOCK WITH SHARE MODE) and row was not explictly unlocked
|
|
|
|
with unlock_row() call
|
|
|
|
*/
|
|
|
|
NdbConnection *trans= m_active_trans;
|
|
|
|
NdbOperation *op;
|
|
|
|
// Lock row
|
|
|
|
DBUG_PRINT("info", ("Keeping lock on scanned row"));
|
|
|
|
|
|
|
|
if (!(op= m_active_cursor->lockCurrentTuple()))
|
|
|
|
{
|
|
|
|
m_lock_tuple= false;
|
|
|
|
ERR_RETURN(trans->getNdbError());
|
|
|
|
}
|
|
|
|
m_ops_pending++;
|
|
|
|
}
|
|
|
|
m_lock_tuple= false;
|
|
|
|
|
|
|
|
bool contact_ndb= m_lock.type < TL_WRITE_ALLOW_WRITE &&
|
|
|
|
m_lock.type != TL_READ_WITH_SHARED_LOCKS;;
|
2004-05-10 14:12:28 +02:00
|
|
|
do {
|
|
|
|
DBUG_PRINT("info", ("Call nextResult, contact_ndb: %d", contact_ndb));
|
2004-07-22 12:38:09 +02:00
|
|
|
/*
|
|
|
|
We can only handle one tuple with blobs at a time.
|
|
|
|
*/
|
2004-11-03 15:53:26 +01:00
|
|
|
if (m_ops_pending && m_blobs_pending)
|
2004-07-22 12:38:09 +02:00
|
|
|
{
|
2006-08-07 14:48:54 +02:00
|
|
|
if (execute_no_commit(this,trans,false) != 0)
|
2005-02-16 14:18:32 +01:00
|
|
|
DBUG_RETURN(ndb_err(trans));
|
2004-11-03 15:53:26 +01:00
|
|
|
m_ops_pending= 0;
|
|
|
|
m_blobs_pending= FALSE;
|
2004-07-22 12:38:09 +02:00
|
|
|
}
|
2004-12-07 15:15:49 +01:00
|
|
|
|
|
|
|
if ((check= cursor->nextResult(contact_ndb, m_force_send)) == 0)
|
2004-05-10 14:12:28 +02:00
|
|
|
{
|
2006-06-12 14:23:21 +02:00
|
|
|
/*
|
|
|
|
Explicitly lock tuple if "select for update" or
|
|
|
|
"select lock in share mode"
|
|
|
|
*/
|
|
|
|
m_lock_tuple= (m_lock.type == TL_WRITE_ALLOW_WRITE
|
|
|
|
||
|
|
|
|
m_lock.type == TL_READ_WITH_SHARED_LOCKS);
|
2004-05-10 14:12:28 +02:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
else if (check == 1 || check == 2)
|
|
|
|
{
|
|
|
|
// 1: No more records
|
|
|
|
// 2: No more cached records
|
2004-12-07 15:15:49 +01:00
|
|
|
|
2004-05-10 14:12:28 +02:00
|
|
|
/*
|
2005-02-16 14:18:32 +01:00
|
|
|
Before fetching more rows and releasing lock(s),
|
|
|
|
all pending update or delete operations should
|
|
|
|
be sent to NDB
|
2004-05-10 14:12:28 +02:00
|
|
|
*/
|
2004-11-03 15:53:26 +01:00
|
|
|
DBUG_PRINT("info", ("ops_pending: %d", m_ops_pending));
|
|
|
|
if (m_ops_pending)
|
2004-09-03 17:11:09 +02:00
|
|
|
{
|
2005-02-16 14:18:32 +01:00
|
|
|
if (m_transaction_on)
|
|
|
|
{
|
2006-08-07 14:48:54 +02:00
|
|
|
if (execute_no_commit(this,trans,false) != 0)
|
2005-02-16 14:18:32 +01:00
|
|
|
DBUG_RETURN(-1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (execute_commit(this,trans) != 0)
|
|
|
|
DBUG_RETURN(-1);
|
2005-07-04 02:42:33 +02:00
|
|
|
if (trans->restart() != 0)
|
2005-02-16 14:18:32 +01:00
|
|
|
{
|
|
|
|
DBUG_ASSERT(0);
|
|
|
|
DBUG_RETURN(-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_ops_pending= 0;
|
2004-09-03 17:11:09 +02:00
|
|
|
}
|
2004-05-10 14:12:28 +02:00
|
|
|
contact_ndb= (check == 2);
|
|
|
|
}
|
2004-12-08 00:36:40 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
DBUG_RETURN(-1);
|
|
|
|
}
|
2004-05-10 14:12:28 +02:00
|
|
|
} while (check == 2);
|
2004-12-08 00:36:40 +01:00
|
|
|
|
2004-12-07 15:15:49 +01:00
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Get the next record of a started scan. Try to fetch
|
|
|
|
it locally from NdbApi cached records if possible,
|
|
|
|
otherwise ask NDB for more.
|
|
|
|
|
|
|
|
NOTE
|
|
|
|
If this is a update/delete make sure to not contact
|
|
|
|
NDB before any pending ops have been sent to NDB.
|
2004-04-15 09:14:14 +02:00
|
|
|
|
2004-12-07 15:15:49 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
inline int ha_ndbcluster::next_result(byte *buf)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
DBUG_ENTER("next_result");
|
|
|
|
|
2004-12-15 15:13:11 +01:00
|
|
|
if (!m_active_cursor)
|
|
|
|
DBUG_RETURN(HA_ERR_END_OF_FILE);
|
|
|
|
|
2005-07-04 02:42:33 +02:00
|
|
|
if ((res= fetch_next(m_active_cursor)) == 0)
|
2004-12-07 15:15:49 +01:00
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("One more record found"));
|
|
|
|
|
|
|
|
unpack_record(buf);
|
|
|
|
table->status= 0;
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
2005-07-04 02:42:33 +02:00
|
|
|
else if (res == 1)
|
2004-12-07 15:15:49 +01:00
|
|
|
{
|
|
|
|
// No more records
|
|
|
|
table->status= STATUS_NOT_FOUND;
|
|
|
|
|
|
|
|
DBUG_PRINT("info", ("No more records"));
|
|
|
|
DBUG_RETURN(HA_ERR_END_OF_FILE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DBUG_RETURN(ndb_err(m_active_trans));
|
|
|
|
}
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
|
2004-04-30 13:38:41 +02:00
|
|
|
/*
|
2004-10-08 10:50:50 +02:00
|
|
|
Set bounds for ordered index scan.
|
2004-04-30 13:38:41 +02:00
|
|
|
*/
|
|
|
|
|
2004-06-11 13:49:22 +02:00
|
|
|
int ha_ndbcluster::set_bounds(NdbIndexScanOperation *op,
|
2005-09-15 02:33:28 +02:00
|
|
|
uint inx,
|
|
|
|
bool rir,
|
2005-02-16 14:18:32 +01:00
|
|
|
const key_range *keys[2],
|
|
|
|
uint range_no)
|
2004-04-30 13:38:41 +02:00
|
|
|
{
|
2005-09-15 02:33:28 +02:00
|
|
|
const KEY *const key_info= table->key_info + inx;
|
2004-10-08 10:50:50 +02:00
|
|
|
const uint key_parts= key_info->key_parts;
|
|
|
|
uint key_tot_len[2];
|
|
|
|
uint tot_len;
|
2004-10-25 22:35:46 +02:00
|
|
|
uint i, j;
|
2004-04-30 13:38:41 +02:00
|
|
|
|
|
|
|
DBUG_ENTER("set_bounds");
|
2004-10-08 10:50:50 +02:00
|
|
|
DBUG_PRINT("info", ("key_parts=%d", key_parts));
|
2004-04-30 13:38:41 +02:00
|
|
|
|
2004-10-08 10:50:50 +02:00
|
|
|
for (j= 0; j <= 1; j++)
|
2004-04-30 13:38:41 +02:00
|
|
|
{
|
2004-10-08 10:50:50 +02:00
|
|
|
const key_range *key= keys[j];
|
|
|
|
if (key != NULL)
|
|
|
|
{
|
|
|
|
// for key->flag see ha_rkey_function
|
|
|
|
DBUG_PRINT("info", ("key %d length=%d flag=%d",
|
|
|
|
j, key->length, key->flag));
|
|
|
|
key_tot_len[j]= key->length;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("key %d not present", j));
|
|
|
|
key_tot_len[j]= 0;
|
|
|
|
}
|
2004-04-30 13:38:41 +02:00
|
|
|
}
|
|
|
|
tot_len= 0;
|
2004-08-31 10:19:10 +02:00
|
|
|
|
2004-10-08 10:50:50 +02:00
|
|
|
for (i= 0; i < key_parts; i++)
|
|
|
|
{
|
|
|
|
KEY_PART_INFO *key_part= &key_info->key_part[i];
|
|
|
|
Field *field= key_part->field;
|
2005-01-11 17:00:31 +01:00
|
|
|
#ifndef DBUG_OFF
|
2004-10-08 10:50:50 +02:00
|
|
|
uint part_len= key_part->length;
|
2005-01-11 17:00:31 +01:00
|
|
|
#endif
|
2004-10-08 10:50:50 +02:00
|
|
|
uint part_store_len= key_part->store_length;
|
|
|
|
// Info about each key part
|
|
|
|
struct part_st {
|
|
|
|
bool part_last;
|
|
|
|
const key_range *key;
|
|
|
|
const byte *part_ptr;
|
|
|
|
bool part_null;
|
|
|
|
int bound_type;
|
|
|
|
const char* bound_ptr;
|
|
|
|
};
|
|
|
|
struct part_st part[2];
|
|
|
|
|
|
|
|
for (j= 0; j <= 1; j++)
|
|
|
|
{
|
2004-12-07 15:15:49 +01:00
|
|
|
struct part_st &p= part[j];
|
2004-10-08 10:50:50 +02:00
|
|
|
p.key= NULL;
|
|
|
|
p.bound_type= -1;
|
|
|
|
if (tot_len < key_tot_len[j])
|
|
|
|
{
|
|
|
|
p.part_last= (tot_len + part_store_len >= key_tot_len[j]);
|
|
|
|
p.key= keys[j];
|
|
|
|
p.part_ptr= &p.key->key[tot_len];
|
2004-11-08 11:11:49 +01:00
|
|
|
p.part_null= key_part->null_bit && *p.part_ptr;
|
2004-10-08 10:50:50 +02:00
|
|
|
p.bound_ptr= (const char *)
|
2004-11-08 11:11:49 +01:00
|
|
|
p.part_null ? 0 : key_part->null_bit ? p.part_ptr + 1 : p.part_ptr;
|
2004-10-08 10:50:50 +02:00
|
|
|
|
|
|
|
if (j == 0)
|
|
|
|
{
|
|
|
|
switch (p.key->flag)
|
|
|
|
{
|
|
|
|
case HA_READ_KEY_EXACT:
|
2005-09-15 02:33:28 +02:00
|
|
|
if (! rir)
|
|
|
|
p.bound_type= NdbIndexScanOperation::BoundEQ;
|
|
|
|
else // differs for records_in_range
|
|
|
|
p.bound_type= NdbIndexScanOperation::BoundLE;
|
2004-10-08 10:50:50 +02:00
|
|
|
break;
|
2004-12-20 15:12:42 +01:00
|
|
|
// ascending
|
2004-10-08 10:50:50 +02:00
|
|
|
case HA_READ_KEY_OR_NEXT:
|
|
|
|
p.bound_type= NdbIndexScanOperation::BoundLE;
|
|
|
|
break;
|
|
|
|
case HA_READ_AFTER_KEY:
|
|
|
|
if (! p.part_last)
|
|
|
|
p.bound_type= NdbIndexScanOperation::BoundLE;
|
|
|
|
else
|
|
|
|
p.bound_type= NdbIndexScanOperation::BoundLT;
|
|
|
|
break;
|
2004-12-20 15:12:42 +01:00
|
|
|
// descending
|
|
|
|
case HA_READ_PREFIX_LAST: // weird
|
|
|
|
p.bound_type= NdbIndexScanOperation::BoundEQ;
|
|
|
|
break;
|
|
|
|
case HA_READ_PREFIX_LAST_OR_PREV: // weird
|
|
|
|
p.bound_type= NdbIndexScanOperation::BoundGE;
|
|
|
|
break;
|
|
|
|
case HA_READ_BEFORE_KEY:
|
|
|
|
if (! p.part_last)
|
|
|
|
p.bound_type= NdbIndexScanOperation::BoundGE;
|
|
|
|
else
|
|
|
|
p.bound_type= NdbIndexScanOperation::BoundGT;
|
|
|
|
break;
|
2004-10-08 10:50:50 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (j == 1) {
|
|
|
|
switch (p.key->flag)
|
|
|
|
{
|
2004-12-20 15:12:42 +01:00
|
|
|
// ascending
|
2004-10-08 10:50:50 +02:00
|
|
|
case HA_READ_BEFORE_KEY:
|
|
|
|
if (! p.part_last)
|
|
|
|
p.bound_type= NdbIndexScanOperation::BoundGE;
|
|
|
|
else
|
|
|
|
p.bound_type= NdbIndexScanOperation::BoundGT;
|
|
|
|
break;
|
|
|
|
case HA_READ_AFTER_KEY: // weird
|
|
|
|
p.bound_type= NdbIndexScanOperation::BoundGE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2004-12-20 15:12:42 +01:00
|
|
|
// descending strangely sets no end key
|
2004-10-08 10:50:50 +02:00
|
|
|
}
|
|
|
|
}
|
2004-04-30 13:38:41 +02:00
|
|
|
|
2004-10-08 10:50:50 +02:00
|
|
|
if (p.bound_type == -1)
|
|
|
|
{
|
|
|
|
DBUG_PRINT("error", ("key %d unknown flag %d", j, p.key->flag));
|
2005-05-06 10:39:30 +02:00
|
|
|
DBUG_ASSERT(FALSE);
|
2004-10-08 10:50:50 +02:00
|
|
|
// Stop setting bounds but continue with what we have
|
2005-02-16 14:18:32 +01:00
|
|
|
op->end_of_bound(range_no);
|
2004-10-08 10:50:50 +02:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-04-30 13:38:41 +02:00
|
|
|
|
2004-10-08 10:50:50 +02:00
|
|
|
// Seen with e.g. b = 1 and c > 1
|
|
|
|
if (part[0].bound_type == NdbIndexScanOperation::BoundLE &&
|
|
|
|
part[1].bound_type == NdbIndexScanOperation::BoundGE &&
|
|
|
|
memcmp(part[0].part_ptr, part[1].part_ptr, part_store_len) == 0)
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("replace LE/GE pair by EQ"));
|
|
|
|
part[0].bound_type= NdbIndexScanOperation::BoundEQ;
|
|
|
|
part[1].bound_type= -1;
|
|
|
|
}
|
|
|
|
// Not seen but was in previous version
|
|
|
|
if (part[0].bound_type == NdbIndexScanOperation::BoundEQ &&
|
|
|
|
part[1].bound_type == NdbIndexScanOperation::BoundGE &&
|
|
|
|
memcmp(part[0].part_ptr, part[1].part_ptr, part_store_len) == 0)
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("remove GE from EQ/GE pair"));
|
|
|
|
part[1].bound_type= -1;
|
|
|
|
}
|
2004-09-06 10:33:12 +02:00
|
|
|
|
2004-10-08 10:50:50 +02:00
|
|
|
for (j= 0; j <= 1; j++)
|
|
|
|
{
|
2004-12-07 15:15:49 +01:00
|
|
|
struct part_st &p= part[j];
|
2004-10-08 10:50:50 +02:00
|
|
|
// Set bound if not done with this key
|
|
|
|
if (p.key != NULL)
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("key %d:%d offset=%d length=%d last=%d bound=%d",
|
|
|
|
j, i, tot_len, part_len, p.part_last, p.bound_type));
|
|
|
|
DBUG_DUMP("info", (const char*)p.part_ptr, part_store_len);
|
|
|
|
|
|
|
|
// Set bound if not cancelled via type -1
|
|
|
|
if (p.bound_type != -1)
|
2005-02-16 14:18:32 +01:00
|
|
|
{
|
2005-01-07 11:55:20 +01:00
|
|
|
const char* ptr= p.bound_ptr;
|
|
|
|
char buf[256];
|
|
|
|
shrink_varchar(field, ptr, buf);
|
2005-01-26 13:22:07 +01:00
|
|
|
if (op->setBound(i, p.bound_type, ptr))
|
2004-10-08 10:50:50 +02:00
|
|
|
ERR_RETURN(op->getNdbError());
|
2005-02-16 14:18:32 +01:00
|
|
|
}
|
2004-10-08 10:50:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tot_len+= part_store_len;
|
2004-09-06 10:33:12 +02:00
|
|
|
}
|
2004-12-06 09:05:30 +01:00
|
|
|
op->end_of_bound(range_no);
|
2004-04-30 13:38:41 +02:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
/*
|
2004-05-10 14:12:28 +02:00
|
|
|
Start ordered index scan in NDB
|
2004-04-15 09:14:14 +02:00
|
|
|
*/
|
|
|
|
|
2004-04-30 13:38:41 +02:00
|
|
|
int ha_ndbcluster::ordered_index_scan(const key_range *start_key,
|
2005-02-16 14:18:32 +01:00
|
|
|
const key_range *end_key,
|
2005-07-18 13:31:02 +02:00
|
|
|
bool sorted, bool descending,
|
|
|
|
byte* buf, part_id_range *part_spec)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
2004-11-17 10:07:52 +01:00
|
|
|
int res;
|
2004-10-05 12:17:42 +02:00
|
|
|
bool restart;
|
2005-01-04 13:47:16 +01:00
|
|
|
NdbTransaction *trans= m_active_trans;
|
2004-06-11 13:49:22 +02:00
|
|
|
NdbIndexScanOperation *op;
|
2004-05-10 14:12:28 +02:00
|
|
|
|
2004-12-20 15:12:42 +01:00
|
|
|
DBUG_ENTER("ha_ndbcluster::ordered_index_scan");
|
|
|
|
DBUG_PRINT("enter", ("index: %u, sorted: %d, descending: %d",
|
|
|
|
active_index, sorted, descending));
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_PRINT("enter", ("Starting new ordered scan on %s", m_tabname));
|
2005-04-28 14:45:27 +02:00
|
|
|
m_write_op= FALSE;
|
2004-07-22 12:38:09 +02:00
|
|
|
|
2004-10-07 11:57:48 +02:00
|
|
|
// Check that sorted seems to be initialised
|
|
|
|
DBUG_ASSERT(sorted == 0 || sorted == 1);
|
2004-04-15 09:14:14 +02:00
|
|
|
|
2004-10-08 10:50:50 +02:00
|
|
|
if (m_active_cursor == 0)
|
2004-10-05 12:17:42 +02:00
|
|
|
{
|
2005-05-06 10:39:30 +02:00
|
|
|
restart= FALSE;
|
2004-10-05 12:17:42 +02:00
|
|
|
NdbOperation::LockMode lm=
|
|
|
|
(NdbOperation::LockMode)get_ndb_lock_type(m_lock.type);
|
2006-06-12 14:23:21 +02:00
|
|
|
bool need_pk = (lm == NdbOperation::LM_Read);
|
2006-05-04 13:58:17 +02:00
|
|
|
if (!(op= trans->getNdbIndexScanOperation(m_index[active_index].index,
|
|
|
|
m_table)) ||
|
2006-06-12 14:23:21 +02:00
|
|
|
op->readTuples(lm, 0, parallelism, sorted, descending, false, need_pk))
|
2004-10-05 12:17:42 +02:00
|
|
|
ERR_RETURN(trans->getNdbError());
|
2005-07-18 13:31:02 +02:00
|
|
|
if (m_use_partition_function && part_spec != NULL &&
|
|
|
|
part_spec->start_part == part_spec->end_part)
|
|
|
|
op->setPartitionId(part_spec->start_part);
|
2004-12-07 15:15:49 +01:00
|
|
|
m_active_cursor= op;
|
2004-10-05 12:17:42 +02:00
|
|
|
} else {
|
2005-05-06 10:39:30 +02:00
|
|
|
restart= TRUE;
|
2004-12-07 15:15:49 +01:00
|
|
|
op= (NdbIndexScanOperation*)m_active_cursor;
|
2004-10-05 12:17:42 +02:00
|
|
|
|
2005-07-18 13:31:02 +02:00
|
|
|
if (m_use_partition_function && part_spec != NULL &&
|
|
|
|
part_spec->start_part == part_spec->end_part)
|
|
|
|
op->setPartitionId(part_spec->start_part);
|
2004-10-05 12:17:42 +02:00
|
|
|
DBUG_ASSERT(op->getSorted() == sorted);
|
|
|
|
DBUG_ASSERT(op->getLockMode() ==
|
2005-02-16 14:18:32 +01:00
|
|
|
(NdbOperation::LockMode)get_ndb_lock_type(m_lock.type));
|
2005-07-04 02:42:33 +02:00
|
|
|
if (op->reset_bounds(m_force_send))
|
2004-10-05 12:17:42 +02:00
|
|
|
DBUG_RETURN(ndb_err(m_active_trans));
|
|
|
|
}
|
2004-12-07 15:15:49 +01:00
|
|
|
|
2004-05-10 14:46:06 +02:00
|
|
|
{
|
2004-10-08 10:50:50 +02:00
|
|
|
const key_range *keys[2]= { start_key, end_key };
|
2005-09-15 02:33:28 +02:00
|
|
|
res= set_bounds(op, active_index, false, keys);
|
2004-11-17 10:07:52 +01:00
|
|
|
if (res)
|
|
|
|
DBUG_RETURN(res);
|
2004-05-10 14:46:06 +02:00
|
|
|
}
|
2005-01-07 15:33:24 +01:00
|
|
|
|
2006-03-14 15:27:38 +01:00
|
|
|
if (!restart)
|
2004-05-10 14:46:06 +02:00
|
|
|
{
|
2006-03-14 15:27:38 +01:00
|
|
|
if (generate_scan_filter(m_cond_stack, op))
|
|
|
|
DBUG_RETURN(ndb_err(trans));
|
|
|
|
|
2006-03-27 19:41:37 +02:00
|
|
|
if ((res= define_read_attrs(buf, op)))
|
2006-03-14 15:27:38 +01:00
|
|
|
{
|
|
|
|
DBUG_RETURN(res);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If table has user defined partitioning
|
|
|
|
// and no primary key, we need to read the partition id
|
|
|
|
// to support ORDER BY queries
|
|
|
|
if (m_use_partition_function &&
|
|
|
|
(table_share->primary_key == MAX_KEY) &&
|
|
|
|
(get_ndb_partition_id(op)))
|
|
|
|
ERR_RETURN(trans->getNdbError());
|
2004-10-05 12:17:42 +02:00
|
|
|
}
|
2004-11-17 10:07:52 +01:00
|
|
|
|
2006-08-07 14:48:54 +02:00
|
|
|
if (execute_no_commit(this,trans,false) != 0)
|
2004-11-17 10:07:52 +01:00
|
|
|
DBUG_RETURN(ndb_err(trans));
|
|
|
|
|
|
|
|
DBUG_RETURN(next_result(buf));
|
|
|
|
}
|
2004-04-15 09:14:14 +02:00
|
|
|
|
2006-10-05 14:25:18 +02:00
|
|
|
static
|
|
|
|
int
|
|
|
|
guess_scan_flags(NdbOperation::LockMode lm,
|
|
|
|
const NDBTAB* tab, const MY_BITMAP* readset)
|
|
|
|
{
|
|
|
|
int flags= 0;
|
|
|
|
flags|= (lm == NdbOperation::LM_Read) ? NdbScanOperation::SF_KeyInfo : 0;
|
|
|
|
if (tab->checkColumns(0, 0) & 2)
|
|
|
|
{
|
|
|
|
int ret = tab->checkColumns(readset->bitmap, no_bytes_in_map(readset));
|
|
|
|
|
|
|
|
if (ret & 2)
|
|
|
|
{ // If disk columns...use disk scan
|
|
|
|
flags |= NdbScanOperation::SF_DiskScan;
|
|
|
|
}
|
|
|
|
else if ((ret & 4) == 0 && (lm == NdbOperation::LM_Exclusive))
|
|
|
|
{
|
|
|
|
// If no mem column is set and exclusive...guess disk scan
|
|
|
|
flags |= NdbScanOperation::SF_DiskScan;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
/*
|
2004-05-10 14:12:28 +02:00
|
|
|
Start full table scan in NDB
|
2004-04-15 09:14:14 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
int ha_ndbcluster::full_table_scan(byte *buf)
|
|
|
|
{
|
2004-11-17 10:07:52 +01:00
|
|
|
int res;
|
2004-04-15 09:14:14 +02:00
|
|
|
NdbScanOperation *op;
|
2005-01-04 13:47:16 +01:00
|
|
|
NdbTransaction *trans= m_active_trans;
|
2006-02-10 17:06:24 +01:00
|
|
|
part_id_range part_spec;
|
2004-04-15 09:14:14 +02:00
|
|
|
|
|
|
|
DBUG_ENTER("full_table_scan");
|
|
|
|
DBUG_PRINT("enter", ("Starting new scan on %s", m_tabname));
|
2005-04-28 14:45:27 +02:00
|
|
|
m_write_op= FALSE;
|
2004-04-15 09:14:14 +02:00
|
|
|
|
2004-09-28 19:35:07 +02:00
|
|
|
NdbOperation::LockMode lm=
|
|
|
|
(NdbOperation::LockMode)get_ndb_lock_type(m_lock.type);
|
2006-10-05 14:25:18 +02:00
|
|
|
int flags= guess_scan_flags(lm, m_table, table->read_set);
|
2006-05-04 13:58:17 +02:00
|
|
|
if (!(op=trans->getNdbScanOperation(m_table)) ||
|
2006-10-05 14:25:18 +02:00
|
|
|
op->readTuples(lm, flags, parallelism))
|
2004-04-15 09:14:14 +02:00
|
|
|
ERR_RETURN(trans->getNdbError());
|
2004-12-07 15:15:49 +01:00
|
|
|
m_active_cursor= op;
|
2006-02-10 17:06:24 +01:00
|
|
|
|
|
|
|
if (m_use_partition_function)
|
|
|
|
{
|
|
|
|
part_spec.start_part= 0;
|
2006-02-16 22:02:44 +01:00
|
|
|
part_spec.end_part= m_part_info->get_tot_partitions() - 1;
|
2006-02-10 17:06:24 +01:00
|
|
|
prune_partition_set(table, &part_spec);
|
|
|
|
DBUG_PRINT("info", ("part_spec.start_part = %u, part_spec.end_part = %u",
|
|
|
|
part_spec.start_part, part_spec.end_part));
|
|
|
|
/*
|
|
|
|
If partition pruning has found no partition in set
|
|
|
|
we can return HA_ERR_END_OF_FILE
|
|
|
|
If partition pruning has found exactly one partition in set
|
|
|
|
we can optimize scan to run towards that partition only.
|
|
|
|
*/
|
|
|
|
if (part_spec.start_part > part_spec.end_part)
|
|
|
|
{
|
|
|
|
DBUG_RETURN(HA_ERR_END_OF_FILE);
|
|
|
|
}
|
|
|
|
else if (part_spec.start_part == part_spec.end_part)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Only one partition is required to scan, if sorted is required we
|
|
|
|
don't need it any more since output from one ordered partitioned
|
|
|
|
index is always sorted.
|
|
|
|
*/
|
|
|
|
m_active_cursor->setPartitionId(part_spec.start_part);
|
|
|
|
}
|
2006-03-14 15:27:38 +01:00
|
|
|
// If table has user defined partitioning
|
|
|
|
// and no primary key, we need to read the partition id
|
|
|
|
// to support ORDER BY queries
|
|
|
|
if ((table_share->primary_key == MAX_KEY) &&
|
|
|
|
(get_ndb_partition_id(op)))
|
|
|
|
ERR_RETURN(trans->getNdbError());
|
2006-02-10 17:06:24 +01:00
|
|
|
}
|
|
|
|
|
2005-01-07 15:33:24 +01:00
|
|
|
if (generate_scan_filter(m_cond_stack, op))
|
|
|
|
DBUG_RETURN(ndb_err(trans));
|
2005-07-04 02:42:33 +02:00
|
|
|
if ((res= define_read_attrs(buf, op)))
|
2004-11-17 10:07:52 +01:00
|
|
|
DBUG_RETURN(res);
|
|
|
|
|
2006-08-07 14:48:54 +02:00
|
|
|
if (execute_no_commit(this,trans,false) != 0)
|
2004-11-17 10:07:52 +01:00
|
|
|
DBUG_RETURN(ndb_err(trans));
|
|
|
|
DBUG_PRINT("exit", ("Scan started successfully"));
|
|
|
|
DBUG_RETURN(next_result(buf));
|
2004-05-10 14:12:28 +02:00
|
|
|
}
|
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
/*
|
|
|
|
Insert one record into NDB
|
|
|
|
*/
|
|
|
|
int ha_ndbcluster::write_row(byte *record)
|
|
|
|
{
|
2004-08-11 15:06:17 +02:00
|
|
|
bool has_auto_increment;
|
2004-04-15 09:14:14 +02:00
|
|
|
uint i;
|
2005-01-04 13:47:16 +01:00
|
|
|
NdbTransaction *trans= m_active_trans;
|
2004-04-15 09:14:14 +02:00
|
|
|
NdbOperation *op;
|
|
|
|
int res;
|
2004-09-14 21:02:23 +02:00
|
|
|
THD *thd= current_thd;
|
2006-01-17 09:25:12 +01:00
|
|
|
longlong func_value= 0;
|
|
|
|
DBUG_ENTER("ha_ndbcluster::write_row");
|
2004-09-15 14:44:21 +02:00
|
|
|
|
2006-01-17 09:25:12 +01:00
|
|
|
m_write_op= TRUE;
|
2006-03-24 10:42:55 +01:00
|
|
|
has_auto_increment= (table->next_number_field && record == table->record[0]);
|
|
|
|
if (table_share->primary_key != MAX_KEY)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Increase any auto_incremented primary key
|
|
|
|
*/
|
|
|
|
if (has_auto_increment)
|
|
|
|
{
|
|
|
|
THD *thd= table->in_use;
|
2006-08-30 22:20:39 +02:00
|
|
|
int error;
|
2006-03-24 10:42:55 +01:00
|
|
|
|
|
|
|
m_skip_auto_increment= FALSE;
|
2006-08-30 22:20:39 +02:00
|
|
|
if ((error= update_auto_increment()))
|
|
|
|
DBUG_RETURN(error);
|
WL#3146 "less locking in auto_increment":
this is a cleanup patch for our current auto_increment handling:
new names for auto_increment variables in THD, new methods to manipulate them
(see sql_class.h), some move into handler::, causing less backup/restore
work when executing substatements.
This makes the logic hopefully clearer, less work is is needed in
mysql_insert().
By cleaning up, using different variables for different purposes (instead
of one for 3 things...), we fix those bugs, which someone may want to fix
in 5.0 too:
BUG#20339 "stored procedure using LAST_INSERT_ID() does not replicate
statement-based"
BUG#20341 "stored function inserting into one auto_increment puts bad
data in slave"
BUG#19243 "wrong LAST_INSERT_ID() after ON DUPLICATE KEY UPDATE"
(now if a row is updated, LAST_INSERT_ID() will return its id)
and re-fixes:
BUG#6880 "LAST_INSERT_ID() value changes during multi-row INSERT"
(already fixed differently by Ramil in 4.1)
Test of documented behaviour of mysql_insert_id() (there was no test).
The behaviour changes introduced are:
- LAST_INSERT_ID() now returns "the first autogenerated auto_increment value
successfully inserted", instead of "the first autogenerated auto_increment
value if any row was successfully inserted", see auto_increment.test.
Same for mysql_insert_id(), see mysql_client_test.c.
- LAST_INSERT_ID() returns the id of the updated row if ON DUPLICATE KEY
UPDATE, see auto_increment.test. Same for mysql_insert_id(), see
mysql_client_test.c.
- LAST_INSERT_ID() does not change if no autogenerated value was successfully
inserted (it used to then be 0), see auto_increment.test.
- if in INSERT SELECT no autogenerated value was successfully inserted,
mysql_insert_id() now returns the id of the last inserted row (it already
did this for INSERT VALUES), see mysql_client_test.c.
- if INSERT SELECT uses LAST_INSERT_ID(X), mysql_insert_id() now returns X
(it already did this for INSERT VALUES), see mysql_client_test.c.
- NDB now behaves like other engines wrt SET INSERT_ID: with INSERT IGNORE,
the id passed in SET INSERT_ID is re-used until a row succeeds; SET INSERT_ID
influences not only the first row now.
Additionally, when unlocking a table we check that the thread is not keeping
a next_insert_id (as the table is unlocked that id is potentially out-of-date);
forgetting about this next_insert_id is done in a new
handler::ha_release_auto_increment().
Finally we prepare for engines capable of reserving finite-length intervals
of auto_increment values: we store such intervals in THD. The next step
(to be done by the replication team in 5.1) is to read those intervals from
THD and actually store them in the statement-based binary log. NDB
will be a good engine to test that.
2006-07-09 17:52:19 +02:00
|
|
|
m_skip_auto_increment= (insert_id_for_cur_row == 0);
|
2006-03-24 10:42:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If IGNORE the ignore constraint violations on primary and unique keys
|
|
|
|
*/
|
|
|
|
if (!m_use_write && m_ignore_dup_key)
|
2004-09-15 14:44:21 +02:00
|
|
|
{
|
2006-06-14 20:16:32 +02:00
|
|
|
/*
|
|
|
|
compare if expression with that in start_bulk_insert()
|
|
|
|
start_bulk_insert will set parameters to ensure that each
|
|
|
|
write_row is committed individually
|
|
|
|
*/
|
2006-03-24 10:42:55 +01:00
|
|
|
int peek_res= peek_indexed_rows(record);
|
2004-11-18 12:11:56 +01:00
|
|
|
|
|
|
|
if (!peek_res)
|
|
|
|
{
|
|
|
|
DBUG_RETURN(HA_ERR_FOUND_DUPP_KEY);
|
|
|
|
}
|
|
|
|
if (peek_res != HA_ERR_KEY_NOT_FOUND)
|
|
|
|
DBUG_RETURN(peek_res);
|
2004-09-15 14:44:21 +02:00
|
|
|
}
|
2005-03-15 15:03:25 +01:00
|
|
|
|
2004-09-14 21:02:23 +02:00
|
|
|
statistic_increment(thd->status_var.ha_write_count, &LOCK_status);
|
2004-10-04 00:27:04 +02:00
|
|
|
if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_INSERT)
|
|
|
|
table->timestamp_field->set_time();
|
2004-04-15 09:14:14 +02:00
|
|
|
|
2006-05-04 13:58:17 +02:00
|
|
|
if (!(op= trans->getNdbOperation(m_table)))
|
2004-04-15 09:14:14 +02:00
|
|
|
ERR_RETURN(trans->getNdbError());
|
|
|
|
|
|
|
|
res= (m_use_write) ? op->writeTuple() :op->insertTuple();
|
|
|
|
if (res != 0)
|
|
|
|
ERR_RETURN(trans->getNdbError());
|
|
|
|
|
2005-07-18 13:31:02 +02:00
|
|
|
if (m_use_partition_function)
|
|
|
|
{
|
|
|
|
uint32 part_id;
|
|
|
|
int error;
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
|
|
|
|
error= m_part_info->get_partition_id(m_part_info, &part_id, &func_value);
|
|
|
|
dbug_tmp_restore_column_map(table->read_set, old_map);
|
|
|
|
if (error)
|
2005-07-18 13:31:02 +02:00
|
|
|
DBUG_RETURN(error);
|
|
|
|
op->setPartitionId(part_id);
|
|
|
|
}
|
|
|
|
|
2006-01-17 08:40:00 +01:00
|
|
|
if (table_share->primary_key == MAX_KEY)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
|
|
|
// Table has hidden primary key
|
2004-12-30 19:56:09 +01:00
|
|
|
Ndb *ndb= get_ndb();
|
2006-05-17 12:40:10 +02:00
|
|
|
int ret;
|
|
|
|
Uint64 auto_value;
|
2005-04-15 16:14:08 +02:00
|
|
|
uint retries= NDB_AUTO_INCREMENT_RETRIES;
|
|
|
|
do {
|
2006-05-25 12:13:47 +02:00
|
|
|
Ndb_tuple_id_range_guard g(m_share);
|
|
|
|
ret= ndb->getAutoIncrementValue(m_table, g.range, auto_value, 1);
|
2006-05-17 12:40:10 +02:00
|
|
|
} while (ret == -1 &&
|
2005-04-15 16:14:08 +02:00
|
|
|
--retries &&
|
|
|
|
ndb->getNdbError().status == NdbError::TemporaryError);
|
2006-05-17 12:40:10 +02:00
|
|
|
if (ret == -1)
|
2005-04-15 15:52:07 +02:00
|
|
|
ERR_RETURN(ndb->getNdbError());
|
2006-01-17 08:40:00 +01:00
|
|
|
if (set_hidden_key(op, table_share->fields, (const byte*)&auto_value))
|
2004-04-15 09:14:14 +02:00
|
|
|
ERR_RETURN(op->getNdbError());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
int error;
|
|
|
|
if ((error= set_primary_key_from_record(op, record)))
|
|
|
|
DBUG_RETURN(error);
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set non-key attribute(s)
|
2004-10-14 17:03:46 +02:00
|
|
|
bool set_blob_value= FALSE;
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
|
2006-01-17 08:40:00 +01:00
|
|
|
for (i= 0; i < table_share->fields; i++)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
|
|
|
Field *field= table->field[i];
|
|
|
|
if (!(field->flags & PRI_KEY_FLAG) &&
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
(bitmap_is_set(table->write_set, i) || !m_use_write) &&
|
2005-11-06 00:20:37 +01:00
|
|
|
set_ndb_value(op, field, i, record-table->record[0], &set_blob_value))
|
2004-08-13 13:51:18 +02:00
|
|
|
{
|
2004-11-03 15:53:26 +01:00
|
|
|
m_skip_auto_increment= TRUE;
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
dbug_tmp_restore_column_map(table->read_set, old_map);
|
2004-04-15 09:14:14 +02:00
|
|
|
ERR_RETURN(op->getNdbError());
|
2004-08-13 13:51:18 +02:00
|
|
|
}
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
dbug_tmp_restore_column_map(table->read_set, old_map);
|
2004-04-15 09:14:14 +02:00
|
|
|
|
2006-01-17 09:25:12 +01:00
|
|
|
if (m_use_partition_function)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
We need to set the value of the partition function value in
|
|
|
|
NDB since the NDB kernel doesn't have easy access to the function
|
|
|
|
to calculate the value.
|
|
|
|
*/
|
|
|
|
if (func_value >= INT_MAX32)
|
|
|
|
func_value= INT_MAX32;
|
|
|
|
uint32 part_func_value= (uint32)func_value;
|
|
|
|
uint no_fields= table_share->fields;
|
|
|
|
if (table_share->primary_key == MAX_KEY)
|
|
|
|
no_fields++;
|
|
|
|
op->setValue(no_fields, part_func_value);
|
|
|
|
}
|
|
|
|
|
2005-03-15 15:03:25 +01:00
|
|
|
m_rows_changed++;
|
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
/*
|
|
|
|
Execute write operation
|
|
|
|
NOTE When doing inserts with many values in
|
|
|
|
each INSERT statement it should not be necessary
|
|
|
|
to NoCommit the transaction between each row.
|
|
|
|
Find out how this is detected!
|
|
|
|
*/
|
2004-11-03 15:53:26 +01:00
|
|
|
m_rows_inserted++;
|
2004-09-14 10:52:21 +02:00
|
|
|
no_uncommitted_rows_update(1);
|
2004-11-03 15:53:26 +01:00
|
|
|
m_bulk_insert_not_flushed= TRUE;
|
2005-04-13 12:42:23 +02:00
|
|
|
if ((m_rows_to_insert == (ha_rows) 1) ||
|
2004-11-03 15:53:26 +01:00
|
|
|
((m_rows_inserted % m_bulk_insert_rows) == 0) ||
|
2005-04-21 13:09:19 +02:00
|
|
|
m_primary_key_update ||
|
2004-10-01 13:16:49 +02:00
|
|
|
set_blob_value)
|
2004-04-29 14:38:35 +02:00
|
|
|
{
|
|
|
|
// Send rows to NDB
|
|
|
|
DBUG_PRINT("info", ("Sending inserts to NDB, "\
|
2005-02-16 14:18:32 +01:00
|
|
|
"rows_inserted:%d, bulk_insert_rows: %d",
|
|
|
|
(int)m_rows_inserted, (int)m_bulk_insert_rows));
|
2004-09-03 17:11:09 +02:00
|
|
|
|
2004-11-03 15:53:26 +01:00
|
|
|
m_bulk_insert_not_flushed= FALSE;
|
2004-11-17 09:15:53 +01:00
|
|
|
if (m_transaction_on)
|
2004-08-13 13:51:18 +02:00
|
|
|
{
|
2006-08-07 14:48:54 +02:00
|
|
|
if (execute_no_commit(this,trans,false) != 0)
|
2004-09-07 14:30:11 +02:00
|
|
|
{
|
2005-02-16 14:18:32 +01:00
|
|
|
m_skip_auto_increment= TRUE;
|
|
|
|
no_uncommitted_rows_execute_failure();
|
|
|
|
DBUG_RETURN(ndb_err(trans));
|
2004-09-07 14:30:11 +02:00
|
|
|
}
|
2004-09-03 17:11:09 +02:00
|
|
|
}
|
|
|
|
else
|
2004-08-13 13:51:18 +02:00
|
|
|
{
|
2004-09-28 21:11:50 +02:00
|
|
|
if (execute_commit(this,trans) != 0)
|
2004-09-03 17:11:09 +02:00
|
|
|
{
|
2005-02-16 14:18:32 +01:00
|
|
|
m_skip_auto_increment= TRUE;
|
|
|
|
no_uncommitted_rows_execute_failure();
|
|
|
|
DBUG_RETURN(ndb_err(trans));
|
2004-09-03 17:11:09 +02:00
|
|
|
}
|
2005-07-04 02:42:33 +02:00
|
|
|
if (trans->restart() != 0)
|
2005-01-11 17:00:31 +01:00
|
|
|
{
|
2005-02-16 14:18:32 +01:00
|
|
|
DBUG_ASSERT(0);
|
|
|
|
DBUG_RETURN(-1);
|
2005-01-11 17:00:31 +01:00
|
|
|
}
|
2004-08-13 13:51:18 +02:00
|
|
|
}
|
2004-04-29 14:38:35 +02:00
|
|
|
}
|
2004-11-03 15:53:26 +01:00
|
|
|
if ((has_auto_increment) && (m_skip_auto_increment))
|
2004-08-10 14:38:24 +02:00
|
|
|
{
|
2004-12-30 19:56:09 +01:00
|
|
|
Ndb *ndb= get_ndb();
|
2004-07-29 11:35:38 +02:00
|
|
|
Uint64 next_val= (Uint64) table->next_number_field->val_int() + 1;
|
2006-06-30 18:15:18 +02:00
|
|
|
char buff[22];
|
2004-08-10 14:38:24 +02:00
|
|
|
DBUG_PRINT("info",
|
2006-06-30 18:15:18 +02:00
|
|
|
("Trying to set next auto increment value to %s",
|
|
|
|
llstr(next_val, buff)));
|
2006-05-25 12:13:47 +02:00
|
|
|
Ndb_tuple_id_range_guard g(m_share);
|
|
|
|
if (ndb->setAutoIncrementValue(m_table, g.range, next_val, TRUE)
|
2006-05-17 12:40:10 +02:00
|
|
|
== -1)
|
2006-05-16 12:58:41 +02:00
|
|
|
ERR_RETURN(ndb->getNdbError());
|
2004-07-29 11:35:38 +02:00
|
|
|
}
|
2004-11-03 15:53:26 +01:00
|
|
|
m_skip_auto_increment= TRUE;
|
2004-07-29 11:35:38 +02:00
|
|
|
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
DBUG_PRINT("exit",("ok"));
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Compare if a key in a row has changed */
|
|
|
|
|
|
|
|
int ha_ndbcluster::key_cmp(uint keynr, const byte * old_row,
|
2005-02-16 14:18:32 +01:00
|
|
|
const byte * new_row)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
|
|
|
KEY_PART_INFO *key_part=table->key_info[keynr].key_part;
|
|
|
|
KEY_PART_INFO *end=key_part+table->key_info[keynr].key_parts;
|
|
|
|
|
|
|
|
for (; key_part != end ; key_part++)
|
|
|
|
{
|
|
|
|
if (key_part->null_bit)
|
|
|
|
{
|
|
|
|
if ((old_row[key_part->null_offset] & key_part->null_bit) !=
|
2005-02-16 14:18:32 +01:00
|
|
|
(new_row[key_part->null_offset] & key_part->null_bit))
|
|
|
|
return 1;
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
2004-12-06 01:00:37 +01:00
|
|
|
if (key_part->key_part_flag & (HA_BLOB_PART | HA_VAR_LENGTH_PART))
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
if (key_part->field->cmp_binary((char*) (old_row + key_part->offset),
|
2005-02-16 14:18:32 +01:00
|
|
|
(char*) (new_row + key_part->offset),
|
|
|
|
(ulong) key_part->length))
|
|
|
|
return 1;
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (memcmp(old_row+key_part->offset, new_row+key_part->offset,
|
2005-02-16 14:18:32 +01:00
|
|
|
key_part->length))
|
|
|
|
return 1;
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Update one record in NDB using primary key
|
|
|
|
*/
|
|
|
|
|
|
|
|
int ha_ndbcluster::update_row(const byte *old_data, byte *new_data)
|
|
|
|
{
|
|
|
|
THD *thd= current_thd;
|
2005-01-04 13:47:16 +01:00
|
|
|
NdbTransaction *trans= m_active_trans;
|
2004-12-07 15:15:49 +01:00
|
|
|
NdbScanOperation* cursor= m_active_cursor;
|
2004-04-15 09:14:14 +02:00
|
|
|
NdbOperation *op;
|
|
|
|
uint i;
|
2005-07-18 13:31:02 +02:00
|
|
|
uint32 old_part_id= 0, new_part_id= 0;
|
|
|
|
int error;
|
2006-01-17 09:25:12 +01:00
|
|
|
longlong func_value;
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_ENTER("update_row");
|
2005-04-28 14:45:27 +02:00
|
|
|
m_write_op= TRUE;
|
2004-04-15 09:14:14 +02:00
|
|
|
|
2004-09-14 21:02:23 +02:00
|
|
|
statistic_increment(thd->status_var.ha_update_count, &LOCK_status);
|
2004-10-04 00:27:04 +02:00
|
|
|
if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_UPDATE)
|
2005-04-01 17:59:46 +02:00
|
|
|
{
|
2004-10-04 00:27:04 +02:00
|
|
|
table->timestamp_field->set_time();
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
bitmap_set_bit(table->write_set, table->timestamp_field->field_index);
|
2005-04-01 17:59:46 +02:00
|
|
|
}
|
2004-10-04 00:27:04 +02:00
|
|
|
|
2005-07-18 13:31:02 +02:00
|
|
|
if (m_use_partition_function &&
|
|
|
|
(error= get_parts_for_update(old_data, new_data, table->record[0],
|
2006-01-17 09:25:12 +01:00
|
|
|
m_part_info, &old_part_id, &new_part_id,
|
|
|
|
&func_value)))
|
2005-07-18 13:31:02 +02:00
|
|
|
{
|
|
|
|
DBUG_RETURN(error);
|
|
|
|
}
|
|
|
|
|
2006-03-01 15:24:46 +01:00
|
|
|
/*
|
|
|
|
* Check for update of primary key or partition change
|
|
|
|
* for special handling
|
|
|
|
*/
|
|
|
|
if (((table_share->primary_key != MAX_KEY) &&
|
|
|
|
key_cmp(table_share->primary_key, old_data, new_data)) ||
|
2005-07-18 13:31:02 +02:00
|
|
|
(old_part_id != new_part_id))
|
2004-07-22 18:35:51 +02:00
|
|
|
{
|
2005-07-06 11:23:36 +02:00
|
|
|
int read_res, insert_res, delete_res, undo_res;
|
2004-07-22 18:35:51 +02:00
|
|
|
|
2006-03-01 15:24:46 +01:00
|
|
|
DBUG_PRINT("info", ("primary key update or partition change, "
|
|
|
|
"doing read+delete+insert"));
|
2004-07-22 18:35:51 +02:00
|
|
|
// Get all old fields, since we optimize away fields not in query
|
2006-03-01 15:24:46 +01:00
|
|
|
read_res= complemented_read(old_data, new_data, old_part_id);
|
2004-07-22 18:35:51 +02:00
|
|
|
if (read_res)
|
|
|
|
{
|
2006-03-01 15:24:46 +01:00
|
|
|
DBUG_PRINT("info", ("read failed"));
|
2004-07-22 18:35:51 +02:00
|
|
|
DBUG_RETURN(read_res);
|
|
|
|
}
|
2004-07-23 15:46:56 +02:00
|
|
|
// Delete old row
|
2004-11-03 15:53:26 +01:00
|
|
|
m_primary_key_update= TRUE;
|
2004-07-23 15:46:56 +02:00
|
|
|
delete_res= delete_row(old_data);
|
2004-11-03 15:53:26 +01:00
|
|
|
m_primary_key_update= FALSE;
|
2004-07-23 15:46:56 +02:00
|
|
|
if (delete_res)
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("delete failed"));
|
2005-04-19 11:21:26 +02:00
|
|
|
DBUG_RETURN(delete_res);
|
2004-07-23 15:46:56 +02:00
|
|
|
}
|
2005-04-19 11:21:26 +02:00
|
|
|
// Insert new row
|
|
|
|
DBUG_PRINT("info", ("delete succeded"));
|
2005-04-21 13:09:19 +02:00
|
|
|
m_primary_key_update= TRUE;
|
2005-04-19 11:21:26 +02:00
|
|
|
insert_res= write_row(new_data);
|
2005-04-21 13:09:19 +02:00
|
|
|
m_primary_key_update= FALSE;
|
2005-04-19 11:21:26 +02:00
|
|
|
if (insert_res)
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("insert failed"));
|
|
|
|
if (trans->commitStatus() == NdbConnection::Started)
|
|
|
|
{
|
2005-07-06 11:23:36 +02:00
|
|
|
// Undo delete_row(old_data)
|
2005-04-19 11:21:26 +02:00
|
|
|
m_primary_key_update= TRUE;
|
2005-07-06 11:23:36 +02:00
|
|
|
undo_res= write_row((byte *)old_data);
|
|
|
|
if (undo_res)
|
|
|
|
push_warning(current_thd,
|
|
|
|
MYSQL_ERROR::WARN_LEVEL_WARN,
|
|
|
|
undo_res,
|
|
|
|
"NDB failed undoing delete at primary key update");
|
2005-04-19 11:21:26 +02:00
|
|
|
m_primary_key_update= FALSE;
|
|
|
|
}
|
|
|
|
DBUG_RETURN(insert_res);
|
|
|
|
}
|
|
|
|
DBUG_PRINT("info", ("delete+insert succeeded"));
|
2004-07-23 15:46:56 +02:00
|
|
|
DBUG_RETURN(0);
|
2004-07-22 18:35:51 +02:00
|
|
|
}
|
2004-07-09 13:18:56 +02:00
|
|
|
|
2004-05-10 14:12:28 +02:00
|
|
|
if (cursor)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
2004-05-10 14:12:28 +02:00
|
|
|
/*
|
|
|
|
We are scanning records and want to update the record
|
|
|
|
that was just found, call updateTuple on the cursor
|
|
|
|
to take over the lock to a new update operation
|
|
|
|
And thus setting the primary key of the record from
|
|
|
|
the active record in cursor
|
|
|
|
*/
|
|
|
|
DBUG_PRINT("info", ("Calling updateTuple on cursor"));
|
2004-12-07 15:15:49 +01:00
|
|
|
if (!(op= cursor->updateCurrentTuple()))
|
2004-05-10 14:12:28 +02:00
|
|
|
ERR_RETURN(trans->getNdbError());
|
2006-06-12 14:23:21 +02:00
|
|
|
m_lock_tuple= false;
|
2004-11-03 15:53:26 +01:00
|
|
|
m_ops_pending++;
|
2005-04-28 14:45:27 +02:00
|
|
|
if (uses_blob_value())
|
2004-11-03 15:53:26 +01:00
|
|
|
m_blobs_pending= TRUE;
|
2005-07-18 13:31:02 +02:00
|
|
|
if (m_use_partition_function)
|
|
|
|
cursor->setPartitionId(new_part_id);
|
2004-05-10 14:12:28 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-05-04 13:58:17 +02:00
|
|
|
if (!(op= trans->getNdbOperation(m_table)) ||
|
2005-02-16 14:18:32 +01:00
|
|
|
op->updateTuple() != 0)
|
2004-05-10 14:12:28 +02:00
|
|
|
ERR_RETURN(trans->getNdbError());
|
|
|
|
|
2005-07-18 13:31:02 +02:00
|
|
|
if (m_use_partition_function)
|
|
|
|
op->setPartitionId(new_part_id);
|
2006-01-17 08:40:00 +01:00
|
|
|
if (table_share->primary_key == MAX_KEY)
|
2004-05-10 14:12:28 +02:00
|
|
|
{
|
|
|
|
// This table has no primary key, use "hidden" primary key
|
|
|
|
DBUG_PRINT("info", ("Using hidden key"));
|
|
|
|
|
|
|
|
// Require that the PK for this record has previously been
|
2006-02-10 17:40:22 +01:00
|
|
|
// read into m_ref
|
|
|
|
DBUG_DUMP("key", m_ref, NDB_HIDDEN_PRIMARY_KEY_LENGTH);
|
2004-05-10 14:12:28 +02:00
|
|
|
|
2006-02-10 17:59:53 +01:00
|
|
|
if (set_hidden_key(op, table->s->fields, m_ref))
|
2005-02-16 14:18:32 +01:00
|
|
|
ERR_RETURN(op->getNdbError());
|
2004-05-10 14:12:28 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int res;
|
2005-06-29 16:13:50 +02:00
|
|
|
if ((res= set_primary_key_from_record(op, old_data)))
|
2005-02-16 14:18:32 +01:00
|
|
|
DBUG_RETURN(res);
|
2004-05-10 14:12:28 +02:00
|
|
|
}
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
|
2005-03-15 15:03:25 +01:00
|
|
|
m_rows_changed++;
|
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
// Set non-key attribute(s)
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
|
2006-01-17 08:40:00 +01:00
|
|
|
for (i= 0; i < table_share->fields; i++)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
|
|
|
Field *field= table->field[i];
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
if (bitmap_is_set(table->write_set, i) &&
|
2004-04-15 09:14:14 +02:00
|
|
|
(!(field->flags & PRI_KEY_FLAG)) &&
|
2005-11-06 00:20:37 +01:00
|
|
|
set_ndb_value(op, field, i, new_data - table->record[0]))
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
{
|
|
|
|
dbug_tmp_restore_column_map(table->read_set, old_map);
|
2004-04-15 09:14:14 +02:00
|
|
|
ERR_RETURN(op->getNdbError());
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
}
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
dbug_tmp_restore_column_map(table->read_set, old_map);
|
2004-05-10 14:12:28 +02:00
|
|
|
|
2006-01-17 09:25:12 +01:00
|
|
|
if (m_use_partition_function)
|
|
|
|
{
|
|
|
|
if (func_value >= INT_MAX32)
|
|
|
|
func_value= INT_MAX32;
|
|
|
|
uint32 part_func_value= (uint32)func_value;
|
|
|
|
uint no_fields= table_share->fields;
|
|
|
|
if (table_share->primary_key == MAX_KEY)
|
|
|
|
no_fields++;
|
|
|
|
op->setValue(no_fields, part_func_value);
|
|
|
|
}
|
2004-04-15 09:14:14 +02:00
|
|
|
// Execute update operation
|
2006-08-07 14:48:54 +02:00
|
|
|
if (!cursor && execute_no_commit(this,trans,false) != 0) {
|
2004-09-14 17:51:57 +02:00
|
|
|
no_uncommitted_rows_execute_failure();
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_RETURN(ndb_err(trans));
|
2004-09-14 17:51:57 +02:00
|
|
|
}
|
2004-04-15 09:14:14 +02:00
|
|
|
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Delete one record from NDB, using primary key
|
|
|
|
*/
|
|
|
|
|
|
|
|
int ha_ndbcluster::delete_row(const byte *record)
|
|
|
|
{
|
2004-09-14 21:02:23 +02:00
|
|
|
THD *thd= current_thd;
|
2005-01-04 13:47:16 +01:00
|
|
|
NdbTransaction *trans= m_active_trans;
|
2004-12-07 15:15:49 +01:00
|
|
|
NdbScanOperation* cursor= m_active_cursor;
|
2004-04-15 09:14:14 +02:00
|
|
|
NdbOperation *op;
|
2005-07-18 13:31:02 +02:00
|
|
|
uint32 part_id;
|
|
|
|
int error;
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_ENTER("delete_row");
|
2005-04-28 14:45:27 +02:00
|
|
|
m_write_op= TRUE;
|
2004-04-15 09:14:14 +02:00
|
|
|
|
2004-09-14 21:02:23 +02:00
|
|
|
statistic_increment(thd->status_var.ha_delete_count,&LOCK_status);
|
2005-03-31 14:33:50 +02:00
|
|
|
m_rows_changed++;
|
2004-04-15 09:14:14 +02:00
|
|
|
|
2005-07-18 13:31:02 +02:00
|
|
|
if (m_use_partition_function &&
|
|
|
|
(error= get_part_for_delete(record, table->record[0], m_part_info,
|
|
|
|
&part_id)))
|
|
|
|
{
|
|
|
|
DBUG_RETURN(error);
|
|
|
|
}
|
|
|
|
|
2004-05-10 14:12:28 +02:00
|
|
|
if (cursor)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
2004-05-10 14:12:28 +02:00
|
|
|
/*
|
2004-07-23 10:33:51 +02:00
|
|
|
We are scanning records and want to delete the record
|
2004-05-10 14:12:28 +02:00
|
|
|
that was just found, call deleteTuple on the cursor
|
2004-07-23 13:13:50 +02:00
|
|
|
to take over the lock to a new delete operation
|
2004-05-10 14:12:28 +02:00
|
|
|
And thus setting the primary key of the record from
|
|
|
|
the active record in cursor
|
|
|
|
*/
|
|
|
|
DBUG_PRINT("info", ("Calling deleteTuple on cursor"));
|
2004-12-07 15:15:49 +01:00
|
|
|
if (cursor->deleteCurrentTuple() != 0)
|
2004-05-10 14:12:28 +02:00
|
|
|
ERR_RETURN(trans->getNdbError());
|
2006-06-12 14:23:21 +02:00
|
|
|
m_lock_tuple= false;
|
2004-11-03 15:53:26 +01:00
|
|
|
m_ops_pending++;
|
2004-04-15 09:14:14 +02:00
|
|
|
|
2005-07-18 13:31:02 +02:00
|
|
|
if (m_use_partition_function)
|
|
|
|
cursor->setPartitionId(part_id);
|
|
|
|
|
2004-09-14 10:52:21 +02:00
|
|
|
no_uncommitted_rows_update(-1);
|
|
|
|
|
2005-04-19 11:21:26 +02:00
|
|
|
if (!m_primary_key_update)
|
|
|
|
// If deleting from cursor, NoCommit will be handled in next_result
|
|
|
|
DBUG_RETURN(0);
|
2004-05-10 14:12:28 +02:00
|
|
|
}
|
|
|
|
else
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
2004-05-10 14:12:28 +02:00
|
|
|
|
2006-05-04 13:58:17 +02:00
|
|
|
if (!(op=trans->getNdbOperation(m_table)) ||
|
2005-02-16 14:18:32 +01:00
|
|
|
op->deleteTuple() != 0)
|
2004-05-10 14:12:28 +02:00
|
|
|
ERR_RETURN(trans->getNdbError());
|
|
|
|
|
2005-07-18 13:31:02 +02:00
|
|
|
if (m_use_partition_function)
|
|
|
|
op->setPartitionId(part_id);
|
|
|
|
|
2004-09-14 10:52:21 +02:00
|
|
|
no_uncommitted_rows_update(-1);
|
|
|
|
|
2006-01-17 08:40:00 +01:00
|
|
|
if (table_share->primary_key == MAX_KEY)
|
2004-05-10 14:12:28 +02:00
|
|
|
{
|
|
|
|
// This table has no primary key, use "hidden" primary key
|
|
|
|
DBUG_PRINT("info", ("Using hidden key"));
|
|
|
|
|
2006-02-10 17:59:53 +01:00
|
|
|
if (set_hidden_key(op, table->s->fields, m_ref))
|
2005-02-16 14:18:32 +01:00
|
|
|
ERR_RETURN(op->getNdbError());
|
2004-05-10 14:12:28 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
if ((error= set_primary_key_from_record(op, record)))
|
|
|
|
DBUG_RETURN(error);
|
2004-05-10 14:12:28 +02:00
|
|
|
}
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
2005-03-15 15:03:25 +01:00
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
// Execute delete operation
|
2006-08-07 14:48:54 +02:00
|
|
|
if (execute_no_commit(this,trans,false) != 0) {
|
2004-09-14 17:51:57 +02:00
|
|
|
no_uncommitted_rows_execute_failure();
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_RETURN(ndb_err(trans));
|
2004-09-14 17:51:57 +02:00
|
|
|
}
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
2004-05-10 14:12:28 +02:00
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
/*
|
|
|
|
Unpack a record read from NDB
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
unpack_record()
|
2005-02-16 14:18:32 +01:00
|
|
|
buf Buffer to store read row
|
2004-04-15 09:14:14 +02:00
|
|
|
|
|
|
|
NOTE
|
|
|
|
The data for each row is read directly into the
|
|
|
|
destination buffer. This function is primarily
|
|
|
|
called in order to check if any fields should be
|
|
|
|
set to null.
|
|
|
|
*/
|
|
|
|
|
2006-01-12 19:51:02 +01:00
|
|
|
void ndb_unpack_record(TABLE *table, NdbValue *value,
|
|
|
|
MY_BITMAP *defined, byte *buf)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
2005-11-06 00:20:37 +01:00
|
|
|
Field **p_field= table->field, *field= *p_field;
|
2006-06-04 20:05:22 +02:00
|
|
|
my_ptrdiff_t row_offset= (my_ptrdiff_t) (buf - table->record[0]);
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
|
2005-11-06 00:20:37 +01:00
|
|
|
DBUG_ENTER("ndb_unpack_record");
|
2004-12-01 12:43:30 +01:00
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
// Set null flag(s)
|
2005-01-06 12:00:13 +01:00
|
|
|
bzero(buf, table->s->null_bytes);
|
2005-11-06 00:20:37 +01:00
|
|
|
for ( ; field;
|
|
|
|
p_field++, value++, field= *p_field)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
2004-07-22 12:38:09 +02:00
|
|
|
if ((*value).ptr)
|
|
|
|
{
|
2005-11-06 00:20:37 +01:00
|
|
|
if (!(field->flags & BLOB_FLAG))
|
2004-07-22 12:38:09 +02:00
|
|
|
{
|
2005-11-06 00:20:37 +01:00
|
|
|
int is_null= (*value).rec->isNULL();
|
|
|
|
if (is_null)
|
2004-12-23 15:28:41 +01:00
|
|
|
{
|
2005-11-06 00:20:37 +01:00
|
|
|
if (is_null > 0)
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info",("[%u] NULL",
|
|
|
|
(*value).rec->getColumn()->getColumnNo()));
|
|
|
|
field->set_null(row_offset);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info",("[%u] UNDEFINED",
|
|
|
|
(*value).rec->getColumn()->getColumnNo()));
|
|
|
|
bitmap_clear_bit(defined,
|
|
|
|
(*value).rec->getColumn()->getColumnNo());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (field->type() == MYSQL_TYPE_BIT)
|
|
|
|
{
|
2006-05-11 11:09:58 +02:00
|
|
|
Field_bit *field_bit= static_cast<Field_bit*>(field);
|
|
|
|
|
|
|
|
/*
|
|
|
|
Move internal field pointer to point to 'buf'. Calling
|
|
|
|
the correct member function directly since we know the
|
|
|
|
type of the object.
|
|
|
|
*/
|
|
|
|
field_bit->Field_bit::move_field_offset(row_offset);
|
2005-11-06 00:20:37 +01:00
|
|
|
if (field->pack_length() < 5)
|
2004-12-23 15:28:41 +01:00
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("bit field H'%.8X",
|
2005-02-16 14:18:32 +01:00
|
|
|
(*value).rec->u_32_value()));
|
2006-05-11 11:09:58 +02:00
|
|
|
field_bit->Field_bit::store((longlong) (*value).rec->u_32_value(),
|
|
|
|
FALSE);
|
2004-12-23 15:28:41 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("bit field H'%.8X%.8X",
|
2005-11-06 00:20:37 +01:00
|
|
|
*(Uint32*) (*value).rec->aRef(),
|
|
|
|
*((Uint32*) (*value).rec->aRef()+1)));
|
2006-05-11 11:09:58 +02:00
|
|
|
field_bit->Field_bit::store((longlong) (*value).rec->u_64_value(),
|
|
|
|
TRUE);
|
2005-09-14 00:41:44 +02:00
|
|
|
}
|
2006-05-11 11:09:58 +02:00
|
|
|
/*
|
|
|
|
Move back internal field pointer to point to original
|
|
|
|
value (usually record[0]).
|
|
|
|
*/
|
|
|
|
field_bit->Field_bit::move_field_offset(-row_offset);
|
2005-11-06 00:20:37 +01:00
|
|
|
DBUG_PRINT("info",("[%u] SET",
|
|
|
|
(*value).rec->getColumn()->getColumnNo()));
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
DBUG_DUMP("info", (const char*) field->ptr, field->pack_length());
|
2005-11-06 00:20:37 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info",("[%u] SET",
|
|
|
|
(*value).rec->getColumn()->getColumnNo()));
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
DBUG_DUMP("info", (const char*) field->ptr, field->pack_length());
|
2004-12-23 15:28:41 +01:00
|
|
|
}
|
2004-07-22 12:38:09 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-11-06 00:20:37 +01:00
|
|
|
NdbBlob *ndb_blob= (*value).blob;
|
2006-01-27 20:27:10 +01:00
|
|
|
uint col_no = ndb_blob->getColumn()->getColumnNo();
|
2006-01-25 22:22:50 +01:00
|
|
|
int isNull;
|
|
|
|
ndb_blob->getDefined(isNull);
|
2006-01-27 20:27:10 +01:00
|
|
|
if (isNull == 1)
|
2006-01-25 22:22:50 +01:00
|
|
|
{
|
2006-02-14 22:36:11 +01:00
|
|
|
DBUG_PRINT("info",("[%u] NULL", col_no));
|
2006-01-27 20:27:10 +01:00
|
|
|
field->set_null(row_offset);
|
|
|
|
}
|
|
|
|
else if (isNull == -1)
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info",("[%u] UNDEFINED", col_no));
|
|
|
|
bitmap_clear_bit(defined, col_no);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
#ifndef DBUG_OFF
|
|
|
|
// pointer vas set in get_ndb_blobs_value
|
|
|
|
Field_blob *field_blob= (Field_blob*)field;
|
|
|
|
char* ptr;
|
|
|
|
field_blob->get_ptr(&ptr, row_offset);
|
|
|
|
uint32 len= field_blob->get_length(row_offset);
|
|
|
|
DBUG_PRINT("info",("[%u] SET ptr=%p len=%u", col_no, ptr, len));
|
|
|
|
#endif
|
2006-01-25 22:22:50 +01:00
|
|
|
}
|
2004-07-22 12:38:09 +02:00
|
|
|
}
|
|
|
|
}
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
dbug_tmp_restore_column_map(table->write_set, old_map);
|
2005-11-06 00:20:37 +01:00
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ha_ndbcluster::unpack_record(byte *buf)
|
|
|
|
{
|
|
|
|
ndb_unpack_record(table, m_value, 0, buf);
|
2004-04-15 09:14:14 +02:00
|
|
|
#ifndef DBUG_OFF
|
|
|
|
// Read and print all values that was fetched
|
2006-01-17 08:40:00 +01:00
|
|
|
if (table_share->primary_key == MAX_KEY)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
|
|
|
// Table with hidden primary key
|
2006-01-17 08:40:00 +01:00
|
|
|
int hidden_no= table_share->fields;
|
2006-05-04 13:58:17 +02:00
|
|
|
const NDBTAB *tab= m_table;
|
2006-06-30 03:10:27 +02:00
|
|
|
char buff[22];
|
2004-04-15 09:14:14 +02:00
|
|
|
const NDBCOL *hidden_col= tab->getColumn(hidden_no);
|
2004-12-01 12:43:30 +01:00
|
|
|
const NdbRecAttr* rec= m_value[hidden_no].rec;
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_ASSERT(rec);
|
2006-07-13 20:09:36 +02:00
|
|
|
DBUG_PRINT("hidden", ("%d: %s \"%s\"", hidden_no,
|
2006-06-30 18:15:18 +02:00
|
|
|
hidden_col->getName(),
|
2006-06-30 03:10:27 +02:00
|
|
|
llstr(rec->u_64_value(), buff)));
|
2006-02-14 22:36:11 +01:00
|
|
|
}
|
|
|
|
//DBUG_EXECUTE("value", print_results(););
|
2004-04-15 09:14:14 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Utility function to print/dump the fetched field
|
2006-02-14 22:36:11 +01:00
|
|
|
to avoid unnecessary work, wrap in DBUG_EXECUTE as in:
|
|
|
|
|
|
|
|
DBUG_EXECUTE("value", print_results(););
|
2004-04-15 09:14:14 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
void ha_ndbcluster::print_results()
|
|
|
|
{
|
|
|
|
DBUG_ENTER("print_results");
|
|
|
|
|
|
|
|
#ifndef DBUG_OFF
|
2005-02-11 22:33:52 +01:00
|
|
|
|
2005-01-11 17:00:31 +01:00
|
|
|
char buf_type[MAX_FIELD_WIDTH], buf_val[MAX_FIELD_WIDTH];
|
2005-02-11 22:33:52 +01:00
|
|
|
String type(buf_type, sizeof(buf_type), &my_charset_bin);
|
2005-01-11 17:00:31 +01:00
|
|
|
String val(buf_val, sizeof(buf_val), &my_charset_bin);
|
2006-01-17 08:40:00 +01:00
|
|
|
for (uint f= 0; f < table_share->fields; f++)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
2005-02-11 22:33:52 +01:00
|
|
|
/* Use DBUG_PRINT since DBUG_FILE cannot be filtered out */
|
2004-12-17 09:01:54 +01:00
|
|
|
char buf[2000];
|
2004-04-15 09:14:14 +02:00
|
|
|
Field *field;
|
2004-12-20 15:12:42 +01:00
|
|
|
void* ptr;
|
2004-07-22 12:38:09 +02:00
|
|
|
NdbValue value;
|
2004-04-15 09:14:14 +02:00
|
|
|
|
2005-01-11 17:00:31 +01:00
|
|
|
buf[0]= 0;
|
2005-02-11 22:33:52 +01:00
|
|
|
field= table->field[f];
|
2004-07-22 12:38:09 +02:00
|
|
|
if (!(value= m_value[f]).ptr)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
2005-07-04 02:42:33 +02:00
|
|
|
strmov(buf, "not read");
|
2004-12-17 09:01:54 +01:00
|
|
|
goto print_value;
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
2005-01-11 17:00:31 +01:00
|
|
|
|
2004-12-20 15:12:42 +01:00
|
|
|
ptr= field->ptr;
|
2004-07-22 12:38:09 +02:00
|
|
|
|
|
|
|
if (! (field->flags & BLOB_FLAG))
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
2004-07-22 12:38:09 +02:00
|
|
|
if (value.rec->isNULL())
|
|
|
|
{
|
2005-07-04 02:42:33 +02:00
|
|
|
strmov(buf, "NULL");
|
2004-12-17 09:01:54 +01:00
|
|
|
goto print_value;
|
2004-07-22 12:38:09 +02:00
|
|
|
}
|
2005-01-11 17:00:31 +01:00
|
|
|
type.length(0);
|
|
|
|
val.length(0);
|
|
|
|
field->sql_type(type);
|
|
|
|
field->val_str(&val);
|
|
|
|
my_snprintf(buf, sizeof(buf), "%s %s", type.c_ptr(), val.c_ptr());
|
2004-07-22 12:38:09 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-02-17 14:22:44 +01:00
|
|
|
NdbBlob *ndb_blob= value.blob;
|
2004-10-14 17:03:46 +02:00
|
|
|
bool isNull= TRUE;
|
2004-07-22 12:38:09 +02:00
|
|
|
ndb_blob->getNull(isNull);
|
2005-07-04 02:42:33 +02:00
|
|
|
if (isNull)
|
|
|
|
strmov(buf, "NULL");
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
2005-02-11 22:33:52 +01:00
|
|
|
|
2004-12-17 09:01:54 +01:00
|
|
|
print_value:
|
2005-02-11 22:33:52 +01:00
|
|
|
DBUG_PRINT("value", ("%u,%s: %s", f, field->field_name, buf));
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-18 13:31:02 +02:00
|
|
|
int ha_ndbcluster::index_init(uint index, bool sorted)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
2004-12-20 15:12:42 +01:00
|
|
|
DBUG_ENTER("ha_ndbcluster::index_init");
|
2005-07-18 13:31:02 +02:00
|
|
|
DBUG_PRINT("enter", ("index: %u sorted: %d", index, sorted));
|
|
|
|
active_index= index;
|
|
|
|
m_sorted= sorted;
|
2006-06-12 14:23:21 +02:00
|
|
|
/*
|
|
|
|
Locks are are explicitly released in scan
|
|
|
|
unless m_lock.type == TL_READ_HIGH_PRIORITY
|
|
|
|
and no sub-sequent call to unlock_row()
|
|
|
|
*/
|
|
|
|
m_lock_tuple= false;
|
|
|
|
m_lock_tuple= false;
|
2005-07-18 13:31:02 +02:00
|
|
|
DBUG_RETURN(0);
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int ha_ndbcluster::index_end()
|
|
|
|
{
|
2004-12-20 15:12:42 +01:00
|
|
|
DBUG_ENTER("ha_ndbcluster::index_end");
|
2004-05-11 13:59:22 +02:00
|
|
|
DBUG_RETURN(close_scan());
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
|
2004-11-30 07:41:26 +01:00
|
|
|
/**
|
|
|
|
* Check if key contains null
|
|
|
|
*/
|
|
|
|
static
|
|
|
|
int
|
|
|
|
check_null_in_key(const KEY* key_info, const byte *key, uint key_len)
|
|
|
|
{
|
|
|
|
KEY_PART_INFO *curr_part, *end_part;
|
2004-12-07 15:15:49 +01:00
|
|
|
const byte* end_ptr= key + key_len;
|
2004-11-30 07:41:26 +01:00
|
|
|
curr_part= key_info->key_part;
|
|
|
|
end_part= curr_part + key_info->key_parts;
|
|
|
|
|
|
|
|
|
|
|
|
for (; curr_part != end_part && key < end_ptr; curr_part++)
|
|
|
|
{
|
2005-07-04 02:42:33 +02:00
|
|
|
if (curr_part->null_bit && *key)
|
2004-11-30 07:41:26 +01:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
key += curr_part->store_length;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2004-04-15 09:14:14 +02:00
|
|
|
|
|
|
|
int ha_ndbcluster::index_read(byte *buf,
|
2005-02-16 14:18:32 +01:00
|
|
|
const byte *key, uint key_len,
|
|
|
|
enum ha_rkey_function find_flag)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
2005-07-18 13:31:02 +02:00
|
|
|
key_range start_key;
|
|
|
|
bool descending= FALSE;
|
2004-12-20 15:12:42 +01:00
|
|
|
DBUG_ENTER("ha_ndbcluster::index_read");
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_PRINT("enter", ("active_index: %u, key_len: %u, find_flag: %d",
|
|
|
|
active_index, key_len, find_flag));
|
|
|
|
|
2004-12-07 15:15:49 +01:00
|
|
|
start_key.key= key;
|
|
|
|
start_key.length= key_len;
|
|
|
|
start_key.flag= find_flag;
|
2005-07-18 13:31:02 +02:00
|
|
|
descending= FALSE;
|
2004-12-20 15:12:42 +01:00
|
|
|
switch (find_flag) {
|
|
|
|
case HA_READ_KEY_OR_PREV:
|
|
|
|
case HA_READ_BEFORE_KEY:
|
|
|
|
case HA_READ_PREFIX_LAST:
|
|
|
|
case HA_READ_PREFIX_LAST_OR_PREV:
|
|
|
|
descending= TRUE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2005-07-18 13:31:02 +02:00
|
|
|
DBUG_RETURN(read_range_first_to_buf(&start_key, 0, descending,
|
|
|
|
m_sorted, buf));
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int ha_ndbcluster::index_read_idx(byte *buf, uint index_no,
|
2005-02-16 14:18:32 +01:00
|
|
|
const byte *key, uint key_len,
|
|
|
|
enum ha_rkey_function find_flag)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
2004-09-14 21:02:23 +02:00
|
|
|
statistic_increment(current_thd->status_var.ha_read_key_count, &LOCK_status);
|
2004-12-20 15:12:42 +01:00
|
|
|
DBUG_ENTER("ha_ndbcluster::index_read_idx");
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_PRINT("enter", ("index_no: %u, key_len: %u", index_no, key_len));
|
2006-01-12 19:51:02 +01:00
|
|
|
close_scan();
|
2005-07-18 13:31:02 +02:00
|
|
|
index_init(index_no, 0);
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_RETURN(index_read(buf, key, key_len, find_flag));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int ha_ndbcluster::index_next(byte *buf)
|
|
|
|
{
|
2004-12-20 15:12:42 +01:00
|
|
|
DBUG_ENTER("ha_ndbcluster::index_next");
|
2004-09-14 21:02:23 +02:00
|
|
|
statistic_increment(current_thd->status_var.ha_read_next_count,
|
2005-02-16 14:18:32 +01:00
|
|
|
&LOCK_status);
|
2004-05-10 14:12:28 +02:00
|
|
|
DBUG_RETURN(next_result(buf));
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int ha_ndbcluster::index_prev(byte *buf)
|
|
|
|
{
|
2004-12-20 15:12:42 +01:00
|
|
|
DBUG_ENTER("ha_ndbcluster::index_prev");
|
2004-09-14 21:02:23 +02:00
|
|
|
statistic_increment(current_thd->status_var.ha_read_prev_count,
|
2005-02-16 14:18:32 +01:00
|
|
|
&LOCK_status);
|
2004-12-20 15:12:42 +01:00
|
|
|
DBUG_RETURN(next_result(buf));
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int ha_ndbcluster::index_first(byte *buf)
|
|
|
|
{
|
2004-12-20 15:12:42 +01:00
|
|
|
DBUG_ENTER("ha_ndbcluster::index_first");
|
2004-09-14 21:02:23 +02:00
|
|
|
statistic_increment(current_thd->status_var.ha_read_first_count,
|
2005-02-16 14:18:32 +01:00
|
|
|
&LOCK_status);
|
2004-09-03 13:55:40 +02:00
|
|
|
// Start the ordered index scan and fetch the first row
|
|
|
|
|
|
|
|
// Only HA_READ_ORDER indexes get called by index_first
|
2005-07-18 13:31:02 +02:00
|
|
|
DBUG_RETURN(ordered_index_scan(0, 0, TRUE, FALSE, buf, NULL));
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int ha_ndbcluster::index_last(byte *buf)
|
|
|
|
{
|
2004-12-20 15:12:42 +01:00
|
|
|
DBUG_ENTER("ha_ndbcluster::index_last");
|
2004-09-13 15:48:01 +02:00
|
|
|
statistic_increment(current_thd->status_var.ha_read_last_count,&LOCK_status);
|
2005-07-18 13:31:02 +02:00
|
|
|
DBUG_RETURN(ordered_index_scan(0, 0, TRUE, TRUE, buf, NULL));
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
|
2004-12-20 15:12:42 +01:00
|
|
|
int ha_ndbcluster::index_read_last(byte * buf, const byte * key, uint key_len)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_ndbcluster::index_read_last");
|
|
|
|
DBUG_RETURN(index_read(buf, key, key_len, HA_READ_PREFIX_LAST));
|
|
|
|
}
|
2004-04-15 09:14:14 +02:00
|
|
|
|
2004-09-07 16:22:42 +02:00
|
|
|
int ha_ndbcluster::read_range_first_to_buf(const key_range *start_key,
|
2005-02-16 14:18:32 +01:00
|
|
|
const key_range *end_key,
|
2005-07-18 13:31:02 +02:00
|
|
|
bool desc, bool sorted,
|
2005-02-16 14:18:32 +01:00
|
|
|
byte* buf)
|
2004-04-30 13:38:41 +02:00
|
|
|
{
|
2005-07-18 13:31:02 +02:00
|
|
|
part_id_range part_spec;
|
|
|
|
ndb_index_type type= get_index_type(active_index);
|
|
|
|
const KEY* key_info= table->key_info+active_index;
|
|
|
|
int error;
|
2004-09-07 16:22:42 +02:00
|
|
|
DBUG_ENTER("ha_ndbcluster::read_range_first_to_buf");
|
2005-07-18 13:31:02 +02:00
|
|
|
DBUG_PRINT("info", ("desc: %d, sorted: %d", desc, sorted));
|
2004-04-30 13:38:41 +02:00
|
|
|
|
2005-07-18 13:31:02 +02:00
|
|
|
if (m_use_partition_function)
|
|
|
|
{
|
|
|
|
get_partition_set(table, buf, active_index, start_key, &part_spec);
|
2006-02-10 17:06:24 +01:00
|
|
|
DBUG_PRINT("info", ("part_spec.start_part = %u, part_spec.end_part = %u",
|
|
|
|
part_spec.start_part, part_spec.end_part));
|
|
|
|
/*
|
|
|
|
If partition pruning has found no partition in set
|
|
|
|
we can return HA_ERR_END_OF_FILE
|
|
|
|
If partition pruning has found exactly one partition in set
|
|
|
|
we can optimize scan to run towards that partition only.
|
|
|
|
*/
|
2005-07-18 13:31:02 +02:00
|
|
|
if (part_spec.start_part > part_spec.end_part)
|
|
|
|
{
|
|
|
|
DBUG_RETURN(HA_ERR_END_OF_FILE);
|
|
|
|
}
|
|
|
|
else if (part_spec.start_part == part_spec.end_part)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Only one partition is required to scan, if sorted is required we
|
|
|
|
don't need it any more since output from one ordered partitioned
|
|
|
|
index is always sorted.
|
|
|
|
*/
|
|
|
|
sorted= FALSE;
|
|
|
|
}
|
|
|
|
}
|
2006-02-10 17:06:24 +01:00
|
|
|
|
2005-07-18 13:31:02 +02:00
|
|
|
m_write_op= FALSE;
|
|
|
|
switch (type){
|
2004-05-24 12:35:39 +02:00
|
|
|
case PRIMARY_KEY_ORDERED_INDEX:
|
2004-04-30 13:38:41 +02:00
|
|
|
case PRIMARY_KEY_INDEX:
|
2004-05-10 14:46:06 +02:00
|
|
|
if (start_key &&
|
2005-02-16 14:18:32 +01:00
|
|
|
start_key->length == key_info->key_length &&
|
|
|
|
start_key->flag == HA_READ_KEY_EXACT)
|
2004-05-17 09:51:02 +02:00
|
|
|
{
|
2005-07-04 02:42:33 +02:00
|
|
|
if (m_active_cursor && (error= close_scan()))
|
2005-02-16 14:18:32 +01:00
|
|
|
DBUG_RETURN(error);
|
2005-07-18 13:31:02 +02:00
|
|
|
DBUG_RETURN(pk_read(start_key->key, start_key->length, buf,
|
|
|
|
part_spec.start_part));
|
2004-05-17 09:51:02 +02:00
|
|
|
}
|
2004-04-30 13:38:41 +02:00
|
|
|
break;
|
2004-05-24 12:35:39 +02:00
|
|
|
case UNIQUE_ORDERED_INDEX:
|
2004-04-30 13:38:41 +02:00
|
|
|
case UNIQUE_INDEX:
|
2004-11-30 07:41:26 +01:00
|
|
|
if (start_key && start_key->length == key_info->key_length &&
|
2005-02-16 14:18:32 +01:00
|
|
|
start_key->flag == HA_READ_KEY_EXACT &&
|
|
|
|
!check_null_in_key(key_info, start_key->key, start_key->length))
|
2004-05-17 09:51:02 +02:00
|
|
|
{
|
2005-07-04 02:42:33 +02:00
|
|
|
if (m_active_cursor && (error= close_scan()))
|
2005-02-16 14:18:32 +01:00
|
|
|
DBUG_RETURN(error);
|
2005-07-18 13:31:02 +02:00
|
|
|
DBUG_RETURN(unique_index_read(start_key->key, start_key->length, buf));
|
2004-05-17 09:51:02 +02:00
|
|
|
}
|
2004-04-30 13:38:41 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2004-05-10 14:46:06 +02:00
|
|
|
// Start the ordered index scan and fetch the first row
|
2005-07-18 13:31:02 +02:00
|
|
|
DBUG_RETURN(ordered_index_scan(start_key, end_key, sorted, desc, buf,
|
|
|
|
&part_spec));
|
2004-04-30 13:38:41 +02:00
|
|
|
}
|
|
|
|
|
2004-10-21 12:39:08 +02:00
|
|
|
int ha_ndbcluster::read_range_first(const key_range *start_key,
|
2005-02-16 14:18:32 +01:00
|
|
|
const key_range *end_key,
|
|
|
|
bool eq_r, bool sorted)
|
2004-10-21 12:39:08 +02:00
|
|
|
{
|
|
|
|
byte* buf= table->record[0];
|
|
|
|
DBUG_ENTER("ha_ndbcluster::read_range_first");
|
2005-07-18 13:31:02 +02:00
|
|
|
DBUG_RETURN(read_range_first_to_buf(start_key, end_key, FALSE,
|
|
|
|
sorted, buf));
|
2004-10-21 12:39:08 +02:00
|
|
|
}
|
|
|
|
|
2004-05-24 12:35:39 +02:00
|
|
|
int ha_ndbcluster::read_range_next()
|
2004-04-30 13:38:41 +02:00
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_ndbcluster::read_range_next");
|
|
|
|
DBUG_RETURN(next_result(table->record[0]));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
int ha_ndbcluster::rnd_init(bool scan)
|
|
|
|
{
|
2004-12-07 15:15:49 +01:00
|
|
|
NdbScanOperation *cursor= m_active_cursor;
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_ENTER("rnd_init");
|
|
|
|
DBUG_PRINT("enter", ("scan: %d", scan));
|
2004-07-09 13:18:56 +02:00
|
|
|
// Check if scan is to be restarted
|
2004-08-24 23:13:32 +02:00
|
|
|
if (cursor)
|
|
|
|
{
|
|
|
|
if (!scan)
|
|
|
|
DBUG_RETURN(1);
|
2005-07-04 02:42:33 +02:00
|
|
|
if (cursor->restart(m_force_send) != 0)
|
2005-01-11 17:00:31 +01:00
|
|
|
{
|
|
|
|
DBUG_ASSERT(0);
|
|
|
|
DBUG_RETURN(-1);
|
|
|
|
}
|
2004-08-24 23:13:32 +02:00
|
|
|
}
|
2006-01-17 08:40:00 +01:00
|
|
|
index_init(table_share->primary_key, 0);
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
2004-05-11 13:59:22 +02:00
|
|
|
int ha_ndbcluster::close_scan()
|
|
|
|
{
|
2005-01-04 13:47:16 +01:00
|
|
|
NdbTransaction *trans= m_active_trans;
|
2004-05-11 13:59:22 +02:00
|
|
|
DBUG_ENTER("close_scan");
|
|
|
|
|
2004-12-08 00:36:40 +01:00
|
|
|
m_multi_cursor= 0;
|
|
|
|
if (!m_active_cursor && !m_multi_cursor)
|
2004-05-11 13:59:22 +02:00
|
|
|
DBUG_RETURN(1);
|
|
|
|
|
2004-12-08 00:36:40 +01:00
|
|
|
NdbScanOperation *cursor= m_active_cursor ? m_active_cursor : m_multi_cursor;
|
2004-08-04 10:54:42 +02:00
|
|
|
|
2006-08-08 12:22:23 +02:00
|
|
|
if (m_lock_tuple)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Lock level m_lock.type either TL_WRITE_ALLOW_WRITE
|
|
|
|
(SELECT FOR UPDATE) or TL_READ_WITH_SHARED_LOCKS (SELECT
|
|
|
|
LOCK WITH SHARE MODE) and row was not explictly unlocked
|
|
|
|
with unlock_row() call
|
|
|
|
*/
|
|
|
|
NdbOperation *op;
|
|
|
|
// Lock row
|
|
|
|
DBUG_PRINT("info", ("Keeping lock on scanned row"));
|
|
|
|
|
2006-08-08 14:42:05 +02:00
|
|
|
if (!(op= cursor->lockCurrentTuple()))
|
2006-08-08 12:22:23 +02:00
|
|
|
{
|
|
|
|
m_lock_tuple= false;
|
|
|
|
ERR_RETURN(trans->getNdbError());
|
|
|
|
}
|
|
|
|
m_ops_pending++;
|
|
|
|
}
|
2006-06-08 16:12:38 +02:00
|
|
|
m_lock_tuple= false;
|
2004-11-03 15:53:26 +01:00
|
|
|
if (m_ops_pending)
|
2004-08-04 10:54:42 +02:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
Take over any pending transactions to the
|
|
|
|
deleteing/updating transaction before closing the scan
|
|
|
|
*/
|
2004-11-03 15:53:26 +01:00
|
|
|
DBUG_PRINT("info", ("ops_pending: %d", m_ops_pending));
|
2006-08-07 14:48:54 +02:00
|
|
|
if (execute_no_commit(this,trans,false) != 0) {
|
2004-09-14 17:51:57 +02:00
|
|
|
no_uncommitted_rows_execute_failure();
|
2004-08-04 10:54:42 +02:00
|
|
|
DBUG_RETURN(ndb_err(trans));
|
2004-09-14 17:51:57 +02:00
|
|
|
}
|
2004-11-03 15:53:26 +01:00
|
|
|
m_ops_pending= 0;
|
2004-08-04 10:54:42 +02:00
|
|
|
}
|
|
|
|
|
2005-05-06 10:39:30 +02:00
|
|
|
cursor->close(m_force_send, TRUE);
|
2004-12-08 00:36:40 +01:00
|
|
|
m_active_cursor= m_multi_cursor= NULL;
|
2004-05-28 11:23:44 +02:00
|
|
|
DBUG_RETURN(0);
|
2004-05-11 13:59:22 +02:00
|
|
|
}
|
2004-04-15 09:14:14 +02:00
|
|
|
|
|
|
|
int ha_ndbcluster::rnd_end()
|
|
|
|
{
|
|
|
|
DBUG_ENTER("rnd_end");
|
2004-05-11 13:59:22 +02:00
|
|
|
DBUG_RETURN(close_scan());
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int ha_ndbcluster::rnd_next(byte *buf)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("rnd_next");
|
2004-09-14 21:02:23 +02:00
|
|
|
statistic_increment(current_thd->status_var.ha_read_rnd_next_count,
|
2005-02-16 14:18:32 +01:00
|
|
|
&LOCK_status);
|
2004-05-10 14:12:28 +02:00
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
if (!m_active_cursor)
|
2004-05-10 14:12:28 +02:00
|
|
|
DBUG_RETURN(full_table_scan(buf));
|
|
|
|
DBUG_RETURN(next_result(buf));
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
An "interesting" record has been found and it's pk
|
|
|
|
retrieved by calling position
|
|
|
|
Now it's time to read the record from db once
|
|
|
|
again
|
|
|
|
*/
|
|
|
|
|
|
|
|
int ha_ndbcluster::rnd_pos(byte *buf, byte *pos)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("rnd_pos");
|
2004-09-14 21:02:23 +02:00
|
|
|
statistic_increment(current_thd->status_var.ha_read_rnd_count,
|
2005-02-16 14:18:32 +01:00
|
|
|
&LOCK_status);
|
2004-04-15 09:14:14 +02:00
|
|
|
// The primary key for the record is stored in pos
|
|
|
|
// Perform a pk_read using primary key "index"
|
2005-07-18 13:31:02 +02:00
|
|
|
{
|
|
|
|
part_id_range part_spec;
|
2006-03-14 15:27:38 +01:00
|
|
|
uint key_length= ref_length;
|
2005-07-18 13:31:02 +02:00
|
|
|
if (m_use_partition_function)
|
|
|
|
{
|
2006-03-14 15:27:38 +01:00
|
|
|
if (table_share->primary_key == MAX_KEY)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
The partition id has been fetched from ndb
|
|
|
|
and has been stored directly after the hidden key
|
|
|
|
*/
|
2006-03-29 13:13:39 +02:00
|
|
|
DBUG_DUMP("key+part", (char *)pos, key_length);
|
2006-03-14 15:27:38 +01:00
|
|
|
key_length= ref_length - sizeof(m_part_id);
|
2006-03-29 23:48:35 +02:00
|
|
|
part_spec.start_part= part_spec.end_part= *(uint32 *)(pos + key_length);
|
2006-03-14 15:27:38 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
key_range key_spec;
|
2006-03-18 10:04:39 +01:00
|
|
|
KEY *key_info= table->key_info + table_share->primary_key;
|
2006-03-14 15:27:38 +01:00
|
|
|
key_spec.key= pos;
|
|
|
|
key_spec.length= key_length;
|
|
|
|
key_spec.flag= HA_READ_KEY_EXACT;
|
|
|
|
get_full_part_id_from_key(table, buf, key_info,
|
|
|
|
&key_spec, &part_spec);
|
|
|
|
DBUG_ASSERT(part_spec.start_part == part_spec.end_part);
|
|
|
|
}
|
|
|
|
DBUG_PRINT("info", ("partition id %u", part_spec.start_part));
|
2005-07-18 13:31:02 +02:00
|
|
|
}
|
2006-03-29 13:13:39 +02:00
|
|
|
DBUG_DUMP("key", (char *)pos, key_length);
|
2006-03-14 15:27:38 +01:00
|
|
|
DBUG_RETURN(pk_read(pos, key_length, buf, part_spec.start_part));
|
2005-07-18 13:31:02 +02:00
|
|
|
}
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Store the primary key of this record in ref
|
|
|
|
variable, so that the row can be retrieved again later
|
|
|
|
using "reference" in rnd_pos
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ha_ndbcluster::position(const byte *record)
|
|
|
|
{
|
|
|
|
KEY *key_info;
|
|
|
|
KEY_PART_INFO *key_part;
|
|
|
|
KEY_PART_INFO *end;
|
|
|
|
byte *buff;
|
2006-03-18 10:04:39 +01:00
|
|
|
uint key_length;
|
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_ENTER("position");
|
|
|
|
|
2006-01-17 08:40:00 +01:00
|
|
|
if (table_share->primary_key != MAX_KEY)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
2006-03-18 10:04:39 +01:00
|
|
|
key_length= ref_length;
|
2006-01-17 08:40:00 +01:00
|
|
|
key_info= table->key_info + table_share->primary_key;
|
2004-04-15 09:14:14 +02:00
|
|
|
key_part= key_info->key_part;
|
|
|
|
end= key_part + key_info->key_parts;
|
|
|
|
buff= ref;
|
|
|
|
|
|
|
|
for (; key_part != end; key_part++)
|
|
|
|
{
|
|
|
|
if (key_part->null_bit) {
|
|
|
|
/* Store 0 if the key part is a NULL part */
|
|
|
|
if (record[key_part->null_offset]
|
|
|
|
& key_part->null_bit) {
|
|
|
|
*buff++= 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
*buff++= 0;
|
|
|
|
}
|
2005-12-20 20:53:29 +01:00
|
|
|
|
|
|
|
size_t len = key_part->length;
|
|
|
|
const byte * ptr = record + key_part->offset;
|
|
|
|
Field *field = key_part->field;
|
|
|
|
if ((field->type() == MYSQL_TYPE_VARCHAR) &&
|
|
|
|
((Field_varstring*)field)->length_bytes == 1)
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Keys always use 2 bytes length
|
|
|
|
*/
|
|
|
|
buff[0] = ptr[0];
|
|
|
|
buff[1] = 0;
|
|
|
|
memcpy(buff+2, ptr + 1, len);
|
|
|
|
len += 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
memcpy(buff, ptr, len);
|
|
|
|
}
|
|
|
|
buff += len;
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// No primary key, get hidden key
|
|
|
|
DBUG_PRINT("info", ("Getting hidden key"));
|
2006-03-14 15:27:38 +01:00
|
|
|
// If table has user defined partition save the partition id as well
|
|
|
|
if(m_use_partition_function)
|
|
|
|
{
|
2006-03-14 15:43:28 +01:00
|
|
|
DBUG_PRINT("info", ("Saving partition id %u", m_part_id));
|
2006-03-14 15:27:38 +01:00
|
|
|
key_length= ref_length - sizeof(m_part_id);
|
|
|
|
memcpy(ref+key_length, (void *)&m_part_id, sizeof(m_part_id));
|
|
|
|
}
|
2006-03-18 10:04:39 +01:00
|
|
|
else
|
|
|
|
key_length= ref_length;
|
2005-01-11 17:00:31 +01:00
|
|
|
#ifndef DBUG_OFF
|
2006-02-10 17:50:17 +01:00
|
|
|
int hidden_no= table->s->fields;
|
2006-05-04 13:58:17 +02:00
|
|
|
const NDBTAB *tab= m_table;
|
2004-04-15 09:14:14 +02:00
|
|
|
const NDBCOL *hidden_col= tab->getColumn(hidden_no);
|
|
|
|
DBUG_ASSERT(hidden_col->getPrimaryKey() &&
|
|
|
|
hidden_col->getAutoIncrement() &&
|
2006-03-14 15:27:38 +01:00
|
|
|
key_length == NDB_HIDDEN_PRIMARY_KEY_LENGTH);
|
2005-01-11 17:00:31 +01:00
|
|
|
#endif
|
2006-03-14 15:27:38 +01:00
|
|
|
memcpy(ref, m_ref, key_length);
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
2006-03-29 13:13:39 +02:00
|
|
|
#ifndef DBUG_OFF
|
|
|
|
if (table_share->primary_key == MAX_KEY && m_use_partition_function)
|
|
|
|
DBUG_DUMP("key+part", (char*)ref, key_length+sizeof(m_part_id));
|
|
|
|
#endif
|
2006-03-14 15:27:38 +01:00
|
|
|
DBUG_DUMP("ref", (char*)ref, key_length);
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ha_ndbcluster::info(uint flag)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("info");
|
|
|
|
DBUG_PRINT("enter", ("flag: %d", flag));
|
|
|
|
|
|
|
|
if (flag & HA_STATUS_POS)
|
|
|
|
DBUG_PRINT("info", ("HA_STATUS_POS"));
|
|
|
|
if (flag & HA_STATUS_NO_LOCK)
|
|
|
|
DBUG_PRINT("info", ("HA_STATUS_NO_LOCK"));
|
|
|
|
if (flag & HA_STATUS_TIME)
|
|
|
|
DBUG_PRINT("info", ("HA_STATUS_TIME"));
|
|
|
|
if (flag & HA_STATUS_VARIABLE)
|
2004-09-14 10:52:21 +02:00
|
|
|
{
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_PRINT("info", ("HA_STATUS_VARIABLE"));
|
2004-09-20 17:52:19 +02:00
|
|
|
if (m_table_info)
|
|
|
|
{
|
2004-11-17 09:15:53 +01:00
|
|
|
if (m_ha_not_exact_count)
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
stats.records= 100;
|
2004-11-17 09:15:53 +01:00
|
|
|
else
|
2005-02-16 14:18:32 +01:00
|
|
|
records_update();
|
2004-09-20 17:52:19 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-12-30 19:56:09 +01:00
|
|
|
if ((my_errno= check_ndb_connection()))
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
Ndb *ndb= get_ndb();
|
2006-04-19 18:29:25 +02:00
|
|
|
ndb->setDatabaseName(m_dbname);
|
2005-01-13 18:24:19 +01:00
|
|
|
struct Ndb_statistics stat;
|
2006-06-29 20:55:21 +02:00
|
|
|
ndb->setDatabaseName(m_dbname);
|
2005-01-13 18:24:19 +01:00
|
|
|
if (current_thd->variables.ndb_use_exact_count &&
|
2006-05-04 13:58:17 +02:00
|
|
|
ndb_get_table_statistics(ndb, m_table, &stat) == 0)
|
2005-01-13 18:24:19 +01:00
|
|
|
{
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
stats.mean_rec_length= stat.row_size;
|
|
|
|
stats.data_file_length= stat.fragment_memory;
|
|
|
|
stats.records= stat.row_count;
|
2005-01-13 18:24:19 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
stats.mean_rec_length= 0;
|
|
|
|
stats.records= 100;
|
2005-01-13 18:24:19 +01:00
|
|
|
}
|
2004-09-20 17:52:19 +02:00
|
|
|
}
|
2004-09-14 10:52:21 +02:00
|
|
|
}
|
2004-10-04 01:20:05 +02:00
|
|
|
if (flag & HA_STATUS_CONST)
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("HA_STATUS_CONST"));
|
|
|
|
set_rec_per_key();
|
|
|
|
}
|
2004-04-15 09:14:14 +02:00
|
|
|
if (flag & HA_STATUS_ERRKEY)
|
2004-08-31 12:07:48 +02:00
|
|
|
{
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_PRINT("info", ("HA_STATUS_ERRKEY"));
|
2004-11-03 15:53:26 +01:00
|
|
|
errkey= m_dupkey;
|
2004-08-31 12:07:48 +02:00
|
|
|
}
|
2004-04-15 09:14:14 +02:00
|
|
|
if (flag & HA_STATUS_AUTO)
|
2005-08-10 09:38:36 +02:00
|
|
|
{
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_PRINT("info", ("HA_STATUS_AUTO"));
|
2005-08-10 09:38:36 +02:00
|
|
|
if (m_table)
|
|
|
|
{
|
|
|
|
Ndb *ndb= get_ndb();
|
2006-05-25 12:13:47 +02:00
|
|
|
Ndb_tuple_id_range_guard g(m_share);
|
2005-08-10 09:38:36 +02:00
|
|
|
|
2006-05-25 20:00:36 +02:00
|
|
|
Uint64 auto_increment_value64;
|
2006-05-25 12:13:47 +02:00
|
|
|
if (ndb->readAutoIncrementValue(m_table, g.range,
|
2006-05-25 20:00:36 +02:00
|
|
|
auto_increment_value64) == -1)
|
2006-05-17 12:40:10 +02:00
|
|
|
{
|
|
|
|
const NdbError err= ndb->getNdbError();
|
|
|
|
sql_print_error("Error %lu in readAutoIncrementValue(): %s",
|
|
|
|
(ulong) err.code, err.message);
|
2006-06-04 20:05:22 +02:00
|
|
|
stats.auto_increment_value= ~(ulonglong)0;
|
2006-05-17 12:40:10 +02:00
|
|
|
}
|
2006-05-25 20:00:36 +02:00
|
|
|
else
|
2006-06-04 20:05:22 +02:00
|
|
|
stats.auto_increment_value= (ulonglong)auto_increment_value64;
|
2005-08-10 09:38:36 +02:00
|
|
|
}
|
|
|
|
}
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
2006-01-10 16:44:04 +01:00
|
|
|
|
|
|
|
void ha_ndbcluster::get_dynamic_partition_info(PARTITION_INFO *stat_info,
|
|
|
|
uint part_id)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
This functions should be fixed. Suggested fix: to
|
|
|
|
implement ndb function which retrives the statistics
|
|
|
|
about ndb partitions.
|
|
|
|
*/
|
|
|
|
bzero((char*) stat_info, sizeof(PARTITION_INFO));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
int ha_ndbcluster::extra(enum ha_extra_function operation)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("extra");
|
|
|
|
switch (operation) {
|
|
|
|
case HA_EXTRA_IGNORE_DUP_KEY: /* Dup keys don't rollback everything*/
|
|
|
|
DBUG_PRINT("info", ("HA_EXTRA_IGNORE_DUP_KEY"));
|
2006-07-01 23:51:10 +02:00
|
|
|
DBUG_PRINT("info", ("Ignoring duplicate key"));
|
|
|
|
m_ignore_dup_key= TRUE;
|
2004-04-15 09:14:14 +02:00
|
|
|
break;
|
|
|
|
case HA_EXTRA_NO_IGNORE_DUP_KEY:
|
|
|
|
DBUG_PRINT("info", ("HA_EXTRA_NO_IGNORE_DUP_KEY"));
|
2004-11-18 12:11:56 +01:00
|
|
|
m_ignore_dup_key= FALSE;
|
2004-04-15 09:14:14 +02:00
|
|
|
break;
|
2006-01-12 19:51:02 +01:00
|
|
|
case HA_EXTRA_IGNORE_NO_KEY:
|
|
|
|
DBUG_PRINT("info", ("HA_EXTRA_IGNORE_NO_KEY"));
|
|
|
|
DBUG_PRINT("info", ("Turning on AO_IgnoreError at Commit/NoCommit"));
|
|
|
|
m_ignore_no_key= TRUE;
|
|
|
|
break;
|
|
|
|
case HA_EXTRA_NO_IGNORE_NO_KEY:
|
|
|
|
DBUG_PRINT("info", ("HA_EXTRA_NO_IGNORE_NO_KEY"));
|
|
|
|
DBUG_PRINT("info", ("Turning on AO_IgnoreError at Commit/NoCommit"));
|
|
|
|
m_ignore_no_key= FALSE;
|
|
|
|
break;
|
2006-07-01 23:51:10 +02:00
|
|
|
case HA_EXTRA_WRITE_CAN_REPLACE:
|
|
|
|
DBUG_PRINT("info", ("HA_EXTRA_WRITE_CAN_REPLACE"));
|
|
|
|
if (!m_has_unique_index)
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("Turning ON use of write instead of insert"));
|
|
|
|
m_use_write= TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case HA_EXTRA_WRITE_CANNOT_REPLACE:
|
|
|
|
DBUG_PRINT("info", ("HA_EXTRA_WRITE_CANNOT_REPLACE"));
|
|
|
|
DBUG_PRINT("info", ("Turning OFF use of write instead of insert"));
|
|
|
|
m_use_write= FALSE;
|
|
|
|
break;
|
2005-07-18 13:31:02 +02:00
|
|
|
default:
|
|
|
|
break;
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
|
|
|
|
int ha_ndbcluster::reset()
|
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_ndbcluster::reset");
|
|
|
|
cond_clear();
|
|
|
|
/*
|
|
|
|
Regular partition pruning will set the bitmap appropriately.
|
|
|
|
Some queries like ALTER TABLE doesn't use partition pruning and
|
|
|
|
thus the 'used_partitions' bitmap needs to be initialized
|
|
|
|
*/
|
|
|
|
if (m_part_info)
|
|
|
|
bitmap_set_all(&m_part_info->used_partitions);
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-04-29 14:38:35 +02:00
|
|
|
/*
|
|
|
|
Start of an insert, remember number of rows to be inserted, it will
|
|
|
|
be used in write_row and get_autoincrement to send an optimal number
|
|
|
|
of rows in each roundtrip to the server
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
rows number of rows to insert, 0 if unknown
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ha_ndbcluster::start_bulk_insert(ha_rows rows)
|
|
|
|
{
|
|
|
|
int bytes, batch;
|
2006-05-04 13:58:17 +02:00
|
|
|
const NDBTAB *tab= m_table;
|
2004-04-29 14:38:35 +02:00
|
|
|
|
|
|
|
DBUG_ENTER("start_bulk_insert");
|
2004-07-22 12:38:09 +02:00
|
|
|
DBUG_PRINT("enter", ("rows: %d", (int)rows));
|
2004-04-29 14:38:35 +02:00
|
|
|
|
2005-04-13 12:42:23 +02:00
|
|
|
m_rows_inserted= (ha_rows) 0;
|
2006-06-14 20:25:51 +02:00
|
|
|
if (!m_use_write && m_ignore_dup_key)
|
2006-06-14 20:16:32 +02:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
compare if expression with that in write_row
|
2006-06-14 20:25:51 +02:00
|
|
|
we have a situation where peek_indexed_rows() will be called
|
2006-06-14 20:16:32 +02:00
|
|
|
so we cannot batch
|
|
|
|
*/
|
|
|
|
DBUG_PRINT("info", ("Batching turned off as duplicate key is "
|
|
|
|
"ignored by using peek_row"));
|
|
|
|
m_rows_to_insert= 1;
|
|
|
|
m_bulk_insert_rows= 1;
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
2005-04-13 12:42:23 +02:00
|
|
|
if (rows == (ha_rows) 0)
|
2005-05-07 22:04:52 +02:00
|
|
|
{
|
2005-04-07 17:44:09 +02:00
|
|
|
/* We don't know how many will be inserted, guess */
|
|
|
|
m_rows_to_insert= m_autoincrement_prefetch;
|
2005-05-07 22:04:52 +02:00
|
|
|
}
|
2005-04-07 17:44:09 +02:00
|
|
|
else
|
|
|
|
m_rows_to_insert= rows;
|
2004-04-29 14:38:35 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
Calculate how many rows that should be inserted
|
|
|
|
per roundtrip to NDB. This is done in order to minimize the
|
|
|
|
number of roundtrips as much as possible. However performance will
|
|
|
|
degrade if too many bytes are inserted, thus it's limited by this
|
|
|
|
calculation.
|
|
|
|
*/
|
2004-07-23 15:46:56 +02:00
|
|
|
const int bytesperbatch= 8192;
|
2004-04-29 14:38:35 +02:00
|
|
|
bytes= 12 + tab->getRowSizeInBytes() + 4 * tab->getNoOfColumns();
|
2004-05-10 14:46:06 +02:00
|
|
|
batch= bytesperbatch/bytes;
|
2004-04-29 14:38:35 +02:00
|
|
|
batch= batch == 0 ? 1 : batch;
|
|
|
|
DBUG_PRINT("info", ("batch: %d, bytes: %d", batch, bytes));
|
2004-11-03 15:53:26 +01:00
|
|
|
m_bulk_insert_rows= batch;
|
2004-04-29 14:38:35 +02:00
|
|
|
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
End of an insert
|
|
|
|
*/
|
|
|
|
int ha_ndbcluster::end_bulk_insert()
|
|
|
|
{
|
2004-07-23 15:46:56 +02:00
|
|
|
int error= 0;
|
|
|
|
|
2004-04-29 14:38:35 +02:00
|
|
|
DBUG_ENTER("end_bulk_insert");
|
2004-07-23 15:46:56 +02:00
|
|
|
// Check if last inserts need to be flushed
|
2004-11-03 15:53:26 +01:00
|
|
|
if (m_bulk_insert_not_flushed)
|
2004-07-23 15:46:56 +02:00
|
|
|
{
|
2005-01-04 13:47:16 +01:00
|
|
|
NdbTransaction *trans= m_active_trans;
|
2004-07-23 15:46:56 +02:00
|
|
|
// Send rows to NDB
|
|
|
|
DBUG_PRINT("info", ("Sending inserts to NDB, "\
|
|
|
|
"rows_inserted:%d, bulk_insert_rows: %d",
|
2005-04-13 12:42:23 +02:00
|
|
|
(int) m_rows_inserted, (int) m_bulk_insert_rows));
|
2004-11-03 15:53:26 +01:00
|
|
|
m_bulk_insert_not_flushed= FALSE;
|
2006-02-07 11:47:04 +01:00
|
|
|
if (m_transaction_on)
|
|
|
|
{
|
2006-08-07 14:48:54 +02:00
|
|
|
if (execute_no_commit(this, trans,false) != 0)
|
2006-02-07 11:47:04 +01:00
|
|
|
{
|
|
|
|
no_uncommitted_rows_execute_failure();
|
|
|
|
my_errno= error= ndb_err(trans);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (execute_commit(this, trans) != 0)
|
|
|
|
{
|
|
|
|
no_uncommitted_rows_execute_failure();
|
|
|
|
my_errno= error= ndb_err(trans);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int res= trans->restart();
|
|
|
|
DBUG_ASSERT(res == 0);
|
|
|
|
}
|
2004-09-14 17:51:57 +02:00
|
|
|
}
|
2004-07-23 15:46:56 +02:00
|
|
|
}
|
|
|
|
|
2005-04-13 12:42:23 +02:00
|
|
|
m_rows_inserted= (ha_rows) 0;
|
|
|
|
m_rows_to_insert= (ha_rows) 1;
|
2004-07-23 15:46:56 +02:00
|
|
|
DBUG_RETURN(error);
|
2004-04-29 14:38:35 +02:00
|
|
|
}
|
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
|
|
|
|
int ha_ndbcluster::extra_opt(enum ha_extra_function operation, ulong cache_size)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("extra_opt");
|
2004-07-22 12:38:09 +02:00
|
|
|
DBUG_PRINT("enter", ("cache_size: %lu", cache_size));
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_RETURN(extra(operation));
|
|
|
|
}
|
|
|
|
|
2005-04-27 11:25:08 +02:00
|
|
|
static const char *ha_ndbcluster_exts[] = {
|
|
|
|
ha_ndb_ext,
|
|
|
|
NullS
|
|
|
|
};
|
2004-04-15 09:14:14 +02:00
|
|
|
|
2005-03-21 12:29:08 +01:00
|
|
|
const char** ha_ndbcluster::bas_ext() const
|
2005-04-27 11:25:08 +02:00
|
|
|
{
|
|
|
|
return ha_ndbcluster_exts;
|
|
|
|
}
|
2004-04-15 09:14:14 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
How many seeks it will take to read through the table
|
|
|
|
This is to be comparable to the number returned by records_in_range so
|
|
|
|
that we can decide if we should scan the table or use keys.
|
|
|
|
*/
|
|
|
|
|
|
|
|
double ha_ndbcluster::scan_time()
|
|
|
|
{
|
2004-09-03 13:55:40 +02:00
|
|
|
DBUG_ENTER("ha_ndbcluster::scan_time()");
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
double res= rows2double(stats.records*1000);
|
2004-09-03 13:55:40 +02:00
|
|
|
DBUG_PRINT("exit", ("table: %s value: %f",
|
2005-02-16 14:18:32 +01:00
|
|
|
m_tabname, res));
|
2004-09-03 13:55:40 +02:00
|
|
|
DBUG_RETURN(res);
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
|
2005-06-20 17:16:22 +02:00
|
|
|
/*
|
|
|
|
Convert MySQL table locks into locks supported by Ndb Cluster.
|
|
|
|
Note that MySQL Cluster does currently not support distributed
|
|
|
|
table locks, so to be safe one should set cluster in Single
|
|
|
|
User Mode, before relying on table locks when updating tables
|
|
|
|
from several MySQL servers
|
|
|
|
*/
|
2004-04-15 09:14:14 +02:00
|
|
|
|
|
|
|
THR_LOCK_DATA **ha_ndbcluster::store_lock(THD *thd,
|
|
|
|
THR_LOCK_DATA **to,
|
|
|
|
enum thr_lock_type lock_type)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("store_lock");
|
|
|
|
if (lock_type != TL_IGNORE && m_lock.type == TL_UNLOCK)
|
|
|
|
{
|
2004-09-28 21:11:50 +02:00
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
/* If we are not doing a LOCK TABLE, then allow multiple
|
|
|
|
writers */
|
|
|
|
|
2004-10-13 10:08:18 +02:00
|
|
|
/* Since NDB does not currently have table locks
|
|
|
|
this is treated as a ordinary lock */
|
|
|
|
|
2005-06-09 13:28:29 +02:00
|
|
|
if ((lock_type >= TL_WRITE_CONCURRENT_INSERT &&
|
2004-04-15 09:14:14 +02:00
|
|
|
lock_type <= TL_WRITE) && !thd->in_lock_tables)
|
|
|
|
lock_type= TL_WRITE_ALLOW_WRITE;
|
|
|
|
|
|
|
|
/* In queries of type INSERT INTO t1 SELECT ... FROM t2 ...
|
|
|
|
MySQL would use the lock TL_READ_NO_INSERT on t2, and that
|
|
|
|
would conflict with TL_WRITE_ALLOW_WRITE, blocking all inserts
|
|
|
|
to t2. Convert the lock to a normal read lock to allow
|
|
|
|
concurrent inserts to t2. */
|
|
|
|
|
|
|
|
if (lock_type == TL_READ_NO_INSERT && !thd->in_lock_tables)
|
|
|
|
lock_type= TL_READ;
|
|
|
|
|
|
|
|
m_lock.type=lock_type;
|
|
|
|
}
|
|
|
|
*to++= &m_lock;
|
2004-05-10 14:12:28 +02:00
|
|
|
|
|
|
|
DBUG_PRINT("exit", ("lock_type: %d", lock_type));
|
2004-04-15 09:14:14 +02:00
|
|
|
|
|
|
|
DBUG_RETURN(to);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef DBUG_OFF
|
|
|
|
#define PRINT_OPTION_FLAGS(t) { \
|
|
|
|
if (t->options & OPTION_NOT_AUTOCOMMIT) \
|
|
|
|
DBUG_PRINT("thd->options", ("OPTION_NOT_AUTOCOMMIT")); \
|
|
|
|
if (t->options & OPTION_BEGIN) \
|
|
|
|
DBUG_PRINT("thd->options", ("OPTION_BEGIN")); \
|
|
|
|
if (t->options & OPTION_TABLE_LOCK) \
|
|
|
|
DBUG_PRINT("thd->options", ("OPTION_TABLE_LOCK")); \
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define PRINT_OPTION_FLAGS(t)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
As MySQL will execute an external lock for every new table it uses
|
|
|
|
we can use this to start the transactions.
|
|
|
|
If we are in auto_commit mode we just need to start a transaction
|
2005-02-17 22:52:40 +01:00
|
|
|
for the statement, this will be stored in thd_ndb.stmt.
|
2004-04-15 09:14:14 +02:00
|
|
|
If not, we have to start a master transaction if there doesn't exist
|
2005-02-17 22:52:40 +01:00
|
|
|
one from before, this will be stored in thd_ndb.all
|
2004-04-15 09:14:14 +02:00
|
|
|
|
|
|
|
When a table lock is held one transaction will be started which holds
|
|
|
|
the table lock and for each statement a hupp transaction will be started
|
2005-03-22 17:48:28 +01:00
|
|
|
If we are locking the table then:
|
2005-03-22 17:42:08 +01:00
|
|
|
- save the NdbDictionary::Table for easy access
|
2005-03-22 17:48:28 +01:00
|
|
|
- save reference to table statistics
|
|
|
|
- refresh list of the indexes for the table if needed (if altered)
|
2004-04-15 09:14:14 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
int ha_ndbcluster::external_lock(THD *thd, int lock_type)
|
|
|
|
{
|
|
|
|
int error=0;
|
2005-01-04 13:47:16 +01:00
|
|
|
NdbTransaction* trans= NULL;
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_ENTER("external_lock");
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
/*
|
|
|
|
Check that this handler instance has a connection
|
|
|
|
set up to the Ndb object of thd
|
|
|
|
*/
|
2005-03-15 15:03:25 +01:00
|
|
|
if (check_ndb_connection(thd))
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_RETURN(1);
|
2005-03-15 15:03:25 +01:00
|
|
|
|
2005-02-17 22:52:40 +01:00
|
|
|
Thd_ndb *thd_ndb= get_thd_ndb(thd);
|
2004-12-30 19:56:09 +01:00
|
|
|
Ndb *ndb= thd_ndb->ndb;
|
2004-09-14 10:52:21 +02:00
|
|
|
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
DBUG_PRINT("enter", ("this: 0x%lx thd: 0x%lx thd_ndb: %lx "
|
2005-11-06 00:20:37 +01:00
|
|
|
"thd_ndb->lock_count: %d",
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
(long) this, (long) thd, (long) thd_ndb,
|
|
|
|
thd_ndb->lock_count));
|
2004-09-14 10:52:21 +02:00
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
if (lock_type != F_UNLCK)
|
|
|
|
{
|
2004-05-24 12:35:39 +02:00
|
|
|
DBUG_PRINT("info", ("lock_type != F_UNLCK"));
|
2006-09-05 16:52:05 +02:00
|
|
|
if (thd->lex->sql_command == SQLCOM_LOAD)
|
|
|
|
{
|
|
|
|
m_transaction_on= FALSE;
|
|
|
|
/* Would be simpler if has_transactions() didn't always say "yes" */
|
|
|
|
thd->options|= OPTION_STATUS_NO_TRANS_UPDATE;
|
|
|
|
thd->no_trans_update= TRUE;
|
|
|
|
}
|
|
|
|
else if (!thd->transaction.on)
|
2005-12-10 00:00:33 +01:00
|
|
|
m_transaction_on= FALSE;
|
|
|
|
else
|
|
|
|
m_transaction_on= thd->variables.ndb_use_transactions;
|
2004-09-14 10:52:21 +02:00
|
|
|
if (!thd_ndb->lock_count++)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
|
|
|
PRINT_OPTION_FLAGS(thd);
|
2005-10-14 11:23:02 +02:00
|
|
|
if (!(thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)))
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
|
|
|
// Autocommit transaction
|
2005-02-17 22:52:40 +01:00
|
|
|
DBUG_ASSERT(!thd_ndb->stmt);
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_PRINT("trans",("Starting transaction stmt"));
|
|
|
|
|
2004-12-30 19:56:09 +01:00
|
|
|
trans= ndb->startTransaction();
|
2004-04-15 09:14:14 +02:00
|
|
|
if (trans == NULL)
|
2004-12-30 19:56:09 +01:00
|
|
|
ERR_RETURN(ndb->getNdbError());
|
2006-04-19 18:29:25 +02:00
|
|
|
thd_ndb->init_open_tables();
|
2005-02-17 22:52:40 +01:00
|
|
|
thd_ndb->stmt= trans;
|
2006-08-07 14:48:54 +02:00
|
|
|
thd_ndb->query_state&= NDB_QUERY_NORMAL;
|
2006-09-15 19:28:00 +02:00
|
|
|
trans_register_ha(thd, FALSE, ndbcluster_hton);
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-02-17 22:52:40 +01:00
|
|
|
if (!thd_ndb->all)
|
2005-02-16 14:18:32 +01:00
|
|
|
{
|
2004-04-15 09:14:14 +02:00
|
|
|
// Not autocommit transaction
|
|
|
|
// A "master" transaction ha not been started yet
|
|
|
|
DBUG_PRINT("trans",("starting transaction, all"));
|
|
|
|
|
2004-12-30 19:56:09 +01:00
|
|
|
trans= ndb->startTransaction();
|
2004-04-15 09:14:14 +02:00
|
|
|
if (trans == NULL)
|
2004-12-30 19:56:09 +01:00
|
|
|
ERR_RETURN(ndb->getNdbError());
|
2006-04-19 18:29:25 +02:00
|
|
|
thd_ndb->init_open_tables();
|
2005-02-17 22:52:40 +01:00
|
|
|
thd_ndb->all= trans;
|
2006-08-07 14:48:54 +02:00
|
|
|
thd_ndb->query_state&= NDB_QUERY_NORMAL;
|
2006-09-15 19:28:00 +02:00
|
|
|
trans_register_ha(thd, TRUE, ndbcluster_hton);
|
2004-04-15 09:14:14 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
If this is the start of a LOCK TABLE, a table look
|
|
|
|
should be taken on the table in NDB
|
|
|
|
|
|
|
|
Check if it should be read or write lock
|
|
|
|
*/
|
|
|
|
if (thd->options & (OPTION_TABLE_LOCK))
|
2005-02-16 14:18:32 +01:00
|
|
|
{
|
2004-04-15 09:14:14 +02:00
|
|
|
//lockThisTable();
|
|
|
|
DBUG_PRINT("info", ("Locking the table..." ));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
This is the place to make sure this handler instance
|
|
|
|
has a started transaction.
|
|
|
|
|
|
|
|
The transaction is started by the first handler on which
|
|
|
|
MySQL Server calls external lock
|
|
|
|
|
|
|
|
Other handlers in the same stmt or transaction should use
|
|
|
|
the same NDB transaction. This is done by setting up the m_active_trans
|
|
|
|
pointer to point to the NDB transaction.
|
|
|
|
*/
|
|
|
|
|
2004-11-17 09:15:53 +01:00
|
|
|
// store thread specific data first to set the right context
|
|
|
|
m_force_send= thd->variables.ndb_force_send;
|
|
|
|
m_ha_not_exact_count= !thd->variables.ndb_use_exact_count;
|
2005-04-13 12:42:23 +02:00
|
|
|
m_autoincrement_prefetch=
|
|
|
|
(ha_rows) thd->variables.ndb_autoincrement_prefetch_sz;
|
2004-11-17 09:15:53 +01:00
|
|
|
|
2005-02-17 22:52:40 +01:00
|
|
|
m_active_trans= thd_ndb->all ? thd_ndb->all : thd_ndb->stmt;
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_ASSERT(m_active_trans);
|
2004-05-10 14:12:28 +02:00
|
|
|
// Start of transaction
|
2005-03-15 15:03:25 +01:00
|
|
|
m_rows_changed= 0;
|
|
|
|
m_ops_pending= 0;
|
2006-05-04 13:58:17 +02:00
|
|
|
|
|
|
|
// TODO remove double pointers...
|
2006-04-19 18:29:25 +02:00
|
|
|
m_thd_ndb_share= thd_ndb->get_open_table(thd, m_table);
|
|
|
|
m_table_info= &m_thd_ndb_share->stat;
|
2005-03-15 15:03:25 +01:00
|
|
|
}
|
|
|
|
else
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
2004-05-24 12:35:39 +02:00
|
|
|
DBUG_PRINT("info", ("lock_type == F_UNLCK"));
|
2005-03-15 15:03:25 +01:00
|
|
|
|
|
|
|
if (ndb_cache_check_time && m_rows_changed)
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("Rows has changed and util thread is running"));
|
|
|
|
if (thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("Add share to list of tables to be invalidated"));
|
|
|
|
/* NOTE push_back allocates memory using transactions mem_root! */
|
|
|
|
thd_ndb->changed_tables.push_back(m_share, &thd->transaction.mem_root);
|
|
|
|
}
|
|
|
|
|
|
|
|
pthread_mutex_lock(&m_share->mutex);
|
|
|
|
DBUG_PRINT("info", ("Invalidating commit_count"));
|
|
|
|
m_share->commit_count= 0;
|
|
|
|
m_share->commit_count_lock++;
|
|
|
|
pthread_mutex_unlock(&m_share->mutex);
|
|
|
|
}
|
|
|
|
|
2004-09-14 10:52:21 +02:00
|
|
|
if (!--thd_ndb->lock_count)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
|
|
|
DBUG_PRINT("trans", ("Last external_lock"));
|
|
|
|
PRINT_OPTION_FLAGS(thd);
|
|
|
|
|
2005-02-17 22:52:40 +01:00
|
|
|
if (thd_ndb->stmt)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
Unlock is done without a transaction commit / rollback.
|
|
|
|
This happens if the thread didn't update any rows
|
|
|
|
We must in this case close the transaction to release resources
|
|
|
|
*/
|
|
|
|
DBUG_PRINT("trans",("ending non-updating transaction"));
|
2004-12-30 19:56:09 +01:00
|
|
|
ndb->closeTransaction(m_active_trans);
|
2005-02-17 22:52:40 +01:00
|
|
|
thd_ndb->stmt= NULL;
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
}
|
2004-09-21 14:52:56 +02:00
|
|
|
m_table_info= NULL;
|
2005-03-15 15:03:25 +01:00
|
|
|
|
2004-09-13 14:46:38 +02:00
|
|
|
/*
|
|
|
|
This is the place to make sure this handler instance
|
|
|
|
no longer are connected to the active transaction.
|
|
|
|
|
|
|
|
And since the handler is no longer part of the transaction
|
|
|
|
it can't have open cursors, ops or blobs pending.
|
|
|
|
*/
|
|
|
|
m_active_trans= NULL;
|
|
|
|
|
2004-09-07 12:54:31 +02:00
|
|
|
if (m_active_cursor)
|
|
|
|
DBUG_PRINT("warning", ("m_active_cursor != NULL"));
|
2004-09-13 14:46:38 +02:00
|
|
|
m_active_cursor= NULL;
|
|
|
|
|
2004-12-08 00:36:40 +01:00
|
|
|
if (m_multi_cursor)
|
|
|
|
DBUG_PRINT("warning", ("m_multi_cursor != NULL"));
|
|
|
|
m_multi_cursor= NULL;
|
|
|
|
|
2004-11-03 15:53:26 +01:00
|
|
|
if (m_blobs_pending)
|
2004-09-07 12:54:31 +02:00
|
|
|
DBUG_PRINT("warning", ("blobs_pending != 0"));
|
2004-11-03 15:53:26 +01:00
|
|
|
m_blobs_pending= 0;
|
2004-09-13 14:46:38 +02:00
|
|
|
|
2004-11-03 15:53:26 +01:00
|
|
|
if (m_ops_pending)
|
2004-09-07 12:54:31 +02:00
|
|
|
DBUG_PRINT("warning", ("ops_pending != 0L"));
|
2004-11-03 15:53:26 +01:00
|
|
|
m_ops_pending= 0;
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
2006-06-22 21:44:21 +02:00
|
|
|
thd->set_current_stmt_binlog_row_based_if_mixed();
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_RETURN(error);
|
|
|
|
}
|
|
|
|
|
2006-06-12 14:23:21 +02:00
|
|
|
/*
|
|
|
|
Unlock the last row read in an open scan.
|
|
|
|
Rows are unlocked by default in ndb, but
|
|
|
|
for SELECT FOR UPDATE and SELECT LOCK WIT SHARE MODE
|
|
|
|
locks are kept if unlock_row() is not called.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ha_ndbcluster::unlock_row()
|
|
|
|
{
|
|
|
|
DBUG_ENTER("unlock_row");
|
|
|
|
|
|
|
|
DBUG_PRINT("info", ("Unlocking row"));
|
|
|
|
m_lock_tuple= false;
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
/*
|
2005-10-14 11:23:02 +02:00
|
|
|
Start a transaction for running a statement if one is not
|
|
|
|
already running in a transaction. This will be the case in
|
|
|
|
a BEGIN; COMMIT; block
|
|
|
|
When using LOCK TABLE's external_lock will start a transaction
|
|
|
|
since ndb does not currently does not support table locking
|
2004-04-15 09:14:14 +02:00
|
|
|
*/
|
|
|
|
|
2005-09-30 20:20:10 +02:00
|
|
|
int ha_ndbcluster::start_stmt(THD *thd, thr_lock_type lock_type)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
|
|
|
int error=0;
|
|
|
|
DBUG_ENTER("start_stmt");
|
|
|
|
PRINT_OPTION_FLAGS(thd);
|
|
|
|
|
2005-02-17 22:52:40 +01:00
|
|
|
Thd_ndb *thd_ndb= get_thd_ndb(thd);
|
2005-10-14 11:28:01 +02:00
|
|
|
NdbTransaction *trans= (thd_ndb->stmt)?thd_ndb->stmt:thd_ndb->all;
|
2004-04-15 09:14:14 +02:00
|
|
|
if (!trans){
|
2005-02-17 22:52:40 +01:00
|
|
|
Ndb *ndb= thd_ndb->ndb;
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_PRINT("trans",("Starting transaction stmt"));
|
2004-12-30 19:56:09 +01:00
|
|
|
trans= ndb->startTransaction();
|
2004-04-15 09:14:14 +02:00
|
|
|
if (trans == NULL)
|
2004-12-30 19:56:09 +01:00
|
|
|
ERR_RETURN(ndb->getNdbError());
|
2004-09-14 10:52:21 +02:00
|
|
|
no_uncommitted_rows_reset(thd);
|
2005-02-17 22:52:40 +01:00
|
|
|
thd_ndb->stmt= trans;
|
2006-09-15 19:28:00 +02:00
|
|
|
trans_register_ha(thd, FALSE, ndbcluster_hton);
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
2006-08-07 14:48:54 +02:00
|
|
|
thd_ndb->query_state&= NDB_QUERY_NORMAL;
|
2004-04-15 09:14:14 +02:00
|
|
|
m_active_trans= trans;
|
2004-05-05 16:04:23 +02:00
|
|
|
|
2004-05-10 14:12:28 +02:00
|
|
|
// Start of statement
|
2004-11-03 15:53:26 +01:00
|
|
|
m_ops_pending= 0;
|
2006-06-22 21:44:21 +02:00
|
|
|
thd->set_current_stmt_binlog_row_based_if_mixed();
|
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_RETURN(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2005-03-15 15:03:25 +01:00
|
|
|
Commit a transaction started in NDB
|
2004-04-15 09:14:14 +02:00
|
|
|
*/
|
|
|
|
|
2006-09-30 21:49:46 +02:00
|
|
|
static int ndbcluster_commit(handlerton *hton, THD *thd, bool all)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
|
|
|
int res= 0;
|
2005-02-17 22:52:40 +01:00
|
|
|
Thd_ndb *thd_ndb= get_thd_ndb(thd);
|
|
|
|
Ndb *ndb= thd_ndb->ndb;
|
|
|
|
NdbTransaction *trans= all ? thd_ndb->all : thd_ndb->stmt;
|
2004-04-15 09:14:14 +02:00
|
|
|
|
|
|
|
DBUG_ENTER("ndbcluster_commit");
|
|
|
|
DBUG_PRINT("transaction",("%s",
|
2005-03-15 15:03:25 +01:00
|
|
|
trans == thd_ndb->stmt ?
|
2004-04-15 09:14:14 +02:00
|
|
|
"stmt" : "all"));
|
|
|
|
DBUG_ASSERT(ndb && trans);
|
|
|
|
|
2004-11-17 09:15:53 +01:00
|
|
|
if (execute_commit(thd,trans) != 0)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
|
|
|
const NdbError err= trans->getNdbError();
|
2004-07-02 16:14:08 +02:00
|
|
|
const NdbOperation *error_op= trans->getNdbErrorOperation();
|
2005-03-15 15:03:25 +01:00
|
|
|
ERR_PRINT(err);
|
2004-04-15 09:14:14 +02:00
|
|
|
res= ndb_to_mysql_error(&err);
|
2005-03-15 15:03:25 +01:00
|
|
|
if (res != -1)
|
2004-07-02 16:14:08 +02:00
|
|
|
ndbcluster_print_error(res, error_op);
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
2004-09-14 10:52:21 +02:00
|
|
|
ndb->closeTransaction(trans);
|
2005-03-15 15:03:25 +01:00
|
|
|
|
2005-07-04 02:42:33 +02:00
|
|
|
if (all)
|
2005-02-21 10:53:19 +01:00
|
|
|
thd_ndb->all= NULL;
|
|
|
|
else
|
|
|
|
thd_ndb->stmt= NULL;
|
2005-03-15 15:03:25 +01:00
|
|
|
|
|
|
|
/* Clear commit_count for tables changed by transaction */
|
|
|
|
NDB_SHARE* share;
|
|
|
|
List_iterator_fast<NDB_SHARE> it(thd_ndb->changed_tables);
|
|
|
|
while ((share= it++))
|
|
|
|
{
|
|
|
|
pthread_mutex_lock(&share->mutex);
|
2005-11-06 00:20:37 +01:00
|
|
|
DBUG_PRINT("info", ("Invalidate commit_count for %s, share->commit_count: %d ",
|
|
|
|
share->key, share->commit_count));
|
2005-03-15 15:03:25 +01:00
|
|
|
share->commit_count= 0;
|
|
|
|
share->commit_count_lock++;
|
|
|
|
pthread_mutex_unlock(&share->mutex);
|
|
|
|
}
|
|
|
|
thd_ndb->changed_tables.empty();
|
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_RETURN(res);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Rollback a transaction started in NDB
|
|
|
|
*/
|
|
|
|
|
2006-09-30 21:49:46 +02:00
|
|
|
static int ndbcluster_rollback(handlerton *hton, THD *thd, bool all)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
|
|
|
int res= 0;
|
2005-02-17 22:52:40 +01:00
|
|
|
Thd_ndb *thd_ndb= get_thd_ndb(thd);
|
|
|
|
Ndb *ndb= thd_ndb->ndb;
|
|
|
|
NdbTransaction *trans= all ? thd_ndb->all : thd_ndb->stmt;
|
2004-04-15 09:14:14 +02:00
|
|
|
|
|
|
|
DBUG_ENTER("ndbcluster_rollback");
|
|
|
|
DBUG_PRINT("transaction",("%s",
|
2005-02-17 22:52:40 +01:00
|
|
|
trans == thd_ndb->stmt ?
|
2004-04-15 09:14:14 +02:00
|
|
|
"stmt" : "all"));
|
|
|
|
DBUG_ASSERT(ndb && trans);
|
|
|
|
|
2005-01-05 17:59:24 +01:00
|
|
|
if (trans->execute(NdbTransaction::Rollback) != 0)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
|
|
|
const NdbError err= trans->getNdbError();
|
2004-07-02 16:14:08 +02:00
|
|
|
const NdbOperation *error_op= trans->getNdbErrorOperation();
|
2004-04-15 09:14:14 +02:00
|
|
|
ERR_PRINT(err);
|
|
|
|
res= ndb_to_mysql_error(&err);
|
2004-07-02 16:14:08 +02:00
|
|
|
if (res != -1)
|
|
|
|
ndbcluster_print_error(res, error_op);
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
ndb->closeTransaction(trans);
|
2005-02-21 10:53:19 +01:00
|
|
|
|
2005-07-04 02:42:33 +02:00
|
|
|
if (all)
|
2005-02-21 10:53:19 +01:00
|
|
|
thd_ndb->all= NULL;
|
|
|
|
else
|
|
|
|
thd_ndb->stmt= NULL;
|
|
|
|
|
2005-03-15 15:03:25 +01:00
|
|
|
/* Clear list of tables changed by transaction */
|
|
|
|
thd_ndb->changed_tables.empty();
|
|
|
|
|
2005-02-17 22:52:40 +01:00
|
|
|
DBUG_RETURN(res);
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2004-07-22 12:38:09 +02:00
|
|
|
Define NDB column based on Field.
|
|
|
|
Returns 0 or mysql error code.
|
|
|
|
Not member of ha_ndbcluster because NDBCOL cannot be declared.
|
2005-01-08 00:03:19 +01:00
|
|
|
|
|
|
|
MySQL text types with character set "binary" are mapped to true
|
|
|
|
NDB binary types without a character set. This may change.
|
2004-04-15 09:14:14 +02:00
|
|
|
*/
|
|
|
|
|
2004-07-22 12:38:09 +02:00
|
|
|
static int create_ndb_column(NDBCOL &col,
|
|
|
|
Field *field,
|
|
|
|
HA_CREATE_INFO *info)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
2004-07-22 12:38:09 +02:00
|
|
|
// Set name
|
2005-05-18 20:50:29 +02:00
|
|
|
col.setName(field->field_name);
|
2004-09-15 17:44:13 +02:00
|
|
|
// Get char set
|
|
|
|
CHARSET_INFO *cs= field->charset();
|
2004-07-22 12:38:09 +02:00
|
|
|
// Set type and sizes
|
|
|
|
const enum enum_field_types mysql_type= field->real_type();
|
|
|
|
switch (mysql_type) {
|
|
|
|
// Numeric types
|
2004-04-15 09:14:14 +02:00
|
|
|
case MYSQL_TYPE_TINY:
|
2004-07-22 12:38:09 +02:00
|
|
|
if (field->flags & UNSIGNED_FLAG)
|
|
|
|
col.setType(NDBCOL::Tinyunsigned);
|
|
|
|
else
|
|
|
|
col.setType(NDBCOL::Tinyint);
|
|
|
|
col.setLength(1);
|
|
|
|
break;
|
2004-04-15 09:14:14 +02:00
|
|
|
case MYSQL_TYPE_SHORT:
|
2004-07-22 12:38:09 +02:00
|
|
|
if (field->flags & UNSIGNED_FLAG)
|
|
|
|
col.setType(NDBCOL::Smallunsigned);
|
|
|
|
else
|
|
|
|
col.setType(NDBCOL::Smallint);
|
|
|
|
col.setLength(1);
|
|
|
|
break;
|
2004-04-15 09:14:14 +02:00
|
|
|
case MYSQL_TYPE_LONG:
|
2004-07-22 12:38:09 +02:00
|
|
|
if (field->flags & UNSIGNED_FLAG)
|
|
|
|
col.setType(NDBCOL::Unsigned);
|
|
|
|
else
|
|
|
|
col.setType(NDBCOL::Int);
|
|
|
|
col.setLength(1);
|
|
|
|
break;
|
2004-04-15 09:14:14 +02:00
|
|
|
case MYSQL_TYPE_INT24:
|
2004-07-22 12:38:09 +02:00
|
|
|
if (field->flags & UNSIGNED_FLAG)
|
|
|
|
col.setType(NDBCOL::Mediumunsigned);
|
|
|
|
else
|
|
|
|
col.setType(NDBCOL::Mediumint);
|
|
|
|
col.setLength(1);
|
|
|
|
break;
|
|
|
|
case MYSQL_TYPE_LONGLONG:
|
|
|
|
if (field->flags & UNSIGNED_FLAG)
|
|
|
|
col.setType(NDBCOL::Bigunsigned);
|
|
|
|
else
|
|
|
|
col.setType(NDBCOL::Bigint);
|
|
|
|
col.setLength(1);
|
2004-04-15 09:14:14 +02:00
|
|
|
break;
|
|
|
|
case MYSQL_TYPE_FLOAT:
|
2004-07-22 12:38:09 +02:00
|
|
|
col.setType(NDBCOL::Float);
|
|
|
|
col.setLength(1);
|
|
|
|
break;
|
2004-04-15 09:14:14 +02:00
|
|
|
case MYSQL_TYPE_DOUBLE:
|
2004-07-22 12:38:09 +02:00
|
|
|
col.setType(NDBCOL::Double);
|
|
|
|
col.setLength(1);
|
|
|
|
break;
|
2005-02-16 12:45:59 +01:00
|
|
|
case MYSQL_TYPE_DECIMAL:
|
|
|
|
{
|
|
|
|
Field_decimal *f= (Field_decimal*)field;
|
|
|
|
uint precision= f->pack_length();
|
|
|
|
uint scale= f->decimals();
|
|
|
|
if (field->flags & UNSIGNED_FLAG)
|
|
|
|
{
|
|
|
|
col.setType(NDBCOL::Olddecimalunsigned);
|
|
|
|
precision-= (scale > 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
col.setType(NDBCOL::Olddecimal);
|
|
|
|
precision-= 1 + (scale > 0);
|
|
|
|
}
|
|
|
|
col.setPrecision(precision);
|
|
|
|
col.setScale(scale);
|
|
|
|
col.setLength(1);
|
|
|
|
}
|
|
|
|
break;
|
2005-02-16 21:19:42 +01:00
|
|
|
case MYSQL_TYPE_NEWDECIMAL:
|
|
|
|
{
|
|
|
|
Field_new_decimal *f= (Field_new_decimal*)field;
|
2005-05-05 17:06:49 +02:00
|
|
|
uint precision= f->precision;
|
2005-02-16 21:19:42 +01:00
|
|
|
uint scale= f->decimals();
|
|
|
|
if (field->flags & UNSIGNED_FLAG)
|
|
|
|
{
|
|
|
|
col.setType(NDBCOL::Decimalunsigned);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
col.setType(NDBCOL::Decimal);
|
|
|
|
}
|
|
|
|
col.setPrecision(precision);
|
|
|
|
col.setScale(scale);
|
|
|
|
col.setLength(1);
|
|
|
|
}
|
|
|
|
break;
|
2004-07-22 12:38:09 +02:00
|
|
|
// Date types
|
|
|
|
case MYSQL_TYPE_DATETIME:
|
|
|
|
col.setType(NDBCOL::Datetime);
|
|
|
|
col.setLength(1);
|
|
|
|
break;
|
2005-01-27 17:33:35 +01:00
|
|
|
case MYSQL_TYPE_DATE: // ?
|
|
|
|
col.setType(NDBCOL::Char);
|
|
|
|
col.setLength(field->pack_length());
|
|
|
|
break;
|
2004-07-22 12:38:09 +02:00
|
|
|
case MYSQL_TYPE_NEWDATE:
|
2005-01-08 16:57:51 +01:00
|
|
|
col.setType(NDBCOL::Date);
|
|
|
|
col.setLength(1);
|
|
|
|
break;
|
2004-07-22 12:38:09 +02:00
|
|
|
case MYSQL_TYPE_TIME:
|
2005-01-08 19:28:44 +01:00
|
|
|
col.setType(NDBCOL::Time);
|
|
|
|
col.setLength(1);
|
|
|
|
break;
|
2005-01-27 17:33:35 +01:00
|
|
|
case MYSQL_TYPE_YEAR:
|
|
|
|
col.setType(NDBCOL::Year);
|
|
|
|
col.setLength(1);
|
|
|
|
break;
|
|
|
|
case MYSQL_TYPE_TIMESTAMP:
|
|
|
|
col.setType(NDBCOL::Timestamp);
|
|
|
|
col.setLength(1);
|
2004-07-22 12:38:09 +02:00
|
|
|
break;
|
|
|
|
// Char types
|
|
|
|
case MYSQL_TYPE_STRING:
|
2004-10-20 19:22:58 +02:00
|
|
|
if (field->pack_length() == 0)
|
2004-12-09 14:17:58 +01:00
|
|
|
{
|
|
|
|
col.setType(NDBCOL::Bit);
|
|
|
|
col.setLength(1);
|
|
|
|
}
|
2005-01-08 00:03:19 +01:00
|
|
|
else if ((field->flags & BINARY_FLAG) && cs == &my_charset_bin)
|
2004-12-10 16:55:04 +01:00
|
|
|
{
|
2004-07-22 12:38:09 +02:00
|
|
|
col.setType(NDBCOL::Binary);
|
2004-12-10 16:55:04 +01:00
|
|
|
col.setLength(field->pack_length());
|
2004-09-15 17:44:13 +02:00
|
|
|
}
|
2004-10-20 19:22:58 +02:00
|
|
|
else
|
2004-12-10 16:55:04 +01:00
|
|
|
{
|
|
|
|
col.setType(NDBCOL::Char);
|
|
|
|
col.setCharset(cs);
|
2004-10-20 19:22:58 +02:00
|
|
|
col.setLength(field->pack_length());
|
2004-12-10 16:55:04 +01:00
|
|
|
}
|
2004-07-22 12:38:09 +02:00
|
|
|
break;
|
2005-01-07 11:55:20 +01:00
|
|
|
case MYSQL_TYPE_VAR_STRING: // ?
|
|
|
|
case MYSQL_TYPE_VARCHAR:
|
|
|
|
{
|
|
|
|
Field_varstring* f= (Field_varstring*)field;
|
|
|
|
if (f->length_bytes == 1)
|
|
|
|
{
|
2005-01-08 00:03:19 +01:00
|
|
|
if ((field->flags & BINARY_FLAG) && cs == &my_charset_bin)
|
2005-01-07 11:55:20 +01:00
|
|
|
col.setType(NDBCOL::Varbinary);
|
|
|
|
else {
|
|
|
|
col.setType(NDBCOL::Varchar);
|
|
|
|
col.setCharset(cs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (f->length_bytes == 2)
|
|
|
|
{
|
2005-01-08 00:03:19 +01:00
|
|
|
if ((field->flags & BINARY_FLAG) && cs == &my_charset_bin)
|
2005-01-07 11:55:20 +01:00
|
|
|
col.setType(NDBCOL::Longvarbinary);
|
|
|
|
else {
|
|
|
|
col.setType(NDBCOL::Longvarchar);
|
|
|
|
col.setCharset(cs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return HA_ERR_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
col.setLength(field->field_length);
|
2004-09-15 17:44:13 +02:00
|
|
|
}
|
2004-07-22 12:38:09 +02:00
|
|
|
break;
|
|
|
|
// Blob types (all come in as MYSQL_TYPE_BLOB)
|
|
|
|
mysql_type_tiny_blob:
|
|
|
|
case MYSQL_TYPE_TINY_BLOB:
|
2005-01-08 00:03:19 +01:00
|
|
|
if ((field->flags & BINARY_FLAG) && cs == &my_charset_bin)
|
2004-07-22 12:38:09 +02:00
|
|
|
col.setType(NDBCOL::Blob);
|
2004-09-15 17:44:13 +02:00
|
|
|
else {
|
2004-07-22 12:38:09 +02:00
|
|
|
col.setType(NDBCOL::Text);
|
2004-09-15 17:44:13 +02:00
|
|
|
col.setCharset(cs);
|
|
|
|
}
|
2004-07-22 12:38:09 +02:00
|
|
|
col.setInlineSize(256);
|
|
|
|
// No parts
|
|
|
|
col.setPartSize(0);
|
|
|
|
col.setStripeSize(0);
|
|
|
|
break;
|
2004-11-29 13:50:13 +01:00
|
|
|
//mysql_type_blob:
|
2005-10-25 08:20:39 +02:00
|
|
|
case MYSQL_TYPE_GEOMETRY:
|
2004-07-22 12:38:09 +02:00
|
|
|
case MYSQL_TYPE_BLOB:
|
2005-01-08 00:03:19 +01:00
|
|
|
if ((field->flags & BINARY_FLAG) && cs == &my_charset_bin)
|
2004-07-22 12:38:09 +02:00
|
|
|
col.setType(NDBCOL::Blob);
|
2004-09-15 17:44:13 +02:00
|
|
|
else {
|
2004-07-22 12:38:09 +02:00
|
|
|
col.setType(NDBCOL::Text);
|
2004-09-15 17:44:13 +02:00
|
|
|
col.setCharset(cs);
|
|
|
|
}
|
2004-07-22 12:38:09 +02:00
|
|
|
// Use "<=" even if "<" is the exact condition
|
|
|
|
if (field->max_length() <= (1 << 8))
|
|
|
|
goto mysql_type_tiny_blob;
|
|
|
|
else if (field->max_length() <= (1 << 16))
|
|
|
|
{
|
|
|
|
col.setInlineSize(256);
|
|
|
|
col.setPartSize(2000);
|
|
|
|
col.setStripeSize(16);
|
|
|
|
}
|
|
|
|
else if (field->max_length() <= (1 << 24))
|
|
|
|
goto mysql_type_medium_blob;
|
|
|
|
else
|
|
|
|
goto mysql_type_long_blob;
|
|
|
|
break;
|
|
|
|
mysql_type_medium_blob:
|
|
|
|
case MYSQL_TYPE_MEDIUM_BLOB:
|
2005-01-08 00:03:19 +01:00
|
|
|
if ((field->flags & BINARY_FLAG) && cs == &my_charset_bin)
|
2004-07-22 12:38:09 +02:00
|
|
|
col.setType(NDBCOL::Blob);
|
2004-09-15 17:44:13 +02:00
|
|
|
else {
|
2004-07-22 12:38:09 +02:00
|
|
|
col.setType(NDBCOL::Text);
|
2004-09-15 17:44:13 +02:00
|
|
|
col.setCharset(cs);
|
|
|
|
}
|
2004-07-22 12:38:09 +02:00
|
|
|
col.setInlineSize(256);
|
|
|
|
col.setPartSize(4000);
|
|
|
|
col.setStripeSize(8);
|
|
|
|
break;
|
|
|
|
mysql_type_long_blob:
|
|
|
|
case MYSQL_TYPE_LONG_BLOB:
|
2005-01-08 00:03:19 +01:00
|
|
|
if ((field->flags & BINARY_FLAG) && cs == &my_charset_bin)
|
2004-07-22 12:38:09 +02:00
|
|
|
col.setType(NDBCOL::Blob);
|
2004-09-15 17:44:13 +02:00
|
|
|
else {
|
2004-07-22 12:38:09 +02:00
|
|
|
col.setType(NDBCOL::Text);
|
2004-09-15 17:44:13 +02:00
|
|
|
col.setCharset(cs);
|
|
|
|
}
|
2004-07-22 12:38:09 +02:00
|
|
|
col.setInlineSize(256);
|
|
|
|
col.setPartSize(8000);
|
|
|
|
col.setStripeSize(4);
|
|
|
|
break;
|
|
|
|
// Other types
|
|
|
|
case MYSQL_TYPE_ENUM:
|
|
|
|
col.setType(NDBCOL::Char);
|
|
|
|
col.setLength(field->pack_length());
|
|
|
|
break;
|
|
|
|
case MYSQL_TYPE_SET:
|
|
|
|
col.setType(NDBCOL::Char);
|
|
|
|
col.setLength(field->pack_length());
|
|
|
|
break;
|
2005-07-04 02:42:33 +02:00
|
|
|
case MYSQL_TYPE_BIT:
|
|
|
|
{
|
2006-04-05 02:54:58 +02:00
|
|
|
int no_of_bits= field->field_length;
|
2004-12-23 15:28:41 +01:00
|
|
|
col.setType(NDBCOL::Bit);
|
|
|
|
if (!no_of_bits)
|
|
|
|
col.setLength(1);
|
|
|
|
else
|
|
|
|
col.setLength(no_of_bits);
|
|
|
|
break;
|
|
|
|
}
|
2004-07-22 12:38:09 +02:00
|
|
|
case MYSQL_TYPE_NULL:
|
|
|
|
goto mysql_type_unsupported;
|
|
|
|
mysql_type_unsupported:
|
|
|
|
default:
|
|
|
|
return HA_ERR_UNSUPPORTED;
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
2004-07-22 12:38:09 +02:00
|
|
|
// Set nullable and pk
|
|
|
|
col.setNullable(field->maybe_null());
|
|
|
|
col.setPrimaryKey(field->flags & PRI_KEY_FLAG);
|
|
|
|
// Set autoincrement
|
|
|
|
if (field->flags & AUTO_INCREMENT_FLAG)
|
|
|
|
{
|
2006-06-30 18:15:18 +02:00
|
|
|
char buff[22];
|
2004-07-22 12:38:09 +02:00
|
|
|
col.setAutoIncrement(TRUE);
|
|
|
|
ulonglong value= info->auto_increment_value ?
|
2004-09-02 17:51:44 +02:00
|
|
|
info->auto_increment_value : (ulonglong) 1;
|
2006-06-30 18:15:18 +02:00
|
|
|
DBUG_PRINT("info", ("Autoincrement key, initial: %s", llstr(value, buff)));
|
2004-07-22 12:38:09 +02:00
|
|
|
col.setAutoIncrementInitialValue(value);
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
2004-07-22 12:38:09 +02:00
|
|
|
else
|
2004-10-14 17:03:46 +02:00
|
|
|
col.setAutoIncrement(FALSE);
|
2004-07-22 12:38:09 +02:00
|
|
|
return 0;
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
|
2005-11-06 00:20:37 +01:00
|
|
|
/*
|
|
|
|
Create a table in NDB Cluster
|
|
|
|
*/
|
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
int ha_ndbcluster::create(const char *name,
|
2005-02-16 14:18:32 +01:00
|
|
|
TABLE *form,
|
|
|
|
HA_CREATE_INFO *info)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
2006-06-14 12:21:18 +02:00
|
|
|
THD *thd= current_thd;
|
2004-04-15 09:14:14 +02:00
|
|
|
NDBTAB tab;
|
|
|
|
NDBCOL col;
|
2004-11-08 11:06:36 +01:00
|
|
|
uint pack_length, length, i, pk_length= 0;
|
2004-04-15 09:14:14 +02:00
|
|
|
const void *data, *pack_data;
|
2005-11-21 12:27:58 +01:00
|
|
|
bool create_from_engine= (info->table_options & HA_OPTION_CREATE_FROM_ENGINE);
|
2006-06-14 12:21:18 +02:00
|
|
|
bool is_truncate= (thd->lex->sql_command == SQLCOM_TRUNCATE);
|
2005-11-25 11:57:13 +01:00
|
|
|
|
2005-01-07 11:55:20 +01:00
|
|
|
DBUG_ENTER("ha_ndbcluster::create");
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_PRINT("enter", ("name: %s", name));
|
2005-11-23 21:45:02 +01:00
|
|
|
|
2006-02-16 03:23:43 +01:00
|
|
|
DBUG_ASSERT(*fn_rext((char*)name) == 0);
|
|
|
|
set_dbname(name);
|
|
|
|
set_tabname(name);
|
2004-09-13 14:46:38 +02:00
|
|
|
|
2006-06-12 14:23:21 +02:00
|
|
|
if (is_truncate)
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("Dropping and re-creating table for TRUNCATE"));
|
|
|
|
if ((my_errno= delete_table(name)))
|
|
|
|
DBUG_RETURN(my_errno);
|
|
|
|
}
|
2005-11-23 21:45:02 +01:00
|
|
|
table= form;
|
2004-09-13 14:46:38 +02:00
|
|
|
if (create_from_engine)
|
|
|
|
{
|
|
|
|
/*
|
2006-01-12 19:51:02 +01:00
|
|
|
Table already exists in NDB and frm file has been created by
|
2004-09-13 14:46:38 +02:00
|
|
|
caller.
|
|
|
|
Do Ndb specific stuff, such as create a .ndb file
|
|
|
|
*/
|
2006-01-17 08:40:00 +01:00
|
|
|
if ((my_errno= write_ndb_file(name)))
|
2005-11-06 00:20:37 +01:00
|
|
|
DBUG_RETURN(my_errno);
|
2006-01-12 19:51:02 +01:00
|
|
|
#ifdef HAVE_NDB_BINLOG
|
2006-02-16 03:23:43 +01:00
|
|
|
ndbcluster_create_binlog_setup(get_ndb(), name, strlen(name),
|
2006-01-31 15:40:26 +01:00
|
|
|
m_dbname, m_tabname, FALSE);
|
2006-01-12 19:51:02 +01:00
|
|
|
#endif /* HAVE_NDB_BINLOG */
|
2004-09-13 14:46:38 +02:00
|
|
|
DBUG_RETURN(my_errno);
|
|
|
|
}
|
2004-04-15 09:14:14 +02:00
|
|
|
|
2006-04-10 16:08:40 +02:00
|
|
|
#ifdef HAVE_NDB_BINLOG
|
|
|
|
/*
|
|
|
|
Don't allow table creation unless
|
|
|
|
schema distribution table is setup
|
|
|
|
( unless it is a creation of the schema dist table itself )
|
|
|
|
*/
|
|
|
|
if (!schema_share &&
|
|
|
|
!(strcmp(m_dbname, NDB_REP_DB) == 0 &&
|
|
|
|
strcmp(m_tabname, NDB_SCHEMA_TABLE) == 0))
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("Schema distribution table not setup"));
|
|
|
|
DBUG_RETURN(HA_ERR_NO_CONNECTION);
|
|
|
|
}
|
|
|
|
#endif /* HAVE_NDB_BINLOG */
|
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_PRINT("table", ("name: %s", m_tabname));
|
|
|
|
tab.setName(m_tabname);
|
|
|
|
tab.setLogging(!(info->options & HA_LEX_CREATE_TMP_TABLE));
|
|
|
|
|
|
|
|
// Save frm data for this table
|
|
|
|
if (readfrm(name, &data, &length))
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
if (packfrm(data, length, &pack_data, &pack_length))
|
2006-05-08 18:09:01 +02:00
|
|
|
{
|
|
|
|
my_free((char*)data, MYF(0));
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_RETURN(2);
|
2006-05-08 18:09:01 +02:00
|
|
|
}
|
|
|
|
|
2005-11-06 00:20:37 +01:00
|
|
|
DBUG_PRINT("info", ("setFrm data=%lx len=%d", pack_data, pack_length));
|
2004-04-15 09:14:14 +02:00
|
|
|
tab.setFrm(pack_data, pack_length);
|
|
|
|
my_free((char*)data, MYF(0));
|
|
|
|
my_free((char*)pack_data, MYF(0));
|
|
|
|
|
2005-01-06 12:00:13 +01:00
|
|
|
for (i= 0; i < form->s->fields; i++)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
|
|
|
Field *field= form->field[i];
|
|
|
|
DBUG_PRINT("info", ("name: %s, type: %u, pack_length: %d",
|
|
|
|
field->field_name, field->real_type(),
|
2005-02-16 14:18:32 +01:00
|
|
|
field->pack_length()));
|
2004-07-23 15:46:56 +02:00
|
|
|
if ((my_errno= create_ndb_column(col, field, info)))
|
2004-07-22 12:38:09 +02:00
|
|
|
DBUG_RETURN(my_errno);
|
2006-01-11 11:35:25 +01:00
|
|
|
|
|
|
|
if (info->store_on_disk || getenv("NDB_DEFAULT_DISK"))
|
2005-11-07 12:19:28 +01:00
|
|
|
col.setStorageType(NdbDictionary::Column::StorageTypeDisk);
|
|
|
|
else
|
|
|
|
col.setStorageType(NdbDictionary::Column::StorageTypeMemory);
|
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
tab.addColumn(col);
|
2005-07-04 02:42:33 +02:00
|
|
|
if (col.getPrimaryKey())
|
2004-11-08 11:06:36 +01:00
|
|
|
pk_length += (field->pack_length() + 3) / 4;
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
2005-11-07 12:19:28 +01:00
|
|
|
|
|
|
|
KEY* key_info;
|
|
|
|
for (i= 0, key_info= form->key_info; i < form->s->keys; i++, key_info++)
|
|
|
|
{
|
|
|
|
KEY_PART_INFO *key_part= key_info->key_part;
|
|
|
|
KEY_PART_INFO *end= key_part + key_info->key_parts;
|
|
|
|
for (; key_part != end; key_part++)
|
|
|
|
tab.getColumn(key_part->fieldnr-1)->setStorageType(
|
|
|
|
NdbDictionary::Column::StorageTypeMemory);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info->store_on_disk)
|
|
|
|
if (info->tablespace)
|
|
|
|
tab.setTablespace(info->tablespace);
|
|
|
|
else
|
|
|
|
tab.setTablespace("DEFAULT-TS");
|
2004-04-15 09:14:14 +02:00
|
|
|
// No primary key, create shadow key as 64 bit, auto increment
|
2005-01-06 12:00:13 +01:00
|
|
|
if (form->s->primary_key == MAX_KEY)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("Generating shadow key"));
|
|
|
|
col.setName("$PK");
|
|
|
|
col.setType(NdbDictionary::Column::Bigunsigned);
|
|
|
|
col.setLength(1);
|
2004-10-14 17:03:46 +02:00
|
|
|
col.setNullable(FALSE);
|
2004-04-15 09:14:14 +02:00
|
|
|
col.setPrimaryKey(TRUE);
|
|
|
|
col.setAutoIncrement(TRUE);
|
|
|
|
tab.addColumn(col);
|
2004-11-08 11:06:36 +01:00
|
|
|
pk_length += 2;
|
|
|
|
}
|
2006-01-17 09:25:12 +01:00
|
|
|
|
2004-11-08 11:06:36 +01:00
|
|
|
// Make sure that blob tables don't have to big part size
|
2005-01-06 12:00:13 +01:00
|
|
|
for (i= 0; i < form->s->fields; i++)
|
2004-11-08 11:06:36 +01:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The extra +7 concists
|
|
|
|
* 2 - words from pk in blob table
|
|
|
|
* 5 - from extra words added by tup/dict??
|
|
|
|
*/
|
|
|
|
switch (form->field[i]->real_type()) {
|
2005-10-25 08:20:39 +02:00
|
|
|
case MYSQL_TYPE_GEOMETRY:
|
2004-11-08 11:06:36 +01:00
|
|
|
case MYSQL_TYPE_BLOB:
|
|
|
|
case MYSQL_TYPE_MEDIUM_BLOB:
|
|
|
|
case MYSQL_TYPE_LONG_BLOB:
|
|
|
|
{
|
2004-12-07 15:15:49 +01:00
|
|
|
NdbDictionary::Column * col= tab.getColumn(i);
|
|
|
|
int size= pk_length + (col->getPartSize()+3)/4 + 7;
|
2005-07-04 02:42:33 +02:00
|
|
|
if (size > NDB_MAX_TUPLE_SIZE_IN_WORDS &&
|
2005-02-16 14:18:32 +01:00
|
|
|
(pk_length+7) < NDB_MAX_TUPLE_SIZE_IN_WORDS)
|
2004-11-08 11:06:36 +01:00
|
|
|
{
|
2005-02-16 14:18:32 +01:00
|
|
|
size= NDB_MAX_TUPLE_SIZE_IN_WORDS - pk_length - 7;
|
|
|
|
col->setPartSize(4*size);
|
2004-11-08 11:06:36 +01:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* If size > NDB_MAX and pk_length+7 >= NDB_MAX
|
|
|
|
* then the table can't be created anyway, so skip
|
|
|
|
* changing part size, and have error later
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
2005-02-11 22:33:52 +01:00
|
|
|
|
2005-07-18 13:31:02 +02:00
|
|
|
// Check partition info
|
2005-11-23 21:45:02 +01:00
|
|
|
partition_info *part_info= form->part_info;
|
2006-01-17 08:40:00 +01:00
|
|
|
if ((my_errno= set_up_partition_info(part_info, form, (void*)&tab)))
|
2005-07-18 13:31:02 +02:00
|
|
|
{
|
2006-01-17 08:40:00 +01:00
|
|
|
DBUG_RETURN(my_errno);
|
2005-07-18 13:31:02 +02:00
|
|
|
}
|
|
|
|
|
2004-09-13 14:46:38 +02:00
|
|
|
if ((my_errno= check_ndb_connection()))
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_RETURN(my_errno);
|
|
|
|
|
|
|
|
// Create the table in NDB
|
2004-12-30 19:56:09 +01:00
|
|
|
Ndb *ndb= get_ndb();
|
|
|
|
NDBDICT *dict= ndb->getDictionary();
|
2004-09-13 14:46:38 +02:00
|
|
|
if (dict->createTable(tab) != 0)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
|
|
|
const NdbError err= dict->getNdbError();
|
|
|
|
ERR_PRINT(err);
|
|
|
|
my_errno= ndb_to_mysql_error(&err);
|
|
|
|
DBUG_RETURN(my_errno);
|
|
|
|
}
|
2006-05-04 13:58:17 +02:00
|
|
|
|
|
|
|
Ndb_table_guard ndbtab_g(dict, m_tabname);
|
|
|
|
// temporary set m_table during create
|
|
|
|
// reset at return
|
|
|
|
m_table= ndbtab_g.get_table();
|
|
|
|
// TODO check also that we have the same frm...
|
2006-06-29 22:22:55 +02:00
|
|
|
if (!m_table)
|
|
|
|
{
|
|
|
|
/* purecov: begin deadcode */
|
|
|
|
const NdbError err= dict->getNdbError();
|
|
|
|
ERR_PRINT(err);
|
|
|
|
my_errno= ndb_to_mysql_error(&err);
|
|
|
|
DBUG_RETURN(my_errno);
|
|
|
|
/* purecov: end */
|
|
|
|
}
|
2006-05-04 13:58:17 +02:00
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_PRINT("info", ("Table %s/%s created successfully",
|
|
|
|
m_dbname, m_tabname));
|
2004-04-30 12:25:31 +02:00
|
|
|
|
2004-08-19 11:10:35 +02:00
|
|
|
// Create secondary indexes
|
2006-01-11 12:35:28 +01:00
|
|
|
my_errno= create_indexes(ndb, form);
|
2004-08-18 19:13:39 +02:00
|
|
|
|
2004-09-13 14:46:38 +02:00
|
|
|
if (!my_errno)
|
2006-01-17 08:40:00 +01:00
|
|
|
my_errno= write_ndb_file(name);
|
2006-01-11 12:35:28 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Failed to create an index,
|
|
|
|
drop the table (and all it's indexes)
|
|
|
|
*/
|
2006-06-14 12:21:18 +02:00
|
|
|
while (dict->dropTableGlobal(*m_table))
|
2006-05-04 13:58:17 +02:00
|
|
|
{
|
2006-06-14 12:21:18 +02:00
|
|
|
switch (dict->getNdbError().status)
|
|
|
|
{
|
|
|
|
case NdbError::TemporaryError:
|
|
|
|
if (!thd->killed)
|
|
|
|
continue; // retry indefinitly
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2006-06-14 13:32:29 +02:00
|
|
|
break;
|
2006-05-04 13:58:17 +02:00
|
|
|
}
|
2006-06-14 12:21:18 +02:00
|
|
|
m_table = 0;
|
|
|
|
DBUG_RETURN(my_errno);
|
2006-01-11 12:35:28 +01:00
|
|
|
}
|
2004-09-13 14:46:38 +02:00
|
|
|
|
2006-01-12 19:51:02 +01:00
|
|
|
#ifdef HAVE_NDB_BINLOG
|
|
|
|
if (!my_errno)
|
|
|
|
{
|
|
|
|
NDB_SHARE *share= 0;
|
|
|
|
pthread_mutex_lock(&ndbcluster_mutex);
|
|
|
|
/*
|
|
|
|
First make sure we get a "fresh" share here, not an old trailing one...
|
|
|
|
*/
|
|
|
|
{
|
2006-02-16 03:23:43 +01:00
|
|
|
uint length= (uint) strlen(name);
|
2006-01-12 19:51:02 +01:00
|
|
|
if ((share= (NDB_SHARE*) hash_search(&ndbcluster_open_tables,
|
2006-02-16 03:23:43 +01:00
|
|
|
(byte*) name, length)))
|
2006-01-12 19:51:02 +01:00
|
|
|
handle_trailing_share(share);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
get a new share
|
|
|
|
*/
|
2006-02-16 03:23:43 +01:00
|
|
|
|
|
|
|
if (!(share= get_share(name, form, true, true)))
|
2006-01-12 19:51:02 +01:00
|
|
|
{
|
2006-02-16 03:23:43 +01:00
|
|
|
sql_print_error("NDB: allocating table share for %s failed", name);
|
2006-01-12 19:51:02 +01:00
|
|
|
/* my_errno is set */
|
|
|
|
}
|
|
|
|
pthread_mutex_unlock(&ndbcluster_mutex);
|
|
|
|
|
|
|
|
while (!IS_TMP_PREFIX(m_tabname))
|
|
|
|
{
|
|
|
|
String event_name(INJECTOR_EVENT_LEN);
|
|
|
|
ndb_rep_event_name(&event_name,m_dbname,m_tabname);
|
2006-02-16 00:30:56 +01:00
|
|
|
int do_event_op= ndb_binlog_running;
|
|
|
|
|
|
|
|
if (!schema_share &&
|
|
|
|
strcmp(share->db, NDB_REP_DB) == 0 &&
|
|
|
|
strcmp(share->table_name, NDB_SCHEMA_TABLE) == 0)
|
|
|
|
do_event_op= 1;
|
2006-01-12 19:51:02 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
Always create an event for the table, as other mysql servers
|
|
|
|
expect it to be there.
|
|
|
|
*/
|
2006-05-04 13:58:17 +02:00
|
|
|
if (!ndbcluster_create_event(ndb, m_table, event_name.c_ptr(), share,
|
2006-07-08 03:26:13 +02:00
|
|
|
share && do_event_op ? 2 : 1/* push warning */))
|
2006-01-12 19:51:02 +01:00
|
|
|
{
|
2006-02-20 12:36:10 +01:00
|
|
|
if (ndb_extra_logging)
|
|
|
|
sql_print_information("NDB Binlog: CREATE TABLE Event: %s",
|
|
|
|
event_name.c_ptr());
|
|
|
|
if (share && do_event_op &&
|
2006-05-04 13:58:17 +02:00
|
|
|
ndbcluster_create_event_ops(share, m_table, event_name.c_ptr()))
|
2006-02-20 12:36:10 +01:00
|
|
|
{
|
|
|
|
sql_print_error("NDB Binlog: FAILED CREATE TABLE event operations."
|
|
|
|
" Event: %s", name);
|
|
|
|
/* a warning has been issued to the client */
|
|
|
|
}
|
2006-01-12 19:51:02 +01:00
|
|
|
}
|
2006-02-20 12:36:10 +01:00
|
|
|
/*
|
|
|
|
warning has been issued if ndbcluster_create_event failed
|
|
|
|
and (share && do_event_op)
|
|
|
|
*/
|
2006-02-16 00:30:56 +01:00
|
|
|
if (share && !do_event_op)
|
2006-01-31 15:40:26 +01:00
|
|
|
share->flags|= NSF_NO_BINLOG;
|
2006-06-14 12:21:18 +02:00
|
|
|
ndbcluster_log_schema_op(thd, share,
|
|
|
|
thd->query, thd->query_length,
|
2006-01-12 19:51:02 +01:00
|
|
|
share->db, share->table_name,
|
2006-05-04 13:58:17 +02:00
|
|
|
m_table->getObjectId(),
|
|
|
|
m_table->getObjectVersion(),
|
2006-06-12 14:23:21 +02:00
|
|
|
(is_truncate) ?
|
|
|
|
SOT_TRUNCATE_TABLE : SOT_CREATE_TABLE,
|
|
|
|
0, 0, 1);
|
2006-01-12 19:51:02 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* HAVE_NDB_BINLOG */
|
|
|
|
|
2006-05-04 13:58:17 +02:00
|
|
|
m_table= 0;
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_RETURN(my_errno);
|
|
|
|
}
|
|
|
|
|
2006-02-01 10:06:07 +01:00
|
|
|
int ha_ndbcluster::create_handler_files(const char *file,
|
|
|
|
const char *old_name,
|
2006-04-20 03:22:35 +02:00
|
|
|
int action_flag,
|
|
|
|
HA_CREATE_INFO *info)
|
2006-01-17 12:53:49 +01:00
|
|
|
{
|
2006-04-11 14:06:32 +02:00
|
|
|
char path[FN_REFLEN];
|
2006-01-17 12:53:49 +01:00
|
|
|
const char *name;
|
|
|
|
Ndb* ndb;
|
|
|
|
const NDBTAB *tab;
|
|
|
|
const void *data, *pack_data;
|
|
|
|
uint length, pack_length;
|
|
|
|
int error= 0;
|
|
|
|
|
|
|
|
DBUG_ENTER("create_handler_files");
|
|
|
|
|
2006-04-20 03:43:30 +02:00
|
|
|
if (action_flag != CHF_INDEX_FLAG)
|
2006-02-01 10:06:07 +01:00
|
|
|
{
|
|
|
|
DBUG_RETURN(FALSE);
|
|
|
|
}
|
2006-04-11 14:06:32 +02:00
|
|
|
DBUG_PRINT("enter", ("file: %s", file));
|
2006-01-17 12:53:49 +01:00
|
|
|
if (!(ndb= get_ndb()))
|
|
|
|
DBUG_RETURN(HA_ERR_NO_CONNECTION);
|
|
|
|
|
|
|
|
NDBDICT *dict= ndb->getDictionary();
|
2006-04-11 14:06:32 +02:00
|
|
|
if (!info->frm_only)
|
2006-01-17 12:53:49 +01:00
|
|
|
DBUG_RETURN(0); // Must be a create, ignore since frm is saved in create
|
2006-05-04 13:58:17 +02:00
|
|
|
|
|
|
|
// TODO handle this
|
|
|
|
DBUG_ASSERT(m_table != 0);
|
|
|
|
|
2006-04-11 14:06:32 +02:00
|
|
|
set_dbname(file);
|
|
|
|
set_tabname(file);
|
2006-05-04 13:58:17 +02:00
|
|
|
Ndb_table_guard ndbtab_g(dict, m_tabname);
|
2006-04-11 14:06:32 +02:00
|
|
|
DBUG_PRINT("info", ("m_dbname: %s, m_tabname: %s", m_dbname, m_tabname));
|
2006-05-04 13:58:17 +02:00
|
|
|
if (!(tab= ndbtab_g.get_table()))
|
2006-04-11 14:06:32 +02:00
|
|
|
DBUG_RETURN(0); // Unkown table, must be temporary table
|
|
|
|
|
2006-02-01 10:21:48 +01:00
|
|
|
DBUG_ASSERT(get_ndb_share_state(m_share) == NSS_ALTERED);
|
2006-04-11 14:06:32 +02:00
|
|
|
if (readfrm(file, &data, &length) ||
|
2006-01-17 12:53:49 +01:00
|
|
|
packfrm(data, length, &pack_data, &pack_length))
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("Missing frm for %s", m_tabname));
|
|
|
|
my_free((char*)data, MYF(MY_ALLOW_ZERO_PTR));
|
|
|
|
my_free((char*)pack_data, MYF(MY_ALLOW_ZERO_PTR));
|
2006-01-27 17:23:14 +01:00
|
|
|
error= 1;
|
2006-01-17 12:53:49 +01:00
|
|
|
}
|
2006-01-27 17:23:14 +01:00
|
|
|
else
|
|
|
|
{
|
2006-01-17 12:53:49 +01:00
|
|
|
DBUG_PRINT("info", ("Table %s has changed, altering frm in ndb",
|
|
|
|
m_tabname));
|
2006-05-04 13:58:17 +02:00
|
|
|
NdbDictionary::Table new_tab= *tab;
|
|
|
|
new_tab.setFrm(pack_data, pack_length);
|
|
|
|
if (dict->alterTableGlobal(*tab, new_tab))
|
|
|
|
{
|
|
|
|
error= ndb_to_mysql_error(&dict->getNdbError());
|
|
|
|
}
|
2006-01-27 17:23:14 +01:00
|
|
|
my_free((char*)data, MYF(MY_ALLOW_ZERO_PTR));
|
|
|
|
my_free((char*)pack_data, MYF(MY_ALLOW_ZERO_PTR));
|
2006-01-17 12:53:49 +01:00
|
|
|
}
|
2006-04-11 14:06:32 +02:00
|
|
|
|
2006-02-01 10:21:48 +01:00
|
|
|
set_ndb_share_state(m_share, NSS_INITIAL);
|
2006-01-27 17:23:14 +01:00
|
|
|
free_share(&m_share); // Decrease ref_count
|
2006-01-17 12:53:49 +01:00
|
|
|
|
|
|
|
DBUG_RETURN(error);
|
|
|
|
}
|
|
|
|
|
2006-01-11 12:35:28 +01:00
|
|
|
int ha_ndbcluster::create_index(const char *name, KEY *key_info,
|
|
|
|
NDB_INDEX_TYPE idx_type, uint idx_no)
|
|
|
|
{
|
|
|
|
int error= 0;
|
|
|
|
char unique_name[FN_LEN];
|
|
|
|
static const char* unique_suffix= "$unique";
|
|
|
|
DBUG_ENTER("ha_ndbcluster::create_ordered_index");
|
|
|
|
DBUG_PRINT("info", ("Creating index %u: %s", idx_no, name));
|
|
|
|
|
|
|
|
if (idx_type == UNIQUE_ORDERED_INDEX || idx_type == UNIQUE_INDEX)
|
|
|
|
{
|
|
|
|
strxnmov(unique_name, FN_LEN, name, unique_suffix, NullS);
|
|
|
|
DBUG_PRINT("info", ("Created unique index name \'%s\' for index %d",
|
|
|
|
unique_name, idx_no));
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (idx_type){
|
|
|
|
case PRIMARY_KEY_INDEX:
|
|
|
|
// Do nothing, already created
|
|
|
|
break;
|
|
|
|
case PRIMARY_KEY_ORDERED_INDEX:
|
|
|
|
error= create_ordered_index(name, key_info);
|
|
|
|
break;
|
|
|
|
case UNIQUE_ORDERED_INDEX:
|
|
|
|
if (!(error= create_ordered_index(name, key_info)))
|
|
|
|
error= create_unique_index(unique_name, key_info);
|
|
|
|
break;
|
|
|
|
case UNIQUE_INDEX:
|
|
|
|
if (!(error= check_index_fields_not_null(idx_no)))
|
|
|
|
error= create_unique_index(unique_name, key_info);
|
|
|
|
break;
|
|
|
|
case ORDERED_INDEX:
|
|
|
|
error= create_ordered_index(name, key_info);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
DBUG_ASSERT(FALSE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
DBUG_RETURN(error);
|
|
|
|
}
|
2004-04-15 09:14:14 +02:00
|
|
|
|
2004-04-30 12:25:31 +02:00
|
|
|
int ha_ndbcluster::create_ordered_index(const char *name,
|
2005-02-16 14:18:32 +01:00
|
|
|
KEY *key_info)
|
2004-04-30 12:25:31 +02:00
|
|
|
{
|
2004-12-20 15:12:42 +01:00
|
|
|
DBUG_ENTER("ha_ndbcluster::create_ordered_index");
|
2006-01-11 12:35:28 +01:00
|
|
|
DBUG_RETURN(create_ndb_index(name, key_info, FALSE));
|
2004-04-30 12:25:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int ha_ndbcluster::create_unique_index(const char *name,
|
2005-02-16 14:18:32 +01:00
|
|
|
KEY *key_info)
|
2004-04-30 12:25:31 +02:00
|
|
|
{
|
|
|
|
|
2004-12-20 15:12:42 +01:00
|
|
|
DBUG_ENTER("ha_ndbcluster::create_unique_index");
|
2006-01-11 12:35:28 +01:00
|
|
|
DBUG_RETURN(create_ndb_index(name, key_info, TRUE));
|
2004-04-30 12:25:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
/*
|
|
|
|
Create an index in NDB Cluster
|
|
|
|
*/
|
|
|
|
|
2006-01-11 12:35:28 +01:00
|
|
|
int ha_ndbcluster::create_ndb_index(const char *name,
|
|
|
|
KEY *key_info,
|
|
|
|
bool unique)
|
2004-04-30 12:25:31 +02:00
|
|
|
{
|
2004-12-30 19:56:09 +01:00
|
|
|
Ndb *ndb= get_ndb();
|
|
|
|
NdbDictionary::Dictionary *dict= ndb->getDictionary();
|
2004-04-15 09:14:14 +02:00
|
|
|
KEY_PART_INFO *key_part= key_info->key_part;
|
|
|
|
KEY_PART_INFO *end= key_part + key_info->key_parts;
|
|
|
|
|
2004-12-20 15:12:42 +01:00
|
|
|
DBUG_ENTER("ha_ndbcluster::create_index");
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_PRINT("enter", ("name: %s ", name));
|
2004-04-30 12:25:31 +02:00
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
NdbDictionary::Index ndb_index(name);
|
2004-04-30 12:25:31 +02:00
|
|
|
if (unique)
|
2004-04-15 09:14:14 +02:00
|
|
|
ndb_index.setType(NdbDictionary::Index::UniqueHashIndex);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ndb_index.setType(NdbDictionary::Index::OrderedIndex);
|
|
|
|
// TODO Only temporary ordered indexes supported
|
2004-10-14 17:03:46 +02:00
|
|
|
ndb_index.setLogging(FALSE);
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
ndb_index.setTable(m_tabname);
|
|
|
|
|
|
|
|
for (; key_part != end; key_part++)
|
|
|
|
{
|
|
|
|
Field *field= key_part->field;
|
|
|
|
DBUG_PRINT("info", ("attr: %s", field->field_name));
|
2005-05-18 20:50:29 +02:00
|
|
|
ndb_index.addColumnName(field->field_name);
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
|
2006-05-04 13:58:17 +02:00
|
|
|
if (dict->createIndex(ndb_index, *m_table))
|
2004-04-15 09:14:14 +02:00
|
|
|
ERR_RETURN(dict->getNdbError());
|
|
|
|
|
|
|
|
// Success
|
|
|
|
DBUG_PRINT("info", ("Created index %s", name));
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
2006-04-11 14:06:32 +02:00
|
|
|
/*
|
|
|
|
Prepare for an on-line alter table
|
|
|
|
*/
|
|
|
|
void ha_ndbcluster::prepare_for_alter()
|
|
|
|
{
|
|
|
|
ndbcluster_get_share(m_share); // Increase ref_count
|
|
|
|
set_ndb_share_state(m_share, NSS_ALTERED);
|
|
|
|
}
|
|
|
|
|
2006-01-13 11:51:30 +01:00
|
|
|
/*
|
|
|
|
Add an index on-line to a table
|
|
|
|
*/
|
|
|
|
int ha_ndbcluster::add_index(TABLE *table_arg,
|
|
|
|
KEY *key_info, uint num_of_keys)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_ndbcluster::add_index");
|
|
|
|
DBUG_PRINT("info", ("ha_ndbcluster::add_index to table %s",
|
|
|
|
table_arg->s->table_name));
|
|
|
|
int error= 0;
|
|
|
|
uint idx;
|
|
|
|
|
2006-04-11 14:06:32 +02:00
|
|
|
DBUG_ASSERT(m_share->state == NSS_ALTERED);
|
2006-01-13 11:51:30 +01:00
|
|
|
for (idx= 0; idx < num_of_keys; idx++)
|
|
|
|
{
|
|
|
|
KEY *key= key_info + idx;
|
|
|
|
KEY_PART_INFO *key_part= key->key_part;
|
|
|
|
KEY_PART_INFO *end= key_part + key->key_parts;
|
2006-03-09 13:41:11 +01:00
|
|
|
NDB_INDEX_TYPE idx_type= get_index_type_from_key(idx, key, false);
|
2006-01-13 11:51:30 +01:00
|
|
|
DBUG_PRINT("info", ("Adding index: '%s'", key_info[idx].name));
|
|
|
|
// Add fields to key_part struct
|
|
|
|
for (; key_part != end; key_part++)
|
|
|
|
key_part->field= table->field[key_part->fieldnr];
|
|
|
|
// Check index type
|
|
|
|
// Create index in ndb
|
|
|
|
if((error= create_index(key_info[idx].name, key, idx_type, idx)))
|
|
|
|
break;
|
|
|
|
}
|
2006-04-11 14:06:32 +02:00
|
|
|
if (error)
|
2006-01-27 17:23:14 +01:00
|
|
|
{
|
2006-04-11 14:06:32 +02:00
|
|
|
set_ndb_share_state(m_share, NSS_INITIAL);
|
|
|
|
free_share(&m_share); // Decrease ref_count
|
2006-01-27 17:23:14 +01:00
|
|
|
}
|
2006-01-13 11:51:30 +01:00
|
|
|
DBUG_RETURN(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Mark one or several indexes for deletion. and
|
|
|
|
renumber the remaining indexes
|
|
|
|
*/
|
|
|
|
int ha_ndbcluster::prepare_drop_index(TABLE *table_arg,
|
|
|
|
uint *key_num, uint num_of_keys)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_ndbcluster::prepare_drop_index");
|
2006-04-11 14:06:32 +02:00
|
|
|
DBUG_ASSERT(m_share->state == NSS_ALTERED);
|
2006-01-13 11:51:30 +01:00
|
|
|
// Mark indexes for deletion
|
|
|
|
uint idx;
|
|
|
|
for (idx= 0; idx < num_of_keys; idx++)
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("ha_ndbcluster::prepare_drop_index %u", *key_num));
|
|
|
|
m_index[*key_num++].status= TO_BE_DROPPED;
|
|
|
|
}
|
|
|
|
// Renumber indexes
|
|
|
|
THD *thd= current_thd;
|
|
|
|
Thd_ndb *thd_ndb= get_thd_ndb(thd);
|
|
|
|
Ndb *ndb= thd_ndb->ndb;
|
2006-01-27 17:23:14 +01:00
|
|
|
renumber_indexes(ndb, table_arg);
|
|
|
|
DBUG_RETURN(0);
|
2006-01-13 11:51:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Really drop all indexes marked for deletion
|
|
|
|
*/
|
|
|
|
int ha_ndbcluster::final_drop_index(TABLE *table_arg)
|
|
|
|
{
|
2006-01-27 17:23:14 +01:00
|
|
|
int error;
|
2006-01-13 11:51:30 +01:00
|
|
|
DBUG_ENTER("ha_ndbcluster::final_drop_index");
|
|
|
|
DBUG_PRINT("info", ("ha_ndbcluster::final_drop_index"));
|
|
|
|
// Really drop indexes
|
|
|
|
THD *thd= current_thd;
|
|
|
|
Thd_ndb *thd_ndb= get_thd_ndb(thd);
|
|
|
|
Ndb *ndb= thd_ndb->ndb;
|
2006-01-27 17:23:14 +01:00
|
|
|
if((error= drop_indexes(ndb, table_arg)))
|
|
|
|
{
|
|
|
|
m_share->state= NSS_INITIAL;
|
|
|
|
free_share(&m_share); // Decrease ref_count
|
|
|
|
}
|
|
|
|
DBUG_RETURN(error);
|
2006-01-13 11:51:30 +01:00
|
|
|
}
|
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
/*
|
|
|
|
Rename a table in NDB Cluster
|
|
|
|
*/
|
|
|
|
|
|
|
|
int ha_ndbcluster::rename_table(const char *from, const char *to)
|
|
|
|
{
|
2004-12-06 14:51:10 +01:00
|
|
|
NDBDICT *dict;
|
2006-03-01 18:23:00 +01:00
|
|
|
char old_dbname[FN_HEADLEN];
|
2006-05-31 10:28:42 +02:00
|
|
|
char new_dbname[FN_HEADLEN];
|
2004-04-15 09:14:14 +02:00
|
|
|
char new_tabname[FN_HEADLEN];
|
2004-12-06 14:51:10 +01:00
|
|
|
const NDBTAB *orig_tab;
|
|
|
|
int result;
|
2006-05-31 10:28:42 +02:00
|
|
|
bool recreate_indexes= FALSE;
|
|
|
|
NDBDICT::List index_list;
|
2004-04-15 09:14:14 +02:00
|
|
|
|
|
|
|
DBUG_ENTER("ha_ndbcluster::rename_table");
|
2004-12-06 14:51:10 +01:00
|
|
|
DBUG_PRINT("info", ("Renaming %s to %s", from, to));
|
2006-03-01 18:23:00 +01:00
|
|
|
set_dbname(from, old_dbname);
|
2006-05-31 10:28:42 +02:00
|
|
|
set_dbname(to, new_dbname);
|
2004-04-15 09:14:14 +02:00
|
|
|
set_tabname(from);
|
|
|
|
set_tabname(to, new_tabname);
|
|
|
|
|
2004-09-13 14:46:38 +02:00
|
|
|
if (check_ndb_connection())
|
|
|
|
DBUG_RETURN(my_errno= HA_ERR_NO_CONNECTION);
|
|
|
|
|
2005-01-03 11:56:51 +01:00
|
|
|
Ndb *ndb= get_ndb();
|
2006-03-01 18:23:00 +01:00
|
|
|
ndb->setDatabaseName(old_dbname);
|
2005-01-03 11:56:51 +01:00
|
|
|
dict= ndb->getDictionary();
|
2006-05-04 13:58:17 +02:00
|
|
|
Ndb_table_guard ndbtab_g(dict, m_tabname);
|
|
|
|
if (!(orig_tab= ndbtab_g.get_table()))
|
2004-12-06 14:51:10 +01:00
|
|
|
ERR_RETURN(dict->getNdbError());
|
2006-05-04 13:58:17 +02:00
|
|
|
|
2006-01-12 19:51:02 +01:00
|
|
|
#ifdef HAVE_NDB_BINLOG
|
2006-05-04 13:58:17 +02:00
|
|
|
int ndb_table_id= orig_tab->getObjectId();
|
|
|
|
int ndb_table_version= orig_tab->getObjectVersion();
|
|
|
|
|
2006-02-16 00:30:56 +01:00
|
|
|
NDB_SHARE *share= get_share(from, 0, false);
|
|
|
|
if (share)
|
2006-01-12 19:51:02 +01:00
|
|
|
{
|
|
|
|
int r= rename_share(share, to);
|
|
|
|
DBUG_ASSERT(r == 0);
|
|
|
|
}
|
|
|
|
#endif
|
2006-05-31 10:28:42 +02:00
|
|
|
if (my_strcasecmp(system_charset_info, new_dbname, old_dbname))
|
|
|
|
{
|
|
|
|
dict->listIndexes(index_list, *orig_tab);
|
|
|
|
recreate_indexes= TRUE;
|
|
|
|
}
|
2004-12-06 14:51:10 +01:00
|
|
|
// Change current database to that of target table
|
|
|
|
set_dbname(to);
|
2005-01-03 11:56:51 +01:00
|
|
|
ndb->setDatabaseName(m_dbname);
|
2005-11-06 00:20:37 +01:00
|
|
|
|
2006-05-04 13:58:17 +02:00
|
|
|
NdbDictionary::Table new_tab= *orig_tab;
|
|
|
|
new_tab.setName(new_tabname);
|
|
|
|
if (dict->alterTableGlobal(*orig_tab, new_tab) != 0)
|
2005-11-06 00:20:37 +01:00
|
|
|
{
|
2006-05-04 13:58:17 +02:00
|
|
|
NdbError ndb_error= dict->getNdbError();
|
2006-01-12 19:51:02 +01:00
|
|
|
#ifdef HAVE_NDB_BINLOG
|
|
|
|
if (share)
|
|
|
|
{
|
|
|
|
int r= rename_share(share, from);
|
|
|
|
DBUG_ASSERT(r == 0);
|
|
|
|
free_share(&share);
|
|
|
|
}
|
|
|
|
#endif
|
2006-05-04 13:58:17 +02:00
|
|
|
ERR_RETURN(ndb_error);
|
2005-11-06 00:20:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Rename .ndb file
|
|
|
|
if ((result= handler::rename_table(from, to)))
|
2004-09-13 14:46:38 +02:00
|
|
|
{
|
2005-11-06 00:20:37 +01:00
|
|
|
// ToDo in 4.1 should rollback alter table...
|
2006-01-12 19:51:02 +01:00
|
|
|
#ifdef HAVE_NDB_BINLOG
|
|
|
|
if (share)
|
|
|
|
free_share(&share);
|
|
|
|
#endif
|
2005-11-06 00:20:37 +01:00
|
|
|
DBUG_RETURN(result);
|
2004-09-13 14:46:38 +02:00
|
|
|
}
|
2004-12-06 14:51:10 +01:00
|
|
|
|
2006-01-12 19:51:02 +01:00
|
|
|
#ifdef HAVE_NDB_BINLOG
|
|
|
|
int is_old_table_tmpfile= 1;
|
|
|
|
if (share && share->op)
|
|
|
|
dict->forceGCPWait();
|
|
|
|
|
|
|
|
/* handle old table */
|
|
|
|
if (!IS_TMP_PREFIX(m_tabname))
|
|
|
|
{
|
|
|
|
is_old_table_tmpfile= 0;
|
|
|
|
String event_name(INJECTOR_EVENT_LEN);
|
|
|
|
ndb_rep_event_name(&event_name, from + sizeof(share_prefix) - 1, 0);
|
2006-04-10 16:08:40 +02:00
|
|
|
ndbcluster_handle_drop_table(ndb, event_name.c_ptr(), share,
|
|
|
|
"rename table");
|
2006-01-12 19:51:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!result && !IS_TMP_PREFIX(new_tabname))
|
|
|
|
{
|
|
|
|
/* always create an event for the table */
|
|
|
|
String event_name(INJECTOR_EVENT_LEN);
|
|
|
|
ndb_rep_event_name(&event_name, to + sizeof(share_prefix) - 1, 0);
|
2006-05-04 13:58:17 +02:00
|
|
|
Ndb_table_guard ndbtab_g2(dict, new_tabname);
|
|
|
|
const NDBTAB *ndbtab= ndbtab_g2.get_table();
|
2006-01-12 19:51:02 +01:00
|
|
|
|
2006-02-20 12:36:10 +01:00
|
|
|
if (!ndbcluster_create_event(ndb, ndbtab, event_name.c_ptr(), share,
|
2006-07-08 03:26:13 +02:00
|
|
|
share && ndb_binlog_running ? 2 : 1/* push warning */))
|
2006-01-12 19:51:02 +01:00
|
|
|
{
|
|
|
|
if (ndb_extra_logging)
|
|
|
|
sql_print_information("NDB Binlog: RENAME Event: %s",
|
|
|
|
event_name.c_ptr());
|
2006-02-20 12:36:10 +01:00
|
|
|
if (share && ndb_binlog_running &&
|
|
|
|
ndbcluster_create_event_ops(share, ndbtab, event_name.c_ptr()))
|
2006-01-12 19:51:02 +01:00
|
|
|
{
|
2006-02-20 12:36:10 +01:00
|
|
|
sql_print_error("NDB Binlog: FAILED create event operations "
|
|
|
|
"during RENAME. Event %s", event_name.c_ptr());
|
|
|
|
/* a warning has been issued to the client */
|
2006-01-12 19:51:02 +01:00
|
|
|
}
|
|
|
|
}
|
2006-02-20 12:36:10 +01:00
|
|
|
/*
|
|
|
|
warning has been issued if ndbcluster_create_event failed
|
|
|
|
and (share && ndb_binlog_running)
|
|
|
|
*/
|
2006-02-06 11:47:12 +01:00
|
|
|
if (!is_old_table_tmpfile)
|
2006-01-12 19:51:02 +01:00
|
|
|
ndbcluster_log_schema_op(current_thd, share,
|
|
|
|
current_thd->query, current_thd->query_length,
|
2006-05-04 13:58:17 +02:00
|
|
|
old_dbname, m_tabname,
|
|
|
|
ndb_table_id, ndb_table_version,
|
2006-03-01 18:23:00 +01:00
|
|
|
SOT_RENAME_TABLE,
|
2006-05-31 01:52:14 +02:00
|
|
|
m_dbname, new_tabname, 1);
|
2006-01-12 19:51:02 +01:00
|
|
|
}
|
2006-05-31 10:28:42 +02:00
|
|
|
|
|
|
|
// If we are moving tables between databases, we need to recreate
|
|
|
|
// indexes
|
|
|
|
if (recreate_indexes)
|
|
|
|
{
|
|
|
|
for (unsigned i = 0; i < index_list.count; i++)
|
|
|
|
{
|
|
|
|
NDBDICT::List::Element& index_el = index_list.elements[i];
|
|
|
|
// Recreate any indexes not stored in the system database
|
|
|
|
if (my_strcasecmp(system_charset_info,
|
|
|
|
index_el.database, NDB_SYSTEM_DATABASE))
|
|
|
|
{
|
|
|
|
set_dbname(from);
|
|
|
|
ndb->setDatabaseName(m_dbname);
|
|
|
|
const NDBINDEX * index= dict->getIndexGlobal(index_el.name, new_tab);
|
|
|
|
DBUG_PRINT("info", ("Creating index %s/%s",
|
|
|
|
index_el.database, index->getName()));
|
|
|
|
dict->createIndex(*index, new_tab);
|
|
|
|
DBUG_PRINT("info", ("Dropping index %s/%s",
|
|
|
|
index_el.database, index->getName()));
|
|
|
|
set_dbname(from);
|
|
|
|
ndb->setDatabaseName(m_dbname);
|
|
|
|
dict->dropIndexGlobal(*index);
|
|
|
|
}
|
|
|
|
}
|
2006-01-12 19:51:02 +01:00
|
|
|
}
|
|
|
|
if (share)
|
|
|
|
free_share(&share);
|
|
|
|
#endif
|
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_RETURN(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2005-02-17 14:22:44 +01:00
|
|
|
Delete table from NDB Cluster
|
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
*/
|
|
|
|
|
2005-11-06 00:20:37 +01:00
|
|
|
/* static version which does not need a handler */
|
|
|
|
|
|
|
|
int
|
|
|
|
ha_ndbcluster::delete_table(ha_ndbcluster *h, Ndb *ndb,
|
|
|
|
const char *path,
|
|
|
|
const char *db,
|
|
|
|
const char *table_name)
|
|
|
|
{
|
2006-05-31 16:16:03 +02:00
|
|
|
THD *thd= current_thd;
|
2005-11-06 00:20:37 +01:00
|
|
|
DBUG_ENTER("ha_ndbcluster::ndbcluster_delete_table");
|
|
|
|
NDBDICT *dict= ndb->getDictionary();
|
2006-05-04 13:58:17 +02:00
|
|
|
int ndb_table_id= 0;
|
|
|
|
int ndb_table_version= 0;
|
2006-06-14 12:21:18 +02:00
|
|
|
#ifdef HAVE_NDB_BINLOG
|
2006-04-10 16:08:40 +02:00
|
|
|
/*
|
|
|
|
Don't allow drop table unless
|
|
|
|
schema distribution table is setup
|
|
|
|
*/
|
|
|
|
if (!schema_share)
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("Schema distribution table not setup"));
|
|
|
|
DBUG_RETURN(HA_ERR_NO_CONNECTION);
|
|
|
|
}
|
2006-01-12 19:51:02 +01:00
|
|
|
NDB_SHARE *share= get_share(path, 0, false);
|
|
|
|
#endif
|
2005-11-06 00:20:37 +01:00
|
|
|
|
|
|
|
/* Drop the table from NDB */
|
|
|
|
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
int res= 0;
|
2006-05-04 13:58:17 +02:00
|
|
|
if (h && h->m_table)
|
2005-11-06 00:20:37 +01:00
|
|
|
{
|
2006-06-14 12:21:18 +02:00
|
|
|
retry_temporary_error1:
|
|
|
|
if (dict->dropTableGlobal(*h->m_table) == 0)
|
2006-05-04 13:58:17 +02:00
|
|
|
{
|
|
|
|
ndb_table_id= h->m_table->getObjectId();
|
|
|
|
ndb_table_version= h->m_table->getObjectVersion();
|
|
|
|
}
|
2006-06-14 12:21:18 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (dict->getNdbError().status)
|
|
|
|
{
|
|
|
|
case NdbError::TemporaryError:
|
|
|
|
if (!thd->killed)
|
|
|
|
goto retry_temporary_error1; // retry indefinitly
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
res= ndb_to_mysql_error(&dict->getNdbError());
|
|
|
|
}
|
2006-05-31 16:16:03 +02:00
|
|
|
h->release_metadata(thd, ndb);
|
2005-11-06 00:20:37 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ndb->setDatabaseName(db);
|
2006-05-04 13:58:17 +02:00
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
Ndb_table_guard ndbtab_g(dict, table_name);
|
|
|
|
if (ndbtab_g.get_table())
|
|
|
|
{
|
2006-06-14 12:21:18 +02:00
|
|
|
retry_temporary_error2:
|
2006-05-04 13:58:17 +02:00
|
|
|
if (dict->dropTableGlobal(*ndbtab_g.get_table()) == 0)
|
|
|
|
{
|
|
|
|
ndb_table_id= ndbtab_g.get_table()->getObjectId();
|
|
|
|
ndb_table_version= ndbtab_g.get_table()->getObjectVersion();
|
|
|
|
}
|
2006-06-14 12:21:18 +02:00
|
|
|
else
|
2006-05-04 13:58:17 +02:00
|
|
|
{
|
2006-06-14 12:21:18 +02:00
|
|
|
switch (dict->getNdbError().status)
|
|
|
|
{
|
|
|
|
case NdbError::TemporaryError:
|
|
|
|
if (!thd->killed)
|
|
|
|
goto retry_temporary_error2; // retry indefinitly
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (dict->getNdbError().code == NDB_INVALID_SCHEMA_OBJECT)
|
|
|
|
{
|
|
|
|
ndbtab_g.invalidate();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2006-05-04 13:58:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
res= ndb_to_mysql_error(&dict->getNdbError());
|
|
|
|
break;
|
|
|
|
}
|
2005-11-06 00:20:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (res)
|
|
|
|
{
|
2006-01-12 19:51:02 +01:00
|
|
|
#ifdef HAVE_NDB_BINLOG
|
|
|
|
/* the drop table failed for some reason, drop the share anyways */
|
|
|
|
if (share)
|
|
|
|
{
|
|
|
|
pthread_mutex_lock(&ndbcluster_mutex);
|
|
|
|
if (share->state != NSS_DROPPED)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
The share kept by the server has not been freed, free it
|
|
|
|
*/
|
|
|
|
share->state= NSS_DROPPED;
|
|
|
|
free_share(&share, TRUE);
|
|
|
|
}
|
|
|
|
/* free the share taken above */
|
|
|
|
free_share(&share, TRUE);
|
|
|
|
pthread_mutex_unlock(&ndbcluster_mutex);
|
|
|
|
}
|
|
|
|
#endif
|
2005-11-06 00:20:37 +01:00
|
|
|
DBUG_RETURN(res);
|
|
|
|
}
|
|
|
|
|
2006-01-12 19:51:02 +01:00
|
|
|
#ifdef HAVE_NDB_BINLOG
|
|
|
|
/* stop the logging of the dropped table, and cleanup */
|
|
|
|
|
|
|
|
/*
|
|
|
|
drop table is successful even if table does not exist in ndb
|
|
|
|
and in case table was actually not dropped, there is no need
|
|
|
|
to force a gcp, and setting the event_name to null will indicate
|
|
|
|
that there is no event to be dropped
|
|
|
|
*/
|
|
|
|
int table_dropped= dict->getNdbError().code != 709;
|
|
|
|
|
2006-06-12 14:23:21 +02:00
|
|
|
if (!IS_TMP_PREFIX(table_name) && share &&
|
|
|
|
current_thd->lex->sql_command != SQLCOM_TRUNCATE)
|
2006-01-12 19:51:02 +01:00
|
|
|
{
|
2006-05-31 16:16:03 +02:00
|
|
|
ndbcluster_log_schema_op(thd, share,
|
|
|
|
thd->query, thd->query_length,
|
2006-01-12 19:51:02 +01:00
|
|
|
share->db, share->table_name,
|
2006-05-04 13:58:17 +02:00
|
|
|
ndb_table_id, ndb_table_version,
|
2006-05-31 01:52:14 +02:00
|
|
|
SOT_DROP_TABLE, 0, 0, 1);
|
2006-01-12 19:51:02 +01:00
|
|
|
}
|
|
|
|
else if (table_dropped && share && share->op) /* ndbcluster_log_schema_op
|
|
|
|
will do a force GCP */
|
|
|
|
dict->forceGCPWait();
|
|
|
|
|
|
|
|
if (!IS_TMP_PREFIX(table_name))
|
|
|
|
{
|
|
|
|
String event_name(INJECTOR_EVENT_LEN);
|
|
|
|
ndb_rep_event_name(&event_name, path + sizeof(share_prefix) - 1, 0);
|
|
|
|
ndbcluster_handle_drop_table(ndb,
|
|
|
|
table_dropped ? event_name.c_ptr() : 0,
|
2006-04-10 16:08:40 +02:00
|
|
|
share, "delete table");
|
2006-01-12 19:51:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (share)
|
|
|
|
{
|
|
|
|
pthread_mutex_lock(&ndbcluster_mutex);
|
|
|
|
if (share->state != NSS_DROPPED)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
The share kept by the server has not been freed, free it
|
|
|
|
*/
|
|
|
|
share->state= NSS_DROPPED;
|
|
|
|
free_share(&share, TRUE);
|
|
|
|
}
|
|
|
|
/* free the share taken above */
|
|
|
|
free_share(&share, TRUE);
|
|
|
|
pthread_mutex_unlock(&ndbcluster_mutex);
|
|
|
|
}
|
|
|
|
#endif
|
2005-11-06 00:20:37 +01:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
int ha_ndbcluster::delete_table(const char *name)
|
|
|
|
{
|
2005-02-17 14:22:44 +01:00
|
|
|
DBUG_ENTER("ha_ndbcluster::delete_table");
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_PRINT("enter", ("name: %s", name));
|
|
|
|
set_dbname(name);
|
|
|
|
set_tabname(name);
|
2005-02-17 14:22:44 +01:00
|
|
|
|
2006-04-10 16:08:40 +02:00
|
|
|
#ifdef HAVE_NDB_BINLOG
|
|
|
|
/*
|
|
|
|
Don't allow drop table unless
|
|
|
|
schema distribution table is setup
|
|
|
|
*/
|
|
|
|
if (!schema_share)
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("Schema distribution table not setup"));
|
|
|
|
DBUG_RETURN(HA_ERR_NO_CONNECTION);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
if (check_ndb_connection())
|
|
|
|
DBUG_RETURN(HA_ERR_NO_CONNECTION);
|
2005-02-17 14:22:44 +01:00
|
|
|
|
|
|
|
/* Call ancestor function to delete .ndb file */
|
2004-09-13 14:46:38 +02:00
|
|
|
handler::delete_table(name);
|
2005-11-06 00:20:37 +01:00
|
|
|
|
|
|
|
DBUG_RETURN(delete_table(this, get_ndb(),name, m_dbname, m_tabname));
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-02 22:21:32 +02:00
|
|
|
void ha_ndbcluster::get_auto_increment(ulonglong offset, ulonglong increment,
|
|
|
|
ulonglong nb_desired_values,
|
|
|
|
ulonglong *first_value,
|
|
|
|
ulonglong *nb_reserved_values)
|
2004-04-29 14:38:35 +02:00
|
|
|
{
|
2004-09-15 21:10:31 +02:00
|
|
|
int cache_size;
|
|
|
|
Uint64 auto_value;
|
2004-07-02 11:50:28 +02:00
|
|
|
DBUG_ENTER("get_auto_increment");
|
|
|
|
DBUG_PRINT("enter", ("m_tabname: %s", m_tabname));
|
2004-12-30 19:56:09 +01:00
|
|
|
Ndb *ndb= get_ndb();
|
2005-04-08 16:49:14 +02:00
|
|
|
|
2005-04-07 20:08:01 +02:00
|
|
|
if (m_rows_inserted > m_rows_to_insert)
|
2005-05-07 22:04:52 +02:00
|
|
|
{
|
2005-04-07 20:08:01 +02:00
|
|
|
/* We guessed too low */
|
|
|
|
m_rows_to_insert+= m_autoincrement_prefetch;
|
2005-05-07 22:04:52 +02:00
|
|
|
}
|
2004-11-20 18:36:41 +01:00
|
|
|
cache_size=
|
2005-07-04 02:42:33 +02:00
|
|
|
(int) ((m_rows_to_insert - m_rows_inserted < m_autoincrement_prefetch) ?
|
|
|
|
m_rows_to_insert - m_rows_inserted :
|
|
|
|
((m_rows_to_insert > m_autoincrement_prefetch) ?
|
|
|
|
m_rows_to_insert : m_autoincrement_prefetch));
|
2006-05-17 12:40:10 +02:00
|
|
|
int ret;
|
2005-04-15 16:14:08 +02:00
|
|
|
uint retries= NDB_AUTO_INCREMENT_RETRIES;
|
|
|
|
do {
|
2006-05-25 12:13:47 +02:00
|
|
|
Ndb_tuple_id_range_guard g(m_share);
|
2006-05-17 12:40:10 +02:00
|
|
|
ret=
|
|
|
|
m_skip_auto_increment ?
|
2006-05-25 12:13:47 +02:00
|
|
|
ndb->readAutoIncrementValue(m_table, g.range, auto_value) :
|
|
|
|
ndb->getAutoIncrementValue(m_table, g.range, auto_value, cache_size);
|
2006-05-17 12:40:10 +02:00
|
|
|
} while (ret == -1 &&
|
2005-04-15 16:14:08 +02:00
|
|
|
--retries &&
|
|
|
|
ndb->getNdbError().status == NdbError::TemporaryError);
|
2006-05-17 12:40:10 +02:00
|
|
|
if (ret == -1)
|
2005-10-14 11:23:02 +02:00
|
|
|
{
|
|
|
|
const NdbError err= ndb->getNdbError();
|
|
|
|
sql_print_error("Error %lu in ::get_auto_increment(): %s",
|
|
|
|
(ulong) err.code, err.message);
|
2006-06-02 22:21:32 +02:00
|
|
|
*first_value= ~(ulonglong) 0;
|
|
|
|
DBUG_VOID_RETURN;
|
2005-10-14 11:23:02 +02:00
|
|
|
}
|
2006-06-02 22:21:32 +02:00
|
|
|
*first_value= (longlong)auto_value;
|
|
|
|
/* From the point of view of MySQL, NDB reserves one row at a time */
|
|
|
|
*nb_reserved_values= 1;
|
|
|
|
DBUG_VOID_RETURN;
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Constructor for the NDB Cluster table handler
|
|
|
|
*/
|
|
|
|
|
2005-11-06 00:20:37 +01:00
|
|
|
#define HA_NDBCLUSTER_TABLE_FLAGS \
|
|
|
|
HA_REC_NOT_IN_SEQ | \
|
|
|
|
HA_NULL_IN_KEY | \
|
|
|
|
HA_AUTO_PART_KEY | \
|
|
|
|
HA_NO_PREFIX_CHAR_KEYS | \
|
|
|
|
HA_NEED_READ_RANGE_BUFFER | \
|
|
|
|
HA_CAN_GEOMETRY | \
|
2006-01-12 19:51:02 +01:00
|
|
|
HA_CAN_BIT_FIELD | \
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
HA_PRIMARY_KEY_REQUIRED_FOR_POSITION | \
|
|
|
|
HA_PRIMARY_KEY_REQUIRED_FOR_DELETE | \
|
2006-06-22 21:44:21 +02:00
|
|
|
HA_PARTIAL_COLUMN_READ | \
|
2006-06-27 17:07:44 +02:00
|
|
|
HA_HAS_OWN_BINLOGGING | \
|
|
|
|
HA_HAS_RECORDS
|
2005-11-06 00:20:37 +01:00
|
|
|
|
2006-09-30 02:19:02 +02:00
|
|
|
ha_ndbcluster::ha_ndbcluster(handlerton *hton, TABLE_SHARE *table_arg):
|
|
|
|
handler(hton, table_arg),
|
2004-04-15 09:14:14 +02:00
|
|
|
m_active_trans(NULL),
|
|
|
|
m_active_cursor(NULL),
|
|
|
|
m_table(NULL),
|
2004-09-14 10:52:21 +02:00
|
|
|
m_table_info(NULL),
|
2005-11-06 00:20:37 +01:00
|
|
|
m_table_flags(HA_NDBCLUSTER_TABLE_FLAGS),
|
2004-09-06 20:30:57 +02:00
|
|
|
m_share(0),
|
2005-07-18 13:31:02 +02:00
|
|
|
m_part_info(NULL),
|
|
|
|
m_use_partition_function(FALSE),
|
|
|
|
m_sorted(FALSE),
|
2004-10-14 17:03:46 +02:00
|
|
|
m_use_write(FALSE),
|
2004-11-18 12:11:56 +01:00
|
|
|
m_ignore_dup_key(FALSE),
|
2006-03-24 10:42:55 +01:00
|
|
|
m_has_unique_index(FALSE),
|
2004-11-03 15:53:26 +01:00
|
|
|
m_primary_key_update(FALSE),
|
2005-11-06 00:20:37 +01:00
|
|
|
m_ignore_no_key(FALSE),
|
2005-04-13 12:42:23 +02:00
|
|
|
m_rows_to_insert((ha_rows) 1),
|
|
|
|
m_rows_inserted((ha_rows) 0),
|
|
|
|
m_bulk_insert_rows((ha_rows) 1024),
|
2005-04-13 16:24:17 +02:00
|
|
|
m_rows_changed((ha_rows) 0),
|
2004-11-03 15:53:26 +01:00
|
|
|
m_bulk_insert_not_flushed(FALSE),
|
|
|
|
m_ops_pending(0),
|
|
|
|
m_skip_auto_increment(TRUE),
|
|
|
|
m_blobs_pending(0),
|
2006-06-21 09:36:50 +02:00
|
|
|
m_blobs_offset(0),
|
2004-11-03 15:53:26 +01:00
|
|
|
m_blobs_buffer(0),
|
|
|
|
m_blobs_buffer_size(0),
|
2004-11-17 09:15:53 +01:00
|
|
|
m_dupkey((uint) -1),
|
|
|
|
m_ha_not_exact_count(FALSE),
|
|
|
|
m_force_send(TRUE),
|
2005-04-13 12:42:23 +02:00
|
|
|
m_autoincrement_prefetch((ha_rows) 32),
|
2004-11-22 14:41:46 +01:00
|
|
|
m_transaction_on(TRUE),
|
2005-02-11 22:05:24 +01:00
|
|
|
m_cond_stack(NULL),
|
|
|
|
m_multi_cursor(NULL)
|
2005-03-15 15:03:25 +01:00
|
|
|
{
|
2004-04-30 12:25:31 +02:00
|
|
|
int i;
|
2005-03-15 15:03:25 +01:00
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_ENTER("ha_ndbcluster");
|
|
|
|
|
|
|
|
m_tabname[0]= '\0';
|
|
|
|
m_dbname[0]= '\0';
|
|
|
|
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
stats.records= ~(ha_rows)0; // uninitialized
|
|
|
|
stats.block_size= 1024;
|
2004-04-15 09:14:14 +02:00
|
|
|
|
2006-05-04 15:55:38 +02:00
|
|
|
for (i= 0; i < MAX_KEY; i++)
|
|
|
|
ndb_init_index(m_index[i]);
|
2004-04-30 12:25:31 +02:00
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-04 13:58:17 +02:00
|
|
|
int ha_ndbcluster::ha_initialise()
|
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_ndbcluster::ha_initialise");
|
|
|
|
if (check_ndb_in_thd(current_thd))
|
|
|
|
{
|
|
|
|
DBUG_RETURN(FALSE);
|
|
|
|
}
|
|
|
|
DBUG_RETURN(TRUE);
|
|
|
|
}
|
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
/*
|
|
|
|
Destructor for NDB Cluster table handler
|
|
|
|
*/
|
|
|
|
|
|
|
|
ha_ndbcluster::~ha_ndbcluster()
|
|
|
|
{
|
2006-05-04 13:58:17 +02:00
|
|
|
THD *thd= current_thd;
|
|
|
|
Ndb *ndb= thd ? check_ndb_in_thd(thd) : g_ndb;
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_ENTER("~ha_ndbcluster");
|
|
|
|
|
2004-09-03 17:11:09 +02:00
|
|
|
if (m_share)
|
2005-11-06 00:20:37 +01:00
|
|
|
{
|
|
|
|
free_share(&m_share);
|
|
|
|
}
|
2006-05-04 13:58:17 +02:00
|
|
|
release_metadata(thd, ndb);
|
2004-11-03 15:53:26 +01:00
|
|
|
my_free(m_blobs_buffer, MYF(MY_ALLOW_ZERO_PTR));
|
|
|
|
m_blobs_buffer= 0;
|
2004-04-15 09:14:14 +02:00
|
|
|
|
|
|
|
// Check for open cursor/transaction
|
2004-09-07 12:54:31 +02:00
|
|
|
if (m_active_cursor) {
|
|
|
|
}
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_ASSERT(m_active_cursor == NULL);
|
2004-09-07 12:54:31 +02:00
|
|
|
if (m_active_trans) {
|
|
|
|
}
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_ASSERT(m_active_trans == NULL);
|
|
|
|
|
2004-12-17 21:13:22 +01:00
|
|
|
// Discard the condition stack
|
|
|
|
DBUG_PRINT("info", ("Clearing condition stack"));
|
|
|
|
cond_clear();
|
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-11 22:33:52 +01:00
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
/*
|
|
|
|
Open a table for further use
|
|
|
|
- fetch metadata for this table from NDB
|
|
|
|
- check that table exists
|
2005-11-23 21:45:02 +01:00
|
|
|
|
|
|
|
RETURN
|
|
|
|
0 ok
|
|
|
|
< 0 Table has changed
|
2004-04-15 09:14:14 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
int ha_ndbcluster::open(const char *name, int mode, uint test_if_locked)
|
|
|
|
{
|
2004-10-04 01:20:05 +02:00
|
|
|
int res;
|
2004-04-15 09:14:14 +02:00
|
|
|
KEY *key;
|
2005-11-23 21:45:02 +01:00
|
|
|
DBUG_ENTER("ha_ndbcluster::open");
|
|
|
|
DBUG_PRINT("enter", ("name: %s mode: %d test_if_locked: %d",
|
|
|
|
name, mode, test_if_locked));
|
2004-04-15 09:14:14 +02:00
|
|
|
|
2005-11-23 21:45:02 +01:00
|
|
|
/*
|
|
|
|
Setup ref_length to make room for the whole
|
|
|
|
primary key to be written in the ref variable
|
|
|
|
*/
|
2004-04-15 09:14:14 +02:00
|
|
|
|
2006-01-17 08:40:00 +01:00
|
|
|
if (table_share->primary_key != MAX_KEY)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
2006-01-17 08:40:00 +01:00
|
|
|
key= table->key_info+table_share->primary_key;
|
2004-04-15 09:14:14 +02:00
|
|
|
ref_length= key->key_length;
|
|
|
|
}
|
2006-03-14 15:27:38 +01:00
|
|
|
else // (table_share->primary_key == MAX_KEY)
|
|
|
|
{
|
|
|
|
if (m_use_partition_function)
|
|
|
|
{
|
|
|
|
ref_length+= sizeof(m_part_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DBUG_PRINT("info", ("ref_length: %d", ref_length));
|
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
// Init table lock structure
|
2006-01-12 19:51:02 +01:00
|
|
|
if (!(m_share=get_share(name, table)))
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_RETURN(1);
|
|
|
|
thr_lock_data_init(&m_share->lock,&m_lock,(void*) 0);
|
|
|
|
|
|
|
|
set_dbname(name);
|
|
|
|
set_tabname(name);
|
|
|
|
|
2004-09-03 17:11:09 +02:00
|
|
|
if (check_ndb_connection()) {
|
2005-11-06 00:20:37 +01:00
|
|
|
free_share(&m_share);
|
|
|
|
m_share= 0;
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_RETURN(HA_ERR_NO_CONNECTION);
|
2004-09-03 17:11:09 +02:00
|
|
|
}
|
2004-09-13 14:46:38 +02:00
|
|
|
|
2004-10-04 01:20:05 +02:00
|
|
|
res= get_metadata(name);
|
|
|
|
if (!res)
|
|
|
|
info(HA_STATUS_VARIABLE | HA_STATUS_CONST);
|
2004-04-15 09:14:14 +02:00
|
|
|
|
2006-04-10 16:08:40 +02:00
|
|
|
#ifdef HAVE_NDB_BINLOG
|
|
|
|
if (!ndb_binlog_tables_inited && ndb_binlog_running)
|
|
|
|
table->db_stat|= HA_READ_ONLY;
|
|
|
|
#endif
|
|
|
|
|
2004-10-04 01:20:05 +02:00
|
|
|
DBUG_RETURN(res);
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
|
2006-01-17 08:40:00 +01:00
|
|
|
/*
|
|
|
|
Set partition info
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
set_part_info()
|
|
|
|
part_info
|
|
|
|
|
|
|
|
RETURN VALUE
|
|
|
|
NONE
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
Set up partition info when handler object created
|
|
|
|
*/
|
|
|
|
|
2005-11-25 09:11:52 +01:00
|
|
|
void ha_ndbcluster::set_part_info(partition_info *part_info)
|
|
|
|
{
|
|
|
|
m_part_info= part_info;
|
|
|
|
if (!(m_part_info->part_type == HASH_PARTITION &&
|
|
|
|
m_part_info->list_of_part_fields &&
|
2006-02-16 22:02:44 +01:00
|
|
|
!m_part_info->is_sub_partitioned()))
|
2005-11-25 09:11:52 +01:00
|
|
|
m_use_partition_function= TRUE;
|
|
|
|
}
|
2004-04-15 09:14:14 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
Close the table
|
|
|
|
- release resources setup by open()
|
|
|
|
*/
|
|
|
|
|
|
|
|
int ha_ndbcluster::close(void)
|
|
|
|
{
|
2006-05-04 13:58:17 +02:00
|
|
|
DBUG_ENTER("close");
|
|
|
|
THD *thd= current_thd;
|
|
|
|
Ndb *ndb= thd ? check_ndb_in_thd(thd) : g_ndb;
|
2005-11-06 00:20:37 +01:00
|
|
|
free_share(&m_share);
|
|
|
|
m_share= 0;
|
2006-05-04 13:58:17 +02:00
|
|
|
release_metadata(thd, ndb);
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-09-14 14:47:34 +02:00
|
|
|
Thd_ndb* ha_ndbcluster::seize_thd_ndb()
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
2004-09-14 14:47:34 +02:00
|
|
|
Thd_ndb *thd_ndb;
|
|
|
|
DBUG_ENTER("seize_thd_ndb");
|
2004-04-15 09:14:14 +02:00
|
|
|
|
2004-09-14 14:47:34 +02:00
|
|
|
thd_ndb= new Thd_ndb();
|
|
|
|
if (thd_ndb->ndb->init(max_transactions) != 0)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
2004-09-14 14:47:34 +02:00
|
|
|
ERR_PRINT(thd_ndb->ndb->getNdbError());
|
2004-04-15 09:14:14 +02:00
|
|
|
/*
|
|
|
|
TODO
|
|
|
|
Alt.1 If init fails because to many allocated Ndb
|
|
|
|
wait on condition for a Ndb object to be released.
|
|
|
|
Alt.2 Seize/release from pool, wait until next release
|
|
|
|
*/
|
2004-09-14 14:47:34 +02:00
|
|
|
delete thd_ndb;
|
|
|
|
thd_ndb= NULL;
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
2004-09-14 14:47:34 +02:00
|
|
|
DBUG_RETURN(thd_ndb);
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-09-14 14:47:34 +02:00
|
|
|
void ha_ndbcluster::release_thd_ndb(Thd_ndb* thd_ndb)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
2004-09-14 14:47:34 +02:00
|
|
|
DBUG_ENTER("release_thd_ndb");
|
|
|
|
delete thd_ndb;
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2004-09-20 17:34:32 +02:00
|
|
|
If this thread already has a Thd_ndb object allocated
|
2004-04-15 09:14:14 +02:00
|
|
|
in current THD, reuse it. Otherwise
|
2004-09-20 17:34:32 +02:00
|
|
|
seize a Thd_ndb object, assign it to current THD and use it.
|
2004-04-15 09:14:14 +02:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
2004-09-13 14:46:38 +02:00
|
|
|
Ndb* check_ndb_in_thd(THD* thd)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
2005-02-17 22:52:40 +01:00
|
|
|
Thd_ndb *thd_ndb= get_thd_ndb(thd);
|
2004-09-14 14:47:34 +02:00
|
|
|
if (!thd_ndb)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
2004-09-20 17:34:32 +02:00
|
|
|
if (!(thd_ndb= ha_ndbcluster::seize_thd_ndb()))
|
2005-02-11 22:33:52 +01:00
|
|
|
return NULL;
|
2005-02-17 22:52:40 +01:00
|
|
|
set_thd_ndb(thd, thd_ndb);
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
2005-02-11 22:33:52 +01:00
|
|
|
return thd_ndb->ndb;
|
2004-09-13 14:46:38 +02:00
|
|
|
}
|
|
|
|
|
2004-09-20 17:34:32 +02:00
|
|
|
|
2004-12-06 14:51:10 +01:00
|
|
|
|
2005-03-15 15:03:25 +01:00
|
|
|
int ha_ndbcluster::check_ndb_connection(THD* thd)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
2004-12-30 19:56:09 +01:00
|
|
|
Ndb *ndb;
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_ENTER("check_ndb_connection");
|
|
|
|
|
2004-12-30 19:56:09 +01:00
|
|
|
if (!(ndb= check_ndb_in_thd(thd)))
|
2004-09-13 14:46:38 +02:00
|
|
|
DBUG_RETURN(HA_ERR_NO_CONNECTION);
|
2004-12-30 19:56:09 +01:00
|
|
|
ndb->setDatabaseName(m_dbname);
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
2004-09-20 17:34:32 +02:00
|
|
|
|
2006-09-30 21:49:46 +02:00
|
|
|
static int ndbcluster_close_connection(handlerton *hton, THD *thd)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
2005-02-17 22:52:40 +01:00
|
|
|
Thd_ndb *thd_ndb= get_thd_ndb(thd);
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_ENTER("ndbcluster_close_connection");
|
2004-09-14 10:52:21 +02:00
|
|
|
if (thd_ndb)
|
|
|
|
{
|
2004-09-14 14:47:34 +02:00
|
|
|
ha_ndbcluster::release_thd_ndb(thd_ndb);
|
2005-02-17 22:52:40 +01:00
|
|
|
set_thd_ndb(thd, NULL); // not strictly required but does not hurt either
|
2004-09-14 10:52:21 +02:00
|
|
|
}
|
2005-02-17 22:52:40 +01:00
|
|
|
DBUG_RETURN(0);
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Try to discover one table from NDB
|
|
|
|
*/
|
|
|
|
|
2006-09-30 21:49:46 +02:00
|
|
|
int ndbcluster_discover(handlerton *hton, THD* thd, const char *db,
|
|
|
|
const char *name,
|
|
|
|
const void** frmblob,
|
|
|
|
uint* frmlen)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
2006-05-04 13:58:17 +02:00
|
|
|
int error= 0;
|
|
|
|
NdbError ndb_error;
|
2004-04-15 09:14:14 +02:00
|
|
|
uint len;
|
|
|
|
const void* data;
|
2004-09-13 14:46:38 +02:00
|
|
|
Ndb* ndb;
|
2006-01-27 17:23:14 +01:00
|
|
|
char key[FN_REFLEN];
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_ENTER("ndbcluster_discover");
|
2004-09-13 14:46:38 +02:00
|
|
|
DBUG_PRINT("enter", ("db: %s, name: %s", db, name));
|
2004-04-15 09:14:14 +02:00
|
|
|
|
2004-09-13 14:46:38 +02:00
|
|
|
if (!(ndb= check_ndb_in_thd(thd)))
|
|
|
|
DBUG_RETURN(HA_ERR_NO_CONNECTION);
|
|
|
|
ndb->setDatabaseName(db);
|
|
|
|
NDBDICT* dict= ndb->getDictionary();
|
2006-08-02 17:57:06 +02:00
|
|
|
build_table_filename(key, sizeof(key), db, name, "", 0);
|
2006-01-27 17:23:14 +01:00
|
|
|
NDB_SHARE *share= get_share(key, 0, false);
|
2006-02-01 10:21:48 +01:00
|
|
|
if (share && get_ndb_share_state(share) == NSS_ALTERED)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
2006-01-27 17:23:14 +01:00
|
|
|
// Frm has been altered on disk, but not yet written to ndb
|
|
|
|
if (readfrm(key, &data, &len))
|
|
|
|
{
|
|
|
|
DBUG_PRINT("error", ("Could not read frm"));
|
2006-05-04 13:58:17 +02:00
|
|
|
error= 1;
|
|
|
|
goto err;
|
2006-01-27 17:23:14 +01:00
|
|
|
}
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
2006-01-27 17:23:14 +01:00
|
|
|
else
|
2005-06-08 13:31:59 +02:00
|
|
|
{
|
2006-05-04 13:58:17 +02:00
|
|
|
Ndb_table_guard ndbtab_g(dict, name);
|
|
|
|
const NDBTAB *tab= ndbtab_g.get_table();
|
|
|
|
if (!tab)
|
|
|
|
{
|
2006-01-27 17:23:14 +01:00
|
|
|
const NdbError err= dict->getNdbError();
|
|
|
|
if (err.code == 709 || err.code == 723)
|
2006-05-04 13:58:17 +02:00
|
|
|
error= -1;
|
|
|
|
else
|
|
|
|
ndb_error= err;
|
|
|
|
goto err;
|
2006-01-27 17:23:14 +01:00
|
|
|
}
|
|
|
|
DBUG_PRINT("info", ("Found table %s", tab->getName()));
|
|
|
|
|
|
|
|
len= tab->getFrmLength();
|
|
|
|
if (len == 0 || tab->getFrmData() == NULL)
|
|
|
|
{
|
|
|
|
DBUG_PRINT("error", ("No frm data found."));
|
2006-05-04 13:58:17 +02:00
|
|
|
error= 1;
|
|
|
|
goto err;
|
2006-01-27 17:23:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (unpackfrm(&data, &len, tab->getFrmData()))
|
|
|
|
{
|
|
|
|
DBUG_PRINT("error", ("Could not unpack table"));
|
2006-05-04 13:58:17 +02:00
|
|
|
error= 1;
|
|
|
|
goto err;
|
2006-01-27 17:23:14 +01:00
|
|
|
}
|
2005-06-08 13:31:59 +02:00
|
|
|
}
|
2004-04-15 09:14:14 +02:00
|
|
|
|
|
|
|
*frmlen= len;
|
|
|
|
*frmblob= data;
|
|
|
|
|
2006-01-27 17:23:14 +01:00
|
|
|
if (share)
|
|
|
|
free_share(&share);
|
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_RETURN(0);
|
2006-05-04 13:58:17 +02:00
|
|
|
err:
|
|
|
|
if (share)
|
|
|
|
free_share(&share);
|
|
|
|
if (ndb_error.code)
|
|
|
|
{
|
|
|
|
ERR_RETURN(ndb_error);
|
|
|
|
}
|
|
|
|
DBUG_RETURN(error);
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2004-09-13 14:46:38 +02:00
|
|
|
Check if a table exists in NDB
|
2005-03-15 15:03:25 +01:00
|
|
|
|
2004-09-13 14:46:38 +02:00
|
|
|
*/
|
2004-04-15 09:14:14 +02:00
|
|
|
|
2006-09-30 21:49:46 +02:00
|
|
|
int ndbcluster_table_exists_in_engine(handlerton *hton, THD* thd,
|
|
|
|
const char *db,
|
2006-05-04 13:58:17 +02:00
|
|
|
const char *name)
|
2004-09-13 14:46:38 +02:00
|
|
|
{
|
|
|
|
Ndb* ndb;
|
2005-06-08 13:31:59 +02:00
|
|
|
DBUG_ENTER("ndbcluster_table_exists_in_engine");
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
DBUG_PRINT("enter", ("db: %s name: %s", db, name));
|
2004-09-13 14:46:38 +02:00
|
|
|
|
|
|
|
if (!(ndb= check_ndb_in_thd(thd)))
|
2005-03-15 15:03:25 +01:00
|
|
|
DBUG_RETURN(HA_ERR_NO_CONNECTION);
|
2004-09-13 14:46:38 +02:00
|
|
|
|
|
|
|
NDBDICT* dict= ndb->getDictionary();
|
2006-05-04 13:58:17 +02:00
|
|
|
NdbDictionary::Dictionary::List list;
|
|
|
|
if (dict->listObjects(list, NdbDictionary::Object::UserTable) != 0)
|
|
|
|
ERR_RETURN(dict->getNdbError());
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
for (uint i= 0 ; i < list.count ; i++)
|
2005-03-15 15:03:25 +01:00
|
|
|
{
|
2006-05-04 13:58:17 +02:00
|
|
|
NdbDictionary::Dictionary::List::Element& elmt= list.elements[i];
|
|
|
|
if (my_strcasecmp(system_charset_info, elmt.database, db))
|
|
|
|
continue;
|
|
|
|
if (my_strcasecmp(system_charset_info, elmt.name, name))
|
|
|
|
continue;
|
|
|
|
DBUG_PRINT("info", ("Found table"));
|
|
|
|
DBUG_RETURN(1);
|
2004-09-13 14:46:38 +02:00
|
|
|
}
|
2006-05-04 13:58:17 +02:00
|
|
|
DBUG_RETURN(0);
|
2004-09-13 14:46:38 +02:00
|
|
|
}
|
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
|
|
|
|
|
2004-09-26 16:11:24 +02:00
|
|
|
extern "C" byte* tables_get_key(const char *entry, uint *length,
|
2005-02-16 14:18:32 +01:00
|
|
|
my_bool not_used __attribute__((unused)))
|
2004-09-21 12:13:58 +02:00
|
|
|
{
|
|
|
|
*length= strlen(entry);
|
|
|
|
return (byte*) entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-22 15:28:23 +02:00
|
|
|
/*
|
|
|
|
Drop a database in NDB Cluster
|
2005-11-07 16:25:06 +01:00
|
|
|
NOTE add a dummy void function, since stupid handlerton is returning void instead of int...
|
|
|
|
*/
|
2005-04-22 15:28:23 +02:00
|
|
|
|
2005-11-07 16:25:06 +01:00
|
|
|
int ndbcluster_drop_database_impl(const char *path)
|
2005-04-22 15:28:23 +02:00
|
|
|
{
|
|
|
|
DBUG_ENTER("ndbcluster_drop_database");
|
|
|
|
THD *thd= current_thd;
|
|
|
|
char dbname[FN_HEADLEN];
|
|
|
|
Ndb* ndb;
|
|
|
|
NdbDictionary::Dictionary::List list;
|
|
|
|
uint i;
|
|
|
|
char *tabname;
|
|
|
|
List<char> drop_list;
|
2005-04-25 11:31:16 +02:00
|
|
|
int ret= 0;
|
2005-04-22 15:28:23 +02:00
|
|
|
ha_ndbcluster::set_dbname(path, (char *)&dbname);
|
|
|
|
DBUG_PRINT("enter", ("db: %s", dbname));
|
|
|
|
|
|
|
|
if (!(ndb= check_ndb_in_thd(thd)))
|
2005-11-07 16:25:06 +01:00
|
|
|
DBUG_RETURN(-1);
|
2005-04-22 15:28:23 +02:00
|
|
|
|
|
|
|
// List tables in NDB
|
|
|
|
NDBDICT *dict= ndb->getDictionary();
|
|
|
|
if (dict->listObjects(list,
|
|
|
|
NdbDictionary::Object::UserTable) != 0)
|
2005-11-07 16:25:06 +01:00
|
|
|
DBUG_RETURN(-1);
|
2005-04-22 15:28:23 +02:00
|
|
|
for (i= 0 ; i < list.count ; i++)
|
|
|
|
{
|
2005-11-06 00:20:37 +01:00
|
|
|
NdbDictionary::Dictionary::List::Element& elmt= list.elements[i];
|
|
|
|
DBUG_PRINT("info", ("Found %s/%s in NDB", elmt.database, elmt.name));
|
2005-04-22 15:28:23 +02:00
|
|
|
|
|
|
|
// Add only tables that belongs to db
|
2005-11-06 00:20:37 +01:00
|
|
|
if (my_strcasecmp(system_charset_info, elmt.database, dbname))
|
2005-04-22 15:28:23 +02:00
|
|
|
continue;
|
2005-11-06 00:20:37 +01:00
|
|
|
DBUG_PRINT("info", ("%s must be dropped", elmt.name));
|
|
|
|
drop_list.push_back(thd->strdup(elmt.name));
|
2005-04-22 15:28:23 +02:00
|
|
|
}
|
|
|
|
// Drop any tables belonging to database
|
2005-11-06 00:20:37 +01:00
|
|
|
char full_path[FN_REFLEN];
|
2006-02-16 03:23:43 +01:00
|
|
|
char *tmp= full_path +
|
2006-08-02 17:57:06 +02:00
|
|
|
build_table_filename(full_path, sizeof(full_path), dbname, "", "", 0);
|
2006-02-16 03:23:43 +01:00
|
|
|
|
2005-04-22 15:28:23 +02:00
|
|
|
ndb->setDatabaseName(dbname);
|
|
|
|
List_iterator_fast<char> it(drop_list);
|
|
|
|
while ((tabname=it++))
|
2005-04-25 11:31:16 +02:00
|
|
|
{
|
2006-02-16 03:23:43 +01:00
|
|
|
tablename_to_filename(tabname, tmp, FN_REFLEN - (tmp - full_path)-1);
|
2006-06-14 01:20:39 +02:00
|
|
|
VOID(pthread_mutex_lock(&LOCK_open));
|
2005-11-06 00:20:37 +01:00
|
|
|
if (ha_ndbcluster::delete_table(0, ndb, full_path, dbname, tabname))
|
2005-04-25 11:31:16 +02:00
|
|
|
{
|
|
|
|
const NdbError err= dict->getNdbError();
|
2005-11-07 12:19:28 +01:00
|
|
|
if (err.code != 709 && err.code != 723)
|
2005-04-25 11:34:47 +02:00
|
|
|
{
|
|
|
|
ERR_PRINT(err);
|
2005-04-25 11:31:16 +02:00
|
|
|
ret= ndb_to_mysql_error(&err);
|
2005-04-25 11:34:47 +02:00
|
|
|
}
|
2005-04-25 11:31:16 +02:00
|
|
|
}
|
2006-06-14 01:20:39 +02:00
|
|
|
VOID(pthread_mutex_unlock(&LOCK_open));
|
2005-04-25 11:31:16 +02:00
|
|
|
}
|
|
|
|
DBUG_RETURN(ret);
|
2005-04-22 15:28:23 +02:00
|
|
|
}
|
|
|
|
|
2006-09-30 21:49:46 +02:00
|
|
|
static void ndbcluster_drop_database(handlerton *hton, char *path)
|
2005-11-07 16:25:06 +01:00
|
|
|
{
|
2006-05-31 16:16:03 +02:00
|
|
|
THD *thd= current_thd;
|
2006-04-10 16:08:40 +02:00
|
|
|
DBUG_ENTER("ndbcluster_drop_database");
|
|
|
|
#ifdef HAVE_NDB_BINLOG
|
|
|
|
/*
|
|
|
|
Don't allow drop database unless
|
|
|
|
schema distribution table is setup
|
|
|
|
*/
|
|
|
|
if (!schema_share)
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("Schema distribution table not setup"));
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
//DBUG_RETURN(HA_ERR_NO_CONNECTION);
|
|
|
|
}
|
|
|
|
#endif
|
2005-11-07 16:25:06 +01:00
|
|
|
ndbcluster_drop_database_impl(path);
|
2006-01-12 19:51:02 +01:00
|
|
|
#ifdef HAVE_NDB_BINLOG
|
|
|
|
char db[FN_REFLEN];
|
|
|
|
ha_ndbcluster::set_dbname(path, db);
|
2006-05-31 16:16:03 +02:00
|
|
|
ndbcluster_log_schema_op(thd, 0,
|
|
|
|
thd->query, thd->query_length,
|
2006-05-31 01:52:14 +02:00
|
|
|
db, "", 0, 0, SOT_DROP_DB, 0, 0, 0);
|
2006-01-12 19:51:02 +01:00
|
|
|
#endif
|
2006-04-10 16:08:40 +02:00
|
|
|
DBUG_VOID_RETURN;
|
2005-11-07 16:25:06 +01:00
|
|
|
}
|
2005-11-06 00:20:37 +01:00
|
|
|
/*
|
|
|
|
find all tables in ndb and discover those needed
|
|
|
|
*/
|
2006-01-31 01:37:48 +01:00
|
|
|
int ndb_create_table_from_engine(THD *thd, const char *db,
|
|
|
|
const char *table_name)
|
|
|
|
{
|
|
|
|
LEX *old_lex= thd->lex, newlex;
|
|
|
|
thd->lex= &newlex;
|
|
|
|
newlex.current_select= NULL;
|
|
|
|
lex_start(thd, (const uchar*) "", 0);
|
|
|
|
int res= ha_create_table_from_engine(thd, db, table_name);
|
|
|
|
thd->lex= old_lex;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2006-01-12 19:51:02 +01:00
|
|
|
int ndbcluster_find_all_files(THD *thd)
|
2005-11-06 00:20:37 +01:00
|
|
|
{
|
|
|
|
DBUG_ENTER("ndbcluster_find_all_files");
|
|
|
|
Ndb* ndb;
|
|
|
|
char key[FN_REFLEN];
|
|
|
|
|
|
|
|
if (!(ndb= check_ndb_in_thd(thd)))
|
|
|
|
DBUG_RETURN(HA_ERR_NO_CONNECTION);
|
|
|
|
|
|
|
|
NDBDICT *dict= ndb->getDictionary();
|
|
|
|
|
2006-04-10 16:08:40 +02:00
|
|
|
int unhandled, retries= 5, skipped;
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
LINT_INIT(unhandled);
|
|
|
|
LINT_INIT(skipped);
|
2005-11-06 00:20:37 +01:00
|
|
|
do
|
|
|
|
{
|
2006-04-10 17:06:33 +02:00
|
|
|
NdbDictionary::Dictionary::List list;
|
2005-11-06 00:20:37 +01:00
|
|
|
if (dict->listObjects(list, NdbDictionary::Object::UserTable) != 0)
|
|
|
|
ERR_RETURN(dict->getNdbError());
|
|
|
|
unhandled= 0;
|
2006-04-10 16:08:40 +02:00
|
|
|
skipped= 0;
|
|
|
|
retries--;
|
2005-11-06 00:20:37 +01:00
|
|
|
for (uint i= 0 ; i < list.count ; i++)
|
|
|
|
{
|
|
|
|
NDBDICT::List::Element& elmt= list.elements[i];
|
2006-02-17 22:33:31 +01:00
|
|
|
if (IS_TMP_PREFIX(elmt.name) || IS_NDB_BLOB_PREFIX(elmt.name))
|
2006-01-12 19:51:02 +01:00
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("Skipping %s.%s in NDB", elmt.database, elmt.name));
|
|
|
|
continue;
|
|
|
|
}
|
2005-11-06 00:20:37 +01:00
|
|
|
DBUG_PRINT("info", ("Found %s.%s in NDB", elmt.database, elmt.name));
|
2006-04-10 16:08:40 +02:00
|
|
|
if (elmt.state != NDBOBJ::StateOnline &&
|
|
|
|
elmt.state != NDBOBJ::StateBackup &&
|
|
|
|
elmt.state != NDBOBJ::StateBuilding)
|
2005-11-06 00:20:37 +01:00
|
|
|
{
|
|
|
|
sql_print_information("NDB: skipping setup table %s.%s, in state %d",
|
|
|
|
elmt.database, elmt.name, elmt.state);
|
2006-04-10 16:08:40 +02:00
|
|
|
skipped++;
|
2005-11-06 00:20:37 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
ndb->setDatabaseName(elmt.database);
|
2006-05-04 13:58:17 +02:00
|
|
|
Ndb_table_guard ndbtab_g(dict, elmt.name);
|
|
|
|
const NDBTAB *ndbtab= ndbtab_g.get_table();
|
|
|
|
if (!ndbtab)
|
2005-11-06 00:20:37 +01:00
|
|
|
{
|
2006-04-10 16:08:40 +02:00
|
|
|
if (retries == 0)
|
2006-01-12 19:51:02 +01:00
|
|
|
sql_print_error("NDB: failed to setup table %s.%s, error: %d, %s",
|
|
|
|
elmt.database, elmt.name,
|
|
|
|
dict->getNdbError().code,
|
|
|
|
dict->getNdbError().message);
|
2005-11-06 00:20:37 +01:00
|
|
|
unhandled++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ndbtab->getFrmLength() == 0)
|
|
|
|
continue;
|
|
|
|
|
2006-01-31 01:37:48 +01:00
|
|
|
/* check if database exists */
|
2006-02-16 03:23:43 +01:00
|
|
|
char *end= key +
|
2006-08-02 17:57:06 +02:00
|
|
|
build_table_filename(key, sizeof(key), elmt.database, "", "", 0);
|
2006-01-31 01:37:48 +01:00
|
|
|
if (my_access(key, F_OK))
|
|
|
|
{
|
|
|
|
/* no such database defined, skip table */
|
|
|
|
continue;
|
|
|
|
}
|
2006-02-16 03:23:43 +01:00
|
|
|
/* finalize construction of path */
|
|
|
|
end+= tablename_to_filename(elmt.name, end,
|
|
|
|
sizeof(key)-(end-key));
|
2005-11-06 00:20:37 +01:00
|
|
|
const void *data= 0, *pack_data= 0;
|
|
|
|
uint length, pack_length;
|
|
|
|
int discover= 0;
|
|
|
|
if (readfrm(key, &data, &length) ||
|
|
|
|
packfrm(data, length, &pack_data, &pack_length))
|
|
|
|
{
|
|
|
|
discover= 1;
|
|
|
|
sql_print_information("NDB: missing frm for %s.%s, discovering...",
|
|
|
|
elmt.database, elmt.name);
|
|
|
|
}
|
|
|
|
else if (cmp_frm(ndbtab, pack_data, pack_length))
|
|
|
|
{
|
2006-01-17 12:53:49 +01:00
|
|
|
NDB_SHARE *share= get_share(key, 0, false);
|
2006-02-01 10:21:48 +01:00
|
|
|
if (!share || get_ndb_share_state(share) != NSS_ALTERED)
|
2006-01-17 12:53:49 +01:00
|
|
|
{
|
|
|
|
discover= 1;
|
|
|
|
sql_print_information("NDB: mismatch in frm for %s.%s, discovering...",
|
|
|
|
elmt.database, elmt.name);
|
|
|
|
}
|
2006-01-17 18:35:17 +01:00
|
|
|
if (share)
|
|
|
|
free_share(&share);
|
2005-11-06 00:20:37 +01:00
|
|
|
}
|
|
|
|
my_free((char*) data, MYF(MY_ALLOW_ZERO_PTR));
|
|
|
|
my_free((char*) pack_data, MYF(MY_ALLOW_ZERO_PTR));
|
|
|
|
|
2006-01-31 15:40:26 +01:00
|
|
|
pthread_mutex_lock(&LOCK_open);
|
2005-11-06 00:20:37 +01:00
|
|
|
if (discover)
|
|
|
|
{
|
|
|
|
/* ToDo 4.1 database needs to be created if missing */
|
2006-01-31 01:37:48 +01:00
|
|
|
if (ndb_create_table_from_engine(thd, elmt.database, elmt.name))
|
2005-11-06 00:20:37 +01:00
|
|
|
{
|
|
|
|
/* ToDo 4.1 handle error */
|
|
|
|
}
|
|
|
|
}
|
2006-01-12 19:51:02 +01:00
|
|
|
#ifdef HAVE_NDB_BINLOG
|
2006-01-31 15:40:26 +01:00
|
|
|
else
|
2006-01-12 19:51:02 +01:00
|
|
|
{
|
|
|
|
/* set up replication for this table */
|
2006-01-31 15:40:26 +01:00
|
|
|
ndbcluster_create_binlog_setup(ndb, key, end-key,
|
|
|
|
elmt.database, elmt.name,
|
|
|
|
TRUE);
|
2006-01-12 19:51:02 +01:00
|
|
|
}
|
|
|
|
#endif
|
2006-01-31 15:40:26 +01:00
|
|
|
pthread_mutex_unlock(&LOCK_open);
|
2005-11-06 00:20:37 +01:00
|
|
|
}
|
|
|
|
}
|
2006-04-10 16:08:40 +02:00
|
|
|
while (unhandled && retries);
|
2005-11-06 00:20:37 +01:00
|
|
|
|
2006-04-10 16:08:40 +02:00
|
|
|
DBUG_RETURN(-(skipped + unhandled));
|
2005-11-06 00:20:37 +01:00
|
|
|
}
|
2005-04-22 15:28:23 +02:00
|
|
|
|
2006-09-30 21:49:46 +02:00
|
|
|
int ndbcluster_find_files(handlerton *hton, THD *thd,
|
|
|
|
const char *db,
|
|
|
|
const char *path,
|
2005-02-16 14:18:32 +01:00
|
|
|
const char *wild, bool dir, List<char> *files)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
2004-10-25 22:35:46 +02:00
|
|
|
DBUG_ENTER("ndbcluster_find_files");
|
|
|
|
DBUG_PRINT("enter", ("db: %s", db));
|
|
|
|
{ // extra bracket to avoid gcc 2.95.3 warning
|
2004-04-15 09:14:14 +02:00
|
|
|
uint i;
|
2004-09-13 14:46:38 +02:00
|
|
|
Ndb* ndb;
|
2004-09-21 12:13:58 +02:00
|
|
|
char name[FN_REFLEN];
|
2004-09-26 16:11:24 +02:00
|
|
|
HASH ndb_tables, ok_tables;
|
2005-11-06 00:20:37 +01:00
|
|
|
NDBDICT::List list;
|
2004-09-13 14:46:38 +02:00
|
|
|
|
|
|
|
if (!(ndb= check_ndb_in_thd(thd)))
|
|
|
|
DBUG_RETURN(HA_ERR_NO_CONNECTION);
|
|
|
|
|
2004-09-21 12:13:58 +02:00
|
|
|
if (dir)
|
2004-09-26 16:11:24 +02:00
|
|
|
DBUG_RETURN(0); // Discover of databases not yet supported
|
2004-09-21 12:13:58 +02:00
|
|
|
|
2004-09-26 16:11:24 +02:00
|
|
|
// List tables in NDB
|
2004-09-13 14:46:38 +02:00
|
|
|
NDBDICT *dict= ndb->getDictionary();
|
2004-04-15 09:14:14 +02:00
|
|
|
if (dict->listObjects(list,
|
2005-02-16 14:18:32 +01:00
|
|
|
NdbDictionary::Object::UserTable) != 0)
|
2004-09-13 06:40:25 +02:00
|
|
|
ERR_RETURN(dict->getNdbError());
|
2004-09-13 14:46:38 +02:00
|
|
|
|
2004-09-26 16:11:24 +02:00
|
|
|
if (hash_init(&ndb_tables, system_charset_info,list.count,0,0,
|
2005-02-16 14:18:32 +01:00
|
|
|
(hash_get_key)tables_get_key,0,0))
|
2004-09-26 16:11:24 +02:00
|
|
|
{
|
|
|
|
DBUG_PRINT("error", ("Failed to init HASH ndb_tables"));
|
|
|
|
DBUG_RETURN(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hash_init(&ok_tables, system_charset_info,32,0,0,
|
2005-02-16 14:18:32 +01:00
|
|
|
(hash_get_key)tables_get_key,0,0))
|
2004-09-26 16:11:24 +02:00
|
|
|
{
|
|
|
|
DBUG_PRINT("error", ("Failed to init HASH ok_tables"));
|
|
|
|
hash_free(&ndb_tables);
|
|
|
|
DBUG_RETURN(-1);
|
|
|
|
}
|
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
for (i= 0 ; i < list.count ; i++)
|
|
|
|
{
|
2005-11-06 00:20:37 +01:00
|
|
|
NDBDICT::List::Element& elmt= list.elements[i];
|
2006-02-17 22:33:31 +01:00
|
|
|
if (IS_TMP_PREFIX(elmt.name) || IS_NDB_BLOB_PREFIX(elmt.name))
|
2006-01-12 19:51:02 +01:00
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("Skipping %s.%s in NDB", elmt.database, elmt.name));
|
|
|
|
continue;
|
|
|
|
}
|
2005-11-06 00:20:37 +01:00
|
|
|
DBUG_PRINT("info", ("Found %s/%s in NDB", elmt.database, elmt.name));
|
2004-04-15 09:14:14 +02:00
|
|
|
|
2004-10-08 13:37:13 +02:00
|
|
|
// Add only tables that belongs to db
|
2005-11-06 00:20:37 +01:00
|
|
|
if (my_strcasecmp(system_charset_info, elmt.database, db))
|
2004-10-08 13:37:13 +02:00
|
|
|
continue;
|
2004-04-15 09:14:14 +02:00
|
|
|
|
2004-09-26 16:11:24 +02:00
|
|
|
// Apply wildcard to list of tables in NDB
|
2004-09-21 12:13:58 +02:00
|
|
|
if (wild)
|
2004-09-13 14:46:38 +02:00
|
|
|
{
|
2004-09-21 12:13:58 +02:00
|
|
|
if (lower_case_table_names)
|
|
|
|
{
|
2005-11-06 00:20:37 +01:00
|
|
|
if (wild_case_compare(files_charset_info, elmt.name, wild))
|
2005-02-16 14:18:32 +01:00
|
|
|
continue;
|
2004-09-21 12:13:58 +02:00
|
|
|
}
|
2005-11-06 00:20:37 +01:00
|
|
|
else if (wild_compare(elmt.name,wild,0))
|
2005-02-16 14:18:32 +01:00
|
|
|
continue;
|
2004-09-21 12:13:58 +02:00
|
|
|
}
|
2005-11-06 00:20:37 +01:00
|
|
|
DBUG_PRINT("info", ("Inserting %s into ndb_tables hash", elmt.name));
|
|
|
|
my_hash_insert(&ndb_tables, (byte*)thd->strdup(elmt.name));
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
|
2004-09-26 16:11:24 +02:00
|
|
|
char *file_name;
|
|
|
|
List_iterator<char> it(*files);
|
|
|
|
List<char> delete_list;
|
|
|
|
while ((file_name=it++))
|
|
|
|
{
|
2006-09-12 16:04:52 +02:00
|
|
|
bool file_on_disk= false;
|
2004-09-26 16:11:24 +02:00
|
|
|
DBUG_PRINT("info", ("%s", file_name));
|
|
|
|
if (hash_search(&ndb_tables, file_name, strlen(file_name)))
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("%s existed in NDB _and_ on disk ", file_name));
|
2006-09-12 16:04:52 +02:00
|
|
|
file_on_disk= true;
|
2004-09-26 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2006-09-12 16:04:52 +02:00
|
|
|
// Check for .ndb file with this name
|
2006-08-02 17:57:06 +02:00
|
|
|
build_table_filename(name, sizeof(name), db, file_name, ha_ndb_ext, 0);
|
2004-09-26 16:11:24 +02:00
|
|
|
DBUG_PRINT("info", ("Check access for %s", name));
|
2006-02-16 03:23:43 +01:00
|
|
|
if (my_access(name, F_OK))
|
2004-09-26 16:11:24 +02:00
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("%s did not exist on disk", name));
|
|
|
|
// .ndb file did not exist on disk, another table type
|
2006-09-12 16:04:52 +02:00
|
|
|
if (file_on_disk)
|
2006-09-13 18:49:05 +02:00
|
|
|
{
|
|
|
|
// Ignore this ndb table
|
|
|
|
gptr record= hash_search(&ndb_tables, file_name, strlen(file_name));
|
|
|
|
DBUG_ASSERT(record);
|
|
|
|
hash_delete(&ndb_tables, record);
|
2006-09-12 16:04:52 +02:00
|
|
|
push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
|
|
|
|
ER_TABLE_EXISTS_ERROR,
|
|
|
|
"Local table %s.%s shadows ndb table",
|
|
|
|
db, file_name);
|
2006-09-13 18:49:05 +02:00
|
|
|
}
|
2006-09-12 16:04:52 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (file_on_disk)
|
|
|
|
{
|
2006-09-13 18:49:05 +02:00
|
|
|
// File existed in NDB and as frm file, put in ok_tables list
|
2006-09-12 16:04:52 +02:00
|
|
|
my_hash_insert(&ok_tables, (byte*)file_name);
|
2004-09-26 16:11:24 +02:00
|
|
|
continue;
|
2004-09-13 14:46:38 +02:00
|
|
|
}
|
2004-09-26 16:11:24 +02:00
|
|
|
DBUG_PRINT("info", ("%s existed on disk", name));
|
|
|
|
// The .ndb file exists on disk, but it's not in list of tables in ndb
|
|
|
|
// Verify that handler agrees table is gone.
|
2006-09-30 21:49:46 +02:00
|
|
|
if (ndbcluster_table_exists_in_engine(hton, thd, db, file_name) == 0)
|
2004-09-26 16:11:24 +02:00
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("NDB says %s does not exists", file_name));
|
|
|
|
it.remove();
|
|
|
|
// Put in list of tables to remove from disk
|
|
|
|
delete_list.push_back(thd->strdup(file_name));
|
|
|
|
}
|
|
|
|
}
|
2004-09-21 12:13:58 +02:00
|
|
|
|
2006-01-12 19:51:02 +01:00
|
|
|
#ifdef HAVE_NDB_BINLOG
|
|
|
|
/* setup logging to binlog for all discovered tables */
|
|
|
|
{
|
2006-02-16 03:23:43 +01:00
|
|
|
char *end, *end1= name +
|
2006-08-02 17:57:06 +02:00
|
|
|
build_table_filename(name, sizeof(name), db, "", "", 0);
|
2006-01-12 19:51:02 +01:00
|
|
|
for (i= 0; i < ok_tables.records; i++)
|
|
|
|
{
|
|
|
|
file_name= (char*)hash_element(&ok_tables, i);
|
2006-02-16 03:23:43 +01:00
|
|
|
end= end1 +
|
|
|
|
tablename_to_filename(file_name, end1, sizeof(name) - (end1 - name));
|
2006-01-31 15:40:26 +01:00
|
|
|
pthread_mutex_lock(&LOCK_open);
|
|
|
|
ndbcluster_create_binlog_setup(ndb, name, end-name,
|
|
|
|
db, file_name, TRUE);
|
|
|
|
pthread_mutex_unlock(&LOCK_open);
|
2006-01-12 19:51:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-09-26 16:11:24 +02:00
|
|
|
// Check for new files to discover
|
|
|
|
DBUG_PRINT("info", ("Checking for new files to discover"));
|
|
|
|
List<char> create_list;
|
|
|
|
for (i= 0 ; i < ndb_tables.records ; i++)
|
2004-09-21 12:13:58 +02:00
|
|
|
{
|
2004-09-26 16:11:24 +02:00
|
|
|
file_name= hash_element(&ndb_tables, i);
|
|
|
|
if (!hash_search(&ok_tables, file_name, strlen(file_name)))
|
2004-09-21 12:13:58 +02:00
|
|
|
{
|
2006-08-02 17:57:06 +02:00
|
|
|
build_table_filename(name, sizeof(name), db, file_name, reg_ext, 0);
|
2006-02-16 03:23:43 +01:00
|
|
|
if (my_access(name, F_OK))
|
2005-11-06 00:20:37 +01:00
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("%s must be discovered", file_name));
|
|
|
|
// File is in list of ndb tables and not in ok_tables
|
|
|
|
// This table need to be created
|
|
|
|
create_list.push_back(thd->strdup(file_name));
|
|
|
|
}
|
2004-09-26 16:11:24 +02:00
|
|
|
}
|
|
|
|
}
|
2004-09-21 12:13:58 +02:00
|
|
|
|
2004-09-26 16:11:24 +02:00
|
|
|
// Lock mutex before deleting and creating frm files
|
|
|
|
pthread_mutex_lock(&LOCK_open);
|
2004-09-21 12:13:58 +02:00
|
|
|
|
2004-09-26 16:11:24 +02:00
|
|
|
if (!global_read_lock)
|
|
|
|
{
|
|
|
|
// Delete old files
|
|
|
|
List_iterator_fast<char> it3(delete_list);
|
|
|
|
while ((file_name=it3++))
|
2005-02-17 14:22:44 +01:00
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("Remove table %s/%s", db, file_name));
|
2004-09-26 16:11:24 +02:00
|
|
|
// Delete the table and all related files
|
|
|
|
TABLE_LIST table_list;
|
|
|
|
bzero((char*) &table_list,sizeof(table_list));
|
|
|
|
table_list.db= (char*) db;
|
2005-01-06 12:00:13 +01:00
|
|
|
table_list.alias= table_list.table_name= (char*)file_name;
|
2005-02-17 14:22:44 +01:00
|
|
|
(void)mysql_rm_table_part2(thd, &table_list,
|
2005-02-21 16:13:29 +01:00
|
|
|
/* if_exists */ FALSE,
|
|
|
|
/* drop_temporary */ FALSE,
|
|
|
|
/* drop_view */ FALSE,
|
|
|
|
/* dont_log_query*/ TRUE);
|
2005-02-17 14:22:44 +01:00
|
|
|
/* Clear error message that is returned when table is deleted */
|
|
|
|
thd->clear_error();
|
2004-09-21 12:13:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-26 16:11:24 +02:00
|
|
|
// Create new files
|
|
|
|
List_iterator_fast<char> it2(create_list);
|
|
|
|
while ((file_name=it2++))
|
|
|
|
{
|
2005-06-02 14:32:06 +02:00
|
|
|
DBUG_PRINT("info", ("Table %s need discovery", file_name));
|
2006-01-31 01:37:48 +01:00
|
|
|
if (ndb_create_table_from_engine(thd, db, file_name) == 0)
|
2004-10-07 09:16:46 +02:00
|
|
|
files->push_back(thd->strdup(file_name));
|
2004-09-26 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2005-11-23 21:45:02 +01:00
|
|
|
pthread_mutex_unlock(&LOCK_open);
|
2004-09-26 16:11:24 +02:00
|
|
|
|
|
|
|
hash_free(&ok_tables);
|
2004-09-21 12:13:58 +02:00
|
|
|
hash_free(&ndb_tables);
|
2004-10-25 22:35:46 +02:00
|
|
|
} // extra bracket to avoid gcc 2.95.3 warning
|
2004-09-21 12:13:58 +02:00
|
|
|
DBUG_RETURN(0);
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Initialise all gloal variables before creating
|
|
|
|
a NDB Cluster table handler
|
|
|
|
*/
|
|
|
|
|
2005-01-14 12:32:33 +01:00
|
|
|
/* Call back after cluster connect */
|
|
|
|
static int connect_callback()
|
|
|
|
{
|
|
|
|
update_status_variables(g_ndb_cluster_connection);
|
2006-01-12 19:51:02 +01:00
|
|
|
|
|
|
|
uint node_id, i= 0;
|
|
|
|
Ndb_cluster_connection_node_iter node_iter;
|
|
|
|
memset((void *)g_node_id_map, 0xFFFF, sizeof(g_node_id_map));
|
|
|
|
while ((node_id= g_ndb_cluster_connection->get_next_node(node_iter)))
|
|
|
|
g_node_id_map[node_id]= i++;
|
|
|
|
|
2005-11-06 00:20:37 +01:00
|
|
|
pthread_cond_signal(&COND_ndb_util_thread);
|
2005-01-14 12:32:33 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-05-04 13:58:17 +02:00
|
|
|
extern int ndb_dictionary_is_mysqld;
|
2006-05-28 14:51:01 +02:00
|
|
|
|
2006-09-15 19:28:00 +02:00
|
|
|
static int ndbcluster_init(void *p)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
2004-09-13 06:40:25 +02:00
|
|
|
int res;
|
2004-04-15 09:14:14 +02:00
|
|
|
DBUG_ENTER("ndbcluster_init");
|
2005-10-03 04:44:28 +02:00
|
|
|
|
2006-05-04 13:58:17 +02:00
|
|
|
ndb_dictionary_is_mysqld= 1;
|
2006-09-15 19:28:00 +02:00
|
|
|
ndbcluster_hton= (handlerton *)p;
|
|
|
|
|
|
|
|
{
|
|
|
|
handlerton *h= ndbcluster_hton;
|
|
|
|
h->state= have_ndbcluster;
|
|
|
|
h->db_type= DB_TYPE_NDBCLUSTER;
|
|
|
|
h->close_connection= ndbcluster_close_connection;
|
|
|
|
h->commit= ndbcluster_commit;
|
|
|
|
h->rollback= ndbcluster_rollback;
|
|
|
|
h->create= ndbcluster_create_handler; /* Create a new handler */
|
|
|
|
h->drop_database= ndbcluster_drop_database; /* Drop a database */
|
|
|
|
h->panic= ndbcluster_end; /* Panic call */
|
|
|
|
h->show_status= ndbcluster_show_status; /* Show status */
|
|
|
|
h->alter_tablespace= ndbcluster_alter_tablespace; /* Show status */
|
|
|
|
h->partition_flags= ndbcluster_partition_flags; /* Partition flags */
|
|
|
|
h->alter_table_flags=ndbcluster_alter_table_flags; /* Alter table flags */
|
|
|
|
h->fill_files_table= ndbcluster_fill_files_table;
|
2006-01-12 19:51:02 +01:00
|
|
|
#ifdef HAVE_NDB_BINLOG
|
|
|
|
ndbcluster_binlog_init_handlerton();
|
|
|
|
#endif
|
2006-09-15 19:28:00 +02:00
|
|
|
h->flags= HTON_CAN_RECREATE | HTON_TEMPORARY_NOT_SUPPORTED;
|
|
|
|
h->discover= ndbcluster_discover;
|
|
|
|
h->find_files= ndbcluster_find_files;
|
|
|
|
h->table_exists_in_engine= ndbcluster_table_exists_in_engine;
|
2006-01-12 19:51:02 +01:00
|
|
|
}
|
|
|
|
|
2006-05-28 14:51:01 +02:00
|
|
|
if (have_ndbcluster != SHOW_OPTION_YES)
|
|
|
|
DBUG_RETURN(0); // nothing else to do
|
|
|
|
|
2006-08-30 11:41:21 +02:00
|
|
|
// Initialize ndb interface
|
|
|
|
ndb_init_internal();
|
|
|
|
|
2004-08-20 18:10:47 +02:00
|
|
|
// Set connectstring if specified
|
2004-12-20 12:36:14 +01:00
|
|
|
if (opt_ndbcluster_connectstring != 0)
|
|
|
|
DBUG_PRINT("connectstring", ("%s", opt_ndbcluster_connectstring));
|
2004-09-06 20:30:57 +02:00
|
|
|
if ((g_ndb_cluster_connection=
|
2004-12-20 12:36:14 +01:00
|
|
|
new Ndb_cluster_connection(opt_ndbcluster_connectstring)) == 0)
|
2004-09-06 20:30:57 +02:00
|
|
|
{
|
2004-12-20 12:36:14 +01:00
|
|
|
DBUG_PRINT("error",("Ndb_cluster_connection(%s)",
|
2005-02-16 14:18:32 +01:00
|
|
|
opt_ndbcluster_connectstring));
|
2004-11-30 18:47:47 +01:00
|
|
|
goto ndbcluster_init_error;
|
2004-08-20 18:10:47 +02:00
|
|
|
}
|
2006-02-13 12:58:12 +01:00
|
|
|
{
|
|
|
|
char buf[128];
|
|
|
|
my_snprintf(buf, sizeof(buf), "mysqld --server-id=%d", server_id);
|
|
|
|
g_ndb_cluster_connection->set_name(buf);
|
|
|
|
}
|
2004-12-20 12:36:14 +01:00
|
|
|
g_ndb_cluster_connection->set_optimized_node_selection
|
|
|
|
(opt_ndb_optimized_node_selection);
|
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
// Create a Ndb object to open the connection to NDB
|
2005-02-21 23:29:07 +01:00
|
|
|
if ( (g_ndb= new Ndb(g_ndb_cluster_connection, "sys")) == 0 )
|
|
|
|
{
|
|
|
|
DBUG_PRINT("error", ("failed to create global ndb object"));
|
|
|
|
goto ndbcluster_init_error;
|
|
|
|
}
|
2004-04-15 09:14:14 +02:00
|
|
|
if (g_ndb->init() != 0)
|
|
|
|
{
|
|
|
|
ERR_PRINT (g_ndb->getNdbError());
|
2004-11-30 18:47:47 +01:00
|
|
|
goto ndbcluster_init_error;
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
2004-09-13 06:40:25 +02:00
|
|
|
|
2004-11-30 18:47:47 +01:00
|
|
|
if ((res= g_ndb_cluster_connection->connect(0,0,0)) == 0)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
2005-01-14 12:32:33 +01:00
|
|
|
connect_callback();
|
2004-11-30 18:47:47 +01:00
|
|
|
DBUG_PRINT("info",("NDBCLUSTER storage engine at %s on port %d",
|
2005-02-16 14:18:32 +01:00
|
|
|
g_ndb_cluster_connection->get_connected_host(),
|
|
|
|
g_ndb_cluster_connection->get_connected_port()));
|
2005-02-24 18:58:56 +01:00
|
|
|
g_ndb_cluster_connection->wait_until_ready(10,3);
|
2004-09-13 06:40:25 +02:00
|
|
|
}
|
2005-07-04 02:42:33 +02:00
|
|
|
else if (res == 1)
|
2004-09-13 06:40:25 +02:00
|
|
|
{
|
2005-01-14 12:32:33 +01:00
|
|
|
if (g_ndb_cluster_connection->start_connect_thread(connect_callback))
|
2005-01-11 17:00:31 +01:00
|
|
|
{
|
2004-09-27 02:24:23 +02:00
|
|
|
DBUG_PRINT("error", ("g_ndb_cluster_connection->start_connect_thread()"));
|
2004-11-30 18:47:47 +01:00
|
|
|
goto ndbcluster_init_error;
|
|
|
|
}
|
2005-01-11 17:00:31 +01:00
|
|
|
#ifndef DBUG_OFF
|
2004-11-30 18:47:47 +01:00
|
|
|
{
|
|
|
|
char buf[1024];
|
2005-01-11 17:00:31 +01:00
|
|
|
DBUG_PRINT("info",
|
2005-02-16 14:18:32 +01:00
|
|
|
("NDBCLUSTER storage engine not started, "
|
|
|
|
"will connect using %s",
|
|
|
|
g_ndb_cluster_connection->
|
|
|
|
get_connectstring(buf,sizeof(buf))));
|
2004-09-27 02:24:23 +02:00
|
|
|
}
|
2005-01-11 17:00:31 +01:00
|
|
|
#endif
|
2004-09-13 06:40:25 +02:00
|
|
|
}
|
2004-09-27 02:24:23 +02:00
|
|
|
else
|
2004-09-13 06:40:25 +02:00
|
|
|
{
|
|
|
|
DBUG_ASSERT(res == -1);
|
|
|
|
DBUG_PRINT("error", ("permanent error"));
|
2004-11-30 18:47:47 +01:00
|
|
|
goto ndbcluster_init_error;
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
2004-09-13 06:40:25 +02:00
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
(void) hash_init(&ndbcluster_open_tables,system_charset_info,32,0,0,
|
|
|
|
(hash_get_key) ndbcluster_get_key,0,0);
|
|
|
|
pthread_mutex_init(&ndbcluster_mutex,MY_MUTEX_INIT_FAST);
|
2006-01-12 19:51:02 +01:00
|
|
|
#ifdef HAVE_NDB_BINLOG
|
|
|
|
/* start the ndb injector thread */
|
2006-02-01 01:12:11 +01:00
|
|
|
if (ndbcluster_binlog_start())
|
|
|
|
goto ndbcluster_init_error;
|
2006-01-12 19:51:02 +01:00
|
|
|
#endif /* HAVE_NDB_BINLOG */
|
2006-05-28 14:51:01 +02:00
|
|
|
|
2005-02-11 22:33:52 +01:00
|
|
|
pthread_mutex_init(&LOCK_ndb_util_thread, MY_MUTEX_INIT_FAST);
|
|
|
|
pthread_cond_init(&COND_ndb_util_thread, NULL);
|
2004-09-14 10:52:21 +02:00
|
|
|
|
2005-02-11 22:33:52 +01:00
|
|
|
|
2006-08-15 14:22:47 +02:00
|
|
|
ndb_cache_check_time = opt_ndb_cache_check_time;
|
2005-02-11 22:33:52 +01:00
|
|
|
// Create utility thread
|
|
|
|
pthread_t tmp;
|
|
|
|
if (pthread_create(&tmp, &connection_attrib, ndb_util_thread_func, 0))
|
|
|
|
{
|
|
|
|
DBUG_PRINT("error", ("Could not create ndb utility thread"));
|
2005-02-21 23:29:07 +01:00
|
|
|
hash_free(&ndbcluster_open_tables);
|
|
|
|
pthread_mutex_destroy(&ndbcluster_mutex);
|
|
|
|
pthread_mutex_destroy(&LOCK_ndb_util_thread);
|
|
|
|
pthread_cond_destroy(&COND_ndb_util_thread);
|
2005-02-11 22:33:52 +01:00
|
|
|
goto ndbcluster_init_error;
|
|
|
|
}
|
2006-05-28 14:51:01 +02:00
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
ndbcluster_inited= 1;
|
2005-10-03 04:44:28 +02:00
|
|
|
DBUG_RETURN(FALSE);
|
2005-02-11 22:33:52 +01:00
|
|
|
|
2005-10-03 04:44:28 +02:00
|
|
|
ndbcluster_init_error:
|
2005-07-04 02:42:33 +02:00
|
|
|
if (g_ndb)
|
2005-02-21 23:29:07 +01:00
|
|
|
delete g_ndb;
|
|
|
|
g_ndb= NULL;
|
|
|
|
if (g_ndb_cluster_connection)
|
|
|
|
delete g_ndb_cluster_connection;
|
|
|
|
g_ndb_cluster_connection= NULL;
|
2005-10-03 04:44:28 +02:00
|
|
|
have_ndbcluster= SHOW_OPTION_DISABLED; // If we couldn't use handler
|
2006-09-15 19:28:00 +02:00
|
|
|
ndbcluster_hton->state= SHOW_OPTION_DISABLED; // If we couldn't use handler
|
|
|
|
|
2005-10-03 04:44:28 +02:00
|
|
|
DBUG_RETURN(TRUE);
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
|
2006-09-30 21:49:46 +02:00
|
|
|
static int ndbcluster_end(handlerton *hton, ha_panic_function type)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
|
|
|
DBUG_ENTER("ndbcluster_end");
|
2005-02-11 22:33:52 +01:00
|
|
|
|
2005-02-21 23:29:07 +01:00
|
|
|
if (!ndbcluster_inited)
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
|
2006-05-04 13:58:17 +02:00
|
|
|
#ifdef HAVE_NDB_BINLOG
|
|
|
|
{
|
|
|
|
pthread_mutex_lock(&ndbcluster_mutex);
|
2006-05-05 15:34:46 +02:00
|
|
|
while (ndbcluster_open_tables.records)
|
2006-05-04 13:58:17 +02:00
|
|
|
{
|
|
|
|
NDB_SHARE *share=
|
2006-05-05 15:34:46 +02:00
|
|
|
(NDB_SHARE*) hash_element(&ndbcluster_open_tables, 0);
|
2006-05-04 13:58:17 +02:00
|
|
|
#ifndef DBUG_OFF
|
|
|
|
fprintf(stderr, "NDB: table share %s with use_count %d not freed\n",
|
|
|
|
share->key, share->use_count);
|
|
|
|
#endif
|
|
|
|
real_free_share(&share);
|
|
|
|
}
|
|
|
|
pthread_mutex_unlock(&ndbcluster_mutex);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
hash_free(&ndbcluster_open_tables);
|
|
|
|
|
2005-07-04 02:42:33 +02:00
|
|
|
if (g_ndb)
|
2005-11-17 12:45:23 +01:00
|
|
|
{
|
|
|
|
#ifndef DBUG_OFF
|
2006-01-05 23:47:49 +01:00
|
|
|
Ndb::Free_list_usage tmp;
|
|
|
|
tmp.m_name= 0;
|
2005-11-17 12:45:23 +01:00
|
|
|
while (g_ndb->get_free_list_usage(&tmp))
|
|
|
|
{
|
|
|
|
uint leaked= (uint) tmp.m_created - tmp.m_free;
|
|
|
|
if (leaked)
|
|
|
|
fprintf(stderr, "NDB: Found %u %s%s that %s not been released\n",
|
|
|
|
leaked, tmp.m_name,
|
|
|
|
(leaked == 1)?"":"'s",
|
|
|
|
(leaked == 1)?"has":"have");
|
|
|
|
}
|
|
|
|
#endif
|
2004-09-13 06:40:25 +02:00
|
|
|
delete g_ndb;
|
2006-01-05 23:47:49 +01:00
|
|
|
g_ndb= NULL;
|
2005-11-17 12:45:23 +01:00
|
|
|
}
|
2006-01-05 23:47:49 +01:00
|
|
|
delete g_ndb_cluster_connection;
|
2004-09-06 20:30:57 +02:00
|
|
|
g_ndb_cluster_connection= NULL;
|
2005-02-21 23:29:07 +01:00
|
|
|
|
2006-08-30 11:41:21 +02:00
|
|
|
// cleanup ndb interface
|
|
|
|
ndb_end_internal();
|
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
pthread_mutex_destroy(&ndbcluster_mutex);
|
2005-02-11 22:33:52 +01:00
|
|
|
pthread_mutex_destroy(&LOCK_ndb_util_thread);
|
|
|
|
pthread_cond_destroy(&COND_ndb_util_thread);
|
2004-04-15 09:14:14 +02:00
|
|
|
ndbcluster_inited= 0;
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
2006-01-17 08:40:00 +01:00
|
|
|
void ha_ndbcluster::print_error(int error, myf errflag)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_ndbcluster::print_error");
|
|
|
|
DBUG_PRINT("enter", ("error = %d", error));
|
|
|
|
|
|
|
|
if (error == HA_ERR_NO_PARTITION_FOUND)
|
2006-06-15 01:40:06 +02:00
|
|
|
m_part_info->print_no_partition_found(table);
|
2006-01-17 08:40:00 +01:00
|
|
|
else
|
|
|
|
handler::print_error(error, errflag);
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-06-23 15:34:45 +02:00
|
|
|
/*
|
|
|
|
Static error print function called from
|
|
|
|
static handler method ndbcluster_commit
|
|
|
|
and ndbcluster_rollback
|
|
|
|
*/
|
2004-07-02 16:14:08 +02:00
|
|
|
|
|
|
|
void ndbcluster_print_error(int error, const NdbOperation *error_op)
|
2004-06-22 09:54:00 +02:00
|
|
|
{
|
2004-06-23 15:34:45 +02:00
|
|
|
DBUG_ENTER("ndbcluster_print_error");
|
2005-11-23 21:45:02 +01:00
|
|
|
TABLE_SHARE share;
|
2004-07-02 16:14:08 +02:00
|
|
|
const char *tab_name= (error_op) ? error_op->getTableName() : "";
|
2005-11-23 21:45:02 +01:00
|
|
|
share.db.str= (char*) "";
|
|
|
|
share.db.length= 0;
|
|
|
|
share.table_name.str= (char *) tab_name;
|
|
|
|
share.table_name.length= strlen(tab_name);
|
2006-09-30 02:19:02 +02:00
|
|
|
ha_ndbcluster error_handler(ndbcluster_hton, &share);
|
2004-06-23 15:34:45 +02:00
|
|
|
error_handler.print_error(error, MYF(0));
|
2004-07-06 08:43:57 +02:00
|
|
|
DBUG_VOID_RETURN;
|
2004-06-22 09:54:00 +02:00
|
|
|
}
|
2004-04-15 09:14:14 +02:00
|
|
|
|
2005-04-22 15:28:23 +02:00
|
|
|
/**
|
|
|
|
* Set a given location from full pathname to database name
|
|
|
|
*
|
2004-04-15 09:14:14 +02:00
|
|
|
*/
|
2005-04-22 15:28:23 +02:00
|
|
|
void ha_ndbcluster::set_dbname(const char *path_name, char *dbname)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
2006-01-17 08:40:00 +01:00
|
|
|
char *end, *ptr, *tmp_name;
|
|
|
|
char tmp_buff[FN_REFLEN];
|
|
|
|
|
|
|
|
tmp_name= tmp_buff;
|
2004-04-15 09:14:14 +02:00
|
|
|
/* Scan name from the end */
|
2005-04-22 15:28:23 +02:00
|
|
|
ptr= strend(path_name)-1;
|
|
|
|
while (ptr >= path_name && *ptr != '\\' && *ptr != '/') {
|
|
|
|
ptr--;
|
|
|
|
}
|
|
|
|
ptr--;
|
|
|
|
end= ptr;
|
2004-04-15 09:14:14 +02:00
|
|
|
while (ptr >= path_name && *ptr != '\\' && *ptr != '/') {
|
|
|
|
ptr--;
|
|
|
|
}
|
|
|
|
uint name_len= end - ptr;
|
2006-01-17 08:40:00 +01:00
|
|
|
memcpy(tmp_name, ptr + 1, name_len);
|
|
|
|
tmp_name[name_len]= '\0';
|
2004-04-15 09:14:14 +02:00
|
|
|
#ifdef __WIN__
|
|
|
|
/* Put to lower case */
|
2005-04-22 15:28:23 +02:00
|
|
|
|
2006-01-17 08:40:00 +01:00
|
|
|
ptr= tmp_name;
|
2004-04-15 09:14:14 +02:00
|
|
|
|
|
|
|
while (*ptr != '\0') {
|
2004-07-23 15:46:56 +02:00
|
|
|
*ptr= tolower(*ptr);
|
2004-04-15 09:14:14 +02:00
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
#endif
|
2006-01-17 08:40:00 +01:00
|
|
|
filename_to_tablename(tmp_name, dbname, FN_REFLEN);
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
|
2005-04-22 15:28:23 +02:00
|
|
|
/*
|
|
|
|
Set m_dbname from full pathname to table file
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ha_ndbcluster::set_dbname(const char *path_name)
|
|
|
|
{
|
|
|
|
set_dbname(path_name, m_dbname);
|
|
|
|
}
|
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
/**
|
|
|
|
* Set a given location from full pathname to table file
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ha_ndbcluster::set_tabname(const char *path_name, char * tabname)
|
|
|
|
{
|
2006-01-17 08:40:00 +01:00
|
|
|
char *end, *ptr, *tmp_name;
|
|
|
|
char tmp_buff[FN_REFLEN];
|
|
|
|
|
|
|
|
tmp_name= tmp_buff;
|
2004-04-15 09:14:14 +02:00
|
|
|
/* Scan name from the end */
|
2004-07-23 15:46:56 +02:00
|
|
|
end= strend(path_name)-1;
|
|
|
|
ptr= end;
|
2004-04-15 09:14:14 +02:00
|
|
|
while (ptr >= path_name && *ptr != '\\' && *ptr != '/') {
|
|
|
|
ptr--;
|
|
|
|
}
|
2004-07-23 15:46:56 +02:00
|
|
|
uint name_len= end - ptr;
|
2006-01-17 08:40:00 +01:00
|
|
|
memcpy(tmp_name, ptr + 1, end - ptr);
|
|
|
|
tmp_name[name_len]= '\0';
|
2004-04-15 09:14:14 +02:00
|
|
|
#ifdef __WIN__
|
|
|
|
/* Put to lower case */
|
2006-01-17 08:40:00 +01:00
|
|
|
ptr= tmp_name;
|
2004-04-15 09:14:14 +02:00
|
|
|
|
|
|
|
while (*ptr != '\0') {
|
|
|
|
*ptr= tolower(*ptr);
|
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
#endif
|
2006-01-17 08:40:00 +01:00
|
|
|
filename_to_tablename(tmp_name, tabname, FN_REFLEN);
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2005-04-22 15:28:23 +02:00
|
|
|
Set m_tabname from full pathname to table file
|
2004-04-15 09:14:14 +02:00
|
|
|
*/
|
|
|
|
|
2005-04-22 15:28:23 +02:00
|
|
|
void ha_ndbcluster::set_tabname(const char *path_name)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
2005-04-22 15:28:23 +02:00
|
|
|
set_tabname(path_name, m_tabname);
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ha_rows
|
2004-05-16 13:48:32 +02:00
|
|
|
ha_ndbcluster::records_in_range(uint inx, key_range *min_key,
|
|
|
|
key_range *max_key)
|
|
|
|
{
|
|
|
|
KEY *key_info= table->key_info + inx;
|
2004-04-15 09:14:14 +02:00
|
|
|
uint key_length= key_info->key_length;
|
2004-05-24 12:35:39 +02:00
|
|
|
NDB_INDEX_TYPE idx_type= get_index_type(inx);
|
2004-04-15 09:14:14 +02:00
|
|
|
|
|
|
|
DBUG_ENTER("records_in_range");
|
2004-05-24 12:35:39 +02:00
|
|
|
// Prevent partial read of hash indexes by returning HA_POS_ERROR
|
|
|
|
if ((idx_type == UNIQUE_INDEX || idx_type == PRIMARY_KEY_INDEX) &&
|
|
|
|
((min_key && min_key->length < key_length) ||
|
|
|
|
(max_key && max_key->length < key_length)))
|
|
|
|
DBUG_RETURN(HA_POS_ERROR);
|
|
|
|
|
|
|
|
// Read from hash index with full key
|
|
|
|
// This is a "const" table which returns only one record!
|
|
|
|
if ((idx_type != ORDERED_INDEX) &&
|
|
|
|
((min_key && min_key->length == key_length) ||
|
|
|
|
(max_key && max_key->length == key_length)))
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
|
2005-09-15 02:33:28 +02:00
|
|
|
if ((idx_type == PRIMARY_KEY_ORDERED_INDEX ||
|
|
|
|
idx_type == UNIQUE_ORDERED_INDEX ||
|
|
|
|
idx_type == ORDERED_INDEX) &&
|
|
|
|
m_index[inx].index_stat != NULL)
|
|
|
|
{
|
|
|
|
NDB_INDEX_DATA& d=m_index[inx];
|
2006-05-04 13:58:17 +02:00
|
|
|
const NDBINDEX* index= d.index;
|
2005-09-15 02:33:28 +02:00
|
|
|
Ndb* ndb=get_ndb();
|
|
|
|
NdbTransaction* trans=NULL;
|
|
|
|
NdbIndexScanOperation* op=NULL;
|
|
|
|
int res=0;
|
|
|
|
Uint64 rows;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
// We must provide approx table rows
|
|
|
|
Uint64 table_rows=0;
|
2006-04-19 18:29:25 +02:00
|
|
|
Ndb_local_table_statistics *info= m_table_info;
|
2005-09-15 02:33:28 +02:00
|
|
|
if (info->records != ~(ha_rows)0 && info->records != 0)
|
|
|
|
{
|
|
|
|
table_rows = info->records;
|
|
|
|
DBUG_PRINT("info", ("use info->records: %llu", table_rows));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Ndb_statistics stat;
|
2006-05-04 13:58:17 +02:00
|
|
|
if ((res=ndb_get_table_statistics(ndb, m_table, &stat)) != 0)
|
2005-09-15 02:33:28 +02:00
|
|
|
break;
|
|
|
|
table_rows=stat.row_count;
|
|
|
|
DBUG_PRINT("info", ("use db row_count: %llu", table_rows));
|
|
|
|
if (table_rows == 0) {
|
|
|
|
// Problem if autocommit=0
|
|
|
|
#ifdef ndb_get_table_statistics_uses_active_trans
|
|
|
|
rows=0;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Define scan op for the range
|
2006-05-05 14:25:57 +02:00
|
|
|
if ((trans=m_active_trans) == NULL ||
|
|
|
|
trans->commitStatus() != NdbTransaction::Started)
|
2005-09-15 02:33:28 +02:00
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("no active trans"));
|
|
|
|
if (! (trans=ndb->startTransaction()))
|
|
|
|
ERR_BREAK(ndb->getNdbError(), res);
|
|
|
|
}
|
|
|
|
if (! (op=trans->getNdbIndexScanOperation(index, (NDBTAB*)m_table)))
|
|
|
|
ERR_BREAK(trans->getNdbError(), res);
|
|
|
|
if ((op->readTuples(NdbOperation::LM_CommittedRead)) == -1)
|
|
|
|
ERR_BREAK(op->getNdbError(), res);
|
|
|
|
const key_range *keys[2]={ min_key, max_key };
|
|
|
|
if ((res=set_bounds(op, inx, true, keys)) != 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Decide if db should be contacted
|
|
|
|
int flags=0;
|
|
|
|
if (d.index_stat_query_count < d.index_stat_cache_entries ||
|
|
|
|
(d.index_stat_update_freq != 0 &&
|
|
|
|
d.index_stat_query_count % d.index_stat_update_freq == 0))
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("force stat from db"));
|
|
|
|
flags|=NdbIndexStat::RR_UseDb;
|
|
|
|
}
|
|
|
|
if (d.index_stat->records_in_range(index, op, table_rows, &rows, flags) == -1)
|
|
|
|
ERR_BREAK(d.index_stat->getNdbError(), res);
|
|
|
|
d.index_stat_query_count++;
|
|
|
|
} while (0);
|
|
|
|
|
|
|
|
if (trans != m_active_trans && rows == 0)
|
|
|
|
rows = 1;
|
|
|
|
if (trans != m_active_trans && trans != NULL)
|
|
|
|
ndb->closeTransaction(trans);
|
|
|
|
if (res != 0)
|
|
|
|
DBUG_RETURN(HA_POS_ERROR);
|
|
|
|
DBUG_RETURN(rows);
|
|
|
|
}
|
|
|
|
|
2004-05-24 12:35:39 +02:00
|
|
|
DBUG_RETURN(10); /* Good guess when you don't know anything */
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
ulonglong ha_ndbcluster::table_flags(void) const
|
2004-11-17 09:15:53 +01:00
|
|
|
{
|
|
|
|
if (m_ha_not_exact_count)
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
return m_table_flags & ~HA_STATS_RECORDS_IS_EXACT;
|
|
|
|
return m_table_flags;
|
2004-11-17 09:15:53 +01:00
|
|
|
}
|
|
|
|
const char * ha_ndbcluster::table_type() const
|
|
|
|
{
|
2005-09-21 04:16:24 +02:00
|
|
|
return("NDBCLUSTER");
|
2004-11-17 09:15:53 +01:00
|
|
|
}
|
|
|
|
uint ha_ndbcluster::max_supported_record_length() const
|
|
|
|
{
|
|
|
|
return NDB_MAX_TUPLE_SIZE;
|
|
|
|
}
|
|
|
|
uint ha_ndbcluster::max_supported_keys() const
|
|
|
|
{
|
|
|
|
return MAX_KEY;
|
|
|
|
}
|
|
|
|
uint ha_ndbcluster::max_supported_key_parts() const
|
|
|
|
{
|
|
|
|
return NDB_MAX_NO_OF_ATTRIBUTES_IN_KEY;
|
|
|
|
}
|
|
|
|
uint ha_ndbcluster::max_supported_key_length() const
|
|
|
|
{
|
|
|
|
return NDB_MAX_KEY_SIZE;
|
|
|
|
}
|
2006-02-07 19:57:31 +01:00
|
|
|
uint ha_ndbcluster::max_supported_key_part_length() const
|
|
|
|
{
|
|
|
|
return NDB_MAX_KEY_SIZE;
|
|
|
|
}
|
2004-11-17 09:15:53 +01:00
|
|
|
bool ha_ndbcluster::low_byte_first() const
|
|
|
|
{
|
|
|
|
#ifdef WORDS_BIGENDIAN
|
|
|
|
return FALSE;
|
|
|
|
#else
|
|
|
|
return TRUE;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
const char* ha_ndbcluster::index_type(uint key_number)
|
|
|
|
{
|
|
|
|
switch (get_index_type(key_number)) {
|
|
|
|
case ORDERED_INDEX:
|
|
|
|
case UNIQUE_ORDERED_INDEX:
|
|
|
|
case PRIMARY_KEY_ORDERED_INDEX:
|
|
|
|
return "BTREE";
|
|
|
|
case UNIQUE_INDEX:
|
|
|
|
case PRIMARY_KEY_INDEX:
|
|
|
|
default:
|
|
|
|
return "HASH";
|
|
|
|
}
|
|
|
|
}
|
2005-02-11 22:33:52 +01:00
|
|
|
|
2004-11-17 09:15:53 +01:00
|
|
|
uint8 ha_ndbcluster::table_cache_type()
|
|
|
|
{
|
2005-02-11 22:33:52 +01:00
|
|
|
DBUG_ENTER("ha_ndbcluster::table_cache_type=HA_CACHE_TBL_ASKTRANSACT");
|
|
|
|
DBUG_RETURN(HA_CACHE_TBL_ASKTRANSACT);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint ndb_get_commitcount(THD *thd, char *dbname, char *tabname,
|
2005-02-16 14:18:32 +01:00
|
|
|
Uint64 *commit_count)
|
2005-02-11 22:33:52 +01:00
|
|
|
{
|
2005-03-15 15:03:25 +01:00
|
|
|
char name[FN_REFLEN];
|
|
|
|
NDB_SHARE *share;
|
2005-11-23 21:45:02 +01:00
|
|
|
DBUG_ENTER("ndb_get_commitcount");
|
|
|
|
|
2006-08-02 17:57:06 +02:00
|
|
|
build_table_filename(name, sizeof(name), dbname, tabname, "", 0);
|
2005-03-15 15:03:25 +01:00
|
|
|
DBUG_PRINT("enter", ("name: %s", name));
|
|
|
|
pthread_mutex_lock(&ndbcluster_mutex);
|
|
|
|
if (!(share=(NDB_SHARE*) hash_search(&ndbcluster_open_tables,
|
|
|
|
(byte*) name,
|
|
|
|
strlen(name))))
|
|
|
|
{
|
|
|
|
pthread_mutex_unlock(&ndbcluster_mutex);
|
2005-11-06 00:20:37 +01:00
|
|
|
DBUG_PRINT("info", ("Table %s not found in ndbcluster_open_tables", name));
|
2005-03-15 15:03:25 +01:00
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
|
|
|
share->use_count++;
|
|
|
|
pthread_mutex_unlock(&ndbcluster_mutex);
|
|
|
|
|
|
|
|
pthread_mutex_lock(&share->mutex);
|
2005-02-11 22:33:52 +01:00
|
|
|
if (ndb_cache_check_time > 0)
|
|
|
|
{
|
2005-03-15 15:03:25 +01:00
|
|
|
if (share->commit_count != 0)
|
2005-02-11 22:33:52 +01:00
|
|
|
{
|
2005-03-15 15:03:25 +01:00
|
|
|
*commit_count= share->commit_count;
|
2006-06-30 18:15:18 +02:00
|
|
|
char buff[22];
|
|
|
|
DBUG_PRINT("info", ("Getting commit_count: %s from share",
|
|
|
|
llstr(share->commit_count, buff)));
|
2005-03-15 15:03:25 +01:00
|
|
|
pthread_mutex_unlock(&share->mutex);
|
2005-11-06 00:20:37 +01:00
|
|
|
free_share(&share);
|
2005-03-15 15:03:25 +01:00
|
|
|
DBUG_RETURN(0);
|
2005-02-11 22:33:52 +01:00
|
|
|
}
|
|
|
|
}
|
2005-03-15 15:03:25 +01:00
|
|
|
DBUG_PRINT("info", ("Get commit_count from NDB"));
|
2005-02-11 22:33:52 +01:00
|
|
|
Ndb *ndb;
|
|
|
|
if (!(ndb= check_ndb_in_thd(thd)))
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
ndb->setDatabaseName(dbname);
|
2005-03-15 15:03:25 +01:00
|
|
|
uint lock= share->commit_count_lock;
|
|
|
|
pthread_mutex_unlock(&share->mutex);
|
2005-02-11 22:33:52 +01:00
|
|
|
|
|
|
|
struct Ndb_statistics stat;
|
2005-03-15 15:03:25 +01:00
|
|
|
{
|
2006-05-04 13:58:17 +02:00
|
|
|
Ndb_table_guard ndbtab_g(ndb->getDictionary(), tabname);
|
|
|
|
if (ndbtab_g.get_table() == 0
|
|
|
|
|| ndb_get_table_statistics(ndb, ndbtab_g.get_table(), &stat))
|
|
|
|
{
|
|
|
|
free_share(&share);
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
2005-03-15 15:03:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pthread_mutex_lock(&share->mutex);
|
2005-07-04 02:42:33 +02:00
|
|
|
if (share->commit_count_lock == lock)
|
2005-03-15 15:03:25 +01:00
|
|
|
{
|
2006-06-30 18:15:18 +02:00
|
|
|
char buff[22];
|
|
|
|
DBUG_PRINT("info", ("Setting commit_count to %s",
|
|
|
|
llstr(stat.commit_count, buff)));
|
2005-03-15 15:03:25 +01:00
|
|
|
share->commit_count= stat.commit_count;
|
|
|
|
*commit_count= stat.commit_count;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("Discarding commit_count, comit_count_lock changed"));
|
|
|
|
*commit_count= 0;
|
|
|
|
}
|
|
|
|
pthread_mutex_unlock(&share->mutex);
|
2005-11-06 00:20:37 +01:00
|
|
|
free_share(&share);
|
2005-02-11 22:33:52 +01:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Check if a cached query can be used.
|
|
|
|
This is done by comparing the supplied engine_data to commit_count of
|
|
|
|
the table.
|
|
|
|
The commit_count is either retrieved from the share for the table, where
|
|
|
|
it has been cached by the util thread. If the util thread is not started,
|
|
|
|
NDB has to be contacetd to retrieve the commit_count, this will introduce
|
|
|
|
a small delay while waiting for NDB to answer.
|
|
|
|
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
ndbcluster_cache_retrieval_allowed
|
|
|
|
thd thread handle
|
|
|
|
full_name concatenation of database name,
|
|
|
|
the null character '\0', and the table
|
|
|
|
name
|
|
|
|
full_name_len length of the full name,
|
|
|
|
i.e. len(dbname) + len(tablename) + 1
|
|
|
|
|
|
|
|
engine_data parameter retrieved when query was first inserted into
|
|
|
|
the cache. If the value of engine_data is changed,
|
|
|
|
all queries for this table should be invalidated.
|
|
|
|
|
|
|
|
RETURN VALUE
|
|
|
|
TRUE Yes, use the query from cache
|
|
|
|
FALSE No, don't use the cached query, and if engine_data
|
|
|
|
has changed, all queries for this table should be invalidated
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
static my_bool
|
|
|
|
ndbcluster_cache_retrieval_allowed(THD *thd,
|
2005-02-16 14:18:32 +01:00
|
|
|
char *full_name, uint full_name_len,
|
|
|
|
ulonglong *engine_data)
|
2005-02-11 22:33:52 +01:00
|
|
|
{
|
|
|
|
Uint64 commit_count;
|
|
|
|
bool is_autocommit= !(thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN));
|
|
|
|
char *dbname= full_name;
|
|
|
|
char *tabname= dbname+strlen(dbname)+1;
|
2006-06-30 18:15:18 +02:00
|
|
|
char buff[22], buff2[22];
|
|
|
|
DBUG_ENTER("ndbcluster_cache_retrieval_allowed");
|
2005-03-15 15:03:25 +01:00
|
|
|
DBUG_PRINT("enter", ("dbname: %s, tabname: %s, is_autocommit: %d",
|
|
|
|
dbname, tabname, is_autocommit));
|
2005-02-11 22:33:52 +01:00
|
|
|
|
|
|
|
if (!is_autocommit)
|
2005-03-15 15:03:25 +01:00
|
|
|
{
|
|
|
|
DBUG_PRINT("exit", ("No, don't use cache in transaction"));
|
2005-02-11 22:33:52 +01:00
|
|
|
DBUG_RETURN(FALSE);
|
2005-03-15 15:03:25 +01:00
|
|
|
}
|
2005-02-11 22:33:52 +01:00
|
|
|
|
|
|
|
if (ndb_get_commitcount(thd, dbname, tabname, &commit_count))
|
|
|
|
{
|
2005-03-15 15:03:25 +01:00
|
|
|
*engine_data= 0; /* invalidate */
|
|
|
|
DBUG_PRINT("exit", ("No, could not retrieve commit_count"));
|
2005-02-11 22:33:52 +01:00
|
|
|
DBUG_RETURN(FALSE);
|
|
|
|
}
|
2006-06-30 18:15:18 +02:00
|
|
|
DBUG_PRINT("info", ("*engine_data: %s, commit_count: %s",
|
|
|
|
llstr(*engine_data, buff), llstr(commit_count, buff2)));
|
2005-03-15 15:03:25 +01:00
|
|
|
if (commit_count == 0)
|
2005-02-11 22:33:52 +01:00
|
|
|
{
|
2005-03-15 15:03:25 +01:00
|
|
|
*engine_data= 0; /* invalidate */
|
|
|
|
DBUG_PRINT("exit", ("No, local commit has been performed"));
|
2005-02-11 22:33:52 +01:00
|
|
|
DBUG_RETURN(FALSE);
|
|
|
|
}
|
2005-03-15 15:03:25 +01:00
|
|
|
else if (*engine_data != commit_count)
|
|
|
|
{
|
|
|
|
*engine_data= commit_count; /* invalidate */
|
|
|
|
DBUG_PRINT("exit", ("No, commit_count has changed"));
|
|
|
|
DBUG_RETURN(FALSE);
|
|
|
|
}
|
2005-02-11 22:33:52 +01:00
|
|
|
|
2006-06-30 18:15:18 +02:00
|
|
|
DBUG_PRINT("exit", ("OK to use cache, engine_data: %s",
|
|
|
|
llstr(*engine_data, buff)));
|
2005-02-11 22:33:52 +01:00
|
|
|
DBUG_RETURN(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Register a table for use in the query cache. Fetch the commit_count
|
|
|
|
for the table and return it in engine_data, this will later be used
|
|
|
|
to check if the table has changed, before the cached query is reused.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
ha_ndbcluster::can_query_cache_table
|
|
|
|
thd thread handle
|
|
|
|
full_name concatenation of database name,
|
|
|
|
the null character '\0', and the table
|
|
|
|
name
|
|
|
|
full_name_len length of the full name,
|
|
|
|
i.e. len(dbname) + len(tablename) + 1
|
|
|
|
qc_engine_callback function to be called before using cache on this table
|
|
|
|
engine_data out, commit_count for this table
|
|
|
|
|
|
|
|
RETURN VALUE
|
|
|
|
TRUE Yes, it's ok to cahce this query
|
|
|
|
FALSE No, don't cach the query
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
my_bool
|
|
|
|
ha_ndbcluster::register_query_cache_table(THD *thd,
|
2005-02-16 14:18:32 +01:00
|
|
|
char *full_name, uint full_name_len,
|
|
|
|
qc_engine_callback *engine_callback,
|
|
|
|
ulonglong *engine_data)
|
2005-02-11 22:33:52 +01:00
|
|
|
{
|
2006-06-30 18:15:18 +02:00
|
|
|
Uint64 commit_count;
|
|
|
|
char buff[22];
|
2005-02-11 22:33:52 +01:00
|
|
|
bool is_autocommit= !(thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN));
|
2006-06-30 18:15:18 +02:00
|
|
|
DBUG_ENTER("ha_ndbcluster::register_query_cache_table");
|
2005-03-15 15:03:25 +01:00
|
|
|
DBUG_PRINT("enter",("dbname: %s, tabname: %s, is_autocommit: %d",
|
|
|
|
m_dbname, m_tabname, is_autocommit));
|
|
|
|
|
2005-02-11 22:33:52 +01:00
|
|
|
if (!is_autocommit)
|
2005-03-15 15:03:25 +01:00
|
|
|
{
|
2006-02-14 22:36:11 +01:00
|
|
|
DBUG_PRINT("exit", ("Can't register table during transaction"));
|
2005-02-11 22:33:52 +01:00
|
|
|
DBUG_RETURN(FALSE);
|
2005-03-15 15:03:25 +01:00
|
|
|
}
|
2005-02-11 22:33:52 +01:00
|
|
|
|
|
|
|
if (ndb_get_commitcount(thd, m_dbname, m_tabname, &commit_count))
|
|
|
|
{
|
|
|
|
*engine_data= 0;
|
2006-02-14 22:36:11 +01:00
|
|
|
DBUG_PRINT("exit", ("Error, could not get commitcount"));
|
2005-02-11 22:33:52 +01:00
|
|
|
DBUG_RETURN(FALSE);
|
|
|
|
}
|
|
|
|
*engine_data= commit_count;
|
|
|
|
*engine_callback= ndbcluster_cache_retrieval_allowed;
|
2006-06-30 18:15:18 +02:00
|
|
|
DBUG_PRINT("exit", ("commit_count: %s", llstr(commit_count, buff)));
|
2005-03-15 15:03:25 +01:00
|
|
|
DBUG_RETURN(commit_count > 0);
|
2004-11-17 09:15:53 +01:00
|
|
|
}
|
2004-04-15 09:14:14 +02:00
|
|
|
|
2005-02-11 22:33:52 +01:00
|
|
|
|
2004-04-15 09:14:14 +02:00
|
|
|
/*
|
2005-02-11 22:33:52 +01:00
|
|
|
Handling the shared NDB_SHARE structure that is needed to
|
2004-04-15 09:14:14 +02:00
|
|
|
provide table locking.
|
|
|
|
It's also used for sharing data with other NDB handlers
|
|
|
|
in the same MySQL Server. There is currently not much
|
|
|
|
data we want to or can share.
|
|
|
|
*/
|
|
|
|
|
2005-11-06 00:20:37 +01:00
|
|
|
static byte *ndbcluster_get_key(NDB_SHARE *share,uint *length,
|
2005-02-16 14:18:32 +01:00
|
|
|
my_bool not_used __attribute__((unused)))
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
2005-11-06 00:20:37 +01:00
|
|
|
*length= share->key_length;
|
|
|
|
return (byte*) share->key;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef DBUG_OFF
|
|
|
|
static void dbug_print_open_tables()
|
|
|
|
{
|
|
|
|
DBUG_ENTER("dbug_print_open_tables");
|
|
|
|
for (uint i= 0; i < ndbcluster_open_tables.records; i++)
|
|
|
|
{
|
|
|
|
NDB_SHARE *share= (NDB_SHARE*) hash_element(&ndbcluster_open_tables, i);
|
|
|
|
DBUG_PRINT("share",
|
|
|
|
("[%d] 0x%lx key: %s key_length: %d",
|
|
|
|
i, share, share->key, share->key_length));
|
|
|
|
DBUG_PRINT("share",
|
|
|
|
("db.tablename: %s.%s use_count: %d commit_count: %d",
|
|
|
|
share->db, share->table_name,
|
|
|
|
share->use_count, share->commit_count));
|
2006-01-12 19:51:02 +01:00
|
|
|
#ifdef HAVE_NDB_BINLOG
|
|
|
|
if (share->table)
|
|
|
|
DBUG_PRINT("share",
|
|
|
|
("table->s->db.table_name: %s.%s",
|
|
|
|
share->table->s->db.str, share->table->s->table_name.str));
|
|
|
|
#endif
|
2005-11-06 00:20:37 +01:00
|
|
|
}
|
|
|
|
DBUG_VOID_RETURN;
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
2005-11-06 00:20:37 +01:00
|
|
|
#else
|
|
|
|
#define dbug_print_open_tables()
|
|
|
|
#endif
|
2004-04-15 09:14:14 +02:00
|
|
|
|
2006-01-12 19:51:02 +01:00
|
|
|
#ifdef HAVE_NDB_BINLOG
|
|
|
|
/*
|
|
|
|
For some reason a share is still around, try to salvage the situation
|
|
|
|
by closing all cached tables. If the share still exists, there is an
|
|
|
|
error somewhere but only report this to the error log. Keep this
|
|
|
|
"trailing share" but rename it since there are still references to it
|
|
|
|
to avoid segmentation faults. There is a risk that the memory for
|
|
|
|
this trailing share leaks.
|
|
|
|
|
|
|
|
Must be called with previous pthread_mutex_lock(&ndbcluster_mutex)
|
|
|
|
*/
|
|
|
|
int handle_trailing_share(NDB_SHARE *share)
|
|
|
|
{
|
2006-05-31 16:16:03 +02:00
|
|
|
THD *thd= current_thd;
|
2006-01-12 19:51:02 +01:00
|
|
|
static ulong trailing_share_id= 0;
|
|
|
|
DBUG_ENTER("handle_trailing_share");
|
|
|
|
|
|
|
|
++share->use_count;
|
|
|
|
pthread_mutex_unlock(&ndbcluster_mutex);
|
|
|
|
|
2006-05-04 13:58:17 +02:00
|
|
|
TABLE_LIST table_list;
|
|
|
|
bzero((char*) &table_list,sizeof(table_list));
|
|
|
|
table_list.db= share->db;
|
|
|
|
table_list.alias= table_list.table_name= share->table_name;
|
2006-05-31 16:16:03 +02:00
|
|
|
close_cached_tables(thd, 0, &table_list, TRUE);
|
2006-01-12 19:51:02 +01:00
|
|
|
|
|
|
|
pthread_mutex_lock(&ndbcluster_mutex);
|
|
|
|
if (!--share->use_count)
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("NDB_SHARE: close_cashed_tables %s freed share.",
|
|
|
|
share->key));
|
|
|
|
real_free_share(&share);
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
share still exists, if share has not been dropped by server
|
|
|
|
release that share
|
|
|
|
*/
|
|
|
|
if (share->state != NSS_DROPPED && !--share->use_count)
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("NDB_SHARE: %s already exists, "
|
|
|
|
"use_count=%d state != NSS_DROPPED.",
|
|
|
|
share->key, share->use_count));
|
|
|
|
real_free_share(&share);
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
DBUG_PRINT("error", ("NDB_SHARE: %s already exists use_count=%d.",
|
|
|
|
share->key, share->use_count));
|
|
|
|
|
|
|
|
sql_print_error("NDB_SHARE: %s already exists use_count=%d."
|
|
|
|
" Moving away for safety, but possible memleak.",
|
|
|
|
share->key, share->use_count);
|
|
|
|
dbug_print_open_tables();
|
|
|
|
|
2006-01-17 07:36:50 +01:00
|
|
|
/*
|
|
|
|
Ndb share has not been released as it should
|
|
|
|
*/
|
|
|
|
DBUG_ASSERT(FALSE);
|
|
|
|
|
2006-01-12 19:51:02 +01:00
|
|
|
/*
|
|
|
|
This is probably an error. We can however save the situation
|
|
|
|
at the cost of a possible mem leak, by "renaming" the share
|
|
|
|
- First remove from hash
|
|
|
|
*/
|
|
|
|
hash_delete(&ndbcluster_open_tables, (byte*) share);
|
|
|
|
|
|
|
|
/*
|
|
|
|
now give it a new name, just a running number
|
|
|
|
if space is not enough allocate some more
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
const uint min_key_length= 10;
|
|
|
|
if (share->key_length < min_key_length)
|
|
|
|
{
|
|
|
|
share->key= alloc_root(&share->mem_root, min_key_length + 1);
|
|
|
|
share->key_length= min_key_length;
|
|
|
|
}
|
|
|
|
share->key_length=
|
|
|
|
my_snprintf(share->key, min_key_length + 1, "#leak%d",
|
|
|
|
trailing_share_id++);
|
|
|
|
}
|
|
|
|
/* Keep it for possible the future trailing free */
|
|
|
|
my_hash_insert(&ndbcluster_open_tables, (byte*) share);
|
|
|
|
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Rename share is used during rename table.
|
|
|
|
*/
|
|
|
|
static int rename_share(NDB_SHARE *share, const char *new_key)
|
|
|
|
{
|
|
|
|
NDB_SHARE *tmp;
|
|
|
|
pthread_mutex_lock(&ndbcluster_mutex);
|
|
|
|
uint new_length= (uint) strlen(new_key);
|
|
|
|
DBUG_PRINT("rename_share", ("old_key: %s old__length: %d",
|
|
|
|
share->key, share->key_length));
|
|
|
|
if ((tmp= (NDB_SHARE*) hash_search(&ndbcluster_open_tables,
|
|
|
|
(byte*) new_key, new_length)))
|
|
|
|
handle_trailing_share(tmp);
|
|
|
|
|
|
|
|
/* remove the share from hash */
|
|
|
|
hash_delete(&ndbcluster_open_tables, (byte*) share);
|
|
|
|
dbug_print_open_tables();
|
|
|
|
|
|
|
|
/* save old stuff if insert should fail */
|
|
|
|
uint old_length= share->key_length;
|
|
|
|
char *old_key= share->key;
|
|
|
|
|
|
|
|
/*
|
|
|
|
now allocate and set the new key, db etc
|
|
|
|
enough space for key, db, and table_name
|
|
|
|
*/
|
|
|
|
share->key= alloc_root(&share->mem_root, 2 * (new_length + 1));
|
|
|
|
strmov(share->key, new_key);
|
|
|
|
share->key_length= new_length;
|
|
|
|
|
|
|
|
if (my_hash_insert(&ndbcluster_open_tables, (byte*) share))
|
|
|
|
{
|
|
|
|
// ToDo free the allocated stuff above?
|
|
|
|
DBUG_PRINT("error", ("rename_share: my_hash_insert %s failed",
|
|
|
|
share->key));
|
|
|
|
share->key= old_key;
|
|
|
|
share->key_length= old_length;
|
|
|
|
if (my_hash_insert(&ndbcluster_open_tables, (byte*) share))
|
|
|
|
{
|
|
|
|
sql_print_error("rename_share: failed to recover %s", share->key);
|
|
|
|
DBUG_PRINT("error", ("rename_share: my_hash_insert %s failed",
|
|
|
|
share->key));
|
|
|
|
}
|
|
|
|
dbug_print_open_tables();
|
|
|
|
pthread_mutex_unlock(&ndbcluster_mutex);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
dbug_print_open_tables();
|
|
|
|
|
|
|
|
share->db= share->key + new_length + 1;
|
|
|
|
ha_ndbcluster::set_dbname(new_key, share->db);
|
|
|
|
share->table_name= share->db + strlen(share->db) + 1;
|
|
|
|
ha_ndbcluster::set_tabname(new_key, share->table_name);
|
|
|
|
|
|
|
|
DBUG_PRINT("rename_share",
|
|
|
|
("0x%lx key: %s key_length: %d",
|
|
|
|
share, share->key, share->key_length));
|
|
|
|
DBUG_PRINT("rename_share",
|
|
|
|
("db.tablename: %s.%s use_count: %d commit_count: %d",
|
|
|
|
share->db, share->table_name,
|
|
|
|
share->use_count, share->commit_count));
|
2006-02-16 00:30:56 +01:00
|
|
|
if (share->table)
|
2006-01-12 19:51:02 +01:00
|
|
|
{
|
2006-02-16 00:30:56 +01:00
|
|
|
DBUG_PRINT("rename_share",
|
|
|
|
("table->s->db.table_name: %s.%s",
|
|
|
|
share->table->s->db.str, share->table->s->table_name.str));
|
|
|
|
|
|
|
|
if (share->op == 0)
|
|
|
|
{
|
|
|
|
share->table->s->db.str= share->db;
|
|
|
|
share->table->s->db.length= strlen(share->db);
|
|
|
|
share->table->s->table_name.str= share->table_name;
|
|
|
|
share->table->s->table_name.length= strlen(share->table_name);
|
|
|
|
}
|
2006-01-12 19:51:02 +01:00
|
|
|
}
|
|
|
|
/* else rename will be handled when the ALTER event comes */
|
|
|
|
share->old_names= old_key;
|
|
|
|
// ToDo free old_names after ALTER EVENT
|
|
|
|
|
|
|
|
pthread_mutex_unlock(&ndbcluster_mutex);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-11-06 00:20:37 +01:00
|
|
|
/*
|
|
|
|
Increase refcount on existing share.
|
|
|
|
Always returns share and cannot fail.
|
|
|
|
*/
|
2006-01-12 19:51:02 +01:00
|
|
|
NDB_SHARE *ndbcluster_get_share(NDB_SHARE *share)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
|
|
|
pthread_mutex_lock(&ndbcluster_mutex);
|
2005-11-06 00:20:37 +01:00
|
|
|
share->use_count++;
|
|
|
|
|
|
|
|
dbug_print_open_tables();
|
|
|
|
|
|
|
|
DBUG_PRINT("get_share",
|
|
|
|
("0x%lx key: %s key_length: %d",
|
|
|
|
share, share->key, share->key_length));
|
|
|
|
DBUG_PRINT("get_share",
|
|
|
|
("db.tablename: %s.%s use_count: %d commit_count: %d",
|
|
|
|
share->db, share->table_name,
|
|
|
|
share->use_count, share->commit_count));
|
|
|
|
pthread_mutex_unlock(&ndbcluster_mutex);
|
|
|
|
return share;
|
|
|
|
}
|
|
|
|
|
2006-02-26 15:03:43 +01:00
|
|
|
|
2005-11-06 00:20:37 +01:00
|
|
|
/*
|
|
|
|
Get a share object for key
|
|
|
|
|
|
|
|
Returns share for key, and increases the refcount on the share.
|
|
|
|
|
|
|
|
create_if_not_exists == TRUE:
|
|
|
|
creates share if it does not alreade exist
|
|
|
|
returns 0 only due to out of memory, and then sets my_error
|
|
|
|
|
|
|
|
create_if_not_exists == FALSE:
|
|
|
|
returns 0 if share does not exist
|
|
|
|
|
|
|
|
have_lock == TRUE, pthread_mutex_lock(&ndbcluster_mutex) already taken
|
|
|
|
*/
|
2006-02-26 15:03:43 +01:00
|
|
|
|
2006-01-12 19:51:02 +01:00
|
|
|
NDB_SHARE *ndbcluster_get_share(const char *key, TABLE *table,
|
|
|
|
bool create_if_not_exists,
|
|
|
|
bool have_lock)
|
2005-11-06 00:20:37 +01:00
|
|
|
{
|
2006-01-12 19:51:02 +01:00
|
|
|
THD *thd= current_thd;
|
2005-11-06 00:20:37 +01:00
|
|
|
NDB_SHARE *share;
|
2006-02-26 15:03:43 +01:00
|
|
|
uint length= (uint) strlen(key);
|
|
|
|
DBUG_ENTER("ndbcluster_get_share");
|
|
|
|
DBUG_PRINT("enter", ("key: '%s'", key));
|
|
|
|
|
2005-11-06 00:20:37 +01:00
|
|
|
if (!have_lock)
|
|
|
|
pthread_mutex_lock(&ndbcluster_mutex);
|
|
|
|
if (!(share= (NDB_SHARE*) hash_search(&ndbcluster_open_tables,
|
|
|
|
(byte*) key,
|
|
|
|
length)))
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
2005-11-06 00:20:37 +01:00
|
|
|
if (!create_if_not_exists)
|
|
|
|
{
|
|
|
|
DBUG_PRINT("error", ("get_share: %s does not exist", key));
|
|
|
|
if (!have_lock)
|
|
|
|
pthread_mutex_unlock(&ndbcluster_mutex);
|
2006-01-13 13:01:19 +01:00
|
|
|
DBUG_RETURN(0);
|
2005-11-06 00:20:37 +01:00
|
|
|
}
|
|
|
|
if ((share= (NDB_SHARE*) my_malloc(sizeof(*share),
|
2004-04-15 09:14:14 +02:00
|
|
|
MYF(MY_WME | MY_ZEROFILL))))
|
|
|
|
{
|
2005-11-06 00:20:37 +01:00
|
|
|
MEM_ROOT **root_ptr=
|
|
|
|
my_pthread_getspecific_ptr(MEM_ROOT**, THR_MALLOC);
|
|
|
|
MEM_ROOT *old_root= *root_ptr;
|
|
|
|
init_sql_alloc(&share->mem_root, 1024, 0);
|
|
|
|
*root_ptr= &share->mem_root; // remember to reset before return
|
2006-01-17 12:53:49 +01:00
|
|
|
share->state= NSS_INITIAL;
|
2005-11-06 00:20:37 +01:00
|
|
|
/* enough space for key, db, and table_name */
|
|
|
|
share->key= alloc_root(*root_ptr, 2 * (length + 1));
|
|
|
|
share->key_length= length;
|
|
|
|
strmov(share->key, key);
|
2004-04-15 09:14:14 +02:00
|
|
|
if (my_hash_insert(&ndbcluster_open_tables, (byte*) share))
|
|
|
|
{
|
2005-11-06 00:20:37 +01:00
|
|
|
free_root(&share->mem_root, MYF(0));
|
|
|
|
my_free((gptr) share, 0);
|
|
|
|
*root_ptr= old_root;
|
|
|
|
if (!have_lock)
|
|
|
|
pthread_mutex_unlock(&ndbcluster_mutex);
|
2006-01-13 13:01:19 +01:00
|
|
|
DBUG_RETURN(0);
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
thr_lock_init(&share->lock);
|
2005-11-06 00:20:37 +01:00
|
|
|
pthread_mutex_init(&share->mutex, MY_MUTEX_INIT_FAST);
|
2005-02-11 22:33:52 +01:00
|
|
|
share->commit_count= 0;
|
2005-03-15 15:03:25 +01:00
|
|
|
share->commit_count_lock= 0;
|
2005-11-06 00:20:37 +01:00
|
|
|
share->db= share->key + length + 1;
|
|
|
|
ha_ndbcluster::set_dbname(key, share->db);
|
|
|
|
share->table_name= share->db + strlen(share->db) + 1;
|
|
|
|
ha_ndbcluster::set_tabname(key, share->table_name);
|
2006-01-12 19:51:02 +01:00
|
|
|
#ifdef HAVE_NDB_BINLOG
|
|
|
|
ndbcluster_binlog_init_share(share, table);
|
|
|
|
#endif
|
2005-11-06 00:20:37 +01:00
|
|
|
*root_ptr= old_root;
|
2005-03-15 15:03:25 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-11-06 00:20:37 +01:00
|
|
|
DBUG_PRINT("error", ("get_share: failed to alloc share"));
|
|
|
|
if (!have_lock)
|
|
|
|
pthread_mutex_unlock(&ndbcluster_mutex);
|
|
|
|
my_error(ER_OUTOFMEMORY, MYF(0), sizeof(*share));
|
2006-01-13 13:01:19 +01:00
|
|
|
DBUG_RETURN(0);
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
share->use_count++;
|
2005-03-15 15:03:25 +01:00
|
|
|
|
2005-11-06 00:20:37 +01:00
|
|
|
dbug_print_open_tables();
|
|
|
|
|
2006-02-26 15:03:43 +01:00
|
|
|
DBUG_PRINT("info",
|
2005-11-06 00:20:37 +01:00
|
|
|
("0x%lx key: %s key_length: %d key: %s",
|
|
|
|
share, share->key, share->key_length, key));
|
2006-02-26 15:03:43 +01:00
|
|
|
DBUG_PRINT("info",
|
2005-11-06 00:20:37 +01:00
|
|
|
("db.tablename: %s.%s use_count: %d commit_count: %d",
|
|
|
|
share->db, share->table_name,
|
|
|
|
share->use_count, share->commit_count));
|
|
|
|
if (!have_lock)
|
|
|
|
pthread_mutex_unlock(&ndbcluster_mutex);
|
2006-01-13 13:01:19 +01:00
|
|
|
DBUG_RETURN(share);
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
|
2006-02-26 15:03:43 +01:00
|
|
|
|
2006-01-12 19:51:02 +01:00
|
|
|
void ndbcluster_real_free_share(NDB_SHARE **share)
|
2005-11-06 00:20:37 +01:00
|
|
|
{
|
2006-02-26 15:03:43 +01:00
|
|
|
DBUG_ENTER("ndbcluster_real_free_share");
|
2005-11-06 00:20:37 +01:00
|
|
|
DBUG_PRINT("real_free_share",
|
|
|
|
("0x%lx key: %s key_length: %d",
|
|
|
|
(*share), (*share)->key, (*share)->key_length));
|
|
|
|
DBUG_PRINT("real_free_share",
|
|
|
|
("db.tablename: %s.%s use_count: %d commit_count: %d",
|
|
|
|
(*share)->db, (*share)->table_name,
|
|
|
|
(*share)->use_count, (*share)->commit_count));
|
|
|
|
|
|
|
|
hash_delete(&ndbcluster_open_tables, (byte*) *share);
|
|
|
|
thr_lock_delete(&(*share)->lock);
|
|
|
|
pthread_mutex_destroy(&(*share)->mutex);
|
|
|
|
|
2006-01-12 19:51:02 +01:00
|
|
|
#ifdef HAVE_NDB_BINLOG
|
|
|
|
if ((*share)->table)
|
|
|
|
{
|
2006-03-07 12:19:27 +01:00
|
|
|
// (*share)->table->mem_root is freed by closefrm
|
2006-01-12 19:51:02 +01:00
|
|
|
closefrm((*share)->table, 0);
|
2006-03-07 12:19:27 +01:00
|
|
|
// (*share)->table_share->mem_root is freed by free_table_share
|
|
|
|
free_table_share((*share)->table_share);
|
2006-01-12 19:51:02 +01:00
|
|
|
#ifndef DBUG_OFF
|
|
|
|
bzero((gptr)(*share)->table_share, sizeof(*(*share)->table_share));
|
|
|
|
bzero((gptr)(*share)->table, sizeof(*(*share)->table));
|
|
|
|
(*share)->table_share= 0;
|
|
|
|
(*share)->table= 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
2006-03-29 16:04:00 +02:00
|
|
|
free_root(&(*share)->mem_root, MYF(0));
|
2005-11-06 00:20:37 +01:00
|
|
|
my_free((gptr) *share, MYF(0));
|
|
|
|
*share= 0;
|
|
|
|
|
|
|
|
dbug_print_open_tables();
|
2006-02-26 15:03:43 +01:00
|
|
|
DBUG_VOID_RETURN;
|
2005-11-06 00:20:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
decrease refcount of share
|
|
|
|
calls real_free_share when refcount reaches 0
|
2004-04-15 09:14:14 +02:00
|
|
|
|
2005-11-06 00:20:37 +01:00
|
|
|
have_lock == TRUE, pthread_mutex_lock(&ndbcluster_mutex) already taken
|
|
|
|
*/
|
2006-01-12 19:51:02 +01:00
|
|
|
void ndbcluster_free_share(NDB_SHARE **share, bool have_lock)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
2005-11-06 00:20:37 +01:00
|
|
|
if (!have_lock)
|
|
|
|
pthread_mutex_lock(&ndbcluster_mutex);
|
|
|
|
if ((*share)->util_lock == current_thd)
|
|
|
|
(*share)->util_lock= 0;
|
|
|
|
if (!--(*share)->use_count)
|
2004-04-15 09:14:14 +02:00
|
|
|
{
|
2005-11-06 00:20:37 +01:00
|
|
|
real_free_share(share);
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
2005-11-06 00:20:37 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
dbug_print_open_tables();
|
|
|
|
DBUG_PRINT("free_share",
|
|
|
|
("0x%lx key: %s key_length: %d",
|
|
|
|
*share, (*share)->key, (*share)->key_length));
|
|
|
|
DBUG_PRINT("free_share",
|
|
|
|
("db.tablename: %s.%s use_count: %d commit_count: %d",
|
|
|
|
(*share)->db, (*share)->table_name,
|
|
|
|
(*share)->use_count, (*share)->commit_count));
|
|
|
|
}
|
|
|
|
if (!have_lock)
|
|
|
|
pthread_mutex_unlock(&ndbcluster_mutex);
|
2004-04-15 09:14:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-09-03 13:55:40 +02:00
|
|
|
static
|
|
|
|
int
|
2006-05-04 13:58:17 +02:00
|
|
|
ndb_get_table_statistics(Ndb* ndb, const NDBTAB *ndbtab,
|
2005-02-16 14:18:32 +01:00
|
|
|
struct Ndb_statistics * ndbstat)
|
2004-09-03 13:55:40 +02:00
|
|
|
{
|
2006-04-26 16:57:44 +02:00
|
|
|
NdbTransaction* pTrans;
|
2006-06-29 20:55:21 +02:00
|
|
|
NdbError error;
|
2006-04-26 16:57:44 +02:00
|
|
|
int retries= 10;
|
|
|
|
int retry_sleep= 30 * 1000; /* 30 milliseconds */
|
2006-06-30 18:15:18 +02:00
|
|
|
char buff[22], buff2[22], buff3[22], buff4[22];
|
|
|
|
DBUG_ENTER("ndb_get_table_statistics");
|
2006-07-14 00:07:37 +02:00
|
|
|
DBUG_PRINT("enter", ("table: %s", ndbtab->getName()));
|
2006-04-26 16:57:44 +02:00
|
|
|
|
2006-05-04 13:58:17 +02:00
|
|
|
DBUG_ASSERT(ndbtab != 0);
|
|
|
|
|
2006-04-26 16:57:44 +02:00
|
|
|
do
|
2004-09-03 13:55:40 +02:00
|
|
|
{
|
2006-07-03 17:09:32 +02:00
|
|
|
Uint64 rows, commits, fixed_mem, var_mem;
|
2006-06-29 21:05:43 +02:00
|
|
|
Uint32 size;
|
2006-06-29 22:11:29 +02:00
|
|
|
Uint32 count= 0;
|
2006-06-29 20:55:21 +02:00
|
|
|
Uint64 sum_rows= 0;
|
|
|
|
Uint64 sum_commits= 0;
|
2006-06-29 22:11:29 +02:00
|
|
|
Uint64 sum_row_size= 0;
|
|
|
|
Uint64 sum_mem= 0;
|
2006-06-29 20:55:21 +02:00
|
|
|
NdbScanOperation*pOp;
|
|
|
|
NdbResultSet *rs;
|
|
|
|
int check;
|
|
|
|
|
|
|
|
if ((pTrans= ndb->startTransaction()) == NULL)
|
2006-04-26 16:57:44 +02:00
|
|
|
{
|
2006-06-29 20:55:21 +02:00
|
|
|
error= ndb->getNdbError();
|
|
|
|
goto retry;
|
|
|
|
}
|
2004-11-22 14:41:46 +01:00
|
|
|
|
2006-06-29 21:25:37 +02:00
|
|
|
if ((pOp= pTrans->getNdbScanOperation(ndbtab)) == NULL)
|
2006-06-29 20:55:21 +02:00
|
|
|
{
|
|
|
|
error= pTrans->getNdbError();
|
|
|
|
goto retry;
|
2006-04-26 16:57:44 +02:00
|
|
|
}
|
2004-09-03 13:55:40 +02:00
|
|
|
|
2004-12-07 15:15:49 +01:00
|
|
|
if (pOp->readTuples(NdbOperation::LM_CommittedRead))
|
2006-06-29 20:55:21 +02:00
|
|
|
{
|
|
|
|
error= pOp->getNdbError();
|
|
|
|
goto retry;
|
|
|
|
}
|
2004-09-03 13:55:40 +02:00
|
|
|
|
2006-06-29 20:55:21 +02:00
|
|
|
if (pOp->interpret_exit_last_row() == -1)
|
|
|
|
{
|
|
|
|
error= pOp->getNdbError();
|
|
|
|
goto retry;
|
|
|
|
}
|
2004-09-03 13:55:40 +02:00
|
|
|
|
|
|
|
pOp->getValue(NdbDictionary::Column::ROW_COUNT, (char*)&rows);
|
|
|
|
pOp->getValue(NdbDictionary::Column::COMMIT_COUNT, (char*)&commits);
|
2005-01-13 18:24:19 +01:00
|
|
|
pOp->getValue(NdbDictionary::Column::ROW_SIZE, (char*)&size);
|
2006-07-03 17:09:32 +02:00
|
|
|
pOp->getValue(NdbDictionary::Column::FRAGMENT_FIXED_MEMORY,
|
|
|
|
(char*)&fixed_mem);
|
|
|
|
pOp->getValue(NdbDictionary::Column::FRAGMENT_VARSIZED_MEMORY,
|
|
|
|
(char*)&var_mem);
|
2004-09-03 13:55:40 +02:00
|
|
|
|
2006-06-29 21:05:43 +02:00
|
|
|
if (pTrans->execute(NdbTransaction::NoCommit,
|
|
|
|
NdbTransaction::AbortOnError,
|
|
|
|
TRUE) == -1)
|
2006-04-26 16:57:44 +02:00
|
|
|
{
|
2006-06-29 20:55:21 +02:00
|
|
|
error= pTrans->getNdbError();
|
|
|
|
goto retry;
|
2006-04-26 16:57:44 +02:00
|
|
|
}
|
2004-09-03 13:55:40 +02:00
|
|
|
|
2005-07-18 14:33:18 +02:00
|
|
|
while ((check= pOp->nextResult(TRUE, TRUE)) == 0)
|
2004-09-03 13:55:40 +02:00
|
|
|
{
|
|
|
|
sum_rows+= rows;
|
|
|
|
sum_commits+= commits;
|
2005-01-13 18:24:19 +01:00
|
|
|
if (sum_row_size < size)
|
2005-02-16 14:18:32 +01:00
|
|
|
sum_row_size= size;
|
2006-07-03 17:09:32 +02:00
|
|
|
sum_mem+= fixed_mem + var_mem;
|
2005-03-15 15:03:25 +01:00
|
|
|
count++;
|
2004-09-03 13:55:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (check == -1)
|
2006-06-29 20:55:21 +02:00
|
|
|
{
|
|
|
|
error= pOp->getNdbError();
|
|
|
|
goto retry;
|
|
|
|
}
|
2004-09-03 13:55:40 +02:00
|
|
|
|
2004-12-07 15:15:49 +01:00
|
|
|
pOp->close(TRUE);
|
2004-11-22 14:41:46 +01:00
|
|
|
|
2004-09-03 13:55:40 +02:00
|
|
|
ndb->closeTransaction(pTrans);
|
2005-01-13 18:24:19 +01:00
|
|
|
|
|
|
|
ndbstat->row_count= sum_rows;
|
|
|
|
ndbstat->commit_count= sum_commits;
|
|
|
|
ndbstat->row_size= sum_row_size;
|
|
|
|
ndbstat->fragment_memory= sum_mem;
|
|
|
|
|
2006-06-30 18:15:18 +02:00
|
|
|
DBUG_PRINT("exit", ("records: %s commits: %s "
|
|
|
|
"row_size: %s mem: %s count: %u",
|
|
|
|
llstr(sum_rows, buff),
|
|
|
|
llstr(sum_commits, buff2),
|
|
|
|
llstr(sum_row_size, buff3),
|
|
|
|
llstr(sum_mem, buff4),
|
|
|
|
count));
|
2005-03-15 15:03:25 +01:00
|
|
|
|
2004-09-03 13:55:40 +02:00
|
|
|
DBUG_RETURN(0);
|
2006-06-29 20:55:21 +02:00
|
|
|
retry:
|
|
|
|
if (pTrans)
|
|
|
|
{
|
|
|
|
ndb->closeTransaction(pTrans);
|
|
|
|
pTrans= NULL;
|
|
|
|
}
|
|
|
|
if (error.status == NdbError::TemporaryError && retries--)
|
|
|
|
{
|
|
|
|
my_sleep(retry_sleep);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
2006-04-26 16:57:44 +02:00
|
|
|
} while(1);
|
2006-06-29 20:55:21 +02:00
|
|
|
DBUG_PRINT("exit", ("failed, error %u(%s)", error.code, error.message));
|
|
|
|
ERR_RETURN(error);
|
2004-09-03 13:55:40 +02:00
|
|
|
}
|
|
|
|
|
2004-09-13 14:46:38 +02:00
|
|
|
/*
|
|
|
|
Create a .ndb file to serve as a placeholder indicating
|
|
|
|
that the table with this name is a ndb table
|
|
|
|
*/
|
|
|
|
|
2006-01-17 08:40:00 +01:00
|
|
|
int ha_ndbcluster::write_ndb_file(const char *name)
|
2004-09-13 14:46:38 +02:00
|
|
|
{
|
|
|
|
File file;
|
|
|
|
bool error=1;
|
|
|
|
char path[FN_REFLEN];
|
|
|
|
|
|
|
|
DBUG_ENTER("write_ndb_file");
|
2006-01-17 08:40:00 +01:00
|
|
|
DBUG_PRINT("enter", ("name: %s", name));
|
2004-09-13 14:46:38 +02:00
|
|
|
|
2005-11-23 21:45:02 +01:00
|
|
|
(void)strxnmov(path, FN_REFLEN-1,
|
2006-01-17 08:40:00 +01:00
|
|
|
mysql_data_home,"/",name,ha_ndb_ext,NullS);
|
2004-09-13 14:46:38 +02:00
|
|
|
|
|
|
|
if ((file=my_create(path, CREATE_MODE,O_RDWR | O_TRUNC,MYF(MY_WME))) >= 0)
|
|
|
|
{
|
|
|
|
// It's an empty file
|
|
|
|
error=0;
|
|
|
|
my_close(file,MYF(0));
|
|
|
|
}
|
|
|
|
DBUG_RETURN(error);
|
|
|
|
}
|
|
|
|
|
2006-08-15 13:12:27 +02:00
|
|
|
void
|
2006-08-15 14:31:21 +02:00
|
|
|
ha_ndbcluster::release_completed_operations(NdbTransaction *trans,
|
|
|
|
bool force_release)
|
2006-08-15 13:12:27 +02:00
|
|
|
{
|
|
|
|
if (trans->hasBlobOperation())
|
|
|
|
{
|
|
|
|
/* We are reading/writing BLOB fields,
|
|
|
|
releasing operation records is unsafe
|
|
|
|
*/
|
|
|
|
return;
|
|
|
|
}
|
2006-08-15 14:31:21 +02:00
|
|
|
if (!force_release)
|
|
|
|
{
|
|
|
|
if (get_thd_ndb(current_thd)->query_state & NDB_QUERY_MULTI_READ_RANGE)
|
|
|
|
{
|
|
|
|
/* We are batching reads and have not consumed all fetched
|
|
|
|
rows yet, releasing operation records is unsafe
|
|
|
|
*/
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2006-08-15 13:12:27 +02:00
|
|
|
trans->releaseCompletedOperations();
|
2006-08-15 14:31:21 +02:00
|
|
|
}
|
|
|
|
|
2004-11-17 10:07:52 +01:00
|
|
|
int
|
2004-12-28 17:01:07 +01:00
|
|
|
ha_ndbcluster::read_multi_range_first(KEY_MULTI_RANGE **found_range_p,
|
2005-02-16 14:18:32 +01:00
|
|
|
KEY_MULTI_RANGE *ranges,
|
|
|
|
uint range_count,
|
|
|
|
bool sorted,
|
|
|
|
HANDLER_BUFFER *buffer)
|
2004-11-17 10:07:52 +01:00
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_ndbcluster::read_multi_range_first");
|
2005-04-28 14:45:27 +02:00
|
|
|
m_write_op= FALSE;
|
2004-12-08 00:36:40 +01:00
|
|
|
|
2004-11-17 10:07:52 +01:00
|
|
|
int res;
|
|
|
|
KEY* key_info= table->key_info + active_index;
|
2004-12-07 15:15:49 +01:00
|
|
|
NDB_INDEX_TYPE index_type= get_index_type(active_index);
|
2006-01-17 08:40:00 +01:00
|
|
|
ulong reclength= table_share->reclength;
|
2004-11-17 10:07:52 +01:00
|
|
|
NdbOperation* op;
|
2006-08-07 14:48:54 +02:00
|
|
|
Thd_ndb *thd_ndb= get_thd_ndb(current_thd);
|
2004-11-17 10:07:52 +01:00
|
|
|
|
2005-04-28 14:45:27 +02:00
|
|
|
if (uses_blob_value())
|
2004-11-17 14:21:56 +01:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* blobs can't be batched currently
|
|
|
|
*/
|
2005-05-06 10:39:30 +02:00
|
|
|
m_disable_multi_read= TRUE;
|
2004-11-25 19:12:05 +01:00
|
|
|
DBUG_RETURN(handler::read_multi_range_first(found_range_p,
|
2005-02-16 14:18:32 +01:00
|
|
|
ranges,
|
|
|
|
range_count,
|
|
|
|
sorted,
|
|
|
|
buffer));
|
2004-11-17 14:21:56 +01:00
|
|
|
}
|
2006-08-07 14:48:54 +02:00
|
|
|
thd_ndb->query_state|= NDB_QUERY_MULTI_READ_RANGE;
|
2005-05-06 10:39:30 +02:00
|
|
|
m_disable_multi_read= FALSE;
|
2004-11-30 07:58:55 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy arguments into member variables
|
|
|
|
*/
|
2004-12-28 17:01:07 +01:00
|
|
|
m_multi_ranges= ranges;
|
|
|
|
multi_range_curr= ranges;
|
|
|
|
multi_range_end= ranges+range_count;
|
2004-11-17 10:07:52 +01:00
|
|
|
multi_range_sorted= sorted;
|
|
|
|
multi_range_buffer= buffer;
|
|
|
|
|
2004-11-30 07:58:55 +01:00
|
|
|
/**
|
|
|
|
* read multi range will read ranges as follows (if not ordered)
|
|
|
|
*
|
|
|
|
* input read order
|
|
|
|
* ====== ==========
|
|
|
|
* pk-op 1 pk-op 1
|
|
|
|
* pk-op 2 pk-op 2
|
|
|
|
* range 3 range (3,5) NOTE result rows will be intermixed
|
|
|
|
* pk-op 4 pk-op 4
|
|
|
|
* range 5
|
|
|
|
* pk-op 6 pk-ok 6
|
2005-01-11 17:00:31 +01:00
|
|
|
*/
|
|
|
|
|
2005-01-11 14:06:44 +01:00
|
|
|
/**
|
2004-11-30 07:58:55 +01:00
|
|
|
* Variables for loop
|
|
|
|
*/
|
2004-12-08 00:36:40 +01:00
|
|
|
byte *curr= (byte*)buffer->buffer;
|
|
|
|
byte *end_of_buffer= (byte*)buffer->buffer_end;
|
2004-11-17 10:07:52 +01:00
|
|
|
NdbOperation::LockMode lm=
|
|
|
|
(NdbOperation::LockMode)get_ndb_lock_type(m_lock.type);
|
2006-06-12 14:23:21 +02:00
|
|
|
bool need_pk = (lm == NdbOperation::LM_Read);
|
2006-05-04 13:58:17 +02:00
|
|
|
const NDBTAB *tab= m_table;
|
|
|
|
const NDBINDEX *unique_idx= m_index[active_index].unique_index;
|
|
|
|
const NDBINDEX *idx= m_index[active_index].index;
|
2004-11-26 15:15:22 +01:00
|
|
|
const NdbOperation* lastOp= m_active_trans->getLastDefinedOperation();
|
|
|
|
NdbIndexScanOperation* scanOp= 0;
|
2005-06-01 15:35:09 +02:00
|
|
|
for (; multi_range_curr<multi_range_end && curr+reclength <= end_of_buffer;
|
|
|
|
multi_range_curr++)
|
2004-11-26 15:15:22 +01:00
|
|
|
{
|
2005-07-18 13:31:02 +02:00
|
|
|
part_id_range part_spec;
|
|
|
|
if (m_use_partition_function)
|
|
|
|
{
|
|
|
|
get_partition_set(table, curr, active_index,
|
|
|
|
&multi_range_curr->start_key,
|
|
|
|
&part_spec);
|
2006-02-10 17:06:24 +01:00
|
|
|
DBUG_PRINT("info", ("part_spec.start_part = %u, part_spec.end_part = %u",
|
|
|
|
part_spec.start_part, part_spec.end_part));
|
|
|
|
/*
|
|
|
|
If partition pruning has found no partition in set
|
|
|
|
we can skip this scan
|
|
|
|
*/
|
2005-07-18 13:31:02 +02:00
|
|
|
if (part_spec.start_part > part_spec.end_part)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
We can skip this partition since the key won't fit into any
|
|
|
|
partition
|
|
|
|
*/
|
|
|
|
curr += reclength;
|
|
|
|
multi_range_curr->range_flag |= SKIP_RANGE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
switch(index_type){
|
2005-07-04 02:42:33 +02:00
|
|
|
case PRIMARY_KEY_ORDERED_INDEX:
|
|
|
|
if (!(multi_range_curr->start_key.length == key_info->key_length &&
|
2005-07-18 13:31:02 +02:00
|
|
|
multi_range_curr->start_key.flag == HA_READ_KEY_EXACT))
|
|
|
|
goto range;
|
|
|
|
// else fall through
|
2004-11-26 15:15:22 +01:00
|
|
|
case PRIMARY_KEY_INDEX:
|
2004-11-17 10:07:52 +01:00
|
|
|
{
|
2004-12-28 17:01:07 +01:00
|
|
|
multi_range_curr->range_flag |= UNIQUE_RANGE;
|
2004-11-17 10:07:52 +01:00
|
|
|
if ((op= m_active_trans->getNdbOperation(tab)) &&
|
2005-02-16 14:18:32 +01:00
|
|
|
!op->readTuple(lm) &&
|
|
|
|
!set_primary_key(op, multi_range_curr->start_key.key) &&
|
|
|
|
!define_read_attrs(curr, op) &&
|
2005-07-18 13:31:02 +02:00
|
|
|
(op->setAbortOption(AO_IgnoreError), TRUE) &&
|
|
|
|
(!m_use_partition_function ||
|
|
|
|
(op->setPartitionId(part_spec.start_part), true)))
|
2005-02-16 14:18:32 +01:00
|
|
|
curr += reclength;
|
2004-11-17 10:07:52 +01:00
|
|
|
else
|
2005-02-16 14:18:32 +01:00
|
|
|
ERR_RETURN(op ? op->getNdbError() : m_active_trans->getNdbError());
|
2004-11-26 15:15:22 +01:00
|
|
|
break;
|
2004-11-17 10:07:52 +01:00
|
|
|
}
|
|
|
|
break;
|
2005-07-04 02:42:33 +02:00
|
|
|
case UNIQUE_ORDERED_INDEX:
|
|
|
|
if (!(multi_range_curr->start_key.length == key_info->key_length &&
|
2005-07-18 13:31:02 +02:00
|
|
|
multi_range_curr->start_key.flag == HA_READ_KEY_EXACT &&
|
|
|
|
!check_null_in_key(key_info, multi_range_curr->start_key.key,
|
|
|
|
multi_range_curr->start_key.length)))
|
|
|
|
goto range;
|
|
|
|
// else fall through
|
2004-11-26 15:15:22 +01:00
|
|
|
case UNIQUE_INDEX:
|
2004-11-17 10:07:52 +01:00
|
|
|
{
|
2004-12-28 17:01:07 +01:00
|
|
|
multi_range_curr->range_flag |= UNIQUE_RANGE;
|
2004-11-17 10:07:52 +01:00
|
|
|
if ((op= m_active_trans->getNdbIndexOperation(unique_idx, tab)) &&
|
2005-02-16 14:18:32 +01:00
|
|
|
!op->readTuple(lm) &&
|
|
|
|
!set_index_key(op, key_info, multi_range_curr->start_key.key) &&
|
|
|
|
!define_read_attrs(curr, op) &&
|
2005-05-06 10:39:30 +02:00
|
|
|
(op->setAbortOption(AO_IgnoreError), TRUE))
|
2005-02-16 14:18:32 +01:00
|
|
|
curr += reclength;
|
2004-11-17 10:07:52 +01:00
|
|
|
else
|
2005-02-16 14:18:32 +01:00
|
|
|
ERR_RETURN(op ? op->getNdbError() : m_active_trans->getNdbError());
|
2004-11-26 15:15:22 +01:00
|
|
|
break;
|
|
|
|
}
|
2005-07-18 13:31:02 +02:00
|
|
|
case ORDERED_INDEX: {
|
2004-11-26 15:15:22 +01:00
|
|
|
range:
|
2004-12-28 17:01:07 +01:00
|
|
|
multi_range_curr->range_flag &= ~(uint)UNIQUE_RANGE;
|
2004-11-26 15:15:22 +01:00
|
|
|
if (scanOp == 0)
|
|
|
|
{
|
2005-02-16 14:18:32 +01:00
|
|
|
if (m_multi_cursor)
|
|
|
|
{
|
|
|
|
scanOp= m_multi_cursor;
|
|
|
|
DBUG_ASSERT(scanOp->getSorted() == sorted);
|
|
|
|
DBUG_ASSERT(scanOp->getLockMode() ==
|
|
|
|
(NdbOperation::LockMode)get_ndb_lock_type(m_lock.type));
|
2005-07-04 02:42:33 +02:00
|
|
|
if (scanOp->reset_bounds(m_force_send))
|
2005-02-16 14:18:32 +01:00
|
|
|
DBUG_RETURN(ndb_err(m_active_trans));
|
|
|
|
|
|
|
|
end_of_buffer -= reclength;
|
|
|
|
}
|
|
|
|
else if ((scanOp= m_active_trans->getNdbIndexScanOperation(idx, tab))
|
2006-06-12 14:23:21 +02:00
|
|
|
&&!scanOp->readTuples(lm, 0, parallelism, sorted,
|
|
|
|
FALSE, TRUE, need_pk)
|
2005-02-16 14:18:32 +01:00
|
|
|
&&!generate_scan_filter(m_cond_stack, scanOp)
|
|
|
|
&&!define_read_attrs(end_of_buffer-reclength, scanOp))
|
|
|
|
{
|
|
|
|
m_multi_cursor= scanOp;
|
|
|
|
m_multi_range_cursor_result_ptr= end_of_buffer-reclength;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ERR_RETURN(scanOp ? scanOp->getNdbError() :
|
|
|
|
m_active_trans->getNdbError());
|
|
|
|
}
|
2004-11-26 15:15:22 +01:00
|
|
|
}
|
2005-01-07 15:33:24 +01:00
|
|
|
|
2004-12-28 17:01:07 +01:00
|
|
|
const key_range *keys[2]= { &multi_range_curr->start_key,
|
2005-02-16 14:18:32 +01:00
|
|
|
&multi_range_curr->end_key };
|
2005-09-15 02:33:28 +02:00
|
|
|
if ((res= set_bounds(scanOp, active_index, false, keys,
|
|
|
|
multi_range_curr-ranges)))
|
2005-02-16 14:18:32 +01:00
|
|
|
DBUG_RETURN(res);
|
2004-11-26 15:15:22 +01:00
|
|
|
break;
|
2004-11-17 10:07:52 +01:00
|
|
|
}
|
2005-07-04 02:42:33 +02:00
|
|
|
case UNDEFINED_INDEX:
|
2005-01-11 14:06:44 +01:00
|
|
|
DBUG_ASSERT(FALSE);
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
break;
|
|
|
|
}
|
2004-11-17 10:07:52 +01:00
|
|
|
}
|
|
|
|
|
2004-12-28 17:01:07 +01:00
|
|
|
if (multi_range_curr != multi_range_end)
|
2004-11-17 10:07:52 +01:00
|
|
|
{
|
2004-11-30 07:58:55 +01:00
|
|
|
/**
|
|
|
|
* Mark that we're using entire buffer (even if might not) as
|
|
|
|
* we haven't read all ranges for some reason
|
|
|
|
* This as we don't want mysqld to reuse the buffer when we read
|
|
|
|
* the remaining ranges
|
|
|
|
*/
|
2004-11-26 15:15:22 +01:00
|
|
|
buffer->end_of_used_area= (byte*)buffer->buffer_end;
|
2004-11-17 10:07:52 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
buffer->end_of_used_area= curr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set first operation in multi range
|
|
|
|
*/
|
|
|
|
m_current_multi_operation=
|
|
|
|
lastOp ? lastOp->next() : m_active_trans->getFirstDefinedOperation();
|
2006-08-07 14:48:54 +02:00
|
|
|
if (!(res= execute_no_commit_ie(this, m_active_trans,true)))
|
2004-11-17 10:07:52 +01:00
|
|
|
{
|
2004-12-28 17:01:07 +01:00
|
|
|
m_multi_range_defined= multi_range_curr;
|
|
|
|
multi_range_curr= ranges;
|
2004-11-26 15:15:22 +01:00
|
|
|
m_multi_range_result_ptr= (byte*)buffer->buffer;
|
|
|
|
DBUG_RETURN(read_multi_range_next(found_range_p));
|
2004-11-17 10:07:52 +01:00
|
|
|
}
|
|
|
|
ERR_RETURN(m_active_trans->getNdbError());
|
|
|
|
}
|
|
|
|
|
2004-12-08 00:36:40 +01:00
|
|
|
#if 0
|
2005-07-18 13:31:02 +02:00
|
|
|
#define DBUG_MULTI_RANGE(x) DBUG_PRINT("info", ("read_multi_range_next: case %d\n", x));
|
2004-12-08 00:36:40 +01:00
|
|
|
#else
|
|
|
|
#define DBUG_MULTI_RANGE(x)
|
|
|
|
#endif
|
|
|
|
|
2004-11-17 10:07:52 +01:00
|
|
|
int
|
2004-12-28 17:01:07 +01:00
|
|
|
ha_ndbcluster::read_multi_range_next(KEY_MULTI_RANGE ** multi_range_found_p)
|
2004-11-17 10:07:52 +01:00
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_ndbcluster::read_multi_range_next");
|
2004-11-26 15:15:22 +01:00
|
|
|
if (m_disable_multi_read)
|
2004-11-30 07:58:55 +01:00
|
|
|
{
|
2005-07-18 13:31:02 +02:00
|
|
|
DBUG_MULTI_RANGE(11);
|
2004-11-26 15:15:22 +01:00
|
|
|
DBUG_RETURN(handler::read_multi_range_next(multi_range_found_p));
|
2004-11-30 07:58:55 +01:00
|
|
|
}
|
2004-12-07 15:15:49 +01:00
|
|
|
|
2004-11-26 15:15:22 +01:00
|
|
|
int res;
|
2004-12-07 15:15:49 +01:00
|
|
|
int range_no;
|
2006-01-17 08:40:00 +01:00
|
|
|
ulong reclength= table_share->reclength;
|
2004-11-26 15:15:22 +01:00
|
|
|
const NdbOperation* op= m_current_multi_operation;
|
2005-06-01 15:35:09 +02:00
|
|
|
for (;multi_range_curr < m_multi_range_defined; multi_range_curr++)
|
2004-11-17 10:07:52 +01:00
|
|
|
{
|
2005-07-18 13:31:02 +02:00
|
|
|
DBUG_MULTI_RANGE(12);
|
|
|
|
if (multi_range_curr->range_flag & SKIP_RANGE)
|
|
|
|
continue;
|
2004-12-28 17:01:07 +01:00
|
|
|
if (multi_range_curr->range_flag & UNIQUE_RANGE)
|
2004-11-26 15:15:22 +01:00
|
|
|
{
|
2004-12-07 15:15:49 +01:00
|
|
|
if (op->getNdbError().code == 0)
|
2005-07-18 13:31:02 +02:00
|
|
|
{
|
|
|
|
DBUG_MULTI_RANGE(13);
|
2005-02-16 14:18:32 +01:00
|
|
|
goto found_next;
|
2005-07-18 13:31:02 +02:00
|
|
|
}
|
2004-11-26 15:15:22 +01:00
|
|
|
|
|
|
|
op= m_active_trans->getNextCompletedOperation(op);
|
|
|
|
m_multi_range_result_ptr += reclength;
|
2004-12-07 15:15:49 +01:00
|
|
|
continue;
|
2004-11-26 15:15:22 +01:00
|
|
|
}
|
2004-12-07 15:15:49 +01:00
|
|
|
else if (m_multi_cursor && !multi_range_sorted)
|
2004-11-26 15:15:22 +01:00
|
|
|
{
|
2004-12-08 00:36:40 +01:00
|
|
|
DBUG_MULTI_RANGE(1);
|
|
|
|
if ((res= fetch_next(m_multi_cursor)) == 0)
|
2004-12-07 15:15:49 +01:00
|
|
|
{
|
2005-02-16 14:18:32 +01:00
|
|
|
DBUG_MULTI_RANGE(2);
|
|
|
|
range_no= m_multi_cursor->get_range_no();
|
|
|
|
goto found;
|
2004-12-07 15:15:49 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-07-18 13:31:02 +02:00
|
|
|
DBUG_MULTI_RANGE(14);
|
2005-02-16 14:18:32 +01:00
|
|
|
goto close_scan;
|
2004-12-07 15:15:49 +01:00
|
|
|
}
|
|
|
|
}
|
2004-12-08 00:36:40 +01:00
|
|
|
else if (m_multi_cursor && multi_range_sorted)
|
2004-12-07 15:15:49 +01:00
|
|
|
{
|
2004-12-08 00:36:40 +01:00
|
|
|
if (m_active_cursor && (res= fetch_next(m_multi_cursor)))
|
|
|
|
{
|
2005-02-16 14:18:32 +01:00
|
|
|
DBUG_MULTI_RANGE(3);
|
|
|
|
goto close_scan;
|
2004-12-08 00:36:40 +01:00
|
|
|
}
|
2004-11-29 13:50:13 +01:00
|
|
|
|
2004-12-07 15:15:49 +01:00
|
|
|
range_no= m_multi_cursor->get_range_no();
|
2004-12-28 17:01:07 +01:00
|
|
|
uint current_range_no= multi_range_curr - m_multi_ranges;
|
2005-01-11 14:06:44 +01:00
|
|
|
if ((uint) range_no == current_range_no)
|
2004-12-07 15:15:49 +01:00
|
|
|
{
|
2005-02-16 14:18:32 +01:00
|
|
|
DBUG_MULTI_RANGE(4);
|
2004-12-07 15:15:49 +01:00
|
|
|
// return current row
|
2005-02-16 14:18:32 +01:00
|
|
|
goto found;
|
2004-12-07 15:15:49 +01:00
|
|
|
}
|
2004-12-28 17:01:07 +01:00
|
|
|
else if (range_no > (int)current_range_no)
|
2004-12-07 15:15:49 +01:00
|
|
|
{
|
2005-02-16 14:18:32 +01:00
|
|
|
DBUG_MULTI_RANGE(5);
|
|
|
|
// wait with current row
|
|
|
|
m_active_cursor= 0;
|
|
|
|
continue;
|
2004-12-07 15:15:49 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-02-16 14:18:32 +01:00
|
|
|
DBUG_MULTI_RANGE(6);
|
|
|
|
// First fetch from cursor
|
|
|
|
DBUG_ASSERT(range_no == -1);
|
2005-07-04 02:42:33 +02:00
|
|
|
if ((res= m_multi_cursor->nextResult(true)))
|
2005-02-16 14:18:32 +01:00
|
|
|
{
|
2005-07-18 13:31:02 +02:00
|
|
|
DBUG_MULTI_RANGE(15);
|
2005-02-16 14:18:32 +01:00
|
|
|
goto close_scan;
|
|
|
|
}
|
|
|
|
multi_range_curr--; // Will be increased in for-loop
|
|
|
|
continue;
|
2004-12-07 15:15:49 +01:00
|
|
|
}
|
2004-11-26 15:15:22 +01:00
|
|
|
}
|
2004-12-08 00:36:40 +01:00
|
|
|
else /** m_multi_cursor == 0 */
|
2004-11-26 15:15:22 +01:00
|
|
|
{
|
2004-12-08 00:36:40 +01:00
|
|
|
DBUG_MULTI_RANGE(7);
|
2004-11-30 07:58:55 +01:00
|
|
|
/**
|
|
|
|
* Corresponds to range 5 in example in read_multi_range_first
|
|
|
|
*/
|
|
|
|
(void)1;
|
2004-12-07 15:15:49 +01:00
|
|
|
continue;
|
2004-11-26 15:15:22 +01:00
|
|
|
}
|
2004-12-07 15:15:49 +01:00
|
|
|
|
2005-05-06 10:39:30 +02:00
|
|
|
DBUG_ASSERT(FALSE); // Should only get here via goto's
|
2004-12-07 15:15:49 +01:00
|
|
|
close_scan:
|
|
|
|
if (res == 1)
|
|
|
|
{
|
2005-05-06 10:39:30 +02:00
|
|
|
m_multi_cursor->close(FALSE, TRUE);
|
2004-12-07 15:15:49 +01:00
|
|
|
m_active_cursor= m_multi_cursor= 0;
|
2004-12-08 00:36:40 +01:00
|
|
|
DBUG_MULTI_RANGE(8);
|
2004-12-07 15:15:49 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-07-18 13:31:02 +02:00
|
|
|
DBUG_MULTI_RANGE(9);
|
2004-12-07 15:15:49 +01:00
|
|
|
DBUG_RETURN(ndb_err(m_active_trans));
|
|
|
|
}
|
|
|
|
}
|
2004-11-26 15:15:22 +01:00
|
|
|
|
2004-12-28 17:01:07 +01:00
|
|
|
if (multi_range_curr == multi_range_end)
|
2005-07-18 13:31:02 +02:00
|
|
|
{
|
|
|
|
DBUG_MULTI_RANGE(16);
|
2004-11-17 10:07:52 +01:00
|
|
|
DBUG_RETURN(HA_ERR_END_OF_FILE);
|
2005-07-18 13:31:02 +02:00
|
|
|
}
|
2004-11-26 15:15:22 +01:00
|
|
|
|
2004-11-17 10:07:52 +01:00
|
|
|
/**
|
|
|
|
* Read remaining ranges
|
|
|
|
*/
|
|
|
|
DBUG_RETURN(read_multi_range_first(multi_range_found_p,
|
2005-02-16 14:18:32 +01:00
|
|
|
multi_range_curr,
|
|
|
|
multi_range_end - multi_range_curr,
|
|
|
|
multi_range_sorted,
|
|
|
|
multi_range_buffer));
|
2004-11-26 15:15:22 +01:00
|
|
|
|
|
|
|
found:
|
2004-11-30 07:58:55 +01:00
|
|
|
/**
|
|
|
|
* Found a record belonging to a scan
|
|
|
|
*/
|
2004-12-07 15:15:49 +01:00
|
|
|
m_active_cursor= m_multi_cursor;
|
2004-12-28 17:01:07 +01:00
|
|
|
* multi_range_found_p= m_multi_ranges + range_no;
|
2004-12-07 15:15:49 +01:00
|
|
|
memcpy(table->record[0], m_multi_range_cursor_result_ptr, reclength);
|
|
|
|
setup_recattr(m_active_cursor->getFirstRecAttr());
|
2004-11-26 15:15:22 +01:00
|
|
|
unpack_record(table->record[0]);
|
|
|
|
table->status= 0;
|
|
|
|
DBUG_RETURN(0);
|
2004-12-07 15:15:49 +01:00
|
|
|
|
2004-11-29 13:50:13 +01:00
|
|
|
found_next:
|
2004-11-30 07:58:55 +01:00
|
|
|
/**
|
|
|
|
* Found a record belonging to a pk/index op,
|
|
|
|
* copy result and move to next to prepare for next call
|
|
|
|
*/
|
2004-12-28 17:01:07 +01:00
|
|
|
* multi_range_found_p= multi_range_curr;
|
2004-11-29 13:50:13 +01:00
|
|
|
memcpy(table->record[0], m_multi_range_result_ptr, reclength);
|
2004-12-01 12:43:30 +01:00
|
|
|
setup_recattr(op->getFirstRecAttr());
|
2004-11-29 13:50:13 +01:00
|
|
|
unpack_record(table->record[0]);
|
2004-12-01 12:43:30 +01:00
|
|
|
table->status= 0;
|
|
|
|
|
2004-11-29 13:50:13 +01:00
|
|
|
multi_range_curr++;
|
2004-12-01 12:43:30 +01:00
|
|
|
m_current_multi_operation= m_active_trans->getNextCompletedOperation(op);
|
2004-11-29 13:50:13 +01:00
|
|
|
m_multi_range_result_ptr += reclength;
|
|
|
|
DBUG_RETURN(0);
|
2004-11-17 10:07:52 +01:00
|
|
|
}
|
|
|
|
|
2004-12-01 12:43:30 +01:00
|
|
|
int
|
|
|
|
ha_ndbcluster::setup_recattr(const NdbRecAttr* curr)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("setup_recattr");
|
|
|
|
|
|
|
|
Field **field, **end;
|
|
|
|
NdbValue *value= m_value;
|
|
|
|
|
2006-01-17 08:40:00 +01:00
|
|
|
end= table->field + table_share->fields;
|
2004-12-01 12:43:30 +01:00
|
|
|
|
|
|
|
for (field= table->field; field < end; field++, value++)
|
|
|
|
{
|
|
|
|
if ((* value).ptr)
|
|
|
|
{
|
|
|
|
DBUG_ASSERT(curr != 0);
|
2006-03-28 14:38:16 +02:00
|
|
|
NdbValue* val= m_value + curr->getColumn()->getColumnNo();
|
|
|
|
DBUG_ASSERT(val->ptr);
|
|
|
|
val->rec= curr;
|
2004-12-07 15:15:49 +01:00
|
|
|
curr= curr->next();
|
2004-12-01 12:43:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-12-08 00:36:40 +01:00
|
|
|
DBUG_RETURN(0);
|
2004-12-01 12:43:30 +01:00
|
|
|
}
|
|
|
|
|
2005-02-11 22:33:52 +01:00
|
|
|
char*
|
|
|
|
ha_ndbcluster::update_table_comment(
|
2005-02-16 14:18:32 +01:00
|
|
|
/* out: table comment + additional */
|
|
|
|
const char* comment)/* in: table comment defined by user */
|
2005-02-11 22:33:52 +01:00
|
|
|
{
|
|
|
|
uint length= strlen(comment);
|
2005-07-04 02:42:33 +02:00
|
|
|
if (length > 64000 - 3)
|
2005-02-11 22:33:52 +01:00
|
|
|
{
|
|
|
|
return((char*)comment); /* string too long */
|
|
|
|
}
|
|
|
|
|
|
|
|
Ndb* ndb;
|
|
|
|
if (!(ndb= get_ndb()))
|
|
|
|
{
|
|
|
|
return((char*)comment);
|
|
|
|
}
|
|
|
|
|
|
|
|
ndb->setDatabaseName(m_dbname);
|
|
|
|
NDBDICT* dict= ndb->getDictionary();
|
2006-05-04 13:58:17 +02:00
|
|
|
const NDBTAB* tab= m_table;
|
|
|
|
DBUG_ASSERT(tab != NULL);
|
2005-02-11 22:33:52 +01:00
|
|
|
|
|
|
|
char *str;
|
|
|
|
const char *fmt="%s%snumber_of_replicas: %d";
|
|
|
|
const unsigned fmt_len_plus_extra= length + strlen(fmt);
|
|
|
|
if ((str= my_malloc(fmt_len_plus_extra, MYF(0))) == NULL)
|
|
|
|
{
|
|
|
|
return (char*)comment;
|
|
|
|
}
|
|
|
|
|
2005-07-04 02:42:33 +02:00
|
|
|
my_snprintf(str,fmt_len_plus_extra,fmt,comment,
|
|
|
|
length > 0 ? " ":"",
|
|
|
|
tab->getReplicaCount());
|
2005-02-11 22:33:52 +01:00
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Utility thread main loop
|
2005-10-08 16:39:55 +02:00
|
|
|
pthread_handler_t ndb_util_thread_func(void *arg __attribute__((unused)))
|
2005-02-11 22:33:52 +01:00
|
|
|
{
|
|
|
|
THD *thd; /* needs to be first for thread_stack */
|
2005-03-15 15:03:25 +01:00
|
|
|
Ndb* ndb;
|
2005-02-11 22:33:52 +01:00
|
|
|
struct timespec abstime;
|
2005-11-06 00:20:37 +01:00
|
|
|
List<NDB_SHARE> util_open_tables;
|
2005-02-11 22:33:52 +01:00
|
|
|
|
|
|
|
my_thread_init();
|
|
|
|
DBUG_ENTER("ndb_util_thread");
|
|
|
|
DBUG_PRINT("enter", ("ndb_cache_check_time: %d", ndb_cache_check_time));
|
|
|
|
|
|
|
|
thd= new THD; /* note that contructor of THD uses DBUG_ */
|
|
|
|
THD_CHECK_SENTRY(thd);
|
2005-03-15 15:03:25 +01:00
|
|
|
ndb= new Ndb(g_ndb_cluster_connection, "");
|
2005-02-11 22:33:52 +01:00
|
|
|
|
|
|
|
pthread_detach_this_thread();
|
|
|
|
ndb_util_thread= pthread_self();
|
|
|
|
|
|
|
|
thd->thread_stack= (char*)&thd; /* remember where our stack is */
|
2006-02-27 10:29:55 +01:00
|
|
|
if (thd->store_globals() || (ndb->init() != 0))
|
2005-02-11 22:33:52 +01:00
|
|
|
{
|
|
|
|
thd->cleanup();
|
|
|
|
delete thd;
|
2005-04-06 12:27:43 +02:00
|
|
|
delete ndb;
|
2005-02-11 22:33:52 +01:00
|
|
|
DBUG_RETURN(NULL);
|
|
|
|
}
|
2005-11-06 00:20:37 +01:00
|
|
|
thd->init_for_queries();
|
|
|
|
thd->version=refresh_version;
|
|
|
|
thd->set_time();
|
|
|
|
thd->main_security_ctx.host_or_ip= "";
|
|
|
|
thd->client_capabilities = 0;
|
|
|
|
my_net_init(&thd->net, 0);
|
|
|
|
thd->main_security_ctx.master_access= ~0;
|
|
|
|
thd->main_security_ctx.priv_user = 0;
|
2006-06-22 21:44:21 +02:00
|
|
|
thd->current_stmt_binlog_row_based= TRUE; // If in mixed mode
|
2005-11-06 00:20:37 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
wait for mysql server to start
|
|
|
|
*/
|
|
|
|
pthread_mutex_lock(&LOCK_server_started);
|
|
|
|
while (!mysqld_server_started)
|
|
|
|
pthread_cond_wait(&COND_server_started, &LOCK_server_started);
|
|
|
|
pthread_mutex_unlock(&LOCK_server_started);
|
|
|
|
|
2006-04-10 16:08:40 +02:00
|
|
|
ndbcluster_util_inited= 1;
|
|
|
|
|
2005-11-06 00:20:37 +01:00
|
|
|
/*
|
|
|
|
Wait for cluster to start
|
|
|
|
*/
|
|
|
|
pthread_mutex_lock(&LOCK_ndb_util_thread);
|
2006-09-15 19:28:00 +02:00
|
|
|
while (!ndb_cluster_node_id && (ndbcluster_hton->slot != ~(uint)0))
|
2005-11-06 00:20:37 +01:00
|
|
|
{
|
|
|
|
/* ndb not connected yet */
|
|
|
|
set_timespec(abstime, 1);
|
|
|
|
pthread_cond_timedwait(&COND_ndb_util_thread,
|
|
|
|
&LOCK_ndb_util_thread,
|
|
|
|
&abstime);
|
|
|
|
if (abort_loop)
|
|
|
|
{
|
|
|
|
pthread_mutex_unlock(&LOCK_ndb_util_thread);
|
|
|
|
goto ndb_util_thread_end;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pthread_mutex_unlock(&LOCK_ndb_util_thread);
|
|
|
|
|
2006-01-12 19:51:02 +01:00
|
|
|
{
|
|
|
|
Thd_ndb *thd_ndb;
|
|
|
|
if (!(thd_ndb= ha_ndbcluster::seize_thd_ndb()))
|
|
|
|
{
|
|
|
|
sql_print_error("Could not allocate Thd_ndb object");
|
|
|
|
goto ndb_util_thread_end;
|
|
|
|
}
|
|
|
|
set_thd_ndb(thd, thd_ndb);
|
|
|
|
thd_ndb->options|= TNO_NO_LOG_SCHEMA_OP;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAVE_NDB_BINLOG
|
2006-04-10 16:08:40 +02:00
|
|
|
if (ndb_extra_logging && ndb_binlog_running)
|
|
|
|
sql_print_information("NDB Binlog: Ndb tables initially read only.");
|
2006-01-12 19:51:02 +01:00
|
|
|
/* create tables needed by the replication */
|
|
|
|
ndbcluster_setup_binlog_table_shares(thd);
|
|
|
|
#else
|
2005-11-06 00:20:37 +01:00
|
|
|
/*
|
|
|
|
Get all table definitions from the storage node
|
|
|
|
*/
|
|
|
|
ndbcluster_find_all_files(thd);
|
2006-01-12 19:51:02 +01:00
|
|
|
#endif
|
2005-11-06 00:20:37 +01:00
|
|
|
|
2005-02-21 14:04:54 +01:00
|
|
|
set_timespec(abstime, 0);
|
2005-11-06 00:20:37 +01:00
|
|
|
for (;!abort_loop;)
|
2005-02-11 22:33:52 +01:00
|
|
|
{
|
|
|
|
pthread_mutex_lock(&LOCK_ndb_util_thread);
|
2005-10-11 23:58:22 +02:00
|
|
|
pthread_cond_timedwait(&COND_ndb_util_thread,
|
|
|
|
&LOCK_ndb_util_thread,
|
|
|
|
&abstime);
|
2005-02-11 22:33:52 +01:00
|
|
|
pthread_mutex_unlock(&LOCK_ndb_util_thread);
|
2005-11-06 00:20:37 +01:00
|
|
|
#ifdef NDB_EXTRA_DEBUG_UTIL_THREAD
|
2005-02-11 22:33:52 +01:00
|
|
|
DBUG_PRINT("ndb_util_thread", ("Started, ndb_cache_check_time: %d",
|
|
|
|
ndb_cache_check_time));
|
2005-11-06 00:20:37 +01:00
|
|
|
#endif
|
2005-02-11 22:33:52 +01:00
|
|
|
if (abort_loop)
|
|
|
|
break; /* Shutting down server */
|
|
|
|
|
2006-01-12 19:51:02 +01:00
|
|
|
#ifdef HAVE_NDB_BINLOG
|
|
|
|
/*
|
|
|
|
Check that the apply_status_share and schema_share has been created.
|
|
|
|
If not try to create it
|
|
|
|
*/
|
2006-04-10 16:08:40 +02:00
|
|
|
if (!ndb_binlog_tables_inited)
|
2006-01-12 19:51:02 +01:00
|
|
|
ndbcluster_setup_binlog_table_shares(thd);
|
|
|
|
#endif
|
|
|
|
|
2005-02-11 22:33:52 +01:00
|
|
|
if (ndb_cache_check_time == 0)
|
|
|
|
{
|
2005-03-15 15:03:25 +01:00
|
|
|
/* Wake up in 1 second to check if value has changed */
|
|
|
|
set_timespec(abstime, 1);
|
2005-02-11 22:33:52 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Lock mutex and fill list with pointers to all open tables */
|
|
|
|
NDB_SHARE *share;
|
|
|
|
pthread_mutex_lock(&ndbcluster_mutex);
|
|
|
|
for (uint i= 0; i < ndbcluster_open_tables.records; i++)
|
|
|
|
{
|
|
|
|
share= (NDB_SHARE *)hash_element(&ndbcluster_open_tables, i);
|
2006-01-12 19:51:02 +01:00
|
|
|
#ifdef HAVE_NDB_BINLOG
|
|
|
|
if ((share->use_count - (int) (share->op != 0) - (int) (share->op != 0))
|
|
|
|
<= 0)
|
|
|
|
continue; // injector thread is the only user, skip statistics
|
|
|
|
share->util_lock= current_thd; // Mark that util thread has lock
|
|
|
|
#endif /* HAVE_NDB_BINLOG */
|
2005-02-11 22:33:52 +01:00
|
|
|
share->use_count++; /* Make sure the table can't be closed */
|
|
|
|
DBUG_PRINT("ndb_util_thread",
|
|
|
|
("Found open table[%d]: %s, use_count: %d",
|
|
|
|
i, share->table_name, share->use_count));
|
|
|
|
|
|
|
|
/* Store pointer to table */
|
|
|
|
util_open_tables.push_back(share);
|
|
|
|
}
|
|
|
|
pthread_mutex_unlock(&ndbcluster_mutex);
|
|
|
|
|
|
|
|
/* Iterate through the open files list */
|
|
|
|
List_iterator_fast<NDB_SHARE> it(util_open_tables);
|
2005-02-16 14:18:32 +01:00
|
|
|
while ((share= it++))
|
2005-02-11 22:33:52 +01:00
|
|
|
{
|
2006-01-12 19:51:02 +01:00
|
|
|
#ifdef HAVE_NDB_BINLOG
|
|
|
|
if ((share->use_count - (int) (share->op != 0) - (int) (share->op != 0))
|
|
|
|
<= 1)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Util thread and injector thread is the only user, skip statistics
|
|
|
|
*/
|
|
|
|
free_share(&share);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#endif /* HAVE_NDB_BINLOG */
|
2005-02-11 22:33:52 +01:00
|
|
|
DBUG_PRINT("ndb_util_thread",
|
2005-03-15 15:03:25 +01:00
|
|
|
("Fetching commit count for: %s",
|
2005-11-06 00:20:37 +01:00
|
|
|
share->key));
|
2005-02-11 22:33:52 +01:00
|
|
|
|
|
|
|
/* Contact NDB to get commit count for table */
|
2005-11-06 00:20:37 +01:00
|
|
|
ndb->setDatabaseName(share->db);
|
2005-03-15 15:03:25 +01:00
|
|
|
struct Ndb_statistics stat;
|
|
|
|
|
|
|
|
uint lock;
|
|
|
|
pthread_mutex_lock(&share->mutex);
|
|
|
|
lock= share->commit_count_lock;
|
|
|
|
pthread_mutex_unlock(&share->mutex);
|
|
|
|
|
2005-02-11 22:33:52 +01:00
|
|
|
{
|
2006-05-04 13:58:17 +02:00
|
|
|
Ndb_table_guard ndbtab_g(ndb->getDictionary(), share->table_name);
|
|
|
|
if (ndbtab_g.get_table() &&
|
|
|
|
ndb_get_table_statistics(ndb, ndbtab_g.get_table(), &stat) == 0)
|
|
|
|
{
|
2006-07-13 20:09:36 +02:00
|
|
|
char buff[22], buff2[22];
|
2006-05-04 13:58:17 +02:00
|
|
|
DBUG_PRINT("ndb_util_thread",
|
|
|
|
("Table: %s, commit_count: %llu, rows: %llu",
|
2006-07-13 20:09:36 +02:00
|
|
|
share->key,
|
|
|
|
llstr(stat.commit_count, buff),
|
2006-07-14 00:07:37 +02:00
|
|
|
llstr(stat.row_count, buff2)));
|
2006-05-04 13:58:17 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DBUG_PRINT("ndb_util_thread",
|
|
|
|
("Error: Could not get commit count for table %s",
|
|
|
|
share->key));
|
|
|
|
stat.commit_count= 0;
|
|
|
|
}
|
2005-02-11 22:33:52 +01:00
|
|
|
}
|
2005-03-15 15:03:25 +01:00
|
|
|
|
|
|
|
pthread_mutex_lock(&share->mutex);
|
|
|
|
if (share->commit_count_lock == lock)
|
|
|
|
share->commit_count= stat.commit_count;
|
|
|
|
pthread_mutex_unlock(&share->mutex);
|
|
|
|
|
2005-02-11 22:33:52 +01:00
|
|
|
/* Decrease the use count and possibly free share */
|
2005-11-06 00:20:37 +01:00
|
|
|
free_share(&share);
|
2005-02-11 22:33:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear the list of open tables */
|
|
|
|
util_open_tables.empty();
|
|
|
|
|
2005-03-15 15:03:25 +01:00
|
|
|
/* Calculate new time to wake up */
|
|
|
|
int secs= 0;
|
|
|
|
int msecs= ndb_cache_check_time;
|
|
|
|
|
|
|
|
struct timeval tick_time;
|
|
|
|
gettimeofday(&tick_time, 0);
|
|
|
|
abstime.tv_sec= tick_time.tv_sec;
|
|
|
|
abstime.tv_nsec= tick_time.tv_usec * 1000;
|
|
|
|
|
2005-07-04 02:42:33 +02:00
|
|
|
if (msecs >= 1000){
|
2005-03-15 15:03:25 +01:00
|
|
|
secs= msecs / 1000;
|
|
|
|
msecs= msecs % 1000;
|
|
|
|
}
|
|
|
|
|
|
|
|
abstime.tv_sec+= secs;
|
|
|
|
abstime.tv_nsec+= msecs * 1000000;
|
|
|
|
if (abstime.tv_nsec >= 1000000000) {
|
|
|
|
abstime.tv_sec+= 1;
|
|
|
|
abstime.tv_nsec-= 1000000000;
|
|
|
|
}
|
2005-02-11 22:33:52 +01:00
|
|
|
}
|
2005-11-06 00:20:37 +01:00
|
|
|
ndb_util_thread_end:
|
2006-01-12 19:51:02 +01:00
|
|
|
sql_print_information("Stopping Cluster Utility thread");
|
2005-11-06 00:20:37 +01:00
|
|
|
net_end(&thd->net);
|
2005-02-11 22:33:52 +01:00
|
|
|
thd->cleanup();
|
|
|
|
delete thd;
|
2005-04-06 12:27:43 +02:00
|
|
|
delete ndb;
|
2005-02-11 22:33:52 +01:00
|
|
|
DBUG_PRINT("exit", ("ndb_util_thread"));
|
|
|
|
my_thread_end();
|
|
|
|
pthread_exit(0);
|
|
|
|
DBUG_RETURN(NULL);
|
|
|
|
}
|
|
|
|
|
2004-12-17 21:13:22 +01:00
|
|
|
/*
|
|
|
|
Condition pushdown
|
|
|
|
*/
|
2005-02-16 14:18:32 +01:00
|
|
|
/*
|
|
|
|
Push a condition to ndbcluster storage engine for evaluation
|
|
|
|
during table and index scans. The conditions will be stored on a stack
|
|
|
|
for possibly storing several conditions. The stack can be popped
|
|
|
|
by calling cond_pop, handler::extra(HA_EXTRA_RESET) (handler::reset())
|
|
|
|
will clear the stack.
|
|
|
|
The current implementation supports arbitrary AND/OR nested conditions
|
|
|
|
with comparisons between columns and constants (including constant
|
|
|
|
expressions and function calls) and the following comparison operators:
|
|
|
|
=, !=, >, >=, <, <=, "is null", and "is not null".
|
|
|
|
|
|
|
|
RETURN
|
|
|
|
NULL The condition was supported and will be evaluated for each
|
|
|
|
row found during the scan
|
|
|
|
cond The condition was not supported and all rows will be returned from
|
|
|
|
the scan for evaluation (and thus not saved on stack)
|
|
|
|
*/
|
2004-12-17 21:13:22 +01:00
|
|
|
const
|
|
|
|
COND*
|
|
|
|
ha_ndbcluster::cond_push(const COND *cond)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("cond_push");
|
2005-05-08 22:42:40 +02:00
|
|
|
Ndb_cond_stack *ndb_cond = new Ndb_cond_stack();
|
|
|
|
DBUG_EXECUTE("where",print_where((COND *)cond, m_tabname););
|
|
|
|
if (m_cond_stack)
|
2005-05-07 22:41:30 +02:00
|
|
|
ndb_cond->next= m_cond_stack;
|
2005-05-08 22:42:40 +02:00
|
|
|
else
|
|
|
|
ndb_cond->next= NULL;
|
|
|
|
m_cond_stack= ndb_cond;
|
|
|
|
|
|
|
|
if (serialize_cond(cond, ndb_cond))
|
|
|
|
{
|
2005-02-11 22:05:24 +01:00
|
|
|
DBUG_RETURN(NULL);
|
2005-05-08 22:42:40 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cond_pop();
|
2005-02-11 22:05:24 +01:00
|
|
|
}
|
2004-12-17 21:13:22 +01:00
|
|
|
DBUG_RETURN(cond);
|
|
|
|
}
|
|
|
|
|
2005-02-16 14:18:32 +01:00
|
|
|
/*
|
|
|
|
Pop the top condition from the condition stack of the handler instance.
|
|
|
|
*/
|
2004-12-17 21:13:22 +01:00
|
|
|
void
|
|
|
|
ha_ndbcluster::cond_pop()
|
|
|
|
{
|
|
|
|
Ndb_cond_stack *ndb_cond_stack= m_cond_stack;
|
|
|
|
if (ndb_cond_stack)
|
|
|
|
{
|
|
|
|
m_cond_stack= ndb_cond_stack->next;
|
|
|
|
delete ndb_cond_stack;
|
|
|
|
}
|
2005-02-11 22:05:24 +01:00
|
|
|
}
|
2004-12-17 21:13:22 +01:00
|
|
|
|
2005-02-16 14:18:32 +01:00
|
|
|
/*
|
|
|
|
Clear the condition stack
|
|
|
|
*/
|
2004-12-17 21:13:22 +01:00
|
|
|
void
|
|
|
|
ha_ndbcluster::cond_clear()
|
|
|
|
{
|
|
|
|
DBUG_ENTER("cond_clear");
|
|
|
|
while (m_cond_stack)
|
|
|
|
cond_pop();
|
|
|
|
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
2005-02-16 14:18:32 +01:00
|
|
|
/*
|
|
|
|
Serialize the item tree into a linked list represented by Ndb_cond
|
|
|
|
for fast generation of NbdScanFilter. Adds information such as
|
|
|
|
position of fields that is not directly available in the Item tree.
|
|
|
|
Also checks if condition is supported.
|
|
|
|
*/
|
2004-12-17 21:13:22 +01:00
|
|
|
void ndb_serialize_cond(const Item *item, void *arg)
|
|
|
|
{
|
|
|
|
Ndb_cond_traverse_context *context= (Ndb_cond_traverse_context *) arg;
|
|
|
|
DBUG_ENTER("ndb_serialize_cond");
|
|
|
|
|
2005-02-11 22:05:24 +01:00
|
|
|
// Check if we are skipping arguments to a function to be evaluated
|
|
|
|
if (context->skip)
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("Skiping argument %d", context->skip));
|
|
|
|
context->skip--;
|
2005-07-04 02:42:33 +02:00
|
|
|
switch (item->type()) {
|
|
|
|
case Item::FUNC_ITEM:
|
|
|
|
{
|
2005-02-11 22:05:24 +01:00
|
|
|
Item_func *func_item= (Item_func *) item;
|
|
|
|
context->skip+= func_item->argument_count();
|
|
|
|
break;
|
|
|
|
}
|
2005-07-04 02:42:33 +02:00
|
|
|
case Item::INT_ITEM:
|
|
|
|
case Item::REAL_ITEM:
|
|
|
|
case Item::STRING_ITEM:
|
|
|
|
case Item::VARBIN_ITEM:
|
|
|
|
case Item::DECIMAL_ITEM:
|
2005-02-11 22:05:24 +01:00
|
|
|
break;
|
|
|
|
default:
|
2005-02-16 14:18:32 +01:00
|
|
|
context->supported= FALSE;
|
2005-02-11 22:05:24 +01:00
|
|
|
break;
|
|
|
|
}
|
2005-05-18 14:32:05 +02:00
|
|
|
|
2005-02-11 22:05:24 +01:00
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
2005-02-16 14:18:32 +01:00
|
|
|
if (context->supported)
|
2004-12-17 21:13:22 +01:00
|
|
|
{
|
2005-05-18 14:32:05 +02:00
|
|
|
Ndb_rewrite_context *rewrite_context= context->rewrite_stack;
|
|
|
|
const Item_func *func_item;
|
|
|
|
// Check if we are rewriting some unsupported function call
|
|
|
|
if (rewrite_context &&
|
|
|
|
(func_item= rewrite_context->func_item) &&
|
|
|
|
rewrite_context->count++ == 0)
|
2005-02-11 22:05:24 +01:00
|
|
|
{
|
2005-07-04 02:42:33 +02:00
|
|
|
switch (func_item->functype()) {
|
|
|
|
case Item_func::BETWEEN:
|
2005-02-16 14:18:32 +01:00
|
|
|
/*
|
2005-05-18 14:32:05 +02:00
|
|
|
Rewrite
|
|
|
|
<field>|<const> BETWEEN <const1>|<field1> AND <const2>|<field2>
|
|
|
|
to <field>|<const> > <const1>|<field1> AND
|
|
|
|
<field>|<const> < <const2>|<field2>
|
|
|
|
or actually in prefix format
|
|
|
|
BEGIN(AND) GT(<field>|<const>, <const1>|<field1>),
|
|
|
|
LT(<field>|<const>, <const2>|<field2>), END()
|
2005-02-16 14:18:32 +01:00
|
|
|
*/
|
2005-07-04 02:42:33 +02:00
|
|
|
case Item_func::IN_FUNC:
|
|
|
|
{
|
2005-05-18 14:32:05 +02:00
|
|
|
/*
|
|
|
|
Rewrite <field>|<const> IN(<const1>|<field1>, <const2>|<field2>,..)
|
|
|
|
to <field>|<const> = <const1>|<field1> OR
|
|
|
|
<field> = <const2>|<field2> ...
|
|
|
|
or actually in prefix format
|
|
|
|
BEGIN(OR) EQ(<field>|<const>, <const1><field1>),
|
|
|
|
EQ(<field>|<const>, <const2>|<field2>), ... END()
|
|
|
|
Each part of the disjunction is added for each call
|
|
|
|
to ndb_serialize_cond and end of rewrite statement
|
|
|
|
is wrapped in end of ndb_serialize_cond
|
|
|
|
*/
|
|
|
|
if (context->expecting(item->type()))
|
|
|
|
{
|
|
|
|
// This is the <field>|<const> item, save it in the rewrite context
|
|
|
|
rewrite_context->left_hand_item= item;
|
|
|
|
if (item->type() == Item::FUNC_ITEM)
|
2005-02-16 14:18:32 +01:00
|
|
|
{
|
2005-05-18 14:32:05 +02:00
|
|
|
Item_func *func_item= (Item_func *) item;
|
|
|
|
if (func_item->functype() == Item_func::UNKNOWN_FUNC &&
|
|
|
|
func_item->const_item())
|
2005-02-16 14:18:32 +01:00
|
|
|
{
|
2005-05-18 14:32:05 +02:00
|
|
|
// Skip any arguments since we will evaluate function instead
|
|
|
|
DBUG_PRINT("info", ("Skip until end of arguments marker"));
|
|
|
|
context->skip= func_item->argument_count();
|
2005-02-23 15:51:26 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-05-18 14:32:05 +02:00
|
|
|
DBUG_PRINT("info", ("Found unsupported functional expression in BETWEEN|IN"));
|
|
|
|
context->supported= FALSE;
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
|
2005-02-16 14:18:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-02-23 15:51:26 +01:00
|
|
|
else
|
|
|
|
{
|
2005-05-18 14:32:05 +02:00
|
|
|
// Non-supported BETWEEN|IN expression
|
|
|
|
DBUG_PRINT("info", ("Found unexpected item of type %u in BETWEEN|IN",
|
|
|
|
item->type()));
|
2005-02-23 15:51:26 +01:00
|
|
|
context->supported= FALSE;
|
2005-05-18 14:32:05 +02:00
|
|
|
DBUG_VOID_RETURN;
|
2005-02-23 15:51:26 +01:00
|
|
|
}
|
2005-05-18 14:32:05 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
context->supported= FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Ndb_cond_stack *ndb_stack= context->stack_ptr;
|
|
|
|
Ndb_cond *prev_cond= context->cond_ptr;
|
|
|
|
Ndb_cond *curr_cond= context->cond_ptr= new Ndb_cond();
|
|
|
|
if (!ndb_stack->ndb_cond)
|
|
|
|
ndb_stack->ndb_cond= curr_cond;
|
|
|
|
curr_cond->prev= prev_cond;
|
|
|
|
if (prev_cond) prev_cond->next= curr_cond;
|
|
|
|
// Check if we are rewriting some unsupported function call
|
|
|
|
if (context->rewrite_stack)
|
|
|
|
{
|
|
|
|
Ndb_rewrite_context *rewrite_context= context->rewrite_stack;
|
|
|
|
const Item_func *func_item= rewrite_context->func_item;
|
2005-07-04 02:42:33 +02:00
|
|
|
switch (func_item->functype()) {
|
|
|
|
case Item_func::BETWEEN:
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Rewrite
|
|
|
|
<field>|<const> BETWEEN <const1>|<field1> AND <const2>|<field2>
|
|
|
|
to <field>|<const> > <const1>|<field1> AND
|
|
|
|
<field>|<const> < <const2>|<field2>
|
|
|
|
or actually in prefix format
|
|
|
|
BEGIN(AND) GT(<field>|<const>, <const1>|<field1>),
|
|
|
|
LT(<field>|<const>, <const2>|<field2>), END()
|
|
|
|
*/
|
2005-05-18 14:32:05 +02:00
|
|
|
if (rewrite_context->count == 2)
|
|
|
|
{
|
|
|
|
// Lower limit of BETWEEN
|
|
|
|
DBUG_PRINT("info", ("GE_FUNC"));
|
|
|
|
curr_cond->ndb_item= new Ndb_item(Item_func::GE_FUNC, 2);
|
|
|
|
}
|
|
|
|
else if (rewrite_context->count == 3)
|
|
|
|
{
|
|
|
|
// Upper limit of BETWEEN
|
|
|
|
DBUG_PRINT("info", ("LE_FUNC"));
|
|
|
|
curr_cond->ndb_item= new Ndb_item(Item_func::LE_FUNC, 2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Illegal BETWEEN expression
|
|
|
|
DBUG_PRINT("info", ("Illegal BETWEEN expression"));
|
|
|
|
context->supported= FALSE;
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
2005-02-16 14:18:32 +01:00
|
|
|
break;
|
|
|
|
}
|
2005-07-04 02:42:33 +02:00
|
|
|
case Item_func::IN_FUNC:
|
|
|
|
{
|
2005-05-18 14:32:05 +02:00
|
|
|
/*
|
|
|
|
Rewrite <field>|<const> IN(<const1>|<field1>, <const2>|<field2>,..)
|
|
|
|
to <field>|<const> = <const1>|<field1> OR
|
|
|
|
<field> = <const2>|<field2> ...
|
|
|
|
or actually in prefix format
|
|
|
|
BEGIN(OR) EQ(<field>|<const>, <const1><field1>),
|
|
|
|
EQ(<field>|<const>, <const2>|<field2>), ... END()
|
|
|
|
Each part of the disjunction is added for each call
|
|
|
|
to ndb_serialize_cond and end of rewrite statement
|
|
|
|
is wrapped in end of ndb_serialize_cond
|
|
|
|
*/
|
|
|
|
DBUG_PRINT("info", ("EQ_FUNC"));
|
|
|
|
curr_cond->ndb_item= new Ndb_item(Item_func::EQ_FUNC, 2);
|
2005-02-16 14:18:32 +01:00
|
|
|
break;
|
|
|
|
}
|
2005-05-18 14:32:05 +02:00
|
|
|
default:
|
|
|
|
context->supported= FALSE;
|
2005-02-18 21:43:51 +01:00
|
|
|
}
|
2005-05-18 14:32:05 +02:00
|
|
|
// Handle left hand <field>|<const>
|
|
|
|
context->rewrite_stack= NULL; // Disable rewrite mode
|
|
|
|
context->expect_only(Item::FIELD_ITEM);
|
|
|
|
context->expect_field_result(STRING_RESULT);
|
|
|
|
context->expect_field_result(REAL_RESULT);
|
|
|
|
context->expect_field_result(INT_RESULT);
|
|
|
|
context->expect_field_result(DECIMAL_RESULT);
|
|
|
|
context->expect(Item::INT_ITEM);
|
|
|
|
context->expect(Item::STRING_ITEM);
|
|
|
|
context->expect(Item::VARBIN_ITEM);
|
|
|
|
context->expect(Item::FUNC_ITEM);
|
|
|
|
ndb_serialize_cond(rewrite_context->left_hand_item, arg);
|
|
|
|
context->skip= 0; // Any FUNC_ITEM expression has already been parsed
|
|
|
|
context->rewrite_stack= rewrite_context; // Enable rewrite mode
|
|
|
|
if (!context->supported)
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
|
|
|
|
prev_cond= context->cond_ptr;
|
|
|
|
curr_cond= context->cond_ptr= new Ndb_cond();
|
|
|
|
prev_cond->next= curr_cond;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for end of AND/OR expression
|
|
|
|
if (!item)
|
|
|
|
{
|
|
|
|
// End marker for condition group
|
|
|
|
DBUG_PRINT("info", ("End of condition group"));
|
|
|
|
curr_cond->ndb_item= new Ndb_item(NDB_END_COND);
|
|
|
|
}
|
|
|
|
else
|
2005-07-04 02:42:33 +02:00
|
|
|
{
|
|
|
|
switch (item->type()) {
|
|
|
|
case Item::FIELD_ITEM:
|
|
|
|
{
|
2005-05-18 14:32:05 +02:00
|
|
|
Item_field *field_item= (Item_field *) item;
|
|
|
|
Field *field= field_item->field;
|
|
|
|
enum_field_types type= field->type();
|
|
|
|
/*
|
|
|
|
Check that the field is part of the table of the handler
|
|
|
|
instance and that we expect a field with of this result type.
|
|
|
|
*/
|
|
|
|
if (context->table == field->table)
|
|
|
|
{
|
|
|
|
const NDBTAB *tab= (const NDBTAB *) context->ndb_table;
|
|
|
|
DBUG_PRINT("info", ("FIELD_ITEM"));
|
|
|
|
DBUG_PRINT("info", ("table %s", tab->getName()));
|
|
|
|
DBUG_PRINT("info", ("column %s", field->field_name));
|
2006-09-05 17:07:00 +02:00
|
|
|
DBUG_PRINT("info", ("type %d", field->type()));
|
2005-05-18 14:32:05 +02:00
|
|
|
DBUG_PRINT("info", ("result type %d", field->result_type()));
|
|
|
|
|
|
|
|
// Check that we are expecting a field and with the correct
|
|
|
|
// result type
|
|
|
|
if (context->expecting(Item::FIELD_ITEM) &&
|
2006-09-05 17:07:00 +02:00
|
|
|
context->expecting_field_type(field->type()) &&
|
2005-05-18 14:32:05 +02:00
|
|
|
(context->expecting_field_result(field->result_type()) ||
|
2005-07-31 21:33:46 +02:00
|
|
|
// Date and year can be written as string or int
|
2005-05-18 14:32:05 +02:00
|
|
|
((type == MYSQL_TYPE_TIME ||
|
|
|
|
type == MYSQL_TYPE_DATE ||
|
|
|
|
type == MYSQL_TYPE_YEAR ||
|
|
|
|
type == MYSQL_TYPE_DATETIME)
|
2005-07-31 21:33:46 +02:00
|
|
|
? (context->expecting_field_result(STRING_RESULT) ||
|
|
|
|
context->expecting_field_result(INT_RESULT))
|
|
|
|
: true)) &&
|
2005-05-18 14:32:05 +02:00
|
|
|
// Bit fields no yet supported in scan filter
|
2006-03-28 09:59:20 +02:00
|
|
|
type != MYSQL_TYPE_BIT &&
|
|
|
|
// No BLOB support in scan filter
|
|
|
|
type != MYSQL_TYPE_TINY_BLOB &&
|
2006-03-28 11:46:35 +02:00
|
|
|
type != MYSQL_TYPE_MEDIUM_BLOB &&
|
|
|
|
type != MYSQL_TYPE_LONG_BLOB &&
|
2006-03-28 09:59:20 +02:00
|
|
|
type != MYSQL_TYPE_BLOB)
|
2005-05-18 14:32:05 +02:00
|
|
|
{
|
|
|
|
const NDBCOL *col= tab->getColumn(field->field_name);
|
|
|
|
DBUG_ASSERT(col);
|
|
|
|
curr_cond->ndb_item= new Ndb_item(field, col->getColumnNo());
|
|
|
|
context->dont_expect(Item::FIELD_ITEM);
|
|
|
|
context->expect_no_field_result();
|
2006-09-15 15:51:05 +02:00
|
|
|
if (! context->expecting_nothing())
|
2005-02-16 14:18:32 +01:00
|
|
|
{
|
2005-05-18 14:32:05 +02:00
|
|
|
// We have not seen second argument yet
|
|
|
|
if (type == MYSQL_TYPE_TIME ||
|
|
|
|
type == MYSQL_TYPE_DATE ||
|
|
|
|
type == MYSQL_TYPE_YEAR ||
|
|
|
|
type == MYSQL_TYPE_DATETIME)
|
|
|
|
{
|
|
|
|
context->expect_only(Item::STRING_ITEM);
|
|
|
|
context->expect(Item::INT_ITEM);
|
|
|
|
}
|
|
|
|
else
|
2005-07-04 02:42:33 +02:00
|
|
|
switch (field->result_type()) {
|
|
|
|
case STRING_RESULT:
|
2005-05-18 14:32:05 +02:00
|
|
|
// Expect char string or binary string
|
|
|
|
context->expect_only(Item::STRING_ITEM);
|
|
|
|
context->expect(Item::VARBIN_ITEM);
|
|
|
|
context->expect_collation(field_item->collation.collation);
|
|
|
|
break;
|
2005-07-04 02:42:33 +02:00
|
|
|
case REAL_RESULT:
|
2005-05-18 14:32:05 +02:00
|
|
|
context->expect_only(Item::REAL_ITEM);
|
|
|
|
context->expect(Item::DECIMAL_ITEM);
|
2005-06-10 10:34:05 +02:00
|
|
|
context->expect(Item::INT_ITEM);
|
2005-05-18 14:32:05 +02:00
|
|
|
break;
|
2005-07-04 02:42:33 +02:00
|
|
|
case INT_RESULT:
|
2005-05-18 14:32:05 +02:00
|
|
|
context->expect_only(Item::INT_ITEM);
|
|
|
|
context->expect(Item::VARBIN_ITEM);
|
|
|
|
break;
|
2005-07-04 02:42:33 +02:00
|
|
|
case DECIMAL_RESULT:
|
2005-05-18 14:32:05 +02:00
|
|
|
context->expect_only(Item::DECIMAL_ITEM);
|
|
|
|
context->expect(Item::REAL_ITEM);
|
2005-06-10 10:34:05 +02:00
|
|
|
context->expect(Item::INT_ITEM);
|
2005-05-18 14:32:05 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2005-02-16 14:18:32 +01:00
|
|
|
}
|
|
|
|
else
|
2005-02-23 15:51:26 +01:00
|
|
|
{
|
|
|
|
// Expect another logical expression
|
|
|
|
context->expect_only(Item::FUNC_ITEM);
|
|
|
|
context->expect(Item::COND_ITEM);
|
2005-05-18 14:32:05 +02:00
|
|
|
// Check that field and string constant collations are the same
|
|
|
|
if ((field->result_type() == STRING_RESULT) &&
|
|
|
|
!context->expecting_collation(item->collation.collation)
|
|
|
|
&& type != MYSQL_TYPE_TIME
|
|
|
|
&& type != MYSQL_TYPE_DATE
|
|
|
|
&& type != MYSQL_TYPE_YEAR
|
|
|
|
&& type != MYSQL_TYPE_DATETIME)
|
2005-02-23 15:51:26 +01:00
|
|
|
{
|
2005-02-23 17:18:06 +01:00
|
|
|
DBUG_PRINT("info", ("Found non-matching collation %s",
|
2005-05-18 14:32:05 +02:00
|
|
|
item->collation.collation->name));
|
|
|
|
context->supported= FALSE;
|
2005-02-23 15:51:26 +01:00
|
|
|
}
|
|
|
|
}
|
2005-02-16 14:18:32 +01:00
|
|
|
break;
|
|
|
|
}
|
2005-05-18 14:32:05 +02:00
|
|
|
else
|
|
|
|
{
|
2005-07-31 21:33:46 +02:00
|
|
|
DBUG_PRINT("info", ("Was not expecting field of type %u(%u)",
|
|
|
|
field->result_type(), type));
|
2005-05-18 14:32:05 +02:00
|
|
|
context->supported= FALSE;
|
2005-02-16 14:18:32 +01:00
|
|
|
}
|
2005-05-18 14:32:05 +02:00
|
|
|
}
|
2005-02-16 14:18:32 +01:00
|
|
|
else
|
2005-05-18 14:32:05 +02:00
|
|
|
{
|
2005-11-23 21:45:02 +01:00
|
|
|
DBUG_PRINT("info", ("Was not expecting field from table %s (%s)",
|
|
|
|
context->table->s->table_name.str,
|
|
|
|
field->table->s->table_name.str));
|
2005-02-16 14:18:32 +01:00
|
|
|
context->supported= FALSE;
|
2005-05-18 14:32:05 +02:00
|
|
|
}
|
2005-02-16 14:18:32 +01:00
|
|
|
break;
|
|
|
|
}
|
2005-07-04 02:42:33 +02:00
|
|
|
case Item::FUNC_ITEM:
|
|
|
|
{
|
2005-05-18 14:32:05 +02:00
|
|
|
Item_func *func_item= (Item_func *) item;
|
|
|
|
// Check that we expect a function or functional expression here
|
|
|
|
if (context->expecting(Item::FUNC_ITEM) ||
|
|
|
|
func_item->functype() == Item_func::UNKNOWN_FUNC)
|
|
|
|
context->expect_nothing();
|
|
|
|
else
|
2005-02-16 14:18:32 +01:00
|
|
|
{
|
2005-05-18 14:32:05 +02:00
|
|
|
// Did not expect function here
|
|
|
|
context->supported= FALSE;
|
|
|
|
break;
|
2005-02-16 14:18:32 +01:00
|
|
|
}
|
2005-05-18 14:32:05 +02:00
|
|
|
|
2005-07-04 02:42:33 +02:00
|
|
|
switch (func_item->functype()) {
|
|
|
|
case Item_func::EQ_FUNC:
|
|
|
|
{
|
2005-05-18 14:32:05 +02:00
|
|
|
DBUG_PRINT("info", ("EQ_FUNC"));
|
|
|
|
curr_cond->ndb_item= new Ndb_item(func_item->functype(),
|
|
|
|
func_item);
|
|
|
|
context->expect(Item::STRING_ITEM);
|
|
|
|
context->expect(Item::INT_ITEM);
|
|
|
|
context->expect(Item::REAL_ITEM);
|
|
|
|
context->expect(Item::DECIMAL_ITEM);
|
|
|
|
context->expect(Item::VARBIN_ITEM);
|
|
|
|
context->expect(Item::FIELD_ITEM);
|
|
|
|
context->expect_field_result(STRING_RESULT);
|
|
|
|
context->expect_field_result(REAL_RESULT);
|
|
|
|
context->expect_field_result(INT_RESULT);
|
|
|
|
context->expect_field_result(DECIMAL_RESULT);
|
|
|
|
break;
|
2005-02-23 15:51:26 +01:00
|
|
|
}
|
2005-07-04 02:42:33 +02:00
|
|
|
case Item_func::NE_FUNC:
|
|
|
|
{
|
2005-05-18 14:32:05 +02:00
|
|
|
DBUG_PRINT("info", ("NE_FUNC"));
|
|
|
|
curr_cond->ndb_item= new Ndb_item(func_item->functype(),
|
|
|
|
func_item);
|
|
|
|
context->expect(Item::STRING_ITEM);
|
|
|
|
context->expect(Item::INT_ITEM);
|
|
|
|
context->expect(Item::REAL_ITEM);
|
|
|
|
context->expect(Item::DECIMAL_ITEM);
|
|
|
|
context->expect(Item::VARBIN_ITEM);
|
|
|
|
context->expect(Item::FIELD_ITEM);
|
|
|
|
context->expect_field_result(STRING_RESULT);
|
|
|
|
context->expect_field_result(REAL_RESULT);
|
|
|
|
context->expect_field_result(INT_RESULT);
|
|
|
|
context->expect_field_result(DECIMAL_RESULT);
|
|
|
|
break;
|
2005-02-16 14:18:32 +01:00
|
|
|
}
|
2005-07-04 02:42:33 +02:00
|
|
|
case Item_func::LT_FUNC:
|
|
|
|
{
|
2005-05-18 14:32:05 +02:00
|
|
|
DBUG_PRINT("info", ("LT_FUNC"));
|
|
|
|
curr_cond->ndb_item= new Ndb_item(func_item->functype(),
|
|
|
|
func_item);
|
|
|
|
context->expect(Item::STRING_ITEM);
|
|
|
|
context->expect(Item::INT_ITEM);
|
|
|
|
context->expect(Item::REAL_ITEM);
|
|
|
|
context->expect(Item::DECIMAL_ITEM);
|
|
|
|
context->expect(Item::VARBIN_ITEM);
|
|
|
|
context->expect(Item::FIELD_ITEM);
|
|
|
|
context->expect_field_result(STRING_RESULT);
|
|
|
|
context->expect_field_result(REAL_RESULT);
|
|
|
|
context->expect_field_result(INT_RESULT);
|
|
|
|
context->expect_field_result(DECIMAL_RESULT);
|
|
|
|
break;
|
|
|
|
}
|
2005-07-04 02:42:33 +02:00
|
|
|
case Item_func::LE_FUNC:
|
|
|
|
{
|
2005-05-18 14:32:05 +02:00
|
|
|
DBUG_PRINT("info", ("LE_FUNC"));
|
|
|
|
curr_cond->ndb_item= new Ndb_item(func_item->functype(),
|
|
|
|
func_item);
|
|
|
|
context->expect(Item::STRING_ITEM);
|
|
|
|
context->expect(Item::INT_ITEM);
|
|
|
|
context->expect(Item::REAL_ITEM);
|
|
|
|
context->expect(Item::DECIMAL_ITEM);
|
|
|
|
context->expect(Item::VARBIN_ITEM);
|
|
|
|
context->expect(Item::FIELD_ITEM);
|
|
|
|
context->expect_field_result(STRING_RESULT);
|
|
|
|
context->expect_field_result(REAL_RESULT);
|
|
|
|
context->expect_field_result(INT_RESULT);
|
|
|
|
context->expect_field_result(DECIMAL_RESULT);
|
|
|
|
break;
|
|
|
|
}
|
2005-07-04 02:42:33 +02:00
|
|
|
case Item_func::GE_FUNC:
|
|
|
|
{
|
2005-05-18 14:32:05 +02:00
|
|
|
DBUG_PRINT("info", ("GE_FUNC"));
|
|
|
|
curr_cond->ndb_item= new Ndb_item(func_item->functype(),
|
|
|
|
func_item);
|
|
|
|
context->expect(Item::STRING_ITEM);
|
|
|
|
context->expect(Item::INT_ITEM);
|
|
|
|
context->expect(Item::REAL_ITEM);
|
|
|
|
context->expect(Item::DECIMAL_ITEM);
|
|
|
|
context->expect(Item::VARBIN_ITEM);
|
|
|
|
context->expect(Item::FIELD_ITEM);
|
|
|
|
context->expect_field_result(STRING_RESULT);
|
|
|
|
context->expect_field_result(REAL_RESULT);
|
|
|
|
context->expect_field_result(INT_RESULT);
|
|
|
|
context->expect_field_result(DECIMAL_RESULT);
|
|
|
|
break;
|
|
|
|
}
|
2005-07-04 02:42:33 +02:00
|
|
|
case Item_func::GT_FUNC:
|
|
|
|
{
|
2005-05-18 14:32:05 +02:00
|
|
|
DBUG_PRINT("info", ("GT_FUNC"));
|
|
|
|
curr_cond->ndb_item= new Ndb_item(func_item->functype(),
|
|
|
|
func_item);
|
|
|
|
context->expect(Item::STRING_ITEM);
|
|
|
|
context->expect(Item::REAL_ITEM);
|
|
|
|
context->expect(Item::DECIMAL_ITEM);
|
|
|
|
context->expect(Item::INT_ITEM);
|
|
|
|
context->expect(Item::VARBIN_ITEM);
|
|
|
|
context->expect(Item::FIELD_ITEM);
|
|
|
|
context->expect_field_result(STRING_RESULT);
|
|
|
|
context->expect_field_result(REAL_RESULT);
|
|
|
|
context->expect_field_result(INT_RESULT);
|
|
|
|
context->expect_field_result(DECIMAL_RESULT);
|
|
|
|
break;
|
|
|
|
}
|
2005-07-04 02:42:33 +02:00
|
|
|
case Item_func::LIKE_FUNC:
|
|
|
|
{
|
2005-05-18 14:32:05 +02:00
|
|
|
DBUG_PRINT("info", ("LIKE_FUNC"));
|
|
|
|
curr_cond->ndb_item= new Ndb_item(func_item->functype(),
|
|
|
|
func_item);
|
|
|
|
context->expect(Item::STRING_ITEM);
|
|
|
|
context->expect(Item::FIELD_ITEM);
|
2006-09-05 17:07:00 +02:00
|
|
|
context->expect_only_field_type(MYSQL_TYPE_STRING);
|
|
|
|
context->expect_field_type(MYSQL_TYPE_VAR_STRING);
|
|
|
|
context->expect_field_type(MYSQL_TYPE_VARCHAR);
|
2005-05-18 14:32:05 +02:00
|
|
|
context->expect_field_result(STRING_RESULT);
|
|
|
|
context->expect(Item::FUNC_ITEM);
|
|
|
|
break;
|
|
|
|
}
|
2005-07-04 02:42:33 +02:00
|
|
|
case Item_func::ISNULL_FUNC:
|
|
|
|
{
|
2005-05-18 14:32:05 +02:00
|
|
|
DBUG_PRINT("info", ("ISNULL_FUNC"));
|
|
|
|
curr_cond->ndb_item= new Ndb_item(func_item->functype(),
|
|
|
|
func_item);
|
|
|
|
context->expect(Item::FIELD_ITEM);
|
|
|
|
context->expect_field_result(STRING_RESULT);
|
|
|
|
context->expect_field_result(REAL_RESULT);
|
|
|
|
context->expect_field_result(INT_RESULT);
|
|
|
|
context->expect_field_result(DECIMAL_RESULT);
|
|
|
|
break;
|
|
|
|
}
|
2005-07-04 02:42:33 +02:00
|
|
|
case Item_func::ISNOTNULL_FUNC:
|
|
|
|
{
|
2005-05-18 14:32:05 +02:00
|
|
|
DBUG_PRINT("info", ("ISNOTNULL_FUNC"));
|
|
|
|
curr_cond->ndb_item= new Ndb_item(func_item->functype(),
|
|
|
|
func_item);
|
|
|
|
context->expect(Item::FIELD_ITEM);
|
|
|
|
context->expect_field_result(STRING_RESULT);
|
|
|
|
context->expect_field_result(REAL_RESULT);
|
|
|
|
context->expect_field_result(INT_RESULT);
|
|
|
|
context->expect_field_result(DECIMAL_RESULT);
|
|
|
|
break;
|
|
|
|
}
|
2005-07-04 02:42:33 +02:00
|
|
|
case Item_func::NOT_FUNC:
|
|
|
|
{
|
2005-05-18 14:32:05 +02:00
|
|
|
DBUG_PRINT("info", ("NOT_FUNC"));
|
|
|
|
curr_cond->ndb_item= new Ndb_item(func_item->functype(),
|
|
|
|
func_item);
|
|
|
|
context->expect(Item::FUNC_ITEM);
|
2005-02-23 15:51:26 +01:00
|
|
|
context->expect(Item::COND_ITEM);
|
2005-05-18 14:32:05 +02:00
|
|
|
break;
|
2005-02-23 15:51:26 +01:00
|
|
|
}
|
2005-07-04 02:42:33 +02:00
|
|
|
case Item_func::BETWEEN:
|
|
|
|
{
|
2005-05-18 14:32:05 +02:00
|
|
|
DBUG_PRINT("info", ("BETWEEN, rewriting using AND"));
|
2005-09-12 09:36:07 +02:00
|
|
|
Item_func_between *between_func= (Item_func_between *) func_item;
|
2005-05-18 14:32:05 +02:00
|
|
|
Ndb_rewrite_context *rewrite_context=
|
|
|
|
new Ndb_rewrite_context(func_item);
|
|
|
|
rewrite_context->next= context->rewrite_stack;
|
|
|
|
context->rewrite_stack= rewrite_context;
|
2005-09-12 09:36:07 +02:00
|
|
|
if (between_func->negated)
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("NOT_FUNC"));
|
|
|
|
curr_cond->ndb_item= new Ndb_item(Item_func::NOT_FUNC, 1);
|
|
|
|
prev_cond= curr_cond;
|
|
|
|
curr_cond= context->cond_ptr= new Ndb_cond();
|
|
|
|
curr_cond->prev= prev_cond;
|
|
|
|
prev_cond->next= curr_cond;
|
|
|
|
}
|
2005-05-18 14:32:05 +02:00
|
|
|
DBUG_PRINT("info", ("COND_AND_FUNC"));
|
2005-09-12 09:36:07 +02:00
|
|
|
curr_cond->ndb_item=
|
|
|
|
new Ndb_item(Item_func::COND_AND_FUNC,
|
|
|
|
func_item->argument_count() - 1);
|
2005-02-16 14:18:32 +01:00
|
|
|
context->expect_only(Item::FIELD_ITEM);
|
2005-05-18 14:32:05 +02:00
|
|
|
context->expect(Item::INT_ITEM);
|
|
|
|
context->expect(Item::STRING_ITEM);
|
|
|
|
context->expect(Item::VARBIN_ITEM);
|
|
|
|
context->expect(Item::FUNC_ITEM);
|
|
|
|
break;
|
2005-02-16 14:18:32 +01:00
|
|
|
}
|
2005-07-04 02:42:33 +02:00
|
|
|
case Item_func::IN_FUNC:
|
|
|
|
{
|
2005-05-18 14:32:05 +02:00
|
|
|
DBUG_PRINT("info", ("IN_FUNC, rewriting using OR"));
|
2005-09-12 09:36:07 +02:00
|
|
|
Item_func_in *in_func= (Item_func_in *) func_item;
|
2005-05-18 14:32:05 +02:00
|
|
|
Ndb_rewrite_context *rewrite_context=
|
|
|
|
new Ndb_rewrite_context(func_item);
|
|
|
|
rewrite_context->next= context->rewrite_stack;
|
|
|
|
context->rewrite_stack= rewrite_context;
|
2005-09-12 09:36:07 +02:00
|
|
|
if (in_func->negated)
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("NOT_FUNC"));
|
|
|
|
curr_cond->ndb_item= new Ndb_item(Item_func::NOT_FUNC, 1);
|
|
|
|
prev_cond= curr_cond;
|
|
|
|
curr_cond= context->cond_ptr= new Ndb_cond();
|
|
|
|
curr_cond->prev= prev_cond;
|
|
|
|
prev_cond->next= curr_cond;
|
|
|
|
}
|
2005-05-18 14:32:05 +02:00
|
|
|
DBUG_PRINT("info", ("COND_OR_FUNC"));
|
|
|
|
curr_cond->ndb_item= new Ndb_item(Item_func::COND_OR_FUNC,
|
|
|
|
func_item->argument_count() - 1);
|
|
|
|
context->expect_only(Item::FIELD_ITEM);
|
|
|
|
context->expect(Item::INT_ITEM);
|
|
|
|
context->expect(Item::STRING_ITEM);
|
|
|
|
context->expect(Item::VARBIN_ITEM);
|
|
|
|
context->expect(Item::FUNC_ITEM);
|
|
|
|
break;
|
2005-02-23 15:51:26 +01:00
|
|
|
}
|
2005-07-04 02:42:33 +02:00
|
|
|
case Item_func::UNKNOWN_FUNC:
|
|
|
|
{
|
2005-05-18 14:32:05 +02:00
|
|
|
DBUG_PRINT("info", ("UNKNOWN_FUNC %s",
|
|
|
|
func_item->const_item()?"const":""));
|
|
|
|
DBUG_PRINT("info", ("result type %d", func_item->result_type()));
|
|
|
|
if (func_item->const_item())
|
2005-07-04 02:42:33 +02:00
|
|
|
{
|
|
|
|
switch (func_item->result_type()) {
|
|
|
|
case STRING_RESULT:
|
|
|
|
{
|
2005-05-18 14:32:05 +02:00
|
|
|
NDB_ITEM_QUALIFICATION q;
|
|
|
|
q.value_type= Item::STRING_ITEM;
|
|
|
|
curr_cond->ndb_item= new Ndb_item(NDB_VALUE, q, item);
|
2006-09-15 15:51:05 +02:00
|
|
|
if (! context->expecting_no_field_result())
|
2005-05-18 14:32:05 +02:00
|
|
|
{
|
|
|
|
// We have not seen the field argument yet
|
|
|
|
context->expect_only(Item::FIELD_ITEM);
|
|
|
|
context->expect_only_field_result(STRING_RESULT);
|
|
|
|
context->expect_collation(func_item->collation.collation);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Expect another logical expression
|
|
|
|
context->expect_only(Item::FUNC_ITEM);
|
|
|
|
context->expect(Item::COND_ITEM);
|
|
|
|
// Check that string result have correct collation
|
|
|
|
if (!context->expecting_collation(item->collation.collation))
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("Found non-matching collation %s",
|
|
|
|
item->collation.collation->name));
|
|
|
|
context->supported= FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Skip any arguments since we will evaluate function instead
|
|
|
|
DBUG_PRINT("info", ("Skip until end of arguments marker"));
|
|
|
|
context->skip= func_item->argument_count();
|
|
|
|
break;
|
|
|
|
}
|
2005-07-04 02:42:33 +02:00
|
|
|
case REAL_RESULT:
|
|
|
|
{
|
2005-05-18 14:32:05 +02:00
|
|
|
NDB_ITEM_QUALIFICATION q;
|
|
|
|
q.value_type= Item::REAL_ITEM;
|
|
|
|
curr_cond->ndb_item= new Ndb_item(NDB_VALUE, q, item);
|
2006-09-15 15:51:05 +02:00
|
|
|
if (! context->expecting_no_field_result())
|
2005-05-18 14:32:05 +02:00
|
|
|
{
|
|
|
|
// We have not seen the field argument yet
|
|
|
|
context->expect_only(Item::FIELD_ITEM);
|
|
|
|
context->expect_only_field_result(REAL_RESULT);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Expect another logical expression
|
|
|
|
context->expect_only(Item::FUNC_ITEM);
|
|
|
|
context->expect(Item::COND_ITEM);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Skip any arguments since we will evaluate function instead
|
|
|
|
DBUG_PRINT("info", ("Skip until end of arguments marker"));
|
|
|
|
context->skip= func_item->argument_count();
|
|
|
|
break;
|
|
|
|
}
|
2005-07-04 02:42:33 +02:00
|
|
|
case INT_RESULT:
|
|
|
|
{
|
2005-05-18 14:32:05 +02:00
|
|
|
NDB_ITEM_QUALIFICATION q;
|
|
|
|
q.value_type= Item::INT_ITEM;
|
|
|
|
curr_cond->ndb_item= new Ndb_item(NDB_VALUE, q, item);
|
2006-09-15 15:51:05 +02:00
|
|
|
if (! context->expecting_no_field_result())
|
2005-05-18 14:32:05 +02:00
|
|
|
{
|
|
|
|
// We have not seen the field argument yet
|
|
|
|
context->expect_only(Item::FIELD_ITEM);
|
|
|
|
context->expect_only_field_result(INT_RESULT);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Expect another logical expression
|
|
|
|
context->expect_only(Item::FUNC_ITEM);
|
|
|
|
context->expect(Item::COND_ITEM);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Skip any arguments since we will evaluate function instead
|
|
|
|
DBUG_PRINT("info", ("Skip until end of arguments marker"));
|
|
|
|
context->skip= func_item->argument_count();
|
|
|
|
break;
|
|
|
|
}
|
2005-07-04 02:42:33 +02:00
|
|
|
case DECIMAL_RESULT:
|
|
|
|
{
|
2005-05-18 14:32:05 +02:00
|
|
|
NDB_ITEM_QUALIFICATION q;
|
|
|
|
q.value_type= Item::DECIMAL_ITEM;
|
|
|
|
curr_cond->ndb_item= new Ndb_item(NDB_VALUE, q, item);
|
2006-09-15 15:51:05 +02:00
|
|
|
if (! context->expecting_no_field_result())
|
2005-05-18 14:32:05 +02:00
|
|
|
{
|
|
|
|
// We have not seen the field argument yet
|
|
|
|
context->expect_only(Item::FIELD_ITEM);
|
|
|
|
context->expect_only_field_result(DECIMAL_RESULT);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Expect another logical expression
|
|
|
|
context->expect_only(Item::FUNC_ITEM);
|
|
|
|
context->expect(Item::COND_ITEM);
|
|
|
|
}
|
|
|
|
// Skip any arguments since we will evaluate function instead
|
|
|
|
DBUG_PRINT("info", ("Skip until end of arguments marker"));
|
|
|
|
context->skip= func_item->argument_count();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2005-07-04 02:42:33 +02:00
|
|
|
}
|
2005-05-18 14:32:05 +02:00
|
|
|
else
|
|
|
|
// Function does not return constant expression
|
|
|
|
context->supported= FALSE;
|
|
|
|
break;
|
|
|
|
}
|
2005-07-04 02:42:33 +02:00
|
|
|
default:
|
|
|
|
{
|
2005-05-18 14:32:05 +02:00
|
|
|
DBUG_PRINT("info", ("Found func_item of type %d",
|
|
|
|
func_item->functype()));
|
|
|
|
context->supported= FALSE;
|
2005-02-23 15:51:26 +01:00
|
|
|
}
|
2005-05-18 14:32:05 +02:00
|
|
|
}
|
|
|
|
break;
|
2005-02-16 14:18:32 +01:00
|
|
|
}
|
2005-07-04 02:42:33 +02:00
|
|
|
case Item::STRING_ITEM:
|
2005-05-18 14:32:05 +02:00
|
|
|
DBUG_PRINT("info", ("STRING_ITEM"));
|
|
|
|
if (context->expecting(Item::STRING_ITEM))
|
|
|
|
{
|
2005-02-16 14:18:32 +01:00
|
|
|
#ifndef DBUG_OFF
|
2005-05-18 14:32:05 +02:00
|
|
|
char buff[256];
|
|
|
|
String str(buff,(uint32) sizeof(buff), system_charset_info);
|
|
|
|
str.length(0);
|
|
|
|
Item_string *string_item= (Item_string *) item;
|
|
|
|
DBUG_PRINT("info", ("value \"%s\"",
|
|
|
|
string_item->val_str(&str)->ptr()));
|
2005-02-16 14:18:32 +01:00
|
|
|
#endif
|
2005-05-18 14:32:05 +02:00
|
|
|
NDB_ITEM_QUALIFICATION q;
|
|
|
|
q.value_type= Item::STRING_ITEM;
|
|
|
|
curr_cond->ndb_item= new Ndb_item(NDB_VALUE, q, item);
|
2006-09-15 15:51:05 +02:00
|
|
|
if (! context->expecting_no_field_result())
|
2005-05-18 14:32:05 +02:00
|
|
|
{
|
|
|
|
// We have not seen the field argument yet
|
|
|
|
context->expect_only(Item::FIELD_ITEM);
|
|
|
|
context->expect_only_field_result(STRING_RESULT);
|
|
|
|
context->expect_collation(item->collation.collation);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Expect another logical expression
|
|
|
|
context->expect_only(Item::FUNC_ITEM);
|
|
|
|
context->expect(Item::COND_ITEM);
|
|
|
|
// Check that we are comparing with a field with same collation
|
|
|
|
if (!context->expecting_collation(item->collation.collation))
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("Found non-matching collation %s",
|
|
|
|
item->collation.collation->name));
|
|
|
|
context->supported= FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
context->supported= FALSE;
|
|
|
|
break;
|
2005-07-04 02:42:33 +02:00
|
|
|
case Item::INT_ITEM:
|
2005-05-18 14:32:05 +02:00
|
|
|
DBUG_PRINT("info", ("INT_ITEM"));
|
|
|
|
if (context->expecting(Item::INT_ITEM))
|
2005-02-16 14:18:32 +01:00
|
|
|
{
|
2005-05-18 14:32:05 +02:00
|
|
|
Item_int *int_item= (Item_int *) item;
|
|
|
|
DBUG_PRINT("info", ("value %d", int_item->value));
|
|
|
|
NDB_ITEM_QUALIFICATION q;
|
|
|
|
q.value_type= Item::INT_ITEM;
|
|
|
|
curr_cond->ndb_item= new Ndb_item(NDB_VALUE, q, item);
|
2006-09-15 15:51:05 +02:00
|
|
|
if (! context->expecting_no_field_result())
|
2005-05-18 14:32:05 +02:00
|
|
|
{
|
|
|
|
// We have not seen the field argument yet
|
|
|
|
context->expect_only(Item::FIELD_ITEM);
|
|
|
|
context->expect_only_field_result(INT_RESULT);
|
2005-06-10 10:34:05 +02:00
|
|
|
context->expect_field_result(REAL_RESULT);
|
|
|
|
context->expect_field_result(DECIMAL_RESULT);
|
2005-05-18 14:32:05 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Expect another logical expression
|
|
|
|
context->expect_only(Item::FUNC_ITEM);
|
|
|
|
context->expect(Item::COND_ITEM);
|
|
|
|
}
|
2005-02-16 14:18:32 +01:00
|
|
|
}
|
|
|
|
else
|
2005-05-18 14:32:05 +02:00
|
|
|
context->supported= FALSE;
|
|
|
|
break;
|
2005-07-04 02:42:33 +02:00
|
|
|
case Item::REAL_ITEM:
|
2005-05-18 14:32:05 +02:00
|
|
|
DBUG_PRINT("info", ("REAL_ITEM %s"));
|
|
|
|
if (context->expecting(Item::REAL_ITEM))
|
2005-02-23 15:51:26 +01:00
|
|
|
{
|
2005-05-18 14:32:05 +02:00
|
|
|
Item_float *float_item= (Item_float *) item;
|
|
|
|
DBUG_PRINT("info", ("value %f", float_item->value));
|
|
|
|
NDB_ITEM_QUALIFICATION q;
|
|
|
|
q.value_type= Item::REAL_ITEM;
|
|
|
|
curr_cond->ndb_item= new Ndb_item(NDB_VALUE, q, item);
|
2006-09-15 15:51:05 +02:00
|
|
|
if (! context->expecting_no_field_result())
|
2005-05-18 14:32:05 +02:00
|
|
|
{
|
|
|
|
// We have not seen the field argument yet
|
|
|
|
context->expect_only(Item::FIELD_ITEM);
|
|
|
|
context->expect_only_field_result(REAL_RESULT);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Expect another logical expression
|
|
|
|
context->expect_only(Item::FUNC_ITEM);
|
|
|
|
context->expect(Item::COND_ITEM);
|
|
|
|
}
|
2005-02-23 15:51:26 +01:00
|
|
|
}
|
2005-05-18 14:32:05 +02:00
|
|
|
else
|
|
|
|
context->supported= FALSE;
|
|
|
|
break;
|
2005-07-04 02:42:33 +02:00
|
|
|
case Item::VARBIN_ITEM:
|
2005-05-18 14:32:05 +02:00
|
|
|
DBUG_PRINT("info", ("VARBIN_ITEM"));
|
|
|
|
if (context->expecting(Item::VARBIN_ITEM))
|
2005-02-16 14:18:32 +01:00
|
|
|
{
|
2005-05-18 14:32:05 +02:00
|
|
|
NDB_ITEM_QUALIFICATION q;
|
|
|
|
q.value_type= Item::VARBIN_ITEM;
|
|
|
|
curr_cond->ndb_item= new Ndb_item(NDB_VALUE, q, item);
|
2006-09-15 15:51:05 +02:00
|
|
|
if (! context->expecting_no_field_result())
|
2005-05-18 14:32:05 +02:00
|
|
|
{
|
|
|
|
// We have not seen the field argument yet
|
|
|
|
context->expect_only(Item::FIELD_ITEM);
|
|
|
|
context->expect_only_field_result(STRING_RESULT);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Expect another logical expression
|
|
|
|
context->expect_only(Item::FUNC_ITEM);
|
|
|
|
context->expect(Item::COND_ITEM);
|
|
|
|
}
|
2005-02-16 14:18:32 +01:00
|
|
|
}
|
|
|
|
else
|
2005-05-18 14:32:05 +02:00
|
|
|
context->supported= FALSE;
|
|
|
|
break;
|
2005-07-04 02:42:33 +02:00
|
|
|
case Item::DECIMAL_ITEM:
|
2005-05-18 14:32:05 +02:00
|
|
|
DBUG_PRINT("info", ("DECIMAL_ITEM %s"));
|
|
|
|
if (context->expecting(Item::DECIMAL_ITEM))
|
2005-02-23 15:51:26 +01:00
|
|
|
{
|
2005-05-18 14:32:05 +02:00
|
|
|
Item_decimal *decimal_item= (Item_decimal *) item;
|
|
|
|
DBUG_PRINT("info", ("value %f", decimal_item->val_real()));
|
|
|
|
NDB_ITEM_QUALIFICATION q;
|
|
|
|
q.value_type= Item::DECIMAL_ITEM;
|
|
|
|
curr_cond->ndb_item= new Ndb_item(NDB_VALUE, q, item);
|
2006-09-15 15:51:05 +02:00
|
|
|
if (! context->expecting_no_field_result())
|
2005-05-18 14:32:05 +02:00
|
|
|
{
|
|
|
|
// We have not seen the field argument yet
|
|
|
|
context->expect_only(Item::FIELD_ITEM);
|
|
|
|
context->expect_only_field_result(REAL_RESULT);
|
|
|
|
context->expect_field_result(DECIMAL_RESULT);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Expect another logical expression
|
|
|
|
context->expect_only(Item::FUNC_ITEM);
|
|
|
|
context->expect(Item::COND_ITEM);
|
|
|
|
}
|
2005-02-23 15:51:26 +01:00
|
|
|
}
|
2005-05-18 14:32:05 +02:00
|
|
|
else
|
|
|
|
context->supported= FALSE;
|
|
|
|
break;
|
2005-07-04 02:42:33 +02:00
|
|
|
case Item::COND_ITEM:
|
|
|
|
{
|
2005-05-18 14:32:05 +02:00
|
|
|
Item_cond *cond_item= (Item_cond *) item;
|
|
|
|
|
|
|
|
if (context->expecting(Item::COND_ITEM))
|
2005-07-04 02:42:33 +02:00
|
|
|
{
|
|
|
|
switch (cond_item->functype()) {
|
|
|
|
case Item_func::COND_AND_FUNC:
|
2005-05-18 14:32:05 +02:00
|
|
|
DBUG_PRINT("info", ("COND_AND_FUNC"));
|
|
|
|
curr_cond->ndb_item= new Ndb_item(cond_item->functype(),
|
|
|
|
cond_item);
|
|
|
|
break;
|
2005-07-04 02:42:33 +02:00
|
|
|
case Item_func::COND_OR_FUNC:
|
2005-05-18 14:32:05 +02:00
|
|
|
DBUG_PRINT("info", ("COND_OR_FUNC"));
|
|
|
|
curr_cond->ndb_item= new Ndb_item(cond_item->functype(),
|
|
|
|
cond_item);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
DBUG_PRINT("info", ("COND_ITEM %d", cond_item->functype()));
|
|
|
|
context->supported= FALSE;
|
|
|
|
break;
|
|
|
|
}
|
2005-07-04 02:42:33 +02:00
|
|
|
}
|
2005-05-18 14:32:05 +02:00
|
|
|
else
|
2005-07-04 02:42:33 +02:00
|
|
|
{
|
|
|
|
/* Did not expect condition */
|
2005-05-18 14:32:05 +02:00
|
|
|
context->supported= FALSE;
|
2005-07-04 02:42:33 +02:00
|
|
|
}
|
2005-05-18 14:32:05 +02:00
|
|
|
break;
|
2005-02-16 14:18:32 +01:00
|
|
|
}
|
2005-07-04 02:42:33 +02:00
|
|
|
default:
|
|
|
|
{
|
2005-05-18 14:32:05 +02:00
|
|
|
DBUG_PRINT("info", ("Found item of type %d", item->type()));
|
2005-02-16 14:18:32 +01:00
|
|
|
context->supported= FALSE;
|
2005-05-18 14:32:05 +02:00
|
|
|
}
|
|
|
|
}
|
2005-07-04 02:42:33 +02:00
|
|
|
}
|
2005-05-18 14:32:05 +02:00
|
|
|
if (context->supported && context->rewrite_stack)
|
|
|
|
{
|
|
|
|
Ndb_rewrite_context *rewrite_context= context->rewrite_stack;
|
|
|
|
if (rewrite_context->count ==
|
|
|
|
rewrite_context->func_item->argument_count())
|
|
|
|
{
|
|
|
|
// Rewrite is done, wrap an END() at the en
|
|
|
|
DBUG_PRINT("info", ("End of condition group"));
|
|
|
|
prev_cond= curr_cond;
|
|
|
|
curr_cond= context->cond_ptr= new Ndb_cond();
|
2005-09-12 09:36:07 +02:00
|
|
|
curr_cond->prev= prev_cond;
|
2005-05-18 14:32:05 +02:00
|
|
|
prev_cond->next= curr_cond;
|
|
|
|
curr_cond->ndb_item= new Ndb_item(NDB_END_COND);
|
|
|
|
// Pop rewrite stack
|
2006-04-25 12:40:31 +02:00
|
|
|
context->rewrite_stack= rewrite_context->next;
|
|
|
|
rewrite_context->next= NULL;
|
|
|
|
delete(rewrite_context);
|
2005-05-18 14:32:05 +02:00
|
|
|
}
|
2004-12-17 21:13:22 +01:00
|
|
|
}
|
2005-05-18 14:32:05 +02:00
|
|
|
}
|
2004-12-17 21:13:22 +01:00
|
|
|
}
|
2005-05-18 14:32:05 +02:00
|
|
|
|
2004-12-17 21:13:22 +01:00
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ha_ndbcluster::serialize_cond(const COND *cond, Ndb_cond_stack *ndb_cond)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("serialize_cond");
|
|
|
|
Item *item= (Item *) cond;
|
2005-02-16 14:18:32 +01:00
|
|
|
Ndb_cond_traverse_context context(table, (void *)m_table, ndb_cond);
|
2005-02-23 15:51:26 +01:00
|
|
|
// Expect a logical expression
|
|
|
|
context.expect(Item::FUNC_ITEM);
|
|
|
|
context.expect(Item::COND_ITEM);
|
2004-12-17 21:13:22 +01:00
|
|
|
item->traverse_cond(&ndb_serialize_cond, (void *) &context, Item::PREFIX);
|
2005-02-16 14:18:32 +01:00
|
|
|
DBUG_PRINT("info", ("The pushed condition is %ssupported", (context.supported)?"":"not "));
|
2004-12-17 21:13:22 +01:00
|
|
|
|
2005-02-16 14:18:32 +01:00
|
|
|
DBUG_RETURN(context.supported);
|
2004-12-17 21:13:22 +01:00
|
|
|
}
|
|
|
|
|
2005-01-07 15:33:24 +01:00
|
|
|
int
|
|
|
|
ha_ndbcluster::build_scan_filter_predicate(Ndb_cond * &cond,
|
2005-02-18 21:43:51 +01:00
|
|
|
NdbScanFilter *filter,
|
|
|
|
bool negated)
|
2004-12-17 21:13:22 +01:00
|
|
|
{
|
|
|
|
DBUG_ENTER("build_scan_filter_predicate");
|
2005-07-04 02:42:33 +02:00
|
|
|
switch (cond->ndb_item->type) {
|
|
|
|
case NDB_FUNCTION:
|
|
|
|
{
|
2004-12-17 21:13:22 +01:00
|
|
|
if (!cond->next)
|
|
|
|
break;
|
|
|
|
Ndb_item *a= cond->next->ndb_item;
|
2005-02-23 15:51:26 +01:00
|
|
|
Ndb_item *b, *field, *value= NULL;
|
2005-08-12 12:54:42 +02:00
|
|
|
LINT_INIT(field);
|
|
|
|
|
2005-07-04 02:42:33 +02:00
|
|
|
switch (cond->ndb_item->argument_count()) {
|
|
|
|
case 1:
|
2005-02-23 15:51:26 +01:00
|
|
|
field=
|
|
|
|
(a->type == NDB_FIELD)? a : NULL;
|
|
|
|
break;
|
2005-07-04 02:42:33 +02:00
|
|
|
case 2:
|
2004-12-17 21:13:22 +01:00
|
|
|
if (!cond->next->next)
|
2005-02-16 14:18:32 +01:00
|
|
|
break;
|
2005-02-23 15:51:26 +01:00
|
|
|
b= cond->next->next->ndb_item;
|
|
|
|
value=
|
2005-02-16 14:18:32 +01:00
|
|
|
(a->type == NDB_VALUE)? a
|
|
|
|
: (b->type == NDB_VALUE)? b
|
|
|
|
: NULL;
|
2005-02-23 15:51:26 +01:00
|
|
|
field=
|
2005-02-16 14:18:32 +01:00
|
|
|
(a->type == NDB_FIELD)? a
|
|
|
|
: (b->type == NDB_FIELD)? b
|
|
|
|
: NULL;
|
2005-02-23 15:51:26 +01:00
|
|
|
break;
|
2005-03-09 16:39:23 +01:00
|
|
|
default:
|
2005-07-18 13:31:02 +02:00
|
|
|
field= NULL; //Keep compiler happy
|
|
|
|
DBUG_ASSERT(0);
|
2005-02-23 15:51:26 +01:00
|
|
|
break;
|
|
|
|
}
|
2005-07-04 02:42:33 +02:00
|
|
|
switch ((negated) ?
|
|
|
|
Ndb_item::negate(cond->ndb_item->qualification.function_type)
|
|
|
|
: cond->ndb_item->qualification.function_type) {
|
2005-08-01 11:50:43 +02:00
|
|
|
case NDB_EQ_FUNC:
|
2005-02-23 15:51:26 +01:00
|
|
|
{
|
2004-12-17 21:13:22 +01:00
|
|
|
if (!value || !field) break;
|
2005-02-11 22:05:24 +01:00
|
|
|
// Save value in right format for the field type
|
|
|
|
value->save_in_field(field);
|
2005-01-04 20:56:04 +01:00
|
|
|
DBUG_PRINT("info", ("Generating EQ filter"));
|
2005-01-07 15:33:24 +01:00
|
|
|
if (filter->cmp(NdbScanFilter::COND_EQ,
|
2005-02-16 14:18:32 +01:00
|
|
|
field->get_field_no(),
|
|
|
|
field->get_val(),
|
|
|
|
field->pack_length()) == -1)
|
|
|
|
DBUG_RETURN(1);
|
2005-01-07 15:33:24 +01:00
|
|
|
cond= cond->next->next->next;
|
|
|
|
DBUG_RETURN(0);
|
2004-12-17 21:13:22 +01:00
|
|
|
}
|
2005-08-01 11:50:43 +02:00
|
|
|
case NDB_NE_FUNC:
|
2005-07-04 02:42:33 +02:00
|
|
|
{
|
2004-12-17 21:13:22 +01:00
|
|
|
if (!value || !field) break;
|
2005-02-11 22:05:24 +01:00
|
|
|
// Save value in right format for the field type
|
|
|
|
value->save_in_field(field);
|
2005-01-04 20:56:04 +01:00
|
|
|
DBUG_PRINT("info", ("Generating NE filter"));
|
2005-01-07 15:33:24 +01:00
|
|
|
if (filter->cmp(NdbScanFilter::COND_NE,
|
2005-02-16 14:18:32 +01:00
|
|
|
field->get_field_no(),
|
|
|
|
field->get_val(),
|
|
|
|
field->pack_length()) == -1)
|
|
|
|
DBUG_RETURN(1);
|
2005-01-07 15:33:24 +01:00
|
|
|
cond= cond->next->next->next;
|
|
|
|
DBUG_RETURN(0);
|
2004-12-17 21:13:22 +01:00
|
|
|
}
|
2005-08-01 11:50:43 +02:00
|
|
|
case NDB_LT_FUNC:
|
2005-07-04 02:42:33 +02:00
|
|
|
{
|
2004-12-17 21:13:22 +01:00
|
|
|
if (!value || !field) break;
|
2005-02-11 22:05:24 +01:00
|
|
|
// Save value in right format for the field type
|
|
|
|
value->save_in_field(field);
|
2004-12-17 21:13:22 +01:00
|
|
|
if (a == field)
|
2005-01-04 14:20:18 +01:00
|
|
|
{
|
2005-02-16 14:18:32 +01:00
|
|
|
DBUG_PRINT("info", ("Generating LT filter"));
|
|
|
|
if (filter->cmp(NdbScanFilter::COND_LT,
|
|
|
|
field->get_field_no(),
|
|
|
|
field->get_val(),
|
|
|
|
field->pack_length()) == -1)
|
|
|
|
DBUG_RETURN(1);
|
2005-01-04 14:20:18 +01:00
|
|
|
}
|
2004-12-17 21:13:22 +01:00
|
|
|
else
|
2005-01-04 14:20:18 +01:00
|
|
|
{
|
2005-02-16 14:18:32 +01:00
|
|
|
DBUG_PRINT("info", ("Generating GT filter"));
|
|
|
|
if (filter->cmp(NdbScanFilter::COND_GT,
|
|
|
|
field->get_field_no(),
|
|
|
|
field->get_val(),
|
|
|
|
field->pack_length()) == -1)
|
|
|
|
DBUG_RETURN(1);
|
2005-01-04 14:20:18 +01:00
|
|
|
}
|
2005-01-07 15:33:24 +01:00
|
|
|
cond= cond->next->next->next;
|
|
|
|
DBUG_RETURN(0);
|
2004-12-17 21:13:22 +01:00
|
|
|
}
|
2005-08-01 11:50:43 +02:00
|
|
|
case NDB_LE_FUNC:
|
2005-07-04 02:42:33 +02:00
|
|
|
{
|
2004-12-17 21:13:22 +01:00
|
|
|
if (!value || !field) break;
|
2005-02-11 22:05:24 +01:00
|
|
|
// Save value in right format for the field type
|
|
|
|
value->save_in_field(field);
|
2004-12-17 21:13:22 +01:00
|
|
|
if (a == field)
|
2005-01-04 14:20:18 +01:00
|
|
|
{
|
2005-02-16 14:18:32 +01:00
|
|
|
DBUG_PRINT("info", ("Generating LE filter"));
|
|
|
|
if (filter->cmp(NdbScanFilter::COND_LE,
|
|
|
|
field->get_field_no(),
|
|
|
|
field->get_val(),
|
|
|
|
field->pack_length()) == -1)
|
|
|
|
DBUG_RETURN(1);
|
2005-01-04 14:20:18 +01:00
|
|
|
}
|
2004-12-17 21:13:22 +01:00
|
|
|
else
|
2005-01-04 14:20:18 +01:00
|
|
|
{
|
2005-02-16 14:18:32 +01:00
|
|
|
DBUG_PRINT("info", ("Generating GE filter"));
|
|
|
|
if (filter->cmp(NdbScanFilter::COND_GE,
|
|
|
|
field->get_field_no(),
|
|
|
|
field->get_val(),
|
|
|
|
field->pack_length()) == -1)
|
|
|
|
DBUG_RETURN(1);
|
2005-01-04 14:20:18 +01:00
|
|
|
}
|
2005-01-07 15:33:24 +01:00
|
|
|
cond= cond->next->next->next;
|
|
|
|
DBUG_RETURN(0);
|
2004-12-17 21:13:22 +01:00
|
|
|
}
|
2005-08-01 11:50:43 +02:00
|
|
|
case NDB_GE_FUNC:
|
2005-07-04 02:42:33 +02:00
|
|
|
{
|
2004-12-17 21:13:22 +01:00
|
|
|
if (!value || !field) break;
|
2005-02-11 22:05:24 +01:00
|
|
|
// Save value in right format for the field type
|
|
|
|
value->save_in_field(field);
|
2004-12-17 21:13:22 +01:00
|
|
|
if (a == field)
|
2005-01-04 14:20:18 +01:00
|
|
|
{
|
2005-02-16 14:18:32 +01:00
|
|
|
DBUG_PRINT("info", ("Generating GE filter"));
|
|
|
|
if (filter->cmp(NdbScanFilter::COND_GE,
|
|
|
|
field->get_field_no(),
|
|
|
|
field->get_val(),
|
|
|
|
field->pack_length()) == -1)
|
|
|
|
DBUG_RETURN(1);
|
2005-01-04 14:20:18 +01:00
|
|
|
}
|
2004-12-17 21:13:22 +01:00
|
|
|
else
|
2005-01-04 14:20:18 +01:00
|
|
|
{
|
2005-02-16 14:18:32 +01:00
|
|
|
DBUG_PRINT("info", ("Generating LE filter"));
|
|
|
|
if (filter->cmp(NdbScanFilter::COND_LE,
|
|
|
|
field->get_field_no(),
|
|
|
|
field->get_val(),
|
|
|
|
field->pack_length()) == -1)
|
|
|
|
DBUG_RETURN(1);
|
2005-01-04 14:20:18 +01:00
|
|
|
}
|
2005-01-07 15:33:24 +01:00
|
|
|
cond= cond->next->next->next;
|
|
|
|
DBUG_RETURN(0);
|
2004-12-17 21:13:22 +01:00
|
|
|
}
|
2005-08-01 11:50:43 +02:00
|
|
|
case NDB_GT_FUNC:
|
2005-07-04 02:42:33 +02:00
|
|
|
{
|
2004-12-17 21:13:22 +01:00
|
|
|
if (!value || !field) break;
|
2005-02-11 22:05:24 +01:00
|
|
|
// Save value in right format for the field type
|
|
|
|
value->save_in_field(field);
|
2004-12-17 21:13:22 +01:00
|
|
|
if (a == field)
|
2005-01-04 14:20:18 +01:00
|
|
|
{
|
2005-02-16 14:18:32 +01:00
|
|
|
DBUG_PRINT("info", ("Generating GT filter"));
|
|
|
|
if (filter->cmp(NdbScanFilter::COND_GT,
|
|
|
|
field->get_field_no(),
|
|
|
|
field->get_val(),
|
|
|
|
field->pack_length()) == -1)
|
|
|
|
DBUG_RETURN(1);
|
2005-01-04 14:20:18 +01:00
|
|
|
}
|
2004-12-17 21:13:22 +01:00
|
|
|
else
|
2005-01-04 14:20:18 +01:00
|
|
|
{
|
2005-02-16 14:18:32 +01:00
|
|
|
DBUG_PRINT("info", ("Generating LT filter"));
|
|
|
|
if (filter->cmp(NdbScanFilter::COND_LT,
|
|
|
|
field->get_field_no(),
|
|
|
|
field->get_val(),
|
|
|
|
field->pack_length()) == -1)
|
|
|
|
DBUG_RETURN(1);
|
2005-01-04 14:20:18 +01:00
|
|
|
}
|
2005-01-07 15:33:24 +01:00
|
|
|
cond= cond->next->next->next;
|
|
|
|
DBUG_RETURN(0);
|
2004-12-17 21:13:22 +01:00
|
|
|
}
|
2005-08-01 11:50:43 +02:00
|
|
|
case NDB_LIKE_FUNC:
|
2005-07-04 02:42:33 +02:00
|
|
|
{
|
2004-12-17 21:13:22 +01:00
|
|
|
if (!value || !field) break;
|
2005-02-24 11:09:14 +01:00
|
|
|
if ((value->qualification.value_type != Item::STRING_ITEM) &&
|
|
|
|
(value->qualification.value_type != Item::VARBIN_ITEM))
|
|
|
|
break;
|
2005-02-11 22:05:24 +01:00
|
|
|
// Save value in right format for the field type
|
|
|
|
value->save_in_field(field);
|
|
|
|
DBUG_PRINT("info", ("Generating LIKE filter: like(%d,%s,%d)",
|
2005-02-18 21:43:51 +01:00
|
|
|
field->get_field_no(), value->get_val(),
|
|
|
|
value->pack_length()));
|
|
|
|
if (filter->cmp(NdbScanFilter::COND_LIKE,
|
|
|
|
field->get_field_no(),
|
2005-02-23 15:51:26 +01:00
|
|
|
value->get_val(),
|
|
|
|
value->pack_length()) == -1)
|
2005-02-16 14:18:32 +01:00
|
|
|
DBUG_RETURN(1);
|
2005-01-07 15:33:24 +01:00
|
|
|
cond= cond->next->next->next;
|
|
|
|
DBUG_RETURN(0);
|
2004-12-17 21:13:22 +01:00
|
|
|
}
|
2005-08-01 11:50:43 +02:00
|
|
|
case NDB_NOTLIKE_FUNC:
|
2005-07-04 02:42:33 +02:00
|
|
|
{
|
2004-12-17 21:13:22 +01:00
|
|
|
if (!value || !field) break;
|
2005-02-24 11:09:14 +01:00
|
|
|
if ((value->qualification.value_type != Item::STRING_ITEM) &&
|
|
|
|
(value->qualification.value_type != Item::VARBIN_ITEM))
|
2005-08-01 11:50:43 +02:00
|
|
|
break;
|
2005-02-11 22:05:24 +01:00
|
|
|
// Save value in right format for the field type
|
|
|
|
value->save_in_field(field);
|
|
|
|
DBUG_PRINT("info", ("Generating NOTLIKE filter: notlike(%d,%s,%d)",
|
2005-02-18 21:43:51 +01:00
|
|
|
field->get_field_no(), value->get_val(),
|
|
|
|
value->pack_length()));
|
|
|
|
if (filter->cmp(NdbScanFilter::COND_NOT_LIKE,
|
|
|
|
field->get_field_no(),
|
2005-02-23 15:51:26 +01:00
|
|
|
value->get_val(),
|
|
|
|
value->pack_length()) == -1)
|
2005-02-16 14:18:32 +01:00
|
|
|
DBUG_RETURN(1);
|
2005-01-07 15:33:24 +01:00
|
|
|
cond= cond->next->next->next;
|
|
|
|
DBUG_RETURN(0);
|
2004-12-17 21:13:22 +01:00
|
|
|
}
|
2005-08-01 11:50:43 +02:00
|
|
|
case NDB_ISNULL_FUNC:
|
2005-02-23 15:51:26 +01:00
|
|
|
if (!field)
|
|
|
|
break;
|
|
|
|
DBUG_PRINT("info", ("Generating ISNULL filter"));
|
|
|
|
if (filter->isnull(field->get_field_no()) == -1)
|
|
|
|
DBUG_RETURN(1);
|
2005-01-07 15:33:24 +01:00
|
|
|
cond= cond->next->next;
|
|
|
|
DBUG_RETURN(0);
|
2005-08-01 11:50:43 +02:00
|
|
|
case NDB_ISNOTNULL_FUNC:
|
2005-07-04 02:42:33 +02:00
|
|
|
{
|
2005-02-23 15:51:26 +01:00
|
|
|
if (!field)
|
|
|
|
break;
|
|
|
|
DBUG_PRINT("info", ("Generating ISNOTNULL filter"));
|
|
|
|
if (filter->isnotnull(field->get_field_no()) == -1)
|
|
|
|
DBUG_RETURN(1);
|
2005-01-07 15:33:24 +01:00
|
|
|
cond= cond->next->next;
|
|
|
|
DBUG_RETURN(0);
|
2004-12-17 21:13:22 +01:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
DBUG_PRINT("info", ("Found illegal condition"));
|
2005-01-07 15:33:24 +01:00
|
|
|
DBUG_RETURN(1);
|
2004-12-17 21:13:22 +01:00
|
|
|
}
|
|
|
|
|
2005-01-07 15:33:24 +01:00
|
|
|
int
|
2005-02-23 15:51:26 +01:00
|
|
|
ha_ndbcluster::build_scan_filter_group(Ndb_cond* &cond, NdbScanFilter *filter)
|
2004-12-17 21:13:22 +01:00
|
|
|
{
|
2005-02-23 15:51:26 +01:00
|
|
|
uint level=0;
|
2005-05-06 10:39:30 +02:00
|
|
|
bool negated= FALSE;
|
2004-12-17 21:13:22 +01:00
|
|
|
DBUG_ENTER("build_scan_filter_group");
|
2005-07-04 02:42:33 +02:00
|
|
|
|
2005-02-23 15:51:26 +01:00
|
|
|
do
|
|
|
|
{
|
2005-07-04 02:42:33 +02:00
|
|
|
if (!cond)
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
switch (cond->ndb_item->type) {
|
|
|
|
case NDB_FUNCTION:
|
|
|
|
{
|
|
|
|
switch (cond->ndb_item->qualification.function_type) {
|
2005-08-01 11:50:43 +02:00
|
|
|
case NDB_COND_AND_FUNC:
|
2005-07-04 02:42:33 +02:00
|
|
|
{
|
2005-02-23 15:51:26 +01:00
|
|
|
level++;
|
|
|
|
DBUG_PRINT("info", ("Generating %s group %u", (negated)?"NAND":"AND",
|
|
|
|
level));
|
|
|
|
if ((negated) ? filter->begin(NdbScanFilter::NAND)
|
|
|
|
: filter->begin(NdbScanFilter::AND) == -1)
|
2005-02-16 14:18:32 +01:00
|
|
|
DBUG_RETURN(1);
|
2005-05-06 10:39:30 +02:00
|
|
|
negated= FALSE;
|
2005-02-23 15:51:26 +01:00
|
|
|
cond= cond->next;
|
|
|
|
break;
|
|
|
|
}
|
2005-08-01 11:50:43 +02:00
|
|
|
case NDB_COND_OR_FUNC:
|
2005-07-04 02:42:33 +02:00
|
|
|
{
|
2005-02-23 15:51:26 +01:00
|
|
|
level++;
|
|
|
|
DBUG_PRINT("info", ("Generating %s group %u", (negated)?"NOR":"OR",
|
|
|
|
level));
|
|
|
|
if ((negated) ? filter->begin(NdbScanFilter::NOR)
|
|
|
|
: filter->begin(NdbScanFilter::OR) == -1)
|
|
|
|
DBUG_RETURN(1);
|
2005-05-06 10:39:30 +02:00
|
|
|
negated= FALSE;
|
2005-02-23 15:51:26 +01:00
|
|
|
cond= cond->next;
|
|
|
|
break;
|
|
|
|
}
|
2005-08-01 11:50:43 +02:00
|
|
|
case NDB_NOT_FUNC:
|
2005-07-04 02:42:33 +02:00
|
|
|
{
|
2005-06-01 11:56:47 +02:00
|
|
|
DBUG_PRINT("info", ("Generating negated query"));
|
2005-02-23 15:51:26 +01:00
|
|
|
cond= cond->next;
|
2005-05-06 10:39:30 +02:00
|
|
|
negated= TRUE;
|
2005-02-23 15:51:26 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
if (build_scan_filter_predicate(cond, filter, negated))
|
2005-02-16 14:18:32 +01:00
|
|
|
DBUG_RETURN(1);
|
2005-05-06 10:39:30 +02:00
|
|
|
negated= FALSE;
|
2005-02-23 15:51:26 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2005-07-04 02:42:33 +02:00
|
|
|
}
|
|
|
|
case NDB_END_COND:
|
2005-02-23 15:51:26 +01:00
|
|
|
DBUG_PRINT("info", ("End of group %u", level));
|
|
|
|
level--;
|
2005-01-07 15:33:24 +01:00
|
|
|
if (cond) cond= cond->next;
|
|
|
|
if (filter->end() == -1)
|
2005-02-16 14:18:32 +01:00
|
|
|
DBUG_RETURN(1);
|
2005-06-01 11:56:47 +02:00
|
|
|
if (!negated)
|
|
|
|
break;
|
|
|
|
// else fall through (NOT END is an illegal condition)
|
2005-07-04 02:42:33 +02:00
|
|
|
default:
|
|
|
|
{
|
2005-02-23 15:51:26 +01:00
|
|
|
DBUG_PRINT("info", ("Illegal scan filter"));
|
2005-02-18 21:43:51 +01:00
|
|
|
}
|
2004-12-17 21:13:22 +01:00
|
|
|
}
|
2005-06-01 11:56:47 +02:00
|
|
|
} while (level > 0 || negated);
|
2004-12-17 21:13:22 +01:00
|
|
|
|
2005-01-07 15:33:24 +01:00
|
|
|
DBUG_RETURN(0);
|
2004-12-17 21:13:22 +01:00
|
|
|
}
|
|
|
|
|
2005-01-07 15:33:24 +01:00
|
|
|
int
|
|
|
|
ha_ndbcluster::build_scan_filter(Ndb_cond * &cond, NdbScanFilter *filter)
|
2004-12-17 21:13:22 +01:00
|
|
|
{
|
|
|
|
bool simple_cond= TRUE;
|
|
|
|
DBUG_ENTER("build_scan_filter");
|
|
|
|
|
2005-07-04 02:42:33 +02:00
|
|
|
switch (cond->ndb_item->type) {
|
|
|
|
case NDB_FUNCTION:
|
|
|
|
switch (cond->ndb_item->qualification.function_type) {
|
2005-08-01 11:50:43 +02:00
|
|
|
case NDB_COND_AND_FUNC:
|
|
|
|
case NDB_COND_OR_FUNC:
|
2005-05-18 14:32:05 +02:00
|
|
|
simple_cond= FALSE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2005-01-07 15:33:24 +01:00
|
|
|
if (simple_cond && filter->begin() == -1)
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
if (build_scan_filter_group(cond, filter))
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
if (simple_cond && filter->end() == -1)
|
|
|
|
DBUG_RETURN(1);
|
2004-12-17 21:13:22 +01:00
|
|
|
|
2005-01-07 15:33:24 +01:00
|
|
|
DBUG_RETURN(0);
|
2004-12-17 21:13:22 +01:00
|
|
|
}
|
|
|
|
|
2005-01-07 15:33:24 +01:00
|
|
|
int
|
2004-12-17 21:13:22 +01:00
|
|
|
ha_ndbcluster::generate_scan_filter(Ndb_cond_stack *ndb_cond_stack,
|
2005-02-16 14:18:32 +01:00
|
|
|
NdbScanOperation *op)
|
2004-12-17 21:13:22 +01:00
|
|
|
{
|
|
|
|
DBUG_ENTER("generate_scan_filter");
|
|
|
|
if (ndb_cond_stack)
|
|
|
|
{
|
2005-06-01 11:56:47 +02:00
|
|
|
DBUG_PRINT("info", ("Generating scan filter"));
|
2004-12-17 21:13:22 +01:00
|
|
|
NdbScanFilter filter(op);
|
|
|
|
bool multiple_cond= FALSE;
|
|
|
|
// Wrap an AND group around multiple conditions
|
|
|
|
if (ndb_cond_stack->next) {
|
|
|
|
multiple_cond= TRUE;
|
2005-01-07 15:33:24 +01:00
|
|
|
if (filter.begin() == -1)
|
2005-02-16 14:18:32 +01:00
|
|
|
DBUG_RETURN(1);
|
2004-12-17 21:13:22 +01:00
|
|
|
}
|
|
|
|
for (Ndb_cond_stack *stack= ndb_cond_stack;
|
2005-02-16 14:18:32 +01:00
|
|
|
(stack);
|
|
|
|
stack= stack->next)
|
2004-12-17 21:13:22 +01:00
|
|
|
{
|
2005-02-16 14:18:32 +01:00
|
|
|
Ndb_cond *cond= stack->ndb_cond;
|
2005-01-07 15:33:24 +01:00
|
|
|
|
2005-02-16 14:18:32 +01:00
|
|
|
if (build_scan_filter(cond, &filter))
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("build_scan_filter failed"));
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
2004-12-17 21:13:22 +01:00
|
|
|
}
|
2005-01-07 15:33:24 +01:00
|
|
|
if (multiple_cond && filter.end() == -1)
|
|
|
|
DBUG_RETURN(1);
|
2004-12-17 21:13:22 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("Empty stack"));
|
|
|
|
}
|
|
|
|
|
2005-01-07 15:33:24 +01:00
|
|
|
DBUG_RETURN(0);
|
2004-12-17 21:13:22 +01:00
|
|
|
}
|
|
|
|
|
2006-01-31 18:46:44 +01:00
|
|
|
/*
|
|
|
|
get table space info for SHOW CREATE TABLE
|
|
|
|
*/
|
2006-02-13 21:55:49 +01:00
|
|
|
char* ha_ndbcluster::get_tablespace_name(THD *thd)
|
2006-01-31 18:46:44 +01:00
|
|
|
{
|
2006-02-13 21:55:49 +01:00
|
|
|
Ndb *ndb= check_ndb_in_thd(thd);
|
2006-01-31 18:46:44 +01:00
|
|
|
NDBDICT *ndbdict= ndb->getDictionary();
|
2006-02-01 11:56:20 +01:00
|
|
|
NdbError ndberr;
|
|
|
|
Uint32 id;
|
2006-01-31 18:46:44 +01:00
|
|
|
ndb->setDatabaseName(m_dbname);
|
2006-05-04 13:58:17 +02:00
|
|
|
const NDBTAB *ndbtab= m_table;
|
|
|
|
DBUG_ASSERT(ndbtab != NULL);
|
2006-02-01 11:56:20 +01:00
|
|
|
if (!ndbtab->getTablespace(&id))
|
|
|
|
{
|
2006-01-31 18:46:44 +01:00
|
|
|
return 0;
|
2006-02-01 11:56:20 +01:00
|
|
|
}
|
|
|
|
{
|
|
|
|
NdbDictionary::Tablespace ts= ndbdict->getTablespace(id);
|
|
|
|
ndberr= ndbdict->getNdbError();
|
2006-03-27 19:41:37 +02:00
|
|
|
if(ndberr.classification != NdbError::NoError)
|
2006-02-01 11:56:20 +01:00
|
|
|
goto err;
|
|
|
|
return (my_strdup(ts.getName(), MYF(0)));
|
|
|
|
}
|
|
|
|
err:
|
|
|
|
if (ndberr.status == NdbError::TemporaryError)
|
2006-02-13 21:55:49 +01:00
|
|
|
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
|
2006-02-01 11:56:20 +01:00
|
|
|
ER_GET_TEMPORARY_ERRMSG, ER(ER_GET_TEMPORARY_ERRMSG),
|
|
|
|
ndberr.code, ndberr.message, "NDB");
|
|
|
|
else
|
2006-02-13 21:55:49 +01:00
|
|
|
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
|
2006-02-01 11:56:20 +01:00
|
|
|
ER_GET_ERRMSG, ER(ER_GET_ERRMSG),
|
|
|
|
ndberr.code, ndberr.message, "NDB");
|
2006-01-31 18:46:44 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-06 00:20:37 +01:00
|
|
|
/*
|
|
|
|
Implements the SHOW NDB STATUS command.
|
|
|
|
*/
|
2005-11-07 16:25:06 +01:00
|
|
|
bool
|
2006-09-30 21:49:46 +02:00
|
|
|
ndbcluster_show_status(handlerton *hton, THD* thd, stat_print_fn *stat_print,
|
2005-11-07 16:25:06 +01:00
|
|
|
enum ha_stat_type stat_type)
|
2005-09-19 15:35:07 +02:00
|
|
|
{
|
2005-11-07 16:25:06 +01:00
|
|
|
char buf[IO_SIZE];
|
2006-01-12 19:51:02 +01:00
|
|
|
uint buflen;
|
2005-09-19 15:35:07 +02:00
|
|
|
DBUG_ENTER("ndbcluster_show_status");
|
|
|
|
|
|
|
|
if (have_ndbcluster != SHOW_OPTION_YES)
|
|
|
|
{
|
2005-11-07 16:25:06 +01:00
|
|
|
DBUG_RETURN(FALSE);
|
|
|
|
}
|
|
|
|
if (stat_type != HA_ENGINE_STATUS)
|
|
|
|
{
|
|
|
|
DBUG_RETURN(FALSE);
|
2005-09-19 15:35:07 +02:00
|
|
|
}
|
2006-01-12 19:51:02 +01:00
|
|
|
|
|
|
|
update_status_variables(g_ndb_cluster_connection);
|
|
|
|
buflen=
|
|
|
|
my_snprintf(buf, sizeof(buf),
|
|
|
|
"cluster_node_id=%u, "
|
|
|
|
"connected_host=%s, "
|
|
|
|
"connected_port=%u, "
|
2006-08-11 12:01:46 +02:00
|
|
|
"number_of_data_nodes=%u, "
|
|
|
|
"number_of_ready_data_nodes=%u, "
|
2006-05-19 12:54:12 +02:00
|
|
|
"connect_count=%u",
|
2006-01-12 19:51:02 +01:00
|
|
|
ndb_cluster_node_id,
|
|
|
|
ndb_connected_host,
|
|
|
|
ndb_connected_port,
|
2006-08-11 12:01:46 +02:00
|
|
|
ndb_number_of_data_nodes,
|
|
|
|
ndb_number_of_ready_data_nodes,
|
2006-05-19 12:54:12 +02:00
|
|
|
ndb_connect_count);
|
2006-05-28 14:51:01 +02:00
|
|
|
if (stat_print(thd, ndbcluster_hton_name, ndbcluster_hton_name_length,
|
|
|
|
STRING_WITH_LEN("connection"), buf, buflen))
|
2006-01-12 19:51:02 +01:00
|
|
|
DBUG_RETURN(TRUE);
|
|
|
|
|
2005-09-20 12:07:18 +02:00
|
|
|
if (get_thd_ndb(thd) && get_thd_ndb(thd)->ndb)
|
2005-09-19 15:35:07 +02:00
|
|
|
{
|
2005-09-20 12:07:18 +02:00
|
|
|
Ndb* ndb= (get_thd_ndb(thd))->ndb;
|
2006-01-05 23:47:49 +01:00
|
|
|
Ndb::Free_list_usage tmp;
|
|
|
|
tmp.m_name= 0;
|
2005-09-19 15:35:07 +02:00
|
|
|
while (ndb->get_free_list_usage(&tmp))
|
|
|
|
{
|
2006-01-12 19:51:02 +01:00
|
|
|
buflen=
|
2005-12-21 19:18:40 +01:00
|
|
|
my_snprintf(buf, sizeof(buf),
|
2005-11-07 16:25:06 +01:00
|
|
|
"created=%u, free=%u, sizeof=%u",
|
|
|
|
tmp.m_created, tmp.m_free, tmp.m_sizeof);
|
2006-05-28 14:51:01 +02:00
|
|
|
if (stat_print(thd, ndbcluster_hton_name, ndbcluster_hton_name_length,
|
2005-12-21 19:18:40 +01:00
|
|
|
tmp.m_name, strlen(tmp.m_name), buf, buflen))
|
2005-11-07 16:25:06 +01:00
|
|
|
DBUG_RETURN(TRUE);
|
2005-09-19 15:35:07 +02:00
|
|
|
}
|
|
|
|
}
|
2006-01-12 19:51:02 +01:00
|
|
|
#ifdef HAVE_NDB_BINLOG
|
|
|
|
ndbcluster_show_status_binlog(thd, stat_print, stat_type);
|
|
|
|
#endif
|
|
|
|
|
2005-09-19 15:35:07 +02:00
|
|
|
DBUG_RETURN(FALSE);
|
|
|
|
}
|
2005-07-18 13:31:02 +02:00
|
|
|
|
2006-01-12 19:51:02 +01:00
|
|
|
|
2005-07-18 13:31:02 +02:00
|
|
|
/*
|
|
|
|
Create a table in NDB Cluster
|
|
|
|
*/
|
2006-06-27 22:19:27 +02:00
|
|
|
static uint get_no_fragments(ulonglong max_rows)
|
2005-07-18 13:31:02 +02:00
|
|
|
{
|
|
|
|
#if MYSQL_VERSION_ID >= 50000
|
|
|
|
uint acc_row_size= 25 + /*safety margin*/ 2;
|
|
|
|
#else
|
|
|
|
uint acc_row_size= pk_length*4;
|
|
|
|
/* add acc overhead */
|
|
|
|
if (pk_length <= 8) /* main page will set the limit */
|
|
|
|
acc_row_size+= 25 + /*safety margin*/ 2;
|
|
|
|
else /* overflow page will set the limit */
|
|
|
|
acc_row_size+= 4 + /*safety margin*/ 4;
|
|
|
|
#endif
|
|
|
|
ulonglong acc_fragment_size= 512*1024*1024;
|
|
|
|
#if MYSQL_VERSION_ID >= 50100
|
|
|
|
return (max_rows*acc_row_size)/acc_fragment_size+1;
|
|
|
|
#else
|
|
|
|
return ((max_rows*acc_row_size)/acc_fragment_size+1
|
|
|
|
+1/*correct rounding*/)/2;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Routine to adjust default number of partitions to always be a multiple
|
|
|
|
of number of nodes and never more than 4 times the number of nodes.
|
|
|
|
|
|
|
|
*/
|
|
|
|
static bool adjusted_frag_count(uint no_fragments, uint no_nodes,
|
|
|
|
uint &reported_frags)
|
|
|
|
{
|
|
|
|
uint i= 0;
|
|
|
|
reported_frags= no_nodes;
|
|
|
|
while (reported_frags < no_fragments && ++i < 4 &&
|
|
|
|
(reported_frags + no_nodes) < MAX_PARTITIONS)
|
|
|
|
reported_frags+= no_nodes;
|
|
|
|
return (reported_frags < no_fragments);
|
|
|
|
}
|
|
|
|
|
2006-06-27 22:19:27 +02:00
|
|
|
int ha_ndbcluster::get_default_no_partitions(HA_CREATE_INFO *info)
|
2005-07-18 13:31:02 +02:00
|
|
|
{
|
2006-06-27 22:19:27 +02:00
|
|
|
ha_rows max_rows, min_rows;
|
|
|
|
if (info)
|
|
|
|
{
|
|
|
|
max_rows= info->max_rows;
|
|
|
|
min_rows= info->min_rows;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
max_rows= table_share->max_rows;
|
|
|
|
min_rows= table_share->min_rows;
|
|
|
|
}
|
2005-07-18 13:31:02 +02:00
|
|
|
uint reported_frags;
|
2006-06-27 22:19:27 +02:00
|
|
|
uint no_fragments=
|
|
|
|
get_no_fragments(max_rows >= min_rows ? max_rows : min_rows);
|
2005-07-18 13:31:02 +02:00
|
|
|
uint no_nodes= g_ndb_cluster_connection->no_db_nodes();
|
2006-01-17 08:40:00 +01:00
|
|
|
if (adjusted_frag_count(no_fragments, no_nodes, reported_frags))
|
|
|
|
{
|
|
|
|
push_warning(current_thd,
|
|
|
|
MYSQL_ERROR::WARN_LEVEL_WARN, ER_UNKNOWN_ERROR,
|
|
|
|
"Ndb might have problems storing the max amount of rows specified");
|
|
|
|
}
|
2005-07-18 13:31:02 +02:00
|
|
|
return (int)reported_frags;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-01-17 08:40:00 +01:00
|
|
|
/*
|
|
|
|
Set-up auto-partitioning for NDB Cluster
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
set_auto_partitions()
|
|
|
|
part_info Partition info struct to set-up
|
|
|
|
|
|
|
|
RETURN VALUE
|
|
|
|
NONE
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
Set-up auto partitioning scheme for tables that didn't define any
|
|
|
|
partitioning. We'll use PARTITION BY KEY() in this case which
|
|
|
|
translates into partition by primary key if a primary key exists
|
|
|
|
and partition by hidden key otherwise.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ha_ndbcluster::set_auto_partitions(partition_info *part_info)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_ndbcluster::set_auto_partitions");
|
|
|
|
part_info->list_of_part_fields= TRUE;
|
|
|
|
part_info->part_type= HASH_PARTITION;
|
|
|
|
switch (opt_ndb_distribution_id)
|
|
|
|
{
|
|
|
|
case ND_KEYHASH:
|
|
|
|
part_info->linear_hash_ind= FALSE;
|
|
|
|
break;
|
|
|
|
case ND_LINHASH:
|
|
|
|
part_info->linear_hash_ind= TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int ha_ndbcluster::set_range_data(void *tab_ref, partition_info *part_info)
|
|
|
|
{
|
|
|
|
NDBTAB *tab= (NDBTAB*)tab_ref;
|
|
|
|
int32 *range_data= (int32*)my_malloc(part_info->no_parts*sizeof(int32),
|
|
|
|
MYF(0));
|
|
|
|
uint i;
|
|
|
|
int error= 0;
|
2006-06-06 19:19:46 +02:00
|
|
|
bool unsigned_flag= part_info->part_expr->unsigned_flag;
|
2006-01-17 08:40:00 +01:00
|
|
|
DBUG_ENTER("set_range_data");
|
|
|
|
|
|
|
|
if (!range_data)
|
|
|
|
{
|
|
|
|
mem_alloc_error(part_info->no_parts*sizeof(int32));
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
|
|
|
for (i= 0; i < part_info->no_parts; i++)
|
|
|
|
{
|
|
|
|
longlong range_val= part_info->range_int_array[i];
|
2006-06-06 19:19:46 +02:00
|
|
|
if (unsigned_flag)
|
|
|
|
range_val-= 0x8000000000000000ULL;
|
2006-01-17 09:25:12 +01:00
|
|
|
if (range_val < INT_MIN32 || range_val >= INT_MAX32)
|
2006-01-17 08:40:00 +01:00
|
|
|
{
|
2006-01-17 09:25:12 +01:00
|
|
|
if ((i != part_info->no_parts - 1) ||
|
|
|
|
(range_val != LONGLONG_MAX))
|
|
|
|
{
|
|
|
|
my_error(ER_LIMITED_PART_RANGE, MYF(0), "NDB");
|
|
|
|
error= 1;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
range_val= INT_MAX32;
|
2006-01-17 08:40:00 +01:00
|
|
|
}
|
|
|
|
range_data[i]= (int32)range_val;
|
|
|
|
}
|
|
|
|
tab->setRangeListData(range_data, sizeof(int32)*part_info->no_parts);
|
|
|
|
error:
|
|
|
|
my_free((char*)range_data, MYF(0));
|
|
|
|
DBUG_RETURN(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ha_ndbcluster::set_list_data(void *tab_ref, partition_info *part_info)
|
|
|
|
{
|
|
|
|
NDBTAB *tab= (NDBTAB*)tab_ref;
|
|
|
|
int32 *list_data= (int32*)my_malloc(part_info->no_list_values * 2
|
|
|
|
* sizeof(int32), MYF(0));
|
|
|
|
uint32 *part_id, i;
|
|
|
|
int error= 0;
|
2006-06-06 19:19:46 +02:00
|
|
|
bool unsigned_flag= part_info->part_expr->unsigned_flag;
|
2006-01-17 08:40:00 +01:00
|
|
|
DBUG_ENTER("set_list_data");
|
|
|
|
|
|
|
|
if (!list_data)
|
|
|
|
{
|
|
|
|
mem_alloc_error(part_info->no_list_values*2*sizeof(int32));
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
|
|
|
for (i= 0; i < part_info->no_list_values; i++)
|
|
|
|
{
|
|
|
|
LIST_PART_ENTRY *list_entry= &part_info->list_array[i];
|
|
|
|
longlong list_val= list_entry->list_value;
|
2006-06-06 19:19:46 +02:00
|
|
|
if (unsigned_flag)
|
|
|
|
list_val-= 0x8000000000000000ULL;
|
2006-01-17 08:40:00 +01:00
|
|
|
if (list_val < INT_MIN32 || list_val > INT_MAX32)
|
|
|
|
{
|
|
|
|
my_error(ER_LIMITED_PART_RANGE, MYF(0), "NDB");
|
|
|
|
error= 1;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
list_data[2*i]= (int32)list_val;
|
|
|
|
part_id= (uint32*)&list_data[2*i+1];
|
|
|
|
*part_id= list_entry->partition_id;
|
|
|
|
}
|
|
|
|
tab->setRangeListData(list_data, 2*sizeof(int32)*part_info->no_list_values);
|
|
|
|
error:
|
|
|
|
my_free((char*)list_data, MYF(0));
|
|
|
|
DBUG_RETURN(error);
|
|
|
|
}
|
|
|
|
|
2005-07-18 13:31:02 +02:00
|
|
|
/*
|
|
|
|
User defined partitioning set-up. We need to check how many fragments the
|
|
|
|
user wants defined and which node groups to put those into. Later we also
|
|
|
|
want to attach those partitions to a tablespace.
|
|
|
|
|
|
|
|
All the functionality of the partition function, partition limits and so
|
|
|
|
forth are entirely handled by the MySQL Server. There is one exception to
|
|
|
|
this rule for PARTITION BY KEY where NDB handles the hash function and
|
|
|
|
this type can thus be handled transparently also by NDB API program.
|
|
|
|
For RANGE, HASH and LIST and subpartitioning the NDB API programs must
|
|
|
|
implement the function to map to a partition.
|
|
|
|
*/
|
|
|
|
|
|
|
|
uint ha_ndbcluster::set_up_partition_info(partition_info *part_info,
|
|
|
|
TABLE *table,
|
|
|
|
void *tab_par)
|
|
|
|
{
|
2006-01-17 08:40:00 +01:00
|
|
|
uint16 frag_data[MAX_PARTITIONS];
|
|
|
|
char *ts_names[MAX_PARTITIONS];
|
|
|
|
ulong ts_index= 0, fd_index= 0, i, j;
|
2005-07-18 13:31:02 +02:00
|
|
|
NDBTAB *tab= (NDBTAB*)tab_par;
|
|
|
|
NDBTAB::FragmentType ftype= NDBTAB::UserDefined;
|
|
|
|
partition_element *part_elem;
|
2006-01-17 08:40:00 +01:00
|
|
|
bool first= TRUE;
|
|
|
|
uint ts_id, ts_version, part_count= 0, tot_ts_name_len;
|
|
|
|
List_iterator<partition_element> part_it(part_info->partitions);
|
|
|
|
int error;
|
|
|
|
char *name_ptr;
|
|
|
|
DBUG_ENTER("ha_ndbcluster::set_up_partition_info");
|
2005-07-18 13:31:02 +02:00
|
|
|
|
|
|
|
if (part_info->part_type == HASH_PARTITION &&
|
|
|
|
part_info->list_of_part_fields == TRUE)
|
|
|
|
{
|
|
|
|
Field **fields= part_info->part_field_array;
|
|
|
|
|
|
|
|
if (part_info->linear_hash_ind)
|
|
|
|
ftype= NDBTAB::DistrKeyLin;
|
|
|
|
else
|
|
|
|
ftype= NDBTAB::DistrKeyHash;
|
|
|
|
|
|
|
|
for (i= 0; i < part_info->part_field_list.elements; i++)
|
|
|
|
{
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
NDBCOL *col= tab->getColumn(fields[i]->field_index);
|
2005-07-18 13:31:02 +02:00
|
|
|
DBUG_PRINT("info",("setting dist key on %s", col->getName()));
|
|
|
|
col->setPartitionKey(TRUE);
|
|
|
|
}
|
|
|
|
}
|
2006-01-17 09:25:12 +01:00
|
|
|
else
|
2005-07-18 13:31:02 +02:00
|
|
|
{
|
2006-06-14 12:21:18 +02:00
|
|
|
if (!current_thd->variables.new_mode)
|
|
|
|
{
|
|
|
|
push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
|
|
|
|
ER_ILLEGAL_HA_CREATE_OPTION,
|
|
|
|
ER(ER_ILLEGAL_HA_CREATE_OPTION),
|
|
|
|
ndbcluster_hton_name,
|
|
|
|
"LIST, RANGE and HASH partition disabled by default,"
|
|
|
|
" use --new option to enable");
|
2006-07-05 01:52:38 +02:00
|
|
|
DBUG_RETURN(HA_ERR_UNSUPPORTED);
|
2006-06-14 12:21:18 +02:00
|
|
|
}
|
|
|
|
/*
|
2006-01-17 09:25:12 +01:00
|
|
|
Create a shadow field for those tables that have user defined
|
|
|
|
partitioning. This field stores the value of the partition
|
|
|
|
function such that NDB can handle reorganisations of the data
|
|
|
|
even when the MySQL Server isn't available to assist with
|
|
|
|
calculation of the partition function value.
|
|
|
|
*/
|
|
|
|
NDBCOL col;
|
|
|
|
DBUG_PRINT("info", ("Generating partition func value field"));
|
|
|
|
col.setName("$PART_FUNC_VALUE");
|
|
|
|
col.setType(NdbDictionary::Column::Int);
|
|
|
|
col.setLength(1);
|
|
|
|
col.setNullable(FALSE);
|
|
|
|
col.setPrimaryKey(FALSE);
|
|
|
|
col.setAutoIncrement(FALSE);
|
|
|
|
tab->addColumn(col);
|
|
|
|
if (part_info->part_type == RANGE_PARTITION)
|
2005-07-18 13:31:02 +02:00
|
|
|
{
|
2006-01-17 09:25:12 +01:00
|
|
|
if ((error= set_range_data((void*)tab, part_info)))
|
|
|
|
{
|
|
|
|
DBUG_RETURN(error);
|
|
|
|
}
|
2005-07-18 13:31:02 +02:00
|
|
|
}
|
2006-01-17 09:25:12 +01:00
|
|
|
else if (part_info->part_type == LIST_PARTITION)
|
2005-07-18 13:31:02 +02:00
|
|
|
{
|
2006-01-17 09:25:12 +01:00
|
|
|
if ((error= set_list_data((void*)tab, part_info)))
|
|
|
|
{
|
|
|
|
DBUG_RETURN(error);
|
|
|
|
}
|
2005-07-18 13:31:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
tab->setFragmentType(ftype);
|
2006-01-17 08:40:00 +01:00
|
|
|
i= 0;
|
|
|
|
tot_ts_name_len= 0;
|
|
|
|
do
|
2005-07-18 13:31:02 +02:00
|
|
|
{
|
2006-01-17 08:40:00 +01:00
|
|
|
uint ng;
|
|
|
|
part_elem= part_it++;
|
2006-02-16 22:02:44 +01:00
|
|
|
if (!part_info->is_sub_partitioned())
|
2005-07-18 13:31:02 +02:00
|
|
|
{
|
2006-01-17 08:40:00 +01:00
|
|
|
ng= part_elem->nodegroup_id;
|
|
|
|
if (first && ng == UNDEF_NODEGROUP)
|
|
|
|
ng= 0;
|
|
|
|
ts_names[fd_index]= part_elem->tablespace_name;
|
|
|
|
frag_data[fd_index++]= ng;
|
2005-07-18 13:31:02 +02:00
|
|
|
}
|
2006-01-17 08:40:00 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
List_iterator<partition_element> sub_it(part_elem->subpartitions);
|
|
|
|
j= 0;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
part_elem= sub_it++;
|
|
|
|
ng= part_elem->nodegroup_id;
|
|
|
|
if (first && ng == UNDEF_NODEGROUP)
|
|
|
|
ng= 0;
|
|
|
|
ts_names[fd_index]= part_elem->tablespace_name;
|
|
|
|
frag_data[fd_index++]= ng;
|
|
|
|
} while (++j < part_info->no_subparts);
|
|
|
|
}
|
|
|
|
first= FALSE;
|
|
|
|
} while (++i < part_info->no_parts);
|
|
|
|
tab->setDefaultNoPartitionsFlag(part_info->use_default_no_partitions);
|
2006-01-17 09:25:12 +01:00
|
|
|
tab->setLinearFlag(part_info->linear_hash_ind);
|
2006-06-27 11:22:42 +02:00
|
|
|
{
|
2006-06-27 22:19:27 +02:00
|
|
|
ha_rows max_rows= table_share->max_rows;
|
|
|
|
ha_rows min_rows= table_share->min_rows;
|
2006-06-27 11:22:42 +02:00
|
|
|
if (max_rows < min_rows)
|
|
|
|
max_rows= min_rows;
|
|
|
|
if (max_rows != (ha_rows)0) /* default setting, don't set fragmentation */
|
|
|
|
{
|
|
|
|
tab->setMaxRows(max_rows);
|
2006-06-27 22:19:27 +02:00
|
|
|
tab->setMinRows(min_rows);
|
2006-06-27 11:22:42 +02:00
|
|
|
}
|
|
|
|
}
|
2006-01-17 08:40:00 +01:00
|
|
|
tab->setTablespaceNames(ts_names, fd_index*sizeof(char*));
|
|
|
|
tab->setFragmentCount(fd_index);
|
|
|
|
tab->setFragmentData(&frag_data, fd_index*2);
|
|
|
|
DBUG_RETURN(0);
|
2005-07-18 13:31:02 +02:00
|
|
|
}
|
2005-07-22 23:15:53 +02:00
|
|
|
|
2006-01-17 08:40:00 +01:00
|
|
|
|
2005-07-22 22:43:59 +02:00
|
|
|
bool ha_ndbcluster::check_if_incompatible_data(HA_CREATE_INFO *info,
|
|
|
|
uint table_changes)
|
|
|
|
{
|
2006-01-27 17:23:14 +01:00
|
|
|
DBUG_ENTER("ha_ndbcluster::check_if_incompatible_data");
|
|
|
|
uint i;
|
|
|
|
const NDBTAB *tab= (const NDBTAB *) m_table;
|
2006-01-31 17:01:14 +01:00
|
|
|
|
2006-06-13 16:44:30 +02:00
|
|
|
if (current_thd->variables.ndb_use_copying_alter_table)
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("On-line alter table disabled"));
|
|
|
|
DBUG_RETURN(COMPATIBLE_DATA_NO);
|
|
|
|
}
|
|
|
|
|
2006-01-27 17:23:14 +01:00
|
|
|
for (i= 0; i < table->s->fields; i++)
|
|
|
|
{
|
|
|
|
Field *field= table->field[i];
|
2006-06-14 11:08:36 +02:00
|
|
|
const NDBCOL *col= tab->getColumn(i);
|
|
|
|
if (field->flags & FIELD_IS_RENAMED)
|
2006-06-13 16:44:30 +02:00
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("Field has been renamed, copy table"));
|
|
|
|
DBUG_RETURN(COMPATIBLE_DATA_NO);
|
|
|
|
}
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
if ((field->flags & FIELD_IN_ADD_INDEX) &&
|
2006-01-27 17:23:14 +01:00
|
|
|
col->getStorageType() == NdbDictionary::Column::StorageTypeDisk)
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("add/drop index not supported for disk stored column"));
|
|
|
|
DBUG_RETURN(COMPATIBLE_DATA_NO);
|
|
|
|
}
|
|
|
|
}
|
2005-07-22 22:43:59 +02:00
|
|
|
if (table_changes != IS_EQUAL_YES)
|
2006-01-27 17:23:14 +01:00
|
|
|
DBUG_RETURN(COMPATIBLE_DATA_NO);
|
2005-07-22 22:43:59 +02:00
|
|
|
|
|
|
|
/* Check that auto_increment value was not changed */
|
|
|
|
if ((info->used_fields & HA_CREATE_USED_AUTO) &&
|
|
|
|
info->auto_increment_value != 0)
|
2006-01-27 17:23:14 +01:00
|
|
|
DBUG_RETURN(COMPATIBLE_DATA_NO);
|
2005-07-22 22:43:59 +02:00
|
|
|
|
|
|
|
/* Check that row format didn't change */
|
|
|
|
if ((info->used_fields & HA_CREATE_USED_AUTO) &&
|
|
|
|
get_row_type() != info->row_type)
|
2006-01-27 17:23:14 +01:00
|
|
|
DBUG_RETURN(COMPATIBLE_DATA_NO);
|
2005-07-22 22:43:59 +02:00
|
|
|
|
2006-01-27 17:23:14 +01:00
|
|
|
DBUG_RETURN(COMPATIBLE_DATA_YES);
|
2005-07-22 22:43:59 +02:00
|
|
|
}
|
|
|
|
|
2005-11-07 12:19:28 +01:00
|
|
|
bool set_up_tablespace(st_alter_tablespace *info,
|
|
|
|
NdbDictionary::Tablespace *ndb_ts)
|
|
|
|
{
|
|
|
|
ndb_ts->setName(info->tablespace_name);
|
|
|
|
ndb_ts->setExtentSize(info->extent_size);
|
|
|
|
ndb_ts->setDefaultLogfileGroup(info->logfile_group_name);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool set_up_datafile(st_alter_tablespace *info,
|
|
|
|
NdbDictionary::Datafile *ndb_df)
|
|
|
|
{
|
|
|
|
if (info->max_size > 0)
|
|
|
|
{
|
|
|
|
my_error(ER_TABLESPACE_AUTO_EXTEND_ERROR, MYF(0));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
ndb_df->setPath(info->data_file_name);
|
|
|
|
ndb_df->setSize(info->initial_size);
|
|
|
|
ndb_df->setTablespace(info->tablespace_name);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool set_up_logfile_group(st_alter_tablespace *info,
|
|
|
|
NdbDictionary::LogfileGroup *ndb_lg)
|
|
|
|
{
|
|
|
|
ndb_lg->setName(info->logfile_group_name);
|
|
|
|
ndb_lg->setUndoBufferSize(info->undo_buffer_size);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool set_up_undofile(st_alter_tablespace *info,
|
|
|
|
NdbDictionary::Undofile *ndb_uf)
|
|
|
|
{
|
|
|
|
ndb_uf->setPath(info->undo_file_name);
|
|
|
|
ndb_uf->setSize(info->initial_size);
|
|
|
|
ndb_uf->setLogfileGroup(info->logfile_group_name);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-09-30 21:49:46 +02:00
|
|
|
int ndbcluster_alter_tablespace(handlerton *hton, THD* thd, st_alter_tablespace *info)
|
2005-11-07 12:19:28 +01:00
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_ndbcluster::alter_tablespace");
|
2006-01-11 11:35:25 +01:00
|
|
|
|
2006-02-01 01:12:11 +01:00
|
|
|
int is_tablespace= 0;
|
2006-01-11 11:35:25 +01:00
|
|
|
Ndb *ndb= check_ndb_in_thd(thd);
|
|
|
|
if (ndb == NULL)
|
2005-11-07 12:19:28 +01:00
|
|
|
{
|
2006-01-11 11:35:25 +01:00
|
|
|
DBUG_RETURN(HA_ERR_NO_CONNECTION);
|
2005-11-07 12:19:28 +01:00
|
|
|
}
|
2006-06-22 10:24:44 +02:00
|
|
|
|
|
|
|
NdbError err;
|
2006-06-26 15:08:09 +02:00
|
|
|
NDBDICT *dict= ndb->getDictionary();
|
2006-01-11 11:35:25 +01:00
|
|
|
int error;
|
|
|
|
const char * errmsg;
|
2006-03-29 13:27:36 +02:00
|
|
|
LINT_INIT(errmsg);
|
2006-01-11 11:35:25 +01:00
|
|
|
|
2005-11-07 12:19:28 +01:00
|
|
|
switch (info->ts_cmd_type){
|
|
|
|
case (CREATE_TABLESPACE):
|
|
|
|
{
|
2006-02-06 13:27:16 +01:00
|
|
|
error= ER_CREATE_FILEGROUP_FAILED;
|
2006-01-11 11:35:25 +01:00
|
|
|
|
2005-11-07 12:19:28 +01:00
|
|
|
NdbDictionary::Tablespace ndb_ts;
|
|
|
|
NdbDictionary::Datafile ndb_df;
|
2006-06-22 10:24:44 +02:00
|
|
|
NdbDictionary::ObjectId objid;
|
2005-11-07 12:19:28 +01:00
|
|
|
if (set_up_tablespace(info, &ndb_ts))
|
|
|
|
{
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
|
|
|
if (set_up_datafile(info, &ndb_df))
|
|
|
|
{
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
2006-01-11 11:35:25 +01:00
|
|
|
errmsg= "TABLESPACE";
|
2006-06-22 10:24:44 +02:00
|
|
|
if (dict->createTablespace(ndb_ts, &objid))
|
2005-11-07 12:19:28 +01:00
|
|
|
{
|
|
|
|
DBUG_PRINT("error", ("createTablespace returned %d", error));
|
2006-01-11 11:35:25 +01:00
|
|
|
goto ndberror;
|
2005-11-07 12:19:28 +01:00
|
|
|
}
|
|
|
|
DBUG_PRINT("info", ("Successfully created Tablespace"));
|
2006-01-11 11:35:25 +01:00
|
|
|
errmsg= "DATAFILE";
|
|
|
|
if (dict->createDatafile(ndb_df))
|
2005-11-07 12:19:28 +01:00
|
|
|
{
|
2006-06-22 10:24:44 +02:00
|
|
|
err= dict->getNdbError();
|
|
|
|
NdbDictionary::Tablespace tmp= dict->getTablespace(ndb_ts.getName());
|
|
|
|
if (dict->getNdbError().code == 0 &&
|
|
|
|
tmp.getObjectId() == objid.getObjectId() &&
|
|
|
|
tmp.getObjectVersion() == objid.getObjectVersion())
|
|
|
|
{
|
|
|
|
dict->dropTablespace(tmp);
|
|
|
|
}
|
|
|
|
|
2005-11-07 12:19:28 +01:00
|
|
|
DBUG_PRINT("error", ("createDatafile returned %d", error));
|
2006-06-22 10:24:44 +02:00
|
|
|
goto ndberror2;
|
2005-11-07 12:19:28 +01:00
|
|
|
}
|
2006-02-01 01:12:11 +01:00
|
|
|
is_tablespace= 1;
|
2005-11-07 12:19:28 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (ALTER_TABLESPACE):
|
|
|
|
{
|
2006-02-06 13:27:16 +01:00
|
|
|
error= ER_ALTER_FILEGROUP_FAILED;
|
2005-11-07 12:19:28 +01:00
|
|
|
if (info->ts_alter_tablespace_type == ALTER_TABLESPACE_ADD_FILE)
|
|
|
|
{
|
|
|
|
NdbDictionary::Datafile ndb_df;
|
|
|
|
if (set_up_datafile(info, &ndb_df))
|
|
|
|
{
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
2006-01-11 11:35:25 +01:00
|
|
|
errmsg= " CREATE DATAFILE";
|
|
|
|
if (dict->createDatafile(ndb_df))
|
2005-11-07 12:19:28 +01:00
|
|
|
{
|
2006-01-11 11:35:25 +01:00
|
|
|
goto ndberror;
|
2005-11-07 12:19:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(info->ts_alter_tablespace_type == ALTER_TABLESPACE_DROP_FILE)
|
|
|
|
{
|
2006-06-26 15:08:09 +02:00
|
|
|
NdbDictionary::Tablespace ts= dict->getTablespace(info->tablespace_name);
|
|
|
|
NdbDictionary::Datafile df= dict->getDatafile(0, info->data_file_name);
|
|
|
|
NdbDictionary::ObjectId objid;
|
|
|
|
df.getTablespaceId(&objid);
|
|
|
|
if (ts.getObjectId() == objid.getObjectId() &&
|
|
|
|
strcmp(df.getPath(), info->data_file_name) == 0)
|
2005-11-07 12:19:28 +01:00
|
|
|
{
|
2006-01-11 11:35:25 +01:00
|
|
|
errmsg= " DROP DATAFILE";
|
|
|
|
if (dict->dropDatafile(df))
|
2005-11-07 12:19:28 +01:00
|
|
|
{
|
2006-01-11 11:35:25 +01:00
|
|
|
goto ndberror;
|
2005-11-07 12:19:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DBUG_PRINT("error", ("No such datafile"));
|
2006-02-06 13:27:16 +01:00
|
|
|
my_error(ER_ALTER_FILEGROUP_FAILED, MYF(0), " NO SUCH FILE");
|
2005-11-07 12:19:28 +01:00
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DBUG_PRINT("error", ("Unsupported alter tablespace: %d",
|
|
|
|
info->ts_alter_tablespace_type));
|
|
|
|
DBUG_RETURN(HA_ADMIN_NOT_IMPLEMENTED);
|
|
|
|
}
|
2006-02-01 01:12:11 +01:00
|
|
|
is_tablespace= 1;
|
2005-11-07 12:19:28 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (CREATE_LOGFILE_GROUP):
|
|
|
|
{
|
2006-02-06 13:27:16 +01:00
|
|
|
error= ER_CREATE_FILEGROUP_FAILED;
|
2005-11-07 12:19:28 +01:00
|
|
|
NdbDictionary::LogfileGroup ndb_lg;
|
|
|
|
NdbDictionary::Undofile ndb_uf;
|
2006-06-22 10:24:44 +02:00
|
|
|
NdbDictionary::ObjectId objid;
|
2005-11-07 12:19:28 +01:00
|
|
|
if (info->undo_file_name == NULL)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
REDO files in LOGFILE GROUP not supported yet
|
|
|
|
*/
|
|
|
|
DBUG_RETURN(HA_ADMIN_NOT_IMPLEMENTED);
|
|
|
|
}
|
|
|
|
if (set_up_logfile_group(info, &ndb_lg))
|
|
|
|
{
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
2006-01-11 11:35:25 +01:00
|
|
|
errmsg= "LOGFILE GROUP";
|
2006-06-22 10:24:44 +02:00
|
|
|
if (dict->createLogfileGroup(ndb_lg, &objid))
|
2005-11-07 12:19:28 +01:00
|
|
|
{
|
2006-01-11 11:35:25 +01:00
|
|
|
goto ndberror;
|
2005-11-07 12:19:28 +01:00
|
|
|
}
|
|
|
|
DBUG_PRINT("info", ("Successfully created Logfile Group"));
|
|
|
|
if (set_up_undofile(info, &ndb_uf))
|
|
|
|
{
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
2006-01-11 11:35:25 +01:00
|
|
|
errmsg= "UNDOFILE";
|
|
|
|
if (dict->createUndofile(ndb_uf))
|
2005-11-07 12:19:28 +01:00
|
|
|
{
|
2006-06-22 10:24:44 +02:00
|
|
|
err= dict->getNdbError();
|
|
|
|
NdbDictionary::LogfileGroup tmp= dict->getLogfileGroup(ndb_lg.getName());
|
|
|
|
if (dict->getNdbError().code == 0 &&
|
|
|
|
tmp.getObjectId() == objid.getObjectId() &&
|
|
|
|
tmp.getObjectVersion() == objid.getObjectVersion())
|
|
|
|
{
|
|
|
|
dict->dropLogfileGroup(tmp);
|
|
|
|
}
|
|
|
|
goto ndberror2;
|
2005-11-07 12:19:28 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (ALTER_LOGFILE_GROUP):
|
|
|
|
{
|
2006-02-06 13:27:16 +01:00
|
|
|
error= ER_ALTER_FILEGROUP_FAILED;
|
2005-11-07 12:19:28 +01:00
|
|
|
if (info->undo_file_name == NULL)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
REDO files in LOGFILE GROUP not supported yet
|
|
|
|
*/
|
|
|
|
DBUG_RETURN(HA_ADMIN_NOT_IMPLEMENTED);
|
|
|
|
}
|
|
|
|
NdbDictionary::Undofile ndb_uf;
|
|
|
|
if (set_up_undofile(info, &ndb_uf))
|
|
|
|
{
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
2006-01-11 11:35:25 +01:00
|
|
|
errmsg= "CREATE UNDOFILE";
|
|
|
|
if (dict->createUndofile(ndb_uf))
|
2005-11-07 12:19:28 +01:00
|
|
|
{
|
2006-01-11 11:35:25 +01:00
|
|
|
goto ndberror;
|
2005-11-07 12:19:28 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (DROP_TABLESPACE):
|
|
|
|
{
|
2006-02-06 13:27:16 +01:00
|
|
|
error= ER_DROP_FILEGROUP_FAILED;
|
2006-01-11 11:35:25 +01:00
|
|
|
errmsg= "TABLESPACE";
|
|
|
|
if (dict->dropTablespace(dict->getTablespace(info->tablespace_name)))
|
2005-11-07 12:19:28 +01:00
|
|
|
{
|
2006-01-11 11:35:25 +01:00
|
|
|
goto ndberror;
|
2005-11-07 12:19:28 +01:00
|
|
|
}
|
2006-02-01 01:12:11 +01:00
|
|
|
is_tablespace= 1;
|
2005-11-07 12:19:28 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (DROP_LOGFILE_GROUP):
|
|
|
|
{
|
2006-02-06 13:27:16 +01:00
|
|
|
error= ER_DROP_FILEGROUP_FAILED;
|
2006-01-11 11:35:25 +01:00
|
|
|
errmsg= "LOGFILE GROUP";
|
|
|
|
if (dict->dropLogfileGroup(dict->getLogfileGroup(info->logfile_group_name)))
|
2005-11-07 12:19:28 +01:00
|
|
|
{
|
2006-01-11 11:35:25 +01:00
|
|
|
goto ndberror;
|
2005-11-07 12:19:28 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (CHANGE_FILE_TABLESPACE):
|
|
|
|
{
|
|
|
|
DBUG_RETURN(HA_ADMIN_NOT_IMPLEMENTED);
|
|
|
|
}
|
|
|
|
case (ALTER_ACCESS_MODE_TABLESPACE):
|
|
|
|
{
|
|
|
|
DBUG_RETURN(HA_ADMIN_NOT_IMPLEMENTED);
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
DBUG_RETURN(HA_ADMIN_NOT_IMPLEMENTED);
|
|
|
|
}
|
|
|
|
}
|
2006-02-01 10:21:48 +01:00
|
|
|
#ifdef HAVE_NDB_BINLOG
|
2006-02-01 01:12:11 +01:00
|
|
|
if (is_tablespace)
|
|
|
|
ndbcluster_log_schema_op(thd, 0,
|
|
|
|
thd->query, thd->query_length,
|
|
|
|
"", info->tablespace_name,
|
|
|
|
0, 0,
|
2006-05-31 01:52:14 +02:00
|
|
|
SOT_TABLESPACE, 0, 0, 0);
|
2006-02-01 01:12:11 +01:00
|
|
|
else
|
|
|
|
ndbcluster_log_schema_op(thd, 0,
|
|
|
|
thd->query, thd->query_length,
|
|
|
|
"", info->logfile_group_name,
|
|
|
|
0, 0,
|
2006-05-31 01:52:14 +02:00
|
|
|
SOT_LOGFILE_GROUP, 0, 0, 0);
|
2006-02-01 10:21:48 +01:00
|
|
|
#endif
|
2005-11-07 12:19:28 +01:00
|
|
|
DBUG_RETURN(FALSE);
|
2006-01-11 11:35:25 +01:00
|
|
|
|
|
|
|
ndberror:
|
2006-06-22 10:24:44 +02:00
|
|
|
err= dict->getNdbError();
|
|
|
|
ndberror2:
|
2006-01-11 11:35:25 +01:00
|
|
|
ERR_PRINT(err);
|
|
|
|
ndb_to_mysql_error(&err);
|
|
|
|
|
|
|
|
my_error(error, MYF(0), errmsg);
|
|
|
|
DBUG_RETURN(1);
|
2005-11-07 12:19:28 +01:00
|
|
|
}
|
|
|
|
|
2006-01-17 08:40:00 +01:00
|
|
|
|
|
|
|
bool ha_ndbcluster::get_no_parts(const char *name, uint *no_parts)
|
|
|
|
{
|
|
|
|
Ndb *ndb;
|
|
|
|
NDBDICT *dict;
|
|
|
|
const NDBTAB *tab;
|
|
|
|
int err;
|
|
|
|
DBUG_ENTER("ha_ndbcluster::get_no_parts");
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
LINT_INIT(err);
|
2006-01-17 08:40:00 +01:00
|
|
|
|
|
|
|
set_dbname(name);
|
|
|
|
set_tabname(name);
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
for (;;)
|
2006-01-17 08:40:00 +01:00
|
|
|
{
|
|
|
|
if (check_ndb_connection())
|
|
|
|
{
|
|
|
|
err= HA_ERR_NO_CONNECTION;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ndb= get_ndb();
|
2006-02-07 16:31:20 +01:00
|
|
|
ndb->setDatabaseName(m_dbname);
|
2006-05-04 13:58:17 +02:00
|
|
|
Ndb_table_guard ndbtab_g(dict= ndb->getDictionary(), m_tabname);
|
|
|
|
if (!ndbtab_g.get_table())
|
2006-01-17 08:40:00 +01:00
|
|
|
ERR_BREAK(dict->getNdbError(), err);
|
2006-05-04 13:58:17 +02:00
|
|
|
*no_parts= ndbtab_g.get_table()->getFragmentCount();
|
2006-01-17 08:40:00 +01:00
|
|
|
DBUG_RETURN(FALSE);
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
}
|
2006-01-17 08:40:00 +01:00
|
|
|
|
|
|
|
print_error(err, MYF(0));
|
|
|
|
DBUG_RETURN(TRUE);
|
|
|
|
}
|
|
|
|
|
2006-09-30 21:49:46 +02:00
|
|
|
static int ndbcluster_fill_files_table(handlerton *hton,
|
|
|
|
THD *thd,
|
|
|
|
TABLE_LIST *tables,
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
COND *cond)
|
2006-01-28 04:16:23 +01:00
|
|
|
{
|
|
|
|
TABLE* table= tables->table;
|
2006-02-01 22:37:25 +01:00
|
|
|
Ndb *ndb= check_ndb_in_thd(thd);
|
2006-01-28 04:16:23 +01:00
|
|
|
NdbDictionary::Dictionary* dict= ndb->getDictionary();
|
|
|
|
NdbDictionary::Dictionary::List dflist;
|
2006-02-02 00:24:42 +01:00
|
|
|
NdbError ndberr;
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
uint i;
|
2006-02-07 12:16:24 +01:00
|
|
|
DBUG_ENTER("ndbcluster_fill_files_table");
|
2006-01-28 04:16:23 +01:00
|
|
|
|
2006-02-02 00:24:42 +01:00
|
|
|
dict->listObjects(dflist, NdbDictionary::Object::Datafile);
|
|
|
|
ndberr= dict->getNdbError();
|
2006-02-07 12:16:24 +01:00
|
|
|
if (ndberr.classification != NdbError::NoError)
|
|
|
|
ERR_RETURN(ndberr);
|
2006-01-28 04:16:23 +01:00
|
|
|
|
2006-02-07 12:16:24 +01:00
|
|
|
for (i= 0; i < dflist.count; i++)
|
2006-01-28 04:16:23 +01:00
|
|
|
{
|
|
|
|
NdbDictionary::Dictionary::List::Element& elt = dflist.elements[i];
|
|
|
|
Ndb_cluster_connection_node_iter iter;
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
uint id;
|
|
|
|
|
2006-01-28 04:16:23 +01:00
|
|
|
g_ndb_cluster_connection->init_get_next_node(iter);
|
|
|
|
|
2006-02-07 12:16:24 +01:00
|
|
|
while ((id= g_ndb_cluster_connection->get_next_node(iter)))
|
2006-01-28 04:16:23 +01:00
|
|
|
{
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
uint c= 0;
|
2006-01-28 04:16:23 +01:00
|
|
|
NdbDictionary::Datafile df= dict->getDatafile(id, elt.name);
|
2006-02-02 00:24:42 +01:00
|
|
|
ndberr= dict->getNdbError();
|
2006-02-07 12:16:24 +01:00
|
|
|
if(ndberr.classification != NdbError::NoError)
|
|
|
|
{
|
|
|
|
if (ndberr.classification == NdbError::SchemaError)
|
|
|
|
continue;
|
|
|
|
ERR_RETURN(ndberr);
|
|
|
|
}
|
2006-02-02 00:24:42 +01:00
|
|
|
NdbDictionary::Tablespace ts= dict->getTablespace(df.getTablespace());
|
|
|
|
ndberr= dict->getNdbError();
|
2006-02-07 12:16:24 +01:00
|
|
|
if (ndberr.classification != NdbError::NoError)
|
|
|
|
{
|
|
|
|
if (ndberr.classification == NdbError::SchemaError)
|
|
|
|
continue;
|
|
|
|
ERR_RETURN(ndberr);
|
|
|
|
}
|
2006-02-02 00:24:42 +01:00
|
|
|
|
2006-01-28 04:16:23 +01:00
|
|
|
table->field[c++]->set_null(); // FILE_ID
|
2006-09-18 17:44:32 +02:00
|
|
|
table->field[c]->set_notnull();
|
2006-02-02 00:24:42 +01:00
|
|
|
table->field[c++]->store(elt.name, strlen(elt.name),
|
|
|
|
system_charset_info);
|
2006-09-18 17:44:32 +02:00
|
|
|
table->field[c]->set_notnull();
|
2006-01-28 04:16:23 +01:00
|
|
|
table->field[c++]->store("DATAFILE",8,system_charset_info);
|
2006-09-18 17:44:32 +02:00
|
|
|
table->field[c]->set_notnull();
|
2006-02-02 00:24:42 +01:00
|
|
|
table->field[c++]->store(df.getTablespace(), strlen(df.getTablespace()),
|
2006-01-28 04:16:23 +01:00
|
|
|
system_charset_info);
|
|
|
|
table->field[c++]->set_null(); // TABLE_CATALOG
|
|
|
|
table->field[c++]->set_null(); // TABLE_SCHEMA
|
|
|
|
table->field[c++]->set_null(); // TABLE_NAME
|
|
|
|
|
|
|
|
// LOGFILE_GROUP_NAME
|
2006-09-18 17:44:32 +02:00
|
|
|
table->field[c]->set_notnull();
|
2006-01-28 04:16:23 +01:00
|
|
|
table->field[c++]->store(ts.getDefaultLogfileGroup(),
|
|
|
|
strlen(ts.getDefaultLogfileGroup()),
|
|
|
|
system_charset_info);
|
|
|
|
table->field[c++]->set_null(); // LOGFILE_GROUP_NUMBER
|
2006-09-18 17:44:32 +02:00
|
|
|
table->field[c]->set_notnull();
|
2006-05-28 14:51:01 +02:00
|
|
|
table->field[c++]->store(ndbcluster_hton_name,
|
|
|
|
ndbcluster_hton_name_length,
|
2006-01-28 04:16:23 +01:00
|
|
|
system_charset_info); // ENGINE
|
|
|
|
|
|
|
|
table->field[c++]->set_null(); // FULLTEXT_KEYS
|
|
|
|
table->field[c++]->set_null(); // DELETED_ROWS
|
|
|
|
table->field[c++]->set_null(); // UPDATE_COUNT
|
2006-09-18 17:44:32 +02:00
|
|
|
table->field[c]->set_notnull();
|
2006-01-28 04:16:23 +01:00
|
|
|
table->field[c++]->store(df.getFree() / ts.getExtentSize()); // FREE_EXTENTS
|
2006-09-18 17:44:32 +02:00
|
|
|
table->field[c]->set_notnull();
|
2006-01-28 04:16:23 +01:00
|
|
|
table->field[c++]->store(df.getSize() / ts.getExtentSize()); // TOTAL_EXTENTS
|
2006-09-18 17:44:32 +02:00
|
|
|
table->field[c]->set_notnull();
|
2006-01-28 04:16:23 +01:00
|
|
|
table->field[c++]->store(ts.getExtentSize()); // EXTENT_SIZE
|
|
|
|
|
2006-09-18 17:44:32 +02:00
|
|
|
table->field[c]->set_notnull();
|
2006-01-28 04:16:23 +01:00
|
|
|
table->field[c++]->store(df.getSize()); // INITIAL_SIZE
|
2006-09-18 17:44:32 +02:00
|
|
|
table->field[c]->set_notnull();
|
2006-01-28 04:16:23 +01:00
|
|
|
table->field[c++]->store(df.getSize()); // MAXIMUM_SIZE
|
|
|
|
table->field[c++]->set_null(); // AUTOEXTEND_SIZE
|
|
|
|
|
|
|
|
table->field[c++]->set_null(); // CREATION_TIME
|
|
|
|
table->field[c++]->set_null(); // LAST_UPDATE_TIME
|
|
|
|
table->field[c++]->set_null(); // LAST_ACCESS_TIME
|
|
|
|
table->field[c++]->set_null(); // RECOVER_TIME
|
|
|
|
table->field[c++]->set_null(); // TRANSACTION_COUNTER
|
|
|
|
|
2006-09-18 17:44:32 +02:00
|
|
|
table->field[c]->set_notnull();
|
2006-01-28 04:16:23 +01:00
|
|
|
table->field[c++]->store(df.getObjectVersion()); // VERSION
|
|
|
|
|
2006-09-18 17:44:32 +02:00
|
|
|
table->field[c]->set_notnull();
|
2006-02-02 00:24:42 +01:00
|
|
|
table->field[c++]->store("FIXED", 5, system_charset_info); // ROW_FORMAT
|
2006-01-28 04:16:23 +01:00
|
|
|
|
|
|
|
table->field[c++]->set_null(); // TABLE_ROWS
|
|
|
|
table->field[c++]->set_null(); // AVG_ROW_LENGTH
|
|
|
|
table->field[c++]->set_null(); // DATA_LENGTH
|
|
|
|
table->field[c++]->set_null(); // MAX_DATA_LENGTH
|
|
|
|
table->field[c++]->set_null(); // INDEX_LENGTH
|
|
|
|
table->field[c++]->set_null(); // DATA_FREE
|
|
|
|
table->field[c++]->set_null(); // CREATE_TIME
|
|
|
|
table->field[c++]->set_null(); // UPDATE_TIME
|
|
|
|
table->field[c++]->set_null(); // CHECK_TIME
|
|
|
|
table->field[c++]->set_null(); // CHECKSUM
|
|
|
|
|
2006-09-18 17:44:32 +02:00
|
|
|
table->field[c]->set_notnull();
|
2006-02-02 00:24:42 +01:00
|
|
|
table->field[c++]->store("NORMAL", 6, system_charset_info);
|
2006-01-28 04:16:23 +01:00
|
|
|
|
|
|
|
char extra[30];
|
2006-02-02 00:24:42 +01:00
|
|
|
int len= my_snprintf(extra, sizeof(extra), "CLUSTER_NODE=%u", id);
|
|
|
|
table->field[c]->store(extra, len, system_charset_info);
|
2006-09-18 17:44:32 +02:00
|
|
|
table->field[c]->set_notnull();
|
2006-01-28 04:16:23 +01:00
|
|
|
schema_table_store_record(thd, table);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-10 17:06:33 +02:00
|
|
|
NdbDictionary::Dictionary::List uflist;
|
|
|
|
dict->listObjects(uflist, NdbDictionary::Object::Undofile);
|
2006-02-02 00:24:42 +01:00
|
|
|
ndberr= dict->getNdbError();
|
2006-02-07 12:16:24 +01:00
|
|
|
if (ndberr.classification != NdbError::NoError)
|
|
|
|
ERR_RETURN(ndberr);
|
2006-01-28 04:16:23 +01:00
|
|
|
|
2006-04-10 17:06:33 +02:00
|
|
|
for (i= 0; i < uflist.count; i++)
|
2006-01-28 04:16:23 +01:00
|
|
|
{
|
2006-04-10 17:06:33 +02:00
|
|
|
NdbDictionary::Dictionary::List::Element& elt= uflist.elements[i];
|
2006-01-28 04:16:23 +01:00
|
|
|
Ndb_cluster_connection_node_iter iter;
|
|
|
|
unsigned id;
|
|
|
|
|
|
|
|
g_ndb_cluster_connection->init_get_next_node(iter);
|
|
|
|
|
2006-02-07 12:16:24 +01:00
|
|
|
while ((id= g_ndb_cluster_connection->get_next_node(iter)))
|
2006-01-28 04:16:23 +01:00
|
|
|
{
|
|
|
|
NdbDictionary::Undofile uf= dict->getUndofile(id, elt.name);
|
2006-02-02 00:24:42 +01:00
|
|
|
ndberr= dict->getNdbError();
|
2006-02-07 12:16:24 +01:00
|
|
|
if (ndberr.classification != NdbError::NoError)
|
|
|
|
{
|
|
|
|
if (ndberr.classification == NdbError::SchemaError)
|
|
|
|
continue;
|
|
|
|
ERR_RETURN(ndberr);
|
|
|
|
}
|
2006-02-02 00:24:42 +01:00
|
|
|
NdbDictionary::LogfileGroup lfg=
|
|
|
|
dict->getLogfileGroup(uf.getLogfileGroup());
|
|
|
|
ndberr= dict->getNdbError();
|
2006-02-07 12:16:24 +01:00
|
|
|
if (ndberr.classification != NdbError::NoError)
|
|
|
|
{
|
|
|
|
if (ndberr.classification == NdbError::SchemaError)
|
|
|
|
continue;
|
|
|
|
ERR_RETURN(ndberr);
|
|
|
|
}
|
2006-02-02 00:24:42 +01:00
|
|
|
|
|
|
|
int c= 0;
|
2006-01-28 04:16:23 +01:00
|
|
|
table->field[c++]->set_null(); // FILE_ID
|
2006-09-18 17:44:32 +02:00
|
|
|
table->field[c]->set_notnull();
|
2006-02-02 00:24:42 +01:00
|
|
|
table->field[c++]->store(elt.name, strlen(elt.name),
|
|
|
|
system_charset_info);
|
2006-09-18 17:44:32 +02:00
|
|
|
table->field[c]->set_notnull();
|
2006-02-02 00:24:42 +01:00
|
|
|
table->field[c++]->store("UNDO LOG", 8, system_charset_info);
|
2006-01-28 04:16:23 +01:00
|
|
|
table->field[c++]->set_null(); // TABLESPACE NAME
|
|
|
|
table->field[c++]->set_null(); // TABLE_CATALOG
|
|
|
|
table->field[c++]->set_null(); // TABLE_SCHEMA
|
|
|
|
table->field[c++]->set_null(); // TABLE_NAME
|
|
|
|
|
|
|
|
// LOGFILE_GROUP_NAME
|
2006-06-26 15:08:09 +02:00
|
|
|
NdbDictionary::ObjectId objid;
|
|
|
|
uf.getLogfileGroupId(&objid);
|
2006-09-18 17:44:32 +02:00
|
|
|
table->field[c]->set_notnull();
|
2006-01-28 04:16:23 +01:00
|
|
|
table->field[c++]->store(uf.getLogfileGroup(),
|
|
|
|
strlen(uf.getLogfileGroup()),
|
|
|
|
system_charset_info);
|
2006-09-18 17:44:32 +02:00
|
|
|
table->field[c]->set_notnull();
|
2006-06-26 15:08:09 +02:00
|
|
|
table->field[c++]->store(objid.getObjectId()); // LOGFILE_GROUP_NUMBER
|
2006-09-18 17:44:32 +02:00
|
|
|
table->field[c]->set_notnull();
|
2006-05-28 14:51:01 +02:00
|
|
|
table->field[c++]->store(ndbcluster_hton_name,
|
|
|
|
ndbcluster_hton_name_length,
|
2006-01-28 04:16:23 +01:00
|
|
|
system_charset_info); // ENGINE
|
|
|
|
|
|
|
|
table->field[c++]->set_null(); // FULLTEXT_KEYS
|
|
|
|
table->field[c++]->set_null(); // DELETED_ROWS
|
|
|
|
table->field[c++]->set_null(); // UPDATE_COUNT
|
2006-09-18 17:44:32 +02:00
|
|
|
table->field[c++]->set_null(); // FREE_EXTENTS
|
|
|
|
table->field[c]->set_notnull();
|
2006-06-19 16:30:19 +02:00
|
|
|
table->field[c++]->store(uf.getSize()/4); // TOTAL_EXTENTS
|
2006-09-18 17:44:32 +02:00
|
|
|
table->field[c]->set_notnull();
|
2006-01-28 04:16:23 +01:00
|
|
|
table->field[c++]->store(4); // EXTENT_SIZE
|
|
|
|
|
2006-09-18 17:44:32 +02:00
|
|
|
table->field[c]->set_notnull();
|
2006-01-28 04:16:23 +01:00
|
|
|
table->field[c++]->store(uf.getSize()); // INITIAL_SIZE
|
2006-09-18 17:44:32 +02:00
|
|
|
table->field[c]->set_notnull();
|
2006-01-28 04:16:23 +01:00
|
|
|
table->field[c++]->store(uf.getSize()); // MAXIMUM_SIZE
|
|
|
|
table->field[c++]->set_null(); // AUTOEXTEND_SIZE
|
|
|
|
|
|
|
|
table->field[c++]->set_null(); // CREATION_TIME
|
|
|
|
table->field[c++]->set_null(); // LAST_UPDATE_TIME
|
|
|
|
table->field[c++]->set_null(); // LAST_ACCESS_TIME
|
|
|
|
table->field[c++]->set_null(); // RECOVER_TIME
|
|
|
|
table->field[c++]->set_null(); // TRANSACTION_COUNTER
|
|
|
|
|
2006-09-18 17:44:32 +02:00
|
|
|
table->field[c]->set_notnull();
|
2006-01-28 04:16:23 +01:00
|
|
|
table->field[c++]->store(uf.getObjectVersion()); // VERSION
|
|
|
|
|
|
|
|
table->field[c++]->set_null(); // ROW FORMAT
|
|
|
|
|
|
|
|
table->field[c++]->set_null(); // TABLE_ROWS
|
|
|
|
table->field[c++]->set_null(); // AVG_ROW_LENGTH
|
|
|
|
table->field[c++]->set_null(); // DATA_LENGTH
|
|
|
|
table->field[c++]->set_null(); // MAX_DATA_LENGTH
|
|
|
|
table->field[c++]->set_null(); // INDEX_LENGTH
|
|
|
|
table->field[c++]->set_null(); // DATA_FREE
|
|
|
|
table->field[c++]->set_null(); // CREATE_TIME
|
|
|
|
table->field[c++]->set_null(); // UPDATE_TIME
|
|
|
|
table->field[c++]->set_null(); // CHECK_TIME
|
|
|
|
table->field[c++]->set_null(); // CHECKSUM
|
|
|
|
|
2006-09-18 17:44:32 +02:00
|
|
|
table->field[c]->set_notnull();
|
2006-02-02 00:24:42 +01:00
|
|
|
table->field[c++]->store("NORMAL", 6, system_charset_info);
|
2006-01-28 04:16:23 +01:00
|
|
|
|
2006-06-19 16:30:19 +02:00
|
|
|
char extra[100];
|
|
|
|
int len= my_snprintf(extra,sizeof(extra),"CLUSTER_NODE=%u;UNDO_BUFFER_SIZE=%lu",id,lfg.getUndoBufferSize());
|
2006-09-18 17:44:32 +02:00
|
|
|
table->field[c]->set_notnull();
|
2006-02-02 00:24:42 +01:00
|
|
|
table->field[c]->store(extra, len, system_charset_info);
|
2006-01-28 04:16:23 +01:00
|
|
|
schema_table_store_record(thd, table);
|
|
|
|
}
|
|
|
|
}
|
2006-09-18 17:44:32 +02:00
|
|
|
|
|
|
|
// now for LFGs
|
|
|
|
NdbDictionary::Dictionary::List lfglist;
|
|
|
|
dict->listObjects(lfglist, NdbDictionary::Object::LogfileGroup);
|
|
|
|
ndberr= dict->getNdbError();
|
|
|
|
if (ndberr.classification != NdbError::NoError)
|
|
|
|
ERR_RETURN(ndberr);
|
|
|
|
|
|
|
|
for (i= 0; i < lfglist.count; i++)
|
|
|
|
{
|
|
|
|
NdbDictionary::Dictionary::List::Element& elt= lfglist.elements[i];
|
|
|
|
unsigned id;
|
|
|
|
|
|
|
|
NdbDictionary::LogfileGroup lfg= dict->getLogfileGroup(elt.name);
|
|
|
|
ndberr= dict->getNdbError();
|
|
|
|
if (ndberr.classification != NdbError::NoError)
|
|
|
|
{
|
|
|
|
if (ndberr.classification == NdbError::SchemaError)
|
|
|
|
continue;
|
|
|
|
ERR_RETURN(ndberr);
|
|
|
|
}
|
|
|
|
|
|
|
|
int c= 0;
|
|
|
|
table->field[c++]->set_null(); // FILE_ID
|
|
|
|
table->field[c++]->set_null(); // name
|
|
|
|
table->field[c]->set_notnull();
|
|
|
|
table->field[c++]->store("UNDO LOG", 8, system_charset_info);
|
|
|
|
table->field[c++]->set_null(); // TABLESPACE NAME
|
|
|
|
table->field[c++]->set_null(); // TABLE_CATALOG
|
|
|
|
table->field[c++]->set_null(); // TABLE_SCHEMA
|
|
|
|
table->field[c++]->set_null(); // TABLE_NAME
|
|
|
|
|
|
|
|
// LOGFILE_GROUP_NAME
|
|
|
|
table->field[c]->set_notnull();
|
|
|
|
table->field[c++]->store(elt.name, strlen(elt.name),
|
|
|
|
system_charset_info);
|
|
|
|
table->field[c]->set_notnull();
|
|
|
|
table->field[c++]->store(lfg.getObjectId()); // LOGFILE_GROUP_NUMBER
|
|
|
|
table->field[c]->set_notnull();
|
|
|
|
table->field[c++]->store(ndbcluster_hton_name,
|
|
|
|
ndbcluster_hton_name_length,
|
|
|
|
system_charset_info); // ENGINE
|
|
|
|
|
|
|
|
table->field[c++]->set_null(); // FULLTEXT_KEYS
|
|
|
|
table->field[c++]->set_null(); // DELETED_ROWS
|
|
|
|
table->field[c++]->set_null(); // UPDATE_COUNT
|
|
|
|
table->field[c]->set_notnull();
|
|
|
|
table->field[c++]->store(lfg.getUndoFreeWords()); // FREE_EXTENTS
|
|
|
|
table->field[c++]->set_null(); //store(uf.getSize()/4); // TOTAL_EXTENTS
|
|
|
|
table->field[c]->set_notnull();
|
|
|
|
table->field[c++]->store(4); // EXTENT_SIZE
|
|
|
|
|
|
|
|
table->field[c++]->set_null();//store(uf.getSize()); // INITIAL_SIZE
|
|
|
|
table->field[c++]->set_null(); //store(uf.getSize()); // MAXIMUM_SIZE
|
|
|
|
table->field[c++]->set_null(); // AUTOEXTEND_SIZE
|
|
|
|
|
|
|
|
table->field[c++]->set_null(); // CREATION_TIME
|
|
|
|
table->field[c++]->set_null(); // LAST_UPDATE_TIME
|
|
|
|
table->field[c++]->set_null(); // LAST_ACCESS_TIME
|
|
|
|
table->field[c++]->set_null(); // RECOVER_TIME
|
|
|
|
table->field[c++]->set_null(); // TRANSACTION_COUNTER
|
|
|
|
|
|
|
|
table->field[c]->set_notnull();
|
|
|
|
table->field[c++]->store(lfg.getObjectVersion()); // VERSION
|
|
|
|
|
|
|
|
table->field[c++]->set_null(); // ROW FORMAT
|
|
|
|
|
|
|
|
table->field[c++]->set_null(); // TABLE_ROWS
|
|
|
|
table->field[c++]->set_null(); // AVG_ROW_LENGTH
|
|
|
|
table->field[c++]->set_null(); // DATA_LENGTH
|
|
|
|
table->field[c++]->set_null(); // MAX_DATA_LENGTH
|
|
|
|
table->field[c++]->set_null(); // INDEX_LENGTH
|
|
|
|
table->field[c++]->set_null(); // DATA_FREE
|
|
|
|
table->field[c++]->set_null(); // CREATE_TIME
|
|
|
|
table->field[c++]->set_null(); // UPDATE_TIME
|
|
|
|
table->field[c++]->set_null(); // CHECK_TIME
|
|
|
|
table->field[c++]->set_null(); // CHECKSUM
|
|
|
|
|
|
|
|
table->field[c]->set_notnull();
|
|
|
|
table->field[c++]->store("NORMAL", 6, system_charset_info);
|
|
|
|
|
|
|
|
char extra[100];
|
|
|
|
int len= my_snprintf(extra,sizeof(extra),"UNDO_BUFFER_SIZE=%lu",id,lfg.getUndoBufferSize());
|
|
|
|
table->field[c]->set_notnull();
|
|
|
|
table->field[c]->store(extra, len, system_charset_info);
|
|
|
|
schema_table_store_record(thd, table);
|
|
|
|
}
|
2006-02-07 12:16:24 +01:00
|
|
|
DBUG_RETURN(0);
|
2006-01-28 04:16:23 +01:00
|
|
|
}
|
2006-04-13 22:49:29 +02:00
|
|
|
|
2006-08-23 01:24:12 +02:00
|
|
|
SHOW_VAR ndb_status_variables_export[]= {
|
|
|
|
{"Ndb", (char*) &ndb_status_variables, SHOW_ARRAY},
|
|
|
|
{NullS, NullS, SHOW_LONG}
|
|
|
|
};
|
|
|
|
|
2006-05-28 14:51:01 +02:00
|
|
|
struct st_mysql_storage_engine ndbcluster_storage_engine=
|
2006-09-27 06:26:04 +02:00
|
|
|
{ MYSQL_HANDLERTON_INTERFACE_VERSION };
|
2006-04-13 22:49:29 +02:00
|
|
|
|
|
|
|
mysql_declare_plugin(ndbcluster)
|
|
|
|
{
|
|
|
|
MYSQL_STORAGE_ENGINE_PLUGIN,
|
2006-05-28 14:51:01 +02:00
|
|
|
&ndbcluster_storage_engine,
|
2006-05-02 13:11:00 +02:00
|
|
|
ndbcluster_hton_name,
|
2006-04-13 22:49:29 +02:00
|
|
|
"MySQL AB",
|
2006-05-28 14:51:01 +02:00
|
|
|
"Clustered, fault-tolerant tables",
|
2006-10-05 09:41:29 +02:00
|
|
|
PLUGIN_LICENSE_GPL,
|
2006-05-28 14:51:01 +02:00
|
|
|
ndbcluster_init, /* Plugin Init */
|
2006-04-13 22:49:29 +02:00
|
|
|
NULL, /* Plugin Deinit */
|
|
|
|
0x0100 /* 1.0 */,
|
2006-08-30 23:27:29 +02:00
|
|
|
ndb_status_variables_export,/* status variables */
|
|
|
|
NULL, /* system variables */
|
|
|
|
NULL /* config options */
|
2006-04-13 22:49:29 +02:00
|
|
|
}
|
|
|
|
mysql_declare_plugin_end;
|
|
|
|
|
|
|
|
#endif
|