2001-12-06 13:10:51 +01:00
|
|
|
/* Copyright (C) 2000 MySQL AB
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2006-12-23 20:17:15 +01:00
|
|
|
the Free Software Foundation; version 2 of the License.
|
2001-12-06 13:10:51 +01:00
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
2001-01-27 10:24:05 +01:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2001-12-06 13:10:51 +01:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
2001-01-27 10:24:05 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
Handling of uchar arrays as large bitmaps.
|
2003-10-30 19:17:57 +01:00
|
|
|
|
|
|
|
API limitations (or, rather asserted safety assumptions,
|
|
|
|
to encourage correct programming)
|
|
|
|
|
|
|
|
* the size of the used bitmap is less than ~(uint) 0
|
|
|
|
* it's a multiple of 8 (for efficiency reasons)
|
|
|
|
* when arguments are a bitmap and a bit number, the number
|
|
|
|
must be within bitmap size
|
|
|
|
* bitmap_set_prefix() is an exception - one can use ~0 to set all bits
|
|
|
|
* when both arguments are bitmaps, they must be of the same size
|
2003-10-30 21:04:09 +01:00
|
|
|
* bitmap_intersect() is an exception :)
|
|
|
|
(for for Bitmap::intersect(ulonglong map2buff))
|
2005-03-09 19:22:30 +01:00
|
|
|
|
|
|
|
If THREAD is defined all bitmap operations except bitmap_init/bitmap_free
|
2004-05-29 00:04:01 +02:00
|
|
|
are thread-safe.
|
2001-01-31 03:47:25 +01:00
|
|
|
|
|
|
|
TODO:
|
2001-02-07 16:42:20 +01:00
|
|
|
Make assembler THREAD safe versions of these using test-and-set instructions
|
2001-01-27 10:24:05 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "mysys_priv.h"
|
|
|
|
#include <my_bitmap.h>
|
2001-12-21 06:00:58 +01:00
|
|
|
#include <m_string.h>
|
2001-01-27 10:24:05 +01:00
|
|
|
|
2006-02-24 17:34:15 +01:00
|
|
|
static inline void bitmap_lock(MY_BITMAP *map __attribute__((unused)))
|
2001-12-13 02:55:33 +01:00
|
|
|
{
|
|
|
|
#ifdef THREAD
|
2003-10-24 22:44:48 +02:00
|
|
|
if (map->mutex)
|
|
|
|
pthread_mutex_lock(map->mutex);
|
2001-12-13 02:55:33 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2006-02-24 17:34:15 +01:00
|
|
|
static inline void bitmap_unlock(MY_BITMAP *map __attribute__((unused)))
|
2001-12-13 02:55:33 +01:00
|
|
|
{
|
|
|
|
#ifdef THREAD
|
2003-10-24 22:44:48 +02:00
|
|
|
if (map->mutex)
|
|
|
|
pthread_mutex_unlock(map->mutex);
|
2001-12-13 02:55:33 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2003-11-18 12:47:27 +01:00
|
|
|
|
|
|
|
my_bool bitmap_init(MY_BITMAP *map, uchar *buf, uint bitmap_size,
|
|
|
|
my_bool thread_safe)
|
2001-02-07 16:42:20 +01:00
|
|
|
{
|
2003-11-18 12:47:27 +01:00
|
|
|
DBUG_ENTER("bitmap_init");
|
|
|
|
|
2003-10-24 22:44:48 +02:00
|
|
|
DBUG_ASSERT((bitmap_size & 7) == 0);
|
|
|
|
bitmap_size/=8;
|
2003-10-11 13:06:55 +02:00
|
|
|
if (!(map->bitmap=buf) &&
|
2003-11-18 12:47:27 +01:00
|
|
|
!(map->bitmap= (uchar*) my_malloc(bitmap_size +
|
|
|
|
(thread_safe ?
|
|
|
|
sizeof(pthread_mutex_t) : 0),
|
|
|
|
MYF(MY_WME | MY_ZEROFILL))))
|
2006-01-03 17:54:54 +01:00
|
|
|
DBUG_RETURN(1);
|
2003-10-24 22:44:48 +02:00
|
|
|
map->bitmap_size=bitmap_size;
|
2001-02-07 16:42:20 +01:00
|
|
|
#ifdef THREAD
|
2003-10-24 22:44:48 +02:00
|
|
|
if (thread_safe)
|
|
|
|
{
|
|
|
|
map->mutex=(pthread_mutex_t *)(map->bitmap+bitmap_size);
|
|
|
|
pthread_mutex_init(map->mutex, MY_MUTEX_INIT_FAST);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
map->mutex=0;
|
2001-02-07 16:42:20 +01:00
|
|
|
#endif
|
2003-11-18 12:47:27 +01:00
|
|
|
DBUG_RETURN(0);
|
2001-02-07 16:42:20 +01:00
|
|
|
}
|
|
|
|
|
2003-11-18 12:47:27 +01:00
|
|
|
|
2001-02-07 22:27:19 +01:00
|
|
|
void bitmap_free(MY_BITMAP *map)
|
2001-02-07 16:42:20 +01:00
|
|
|
{
|
2003-11-18 12:47:27 +01:00
|
|
|
DBUG_ENTER("bitmap_free");
|
2001-02-07 16:42:20 +01:00
|
|
|
if (map->bitmap)
|
|
|
|
{
|
2003-11-18 12:47:27 +01:00
|
|
|
#ifdef THREAD
|
|
|
|
if (map->mutex)
|
|
|
|
pthread_mutex_destroy(map->mutex);
|
|
|
|
#endif
|
2001-02-07 16:42:20 +01:00
|
|
|
my_free((char*) map->bitmap, MYF(0));
|
|
|
|
map->bitmap=0;
|
|
|
|
}
|
2003-11-18 12:47:27 +01:00
|
|
|
DBUG_VOID_RETURN;
|
2001-02-07 16:42:20 +01:00
|
|
|
}
|
|
|
|
|
2003-11-18 12:47:27 +01:00
|
|
|
|
2001-02-07 22:27:19 +01:00
|
|
|
void bitmap_set_bit(MY_BITMAP *map, uint bitmap_bit)
|
2001-01-31 03:47:25 +01:00
|
|
|
{
|
2003-10-24 22:44:48 +02:00
|
|
|
DBUG_ASSERT(map->bitmap && bitmap_bit < map->bitmap_size*8);
|
|
|
|
bitmap_lock(map);
|
2004-05-16 13:48:32 +02:00
|
|
|
bitmap_fast_set_bit(map, bitmap_bit);
|
2003-10-24 22:44:48 +02:00
|
|
|
bitmap_unlock(map);
|
2001-01-31 03:47:25 +01:00
|
|
|
}
|
2001-01-27 10:24:05 +01:00
|
|
|
|
2003-11-18 12:47:27 +01:00
|
|
|
|
2005-07-01 06:05:42 +02:00
|
|
|
/*
|
|
|
|
test if bit already set and set it if it was not (thread unsafe method)
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
bitmap_fast_test_and_set()
|
|
|
|
MAP bit map struct
|
|
|
|
BIT bit number
|
|
|
|
|
|
|
|
RETURN
|
|
|
|
0 bit was not set
|
|
|
|
!=0 bit was set
|
|
|
|
*/
|
|
|
|
|
|
|
|
my_bool bitmap_fast_test_and_set(MY_BITMAP *map, uint bitmap_bit)
|
|
|
|
{
|
2006-12-14 23:51:37 +01:00
|
|
|
uchar *value= map->bitmap + (bitmap_bit / 8);
|
2005-07-01 06:05:42 +02:00
|
|
|
uchar bit= 1 << ((bitmap_bit) & 7);
|
2006-12-14 23:51:37 +01:00
|
|
|
uchar res= (*value) & bit;
|
|
|
|
*value|= bit;
|
2005-07-01 06:05:42 +02:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
test if bit already set and set it if it was not (thread safe method)
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
bitmap_fast_test_and_set()
|
|
|
|
map bit map struct
|
|
|
|
bitmap_bit bit number
|
|
|
|
|
|
|
|
RETURN
|
|
|
|
0 bit was not set
|
|
|
|
!=0 bit was set
|
|
|
|
*/
|
|
|
|
|
|
|
|
my_bool bitmap_test_and_set(MY_BITMAP *map, uint bitmap_bit)
|
|
|
|
{
|
|
|
|
my_bool res;
|
|
|
|
DBUG_ASSERT(map->bitmap && bitmap_bit < map->bitmap_size*8);
|
|
|
|
bitmap_lock(map);
|
|
|
|
res= bitmap_fast_test_and_set(map, bitmap_bit);
|
|
|
|
bitmap_unlock(map);
|
2005-07-18 14:33:18 +02:00
|
|
|
return res;
|
2005-07-01 06:05:42 +02:00
|
|
|
}
|
|
|
|
|
2001-02-07 22:27:19 +01:00
|
|
|
uint bitmap_set_next(MY_BITMAP *map)
|
2001-01-31 03:47:25 +01:00
|
|
|
{
|
2001-02-07 16:42:20 +01:00
|
|
|
uchar *bitmap=map->bitmap;
|
2001-01-27 10:24:05 +01:00
|
|
|
uint bit_found = MY_BIT_NONE;
|
BUG#21206: memory corruption when too many cursors are opened at once
Too many cursors (more than 1024) could lead to memory corruption.
This affects both, stored routines and C API cursors, and the
threshold is per-server, not per-connection. Similarly, the
corruption could happen when the server was under heavy load
(executing more than 1024 simultaneous complex queries), and this is
the reason why this bug is fixed in 4.1, which doesn't support
cursors.
The corruption was caused by a bug in the temporary tables code, when
an attempt to create a table could lead to a write beyond allocated
space. Note, that only internal tables were affected (the tables
created internally by the server to resolve the query), not tables
created with CREATE TEMPORARY TABLE. Another pre-condition for the
bug is TRUE value of --temp-pool startup option, which, however, is a
default.
The cause of a bug was that random memory was overwritten in
bitmap_set_next() due to out-of-bound memory access.
mysys/my_bitmap.c:
Local 'bitmap_size' is measured in bytes, no need to multiply it by 8.
sql/sql_select.cc:
Clear the temp_pool_slot bit only if we have set it previously.
2006-07-26 14:23:07 +02:00
|
|
|
uint bitmap_size=map->bitmap_size;
|
2001-01-31 03:47:25 +01:00
|
|
|
uint i;
|
2001-01-27 10:24:05 +01:00
|
|
|
|
2003-10-11 13:06:55 +02:00
|
|
|
DBUG_ASSERT(map->bitmap);
|
2001-12-13 02:55:33 +01:00
|
|
|
bitmap_lock(map);
|
2001-01-31 03:47:25 +01:00
|
|
|
for (i=0; i < bitmap_size ; i++, bitmap++)
|
|
|
|
{
|
|
|
|
if (*bitmap != 0xff)
|
|
|
|
{ /* Found slot with free bit */
|
|
|
|
uint b;
|
|
|
|
for (b=0; ; b++)
|
|
|
|
{
|
|
|
|
if (!(*bitmap & (1 << b)))
|
|
|
|
{
|
|
|
|
*bitmap |= 1<<b;
|
|
|
|
bit_found = (i*8)+b;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break; /* Found bit */
|
|
|
|
}
|
|
|
|
}
|
2001-12-13 02:55:33 +01:00
|
|
|
bitmap_unlock(map);
|
2001-01-27 10:24:05 +01:00
|
|
|
return bit_found;
|
2001-01-31 03:47:25 +01:00
|
|
|
}
|
|
|
|
|
2003-11-18 12:47:27 +01:00
|
|
|
|
2001-02-07 22:27:19 +01:00
|
|
|
void bitmap_clear_bit(MY_BITMAP *map, uint bitmap_bit)
|
2001-01-31 03:47:25 +01:00
|
|
|
{
|
2003-10-24 22:44:48 +02:00
|
|
|
DBUG_ASSERT(map->bitmap && bitmap_bit < map->bitmap_size*8);
|
|
|
|
bitmap_lock(map);
|
2004-05-16 13:48:32 +02:00
|
|
|
bitmap_fast_clear_bit(map, bitmap_bit);
|
2003-10-24 22:44:48 +02:00
|
|
|
bitmap_unlock(map);
|
2001-01-31 03:47:25 +01:00
|
|
|
}
|
2001-01-27 10:24:05 +01:00
|
|
|
|
2003-11-18 12:47:27 +01:00
|
|
|
|
2003-10-11 13:06:55 +02:00
|
|
|
void bitmap_set_prefix(MY_BITMAP *map, uint prefix_size)
|
|
|
|
{
|
2003-10-24 22:44:48 +02:00
|
|
|
uint prefix_bytes, prefix_bits;
|
2003-10-11 13:06:55 +02:00
|
|
|
|
2003-10-30 19:17:57 +01:00
|
|
|
DBUG_ASSERT(map->bitmap &&
|
2003-11-18 12:47:27 +01:00
|
|
|
(prefix_size <= map->bitmap_size*8 || prefix_size == (uint) ~0));
|
2003-10-11 13:06:55 +02:00
|
|
|
bitmap_lock(map);
|
2003-10-24 22:44:48 +02:00
|
|
|
set_if_smaller(prefix_size, map->bitmap_size*8);
|
|
|
|
if ((prefix_bytes= prefix_size / 8))
|
|
|
|
memset(map->bitmap, 0xff, prefix_bytes);
|
|
|
|
if ((prefix_bits= prefix_size & 7))
|
|
|
|
map->bitmap[prefix_bytes++]= (1 << prefix_bits)-1;
|
|
|
|
if (prefix_bytes < map->bitmap_size)
|
|
|
|
bzero(map->bitmap+prefix_bytes, map->bitmap_size-prefix_bytes);
|
2003-10-11 13:06:55 +02:00
|
|
|
bitmap_unlock(map);
|
|
|
|
}
|
|
|
|
|
2003-11-18 12:47:27 +01:00
|
|
|
|
2003-10-11 13:06:55 +02:00
|
|
|
void bitmap_clear_all(MY_BITMAP *map)
|
|
|
|
{
|
|
|
|
bitmap_set_prefix(map, 0);
|
|
|
|
}
|
|
|
|
|
2003-11-18 12:47:27 +01:00
|
|
|
|
2003-10-11 13:06:55 +02:00
|
|
|
void bitmap_set_all(MY_BITMAP *map)
|
|
|
|
{
|
2003-10-24 22:44:48 +02:00
|
|
|
bitmap_set_prefix(map, ~0);
|
2003-10-11 13:06:55 +02:00
|
|
|
}
|
2001-12-15 04:12:21 +01:00
|
|
|
|
2003-11-18 12:47:27 +01:00
|
|
|
|
2003-10-30 19:17:57 +01:00
|
|
|
my_bool bitmap_is_prefix(const MY_BITMAP *map, uint prefix_size)
|
2001-12-13 02:55:33 +01:00
|
|
|
{
|
2003-10-24 22:44:48 +02:00
|
|
|
uint prefix_bits= prefix_size & 7, res= 0;
|
|
|
|
uchar *m= map->bitmap, *end_prefix= map->bitmap+prefix_size/8,
|
|
|
|
*end= map->bitmap+map->bitmap_size;
|
2003-10-11 13:06:55 +02:00
|
|
|
|
2003-10-24 22:44:48 +02:00
|
|
|
DBUG_ASSERT(map->bitmap && prefix_size <= map->bitmap_size*8);
|
2003-10-11 13:06:55 +02:00
|
|
|
|
2003-11-03 13:55:25 +01:00
|
|
|
bitmap_lock((MY_BITMAP *)map);
|
2003-10-24 22:44:48 +02:00
|
|
|
while (m < end_prefix)
|
|
|
|
if (*m++ != 0xff)
|
2003-10-11 13:06:55 +02:00
|
|
|
goto ret;
|
|
|
|
|
2003-10-24 22:44:48 +02:00
|
|
|
if (prefix_bits && *m++ != (1 << prefix_bits)-1)
|
2003-10-11 13:06:55 +02:00
|
|
|
goto ret;
|
|
|
|
|
2003-10-24 22:44:48 +02:00
|
|
|
while (m < end)
|
2003-10-30 19:17:57 +01:00
|
|
|
if (*m++ != 0)
|
2003-10-11 13:06:55 +02:00
|
|
|
goto ret;
|
|
|
|
|
|
|
|
res=1;
|
|
|
|
ret:
|
2003-11-03 13:55:25 +01:00
|
|
|
bitmap_unlock((MY_BITMAP *)map);
|
2003-10-11 13:06:55 +02:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2003-11-18 12:47:27 +01:00
|
|
|
|
2003-10-30 19:17:57 +01:00
|
|
|
my_bool bitmap_is_clear_all(const MY_BITMAP *map)
|
2003-10-11 13:06:55 +02:00
|
|
|
{
|
|
|
|
return bitmap_is_prefix(map, 0);
|
|
|
|
}
|
|
|
|
|
2003-10-30 19:17:57 +01:00
|
|
|
my_bool bitmap_is_set_all(const MY_BITMAP *map)
|
2003-10-11 13:06:55 +02:00
|
|
|
{
|
2003-10-24 22:44:48 +02:00
|
|
|
return bitmap_is_prefix(map, map->bitmap_size*8);
|
2001-12-13 02:55:33 +01:00
|
|
|
}
|
|
|
|
|
2003-11-18 12:47:27 +01:00
|
|
|
|
2003-10-30 19:17:57 +01:00
|
|
|
my_bool bitmap_is_set(const MY_BITMAP *map, uint bitmap_bit)
|
2001-12-13 02:55:33 +01:00
|
|
|
{
|
2003-10-24 22:44:48 +02:00
|
|
|
DBUG_ASSERT(map->bitmap && bitmap_bit < map->bitmap_size*8);
|
2004-05-16 13:48:32 +02:00
|
|
|
return bitmap_fast_is_set(map, bitmap_bit);
|
2003-10-11 13:06:55 +02:00
|
|
|
}
|
|
|
|
|
2003-11-18 12:47:27 +01:00
|
|
|
|
2003-10-30 19:17:57 +01:00
|
|
|
my_bool bitmap_is_subset(const MY_BITMAP *map1, const MY_BITMAP *map2)
|
2003-10-11 13:06:55 +02:00
|
|
|
{
|
2003-11-18 12:47:27 +01:00
|
|
|
uint res=0;
|
2003-10-24 22:44:48 +02:00
|
|
|
uchar *m1=map1->bitmap, *m2=map2->bitmap, *end;
|
2003-10-11 13:06:55 +02:00
|
|
|
|
2003-10-24 22:44:48 +02:00
|
|
|
DBUG_ASSERT(map1->bitmap && map2->bitmap &&
|
|
|
|
map1->bitmap_size==map2->bitmap_size);
|
2003-11-03 13:55:25 +01:00
|
|
|
bitmap_lock((MY_BITMAP *)map1);
|
|
|
|
bitmap_lock((MY_BITMAP *)map2);
|
2003-10-11 13:06:55 +02:00
|
|
|
|
2003-10-24 22:44:48 +02:00
|
|
|
end= m1+map1->bitmap_size;
|
2003-10-11 13:06:55 +02:00
|
|
|
|
2003-10-24 22:44:48 +02:00
|
|
|
while (m1 < end)
|
2003-11-18 12:47:27 +01:00
|
|
|
{
|
2003-10-11 13:06:55 +02:00
|
|
|
if ((*m1++) & ~(*m2++))
|
|
|
|
goto ret;
|
2003-11-18 12:47:27 +01:00
|
|
|
}
|
2003-10-11 13:06:55 +02:00
|
|
|
|
|
|
|
res=1;
|
|
|
|
ret:
|
2003-11-03 13:55:25 +01:00
|
|
|
bitmap_unlock((MY_BITMAP *)map2);
|
|
|
|
bitmap_unlock((MY_BITMAP *)map1);
|
2003-10-11 13:06:55 +02:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2003-11-18 12:47:27 +01:00
|
|
|
|
2003-10-30 19:17:57 +01:00
|
|
|
my_bool bitmap_cmp(const MY_BITMAP *map1, const MY_BITMAP *map2)
|
2003-10-11 13:06:55 +02:00
|
|
|
{
|
|
|
|
uint res;
|
|
|
|
|
2003-10-24 22:44:48 +02:00
|
|
|
DBUG_ASSERT(map1->bitmap && map2->bitmap &&
|
|
|
|
map1->bitmap_size==map2->bitmap_size);
|
2003-11-03 13:55:25 +01:00
|
|
|
bitmap_lock((MY_BITMAP *)map1);
|
|
|
|
bitmap_lock((MY_BITMAP *)map2);
|
2003-10-11 13:06:55 +02:00
|
|
|
|
2003-10-24 22:44:48 +02:00
|
|
|
res= memcmp(map1->bitmap, map2->bitmap, map1->bitmap_size)==0;
|
2003-10-11 13:06:55 +02:00
|
|
|
|
2003-11-03 13:55:25 +01:00
|
|
|
bitmap_unlock((MY_BITMAP *)map2);
|
|
|
|
bitmap_unlock((MY_BITMAP *)map1);
|
2003-10-11 13:06:55 +02:00
|
|
|
return res;
|
2001-12-13 02:55:33 +01:00
|
|
|
}
|
|
|
|
|
2003-11-18 12:47:27 +01:00
|
|
|
|
2003-10-30 19:17:57 +01:00
|
|
|
void bitmap_intersect(MY_BITMAP *map, const MY_BITMAP *map2)
|
2001-12-13 02:55:33 +01:00
|
|
|
{
|
2003-10-24 22:44:48 +02:00
|
|
|
uchar *to=map->bitmap, *from=map2->bitmap, *end;
|
2003-11-03 13:55:25 +01:00
|
|
|
uint len=map->bitmap_size, len2=map2->bitmap_size;
|
2003-10-11 13:06:55 +02:00
|
|
|
|
2003-10-30 21:04:09 +01:00
|
|
|
DBUG_ASSERT(map->bitmap && map2->bitmap);
|
2001-12-13 02:55:33 +01:00
|
|
|
bitmap_lock(map);
|
2003-11-03 13:55:25 +01:00
|
|
|
bitmap_lock((MY_BITMAP *)map2);
|
2003-10-11 13:06:55 +02:00
|
|
|
|
2003-10-30 21:04:09 +01:00
|
|
|
end= to+min(len,len2);
|
2003-10-11 13:06:55 +02:00
|
|
|
|
2003-10-24 22:44:48 +02:00
|
|
|
while (to < end)
|
|
|
|
*to++ &= *from++;
|
2003-10-11 13:06:55 +02:00
|
|
|
|
2003-10-30 21:04:09 +01:00
|
|
|
if (len2 < len)
|
|
|
|
{
|
|
|
|
end+=len-len2;
|
|
|
|
while (to < end)
|
|
|
|
*to++=0;
|
|
|
|
}
|
|
|
|
|
2003-11-03 13:55:25 +01:00
|
|
|
bitmap_unlock((MY_BITMAP *)map2);
|
2001-12-13 02:55:33 +01:00
|
|
|
bitmap_unlock(map);
|
|
|
|
}
|
2003-10-11 13:06:55 +02:00
|
|
|
|
2003-11-18 12:47:27 +01:00
|
|
|
|
Bug#10932 - Building server with key limit of 128, makes test cases fail
This patch allows to configure MyISAM for 128 indexes per table.
The main problem is the key_map, wich is implemented as an ulonglong.
To get rid of the limit and keep the efficient and flexible
implementation, the highest bit is now used for all upper keys.
This means that the lower keys can be disabled and enabled
individually as usual and the high keys can only be disabled and
enabled as a block. That way the existing test suite is still
applicable, while more keys work, though slightly less efficient.
To really get more than 64 keys, some defines need to be changed.
Another patch will address this.
include/my_bitmap.h:
Bug#10932 - Building server with key limit of 128, makes test cases fail
Added the declaration for a function that extends the highest bit value
to all upper bits of a bigger bitmap.
include/myisam.h:
Bug#10932 - Building server with key limit of 128, makes test cases fail
Changed MI_MAX_POSSIBLE_KEY to what it was meant for.
Added a bunch of macros to handle the MyISAM key_map.
myisam/mi_check.c:
Bug#10932 - Building server with key limit of 128, makes test cases fail
Changed key_map access to use the new macros.
myisam/mi_create.c:
Bug#10932 - Building server with key limit of 128, makes test cases fail
Changed key_map access to use the new macros.
myisam/mi_delete.c:
Bug#10932 - Building server with key limit of 128, makes test cases fail
Changed key_map access to use the new macros.
myisam/mi_extra.c:
Bug#10932 - Building server with key limit of 128, makes test cases fail
Changed key_map access to use the new macros.
myisam/mi_open.c:
Bug#10932 - Building server with key limit of 128, makes test cases fail
Changed key_map access to use the new macros.
Changed pointer types from signed char* to unsigned char*.
myisam/mi_preload.c:
Bug#10932 - Building server with key limit of 128, makes test cases fail
Changed key_map access to use the new macros.
myisam/mi_rsame.c:
Bug#10932 - Building server with key limit of 128, makes test cases fail
Changed key_map access to use the new macros.
myisam/mi_rsamepos.c:
Bug#10932 - Building server with key limit of 128, makes test cases fail
Changed key_map access to use the new macros.
myisam/mi_search.c:
Bug#10932 - Building server with key limit of 128, makes test cases fail
Changed key_map access to use the new macros.
myisam/mi_update.c:
Bug#10932 - Building server with key limit of 128, makes test cases fail
Changed key_map access to use the new macros.
myisam/mi_write.c:
Bug#10932 - Building server with key limit of 128, makes test cases fail
Changed key_map access to use the new macros.
myisam/myisamchk.c:
Bug#10932 - Building server with key limit of 128, makes test cases fail
Changed key_map access to use the new macros.
myisam/myisamdef.h:
Bug#10932 - Building server with key limit of 128, makes test cases fail
Changed pointer types from signed char* to unsigned char*.
myisam/myisamlog.c:
Bug#10932 - Building server with key limit of 128, makes test cases fail
Changed key_map access to use the new macros.
myisam/myisampack.c:
Bug#10932 - Building server with key limit of 128, makes test cases fail
Changed key_map access to use the new macros.
myisam/sort.c:
Bug#10932 - Building server with key limit of 128, makes test cases fail
Changed key_map access to use the new macros.
mysys/my_bitmap.c:
Bug#10932 - Building server with key limit of 128, makes test cases fail
Added a function that extends the highest bit value
to all upper bits of a bigger bitmap.
sql/ha_myisam.cc:
Bug#10932 - Building server with key limit of 128, makes test cases fail
Changed key_map access to use the new macros.
sql/sql_bitmap.h:
Bug#10932 - Building server with key limit of 128, makes test cases fail
Added a method that extends the highest bit value
to all upper bits of a bigger bitmap.
2005-07-19 14:13:56 +02:00
|
|
|
/*
|
|
|
|
Set/clear all bits above a bit.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
bitmap_set_above()
|
|
|
|
map RETURN The bitmap to change.
|
|
|
|
from_byte The bitmap buffer byte offset to start with.
|
|
|
|
use_bit The bit value (1/0) to use for all upper bits.
|
|
|
|
|
|
|
|
NOTE
|
|
|
|
You can only set/clear full bytes.
|
|
|
|
The function is meant for the situation that you copy a smaller bitmap
|
|
|
|
to a bigger bitmap. Bitmap lengths are always multiple of eigth (the
|
|
|
|
size of a byte). Using 'from_byte' saves multiplication and division
|
|
|
|
by eight during parameter passing.
|
|
|
|
|
|
|
|
RETURN
|
|
|
|
void
|
|
|
|
*/
|
|
|
|
|
|
|
|
void bitmap_set_above(MY_BITMAP *map, uint from_byte, uint use_bit)
|
|
|
|
{
|
|
|
|
uchar use_byte= use_bit ? 0xff : 0;
|
|
|
|
uchar *to= map->bitmap + from_byte;
|
|
|
|
uchar *end= map->bitmap + map->bitmap_size;
|
|
|
|
|
|
|
|
while (to < end)
|
|
|
|
*to++= use_byte;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-30 19:17:57 +01:00
|
|
|
void bitmap_subtract(MY_BITMAP *map, const MY_BITMAP *map2)
|
2003-10-11 13:06:55 +02:00
|
|
|
{
|
2003-10-24 22:44:48 +02:00
|
|
|
uchar *to=map->bitmap, *from=map2->bitmap, *end;
|
2003-10-11 13:06:55 +02:00
|
|
|
|
2003-10-24 22:44:48 +02:00
|
|
|
DBUG_ASSERT(map->bitmap && map2->bitmap &&
|
|
|
|
map->bitmap_size==map2->bitmap_size);
|
2003-10-11 13:06:55 +02:00
|
|
|
bitmap_lock(map);
|
2003-11-03 13:55:25 +01:00
|
|
|
bitmap_lock((MY_BITMAP *)map2);
|
2003-10-11 13:06:55 +02:00
|
|
|
|
2003-10-24 22:44:48 +02:00
|
|
|
end= to+map->bitmap_size;
|
2003-10-11 13:06:55 +02:00
|
|
|
|
2003-10-24 22:44:48 +02:00
|
|
|
while (to < end)
|
|
|
|
*to++ &= ~(*from++);
|
2003-10-11 13:06:55 +02:00
|
|
|
|
2003-11-03 13:55:25 +01:00
|
|
|
bitmap_unlock((MY_BITMAP *)map2);
|
2003-10-11 13:06:55 +02:00
|
|
|
bitmap_unlock(map);
|
|
|
|
}
|
|
|
|
|
2003-11-18 12:47:27 +01:00
|
|
|
|
2003-10-30 19:17:57 +01:00
|
|
|
void bitmap_union(MY_BITMAP *map, const MY_BITMAP *map2)
|
2003-10-11 13:06:55 +02:00
|
|
|
{
|
2003-10-24 22:44:48 +02:00
|
|
|
uchar *to=map->bitmap, *from=map2->bitmap, *end;
|
2003-10-11 13:06:55 +02:00
|
|
|
|
2003-10-24 22:44:48 +02:00
|
|
|
DBUG_ASSERT(map->bitmap && map2->bitmap &&
|
|
|
|
map->bitmap_size==map2->bitmap_size);
|
2003-10-11 13:06:55 +02:00
|
|
|
bitmap_lock(map);
|
2003-11-03 13:55:25 +01:00
|
|
|
bitmap_lock((MY_BITMAP *)map2);
|
2003-10-11 13:06:55 +02:00
|
|
|
|
2003-10-24 22:44:48 +02:00
|
|
|
end= to+map->bitmap_size;
|
2003-10-11 13:06:55 +02:00
|
|
|
|
2003-10-24 22:44:48 +02:00
|
|
|
while (to < end)
|
|
|
|
*to++ |= *from++;
|
2003-10-11 13:06:55 +02:00
|
|
|
|
2003-11-03 13:55:25 +01:00
|
|
|
bitmap_unlock((MY_BITMAP *)map2);
|
2003-10-11 13:06:55 +02:00
|
|
|
bitmap_unlock(map);
|
|
|
|
}
|
|
|
|
|
2004-05-12 23:38:40 +02:00
|
|
|
|
|
|
|
/*
|
2004-05-29 00:04:01 +02:00
|
|
|
SYNOPSIS
|
|
|
|
bitmap_bits_set()
|
|
|
|
map
|
|
|
|
RETURN
|
|
|
|
Number of set bits in the bitmap.
|
2004-05-12 23:38:40 +02:00
|
|
|
*/
|
2004-05-29 00:04:01 +02:00
|
|
|
|
2004-05-12 23:38:40 +02:00
|
|
|
uint bitmap_bits_set(const MY_BITMAP *map)
|
|
|
|
{
|
2004-05-29 00:04:01 +02:00
|
|
|
uchar *m= map->bitmap;
|
|
|
|
uchar *end= m + map->bitmap_size;
|
2004-05-12 23:38:40 +02:00
|
|
|
uint res= 0;
|
|
|
|
|
|
|
|
DBUG_ASSERT(map->bitmap);
|
|
|
|
bitmap_lock((MY_BITMAP *)map);
|
|
|
|
while (m < end)
|
|
|
|
{
|
|
|
|
res+= my_count_bits_ushort(*m++);
|
|
|
|
}
|
|
|
|
bitmap_unlock((MY_BITMAP *)map);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2004-05-29 00:04:01 +02:00
|
|
|
SYNOPSIS
|
|
|
|
bitmap_get_first()
|
|
|
|
map
|
|
|
|
RETURN
|
|
|
|
Number of first unset bit in the bitmap or MY_BIT_NONE if all bits are set.
|
2004-05-12 23:38:40 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
uint bitmap_get_first(const MY_BITMAP *map)
|
|
|
|
{
|
|
|
|
uchar *bitmap=map->bitmap;
|
|
|
|
uint bit_found = MY_BIT_NONE;
|
2006-07-29 11:50:08 +02:00
|
|
|
uint bitmap_size=map->bitmap_size;
|
2004-05-12 23:38:40 +02:00
|
|
|
uint i;
|
|
|
|
|
|
|
|
DBUG_ASSERT(map->bitmap);
|
|
|
|
bitmap_lock((MY_BITMAP *)map);
|
|
|
|
for (i=0; i < bitmap_size ; i++, bitmap++)
|
|
|
|
{
|
|
|
|
if (*bitmap != 0xff)
|
|
|
|
{ /* Found slot with free bit */
|
|
|
|
uint b;
|
|
|
|
for (b=0; ; b++)
|
|
|
|
{
|
|
|
|
if (!(*bitmap & (1 << b)))
|
|
|
|
{
|
|
|
|
bit_found = (i*8)+b;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break; /* Found bit */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bitmap_unlock((MY_BITMAP *)map);
|
|
|
|
return bit_found;
|
|
|
|
}
|
|
|
|
|