~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to storage/myisam/mi_rnext.c

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2000-2004 MySQL AB
 
2
 
 
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.
 
6
 
 
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.
 
11
 
 
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
#include "myisamdef.h"
 
17
 
 
18
#include "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_rnext(MI_INFO *info, uchar *buf, int inx)
 
28
{
 
29
  int error,changed;
 
30
  uint flag;
 
31
  DBUG_ENTER("mi_rnext");
 
32
 
 
33
  if ((inx = _mi_check_index(info,inx)) < 0)
 
34
    DBUG_RETURN(my_errno);
 
35
  flag=SEARCH_BIGGER;                           /* Read next */
 
36
  if (info->lastpos == HA_OFFSET_ERROR && info->update & HA_STATE_PREV_FOUND)
 
37
    flag=0;                                     /* Read first */
 
38
 
 
39
  if (fast_mi_readinfo(info))
 
40
    DBUG_RETURN(my_errno);
 
41
  if (info->s->concurrent_insert)
 
42
    rw_rdlock(&info->s->key_root_lock[inx]);
 
43
  changed=_mi_test_if_changed(info);
 
44
  if (!flag)
 
45
  {
 
46
    switch(info->s->keyinfo[inx].key_alg){
 
47
#ifdef HAVE_RTREE_KEYS
 
48
    case HA_KEY_ALG_RTREE:
 
49
      error=rtree_get_first(info,inx,info->lastkey_length);
 
50
      break;
 
51
#endif
 
52
    case HA_KEY_ALG_BTREE:
 
53
    default:
 
54
      error=_mi_search_first(info,info->s->keyinfo+inx,
 
55
                           info->s->state.key_root[inx]);
 
56
      break;
 
57
    }
 
58
  }
 
59
  else
 
60
  {
 
61
    switch (info->s->keyinfo[inx].key_alg) {
 
62
#ifdef HAVE_RTREE_KEYS
 
63
    case HA_KEY_ALG_RTREE:
 
64
      /*
 
65
        Note that rtree doesn't support that the table
 
66
        may be changed since last call, so we do need
 
67
        to skip rows inserted by other threads like in btree
 
68
      */
 
69
      error= rtree_get_next(info,inx,info->lastkey_length);
 
70
      break;
 
71
#endif
 
72
    case HA_KEY_ALG_BTREE:
 
73
    default:
 
74
      if (!changed)
 
75
        error= _mi_search_next(info,info->s->keyinfo+inx,info->lastkey,
 
76
                               info->lastkey_length,flag,
 
77
                               info->s->state.key_root[inx]);
 
78
      else
 
79
        error= _mi_search(info,info->s->keyinfo+inx,info->lastkey,
 
80
                          USE_WHOLE_KEY,flag, info->s->state.key_root[inx]);
 
81
    }
 
82
  }
 
83
 
 
84
  if (info->s->concurrent_insert)
 
85
  {
 
86
    if (!error)
 
87
    {
 
88
      while (info->lastpos >= info->state->data_file_length)
 
89
      {
 
90
        /* Skip rows inserted by other threads since we got a lock */
 
91
        if  ((error=_mi_search_next(info,info->s->keyinfo+inx,
 
92
                                    info->lastkey,
 
93
                                    info->lastkey_length,
 
94
                                    SEARCH_BIGGER,
 
95
                                    info->s->state.key_root[inx])))
 
96
          break;
 
97
      }
 
98
    }
 
99
    rw_unlock(&info->s->key_root_lock[inx]);
 
100
  }
 
101
        /* Don't clear if database-changed */
 
102
  info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED);
 
103
  info->update|= HA_STATE_NEXT_FOUND;
 
104
 
 
105
  if (error)
 
106
  {
 
107
    if (my_errno == HA_ERR_KEY_NOT_FOUND)
 
108
      my_errno=HA_ERR_END_OF_FILE;
 
109
  }
 
110
  else if (!buf)
 
111
  {
 
112
    DBUG_RETURN(info->lastpos==HA_OFFSET_ERROR ? my_errno : 0);
 
113
  }
 
114
  else if (!(*info->read_record)(info,info->lastpos,buf))
 
115
  {
 
116
    info->update|= HA_STATE_AKTIV;              /* Record is read */
 
117
    DBUG_RETURN(0);
 
118
  }
 
119
  DBUG_PRINT("error",("Got error: %d,  errno: %d",error, my_errno));
 
120
  DBUG_RETURN(my_errno);
 
121
} /* mi_rnext */