mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / storage / myisam / mi_rnext_same.c
blob1ae65b3c3432be0f2f85d4b0bae24d9aa34d979f
1 /* Copyright (c) 2000-2007 MySQL AB
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; version 2 of the License.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
16 #include "myisamdef.h"
17 #include "rt_index.h"
20 Read next row with the same key as previous read, but abort if
21 the key changes.
22 One may have done a write, update or delete of the previous row.
23 NOTE! Even if one changes the previous row, the next read is done
24 based on the position of the last used key!
27 int mi_rnext_same(MI_INFO *info, uchar *buf)
29 int error;
30 uint inx,not_used[2];
31 MI_KEYDEF *keyinfo;
32 DBUG_ENTER("mi_rnext_same");
34 if ((int) (inx=info->lastinx) < 0 || info->lastpos == HA_OFFSET_ERROR)
35 DBUG_RETURN(my_errno=HA_ERR_WRONG_INDEX);
36 keyinfo=info->s->keyinfo+inx;
37 if (fast_mi_readinfo(info))
38 DBUG_RETURN(my_errno);
40 if (info->s->concurrent_insert)
41 rw_rdlock(&info->s->key_root_lock[inx]);
43 switch (keyinfo->key_alg)
45 #ifdef HAVE_RTREE_KEYS
46 case HA_KEY_ALG_RTREE:
47 if ((error=rtree_find_next(info,inx,
48 myisam_read_vec[info->last_key_func])))
50 error=1;
51 my_errno=HA_ERR_END_OF_FILE;
52 info->lastpos= HA_OFFSET_ERROR;
53 break;
55 break;
56 #endif
57 case HA_KEY_ALG_BTREE:
58 default:
59 if (!(info->update & HA_STATE_RNEXT_SAME))
61 /* First rnext_same; Store old key */
62 memcpy(info->lastkey2,info->lastkey,info->last_rkey_length);
64 for (;;)
66 if ((error=_mi_search_next(info,keyinfo,info->lastkey,
67 info->lastkey_length,SEARCH_BIGGER,
68 info->s->state.key_root[inx])))
69 break;
70 if (ha_key_cmp(keyinfo->seg, info->lastkey, info->lastkey2,
71 info->last_rkey_length, SEARCH_FIND, not_used))
73 error=1;
74 my_errno=HA_ERR_END_OF_FILE;
75 info->lastpos= HA_OFFSET_ERROR;
76 break;
78 /* Skip rows that are inserted by other threads since we got a lock */
79 if (info->lastpos < info->state->data_file_length)
80 break;
83 if (info->s->concurrent_insert)
84 rw_unlock(&info->s->key_root_lock[inx]);
85 /* Don't clear if database-changed */
86 info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED);
87 info->update|= HA_STATE_NEXT_FOUND | HA_STATE_RNEXT_SAME;
89 if (error)
91 if (my_errno == HA_ERR_KEY_NOT_FOUND)
92 my_errno=HA_ERR_END_OF_FILE;
94 else if (!buf)
96 DBUG_RETURN(info->lastpos==HA_OFFSET_ERROR ? my_errno : 0);
98 else if (!(*info->read_record)(info,info->lastpos,buf))
100 info->update|= HA_STATE_AKTIV; /* Record is read */
101 DBUG_RETURN(0);
103 DBUG_RETURN(my_errno);
104 } /* mi_rnext_same */