Debian Codegraph @

storage/myisam/mi_rnext.c

raw symbols SCIP
1 /*
2 Copyright (c) 2000, 2010, Oracle and/or its affiliates
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; version 2 of the License.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */
16
17 #include "myisamdef.h"cxx . . $ `<file>/storage/myisam/myisamdef.h`/
18 #include "rt_index.h"cxx . . $ `<file>/storage/myisam/rt_index.h`/
19
20 /*
21 Read next row with the same key as previous read
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!
25 */
26
27 int mi_rnextcxx . . $ mi_rnext(b13a3588bf66f733).(MI_INFOcxx . . $ MI_INFO# *info, ucharcxx . . $ uchar# *buf, int inx)
28 {
29 int error,changed;
30 uintcxx . . $ uint# flag;
31 check_result_tcxx . . $ check_result_t# check= CHECK_POScxx . . $ CHECK_POS.;
32 uintcxx . . $ uint# update_mask= HA_STATE_NEXT_FOUNDcxx . . $ `include/my_base.h:621:9`!;
33 DBUG_ENTERcxx . . $ `include/my_dbug.h:165:9`!("mi_rnext");
34
35 if ((inx = _mi_check_indexcxx . . $ _mi_check_index(a395578934ddaf1c).(info,inx)) < 0)
36 DBUG_RETURNcxx . . $ `include/my_dbug.h:168:9`!(my_errnocxx . . $ `include/my_pthread.h:720:9`!);
37 flag=SEARCH_BIGGERcxx . . $ `include/my_base.h:585:9`!; /* Read next */
38 if (info->lastposcxx . . $ st_myisam_info#lastpos. == HA_OFFSET_ERRORcxx . . $ `include/my_base.h:695:9`! && info->updatecxx . . $ st_myisam_info#update. & HA_STATE_PREV_FOUNDcxx . . $ `include/my_base.h:622:9`!)
39 flag=0; /* Read first */
40
41 if (fast_mi_readinfocxx . . $ `storage/myisam/myisamdef.h:673:9`!(info))
42 DBUG_RETURNcxx . . $ `include/my_dbug.h:168:9`!(my_errnocxx . . $ `include/my_pthread.h:720:9`!);
43 if (info->scxx . . $ st_myisam_info#s.->concurrent_insertcxx . . $ st_mi_isam_share#concurrent_insert.)
44 mysql_rwlock_rdlockcxx . . $ `include/mysql/psi/mysql_thread.h:452:11`!(&info->s->key_root_lock[inx]);
45 changed=_mi_test_if_changedcxx . . $ _mi_test_if_changed(5bca52a199e8d1d4).(info);
46 if (!flag)
47 {
48 switch(info->scxx . . $ st_myisam_info#s.->keyinfocxx . . $ st_mi_isam_share#keyinfo.[inx].key_algcxx . . $ st_mi_keydef#key_alg.){
49 case HA_KEY_ALG_RTREEcxx . . $ HA_KEY_ALG_RTREE.:
50 error=rtree_get_firstcxx . . $ rtree_get_first(8fbb67b92b1bef59).(info,inx,info->lastkey_lengthcxx . . $ st_myisam_info#lastkey_length.);
51 break;
52 case HA_KEY_ALG_BTREEcxx . . $ HA_KEY_ALG_BTREE.:
53 default:
54 error=_mi_search_firstcxx . . $ _mi_search_first(31890286b5e8653e).(info,info->scxx . . $ st_myisam_info#s.->keyinfocxx . . $ st_mi_isam_share#keyinfo.+inx,
55 info->scxx . . $ st_myisam_info#s.->statecxx . . $ st_mi_isam_share#state..key_rootcxx . . $ st_mi_state_info#key_root.[inx]);
56 break;
57 }
58 /*
59 "search first" failed. This means we have no pivot for
60 "search next", or in other words MI_INFO::lastkey is
61 likely uninitialized.
62
63 Normally SQL layer would never request "search next" if
64 "search first" failed. But HANDLER may do anything.
65
66 As mi_rnext() without preceding mi_rkey()/mi_rfirst()
67 equals to mi_rfirst(), we must restore original state
68 as if failing mi_rfirst() was not called.
69 */
70 if (error)
71 update_mask|= HA_STATE_PREV_FOUNDcxx . . $ `include/my_base.h:622:9`!;
72 }
73 else
74 {
75 switch (info->scxx . . $ st_myisam_info#s.->keyinfocxx . . $ st_mi_isam_share#keyinfo.[inx].key_algcxx . . $ st_mi_keydef#key_alg.) {
76 case HA_KEY_ALG_RTREEcxx . . $ HA_KEY_ALG_RTREE.:
77 /*
78 Note that rtree doesn't support that the table
79 may be changed since last call, so we do need
80 to skip rows inserted by other threads like in btree
81 */
82 error= rtree_get_nextcxx . . $ rtree_get_next(8fbb67b92b1bef59).(info,inx,info->lastkey_lengthcxx . . $ st_myisam_info#lastkey_length.);
83 break;
84 case HA_KEY_ALG_BTREEcxx . . $ HA_KEY_ALG_BTREE.:
85 default:
86 if (!changed)
87 error= _mi_search_nextcxx . . $ _mi_search_next(11619ded83ef7296).(info,info->scxx . . $ st_myisam_info#s.->keyinfocxx . . $ st_mi_isam_share#keyinfo.+inx,info->lastkeycxx . . $ st_myisam_info#lastkey.,
88 info->lastkey_lengthcxx . . $ st_myisam_info#lastkey_length.,flag,
89 info->scxx . . $ st_myisam_info#s.->statecxx . . $ st_mi_isam_share#state..key_rootcxx . . $ st_mi_state_info#key_root.[inx]);
90 else
91 error= _mi_searchcxx . . $ _mi_search(11619ded83ef7296).(info,info->scxx . . $ st_myisam_info#s.->keyinfocxx . . $ st_mi_isam_share#keyinfo.+inx,info->lastkeycxx . . $ st_myisam_info#lastkey.,
92 USE_WHOLE_KEYcxx . . $ `storage/myisam/myisamdef.h:319:9`!,flag, info->scxx . . $ st_myisam_info#s.->statecxx . . $ st_mi_isam_share#state..key_rootcxx . . $ st_mi_state_info#key_root.[inx]);
93 }
94 }
95
96 if (!error)
97 {
98 while ((info->scxx . . $ st_myisam_info#s.->concurrent_insertcxx . . $ st_mi_isam_share#concurrent_insert. &&
99 info->lastposcxx . . $ st_myisam_info#lastpos. >= info->statecxx . . $ st_myisam_info#state.->data_file_lengthcxx . . $ st_mi_status_info#data_file_length.) ||
100 (check= mi_check_index_tuplecxx . . $ mi_check_index_tuple(8d6ff5a0859961cd).(info, inx, buf)) == CHECK_NEGcxx . . $ CHECK_NEG.)
101 {
102 /*
103 If we are at the last key on the key page, allow writers to
104 access the index.
105 */
106 if (info->int_keyposcxx . . $ st_myisam_info#int_keypos. >= info->int_maxposcxx . . $ st_myisam_info#int_maxpos. &&
107 mi_yield_and_check_if_killedcxx . . $ mi_yield_and_check_if_killed(34a1a3a12ffdfe3).(info, inx))
108 {
109 error= 1;
110 break;
111 }
112
113 /*
114 Skip rows that are either inserted by other threads since
115 we got a lock or do not match pushed index conditions
116 */
117 if ((error=_mi_search_nextcxx . . $ _mi_search_next(11619ded83ef7296).(info,info->scxx . . $ st_myisam_info#s.->keyinfocxx . . $ st_mi_isam_share#keyinfo.+inx,
118 info->lastkeycxx . . $ st_myisam_info#lastkey.,
119 info->lastkey_lengthcxx . . $ st_myisam_info#lastkey_length.,
120 SEARCH_BIGGERcxx . . $ `include/my_base.h:585:9`!,
121 info->scxx . . $ st_myisam_info#s.->statecxx . . $ st_mi_isam_share#state..key_rootcxx . . $ st_mi_state_info#key_root.[inx])))
122 break;
123 }
124 }
125
126 if (info->scxx . . $ st_myisam_info#s.->concurrent_insertcxx . . $ st_mi_isam_share#concurrent_insert.)
127 mysql_rwlock_unlockcxx . . $ `include/mysql/psi/mysql_thread.h:535:9`!(&info->s->key_root_lock[inx]);
128
129 /* Don't clear if database-changed */
130 info->updatecxx . . $ st_myisam_info#update.&= (HA_STATE_CHANGEDcxx . . $ `include/my_base.h:617:9`! | HA_STATE_ROW_CHANGEDcxx . . $ `include/my_base.h:627:9`!);
131 info->updatecxx . . $ st_myisam_info#update.|= update_mask;
132
133 if (error || check != CHECK_POScxx . . $ CHECK_POS.)
134 {
135 fast_mi_writeinfocxx . . $ `storage/myisam/myisamdef.h:672:9`!(info);
136 if (my_errnocxx . . $ `include/my_pthread.h:720:9`! == HA_ERR_KEY_NOT_FOUNDcxx . . $ `include/my_base.h:466:9`!)
137 my_errnocxx . . $ `include/my_pthread.h:720:9`!=HA_ERR_END_OF_FILEcxx . . $ `include/my_base.h:482:9`!;
138 }
139 else if (!buf)
140 {
141 fast_mi_writeinfocxx . . $ `storage/myisam/myisamdef.h:672:9`!(info);
142 DBUG_RETURNcxx . . $ `include/my_dbug.h:168:9`!(info->lastpos==HA_OFFSET_ERRORcxx . . $ `include/my_base.h:695:9`! ? my_errnocxx . . $ `include/my_pthread.h:720:9`! : 0);
143 }
144 else if (!(*info->read_recordcxx . . $ st_myisam_info#read_record.)(info,info->lastposcxx . . $ st_myisam_info#lastpos.,buf))
145 {
146 info->updatecxx . . $ st_myisam_info#update.|= HA_STATE_AKTIVcxx . . $ `include/my_base.h:618:9`!; /* Record is read */
147 DBUG_RETURNcxx . . $ `include/my_dbug.h:168:9`!(0);
148 }
149 DBUG_PRINTcxx . . $ `include/my_dbug.h:174:9`!("error",("Got error: %d, errno: %d",error, my_errno));
150 DBUG_RETURNcxx . . $ `include/my_dbug.h:168:9`!(my_errnocxx . . $ `include/my_pthread.h:720:9`!);
151 } /* mi_rnext */