~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mi_preload.c

Merged.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
*/
19
19
 
20
20
#include "myisamdef.h"
21
 
#include <drizzled/util/test.h>
22
 
 
23
21
 
24
22
 
25
23
/*
40
38
    of the table will be preloaded.
41
39
*/
42
40
 
43
 
int mi_preload(MI_INFO *info, uint64_t key_map, bool ignore_leaves)
 
41
int mi_preload(MI_INFO *info, uint64_t key_map, my_bool ignore_leaves)
44
42
{
45
 
  uint32_t i;
46
 
  uint32_t length, block_length= 0;
47
 
  unsigned char *buff= NULL;
 
43
  uint i;
 
44
  ulong length, block_length= 0;
 
45
  uchar *buff= NULL;
48
46
  MYISAM_SHARE* share= info->s;
49
 
  uint32_t keys= share->state.header.keys;
 
47
  uint keys= share->state.header.keys;
50
48
  MI_KEYDEF *keyinfo= share->keyinfo;
51
49
  my_off_t key_file_length= share->state.state.key_file_length;
52
50
  my_off_t pos= share->base.keystart;
 
51
  DBUG_ENTER("mi_preload");
53
52
 
54
53
  if (!keys || !mi_is_any_key_active(key_map) || key_file_length == pos)
55
 
    return(0);
 
54
    DBUG_RETURN(0);
56
55
 
57
56
  block_length= keyinfo[0].block_length;
58
57
 
62
61
    for (i= 1 ; i < keys ; i++)
63
62
    {
64
63
      if (keyinfo[i].block_length != block_length)
65
 
        return(my_errno= HA_ERR_NON_UNIQUE_BLOCK_SIZE);
 
64
        DBUG_RETURN(my_errno= HA_ERR_NON_UNIQUE_BLOCK_SIZE);
66
65
    }
67
66
  }
68
67
  else
71
70
  length= info->preload_buff_size/block_length * block_length;
72
71
  set_if_bigger(length, block_length);
73
72
 
74
 
  if (!(buff= (unsigned char *) my_malloc(length, MYF(MY_WME))))
75
 
    return(my_errno= HA_ERR_OUT_OF_MEM);
 
73
  if (!(buff= (uchar *) my_malloc(length, MYF(MY_WME))))
 
74
    DBUG_RETURN(my_errno= HA_ERR_OUT_OF_MEM);
76
75
 
77
76
  if (flush_key_blocks(share->key_cache,share->kfile, FLUSH_RELEASE))
78
77
    goto err;
81
80
  {
82
81
    /* Read the next block of index file into the preload buffer */
83
82
    if ((my_off_t) length > (key_file_length-pos))
84
 
      length= (uint32_t) (key_file_length-pos);
85
 
    if (my_pread(share->kfile, (unsigned char*) buff, length, pos, MYF(MY_FAE|MY_FNABP)))
 
83
      length= (ulong) (key_file_length-pos);
 
84
    if (my_pread(share->kfile, (uchar*) buff, length, pos, MYF(MY_FAE|MY_FNABP)))
86
85
      goto err;
87
86
 
88
87
    if (ignore_leaves)
89
88
    {
90
 
      unsigned char *end= buff+length;
 
89
      uchar *end= buff+length;
91
90
      do
92
91
      {
93
92
        if (mi_test_if_nod(buff))
94
93
        {
95
94
          if (key_cache_insert(share->key_cache,
96
95
                               share->kfile, pos, DFLT_INIT_HITS,
97
 
                              (unsigned char*) buff, block_length))
 
96
                              (uchar*) buff, block_length))
98
97
            goto err;
99
98
        }
100
99
        pos+= block_length;
106
105
    {
107
106
      if (key_cache_insert(share->key_cache,
108
107
                           share->kfile, pos, DFLT_INIT_HITS,
109
 
                           (unsigned char*) buff, length))
 
108
                           (uchar*) buff, length))
110
109
        goto err;
111
110
      pos+= length;
112
111
    }
113
112
  }
114
113
  while (pos != key_file_length);
115
114
 
116
 
  free((char*) buff);
117
 
  return(0);
 
115
  my_free((char*) buff, MYF(0));
 
116
  DBUG_RETURN(0);
118
117
 
119
118
err:
120
 
  free((char*) buff);
121
 
  return(my_errno= errno);
 
119
  my_free((char*) buff, MYF(MY_ALLOW_ZERO_PTR));
 
120
  DBUG_RETURN(my_errno= errno);
122
121
}
123
122