~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mi_preload.c

  • Committer: Monty Taylor
  • Date: 2008-08-02 00:06:32 UTC
  • mto: (236.1.42 codestyle)
  • mto: This revision was merged to the branch mainline in revision 261.
  • Revision ID: monty@inaugust.com-20080802000632-jsse0zdd9r6ic5ku
Actually turn gettext on...

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
41
38
    of the table will be preloaded.
42
39
*/
43
40
 
44
 
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)
45
42
{
46
 
  uint32_t i;
47
 
  uint32_t length, block_length= 0;
48
 
  unsigned char *buff= NULL;
 
43
  uint i;
 
44
  ulong length, block_length= 0;
 
45
  uchar *buff= NULL;
49
46
  MYISAM_SHARE* share= info->s;
50
 
  uint32_t keys= share->state.header.keys;
 
47
  uint 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= (uchar *) 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))
85
 
      length= (uint32_t) (key_file_length-pos);
86
 
    if (my_pread(share->kfile, (unsigned char*) buff, length, pos, MYF(MY_FAE|MY_FNABP)))
 
81
    if ((my_off_t) length > (key_file_length-pos))
 
82
      length= (ulong) (key_file_length-pos);
 
83
    if (my_pread(share->kfile, (uchar*) buff, length, pos, MYF(MY_FAE|MY_FNABP)))
87
84
      goto err;
88
85
 
89
86
    if (ignore_leaves)
90
87
    {
91
 
      unsigned char *end= buff+length;
 
88
      uchar *end= buff+length;
92
89
      do
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
 
                              (unsigned char*) buff, block_length))
 
95
                              (uchar*) buff, block_length))
99
96
            goto err;
100
97
        }
101
98
        pos+= block_length;
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
 
                           (unsigned char*) buff, length))
 
107
                           (uchar*) buff, length))
111
108
        goto err;
112
109
      pos+= length;
113
110
    }
114
111
  }
115
112
  while (pos != key_file_length);
116
113
 
117
 
  free((char*) buff);
 
114
  my_free((char*) buff, MYF(0));
118
115
  return(0);
119
116
 
120
117
err:
121
 
  free((char*) buff);
122
 
  return(errno= errno);
 
118
  my_free((char*) buff, MYF(MY_ALLOW_ZERO_PTR));
 
119
  return(my_errno= errno);
123
120
}
124
121