1
by brian
clean slate |
1 |
/* Copyright (C) 2003, 2005 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
|
|
1802.10.2
by Monty Taylor
Update all of the copyright headers to include the correct address. |
14 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
|
1
by brian
clean slate |
15 |
|
16 |
/*
|
|
17 |
Preload indexes into key cache
|
|
18 |
*/
|
|
19 |
||
1130.3.28
by Monty Taylor
Moved heapdef.h and myisamdef.h to *_priv.h for easier filtering for include guard check. |
20 |
#include "myisam_priv.h" |
1241.9.1
by Monty Taylor
Removed global.h. Fixed all the headers. |
21 |
#include <stdlib.h> |
492.1.7
by Monty Taylor
Moved test() to its own file. |
22 |
#include <drizzled/util/test.h> |
23 |
||
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
24 |
using namespace drizzled; |
1
by brian
clean slate |
25 |
|
26 |
/*
|
|
27 |
Preload pages of the index file for a table into the key cache
|
|
28 |
||
29 |
SYNOPSIS
|
|
30 |
mi_preload()
|
|
31 |
info open table
|
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
32 |
map map of indexes to preload into key cache
|
1
by brian
clean slate |
33 |
ignore_leaves only non-leaves pages are to be preloaded
|
34 |
||
35 |
RETURN VALUE
|
|
36 |
0 if a success. error code - otherwise.
|
|
37 |
||
38 |
NOTES.
|
|
39 |
At present pages for all indexes are preloaded.
|
|
40 |
In future only pages for indexes specified in the key_map parameter
|
|
41 |
of the table will be preloaded.
|
|
42 |
*/
|
|
43 |
||
281
by Brian Aker
Converted myisam away from my_bool |
44 |
int mi_preload(MI_INFO *info, uint64_t key_map, bool ignore_leaves) |
1
by brian
clean slate |
45 |
{
|
482
by Brian Aker
Remove uint. |
46 |
uint32_t i; |
313
by Brian Aker
Further work with ulong in myisam |
47 |
uint32_t length, block_length= 0; |
481
by Brian Aker
Remove all of uchar. |
48 |
unsigned char *buff= NULL; |
1
by brian
clean slate |
49 |
MYISAM_SHARE* share= info->s; |
482
by Brian Aker
Remove uint. |
50 |
uint32_t keys= share->state.header.keys; |
1
by brian
clean slate |
51 |
MI_KEYDEF *keyinfo= share->keyinfo; |
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
52 |
internal::my_off_t key_file_length= share->state.state.key_file_length; |
53 |
internal::my_off_t pos= share->base.keystart; |
|
1
by brian
clean slate |
54 |
|
55 |
if (!keys || !mi_is_any_key_active(key_map) || key_file_length == pos) |
|
51.1.107
by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE |
56 |
return(0); |
1
by brian
clean slate |
57 |
|
58 |
block_length= keyinfo[0].block_length; |
|
59 |
||
60 |
if (ignore_leaves) |
|
61 |
{
|
|
62 |
/* Check whether all indexes use the same block size */
|
|
63 |
for (i= 1 ; i < keys ; i++) |
|
64 |
{
|
|
65 |
if (keyinfo[i].block_length != block_length) |
|
1241.9.57
by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined. |
66 |
return(errno= HA_ERR_NON_UNIQUE_BLOCK_SIZE); |
1
by brian
clean slate |
67 |
}
|
68 |
}
|
|
69 |
else
|
|
1689.2.15
by Brian Aker
Encapsulate the key cache object in myisam. |
70 |
block_length= share->getKeyCache()->key_cache_block_size; |
1
by brian
clean slate |
71 |
|
72 |
length= info->preload_buff_size/block_length * block_length; |
|
73 |
set_if_bigger(length, block_length); |
|
74 |
||
656.1.25
by Monty Taylor
Removed my_malloc stuff from storage/ |
75 |
if (!(buff= (unsigned char *) malloc(length))) |
1241.9.57
by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined. |
76 |
return(errno= HA_ERR_OUT_OF_MEM); |
1
by brian
clean slate |
77 |
|
1689.2.15
by Brian Aker
Encapsulate the key cache object in myisam. |
78 |
if (flush_key_blocks(share->getKeyCache(), share->kfile, FLUSH_RELEASE)) |
1
by brian
clean slate |
79 |
goto err; |
80 |
||
81 |
do
|
|
82 |
{
|
|
83 |
/* Read the next block of index file into the preload buffer */
|
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
84 |
if ((internal::my_off_t) length > (key_file_length-pos)) |
313
by Brian Aker
Further work with ulong in myisam |
85 |
length= (uint32_t) (key_file_length-pos); |
481
by Brian Aker
Remove all of uchar. |
86 |
if (my_pread(share->kfile, (unsigned char*) buff, length, pos, MYF(MY_FAE|MY_FNABP))) |
1
by brian
clean slate |
87 |
goto err; |
88 |
||
89 |
if (ignore_leaves) |
|
90 |
{
|
|
481
by Brian Aker
Remove all of uchar. |
91 |
unsigned char *end= buff+length; |
1
by brian
clean slate |
92 |
do
|
93 |
{
|
|
94 |
if (mi_test_if_nod(buff)) |
|
95 |
{
|
|
1689.2.15
by Brian Aker
Encapsulate the key cache object in myisam. |
96 |
if (key_cache_insert(share->getKeyCache(), |
1
by brian
clean slate |
97 |
share->kfile, pos, DFLT_INIT_HITS, |
481
by Brian Aker
Remove all of uchar. |
98 |
(unsigned char*) buff, block_length)) |
1
by brian
clean slate |
99 |
goto err; |
100 |
}
|
|
101 |
pos+= block_length; |
|
102 |
}
|
|
103 |
while ((buff+= block_length) != end); |
|
104 |
buff= end-length; |
|
105 |
}
|
|
106 |
else
|
|
107 |
{
|
|
1689.2.15
by Brian Aker
Encapsulate the key cache object in myisam. |
108 |
if (key_cache_insert(share->getKeyCache(), |
1
by brian
clean slate |
109 |
share->kfile, pos, DFLT_INIT_HITS, |
481
by Brian Aker
Remove all of uchar. |
110 |
(unsigned char*) buff, length)) |
1
by brian
clean slate |
111 |
goto err; |
112 |
pos+= length; |
|
113 |
}
|
|
114 |
}
|
|
115 |
while (pos != key_file_length); |
|
116 |
||
477
by Monty Taylor
Removed my_free(). It turns out that it had been def'd to ignore the flags passed to it in the second arg anyway. Gotta love that. |
117 |
free((char*) buff); |
51.1.107
by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE |
118 |
return(0); |
1
by brian
clean slate |
119 |
|
120 |
err: |
|
477
by Monty Taylor
Removed my_free(). It turns out that it had been def'd to ignore the flags passed to it in the second arg anyway. Gotta love that. |
121 |
free((char*) buff); |
1241.9.57
by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined. |
122 |
return(errno= errno); |
1
by brian
clean slate |
123 |
}
|
124 |