2004-04-01 11:02:42 +02:00
|
|
|
/* Copyright (C) 2003 MySQL AB
|
|
|
|
|
|
|
|
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
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
|
|
|
2004-06-23 21:26:34 +02:00
|
|
|
/*
|
|
|
|
ha_example is a stubbed storage engine. It does nothing at this point. It
|
|
|
|
will let you create/open/delete tables but that is all. You can enable it
|
2004-05-12 00:59:20 +02:00
|
|
|
in your buld by doing the following during your build process:
|
|
|
|
./configure --with-example-storage-engine
|
2004-06-23 21:26:34 +02:00
|
|
|
|
2004-05-12 00:59:20 +02:00
|
|
|
Once this is done mysql will let you create tables with:
|
|
|
|
CREATE TABLE A (...) ENGINE=EXAMPLE;
|
|
|
|
|
|
|
|
The example is setup to use table locks. It implements an example "SHARE"
|
2004-06-23 21:26:34 +02:00
|
|
|
that is inserted into a hash by table name. You can use this to store
|
2004-05-12 00:59:20 +02:00
|
|
|
information of state that any example handler object will be able to see
|
|
|
|
if it is using the same table.
|
|
|
|
|
2004-06-23 21:26:34 +02:00
|
|
|
Please read the object definition in ha_example.h before reading the rest
|
2004-05-12 00:59:20 +02:00
|
|
|
if this file.
|
|
|
|
|
2004-06-23 21:26:34 +02:00
|
|
|
To get an idea of what occurs here is an example select that would do a
|
2004-05-12 00:59:20 +02:00
|
|
|
scan of an entire table:
|
|
|
|
ha_example::store_lock
|
|
|
|
ha_example::external_lock
|
|
|
|
ha_example::info
|
|
|
|
ha_example::rnd_init
|
|
|
|
ha_example::extra
|
|
|
|
ENUM HA_EXTRA_CACHE Cash record in HA_rrnd()
|
|
|
|
ha_example::rnd_next
|
|
|
|
ha_example::rnd_next
|
|
|
|
ha_example::rnd_next
|
|
|
|
ha_example::rnd_next
|
|
|
|
ha_example::rnd_next
|
|
|
|
ha_example::rnd_next
|
|
|
|
ha_example::rnd_next
|
|
|
|
ha_example::rnd_next
|
|
|
|
ha_example::rnd_next
|
|
|
|
ha_example::extra
|
|
|
|
ENUM HA_EXTRA_NO_CACHE End cacheing of records (def)
|
2004-06-23 21:26:34 +02:00
|
|
|
ha_example::external_lock
|
2004-05-12 00:59:20 +02:00
|
|
|
ha_example::extra
|
|
|
|
ENUM HA_EXTRA_RESET Reset database to after open
|
|
|
|
|
2004-06-23 21:26:34 +02:00
|
|
|
In the above example has 9 row called before rnd_next signalled that it was
|
|
|
|
at the end of its data. In the above example the table was already opened
|
|
|
|
(or you would have seen a call to ha_example::open(). Calls to
|
2004-05-12 00:59:20 +02:00
|
|
|
ha_example::extra() are hints as to what will be occuring to the request.
|
|
|
|
|
|
|
|
Happy coding!
|
|
|
|
-Brian
|
|
|
|
*/
|
|
|
|
|
2005-06-02 02:43:32 +02:00
|
|
|
#ifdef USE_PRAGMA_IMPLEMENTATION
|
2004-04-01 11:02:42 +02:00
|
|
|
#pragma implementation // gcc: Class implementation
|
|
|
|
#endif
|
|
|
|
|
2005-08-18 17:29:24 +02:00
|
|
|
#include "../mysql_priv.h"
|
2005-12-21 19:18:40 +01:00
|
|
|
#include <plugin.h>
|
2004-04-13 06:01:45 +02:00
|
|
|
|
2004-04-01 11:02:42 +02:00
|
|
|
#include "ha_example.h"
|
|
|
|
|
2005-11-25 10:35:26 +01:00
|
|
|
static handler* example_create_handler(TABLE_SHARE *table);
|
2005-12-21 19:18:40 +01:00
|
|
|
static int example_init_func();
|
A fix and a test case for Bug#10760 and complementary cleanups.
The idea of the patch
is that every cursor gets its own lock id for table level locking.
Thus cursors are protected from updates performed within the same
connection. Additionally a list of transient (must be closed at
commit) cursors is maintained and all transient cursors are closed
when necessary. Lastly, this patch adds support for deadlock
timeouts to TLL locking when using cursors.
+ post-review fixes.
include/thr_lock.h:
- add a notion of lock owner to table level locking. When using
cursors, lock owner can not be identified by a thread id any more,
as we must protect cursors from updates issued within the same
connection (thread). So, each cursor has its own lock identifier to
use with table level locking.
- extend return values of thr_lock and thr_multi_lock with
THR_LOCK_TIMEOUT and THR_LOCK_DEADLOCK, since these conditions
are now possible (see comments to thr_lock.c)
mysys/thr_lock.c:
Better support for cursors:
- use THR_LOCK_OWNER * as lock identifier, not pthread_t.
- check and return an error for a trivial deadlock case, when an
update statement is issued to a table locked by a cursor which has
been previously opened in the same connection.
- add support for locking timeouts: with use of cursors, trivial
deadlocks can occur. For now the only remedy is the lock wait timeout,
which is initialized from a new global variable 'table_lock_wait_timeout'
Example of a deadlock (assuming the storage engine does not downgrade
locks):
con1: open cursor for select * from t1;
con2: open cursor for select * from t2;
con1: update t2 set id=id*2; -- blocked
con2: update t1 set id=id*2; -- deadlock
Lock timeouts are active only if a connection is using cursors.
- the check in the wait_for_lock loop has been changed from
data->cond != cond to data->cond != 0. data->cond is zeroed
in every place it's changed.
- added comments
sql/examples/ha_archive.cc:
- extend the handlerton with the info about cursor behaviour at commit.
sql/examples/ha_archive.h:
- ctor moved to .cc to make use of archive handlerton
sql/examples/ha_example.cc:
- add handlerton instance, init handler::ht with it
sql/examples/ha_example.h:
- ctor moved to .cc to make use of ha_example handlerton
sql/examples/ha_tina.cc:
- add handlerton instance, init handler::ht with it
sql/examples/ha_tina.h:
- ctor moved to .cc to make use of CSV handlerton
sql/ha_berkeley.cc:
- init handlerton::flags and handler::ht
sql/ha_berkeley.h:
- ctor moved to .cc to make use of BerkeleyDB handlerton
sql/ha_blackhole.cc:
- add handlerton instance, init handler::ht with it
sql/ha_blackhole.h:
- ctor moved to .cc to make use of blackhole handlerton
sql/ha_federated.cc:
- add handlerton instance, init handler::ht with it
sql/ha_federated.h:
- ctor moved to .cc to make use of federated handlerton
sql/ha_heap.cc:
- add handlerton instance, init handler::ht with it
sql/ha_heap.h:
- ctor moved to .cc to make use of ha_heap handlerton
sql/ha_innodb.cc:
- init handlerton::flags and handler::ht of innobase storage engine
sql/ha_innodb.h:
- ctor moved to .cc to make use of archive handlerton
sql/ha_myisam.cc:
- add handlerton instance, init handler::ht with it
sql/ha_myisam.h:
- ctor moved to .cc to make use of MyISAM handlerton
sql/ha_myisammrg.cc:
- init handler::ht in the ctor
sql/ha_myisammrg.h:
- ctor moved to .cc to make use of MyISAM MERGE handlerton
sql/ha_ndbcluster.cc:
- init handlerton::flags and handler::ht
sql/handler.cc:
- drop support for ISAM storage engine, which was removed from 5.0
- close all "transient" cursors at COMMIT/ROLLBACK. A "transient"
SQL level cursor is a cursor that uses tables that have a transaction-
specific state.
sql/handler.h:
- extend struct handlerton with flags, add handlerton *ht to every
handler instance.
sql/lock.cc:
- extend mysql_lock_tables to send error to the client if
thr_multi_lock returns a timeout or a deadlock error.
sql/mysqld.cc:
- add server option --table_lock_wait_timeout (in seconds)
sql/set_var.cc:
- add new global variable 'table_lock_wait_timeout' to specify
a wait timeout for table-level locks of MySQL (in seconds). The default
timeout is 50 seconds. The timeout is active only if the connection
has open cursors.
sql/sql_class.cc:
- implement Statement_map::close_transient_cursors
- safety suggests that we need an assert ensuring
llock_info->n_cursors is functioning properly, adjust destruction of
the Statement_map to allow such assert in THD::~THD
sql/sql_class.h:
- add support for Cursors registry to Statement map.
sql/sql_prepare.cc:
- maintain a list of cursors that must be closed at commit/rollback.
sql/sql_select.cc:
- extend class Cursor to support specific at-COMMIT/ROLLBACK behavior.
If a cursor uses tables of a storage engine that
invalidates all open tables at COMMIT/ROLLBACK, it must be closed
before COMMIT/ROLLBACK is executed.
sql/sql_select.h:
- add an own lock_id and commit/rollback status flag to class Cursor
tests/mysql_client_test.c:
A test case for Bug#10760 and complementary issues: test a simple
deadlock case too.
mysql-test/var:
New BitKeeper file ``mysql-test/var''
2005-07-19 20:21:12 +02:00
|
|
|
|
2005-09-19 21:06:23 +02:00
|
|
|
handlerton example_hton= {
|
2005-12-21 19:18:40 +01:00
|
|
|
MYSQL_HANDLERTON_INTERFACE_VERSION,
|
2005-10-03 04:44:28 +02:00
|
|
|
"EXAMPLE",
|
|
|
|
SHOW_OPTION_YES,
|
|
|
|
"Example storage engine",
|
|
|
|
DB_TYPE_EXAMPLE_DB,
|
2005-12-21 19:18:40 +01:00
|
|
|
(bool (*)()) example_init_func,
|
A fix and a test case for Bug#10760 and complementary cleanups.
The idea of the patch
is that every cursor gets its own lock id for table level locking.
Thus cursors are protected from updates performed within the same
connection. Additionally a list of transient (must be closed at
commit) cursors is maintained and all transient cursors are closed
when necessary. Lastly, this patch adds support for deadlock
timeouts to TLL locking when using cursors.
+ post-review fixes.
include/thr_lock.h:
- add a notion of lock owner to table level locking. When using
cursors, lock owner can not be identified by a thread id any more,
as we must protect cursors from updates issued within the same
connection (thread). So, each cursor has its own lock identifier to
use with table level locking.
- extend return values of thr_lock and thr_multi_lock with
THR_LOCK_TIMEOUT and THR_LOCK_DEADLOCK, since these conditions
are now possible (see comments to thr_lock.c)
mysys/thr_lock.c:
Better support for cursors:
- use THR_LOCK_OWNER * as lock identifier, not pthread_t.
- check and return an error for a trivial deadlock case, when an
update statement is issued to a table locked by a cursor which has
been previously opened in the same connection.
- add support for locking timeouts: with use of cursors, trivial
deadlocks can occur. For now the only remedy is the lock wait timeout,
which is initialized from a new global variable 'table_lock_wait_timeout'
Example of a deadlock (assuming the storage engine does not downgrade
locks):
con1: open cursor for select * from t1;
con2: open cursor for select * from t2;
con1: update t2 set id=id*2; -- blocked
con2: update t1 set id=id*2; -- deadlock
Lock timeouts are active only if a connection is using cursors.
- the check in the wait_for_lock loop has been changed from
data->cond != cond to data->cond != 0. data->cond is zeroed
in every place it's changed.
- added comments
sql/examples/ha_archive.cc:
- extend the handlerton with the info about cursor behaviour at commit.
sql/examples/ha_archive.h:
- ctor moved to .cc to make use of archive handlerton
sql/examples/ha_example.cc:
- add handlerton instance, init handler::ht with it
sql/examples/ha_example.h:
- ctor moved to .cc to make use of ha_example handlerton
sql/examples/ha_tina.cc:
- add handlerton instance, init handler::ht with it
sql/examples/ha_tina.h:
- ctor moved to .cc to make use of CSV handlerton
sql/ha_berkeley.cc:
- init handlerton::flags and handler::ht
sql/ha_berkeley.h:
- ctor moved to .cc to make use of BerkeleyDB handlerton
sql/ha_blackhole.cc:
- add handlerton instance, init handler::ht with it
sql/ha_blackhole.h:
- ctor moved to .cc to make use of blackhole handlerton
sql/ha_federated.cc:
- add handlerton instance, init handler::ht with it
sql/ha_federated.h:
- ctor moved to .cc to make use of federated handlerton
sql/ha_heap.cc:
- add handlerton instance, init handler::ht with it
sql/ha_heap.h:
- ctor moved to .cc to make use of ha_heap handlerton
sql/ha_innodb.cc:
- init handlerton::flags and handler::ht of innobase storage engine
sql/ha_innodb.h:
- ctor moved to .cc to make use of archive handlerton
sql/ha_myisam.cc:
- add handlerton instance, init handler::ht with it
sql/ha_myisam.h:
- ctor moved to .cc to make use of MyISAM handlerton
sql/ha_myisammrg.cc:
- init handler::ht in the ctor
sql/ha_myisammrg.h:
- ctor moved to .cc to make use of MyISAM MERGE handlerton
sql/ha_ndbcluster.cc:
- init handlerton::flags and handler::ht
sql/handler.cc:
- drop support for ISAM storage engine, which was removed from 5.0
- close all "transient" cursors at COMMIT/ROLLBACK. A "transient"
SQL level cursor is a cursor that uses tables that have a transaction-
specific state.
sql/handler.h:
- extend struct handlerton with flags, add handlerton *ht to every
handler instance.
sql/lock.cc:
- extend mysql_lock_tables to send error to the client if
thr_multi_lock returns a timeout or a deadlock error.
sql/mysqld.cc:
- add server option --table_lock_wait_timeout (in seconds)
sql/set_var.cc:
- add new global variable 'table_lock_wait_timeout' to specify
a wait timeout for table-level locks of MySQL (in seconds). The default
timeout is 50 seconds. The timeout is active only if the connection
has open cursors.
sql/sql_class.cc:
- implement Statement_map::close_transient_cursors
- safety suggests that we need an assert ensuring
llock_info->n_cursors is functioning properly, adjust destruction of
the Statement_map to allow such assert in THD::~THD
sql/sql_class.h:
- add support for Cursors registry to Statement map.
sql/sql_prepare.cc:
- maintain a list of cursors that must be closed at commit/rollback.
sql/sql_select.cc:
- extend class Cursor to support specific at-COMMIT/ROLLBACK behavior.
If a cursor uses tables of a storage engine that
invalidates all open tables at COMMIT/ROLLBACK, it must be closed
before COMMIT/ROLLBACK is executed.
sql/sql_select.h:
- add an own lock_id and commit/rollback status flag to class Cursor
tests/mysql_client_test.c:
A test case for Bug#10760 and complementary issues: test a simple
deadlock case too.
mysql-test/var:
New BitKeeper file ``mysql-test/var''
2005-07-19 20:21:12 +02:00
|
|
|
0, /* slot */
|
|
|
|
0, /* savepoint size. */
|
2005-07-20 18:02:36 +02:00
|
|
|
NULL, /* close_connection */
|
|
|
|
NULL, /* savepoint */
|
|
|
|
NULL, /* rollback to savepoint */
|
|
|
|
NULL, /* release savepoint */
|
|
|
|
NULL, /* commit */
|
|
|
|
NULL, /* rollback */
|
|
|
|
NULL, /* prepare */
|
|
|
|
NULL, /* recover */
|
|
|
|
NULL, /* commit_by_xid */
|
|
|
|
NULL, /* rollback_by_xid */
|
|
|
|
NULL, /* create_cursor_read_view */
|
|
|
|
NULL, /* set_cursor_read_view */
|
|
|
|
NULL, /* close_cursor_read_view */
|
2005-11-07 16:25:06 +01:00
|
|
|
example_create_handler, /* Create a new handler */
|
|
|
|
NULL, /* Drop a database */
|
|
|
|
NULL, /* Panic call */
|
|
|
|
NULL, /* Release temporary latches */
|
|
|
|
NULL, /* Update Statistics */
|
|
|
|
NULL, /* Start Consistent Snapshot */
|
|
|
|
NULL, /* Flush logs */
|
|
|
|
NULL, /* Show status */
|
|
|
|
NULL, /* Replication Report Sent Binlog */
|
2005-10-01 01:26:48 +02:00
|
|
|
HTON_CAN_RECREATE
|
A fix and a test case for Bug#10760 and complementary cleanups.
The idea of the patch
is that every cursor gets its own lock id for table level locking.
Thus cursors are protected from updates performed within the same
connection. Additionally a list of transient (must be closed at
commit) cursors is maintained and all transient cursors are closed
when necessary. Lastly, this patch adds support for deadlock
timeouts to TLL locking when using cursors.
+ post-review fixes.
include/thr_lock.h:
- add a notion of lock owner to table level locking. When using
cursors, lock owner can not be identified by a thread id any more,
as we must protect cursors from updates issued within the same
connection (thread). So, each cursor has its own lock identifier to
use with table level locking.
- extend return values of thr_lock and thr_multi_lock with
THR_LOCK_TIMEOUT and THR_LOCK_DEADLOCK, since these conditions
are now possible (see comments to thr_lock.c)
mysys/thr_lock.c:
Better support for cursors:
- use THR_LOCK_OWNER * as lock identifier, not pthread_t.
- check and return an error for a trivial deadlock case, when an
update statement is issued to a table locked by a cursor which has
been previously opened in the same connection.
- add support for locking timeouts: with use of cursors, trivial
deadlocks can occur. For now the only remedy is the lock wait timeout,
which is initialized from a new global variable 'table_lock_wait_timeout'
Example of a deadlock (assuming the storage engine does not downgrade
locks):
con1: open cursor for select * from t1;
con2: open cursor for select * from t2;
con1: update t2 set id=id*2; -- blocked
con2: update t1 set id=id*2; -- deadlock
Lock timeouts are active only if a connection is using cursors.
- the check in the wait_for_lock loop has been changed from
data->cond != cond to data->cond != 0. data->cond is zeroed
in every place it's changed.
- added comments
sql/examples/ha_archive.cc:
- extend the handlerton with the info about cursor behaviour at commit.
sql/examples/ha_archive.h:
- ctor moved to .cc to make use of archive handlerton
sql/examples/ha_example.cc:
- add handlerton instance, init handler::ht with it
sql/examples/ha_example.h:
- ctor moved to .cc to make use of ha_example handlerton
sql/examples/ha_tina.cc:
- add handlerton instance, init handler::ht with it
sql/examples/ha_tina.h:
- ctor moved to .cc to make use of CSV handlerton
sql/ha_berkeley.cc:
- init handlerton::flags and handler::ht
sql/ha_berkeley.h:
- ctor moved to .cc to make use of BerkeleyDB handlerton
sql/ha_blackhole.cc:
- add handlerton instance, init handler::ht with it
sql/ha_blackhole.h:
- ctor moved to .cc to make use of blackhole handlerton
sql/ha_federated.cc:
- add handlerton instance, init handler::ht with it
sql/ha_federated.h:
- ctor moved to .cc to make use of federated handlerton
sql/ha_heap.cc:
- add handlerton instance, init handler::ht with it
sql/ha_heap.h:
- ctor moved to .cc to make use of ha_heap handlerton
sql/ha_innodb.cc:
- init handlerton::flags and handler::ht of innobase storage engine
sql/ha_innodb.h:
- ctor moved to .cc to make use of archive handlerton
sql/ha_myisam.cc:
- add handlerton instance, init handler::ht with it
sql/ha_myisam.h:
- ctor moved to .cc to make use of MyISAM handlerton
sql/ha_myisammrg.cc:
- init handler::ht in the ctor
sql/ha_myisammrg.h:
- ctor moved to .cc to make use of MyISAM MERGE handlerton
sql/ha_ndbcluster.cc:
- init handlerton::flags and handler::ht
sql/handler.cc:
- drop support for ISAM storage engine, which was removed from 5.0
- close all "transient" cursors at COMMIT/ROLLBACK. A "transient"
SQL level cursor is a cursor that uses tables that have a transaction-
specific state.
sql/handler.h:
- extend struct handlerton with flags, add handlerton *ht to every
handler instance.
sql/lock.cc:
- extend mysql_lock_tables to send error to the client if
thr_multi_lock returns a timeout or a deadlock error.
sql/mysqld.cc:
- add server option --table_lock_wait_timeout (in seconds)
sql/set_var.cc:
- add new global variable 'table_lock_wait_timeout' to specify
a wait timeout for table-level locks of MySQL (in seconds). The default
timeout is 50 seconds. The timeout is active only if the connection
has open cursors.
sql/sql_class.cc:
- implement Statement_map::close_transient_cursors
- safety suggests that we need an assert ensuring
llock_info->n_cursors is functioning properly, adjust destruction of
the Statement_map to allow such assert in THD::~THD
sql/sql_class.h:
- add support for Cursors registry to Statement map.
sql/sql_prepare.cc:
- maintain a list of cursors that must be closed at commit/rollback.
sql/sql_select.cc:
- extend class Cursor to support specific at-COMMIT/ROLLBACK behavior.
If a cursor uses tables of a storage engine that
invalidates all open tables at COMMIT/ROLLBACK, it must be closed
before COMMIT/ROLLBACK is executed.
sql/sql_select.h:
- add an own lock_id and commit/rollback status flag to class Cursor
tests/mysql_client_test.c:
A test case for Bug#10760 and complementary issues: test a simple
deadlock case too.
mysql-test/var:
New BitKeeper file ``mysql-test/var''
2005-07-19 20:21:12 +02:00
|
|
|
};
|
|
|
|
|
2004-04-06 07:57:53 +02:00
|
|
|
/* Variables for example share methods */
|
2004-05-12 00:59:20 +02:00
|
|
|
static HASH example_open_tables; // Hash used to track open tables
|
|
|
|
pthread_mutex_t example_mutex; // This is the mutex we use to init the hash
|
|
|
|
static int example_init= 0; // Variable for checking the init state of hash
|
2004-04-01 11:02:42 +02:00
|
|
|
|
2004-05-12 00:59:20 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
Function we use in the creation of our hash to get key.
|
|
|
|
*/
|
2004-04-06 07:57:53 +02:00
|
|
|
static byte* example_get_key(EXAMPLE_SHARE *share,uint *length,
|
2004-04-01 11:02:42 +02:00
|
|
|
my_bool not_used __attribute__((unused)))
|
|
|
|
{
|
|
|
|
*length=share->table_name_length;
|
|
|
|
return (byte*) share->table_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-12-21 19:18:40 +01:00
|
|
|
static int example_init_func()
|
|
|
|
{
|
|
|
|
if (!example_init)
|
|
|
|
{
|
|
|
|
example_init++;
|
|
|
|
VOID(pthread_mutex_init(&example_mutex,MY_MUTEX_INIT_FAST));
|
|
|
|
(void) hash_init(&example_open_tables,system_charset_info,32,0,0,
|
|
|
|
(hash_get_key) example_get_key,0,0);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int example_done_func()
|
|
|
|
{
|
|
|
|
if (example_init)
|
|
|
|
{
|
|
|
|
if (example_open_tables.records)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
hash_free(&example_open_tables);
|
|
|
|
pthread_mutex_destroy(&example_mutex);
|
|
|
|
example_init--;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-04-01 11:02:42 +02:00
|
|
|
/*
|
2004-05-12 00:59:20 +02:00
|
|
|
Example of simple lock controls. The "share" it creates is structure we will
|
|
|
|
pass to each example handler. Do you have to have one of these? Well, you have
|
2004-06-23 21:26:34 +02:00
|
|
|
pieces that are used for locking, and they are needed to function.
|
2004-04-01 11:02:42 +02:00
|
|
|
*/
|
2004-04-06 07:57:53 +02:00
|
|
|
static EXAMPLE_SHARE *get_share(const char *table_name, TABLE *table)
|
2004-04-01 11:02:42 +02:00
|
|
|
{
|
2004-04-06 07:57:53 +02:00
|
|
|
EXAMPLE_SHARE *share;
|
2004-04-01 11:02:42 +02:00
|
|
|
uint length;
|
|
|
|
char *tmp_name;
|
|
|
|
|
|
|
|
pthread_mutex_lock(&example_mutex);
|
|
|
|
length=(uint) strlen(table_name);
|
|
|
|
|
2004-04-06 07:57:53 +02:00
|
|
|
if (!(share=(EXAMPLE_SHARE*) hash_search(&example_open_tables,
|
2004-04-01 11:02:42 +02:00
|
|
|
(byte*) table_name,
|
2004-04-13 06:01:45 +02:00
|
|
|
length)))
|
|
|
|
{
|
2004-04-06 07:57:53 +02:00
|
|
|
if (!(share=(EXAMPLE_SHARE *)
|
2004-04-01 11:02:42 +02:00
|
|
|
my_multi_malloc(MYF(MY_WME | MY_ZEROFILL),
|
|
|
|
&share, sizeof(*share),
|
|
|
|
&tmp_name, length+1,
|
2004-06-23 21:26:34 +02:00
|
|
|
NullS)))
|
2004-04-01 11:02:42 +02:00
|
|
|
{
|
|
|
|
pthread_mutex_unlock(&example_mutex);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
share->use_count=0;
|
|
|
|
share->table_name_length=length;
|
|
|
|
share->table_name=tmp_name;
|
|
|
|
strmov(share->table_name,table_name);
|
|
|
|
if (my_hash_insert(&example_open_tables, (byte*) share))
|
|
|
|
goto error;
|
|
|
|
thr_lock_init(&share->lock);
|
|
|
|
pthread_mutex_init(&share->mutex,MY_MUTEX_INIT_FAST);
|
|
|
|
}
|
|
|
|
share->use_count++;
|
|
|
|
pthread_mutex_unlock(&example_mutex);
|
|
|
|
|
|
|
|
return share;
|
|
|
|
|
|
|
|
error:
|
2005-06-02 02:34:10 +02:00
|
|
|
pthread_mutex_destroy(&share->mutex);
|
2004-04-01 11:02:42 +02:00
|
|
|
my_free((gptr) share, MYF(0));
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-06-23 21:26:34 +02:00
|
|
|
/*
|
2004-05-12 00:59:20 +02:00
|
|
|
Free lock controls. We call this whenever we close a table. If the table had
|
|
|
|
the last reference to the share then we free memory associated with it.
|
2004-04-01 11:02:42 +02:00
|
|
|
*/
|
2004-04-06 07:57:53 +02:00
|
|
|
static int free_share(EXAMPLE_SHARE *share)
|
2004-04-01 11:02:42 +02:00
|
|
|
{
|
|
|
|
pthread_mutex_lock(&example_mutex);
|
2004-04-06 07:57:53 +02:00
|
|
|
if (!--share->use_count)
|
|
|
|
{
|
2004-04-01 11:02:42 +02:00
|
|
|
hash_delete(&example_open_tables, (byte*) share);
|
|
|
|
thr_lock_delete(&share->lock);
|
|
|
|
pthread_mutex_destroy(&share->mutex);
|
|
|
|
my_free((gptr) share, MYF(0));
|
|
|
|
}
|
|
|
|
pthread_mutex_unlock(&example_mutex);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-25 10:35:26 +01:00
|
|
|
static handler* example_create_handler(TABLE_SHARE *table)
|
2005-11-07 16:25:06 +01:00
|
|
|
{
|
|
|
|
return new ha_example(table);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Table definition cache, part 2
The table opening process now works the following way:
- Create common TABLE_SHARE object
- Read the .frm file and unpack it into the TABLE_SHARE object
- Create a TABLE object based on the information in the TABLE_SHARE
object and open a handler to the table object
Other noteworthy changes:
- In TABLE_SHARE the most common strings are now LEX_STRING's
- Better error message when table is not found
- Variable table_cache is now renamed 'table_open_cache'
- New variable 'table_definition_cache' that is the number of table defintions that will be cached
- strxnmov() calls are now fixed to avoid overflows
- strxnmov() will now always add one end \0 to result
- engine objects are now created with a TABLE_SHARE object instead of a TABLE object.
- After creating a field object one must call field->init(table) before using it
- For a busy system this change will give you:
- Less memory usage for table object
- Faster opening of tables (if it's has been in use or is in table definition cache)
- Allow you to cache many table definitions objects
- Faster drop of table
mysql-test/mysql-test-run.sh:
Fixed some problems with --gdb option
Test both with socket and tcp/ip port that all old servers are killed
mysql-test/r/flush_table.result:
More tests with lock table with 2 threads + flush table
mysql-test/r/information_schema.result:
Removed old (now wrong) result
mysql-test/r/innodb.result:
Better error messages (thanks to TDC patch)
mysql-test/r/merge.result:
Extra flush table test
mysql-test/r/ndb_bitfield.result:
Better error messages (thanks to TDC patch)
mysql-test/r/ndb_partition_error.result:
Better error messages (thanks to TDC patch)
mysql-test/r/query_cache.result:
Remove tables left from old tests
mysql-test/r/temp_table.result:
Test truncate with temporary tables
mysql-test/r/variables.result:
Table_cache -> Table_open_cache
mysql-test/t/flush_table.test:
More tests with lock table with 2 threads + flush table
mysql-test/t/merge.test:
Extra flush table test
mysql-test/t/multi_update.test:
Added 'sleep' to make test predictable
mysql-test/t/query_cache.test:
Remove tables left from old tests
mysql-test/t/temp_table.test:
Test truncate with temporary tables
mysql-test/t/variables.test:
Table_cache -> Table_open_cache
mysql-test/valgrind.supp:
Remove warning that may happens becasue threads dies in different order
mysys/hash.c:
Fixed wrong DBUG_PRINT
mysys/mf_dirname.c:
More DBUG
mysys/mf_pack.c:
Better comment
mysys/mf_tempdir.c:
More DBUG
Ensure that we call cleanup_dirname() on all temporary directory paths.
If we don't do this, we will get a failure when comparing temporary table
names as in some cases the temporary table name is run through convert_dirname())
mysys/my_alloc.c:
Indentation fix
sql/examples/ha_example.cc:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/examples/ha_example.h:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/examples/ha_tina.cc:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/examples/ha_tina.h:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/field.cc:
Update for table definition cache:
- Field creation now takes TABLE_SHARE instead of TABLE as argument
(This is becasue field definitions are now cached in TABLE_SHARE)
When a field is created, one now must call field->init(TABLE) before using it
- Use s->db instead of s->table_cache_key
- Added Field::clone() to create a field in TABLE from a field in TABLE_SHARE
- make_field() takes TABLE_SHARE as argument instead of TABLE
- move_field() -> move_field_offset()
sql/field.h:
Update for table definition cache:
- Field creation now takes TABLE_SHARE instead of TABLE as argument
(This is becasue field definitions are now cached in TABLE_SHARE)
When a field is created, one now must call field->init(TABLE) before using it
- Added Field::clone() to create a field in TABLE from a field in TABLE_SHARE
- make_field() takes TABLE_SHARE as argument instead of TABLE
- move_field() -> move_field_offset()
sql/ha_archive.cc:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/ha_archive.h:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/ha_berkeley.cc:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
Changed name of argument create() to not hide internal 'table' variable.
table->s -> table_share
sql/ha_berkeley.h:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/ha_blackhole.cc:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/ha_blackhole.h:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/ha_federated.cc:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
Fixed comments
Remove index variable and replace with pointers (simple optimization)
move_field() -> move_field_offset()
Removed some strlen() calls
sql/ha_federated.h:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/ha_heap.cc:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
Simplify delete_table() and create() as the given file names are now without extension
sql/ha_heap.h:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/ha_innodb.cc:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/ha_innodb.h:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/ha_myisam.cc:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
Remove not needed fn_format()
Fixed for new table->s structure
sql/ha_myisam.h:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/ha_myisammrg.cc:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
Don't set 'is_view' for MERGE tables
Use new interface to find_temporary_table()
sql/ha_myisammrg.h:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
Added flag HA_NO_COPY_ON_ALTER
sql/ha_ndbcluster.cc:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
Fixed wrong calls to strxnmov()
Give error HA_ERR_TABLE_DEF_CHANGED if table definition has changed
drop_table -> intern_drop_table()
table->s -> table_share
Move part_info to TABLE
Fixed comments & DBUG print's
New arguments to print_error()
sql/ha_ndbcluster.h:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/ha_partition.cc:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
We can't set up or use part_info when creating handler as there is not yet any table object
New ha_intialise() to work with TDC (Done by Mikael)
sql/ha_partition.h:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
Got set_part_info() from Mikael
sql/handler.cc:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
ha_delete_table() now also takes database as an argument
handler::ha_open() now takes TABLE as argument
ha_open() now calls ha_allocate_read_write_set()
Simplify ha_allocate_read_write_set()
Remove ha_deallocate_read_write_set()
Use table_share (Cached by table definition cache)
sql/handler.h:
New table flag: HA_NO_COPY_ON_ALTER (used by merge tables)
Remove ha_deallocate_read_write_set()
get_new_handler() now takes TABLE_SHARE as argument
ha_delete_table() now gets database as argument
sql/item.cc:
table_name and db are now LEX_STRING objects
When creating fields, we have now have to call field->init(table)
move_field -> move_field_offset()
sql/item.h:
tmp_table_field_from_field_type() now takes an extra paramenter 'fixed_length' to allow one to force usage of CHAR
instead of BLOB
sql/item_cmpfunc.cc:
Fixed call to tmp_table_field_from_field_type()
sql/item_create.cc:
Assert if new not handled cast type
sql/item_func.cc:
When creating fields, we have now have to call field->init(table)
dummy_table used by 'sp' now needs a TABLE_SHARE object
sql/item_subselect.cc:
Trivial code cleanups
sql/item_sum.cc:
When creating fields, we have now have to call field->init(table)
sql/item_timefunc.cc:
Item_func_str_to_date::tmp_table_field() now replaced by call to
tmp_table_field_from_field_type() (see item_timefunc.h)
sql/item_timefunc.h:
Simply tmp_table_field()
sql/item_uniq.cc:
When creating fields, we have now have to call field->init(table)
sql/key.cc:
Added 'KEY' argument to 'find_ref_key' to simplify code
sql/lock.cc:
More debugging
Use create_table_def_key() to create key for table cache
Allocate TABLE_SHARE properly when creating name lock
Fix that locked_table_name doesn't test same table twice
sql/mysql_priv.h:
New functions for table definition cache
New interfaces to a lot of functions.
New faster interface to find_temporary_table() and close_temporary_table()
sql/mysqld.cc:
Added support for table definition cache of size 'table_def_size'
Fixed som calls to strnmov()
Changed name of 'table_cache' to 'table_open_cache'
sql/opt_range.cc:
Use new interfaces
Fixed warnings from valgrind
sql/parse_file.cc:
Safer calls to strxnmov()
Fixed typo
sql/set_var.cc:
Added variable 'table_definition_cache'
Variable table_cache renamed to 'table_open_cache'
sql/slave.cc:
Use new interface
sql/sp.cc:
Proper use of TABLE_SHARE
sql/sp_head.cc:
Remove compiler warnings
We have now to call field->init(table)
sql/sp_head.h:
Pointers to parsed strings are now const
sql/sql_acl.cc:
table_name is now a LEX_STRING
sql/sql_base.cc:
Main implementation of table definition cache
(The #ifdef's are there for the future when table definition cache will replace open table cache)
Now table definitions are cached indepndent of open tables, which will speed up things when a table is in use at once from several places
Views are not yet cached; For the moment we only cache if a table is a view or not.
Faster implementation of find_temorary_table()
Replace 'wait_for_refresh()' with the more general function 'wait_for_condition()'
Drop table is slightly faster as we can use the table definition cache to know the type of the table
sql/sql_cache.cc:
table_cache_key and table_name are now LEX_STRING
'sDBUG print fixes
sql/sql_class.cc:
table_cache_key is now a LEX_STRING
safer strxnmov()
sql/sql_class.h:
Added number of open table shares (table definitions)
sql/sql_db.cc:
safer strxnmov()
sql/sql_delete.cc:
Use new interface to find_temporary_table()
sql/sql_derived.cc:
table_name is now a LEX_STRING
sql/sql_handler.cc:
TABLE_SHARE->db and TABLE_SHARE->table_name are now LEX_STRING's
sql/sql_insert.cc:
TABLE_SHARE->db and TABLE_SHARE->table_name are now LEX_STRING's
sql/sql_lex.cc:
Make parsed string a const (to quickly find out if anything is trying to change the query string)
sql/sql_lex.h:
Make parsed string a const (to quickly find out if anything is trying to change the query string)
sql/sql_load.cc:
Safer strxnmov()
sql/sql_parse.cc:
Better error if wrong DB name
sql/sql_partition.cc:
part_info moved to TABLE from TABLE_SHARE
Indentation changes
sql/sql_select.cc:
Indentation fixes
Call field->init(TABLE) for new created fields
Update create_tmp_table() to use TABLE_SHARE properly
sql/sql_select.h:
Call field->init(TABLE) for new created fields
sql/sql_show.cc:
table_name is now a LEX_STRING
part_info moved to TABLE
sql/sql_table.cc:
Use table definition cache to speed up delete of tables
Fixed calls to functions with new interfaces
Don't use 'share_not_to_be_used'
Instead of doing openfrm() when doing repair, we now have to call
get_table_share() followed by open_table_from_share().
Replace some fn_format() with faster unpack_filename().
Safer strxnmov()
part_info is now in TABLE
Added Mikaels patch for partition and ALTER TABLE
Instead of using 'TABLE_SHARE->is_view' use 'table_flags() & HA_NO_COPY_ON_ALTER
sql/sql_test.cc:
table_name and table_cache_key are now LEX_STRING's
sql/sql_trigger.cc:
TABLE_SHARE->db and TABLE_SHARE->table_name are now LEX_STRING's
safer strxnmov()
Removed compiler warnings
sql/sql_update.cc:
Call field->init(TABLE) after field is created
sql/sql_view.cc:
safer strxnmov()
Create common TABLE_SHARE object for views to allow us to cache if table is a view
sql/structs.h:
Added SHOW_TABLE_DEFINITIONS
sql/table.cc:
Creation and destruct of TABLE_SHARE objects that are common for many TABLE objects
The table opening process now works the following way:
- Create common TABLE_SHARE object
- Read the .frm file and unpack it into the TABLE_SHARE object
- Create a TABLE object based on the information in the TABLE_SHARE
object and open a handler to the table object
open_table_def() is written in such a way that it should be trival to add parsing of the .frm files in new formats
sql/table.h:
TABLE objects for the same database table now share a common TABLE_SHARE object
In TABLE_SHARE the most common strings are now LEX_STRING's
sql/unireg.cc:
Changed arguments to rea_create_table() to have same order as other functions
Call field->init(table) for new created fields
sql/unireg.h:
Added OPEN_VIEW
strings/strxnmov.c:
Change strxnmov() to always add end \0
This makes usage of strxnmov() safer as most of MySQL code assumes that strxnmov() will create a null terminated string
2005-11-23 21:45:02 +01:00
|
|
|
ha_example::ha_example(TABLE_SHARE *table_arg)
|
A fix and a test case for Bug#10760 and complementary cleanups.
The idea of the patch
is that every cursor gets its own lock id for table level locking.
Thus cursors are protected from updates performed within the same
connection. Additionally a list of transient (must be closed at
commit) cursors is maintained and all transient cursors are closed
when necessary. Lastly, this patch adds support for deadlock
timeouts to TLL locking when using cursors.
+ post-review fixes.
include/thr_lock.h:
- add a notion of lock owner to table level locking. When using
cursors, lock owner can not be identified by a thread id any more,
as we must protect cursors from updates issued within the same
connection (thread). So, each cursor has its own lock identifier to
use with table level locking.
- extend return values of thr_lock and thr_multi_lock with
THR_LOCK_TIMEOUT and THR_LOCK_DEADLOCK, since these conditions
are now possible (see comments to thr_lock.c)
mysys/thr_lock.c:
Better support for cursors:
- use THR_LOCK_OWNER * as lock identifier, not pthread_t.
- check and return an error for a trivial deadlock case, when an
update statement is issued to a table locked by a cursor which has
been previously opened in the same connection.
- add support for locking timeouts: with use of cursors, trivial
deadlocks can occur. For now the only remedy is the lock wait timeout,
which is initialized from a new global variable 'table_lock_wait_timeout'
Example of a deadlock (assuming the storage engine does not downgrade
locks):
con1: open cursor for select * from t1;
con2: open cursor for select * from t2;
con1: update t2 set id=id*2; -- blocked
con2: update t1 set id=id*2; -- deadlock
Lock timeouts are active only if a connection is using cursors.
- the check in the wait_for_lock loop has been changed from
data->cond != cond to data->cond != 0. data->cond is zeroed
in every place it's changed.
- added comments
sql/examples/ha_archive.cc:
- extend the handlerton with the info about cursor behaviour at commit.
sql/examples/ha_archive.h:
- ctor moved to .cc to make use of archive handlerton
sql/examples/ha_example.cc:
- add handlerton instance, init handler::ht with it
sql/examples/ha_example.h:
- ctor moved to .cc to make use of ha_example handlerton
sql/examples/ha_tina.cc:
- add handlerton instance, init handler::ht with it
sql/examples/ha_tina.h:
- ctor moved to .cc to make use of CSV handlerton
sql/ha_berkeley.cc:
- init handlerton::flags and handler::ht
sql/ha_berkeley.h:
- ctor moved to .cc to make use of BerkeleyDB handlerton
sql/ha_blackhole.cc:
- add handlerton instance, init handler::ht with it
sql/ha_blackhole.h:
- ctor moved to .cc to make use of blackhole handlerton
sql/ha_federated.cc:
- add handlerton instance, init handler::ht with it
sql/ha_federated.h:
- ctor moved to .cc to make use of federated handlerton
sql/ha_heap.cc:
- add handlerton instance, init handler::ht with it
sql/ha_heap.h:
- ctor moved to .cc to make use of ha_heap handlerton
sql/ha_innodb.cc:
- init handlerton::flags and handler::ht of innobase storage engine
sql/ha_innodb.h:
- ctor moved to .cc to make use of archive handlerton
sql/ha_myisam.cc:
- add handlerton instance, init handler::ht with it
sql/ha_myisam.h:
- ctor moved to .cc to make use of MyISAM handlerton
sql/ha_myisammrg.cc:
- init handler::ht in the ctor
sql/ha_myisammrg.h:
- ctor moved to .cc to make use of MyISAM MERGE handlerton
sql/ha_ndbcluster.cc:
- init handlerton::flags and handler::ht
sql/handler.cc:
- drop support for ISAM storage engine, which was removed from 5.0
- close all "transient" cursors at COMMIT/ROLLBACK. A "transient"
SQL level cursor is a cursor that uses tables that have a transaction-
specific state.
sql/handler.h:
- extend struct handlerton with flags, add handlerton *ht to every
handler instance.
sql/lock.cc:
- extend mysql_lock_tables to send error to the client if
thr_multi_lock returns a timeout or a deadlock error.
sql/mysqld.cc:
- add server option --table_lock_wait_timeout (in seconds)
sql/set_var.cc:
- add new global variable 'table_lock_wait_timeout' to specify
a wait timeout for table-level locks of MySQL (in seconds). The default
timeout is 50 seconds. The timeout is active only if the connection
has open cursors.
sql/sql_class.cc:
- implement Statement_map::close_transient_cursors
- safety suggests that we need an assert ensuring
llock_info->n_cursors is functioning properly, adjust destruction of
the Statement_map to allow such assert in THD::~THD
sql/sql_class.h:
- add support for Cursors registry to Statement map.
sql/sql_prepare.cc:
- maintain a list of cursors that must be closed at commit/rollback.
sql/sql_select.cc:
- extend class Cursor to support specific at-COMMIT/ROLLBACK behavior.
If a cursor uses tables of a storage engine that
invalidates all open tables at COMMIT/ROLLBACK, it must be closed
before COMMIT/ROLLBACK is executed.
sql/sql_select.h:
- add an own lock_id and commit/rollback status flag to class Cursor
tests/mysql_client_test.c:
A test case for Bug#10760 and complementary issues: test a simple
deadlock case too.
mysql-test/var:
New BitKeeper file ``mysql-test/var''
2005-07-19 20:21:12 +02:00
|
|
|
:handler(&example_hton, table_arg)
|
|
|
|
{}
|
|
|
|
|
2004-05-12 00:59:20 +02:00
|
|
|
/*
|
2004-06-23 21:26:34 +02:00
|
|
|
If frm_error() is called then we will use this to to find out what file extentions
|
2004-05-12 00:59:20 +02:00
|
|
|
exist for the storage engine. This is also used by the default rename_table and
|
|
|
|
delete_table method in handler.cc.
|
|
|
|
*/
|
2005-04-27 11:25:08 +02:00
|
|
|
static const char *ha_example_exts[] = {
|
|
|
|
NullS
|
|
|
|
};
|
|
|
|
|
2004-04-01 11:02:42 +02:00
|
|
|
const char **ha_example::bas_ext() const
|
2005-04-27 11:25:08 +02:00
|
|
|
{
|
|
|
|
return ha_example_exts;
|
|
|
|
}
|
2004-04-01 11:02:42 +02:00
|
|
|
|
|
|
|
|
2004-06-23 21:26:34 +02:00
|
|
|
/*
|
2004-05-12 00:59:20 +02:00
|
|
|
Used for opening tables. The name will be the name of the file.
|
|
|
|
A table is opened when it needs to be opened. For instance
|
2004-06-23 21:26:34 +02:00
|
|
|
when a request comes in for a select on the table (tables are not
|
2004-05-12 00:59:20 +02:00
|
|
|
open and closed for each request, they are cached).
|
|
|
|
|
|
|
|
Called from handler.cc by handler::ha_open(). The server opens all tables by
|
|
|
|
calling ha_open() which then calls the handler specific open().
|
|
|
|
*/
|
2004-04-01 11:02:42 +02:00
|
|
|
int ha_example::open(const char *name, int mode, uint test_if_locked)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_example::open");
|
|
|
|
|
|
|
|
if (!(share = get_share(name, table)))
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
thr_lock_data_init(&share->lock,&lock,NULL);
|
|
|
|
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
2004-05-12 00:59:20 +02:00
|
|
|
|
|
|
|
/*
|
2004-06-23 21:26:34 +02:00
|
|
|
Closes a table. We call the free_share() function to free any resources
|
2004-05-12 00:59:20 +02:00
|
|
|
that we have allocated in the "shared" structure.
|
|
|
|
|
|
|
|
Called from sql_base.cc, sql_select.cc, and table.cc.
|
|
|
|
In sql_select.cc it is only used to close up temporary tables or during
|
2004-06-23 21:26:34 +02:00
|
|
|
the process where a temporary table is converted over to being a
|
2004-05-12 00:59:20 +02:00
|
|
|
myisam table.
|
|
|
|
For sql_base.cc look at close_data_tables().
|
|
|
|
*/
|
2004-04-01 11:02:42 +02:00
|
|
|
int ha_example::close(void)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_example::close");
|
|
|
|
DBUG_RETURN(free_share(share));
|
|
|
|
}
|
|
|
|
|
2004-05-12 00:59:20 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
write_row() inserts a row. No extra() hint is given currently if a bulk load
|
2004-06-23 21:26:34 +02:00
|
|
|
is happeneding. buf() is a byte array of data. You can use the field
|
2004-05-12 00:59:20 +02:00
|
|
|
information to extract the data from the native byte array type.
|
|
|
|
Example of this would be:
|
|
|
|
for (Field **field=table->field ; *field ; field++)
|
|
|
|
{
|
|
|
|
...
|
|
|
|
}
|
|
|
|
|
2004-06-23 21:26:34 +02:00
|
|
|
See ha_tina.cc for an example of extracting all of the data as strings.
|
2004-05-12 00:59:20 +02:00
|
|
|
ha_berekly.cc has an example of how to store it intact by "packing" it
|
|
|
|
for ha_berkeley's own native storage type.
|
|
|
|
|
|
|
|
See the note for update_row() on auto_increments and timestamps. This
|
|
|
|
case also applied to write_row().
|
|
|
|
|
2004-06-23 21:26:34 +02:00
|
|
|
Called from item_sum.cc, item_sum.cc, sql_acl.cc, sql_insert.cc,
|
2004-05-12 00:59:20 +02:00
|
|
|
sql_insert.cc, sql_select.cc, sql_table.cc, sql_udf.cc, and sql_update.cc.
|
|
|
|
*/
|
2004-04-01 11:02:42 +02:00
|
|
|
int ha_example::write_row(byte * buf)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_example::write_row");
|
2004-06-23 21:26:34 +02:00
|
|
|
DBUG_RETURN(HA_ERR_WRONG_COMMAND);
|
2004-04-01 11:02:42 +02:00
|
|
|
}
|
|
|
|
|
2004-05-12 00:59:20 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
Yes, update_row() does what you expect, it updates a row. old_data will have
|
|
|
|
the previous row record in it, while new_data will have the newest data in
|
|
|
|
it.
|
|
|
|
Keep in mind that the server can do updates based on ordering if an ORDER BY
|
|
|
|
clause was used. Consecutive ordering is not guarenteed.
|
|
|
|
Currently new_data will not have an updated auto_increament record, or
|
|
|
|
and updated timestamp field. You can do these for example by doing these:
|
2004-10-18 08:32:52 +02:00
|
|
|
if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_UPDATE)
|
|
|
|
table->timestamp_field->set_time();
|
2004-05-12 00:59:20 +02:00
|
|
|
if (table->next_number_field && record == table->record[0])
|
|
|
|
update_auto_increment();
|
|
|
|
|
|
|
|
Called from sql_select.cc, sql_acl.cc, sql_update.cc, and sql_insert.cc.
|
|
|
|
*/
|
2004-04-01 11:02:42 +02:00
|
|
|
int ha_example::update_row(const byte * old_data, byte * new_data)
|
|
|
|
{
|
|
|
|
|
|
|
|
DBUG_ENTER("ha_example::update_row");
|
2004-06-23 21:26:34 +02:00
|
|
|
DBUG_RETURN(HA_ERR_WRONG_COMMAND);
|
2004-04-01 11:02:42 +02:00
|
|
|
}
|
|
|
|
|
2004-05-12 00:59:20 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
This will delete a row. buf will contain a copy of the row to be deleted.
|
|
|
|
The server will call this right after the current row has been called (from
|
|
|
|
either a previous rnd_nexT() or index call).
|
2004-06-23 21:26:34 +02:00
|
|
|
If you keep a pointer to the last row or can access a primary key it will
|
|
|
|
make doing the deletion quite a bit easier.
|
2004-05-12 00:59:20 +02:00
|
|
|
Keep in mind that the server does no guarentee consecutive deletions. ORDER BY
|
|
|
|
clauses can be used.
|
|
|
|
|
|
|
|
Called in sql_acl.cc and sql_udf.cc to manage internal table information.
|
|
|
|
Called in sql_delete.cc, sql_insert.cc, and sql_select.cc. In sql_select it is
|
|
|
|
used for removing duplicates while in insert it is used for REPLACE calls.
|
|
|
|
*/
|
2004-04-01 11:02:42 +02:00
|
|
|
int ha_example::delete_row(const byte * buf)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_example::delete_row");
|
2004-06-23 21:26:34 +02:00
|
|
|
DBUG_RETURN(HA_ERR_WRONG_COMMAND);
|
2004-04-01 11:02:42 +02:00
|
|
|
}
|
|
|
|
|
2004-05-12 00:59:20 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
Positions an index cursor to the index specified in the handle. Fetches the
|
|
|
|
row if available. If the key value is null, begin at the first key of the
|
|
|
|
index.
|
|
|
|
*/
|
2004-04-01 11:02:42 +02:00
|
|
|
int ha_example::index_read(byte * buf, const byte * key,
|
|
|
|
uint key_len __attribute__((unused)),
|
|
|
|
enum ha_rkey_function find_flag
|
|
|
|
__attribute__((unused)))
|
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_example::index_read");
|
2004-06-23 21:26:34 +02:00
|
|
|
DBUG_RETURN(HA_ERR_WRONG_COMMAND);
|
2004-04-01 11:02:42 +02:00
|
|
|
}
|
|
|
|
|
2004-05-12 00:59:20 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
Positions an index cursor to the index specified in key. Fetches the
|
|
|
|
row if any. This is only used to read whole keys.
|
|
|
|
*/
|
2004-04-01 11:02:42 +02:00
|
|
|
int ha_example::index_read_idx(byte * buf, uint index, const byte * key,
|
|
|
|
uint key_len __attribute__((unused)),
|
|
|
|
enum ha_rkey_function find_flag
|
|
|
|
__attribute__((unused)))
|
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_example::index_read_idx");
|
2004-06-23 21:26:34 +02:00
|
|
|
DBUG_RETURN(HA_ERR_WRONG_COMMAND);
|
2004-04-01 11:02:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-05-12 00:59:20 +02:00
|
|
|
/*
|
|
|
|
Used to read forward through the index.
|
|
|
|
*/
|
2004-04-01 11:02:42 +02:00
|
|
|
int ha_example::index_next(byte * buf)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_example::index_next");
|
2004-06-23 21:26:34 +02:00
|
|
|
DBUG_RETURN(HA_ERR_WRONG_COMMAND);
|
2004-04-01 11:02:42 +02:00
|
|
|
}
|
|
|
|
|
2004-05-12 00:59:20 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
Used to read backwards through the index.
|
|
|
|
*/
|
2004-04-01 11:02:42 +02:00
|
|
|
int ha_example::index_prev(byte * buf)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_example::index_prev");
|
2004-06-23 21:26:34 +02:00
|
|
|
DBUG_RETURN(HA_ERR_WRONG_COMMAND);
|
2004-04-01 11:02:42 +02:00
|
|
|
}
|
|
|
|
|
2004-05-12 00:59:20 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
index_first() asks for the first key in the index.
|
|
|
|
|
2004-06-23 21:26:34 +02:00
|
|
|
Called from opt_range.cc, opt_sum.cc, sql_handler.cc,
|
2004-05-12 00:59:20 +02:00
|
|
|
and sql_select.cc.
|
|
|
|
*/
|
2004-04-01 11:02:42 +02:00
|
|
|
int ha_example::index_first(byte * buf)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_example::index_first");
|
2004-06-23 21:26:34 +02:00
|
|
|
DBUG_RETURN(HA_ERR_WRONG_COMMAND);
|
2004-04-01 11:02:42 +02:00
|
|
|
}
|
|
|
|
|
2004-05-12 00:59:20 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
index_last() asks for the last key in the index.
|
|
|
|
|
2004-06-23 21:26:34 +02:00
|
|
|
Called from opt_range.cc, opt_sum.cc, sql_handler.cc,
|
2004-05-12 00:59:20 +02:00
|
|
|
and sql_select.cc.
|
|
|
|
*/
|
2004-04-01 11:02:42 +02:00
|
|
|
int ha_example::index_last(byte * buf)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_example::index_last");
|
2004-06-23 21:26:34 +02:00
|
|
|
DBUG_RETURN(HA_ERR_WRONG_COMMAND);
|
2004-04-01 11:02:42 +02:00
|
|
|
}
|
|
|
|
|
2004-05-12 00:59:20 +02:00
|
|
|
|
2004-06-23 21:26:34 +02:00
|
|
|
/*
|
2004-05-12 00:59:20 +02:00
|
|
|
rnd_init() is called when the system wants the storage engine to do a table
|
2004-06-23 21:26:34 +02:00
|
|
|
scan.
|
|
|
|
See the example in the introduction at the top of this file to see when
|
2004-05-12 00:59:20 +02:00
|
|
|
rnd_init() is called.
|
|
|
|
|
|
|
|
Called from filesort.cc, records.cc, sql_handler.cc, sql_select.cc, sql_table.cc,
|
|
|
|
and sql_update.cc.
|
|
|
|
*/
|
2004-04-01 11:02:42 +02:00
|
|
|
int ha_example::rnd_init(bool scan)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_example::rnd_init");
|
2004-06-23 21:26:34 +02:00
|
|
|
DBUG_RETURN(HA_ERR_WRONG_COMMAND);
|
2004-04-01 11:02:42 +02:00
|
|
|
}
|
|
|
|
|
2004-06-23 21:26:34 +02:00
|
|
|
int ha_example::rnd_end()
|
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_example::rnd_end");
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
2004-05-12 00:59:20 +02:00
|
|
|
|
2004-06-23 21:26:34 +02:00
|
|
|
/*
|
2004-05-12 00:59:20 +02:00
|
|
|
This is called for each row of the table scan. When you run out of records
|
|
|
|
you should return HA_ERR_END_OF_FILE. Fill buff up with the row information.
|
|
|
|
The Field structure for the table is the key to getting data into buf
|
|
|
|
in a manner that will allow the server to understand it.
|
|
|
|
|
|
|
|
Called from filesort.cc, records.cc, sql_handler.cc, sql_select.cc, sql_table.cc,
|
|
|
|
and sql_update.cc.
|
|
|
|
*/
|
2004-04-01 11:02:42 +02:00
|
|
|
int ha_example::rnd_next(byte *buf)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_example::rnd_next");
|
|
|
|
DBUG_RETURN(HA_ERR_END_OF_FILE);
|
|
|
|
}
|
|
|
|
|
2004-05-12 00:59:20 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
position() is called after each call to rnd_next() if the data needs
|
|
|
|
to be ordered. You can do something like the following to store
|
|
|
|
the position:
|
2005-02-20 20:52:28 +01:00
|
|
|
my_store_ptr(ref, ref_length, current_position);
|
2004-05-12 00:59:20 +02:00
|
|
|
|
|
|
|
The server uses ref to store data. ref_length in the above case is
|
|
|
|
the size needed to store current_position. ref is just a byte array
|
|
|
|
that the server will maintain. If you are using offsets to mark rows, then
|
|
|
|
current_position should be the offset. If it is a primary key like in
|
2004-06-23 21:26:34 +02:00
|
|
|
BDB, then it needs to be a primary key.
|
|
|
|
|
2004-05-12 00:59:20 +02:00
|
|
|
Called from filesort.cc, sql_select.cc, sql_delete.cc and sql_update.cc.
|
|
|
|
*/
|
2004-04-01 11:02:42 +02:00
|
|
|
void ha_example::position(const byte *record)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_example::position");
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
2004-05-12 00:59:20 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
This is like rnd_next, but you are given a position to use
|
|
|
|
to determine the row. The position will be of the type that you stored in
|
|
|
|
ref. You can use ha_get_ptr(pos,ref_length) to retrieve whatever key
|
|
|
|
or position you saved when position() was called.
|
|
|
|
Called from filesort.cc records.cc sql_insert.cc sql_select.cc sql_update.cc.
|
|
|
|
*/
|
2004-04-01 11:02:42 +02:00
|
|
|
int ha_example::rnd_pos(byte * buf, byte *pos)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_example::rnd_pos");
|
2004-06-23 21:26:34 +02:00
|
|
|
DBUG_RETURN(HA_ERR_WRONG_COMMAND);
|
2004-04-01 11:02:42 +02:00
|
|
|
}
|
|
|
|
|
2004-05-12 00:59:20 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
::info() is used to return information to the optimizer.
|
2005-11-26 08:54:13 +01:00
|
|
|
see my_base.h for the complete description
|
|
|
|
|
2004-05-12 00:59:20 +02:00
|
|
|
Currently this table handler doesn't implement most of the fields
|
|
|
|
really needed. SHOW also makes use of this data
|
|
|
|
Another note, you will probably want to have the following in your
|
|
|
|
code:
|
|
|
|
if (records < 2)
|
|
|
|
records = 2;
|
|
|
|
The reason is that the server will optimize for cases of only a single
|
2004-06-23 21:26:34 +02:00
|
|
|
record. If in a table scan you don't know the number of records
|
2004-05-12 00:59:20 +02:00
|
|
|
it will probably be better to set records to two so you can return
|
2004-06-23 21:26:34 +02:00
|
|
|
as many records as you need.
|
2004-05-12 00:59:20 +02:00
|
|
|
Along with records a few more variables you may wish to set are:
|
|
|
|
records
|
|
|
|
deleted
|
|
|
|
data_file_length
|
|
|
|
index_file_length
|
|
|
|
delete_length
|
|
|
|
check_time
|
|
|
|
Take a look at the public variables in handler.h for more information.
|
|
|
|
|
|
|
|
Called in:
|
|
|
|
filesort.cc
|
|
|
|
ha_heap.cc
|
|
|
|
item_sum.cc
|
|
|
|
opt_sum.cc
|
|
|
|
sql_delete.cc
|
|
|
|
sql_delete.cc
|
|
|
|
sql_derived.cc
|
|
|
|
sql_select.cc
|
|
|
|
sql_select.cc
|
|
|
|
sql_select.cc
|
|
|
|
sql_select.cc
|
|
|
|
sql_select.cc
|
|
|
|
sql_show.cc
|
|
|
|
sql_show.cc
|
|
|
|
sql_show.cc
|
|
|
|
sql_show.cc
|
|
|
|
sql_table.cc
|
|
|
|
sql_union.cc
|
|
|
|
sql_update.cc
|
|
|
|
|
|
|
|
*/
|
2004-04-01 11:02:42 +02:00
|
|
|
void ha_example::info(uint flag)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_example::info");
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
2004-05-12 00:59:20 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
extra() is called whenever the server wishes to send a hint to
|
|
|
|
the storage engine. The myisam engine implements the most hints.
|
|
|
|
ha_innodb.cc has the most exhaustive list of these hints.
|
|
|
|
*/
|
2004-04-01 11:02:42 +02:00
|
|
|
int ha_example::extra(enum ha_extra_function operation)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_example::extra");
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
2004-05-12 00:59:20 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
Deprecated and likely to be removed in the future. Storage engines normally
|
|
|
|
just make a call like:
|
|
|
|
ha_example::extra(HA_EXTRA_RESET);
|
|
|
|
to handle it.
|
|
|
|
*/
|
2004-04-01 11:02:42 +02:00
|
|
|
int ha_example::reset(void)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_example::reset");
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-05-12 00:59:20 +02:00
|
|
|
/*
|
|
|
|
Used to delete all rows in a table. Both for cases of truncate and
|
|
|
|
for cases where the optimizer realizes that all rows will be
|
2004-06-23 21:26:34 +02:00
|
|
|
removed as a result of a SQL statement.
|
2004-05-12 00:59:20 +02:00
|
|
|
|
2004-06-23 21:26:34 +02:00
|
|
|
Called from item_sum.cc by Item_func_group_concat::clear(),
|
2004-05-12 00:59:20 +02:00
|
|
|
Item_sum_count_distinct::clear(), and Item_func_group_concat::clear().
|
|
|
|
Called from sql_delete.cc by mysql_delete().
|
|
|
|
Called from sql_select.cc by JOIN::reinit().
|
|
|
|
Called from sql_union.cc by st_select_lex_unit::exec().
|
|
|
|
*/
|
2004-04-01 11:02:42 +02:00
|
|
|
int ha_example::delete_all_rows()
|
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_example::delete_all_rows");
|
2004-06-23 21:26:34 +02:00
|
|
|
DBUG_RETURN(HA_ERR_WRONG_COMMAND);
|
2004-04-01 11:02:42 +02:00
|
|
|
}
|
|
|
|
|
2004-05-12 00:59:20 +02:00
|
|
|
|
2004-06-23 21:26:34 +02:00
|
|
|
/*
|
|
|
|
First you should go read the section "locking functions for mysql" in
|
2004-05-12 00:59:20 +02:00
|
|
|
lock.cc to understand this.
|
|
|
|
This create a lock on the table. If you are implementing a storage engine
|
|
|
|
that can handle transacations look at ha_berkely.cc to see how you will
|
|
|
|
want to goo about doing this. Otherwise you should consider calling flock()
|
|
|
|
here.
|
|
|
|
|
|
|
|
Called from lock.cc by lock_external() and unlock_external(). Also called
|
|
|
|
from sql_table.cc by copy_data_between_tables().
|
|
|
|
*/
|
2004-04-01 11:02:42 +02:00
|
|
|
int ha_example::external_lock(THD *thd, int lock_type)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_example::external_lock");
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
2004-05-12 00:59:20 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
The idea with handler::store_lock() is the following:
|
|
|
|
|
|
|
|
The statement decided which locks we should need for the table
|
|
|
|
for updates/deletes/inserts we get WRITE locks, for SELECT... we get
|
|
|
|
read locks.
|
|
|
|
|
|
|
|
Before adding the lock into the table lock handler (see thr_lock.c)
|
|
|
|
mysqld calls store lock with the requested locks. Store lock can now
|
|
|
|
modify a write lock to a read lock (or some other lock), ignore the
|
|
|
|
lock (if we don't want to use MySQL table locks at all) or add locks
|
|
|
|
for many tables (like we do when we are using a MERGE handler).
|
|
|
|
|
2004-06-23 21:26:34 +02:00
|
|
|
Berkeley DB for example changes all WRITE locks to TL_WRITE_ALLOW_WRITE
|
2004-05-12 00:59:20 +02:00
|
|
|
(which signals that we are doing WRITES, but we are still allowing other
|
|
|
|
reader's and writer's.
|
|
|
|
|
|
|
|
When releasing locks, store_lock() are also called. In this case one
|
|
|
|
usually doesn't have to do anything.
|
|
|
|
|
|
|
|
In some exceptional cases MySQL may send a request for a TL_IGNORE;
|
|
|
|
This means that we are requesting the same lock as last time and this
|
|
|
|
should also be ignored. (This may happen when someone does a flush
|
|
|
|
table when we have opened a part of the tables, in which case mysqld
|
|
|
|
closes and reopens the tables and tries to get the same locks at last
|
|
|
|
time). In the future we will probably try to remove this.
|
|
|
|
|
|
|
|
Called from lock.cc by get_lock_data().
|
|
|
|
*/
|
2004-04-01 11:02:42 +02:00
|
|
|
THR_LOCK_DATA **ha_example::store_lock(THD *thd,
|
|
|
|
THR_LOCK_DATA **to,
|
|
|
|
enum thr_lock_type lock_type)
|
|
|
|
{
|
|
|
|
if (lock_type != TL_IGNORE && lock.type == TL_UNLOCK)
|
|
|
|
lock.type=lock_type;
|
|
|
|
*to++= &lock;
|
|
|
|
return to;
|
|
|
|
}
|
|
|
|
|
2004-05-12 00:59:20 +02:00
|
|
|
/*
|
2004-06-23 21:26:34 +02:00
|
|
|
Used to delete a table. By the time delete_table() has been called all
|
2004-05-12 00:59:20 +02:00
|
|
|
opened references to this table will have been closed (and your globally
|
2004-06-23 21:26:34 +02:00
|
|
|
shared references released. The variable name will just be the name of
|
2004-05-12 00:59:20 +02:00
|
|
|
the table. You will need to remove any files you have created at this point.
|
|
|
|
|
2004-06-07 11:06:33 +02:00
|
|
|
If you do not implement this, the default delete_table() is called from
|
|
|
|
handler.cc and it will delete all files with the file extentions returned
|
|
|
|
by bas_ext().
|
|
|
|
|
2004-05-12 00:59:20 +02:00
|
|
|
Called from handler.cc by delete_table and ha_create_table(). Only used
|
|
|
|
during create if the table_flag HA_DROP_BEFORE_CREATE was specified for
|
|
|
|
the storage engine.
|
|
|
|
*/
|
2004-04-01 11:02:42 +02:00
|
|
|
int ha_example::delete_table(const char *name)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_example::delete_table");
|
2004-04-13 06:01:45 +02:00
|
|
|
/* This is not implemented but we want someone to be able that it works. */
|
|
|
|
DBUG_RETURN(0);
|
2004-04-01 11:02:42 +02:00
|
|
|
}
|
|
|
|
|
2004-05-12 00:59:20 +02:00
|
|
|
/*
|
|
|
|
Renames a table from one name to another from alter table call.
|
|
|
|
|
2004-06-07 11:06:33 +02:00
|
|
|
If you do not implement this, the default rename_table() is called from
|
|
|
|
handler.cc and it will delete all files with the file extentions returned
|
|
|
|
by bas_ext().
|
|
|
|
|
2004-05-12 00:59:20 +02:00
|
|
|
Called from sql_table.cc by mysql_rename_table().
|
|
|
|
*/
|
2004-04-01 11:02:42 +02:00
|
|
|
int ha_example::rename_table(const char * from, const char * to)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_example::rename_table ");
|
2004-06-23 21:26:34 +02:00
|
|
|
DBUG_RETURN(HA_ERR_WRONG_COMMAND);
|
2004-04-01 11:02:42 +02:00
|
|
|
}
|
|
|
|
|
2004-06-23 21:26:34 +02:00
|
|
|
/*
|
2004-05-12 00:59:20 +02:00
|
|
|
Given a starting key, and an ending key estimate the number of rows that
|
|
|
|
will exist between the two. end_key may be empty which in case determine
|
|
|
|
if start_key matches any rows.
|
|
|
|
|
|
|
|
Called from opt_range.cc by check_quick_keys().
|
|
|
|
*/
|
2004-05-16 13:48:32 +02:00
|
|
|
ha_rows ha_example::records_in_range(uint inx, key_range *min_key,
|
|
|
|
key_range *max_key)
|
2004-04-01 11:02:42 +02:00
|
|
|
{
|
2004-05-16 13:48:32 +02:00
|
|
|
DBUG_ENTER("ha_example::records_in_range");
|
|
|
|
DBUG_RETURN(10); // low number to force index usage
|
2004-04-01 11:02:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-05-12 00:59:20 +02:00
|
|
|
/*
|
|
|
|
create() is called to create a database. The variable name will have the name
|
|
|
|
of the table. When create() is called you do not need to worry about opening
|
2004-06-23 21:26:34 +02:00
|
|
|
the table. Also, the FRM file will have already been created so adjusting
|
2004-05-12 00:59:20 +02:00
|
|
|
create_info will not do you any good. You can overwrite the frm file at this
|
2004-06-23 21:26:34 +02:00
|
|
|
point if you wish to change the table definition, but there are no methods
|
2004-05-12 00:59:20 +02:00
|
|
|
currently provided for doing that.
|
|
|
|
|
|
|
|
Called from handle.cc by ha_create_table().
|
|
|
|
*/
|
2004-06-23 21:26:34 +02:00
|
|
|
int ha_example::create(const char *name, TABLE *table_arg,
|
2004-05-12 00:59:20 +02:00
|
|
|
HA_CREATE_INFO *create_info)
|
2004-04-01 11:02:42 +02:00
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_example::create");
|
2004-04-13 06:01:45 +02:00
|
|
|
/* This is not implemented but we want someone to be able that it works. */
|
|
|
|
DBUG_RETURN(0);
|
2004-04-01 11:02:42 +02:00
|
|
|
}
|
2005-12-21 19:18:40 +01:00
|
|
|
|
|
|
|
mysql_declare_plugin
|
|
|
|
{
|
|
|
|
MYSQL_STORAGE_ENGINE_PLUGIN,
|
|
|
|
&example_hton,
|
|
|
|
example_hton.name,
|
|
|
|
0x01000000 /* 1.0.0 */,
|
|
|
|
"Brian Aker, MySQL AB",
|
|
|
|
"Example Storage Engine",
|
|
|
|
tina_init_func, /* Plugin Init */
|
|
|
|
tina_done_func /* Plugin Deinit */
|
|
|
|
}
|
|
|
|
mysql_declare_plugin_end;
|
|
|
|
|