mariadb/myisam/mi_rnext_same.c
unknown 8d6634c9e0 Added more tests for new UPDATE ... ORDER BY ... LIMIT optimization
heap/_check.c:
  Change arguments to ha_key_cmp
heap/hp_create.c:
  Change arguments to ha_key_cmp
include/my_base.h:
  Remove SEARCH_RETURN_B_POS and instead always send an array to ha_key_cmp() as last argument
myisam/mi_check.c:
  Change arguments to ha_key_cmp
myisam/mi_rnext_same.c:
  Change arguments to ha_key_cmp
myisam/mi_search.c:
  Change arguments to ha_key_cmp
myisam/mi_write.c:
  Change arguments to ha_key_cmp
myisammrg/myrg_queue.c:
  Change arguments to ha_key_cmp
mysys/my_handler.c:
  Remove SEARCH_RETURN_B_POS and instead always send an array to ha_key_cmp() as last argument
  (This removes an if in a loop at the expensive of an int on the stack)
sql/records.cc:
  Simplify new rr_index() code
  Create common error handling function for rr_() functions.
  Remove loop from rr_index() as handler::index_next() can never return HA_ERR_RECORD_DELETED
sql/sql_load.cc:
  Simplify
sql/sql_update.cc:
  Simplify code
  Fixed bug when one is updating an index column that could be used with ORDER BY
sql/structs.h:
  Removed not needed structure element
2005-10-25 02:27:40 +03:00

105 lines
3.2 KiB
C

/* Copyright (C) 2000 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 */
#include "myisamdef.h"
#include "rt_index.h"
/*
Read next row with the same key as previous read, but abort if
the key changes.
One may have done a write, update or delete of the previous row.
NOTE! Even if one changes the previous row, the next read is done
based on the position of the last used key!
*/
int mi_rnext_same(MI_INFO *info, byte *buf)
{
int error;
uint inx,not_used[2];
MI_KEYDEF *keyinfo;
DBUG_ENTER("mi_rnext_same");
if ((int) (inx=info->lastinx) < 0 || info->lastpos == HA_OFFSET_ERROR)
DBUG_RETURN(my_errno=HA_ERR_WRONG_INDEX);
keyinfo=info->s->keyinfo+inx;
if (fast_mi_readinfo(info))
DBUG_RETURN(my_errno);
if (info->s->concurrent_insert)
rw_rdlock(&info->s->key_root_lock[inx]);
switch (keyinfo->key_alg)
{
#ifdef HAVE_RTREE_KEYS
case HA_KEY_ALG_RTREE:
if ((error=rtree_find_next(info,inx,
myisam_read_vec[info->last_key_func])))
{
error=1;
my_errno=HA_ERR_END_OF_FILE;
info->lastpos= HA_OFFSET_ERROR;
break;
}
break;
#endif
case HA_KEY_ALG_BTREE:
default:
if (!(info->update & HA_STATE_RNEXT_SAME))
{
/* First rnext_same; Store old key */
memcpy(info->lastkey2,info->lastkey,info->last_rkey_length);
}
for (;;)
{
if ((error=_mi_search_next(info,keyinfo,info->lastkey,
info->lastkey_length,SEARCH_BIGGER,
info->s->state.key_root[inx])))
break;
if (ha_key_cmp(keyinfo->seg, info->lastkey, info->lastkey2,
info->last_rkey_length, SEARCH_FIND, not_used))
{
error=1;
my_errno=HA_ERR_END_OF_FILE;
info->lastpos= HA_OFFSET_ERROR;
break;
}
/* Skip rows that are inserted by other threads since we got a lock */
if (info->lastpos < info->state->data_file_length)
break;
}
}
if (info->s->concurrent_insert)
rw_unlock(&info->s->key_root_lock[inx]);
/* Don't clear if database-changed */
info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED);
info->update|= HA_STATE_NEXT_FOUND | HA_STATE_RNEXT_SAME;
if (error)
{
if (my_errno == HA_ERR_KEY_NOT_FOUND)
my_errno=HA_ERR_END_OF_FILE;
}
else if (!buf)
{
DBUG_RETURN(info->lastpos==HA_OFFSET_ERROR ? my_errno : 0);
}
else if (!(*info->read_record)(info,info->lastpos,buf))
{
info->update|= HA_STATE_AKTIV; /* Record is read */
DBUG_RETURN(0);
}
DBUG_RETURN(my_errno);
} /* mi_rnext */