diff options
author | Michael Widenius <monty@askmonty.org> | 2011-01-11 18:51:59 +0200 |
---|---|---|
committer | Michael Widenius <monty@askmonty.org> | 2011-01-11 18:51:59 +0200 |
commit | 0d01dd200f97835dfb4e23676332f0ea28050c33 (patch) | |
tree | 9e922c6c08df36917f51c509b66df58a04ddf14d /storage/heap | |
parent | 050c004f5e6f152f5c4cdadda8a15e01d2f07a9a (diff) | |
download | mariadb-git-0d01dd200f97835dfb4e23676332f0ea28050c33.tar.gz |
Added HANDLER support for MEMORY tables
Added key and file version numbers to MEMORY tables so that we can detect if someone has changed them between HANDLER calls.
mysql-test/suite/handler/aria.result:
Fixed result after test changes
mysql-test/suite/handler/handler.inc:
Changed test to use combined key to ensure rows are returned in a pre-determinated order.
mysql-test/suite/handler/heap.result:
New result
mysql-test/suite/handler/heap.test:
Added test for HANDLER + HEAP
mysql-test/suite/handler/innodb.result:
Fixed result after test changes
mysql-test/suite/handler/myisam.result:
Fixed result after test changes
sql/sql_handler.cc:
Fixed wrong parameter to ha_index_next_same()
storage/heap/ha_heap.cc:
Abort key scan if table has changed.
Abort table scan if table has been recreated.
storage/heap/ha_heap.h:
Added support for HANDLER
storage/heap/hp_clear.c:
Increase version number so that we can notice changes if using HANDLER
storage/heap/hp_delete.c:
Increase key data version number on key changes.
storage/heap/hp_rfirst.c:
Remember version of key data
Give error if using read-first on hash key.
storage/heap/hp_rkey.c:
Remember version of key data
storage/heap/hp_rlast.c:
Remember version of key data
Give error if using read-last on hash key.
storage/heap/hp_rnext.c:
Fixed that we get next key from last search.
storage/heap/hp_rprev.c:
Fixed that we get previous key from last search.
storage/heap/hp_scan.c:
Remember version of key and file data
storage/heap/hp_update.c:
Increase key data version number on key changes.
storage/heap/hp_write.c:
Increase key data version number on key changes.
Diffstat (limited to 'storage/heap')
-rw-r--r-- | storage/heap/ha_heap.cc | 13 | ||||
-rw-r--r-- | storage/heap/ha_heap.h | 4 | ||||
-rw-r--r-- | storage/heap/hp_clear.c | 2 | ||||
-rw-r--r-- | storage/heap/hp_delete.c | 1 | ||||
-rw-r--r-- | storage/heap/hp_rfirst.c | 15 | ||||
-rw-r--r-- | storage/heap/hp_rkey.c | 1 | ||||
-rw-r--r-- | storage/heap/hp_rlast.c | 8 | ||||
-rw-r--r-- | storage/heap/hp_rnext.c | 1 | ||||
-rw-r--r-- | storage/heap/hp_rprev.c | 1 | ||||
-rw-r--r-- | storage/heap/hp_scan.c | 2 | ||||
-rw-r--r-- | storage/heap/hp_update.c | 4 | ||||
-rw-r--r-- | storage/heap/hp_write.c | 1 |
12 files changed, 37 insertions, 16 deletions
diff --git a/storage/heap/ha_heap.cc b/storage/heap/ha_heap.cc index 2d2c23a2ed6..6bb6936de9d 100644 --- a/storage/heap/ha_heap.cc +++ b/storage/heap/ha_heap.cc @@ -183,6 +183,19 @@ void ha_heap::set_keys_for_scanning(void) } +int ha_heap::can_continue_handler_scan() +{ + int error= 0; + if ((file->key_version != file->s->key_version && inited == INDEX) || + (file->file_version != file->s->file_version && inited == RND)) + { + /* Data changed, not safe to do index or rnd scan */ + error= HA_ERR_RECORD_CHANGED; + } + return error; +} + + void ha_heap::update_key_stats() { for (uint i= 0; i < table->s->keys; i++) diff --git a/storage/heap/ha_heap.h b/storage/heap/ha_heap.h index 22722129f4c..49aa91a6caa 100644 --- a/storage/heap/ha_heap.h +++ b/storage/heap/ha_heap.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2006 MySQL AB +/* Copyright (C) 2000-2006 MySQL AB, 2009-2011 Monty Program 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 @@ -52,6 +52,7 @@ public: { return (HA_FAST_KEY_READ | HA_NO_BLOBS | HA_NULL_IN_KEY | HA_BINLOG_ROW_CAPABLE | HA_BINLOG_STMT_CAPABLE | + HA_CAN_SQL_HANDLER | HA_REC_NOT_IN_SEQ | HA_CAN_INSERT_DELAYED | HA_NO_TRANSACTIONS | HA_HAS_RECORDS | HA_STATS_RECORDS_IS_EXACT); } @@ -93,6 +94,7 @@ public: int rnd_next(uchar *buf); int rnd_pos(uchar * buf, uchar *pos); void position(const uchar *record); + int can_continue_handler_scan(); int info(uint); int extra(enum ha_extra_function operation); int reset(); diff --git a/storage/heap/hp_clear.c b/storage/heap/hp_clear.c index babfcbd6f41..b999f1ff5e8 100644 --- a/storage/heap/hp_clear.c +++ b/storage/heap/hp_clear.c @@ -40,6 +40,8 @@ void hp_clear(HP_SHARE *info) info->blength=1; info->changed=0; info->del_link=0; + info->key_version++; + info->file_version++; DBUG_VOID_RETURN; } diff --git a/storage/heap/hp_delete.c b/storage/heap/hp_delete.c index 9e9e28da335..1af9cf26f8c 100644 --- a/storage/heap/hp_delete.c +++ b/storage/heap/hp_delete.c @@ -47,6 +47,7 @@ int heap_delete(HP_INFO *info, const uchar *record) share->del_link=pos; pos[share->reclength]=0; /* Record deleted */ share->deleted++; + share->key_version++; info->current_hash_ptr=0; #if !defined(DBUG_OFF) && defined(EXTRA_HEAP_DEBUG) DBUG_EXECUTE("check_heap",heap_check_heap(info, 0);); diff --git a/storage/heap/hp_rfirst.c b/storage/heap/hp_rfirst.c index d0d2ec9b506..8e562983b02 100644 --- a/storage/heap/hp_rfirst.c +++ b/storage/heap/hp_rfirst.c @@ -24,6 +24,8 @@ int heap_rfirst(HP_INFO *info, uchar *record, int inx) DBUG_ENTER("heap_rfirst"); info->lastinx= inx; + info->key_version= info->s->key_version; + if (keyinfo->algorithm == HA_KEY_ALG_BTREE) { uchar *pos; @@ -57,15 +59,8 @@ int heap_rfirst(HP_INFO *info, uchar *record, int inx) } else { - if (!(info->s->records)) - { - my_errno=HA_ERR_END_OF_FILE; - DBUG_RETURN(my_errno); - } - DBUG_ASSERT(0); /* TODO fix it */ - info->current_record=0; - info->current_hash_ptr=0; - info->update=HA_STATE_PREV_FOUND; - DBUG_RETURN(heap_rnext(info,record)); + /* We can't scan a non existing key value with hash index */ + my_errno= HA_ERR_WRONG_COMMAND; + DBUG_RETURN(my_errno); } } diff --git a/storage/heap/hp_rkey.c b/storage/heap/hp_rkey.c index 27d1114770e..c2edf63f6f2 100644 --- a/storage/heap/hp_rkey.c +++ b/storage/heap/hp_rkey.c @@ -30,6 +30,7 @@ int heap_rkey(HP_INFO *info, uchar *record, int inx, const uchar *key, } info->lastinx= inx; info->current_record= (ulong) ~0L; /* For heap_rrnd() */ + info->key_version= info->s->key_version; if (keyinfo->algorithm == HA_KEY_ALG_BTREE) { diff --git a/storage/heap/hp_rlast.c b/storage/heap/hp_rlast.c index 45ad7c21f49..0710401e5a5 100644 --- a/storage/heap/hp_rlast.c +++ b/storage/heap/hp_rlast.c @@ -25,6 +25,7 @@ int heap_rlast(HP_INFO *info, uchar *record, int inx) DBUG_ENTER("heap_rlast"); info->lastinx= inx; + info->key_version= info->s->key_version; if (keyinfo->algorithm == HA_KEY_ALG_BTREE) { uchar *pos; @@ -47,9 +48,8 @@ int heap_rlast(HP_INFO *info, uchar *record, int inx) } else { - info->current_ptr=0; - info->current_hash_ptr=0; - info->update=HA_STATE_NEXT_FOUND; - DBUG_RETURN(heap_rprev(info,record)); + /* We can't scan a non existing key value with hash index */ + my_errno= HA_ERR_WRONG_COMMAND; + DBUG_RETURN(my_errno); } } diff --git a/storage/heap/hp_rnext.c b/storage/heap/hp_rnext.c index 3d715f4e6d3..7a654850e0e 100644 --- a/storage/heap/hp_rnext.c +++ b/storage/heap/hp_rnext.c @@ -70,6 +70,7 @@ int heap_rnext(HP_INFO *info, uchar *record) custom_arg.keyseg = keyinfo->seg; custom_arg.key_length = info->lastkey_len; custom_arg.search_flag = SEARCH_SAME | SEARCH_FIND; + info->last_find_flag= HA_READ_KEY_OR_NEXT; pos = tree_search_key(&keyinfo->rb_tree, info->lastkey, info->parents, &info->last_pos, info->last_find_flag, &custom_arg); } diff --git a/storage/heap/hp_rprev.c b/storage/heap/hp_rprev.c index 63bfffffba9..1d71c20eef4 100644 --- a/storage/heap/hp_rprev.c +++ b/storage/heap/hp_rprev.c @@ -41,6 +41,7 @@ int heap_rprev(HP_INFO *info, uchar *record) custom_arg.keyseg = keyinfo->seg; custom_arg.key_length = keyinfo->length; custom_arg.search_flag = SEARCH_SAME; + info->last_find_flag= HA_READ_KEY_OR_PREV; pos = tree_search_key(&keyinfo->rb_tree, info->lastkey, info->parents, &info->last_pos, info->last_find_flag, &custom_arg); } diff --git a/storage/heap/hp_scan.c b/storage/heap/hp_scan.c index e8913e92c86..397dd8b54d4 100644 --- a/storage/heap/hp_scan.c +++ b/storage/heap/hp_scan.c @@ -31,6 +31,8 @@ int heap_scan_init(register HP_INFO *info) info->current_record= (ulong) ~0L; /* No current record */ info->update=0; info->next_block=0; + info->key_version= info->s->key_version; + info->file_version= info->s->file_version; DBUG_RETURN(0); } diff --git a/storage/heap/hp_update.c b/storage/heap/hp_update.c index 7f469af3c96..ab831382325 100644 --- a/storage/heap/hp_update.c +++ b/storage/heap/hp_update.c @@ -21,7 +21,7 @@ int heap_update(HP_INFO *info, const uchar *old, const uchar *heap_new) { HP_KEYDEF *keydef, *end, *p_lastinx; uchar *pos; - my_bool auto_key_changed= 0; + my_bool auto_key_changed= 0, key_changed= 0; HP_SHARE *share= info->s; DBUG_ENTER("heap_update"); @@ -54,6 +54,8 @@ int heap_update(HP_INFO *info, const uchar *old, const uchar *heap_new) #endif if (auto_key_changed) heap_update_auto_increment(info, heap_new); + if (key_changed) + share->key_version++; DBUG_RETURN(0); err: diff --git a/storage/heap/hp_write.c b/storage/heap/hp_write.c index 4e8fa7e3580..bf27503de9b 100644 --- a/storage/heap/hp_write.c +++ b/storage/heap/hp_write.c @@ -56,6 +56,7 @@ int heap_write(HP_INFO *info, const uchar *record) pos[share->reclength]=1; /* Mark record as not deleted */ if (++share->records == share->blength) share->blength+= share->blength; + info->s->key_version++; info->current_ptr=pos; info->current_hash_ptr=0; info->update|=HA_STATE_AKTIV; |