~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mi_preload.c

Merged vcol stuff.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
   You should have received a copy of the GNU General Public License
13
13
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
/*
17
17
  Preload indexes into key cache
18
18
*/
19
19
 
20
 
#include "myisam_priv.h"
21
 
#include <stdlib.h>
22
 
#include <drizzled/util/test.h>
 
20
#include "myisamdef.h"
23
21
 
24
 
using namespace drizzled;
25
22
 
26
23
/*
27
24
  Preload pages of the index file for a table into the key cache
29
26
  SYNOPSIS
30
27
    mi_preload()
31
28
      info          open table
32
 
      map           map of indexes to preload into key cache
 
29
      map           map of indexes to preload into key cache 
33
30
      ignore_leaves only non-leaves pages are to be preloaded
34
31
 
35
32
  RETURN VALUE
49
46
  MYISAM_SHARE* share= info->s;
50
47
  uint32_t keys= share->state.header.keys;
51
48
  MI_KEYDEF *keyinfo= share->keyinfo;
52
 
  internal::my_off_t key_file_length= share->state.state.key_file_length;
53
 
  internal::my_off_t pos= share->base.keystart;
 
49
  my_off_t key_file_length= share->state.state.key_file_length;
 
50
  my_off_t pos= share->base.keystart;
54
51
 
55
52
  if (!keys || !mi_is_any_key_active(key_map) || key_file_length == pos)
56
53
    return(0);
63
60
    for (i= 1 ; i < keys ; i++)
64
61
    {
65
62
      if (keyinfo[i].block_length != block_length)
66
 
        return(errno= HA_ERR_NON_UNIQUE_BLOCK_SIZE);
 
63
        return(my_errno= HA_ERR_NON_UNIQUE_BLOCK_SIZE);
67
64
    }
68
65
  }
69
66
  else
70
 
    block_length= share->getKeyCache()->key_cache_block_size;
 
67
    block_length= share->key_cache->key_cache_block_size;
71
68
 
72
69
  length= info->preload_buff_size/block_length * block_length;
73
70
  set_if_bigger(length, block_length);
74
71
 
75
 
  if (!(buff= (unsigned char *) malloc(length)))
76
 
    return(errno= HA_ERR_OUT_OF_MEM);
 
72
  if (!(buff= (unsigned char *) my_malloc(length, MYF(MY_WME))))
 
73
    return(my_errno= HA_ERR_OUT_OF_MEM);
77
74
 
78
 
  if (flush_key_blocks(share->getKeyCache(), share->kfile, FLUSH_RELEASE))
 
75
  if (flush_key_blocks(share->key_cache,share->kfile, FLUSH_RELEASE))
79
76
    goto err;
80
77
 
81
78
  do
82
79
  {
83
80
    /* Read the next block of index file into the preload buffer */
84
 
    if ((internal::my_off_t) length > (key_file_length-pos))
 
81
    if ((my_off_t) length > (key_file_length-pos))
85
82
      length= (uint32_t) (key_file_length-pos);
86
83
    if (my_pread(share->kfile, (unsigned char*) buff, length, pos, MYF(MY_FAE|MY_FNABP)))
87
84
      goto err;
93
90
      {
94
91
        if (mi_test_if_nod(buff))
95
92
        {
96
 
          if (key_cache_insert(share->getKeyCache(),
 
93
          if (key_cache_insert(share->key_cache,
97
94
                               share->kfile, pos, DFLT_INIT_HITS,
98
95
                              (unsigned char*) buff, block_length))
99
96
            goto err;
105
102
    }
106
103
    else
107
104
    {
108
 
      if (key_cache_insert(share->getKeyCache(),
 
105
      if (key_cache_insert(share->key_cache,
109
106
                           share->kfile, pos, DFLT_INIT_HITS,
110
107
                           (unsigned char*) buff, length))
111
108
        goto err;
119
116
 
120
117
err:
121
118
  free((char*) buff);
122
 
  return(errno= errno);
 
119
  return(my_errno= errno);
123
120
}
124
121