~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mi_preload.c

  • Committer: Monty Taylor
  • Date: 2008-10-16 06:32:30 UTC
  • mto: (511.1.5 codestyle)
  • mto: This revision was merged to the branch mainline in revision 521.
  • Revision ID: monty@inaugust.com-20081016063230-4brxsra0qsmsg84q
Added -Wunused-macros.

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