mirror of
https://github.com/MariaDB/server.git
synced 2025-01-17 20:42:30 +01:00
99c431db92
Manually imported changes done to MyISAM (include/myisam.h, storage/myisam/*, sql/ha_myisam.*, mysql-test/t/myisam.test, mysql-test/t/ps_2myisam.test) the last months into Maria (tedious, should do it more frequently in the future), including those not done at the previous 5.1->Maria merge (please in the future don't forget to apply MyISAM changes to Maria when you merge 5.1 into Maria). Note: I didn't try to import anything which could be MyISAM-related in other tests of mysql-test (I didn't want to dig in all csets), but as QA is working to make most tests re-usable for other engines (Falcon), it is likely that we'll benefit from this and just have to set engine=Maria somewhere to run those tests on Maria. func_group and partition tests fail but they already do in main 5.1 on my machine. No Valgrind error in t/*maria*.test. Monty: please see the commit comment of maria.result and check. BitKeeper/deleted/.del-ha_maria.m4: Delete: config/ac-macros/ha_maria.m4 configure.in: fix for the new way of enabling engines include/maria.h: importing changes done to MyISAM the last months into Maria include/my_handler.h: importing changes done to MyISAM the last months into Maria include/myisam.h: importing changes done to MyISAM the last months into Maria mysql-test/r/maria.result: identical to myisam.result, except the engine name in some places AND in the line testing key_block_size=1000000000000000000: Maria gives a key block size of 8192 while MyISAM gives 4096; is it explainable by the difference between MARIA_KEY_BLOCK_LENGTH and the same constant in MyISAM? Monty? mysql-test/r/ps_maria.result: identical to ps_2myisam.result (except the engine name in some places) mysql-test/t/maria.test: instead of engine=maria everywhere, I use @@storage_engine (reduces the diff with myisam.test). importing changes done to MyISAM the last months into Maria mysys/my_handler.c: importing changes done to MyISAM the last months into Maria sql/ha_maria.cc: importing changes done to MyISAM the last months into Maria sql/ha_maria.h: importing changes done to MyISAM the last months into Maria sql/mysqld.cc: unneeded storage/maria/Makefile.am: importing changes done to MyISAM the last months into Maria storage/maria/ma_check.c: importing changes done to MyISAM the last months into Maria storage/maria/ma_create.c: importing changes done to MyISAM the last months into Maria storage/maria/ma_delete_table.c: importing changes done to MyISAM the last months into Maria storage/maria/ma_dynrec.c: importing changes done to MyISAM the last months into Maria storage/maria/ma_extra.c: importing changes done to MyISAM the last months into Maria storage/maria/ma_ft_boolean_search.c: importing changes done to MyISAM the last months into Maria storage/maria/ma_ft_eval.c: importing changes done to MyISAM the last months into Maria storage/maria/ma_ft_nlq_search.c: importing changes done to MyISAM the last months into Maria storage/maria/ma_ft_parser.c: importing changes done to MyISAM the last months into Maria storage/maria/ma_ft_test1.c: importing changes done to MyISAM the last months into Maria storage/maria/ma_ft_update.c: importing changes done to MyISAM the last months into Maria storage/maria/ma_ftdefs.h: importing changes done to MyISAM the last months into Maria storage/maria/ma_key.c: importing changes done to MyISAM the last months into Maria storage/maria/ma_open.c: importing changes done to MyISAM the last months into Maria storage/maria/ma_page.c: importing changes done to MyISAM the last months into Maria storage/maria/ma_rkey.c: importing changes done to MyISAM the last months into Maria storage/maria/ma_rsamepos.c: importing changes done to MyISAM the last months into Maria storage/maria/ma_rt_index.c: importing changes done to MyISAM the last months into Maria storage/maria/ma_rt_mbr.c: importing changes done to MyISAM the last months into Maria storage/maria/ma_search.c: importing changes done to MyISAM the last months into Maria storage/maria/ma_sort.c: importing changes done to MyISAM the last months into Maria storage/maria/ma_test1.c: importing changes done to MyISAM the last months into Maria storage/maria/ma_test2.c: importing changes done to MyISAM the last months into Maria storage/maria/ma_test3.c: importing changes done to MyISAM the last months into Maria storage/maria/ma_update.c: importing changes done to MyISAM the last months into Maria storage/maria/ma_write.c: importing changes done to MyISAM the last months into Maria storage/maria/maria_chk.c: importing changes done to MyISAM the last months into Maria storage/maria/maria_def.h: importing changes done to MyISAM the last months into Maria storage/maria/maria_ftdump.c: importing changes done to MyISAM the last months into Maria storage/maria/maria_pack.c: importing changes done to MyISAM the last months into Maria
155 lines
5.3 KiB
C
155 lines
5.3 KiB
C
/* Copyright (C) 2006 MySQL AB & MySQL Finland AB & TCX DataKonsult 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 */
|
|
|
|
/* Read record based on a key */
|
|
|
|
#include "maria_def.h"
|
|
#include "ma_rt_index.h"
|
|
|
|
/* Read a record using key */
|
|
/* Ordinary search_flag is 0 ; Give error if no record with key */
|
|
|
|
int maria_rkey(MARIA_HA *info, byte *buf, int inx, const byte *key, uint key_len,
|
|
enum ha_rkey_function search_flag)
|
|
{
|
|
uchar *key_buff;
|
|
MARIA_SHARE *share=info->s;
|
|
MARIA_KEYDEF *keyinfo;
|
|
HA_KEYSEG *last_used_keyseg;
|
|
uint pack_key_length, use_key_length, nextflag;
|
|
DBUG_ENTER("maria_rkey");
|
|
DBUG_PRINT("enter", ("base: %lx buf: %lx inx: %d search_flag: %d",
|
|
(long) info, (long) buf, inx, search_flag));
|
|
|
|
if ((inx = _ma_check_index(info,inx)) < 0)
|
|
DBUG_RETURN(my_errno);
|
|
|
|
info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED);
|
|
info->last_key_func= search_flag;
|
|
keyinfo= share->keyinfo + inx;
|
|
|
|
if (info->once_flags & USE_PACKED_KEYS)
|
|
{
|
|
info->once_flags&= ~USE_PACKED_KEYS; /* Reset flag */
|
|
/*
|
|
key is already packed!; This happens when we are using a MERGE TABLE
|
|
*/
|
|
key_buff=info->lastkey+info->s->base.max_key_length;
|
|
pack_key_length= key_len;
|
|
bmove(key_buff,key,key_len);
|
|
last_used_keyseg= 0;
|
|
}
|
|
else
|
|
{
|
|
if (key_len == 0)
|
|
key_len=USE_WHOLE_KEY;
|
|
/* Save the packed key for later use in the second buffer of lastkey. */
|
|
key_buff=info->lastkey+info->s->base.max_key_length;
|
|
pack_key_length= _ma_pack_key(info,(uint) inx, key_buff, (uchar*) key,
|
|
key_len, &last_used_keyseg);
|
|
/* Save packed_key_length for use by the MERGE engine. */
|
|
info->pack_key_length= pack_key_length;
|
|
DBUG_EXECUTE("key", _ma_print_key(DBUG_FILE, keyinfo->seg,
|
|
key_buff, pack_key_length););
|
|
}
|
|
|
|
if (fast_ma_readinfo(info))
|
|
goto err;
|
|
if (share->concurrent_insert)
|
|
rw_rdlock(&share->key_root_lock[inx]);
|
|
|
|
nextflag=maria_read_vec[search_flag];
|
|
use_key_length=pack_key_length;
|
|
if (!(nextflag & (SEARCH_FIND | SEARCH_NO_FIND | SEARCH_LAST)))
|
|
use_key_length=USE_WHOLE_KEY;
|
|
|
|
switch (info->s->keyinfo[inx].key_alg) {
|
|
#ifdef HAVE_RTREE_KEYS
|
|
case HA_KEY_ALG_RTREE:
|
|
if (maria_rtree_find_first(info,inx,key_buff,use_key_length,nextflag) < 0)
|
|
{
|
|
maria_print_error(info->s, HA_ERR_CRASHED);
|
|
my_errno=HA_ERR_CRASHED;
|
|
goto err;
|
|
}
|
|
break;
|
|
#endif
|
|
case HA_KEY_ALG_BTREE:
|
|
default:
|
|
if (!_ma_search(info, keyinfo, key_buff, use_key_length,
|
|
maria_read_vec[search_flag], info->s->state.key_root[inx]))
|
|
{
|
|
/*
|
|
If we are searching for an exact key (including the data pointer)
|
|
and this was added by an concurrent insert,
|
|
then the result is "key not found".
|
|
*/
|
|
if ((search_flag == HA_READ_KEY_EXACT) &&
|
|
(info->lastpos >= info->state->data_file_length))
|
|
{
|
|
my_errno= HA_ERR_KEY_NOT_FOUND;
|
|
info->lastpos= HA_OFFSET_ERROR;
|
|
}
|
|
else while (info->lastpos >= info->state->data_file_length)
|
|
{
|
|
/*
|
|
Skip rows that are inserted by other threads since we got a lock
|
|
Note that this can only happen if we are not searching after an
|
|
exact key, because the keys are sorted according to position
|
|
*/
|
|
|
|
if (_ma_search_next(info, keyinfo, info->lastkey,
|
|
info->lastkey_length,
|
|
maria_readnext_vec[search_flag],
|
|
info->s->state.key_root[inx]))
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if (share->concurrent_insert)
|
|
rw_unlock(&share->key_root_lock[inx]);
|
|
|
|
/* Calculate length of the found key; Used by maria_rnext_same */
|
|
if ((keyinfo->flag & HA_VAR_LENGTH_KEY) && last_used_keyseg &&
|
|
info->lastpos != HA_OFFSET_ERROR)
|
|
info->last_rkey_length= _ma_keylength_part(keyinfo, info->lastkey,
|
|
last_used_keyseg);
|
|
else
|
|
info->last_rkey_length= pack_key_length;
|
|
|
|
/* Check if we don't want to have record back, only error message */
|
|
if (!buf)
|
|
DBUG_RETURN(info->lastpos == HA_OFFSET_ERROR ? my_errno : 0);
|
|
|
|
if (!(*info->read_record)(info,info->lastpos,buf))
|
|
{
|
|
info->update|= HA_STATE_AKTIV; /* Record is read */
|
|
DBUG_RETURN(0);
|
|
}
|
|
|
|
info->lastpos = HA_OFFSET_ERROR; /* Didn't find key */
|
|
|
|
/* Store last used key as a base for read next */
|
|
memcpy(info->lastkey,key_buff,pack_key_length);
|
|
info->last_rkey_length= pack_key_length;
|
|
bzero((char*) info->lastkey+pack_key_length,info->s->base.rec_reflength);
|
|
info->lastkey_length=pack_key_length+info->s->base.rec_reflength;
|
|
|
|
if (search_flag == HA_READ_AFTER_KEY)
|
|
info->update|=HA_STATE_NEXT_FOUND; /* Previous gives last row */
|
|
err:
|
|
DBUG_RETURN(my_errno);
|
|
} /* _ma_rkey */
|