summaryrefslogtreecommitdiff
path: root/storage/sequence
diff options
context:
space:
mode:
authorSergey Vojtovich <svoj@mariadb.org>2013-07-23 17:38:44 +0400
committerSergey Vojtovich <svoj@mariadb.org>2013-07-23 17:38:44 +0400
commit6069e780dcc4848ae795267ea26300ff8c1bb65b (patch)
treedbc93e1d8195b2f187494c6b16767c649e9687f7 /storage/sequence
parent43946c08888f06b84551302fcc3940e3018a40a4 (diff)
downloadmariadb-git-6069e780dcc4848ae795267ea26300ff8c1bb65b.tar.gz
MDEV-4786 - merge 10.0-monty → 10.0
Fixed sequence compilation failure. storage/sequence/sequence.cc: Adjusted sequence according to: WL#4305 - storage-engine private data area per physical table.
Diffstat (limited to 'storage/sequence')
-rw-r--r--storage/sequence/sequence.cc101
1 files changed, 58 insertions, 43 deletions
diff --git a/storage/sequence/sequence.cc b/storage/sequence/sequence.cc
index 60b360592ce..4ba5ff24fea 100644
--- a/storage/sequence/sequence.cc
+++ b/storage/sequence/sequence.cc
@@ -25,21 +25,33 @@
#include <table.h>
#include <field.h>
-typedef struct st_share {
+class SHARE : public Handler_share {
+public:
const char *name;
THR_LOCK lock;
- uint use_count;
- struct st_share *next;
ulonglong from, to, step;
bool reverse;
-} SHARE;
+
+ SHARE(const char *name_arg, ulonglong from_arg, ulonglong to_arg,
+ ulonglong step_arg, bool reverse_arg):
+ name(name_arg), from(from_arg), to(to_arg), step(step_arg),
+ reverse(reverse_arg)
+ {
+ thr_lock_init(&lock);
+ }
+ ~SHARE()
+ {
+ thr_lock_delete(&lock);
+ }
+};
class ha_seq: public handler
{
private:
THR_LOCK_DATA lock;
SHARE *seqs;
+ SHARE *get_share();
ulonglong cur;
public:
@@ -229,12 +241,9 @@ ha_rows ha_seq::records_in_range(uint inx, key_range *min_key,
int ha_seq::open(const char *name, int mode, uint test_if_locked)
{
- mysql_mutex_lock(&table->s->LOCK_ha_data);
- seqs= (SHARE*)table->s->ha_data;
+ if (!(seqs= get_share()))
+ return HA_ERR_OUT_OF_MEM;
DBUG_ASSERT(my_strcasecmp(table_alias_charset, name, seqs->name) == 0);
- if (seqs->use_count++ == 0)
- thr_lock_init(&seqs->lock);
- mysql_mutex_unlock(&table->s->LOCK_ha_data);
ref_length= sizeof(cur);
thr_lock_data_init(&seqs->lock,&lock,NULL);
@@ -243,10 +252,6 @@ int ha_seq::open(const char *name, int mode, uint test_if_locked)
int ha_seq::close(void)
{
- mysql_mutex_lock(&table->s->LOCK_ha_data);
- if (--seqs->use_count == 0)
- thr_lock_delete(&seqs->lock);
- mysql_mutex_unlock(&table->s->LOCK_ha_data);
return 0;
}
@@ -271,6 +276,45 @@ static bool parse_table_name(const char *name, size_t name_length,
}
+SHARE *ha_seq::get_share()
+{
+ SHARE *tmp_share;
+ lock_shared_ha_data();
+ if (!(tmp_share= static_cast<SHARE*>(get_ha_share_ptr())))
+ {
+ bool reverse;
+ ulonglong from, to, step;
+
+ parse_table_name(table_share->table_name.str,
+ table_share->table_name.length, &from, &to, &step);
+
+ if ((reverse = from > to))
+ {
+ if (step > from - to)
+ to = from;
+ else
+ swap_variables(ulonglong, from, to);
+ /*
+ when keyread is allowed, optimizer will always prefer an index to a
+ table scan for our tables, and we'll never see the range reversed.
+ */
+ table_share->keys_for_keyread.clear_all();
+ }
+
+ to= (to - from) / step * step + step + from;
+
+ tmp_share= new SHARE(table_share->normalized_path.str, from, to, step, reverse);
+
+ if (!tmp_share)
+ goto err;
+ set_ha_share_ptr(static_cast<Handler_share*>(tmp_share));
+ }
+err:
+ unlock_shared_ha_data();
+ return tmp_share;
+}
+
+
static int discover_table(handlerton *hton, THD *thd, TABLE_SHARE *share)
{
ulonglong from, to, step;
@@ -282,36 +326,7 @@ static int discover_table(handlerton *hton, THD *thd, TABLE_SHARE *share)
return HA_WRONG_CREATE_OPTION;
const char *sql="create table seq (seq bigint unsigned primary key)";
- int res= share->init_from_sql_statement_string(thd, 0, sql, strlen(sql));
- if (res)
- return res;
-
- bool reverse;
- if ((reverse = from > to))
- {
- if (step > from - to)
- to = from;
- else
- swap_variables(ulonglong, from, to);
- /*
- when keyread is allowed, optimizer will always prefer an index to a
- table scan for our tables, and we'll never see the range reversed.
- */
- share->keys_for_keyread.clear_all();
- }
-
- to= (to - from) / step * step + step + from;
-
- SHARE *seqs= (SHARE*)alloc_root(&share->mem_root, sizeof(*seqs));
- bzero(seqs, sizeof(*seqs));
- seqs->name = share->normalized_path.str;
- seqs->from= from;
- seqs->to= to;
- seqs->step= step;
- seqs->reverse= reverse;
-
- share->ha_data = seqs;
- return 0;
+ return share->init_from_sql_statement_string(thd, 0, sql, strlen(sql));
}