~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to plugin/myisam/mi_rnext.cc

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-03-18 12:12:31 UTC
  • Revision ID: james.westby@ubuntu.com-20100318121231-k6g1xe6cshbwa0f8
Tags: upstream-2010.03.1347
ImportĀ upstreamĀ versionĀ 2010.03.1347

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 "myisam_priv.h"
 
17
 
 
18
using namespace drizzled;
 
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, unsigned char *buf, int inx)
 
28
{
 
29
  int error,changed;
 
30
  uint32_t flag;
 
31
  int res= 0;
 
32
 
 
33
  if ((inx = _mi_check_index(info,inx)) < 0)
 
34
    return(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
    return(errno);
 
41
  if (info->s->concurrent_insert)
 
42
    pthread_rwlock_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
    case HA_KEY_ALG_BTREE:
 
48
    default:
 
49
      error=_mi_search_first(info,info->s->keyinfo+inx,
 
50
                           info->s->state.key_root[inx]);
 
51
      break;
 
52
    }
 
53
  }
 
54
  else
 
55
  {
 
56
    switch (info->s->keyinfo[inx].key_alg) {
 
57
    case HA_KEY_ALG_BTREE:
 
58
    default:
 
59
      if (!changed)
 
60
        error= _mi_search_next(info,info->s->keyinfo+inx,info->lastkey,
 
61
                               info->lastkey_length,flag,
 
62
                               info->s->state.key_root[inx]);
 
63
      else
 
64
        error= _mi_search(info,info->s->keyinfo+inx,info->lastkey,
 
65
                          USE_WHOLE_KEY,flag, info->s->state.key_root[inx]);
 
66
    }
 
67
  }
 
68
 
 
69
  if (!error)
 
70
  {
 
71
    while ((info->s->concurrent_insert &&
 
72
            info->lastpos >= info->state->data_file_length) ||
 
73
           (info->index_cond_func &&
 
74
           !(res= mi_check_index_cond(info, inx, buf))))
 
75
    {
 
76
      /* Skip rows inserted by other threads since we got a lock */
 
77
      if  ((error=_mi_search_next(info,info->s->keyinfo+inx,
 
78
                                  info->lastkey,
 
79
                                  info->lastkey_length,
 
80
                                  SEARCH_BIGGER,
 
81
                                  info->s->state.key_root[inx])))
 
82
        break;
 
83
    }
 
84
    if (!error && res == 2)
 
85
    {
 
86
      if (info->s->concurrent_insert)
 
87
        pthread_rwlock_unlock(&info->s->key_root_lock[inx]);
 
88
      info->lastpos= HA_OFFSET_ERROR;
 
89
      return(errno= HA_ERR_END_OF_FILE);
 
90
    }
 
91
  }
 
92
 
 
93
  if (info->s->concurrent_insert)
 
94
    pthread_rwlock_unlock(&info->s->key_root_lock[inx]);
 
95
 
 
96
        /* Don't clear if database-changed */
 
97
  info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED);
 
98
  info->update|= HA_STATE_NEXT_FOUND;
 
99
 
 
100
  if (error)
 
101
  {
 
102
    if (errno == HA_ERR_KEY_NOT_FOUND)
 
103
      errno=HA_ERR_END_OF_FILE;
 
104
  }
 
105
  else if (!buf)
 
106
  {
 
107
    return(info->lastpos==HA_OFFSET_ERROR ? errno : 0);
 
108
  }
 
109
  else if (!(*info->read_record)(info,info->lastpos,buf))
 
110
  {
 
111
    info->update|= HA_STATE_AKTIV;              /* Record is read */
 
112
    return(0);
 
113
  }
 
114
  return(errno);
 
115
} /* mi_rnext */