2006-12-31 01:02:27 +01:00
|
|
|
/* Copyright (C) 2000-2006 MySQL AB
|
2001-12-06 14:10:51 +02:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
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 14:10:51 +02:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2001-12-06 14:10:51 +02:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
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 */
|
|
|
|
|
|
|
|
/* The hash functions used for saveing keys */
|
|
|
|
|
|
|
|
#include "heapdef.h"
|
|
|
|
#include <m_ctype.h>
|
|
|
|
|
2004-03-25 15:05:01 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Find out how many rows there is in the given range
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
hp_rb_records_in_range()
|
|
|
|
info HEAP handler
|
|
|
|
inx Index to use
|
2004-05-16 14:48:32 +03:00
|
|
|
min_key Min key. Is = 0 if no min range
|
|
|
|
max_key Max key. Is = 0 if no max range
|
2004-03-25 15:05:01 +02:00
|
|
|
|
|
|
|
NOTES
|
2004-05-16 14:48:32 +03:00
|
|
|
min_key.flag can have one of the following values:
|
2004-03-25 15:05:01 +02:00
|
|
|
HA_READ_KEY_EXACT Include the key in the range
|
|
|
|
HA_READ_AFTER_KEY Don't include key in range
|
|
|
|
|
2007-03-17 00:13:25 +01:00
|
|
|
max_key.flag can have one of the following values:
|
2004-03-25 15:05:01 +02:00
|
|
|
HA_READ_BEFORE_KEY Don't include key in range
|
|
|
|
HA_READ_AFTER_KEY Include all 'end_key' values in the range
|
|
|
|
|
|
|
|
RETURN
|
|
|
|
HA_POS_ERROR Something is wrong with the index tree.
|
|
|
|
0 There is no matching keys in the given range
|
|
|
|
number > 0 There is approximately 'number' matching rows in
|
|
|
|
the range.
|
|
|
|
*/
|
|
|
|
|
2004-05-16 14:48:32 +03:00
|
|
|
ha_rows hp_rb_records_in_range(HP_INFO *info, int inx, key_range *min_key,
|
|
|
|
key_range *max_key)
|
2002-04-25 13:36:55 +05:00
|
|
|
{
|
|
|
|
ha_rows start_pos, end_pos;
|
2002-05-23 19:26:16 +05:00
|
|
|
HP_KEYDEF *keyinfo= info->s->keydef + inx;
|
|
|
|
TREE *rb_tree = &keyinfo->rb_tree;
|
2002-04-25 13:36:55 +05:00
|
|
|
heap_rb_param custom_arg;
|
2004-03-25 15:05:01 +02:00
|
|
|
DBUG_ENTER("hp_rb_records_in_range");
|
2002-04-25 13:36:55 +05:00
|
|
|
|
2002-11-15 16:45:08 +04:00
|
|
|
info->lastinx= inx;
|
|
|
|
custom_arg.keyseg= keyinfo->seg;
|
|
|
|
custom_arg.search_flag= SEARCH_FIND | SEARCH_SAME;
|
2004-05-16 14:48:32 +03:00
|
|
|
if (min_key)
|
2002-04-25 13:36:55 +05:00
|
|
|
{
|
2003-02-27 03:44:44 +02:00
|
|
|
custom_arg.key_length= hp_rb_pack_key(keyinfo, (uchar*) info->recbuf,
|
2004-05-16 14:48:32 +03:00
|
|
|
(uchar*) min_key->key,
|
2007-03-17 00:13:25 +01:00
|
|
|
min_key->keypart_map);
|
2004-05-16 14:48:32 +03:00
|
|
|
start_pos= tree_record_pos(rb_tree, info->recbuf, min_key->flag,
|
2002-11-15 16:45:08 +04:00
|
|
|
&custom_arg);
|
2002-04-25 13:36:55 +05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
start_pos= 0;
|
|
|
|
}
|
2007-03-17 00:13:25 +01:00
|
|
|
|
2004-05-16 14:48:32 +03:00
|
|
|
if (max_key)
|
2002-04-25 13:36:55 +05:00
|
|
|
{
|
2003-02-27 03:44:44 +02:00
|
|
|
custom_arg.key_length= hp_rb_pack_key(keyinfo, (uchar*) info->recbuf,
|
2004-05-16 14:48:32 +03:00
|
|
|
(uchar*) max_key->key,
|
2007-03-17 00:13:25 +01:00
|
|
|
max_key->keypart_map);
|
2004-05-16 14:48:32 +03:00
|
|
|
end_pos= tree_record_pos(rb_tree, info->recbuf, max_key->flag,
|
2002-11-15 16:45:08 +04:00
|
|
|
&custom_arg);
|
2002-04-25 13:36:55 +05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
end_pos= rb_tree->elements_in_tree + (ha_rows)1;
|
|
|
|
}
|
|
|
|
|
2004-03-25 15:05:01 +02:00
|
|
|
DBUG_PRINT("info",("start_pos: %lu end_pos: %lu", (ulong) start_pos,
|
|
|
|
(ulong) end_pos));
|
2002-04-25 13:36:55 +05:00
|
|
|
if (start_pos == HA_POS_ERROR || end_pos == HA_POS_ERROR)
|
2004-03-25 15:05:01 +02:00
|
|
|
DBUG_RETURN(HA_POS_ERROR);
|
|
|
|
DBUG_RETURN(end_pos < start_pos ? (ha_rows) 0 :
|
|
|
|
(end_pos == start_pos ? (ha_rows) 1 : end_pos - start_pos));
|
2002-04-25 13:36:55 +05:00
|
|
|
}
|
|
|
|
|
2004-05-16 14:48:32 +03:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
/* Search after a record based on a key */
|
|
|
|
/* Sets info->current_ptr to found record */
|
|
|
|
/* next_flag: Search=0, next=1, prev =2, same =3 */
|
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
uchar *hp_search(HP_INFO *info, HP_KEYDEF *keyinfo, const uchar *key,
|
2004-05-16 14:48:32 +03:00
|
|
|
uint nextflag)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
reg1 HASH_INFO *pos,*prev_ptr;
|
|
|
|
int flag;
|
|
|
|
uint old_nextflag;
|
|
|
|
HP_SHARE *share=info->s;
|
2002-04-25 13:36:55 +05:00
|
|
|
DBUG_ENTER("hp_search");
|
2000-07-31 21:29:14 +02:00
|
|
|
old_nextflag=nextflag;
|
|
|
|
flag=1;
|
|
|
|
prev_ptr=0;
|
|
|
|
|
|
|
|
if (share->records)
|
|
|
|
{
|
2002-04-25 13:36:55 +05:00
|
|
|
pos=hp_find_hash(&keyinfo->block, hp_mask(hp_hashnr(keyinfo, key),
|
|
|
|
share->blength, share->records));
|
2000-07-31 21:29:14 +02:00
|
|
|
do
|
|
|
|
{
|
2002-04-25 13:36:55 +05:00
|
|
|
if (!hp_key_cmp(keyinfo, pos->ptr_to_rec, key))
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
switch (nextflag) {
|
|
|
|
case 0: /* Search after key */
|
2006-11-20 22:42:06 +02:00
|
|
|
DBUG_PRINT("exit", ("found key at 0x%lx", (long) pos->ptr_to_rec));
|
2000-07-31 21:29:14 +02:00
|
|
|
info->current_hash_ptr=pos;
|
|
|
|
DBUG_RETURN(info->current_ptr= pos->ptr_to_rec);
|
|
|
|
case 1: /* Search next */
|
|
|
|
if (pos->ptr_to_rec == info->current_ptr)
|
|
|
|
nextflag=0;
|
|
|
|
break;
|
|
|
|
case 2: /* Search previous */
|
|
|
|
if (pos->ptr_to_rec == info->current_ptr)
|
|
|
|
{
|
|
|
|
my_errno=HA_ERR_KEY_NOT_FOUND; /* If gpos == 0 */
|
|
|
|
info->current_hash_ptr=prev_ptr;
|
|
|
|
DBUG_RETURN(info->current_ptr=prev_ptr ? prev_ptr->ptr_to_rec : 0);
|
|
|
|
}
|
|
|
|
prev_ptr=pos; /* Prev. record found */
|
|
|
|
break;
|
|
|
|
case 3: /* Search same */
|
|
|
|
if (pos->ptr_to_rec == info->current_ptr)
|
|
|
|
{
|
|
|
|
info->current_hash_ptr=pos;
|
|
|
|
DBUG_RETURN(info->current_ptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (flag)
|
|
|
|
{
|
|
|
|
flag=0; /* Reset flag */
|
|
|
|
if (hp_find_hash(&keyinfo->block,
|
2002-04-25 13:36:55 +05:00
|
|
|
hp_mask(hp_rec_hashnr(keyinfo, pos->ptr_to_rec),
|
|
|
|
share->blength, share->records)) != pos)
|
2000-07-31 21:29:14 +02:00
|
|
|
break; /* Wrong link */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while ((pos=pos->next_key));
|
|
|
|
}
|
|
|
|
my_errno=HA_ERR_KEY_NOT_FOUND;
|
|
|
|
if (nextflag == 2 && ! info->current_ptr)
|
|
|
|
{
|
|
|
|
/* Do a previous from end */
|
|
|
|
info->current_hash_ptr=prev_ptr;
|
|
|
|
DBUG_RETURN(info->current_ptr=prev_ptr ? prev_ptr->ptr_to_rec : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (old_nextflag && nextflag)
|
|
|
|
my_errno=HA_ERR_RECORD_CHANGED; /* Didn't find old record */
|
|
|
|
DBUG_PRINT("exit",("Error: %d",my_errno));
|
|
|
|
info->current_hash_ptr=0;
|
|
|
|
DBUG_RETURN((info->current_ptr= 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Search next after last read; Assumes that the table hasn't changed
|
|
|
|
since last read !
|
|
|
|
*/
|
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
uchar *hp_search_next(HP_INFO *info, HP_KEYDEF *keyinfo, const uchar *key,
|
2000-07-31 21:29:14 +02:00
|
|
|
HASH_INFO *pos)
|
|
|
|
{
|
2002-04-25 13:36:55 +05:00
|
|
|
DBUG_ENTER("hp_search_next");
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
while ((pos= pos->next_key))
|
|
|
|
{
|
2002-04-25 13:36:55 +05:00
|
|
|
if (! hp_key_cmp(keyinfo, pos->ptr_to_rec, key))
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
info->current_hash_ptr=pos;
|
|
|
|
DBUG_RETURN (info->current_ptr= pos->ptr_to_rec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
my_errno=HA_ERR_KEY_NOT_FOUND;
|
|
|
|
DBUG_PRINT("exit",("Error: %d",my_errno));
|
|
|
|
info->current_hash_ptr=0;
|
|
|
|
DBUG_RETURN ((info->current_ptr= 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-09-08 02:07:53 +04:00
|
|
|
/*
|
|
|
|
Calculate position number for hash value.
|
|
|
|
SYNOPSIS
|
|
|
|
hp_mask()
|
|
|
|
hashnr Hash value
|
|
|
|
buffmax Value such that
|
|
|
|
2^(n-1) < maxlength <= 2^n = buffmax
|
|
|
|
maxlength
|
|
|
|
|
|
|
|
RETURN
|
|
|
|
Array index, in [0..maxlength)
|
|
|
|
*/
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2002-04-25 13:36:55 +05:00
|
|
|
ulong hp_mask(ulong hashnr, ulong buffmax, ulong maxlength)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
if ((hashnr & (buffmax-1)) < maxlength) return (hashnr & (buffmax-1));
|
|
|
|
return (hashnr & ((buffmax >> 1) -1));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-09-08 02:07:53 +04:00
|
|
|
/*
|
|
|
|
Change
|
|
|
|
next_link -> ... -> X -> pos
|
|
|
|
to
|
|
|
|
next_link -> ... -> X -> newlink
|
|
|
|
*/
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2002-04-25 13:36:55 +05:00
|
|
|
void hp_movelink(HASH_INFO *pos, HASH_INFO *next_link, HASH_INFO *newlink)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
HASH_INFO *old_link;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
old_link=next_link;
|
|
|
|
}
|
|
|
|
while ((next_link=next_link->next_key) != pos);
|
|
|
|
old_link->next_key=newlink;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-12-29 16:06:10 +02:00
|
|
|
#ifndef NEW_HASH_FUNCTION
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
/* Calc hashvalue for a key */
|
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
ulong hp_hashnr(register HP_KEYDEF *keydef, register const uchar *key)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2002-04-17 17:27:13 +05:00
|
|
|
/*register*/
|
|
|
|
ulong nr=1, nr2=4;
|
2002-04-25 15:10:29 +05:00
|
|
|
HA_KEYSEG *seg,*endseg;
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
for (seg=keydef->seg,endseg=seg+keydef->keysegs ; seg < endseg ; seg++)
|
|
|
|
{
|
2000-12-29 16:06:10 +02:00
|
|
|
uchar *pos=(uchar*) key;
|
|
|
|
key+=seg->length;
|
2002-01-12 15:42:54 +02:00
|
|
|
if (seg->null_bit)
|
|
|
|
{
|
2004-06-03 11:52:54 -05:00
|
|
|
key++; /* Skip null byte */
|
2002-01-12 15:42:54 +02:00
|
|
|
if (*pos) /* Found null */
|
|
|
|
{
|
|
|
|
nr^= (nr << 1) | 1;
|
2005-04-21 21:06:08 +05:00
|
|
|
/* Add key pack length (2) to key for VARCHAR segments */
|
|
|
|
if (seg->type == HA_KEYTYPE_VARTEXT1)
|
|
|
|
key+= 2;
|
2002-01-12 15:42:54 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
pos++;
|
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
if (seg->type == HA_KEYTYPE_TEXT)
|
|
|
|
{
|
2004-08-16 19:58:50 +05:00
|
|
|
CHARSET_INFO *cs= seg->charset;
|
2004-12-06 02:00:37 +02:00
|
|
|
uint length= seg->length;
|
2004-08-26 18:26:38 +03:00
|
|
|
if (cs->mbmaxlen > 1)
|
2004-08-16 19:58:50 +05:00
|
|
|
{
|
2004-12-06 02:00:37 +02:00
|
|
|
uint char_length;
|
2004-08-26 18:26:38 +03:00
|
|
|
char_length= my_charpos(cs, pos, pos + length, length/cs->mbmaxlen);
|
2004-12-06 02:00:37 +02:00
|
|
|
set_if_smaller(length, char_length);
|
2004-08-16 19:58:50 +05:00
|
|
|
}
|
2004-12-06 02:00:37 +02:00
|
|
|
cs->coll->hash_sort(cs, pos, length, &nr, &nr2);
|
|
|
|
}
|
2004-12-18 05:19:21 +02:00
|
|
|
else if (seg->type == HA_KEYTYPE_VARTEXT1) /* Any VARCHAR segments */
|
2004-12-06 02:00:37 +02:00
|
|
|
{
|
|
|
|
CHARSET_INFO *cs= seg->charset;
|
2004-12-18 05:19:21 +02:00
|
|
|
uint pack_length= 2; /* Key packing is constant */
|
2004-12-06 02:00:37 +02:00
|
|
|
uint length= uint2korr(pos);
|
|
|
|
if (cs->mbmaxlen > 1)
|
|
|
|
{
|
|
|
|
uint char_length;
|
2004-12-18 05:19:21 +02:00
|
|
|
char_length= my_charpos(cs, pos +pack_length,
|
|
|
|
pos +pack_length + length,
|
2004-12-06 02:00:37 +02:00
|
|
|
seg->length/cs->mbmaxlen);
|
|
|
|
set_if_smaller(length, char_length);
|
|
|
|
}
|
2004-12-18 05:19:21 +02:00
|
|
|
cs->coll->hash_sort(cs, pos+pack_length, length, &nr, &nr2);
|
|
|
|
key+= pack_length;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-12-29 16:06:10 +02:00
|
|
|
for (; pos < (uchar*) key ; pos++)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2002-01-12 15:42:54 +02:00
|
|
|
nr^=(ulong) ((((uint) nr & 63)+nr2)*((uint) *pos)) + (nr << 8);
|
2000-07-31 21:29:14 +02:00
|
|
|
nr2+=3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-12-18 05:19:21 +02:00
|
|
|
DBUG_PRINT("exit", ("hash: 0x%lx", nr));
|
2000-07-31 21:29:14 +02:00
|
|
|
return((ulong) nr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Calc hashvalue for a key in a record */
|
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
ulong hp_rec_hashnr(register HP_KEYDEF *keydef, register const uchar *rec)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2002-04-17 17:27:13 +05:00
|
|
|
ulong nr=1, nr2=4;
|
2002-04-25 15:10:29 +05:00
|
|
|
HA_KEYSEG *seg,*endseg;
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
for (seg=keydef->seg,endseg=seg+keydef->keysegs ; seg < endseg ; seg++)
|
|
|
|
{
|
2000-12-29 16:06:10 +02:00
|
|
|
uchar *pos=(uchar*) rec+seg->start,*end=pos+seg->length;
|
2002-01-12 15:42:54 +02:00
|
|
|
if (seg->null_bit)
|
|
|
|
{
|
|
|
|
if (rec[seg->null_pos] & seg->null_bit)
|
|
|
|
{
|
|
|
|
nr^= (nr << 1) | 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
if (seg->type == HA_KEYTYPE_TEXT)
|
|
|
|
{
|
2004-08-16 19:58:50 +05:00
|
|
|
CHARSET_INFO *cs= seg->charset;
|
2004-08-26 18:26:38 +03:00
|
|
|
uint char_length= seg->length;
|
|
|
|
if (cs->mbmaxlen > 1)
|
2004-08-16 19:58:50 +05:00
|
|
|
{
|
2004-08-26 18:26:38 +03:00
|
|
|
char_length= my_charpos(cs, pos, pos + char_length,
|
|
|
|
char_length / cs->mbmaxlen);
|
|
|
|
set_if_smaller(char_length, seg->length); /* QQ: ok to remove? */
|
2004-08-16 19:58:50 +05:00
|
|
|
}
|
|
|
|
cs->coll->hash_sort(cs, pos, char_length, &nr, &nr2);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
2004-12-18 05:19:21 +02:00
|
|
|
else if (seg->type == HA_KEYTYPE_VARTEXT1) /* Any VARCHAR segments */
|
2004-12-06 02:00:37 +02:00
|
|
|
{
|
|
|
|
CHARSET_INFO *cs= seg->charset;
|
2004-12-18 05:19:21 +02:00
|
|
|
uint pack_length= seg->bit_start;
|
|
|
|
uint length= (pack_length == 1 ? (uint) *(uchar*) pos : uint2korr(pos));
|
2004-12-06 02:00:37 +02:00
|
|
|
if (cs->mbmaxlen > 1)
|
|
|
|
{
|
|
|
|
uint char_length;
|
2004-12-18 05:19:21 +02:00
|
|
|
char_length= my_charpos(cs, pos + pack_length,
|
|
|
|
pos + pack_length + length,
|
2004-12-06 02:00:37 +02:00
|
|
|
seg->length/cs->mbmaxlen);
|
|
|
|
set_if_smaller(length, char_length);
|
|
|
|
}
|
2004-12-18 05:19:21 +02:00
|
|
|
cs->coll->hash_sort(cs, pos+pack_length, length, &nr, &nr2);
|
2004-12-06 02:00:37 +02:00
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
else
|
|
|
|
{
|
2000-12-29 16:06:10 +02:00
|
|
|
for (; pos < end ; pos++)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
nr^=(ulong) ((((uint) nr & 63)+nr2)*((uint) *pos))+ (nr << 8);
|
|
|
|
nr2+=3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-12-18 05:19:21 +02:00
|
|
|
DBUG_PRINT("exit", ("hash: 0x%lx", nr));
|
|
|
|
return(nr);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2000-12-29 16:06:10 +02:00
|
|
|
#else
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fowler/Noll/Vo hash
|
|
|
|
*
|
|
|
|
* The basis of the hash algorithm was taken from an idea sent by email to the
|
|
|
|
* IEEE Posix P1003.2 mailing list from Phong Vo (kpv@research.att.com) and
|
|
|
|
* Glenn Fowler (gsf@research.att.com). Landon Curt Noll (chongo@toad.com)
|
|
|
|
* later improved on their algorithm.
|
|
|
|
*
|
|
|
|
* The magic is in the interesting relationship between the special prime
|
|
|
|
* 16777619 (2^24 + 403) and 2^32 and 2^8.
|
|
|
|
*
|
|
|
|
* This hash produces the fewest collisions of any function that we've seen so
|
|
|
|
* far, and works well on both numbers and strings.
|
|
|
|
*/
|
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
ulong hp_hashnr(register HP_KEYDEF *keydef, register const uchar *key)
|
2000-12-29 16:06:10 +02:00
|
|
|
{
|
2007-05-08 17:04:56 +05:00
|
|
|
/*
|
|
|
|
Note, if a key consists of a combination of numeric and
|
|
|
|
a text columns, it most likely won't work well.
|
|
|
|
Making text columns work with NEW_HASH_FUNCTION
|
|
|
|
needs also changes in strings/ctype-xxx.c.
|
|
|
|
*/
|
|
|
|
ulong nr= 1, nr2= 4;
|
2002-04-25 15:10:29 +05:00
|
|
|
HA_KEYSEG *seg,*endseg;
|
2000-12-29 16:06:10 +02:00
|
|
|
|
|
|
|
for (seg=keydef->seg,endseg=seg+keydef->keysegs ; seg < endseg ; seg++)
|
|
|
|
{
|
|
|
|
uchar *pos=(uchar*) key;
|
|
|
|
key+=seg->length;
|
2002-01-12 15:42:54 +02:00
|
|
|
if (seg->null_bit)
|
|
|
|
{
|
|
|
|
key++;
|
|
|
|
if (*pos)
|
|
|
|
{
|
|
|
|
nr^= (nr << 1) | 1;
|
2005-04-21 21:06:08 +05:00
|
|
|
/* Add key pack length (2) to key for VARCHAR segments */
|
|
|
|
if (seg->type == HA_KEYTYPE_VARTEXT1)
|
|
|
|
key+= 2;
|
2002-01-12 15:42:54 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
pos++;
|
|
|
|
}
|
2000-12-29 16:06:10 +02:00
|
|
|
if (seg->type == HA_KEYTYPE_TEXT)
|
|
|
|
{
|
2007-05-08 17:04:56 +05:00
|
|
|
seg->charset->coll->hash_sort(seg->charset, pos, ((uchar*)key)-pos,
|
|
|
|
&nr, &nr2);
|
2000-12-29 16:06:10 +02:00
|
|
|
}
|
2004-12-18 05:19:21 +02:00
|
|
|
else if (seg->type == HA_KEYTYPE_VARTEXT1) /* Any VARCHAR segments */
|
2004-12-06 02:00:37 +02:00
|
|
|
{
|
2004-12-18 05:19:21 +02:00
|
|
|
uint pack_length= 2; /* Key packing is constant */
|
2004-12-06 02:00:37 +02:00
|
|
|
uint length= uint2korr(pos);
|
2007-05-08 17:04:56 +05:00
|
|
|
seg->charset->coll->hash_sort(seg->charset, pos+pack_length, length,
|
|
|
|
&nr, &nr2);
|
2004-12-18 05:19:21 +02:00
|
|
|
key+= pack_length;
|
2004-12-06 02:00:37 +02:00
|
|
|
}
|
2000-12-29 16:06:10 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
for ( ; pos < (uchar*) key ; pos++)
|
|
|
|
{
|
|
|
|
nr *=16777619;
|
|
|
|
nr ^=(uint) *pos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-12-18 05:19:21 +02:00
|
|
|
DBUG_PRINT("exit", ("hash: 0x%lx", nr));
|
|
|
|
return(nr);
|
2000-12-29 16:06:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Calc hashvalue for a key in a record */
|
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
ulong hp_rec_hashnr(register HP_KEYDEF *keydef, register const uchar *rec)
|
2000-12-29 16:06:10 +02:00
|
|
|
{
|
2007-05-08 17:04:56 +05:00
|
|
|
ulong nr= 1, nr2= 4;
|
2002-04-25 15:10:29 +05:00
|
|
|
HA_KEYSEG *seg,*endseg;
|
2000-12-29 16:06:10 +02:00
|
|
|
|
|
|
|
for (seg=keydef->seg,endseg=seg+keydef->keysegs ; seg < endseg ; seg++)
|
|
|
|
{
|
2004-12-18 05:19:21 +02:00
|
|
|
uchar *pos=(uchar*) rec+seg->start;
|
2002-01-12 15:42:54 +02:00
|
|
|
if (seg->null_bit)
|
|
|
|
{
|
|
|
|
if (rec[seg->null_pos] & seg->null_bit)
|
|
|
|
{
|
|
|
|
nr^= (nr << 1) | 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2000-12-29 16:06:10 +02:00
|
|
|
if (seg->type == HA_KEYTYPE_TEXT)
|
|
|
|
{
|
2007-05-08 17:04:56 +05:00
|
|
|
uint char_length= seg->length; /* TODO: fix to use my_charpos() */
|
|
|
|
seg->charset->coll->hash_sort(seg->charset, pos, char_length,
|
|
|
|
&nr, &nr2);
|
2000-12-29 16:06:10 +02:00
|
|
|
}
|
2004-12-18 05:19:21 +02:00
|
|
|
else if (seg->type == HA_KEYTYPE_VARTEXT1) /* Any VARCHAR segments */
|
2004-12-06 02:00:37 +02:00
|
|
|
{
|
2004-12-18 05:19:21 +02:00
|
|
|
uint pack_length= seg->bit_start;
|
|
|
|
uint length= (pack_length == 1 ? (uint) *(uchar*) pos : uint2korr(pos));
|
2007-05-08 17:04:56 +05:00
|
|
|
seg->charset->coll->hash_sort(seg->charset, pos+pack_length,
|
|
|
|
length, &nr, &nr2);
|
2004-12-06 02:00:37 +02:00
|
|
|
}
|
2000-12-29 16:06:10 +02:00
|
|
|
else
|
|
|
|
{
|
2004-12-18 05:19:21 +02:00
|
|
|
uchar *end= pos+seg->length;
|
2000-12-29 16:06:10 +02:00
|
|
|
for ( ; pos < end ; pos++)
|
|
|
|
{
|
|
|
|
nr *=16777619;
|
|
|
|
nr ^=(uint) *pos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-12-18 05:19:21 +02:00
|
|
|
DBUG_PRINT("exit", ("hash: 0x%lx", nr));
|
|
|
|
return(nr);
|
2000-12-29 16:06:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2004-12-06 02:00:37 +02:00
|
|
|
/*
|
|
|
|
Compare keys for two records. Returns 0 if they are identical
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2004-12-06 02:00:37 +02:00
|
|
|
SYNOPSIS
|
|
|
|
hp_rec_key_cmp()
|
|
|
|
keydef Key definition
|
|
|
|
rec1 Record to compare
|
|
|
|
rec2 Other record to compare
|
|
|
|
diff_if_only_endspace_difference
|
|
|
|
Different number of end space is significant
|
|
|
|
|
|
|
|
NOTES
|
|
|
|
diff_if_only_endspace_difference is used to allow us to insert
|
|
|
|
'a' and 'a ' when there is an an unique key.
|
|
|
|
|
|
|
|
RETURN
|
|
|
|
0 Key is identical
|
|
|
|
<> 0 Key differes
|
|
|
|
*/
|
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
int hp_rec_key_cmp(HP_KEYDEF *keydef, const uchar *rec1, const uchar *rec2,
|
2004-12-06 02:00:37 +02:00
|
|
|
my_bool diff_if_only_endspace_difference)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2002-04-25 15:10:29 +05:00
|
|
|
HA_KEYSEG *seg,*endseg;
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
for (seg=keydef->seg,endseg=seg+keydef->keysegs ; seg < endseg ; seg++)
|
|
|
|
{
|
2002-01-12 15:42:54 +02:00
|
|
|
if (seg->null_bit)
|
|
|
|
{
|
|
|
|
if ((rec1[seg->null_pos] & seg->null_bit) !=
|
|
|
|
(rec2[seg->null_pos] & seg->null_bit))
|
|
|
|
return 1;
|
|
|
|
if (rec1[seg->null_pos] & seg->null_bit)
|
|
|
|
continue;
|
|
|
|
}
|
2002-05-21 21:54:08 +05:00
|
|
|
if (seg->type == HA_KEYTYPE_TEXT)
|
|
|
|
{
|
2004-08-16 19:58:50 +05:00
|
|
|
CHARSET_INFO *cs= seg->charset;
|
|
|
|
uint char_length1;
|
|
|
|
uint char_length2;
|
|
|
|
uchar *pos1= (uchar*)rec1 + seg->start;
|
|
|
|
uchar *pos2= (uchar*)rec2 + seg->start;
|
2004-08-26 18:26:38 +03:00
|
|
|
if (cs->mbmaxlen > 1)
|
2004-08-16 19:58:50 +05:00
|
|
|
{
|
2004-08-26 18:26:38 +03:00
|
|
|
uint char_length= seg->length / cs->mbmaxlen;
|
2004-08-16 19:58:50 +05:00
|
|
|
char_length1= my_charpos(cs, pos1, pos1 + seg->length, char_length);
|
2004-12-06 02:00:37 +02:00
|
|
|
set_if_smaller(char_length1, seg->length);
|
2004-08-16 19:58:50 +05:00
|
|
|
char_length2= my_charpos(cs, pos2, pos2 + seg->length, char_length);
|
2004-12-06 02:00:37 +02:00
|
|
|
set_if_smaller(char_length2, seg->length);
|
2004-08-16 19:58:50 +05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char_length1= char_length2= seg->length;
|
|
|
|
}
|
2003-08-05 11:03:05 +05:00
|
|
|
if (seg->charset->coll->strnncollsp(seg->charset,
|
2004-08-16 19:58:50 +05:00
|
|
|
pos1,char_length1,
|
2004-12-06 02:00:37 +02:00
|
|
|
pos2,char_length2, 0))
|
|
|
|
return 1;
|
|
|
|
}
|
2004-12-18 05:19:21 +02:00
|
|
|
else if (seg->type == HA_KEYTYPE_VARTEXT1) /* Any VARCHAR segments */
|
2004-12-06 02:00:37 +02:00
|
|
|
{
|
2004-12-18 05:19:21 +02:00
|
|
|
uchar *pos1= (uchar*) rec1 + seg->start;
|
|
|
|
uchar *pos2= (uchar*) rec2 + seg->start;
|
|
|
|
uint char_length1, char_length2;
|
|
|
|
uint pack_length= seg->bit_start;
|
2004-12-06 02:00:37 +02:00
|
|
|
CHARSET_INFO *cs= seg->charset;
|
2004-12-18 05:19:21 +02:00
|
|
|
if (pack_length == 1)
|
|
|
|
{
|
|
|
|
char_length1= (uint) *(uchar*) pos1++;
|
|
|
|
char_length2= (uint) *(uchar*) pos2++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char_length1= uint2korr(pos1);
|
|
|
|
char_length2= uint2korr(pos2);
|
|
|
|
pos1+= 2;
|
|
|
|
pos2+= 2;
|
|
|
|
}
|
2004-12-06 02:00:37 +02:00
|
|
|
if (cs->mbmaxlen > 1)
|
|
|
|
{
|
2005-09-01 19:31:08 +05:00
|
|
|
uint safe_length1= char_length1;
|
|
|
|
uint safe_length2= char_length2;
|
2004-12-06 02:00:37 +02:00
|
|
|
uint char_length= seg->length / cs->mbmaxlen;
|
2005-09-01 19:31:08 +05:00
|
|
|
char_length1= my_charpos(cs, pos1, pos1 + char_length1, char_length);
|
|
|
|
set_if_smaller(char_length1, safe_length1);
|
|
|
|
char_length2= my_charpos(cs, pos2, pos2 + char_length2, char_length);
|
|
|
|
set_if_smaller(char_length2, safe_length2);
|
2004-12-06 02:00:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cs->coll->strnncollsp(seg->charset,
|
2004-12-18 05:19:21 +02:00
|
|
|
pos1, char_length1,
|
|
|
|
pos2, char_length2,
|
2004-12-06 02:00:37 +02:00
|
|
|
seg->flag & HA_END_SPACE_ARE_EQUAL ?
|
|
|
|
0 : diff_if_only_endspace_difference))
|
2000-07-31 21:29:14 +02:00
|
|
|
return 1;
|
2002-05-21 21:54:08 +05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-07-31 21:29:14 +02:00
|
|
|
if (bcmp(rec1+seg->start,rec2+seg->start,seg->length))
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-01-12 15:42:54 +02:00
|
|
|
/* Compare a key in a record to a whole key */
|
2000-07-31 21:29:14 +02:00
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
int hp_key_cmp(HP_KEYDEF *keydef, const uchar *rec, const uchar *key)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2002-04-25 15:10:29 +05:00
|
|
|
HA_KEYSEG *seg,*endseg;
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2002-01-12 15:42:54 +02:00
|
|
|
for (seg=keydef->seg,endseg=seg+keydef->keysegs ;
|
|
|
|
seg < endseg ;
|
|
|
|
key+= (seg++)->length)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2002-01-12 15:42:54 +02:00
|
|
|
if (seg->null_bit)
|
|
|
|
{
|
|
|
|
int found_null=test(rec[seg->null_pos] & seg->null_bit);
|
|
|
|
if (found_null != (int) *key++)
|
|
|
|
return 1;
|
|
|
|
if (found_null)
|
2005-04-21 21:06:08 +05:00
|
|
|
{
|
|
|
|
/* Add key pack length (2) to key for VARCHAR segments */
|
|
|
|
if (seg->type == HA_KEYTYPE_VARTEXT1)
|
|
|
|
key+= 2;
|
2002-01-12 15:42:54 +02:00
|
|
|
continue;
|
2005-04-21 21:06:08 +05:00
|
|
|
}
|
2002-01-12 15:42:54 +02:00
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
if (seg->type == HA_KEYTYPE_TEXT)
|
|
|
|
{
|
2004-08-16 19:58:50 +05:00
|
|
|
CHARSET_INFO *cs= seg->charset;
|
|
|
|
uint char_length_key;
|
|
|
|
uint char_length_rec;
|
|
|
|
uchar *pos= (uchar*) rec + seg->start;
|
2004-08-26 18:26:38 +03:00
|
|
|
if (cs->mbmaxlen > 1)
|
2004-08-16 19:58:50 +05:00
|
|
|
{
|
2004-08-26 18:26:38 +03:00
|
|
|
uint char_length= seg->length / cs->mbmaxlen;
|
2004-08-16 19:58:50 +05:00
|
|
|
char_length_key= my_charpos(cs, key, key + seg->length, char_length);
|
|
|
|
set_if_smaller(char_length_key, seg->length);
|
|
|
|
char_length_rec= my_charpos(cs, pos, pos + seg->length, char_length);
|
|
|
|
set_if_smaller(char_length_rec, seg->length);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char_length_key= seg->length;
|
|
|
|
char_length_rec= seg->length;
|
|
|
|
}
|
|
|
|
|
2003-08-05 11:03:05 +05:00
|
|
|
if (seg->charset->coll->strnncollsp(seg->charset,
|
2004-08-16 19:58:50 +05:00
|
|
|
(uchar*) pos, char_length_rec,
|
2004-12-06 02:00:37 +02:00
|
|
|
(uchar*) key, char_length_key, 0))
|
|
|
|
return 1;
|
|
|
|
}
|
2004-12-18 05:19:21 +02:00
|
|
|
else if (seg->type == HA_KEYTYPE_VARTEXT1) /* Any VARCHAR segments */
|
2004-12-06 02:00:37 +02:00
|
|
|
{
|
|
|
|
uchar *pos= (uchar*) rec + seg->start;
|
|
|
|
CHARSET_INFO *cs= seg->charset;
|
2004-12-18 05:19:21 +02:00
|
|
|
uint pack_length= seg->bit_start;
|
|
|
|
uint char_length_rec= (pack_length == 1 ? (uint) *(uchar*) pos :
|
|
|
|
uint2korr(pos));
|
|
|
|
/* Key segments are always packed with 2 bytes */
|
2004-12-06 02:00:37 +02:00
|
|
|
uint char_length_key= uint2korr(key);
|
2004-12-18 05:19:21 +02:00
|
|
|
pos+= pack_length;
|
|
|
|
key+= 2; /* skip key pack length */
|
2004-12-06 02:00:37 +02:00
|
|
|
if (cs->mbmaxlen > 1)
|
|
|
|
{
|
2005-05-09 16:22:49 +00:00
|
|
|
uint char_length1, char_length2;
|
|
|
|
char_length1= char_length2= seg->length / cs->mbmaxlen;
|
|
|
|
char_length1= my_charpos(cs, key, key + char_length_key, char_length1);
|
|
|
|
set_if_smaller(char_length_key, char_length1);
|
|
|
|
char_length2= my_charpos(cs, pos, pos + char_length_rec, char_length2);
|
|
|
|
set_if_smaller(char_length_rec, char_length2);
|
2004-12-06 02:00:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cs->coll->strnncollsp(seg->charset,
|
2004-12-18 05:19:21 +02:00
|
|
|
(uchar*) pos, char_length_rec,
|
|
|
|
(uchar*) key, char_length_key, 0))
|
2000-07-31 21:29:14 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (bcmp(rec+seg->start,key,seg->length))
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Copy a key from a record to a keybuffer */
|
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
void hp_make_key(HP_KEYDEF *keydef, uchar *key, const uchar *rec)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2002-04-25 15:10:29 +05:00
|
|
|
HA_KEYSEG *seg,*endseg;
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
for (seg=keydef->seg,endseg=seg+keydef->keysegs ; seg < endseg ; seg++)
|
|
|
|
{
|
2004-08-16 19:58:50 +05:00
|
|
|
CHARSET_INFO *cs= seg->charset;
|
2004-08-26 18:26:38 +03:00
|
|
|
uint char_length= seg->length;
|
2004-08-16 19:58:50 +05:00
|
|
|
uchar *pos= (uchar*) rec + seg->start;
|
2002-01-12 15:42:54 +02:00
|
|
|
if (seg->null_bit)
|
|
|
|
*key++= test(rec[seg->null_pos] & seg->null_bit);
|
2004-08-26 18:26:38 +03:00
|
|
|
if (cs->mbmaxlen > 1)
|
2004-08-16 19:58:50 +05:00
|
|
|
{
|
2004-08-26 18:26:38 +03:00
|
|
|
char_length= my_charpos(cs, pos, pos + seg->length,
|
|
|
|
char_length / cs->mbmaxlen);
|
|
|
|
set_if_smaller(char_length, seg->length); /* QQ: ok to remove? */
|
2004-08-16 19:58:50 +05:00
|
|
|
}
|
2004-12-18 05:19:21 +02:00
|
|
|
if (seg->type == HA_KEYTYPE_VARTEXT1)
|
|
|
|
char_length+= seg->bit_start; /* Copy also length */
|
2004-08-16 19:58:50 +05:00
|
|
|
memcpy(key,rec+seg->start,(size_t) char_length);
|
|
|
|
key+= char_length;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
}
|
2002-01-12 15:42:54 +02:00
|
|
|
|
2004-12-06 02:00:37 +02:00
|
|
|
#define FIX_LENGTH(cs, pos, length, char_length) \
|
|
|
|
do { \
|
|
|
|
if (length > char_length) \
|
|
|
|
char_length= my_charpos(cs, pos, pos+length, char_length); \
|
|
|
|
set_if_smaller(char_length,length); \
|
|
|
|
} while(0)
|
|
|
|
|
2004-08-26 18:26:38 +03:00
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
uint hp_rb_make_key(HP_KEYDEF *keydef, uchar *key,
|
|
|
|
const uchar *rec, uchar *recpos)
|
2002-04-25 13:36:55 +05:00
|
|
|
{
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
uchar *start_key= key;
|
2002-04-25 15:10:29 +05:00
|
|
|
HA_KEYSEG *seg, *endseg;
|
2002-04-25 13:36:55 +05:00
|
|
|
|
2002-05-21 21:54:08 +05:00
|
|
|
for (seg= keydef->seg, endseg= seg + keydef->keysegs; seg < endseg; seg++)
|
2002-04-25 13:36:55 +05:00
|
|
|
{
|
2004-08-16 19:58:50 +05:00
|
|
|
uint char_length;
|
2002-04-25 13:36:55 +05:00
|
|
|
if (seg->null_bit)
|
2002-05-21 21:54:08 +05:00
|
|
|
{
|
|
|
|
if (!(*key++= 1 - test(rec[seg->null_pos] & seg->null_bit)))
|
|
|
|
continue;
|
|
|
|
}
|
2002-11-19 18:48:22 +04:00
|
|
|
if (seg->flag & HA_SWAP_KEY)
|
|
|
|
{
|
|
|
|
uint length= seg->length;
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
uchar *pos= (uchar*) rec + seg->start;
|
2002-11-19 18:48:22 +04:00
|
|
|
|
|
|
|
#ifdef HAVE_ISNAN
|
|
|
|
if (seg->type == HA_KEYTYPE_FLOAT)
|
|
|
|
{
|
|
|
|
float nr;
|
|
|
|
float4get(nr, pos);
|
|
|
|
if (isnan(nr))
|
|
|
|
{
|
|
|
|
/* Replace NAN with zero */
|
|
|
|
bzero(key, length);
|
|
|
|
key+= length;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (seg->type == HA_KEYTYPE_DOUBLE)
|
|
|
|
{
|
|
|
|
double nr;
|
|
|
|
float8get(nr, pos);
|
|
|
|
if (isnan(nr))
|
|
|
|
{
|
|
|
|
bzero(key, length);
|
|
|
|
key+= length;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
pos+= length;
|
|
|
|
while (length--)
|
|
|
|
{
|
|
|
|
*key++= *--pos;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2004-12-06 02:00:37 +02:00
|
|
|
|
|
|
|
if (seg->flag & HA_VAR_LENGTH_PART)
|
|
|
|
{
|
|
|
|
uchar *pos= (uchar*) rec + seg->start;
|
|
|
|
uint length= seg->length;
|
2004-12-18 05:19:21 +02:00
|
|
|
uint pack_length= seg->bit_start;
|
|
|
|
uint tmp_length= (pack_length == 1 ? (uint) *(uchar*) pos :
|
|
|
|
uint2korr(pos));
|
2004-12-06 02:00:37 +02:00
|
|
|
CHARSET_INFO *cs= seg->charset;
|
|
|
|
char_length= length/cs->mbmaxlen;
|
|
|
|
|
2004-12-18 05:19:21 +02:00
|
|
|
pos+= pack_length; /* Skip VARCHAR length */
|
2004-12-06 02:00:37 +02:00
|
|
|
set_if_smaller(length,tmp_length);
|
|
|
|
FIX_LENGTH(cs, pos, length, char_length);
|
|
|
|
store_key_length_inc(key,char_length);
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
memcpy((uchar*) key,(uchar*) pos,(size_t) char_length);
|
2004-12-06 02:00:37 +02:00
|
|
|
key+= char_length;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2004-08-26 18:26:38 +03:00
|
|
|
char_length= seg->length;
|
|
|
|
if (seg->charset->mbmaxlen > 1)
|
2004-08-16 19:58:50 +05:00
|
|
|
{
|
|
|
|
char_length= my_charpos(seg->charset,
|
2004-08-26 18:26:38 +03:00
|
|
|
rec + seg->start, rec + seg->start + char_length,
|
|
|
|
char_length / seg->charset->mbmaxlen);
|
|
|
|
set_if_smaller(char_length, seg->length); /* QQ: ok to remove? */
|
2004-08-16 19:58:50 +05:00
|
|
|
if (char_length < seg->length)
|
2007-03-17 00:13:25 +01:00
|
|
|
seg->charset->cset->fill(seg->charset, (char*) key + char_length,
|
2004-08-16 19:58:50 +05:00
|
|
|
seg->length - char_length, ' ');
|
|
|
|
}
|
|
|
|
memcpy(key, rec + seg->start, (size_t) char_length);
|
2002-04-25 13:36:55 +05:00
|
|
|
key+= seg->length;
|
|
|
|
}
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
memcpy(key, &recpos, sizeof(uchar*));
|
2005-06-13 12:41:15 +02:00
|
|
|
return (uint) (key - start_key);
|
2002-04-25 13:36:55 +05:00
|
|
|
}
|
2002-01-12 15:42:54 +02:00
|
|
|
|
2004-08-26 18:26:38 +03:00
|
|
|
|
|
|
|
uint hp_rb_pack_key(HP_KEYDEF *keydef, uchar *key, const uchar *old,
|
2007-03-17 00:13:25 +01:00
|
|
|
key_part_map keypart_map)
|
2002-04-25 13:36:55 +05:00
|
|
|
{
|
2002-04-25 15:10:29 +05:00
|
|
|
HA_KEYSEG *seg, *endseg;
|
2002-04-25 13:36:55 +05:00
|
|
|
uchar *start_key= key;
|
2007-03-17 00:13:25 +01:00
|
|
|
|
2002-11-15 16:45:08 +04:00
|
|
|
for (seg= keydef->seg, endseg= seg + keydef->keysegs;
|
2007-01-29 10:40:26 +01:00
|
|
|
seg < endseg && keypart_map; old+= seg->length, seg++)
|
2002-04-25 13:36:55 +05:00
|
|
|
{
|
2004-08-16 19:58:50 +05:00
|
|
|
uint char_length;
|
2007-01-29 10:40:26 +01:00
|
|
|
keypart_map>>= 1;
|
2002-04-25 13:36:55 +05:00
|
|
|
if (seg->null_bit)
|
2002-05-21 21:54:08 +05:00
|
|
|
{
|
|
|
|
if (!(*key++= (char) 1 - *old++))
|
|
|
|
continue;
|
2002-11-15 16:45:08 +04:00
|
|
|
}
|
2002-11-19 18:48:22 +04:00
|
|
|
if (seg->flag & HA_SWAP_KEY)
|
|
|
|
{
|
|
|
|
uint length= seg->length;
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
uchar *pos= (uchar*) old + length;
|
2002-11-19 18:48:22 +04:00
|
|
|
|
|
|
|
while (length--)
|
|
|
|
{
|
|
|
|
*key++= *--pos;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2004-12-06 02:00:37 +02:00
|
|
|
if (seg->flag & (HA_VAR_LENGTH_PART | HA_BLOB_PART))
|
|
|
|
{
|
|
|
|
/* Length of key-part used with heap_rkey() always 2 */
|
|
|
|
uint tmp_length=uint2korr(old);
|
|
|
|
uint length= seg->length;
|
|
|
|
CHARSET_INFO *cs= seg->charset;
|
|
|
|
char_length= length/cs->mbmaxlen;
|
|
|
|
|
|
|
|
old+= 2;
|
|
|
|
set_if_smaller(length,tmp_length); /* Safety */
|
|
|
|
FIX_LENGTH(cs, old, length, char_length);
|
|
|
|
store_key_length_inc(key,char_length);
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
memcpy((uchar*) key, old,(size_t) char_length);
|
2004-12-06 02:00:37 +02:00
|
|
|
key+= char_length;
|
|
|
|
continue;
|
|
|
|
}
|
2004-08-26 18:26:38 +03:00
|
|
|
char_length= seg->length;
|
|
|
|
if (seg->charset->mbmaxlen > 1)
|
2004-08-16 19:58:50 +05:00
|
|
|
{
|
2004-08-26 18:26:38 +03:00
|
|
|
char_length= my_charpos(seg->charset, old, old+char_length,
|
|
|
|
char_length / seg->charset->mbmaxlen);
|
|
|
|
set_if_smaller(char_length, seg->length); /* QQ: ok to remove? */
|
2004-08-16 19:58:50 +05:00
|
|
|
if (char_length < seg->length)
|
2004-10-22 18:44:51 +03:00
|
|
|
seg->charset->cset->fill(seg->charset, (char*) key + char_length,
|
2004-08-16 19:58:50 +05:00
|
|
|
seg->length - char_length, ' ');
|
|
|
|
}
|
|
|
|
memcpy(key, old, (size_t) char_length);
|
2002-04-25 13:36:55 +05:00
|
|
|
key+= seg->length;
|
|
|
|
}
|
2005-06-13 12:41:15 +02:00
|
|
|
return (uint) (key - start_key);
|
2002-04-25 13:36:55 +05:00
|
|
|
}
|
2002-05-21 21:54:08 +05:00
|
|
|
|
2004-08-26 18:26:38 +03:00
|
|
|
|
2002-05-23 19:26:16 +05:00
|
|
|
uint hp_rb_key_length(HP_KEYDEF *keydef,
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
const uchar *key __attribute__((unused)))
|
2002-05-23 19:26:16 +05:00
|
|
|
{
|
|
|
|
return keydef->length;
|
|
|
|
}
|
|
|
|
|
2004-08-26 18:26:38 +03:00
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
uint hp_rb_null_key_length(HP_KEYDEF *keydef, const uchar *key)
|
2002-05-21 21:54:08 +05:00
|
|
|
{
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
const uchar *start_key= key;
|
2002-05-21 21:54:08 +05:00
|
|
|
HA_KEYSEG *seg, *endseg;
|
|
|
|
|
2002-05-23 19:26:16 +05:00
|
|
|
for (seg= keydef->seg, endseg= seg + keydef->keysegs; seg < endseg; seg++)
|
2002-05-21 21:54:08 +05:00
|
|
|
{
|
2002-05-23 19:26:16 +05:00
|
|
|
if (seg->null_bit && !*key++)
|
|
|
|
continue;
|
|
|
|
key+= seg->length;
|
2002-05-21 21:54:08 +05:00
|
|
|
}
|
2005-06-13 12:41:15 +02:00
|
|
|
return (uint) (key - start_key);
|
2002-05-21 21:54:08 +05:00
|
|
|
}
|
2002-04-25 13:36:55 +05:00
|
|
|
|
2004-12-06 02:00:37 +02:00
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
uint hp_rb_var_key_length(HP_KEYDEF *keydef, const uchar *key)
|
2004-12-06 02:00:37 +02:00
|
|
|
{
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
const uchar *start_key= key;
|
2004-12-06 02:00:37 +02:00
|
|
|
HA_KEYSEG *seg, *endseg;
|
|
|
|
|
|
|
|
for (seg= keydef->seg, endseg= seg + keydef->keysegs; seg < endseg; seg++)
|
|
|
|
{
|
|
|
|
uint length= seg->length;
|
|
|
|
if (seg->null_bit && !*key++)
|
|
|
|
continue;
|
|
|
|
if (seg->flag & (HA_VAR_LENGTH_PART | HA_BLOB_PART))
|
|
|
|
{
|
|
|
|
get_key_length(length, key);
|
|
|
|
}
|
|
|
|
key+= length;
|
|
|
|
}
|
2005-06-13 12:41:15 +02:00
|
|
|
return (uint) (key - start_key);
|
2004-12-06 02:00:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-01-12 15:42:54 +02:00
|
|
|
/*
|
|
|
|
Test if any of the key parts are NULL.
|
|
|
|
Return:
|
|
|
|
1 if any of the key parts was NULL
|
|
|
|
0 otherwise
|
|
|
|
*/
|
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
my_bool hp_if_null_in_key(HP_KEYDEF *keydef, const uchar *record)
|
2002-01-12 15:42:54 +02:00
|
|
|
{
|
2002-04-25 15:10:29 +05:00
|
|
|
HA_KEYSEG *seg,*endseg;
|
2002-01-12 15:42:54 +02:00
|
|
|
for (seg=keydef->seg,endseg=seg+keydef->keysegs ; seg < endseg ; seg++)
|
|
|
|
{
|
|
|
|
if (seg->null_bit && (record[seg->null_pos] & seg->null_bit))
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2002-10-07 17:49:03 +05:00
|
|
|
|
2003-12-15 17:58:15 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
Update auto_increment info
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
update_auto_increment()
|
|
|
|
info MyISAM handler
|
|
|
|
record Row to update
|
|
|
|
|
|
|
|
IMPLEMENTATION
|
|
|
|
Only replace the auto_increment value if it is higher than the previous
|
|
|
|
one. For signed columns we don't update the auto increment value if it's
|
|
|
|
less than zero.
|
|
|
|
*/
|
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
|
|
|
void heap_update_auto_increment(HP_INFO *info, const uchar *record)
|
2002-10-07 17:49:03 +05:00
|
|
|
{
|
2003-12-15 17:58:15 +02:00
|
|
|
ulonglong value= 0; /* Store unsigned values here */
|
|
|
|
longlong s_value= 0; /* Store signed values here */
|
|
|
|
|
2002-10-07 17:49:03 +05:00
|
|
|
HA_KEYSEG *keyseg= info->s->keydef[info->s->auto_key - 1].seg;
|
|
|
|
const uchar *key= (uchar*) record + keyseg->start;
|
|
|
|
|
|
|
|
switch (info->s->auto_key_type) {
|
|
|
|
case HA_KEYTYPE_INT8:
|
2003-12-15 17:58:15 +02:00
|
|
|
s_value= (longlong) *(char*)key;
|
|
|
|
break;
|
2002-10-07 17:49:03 +05:00
|
|
|
case HA_KEYTYPE_BINARY:
|
2003-12-15 17:58:15 +02:00
|
|
|
value=(ulonglong) *(uchar*) key;
|
2002-10-07 17:49:03 +05:00
|
|
|
break;
|
|
|
|
case HA_KEYTYPE_SHORT_INT:
|
2003-12-15 17:58:15 +02:00
|
|
|
s_value= (longlong) sint2korr(key);
|
|
|
|
break;
|
2002-10-07 17:49:03 +05:00
|
|
|
case HA_KEYTYPE_USHORT_INT:
|
2003-12-15 17:58:15 +02:00
|
|
|
value=(ulonglong) uint2korr(key);
|
2002-10-07 17:49:03 +05:00
|
|
|
break;
|
|
|
|
case HA_KEYTYPE_LONG_INT:
|
2003-12-15 17:58:15 +02:00
|
|
|
s_value= (longlong) sint4korr(key);
|
|
|
|
break;
|
2002-10-07 17:49:03 +05:00
|
|
|
case HA_KEYTYPE_ULONG_INT:
|
2003-12-15 17:58:15 +02:00
|
|
|
value=(ulonglong) uint4korr(key);
|
2002-10-07 17:49:03 +05:00
|
|
|
break;
|
|
|
|
case HA_KEYTYPE_INT24:
|
2003-12-15 17:58:15 +02:00
|
|
|
s_value= (longlong) sint3korr(key);
|
|
|
|
break;
|
2002-10-07 17:49:03 +05:00
|
|
|
case HA_KEYTYPE_UINT24:
|
2003-12-15 17:58:15 +02:00
|
|
|
value=(ulonglong) uint3korr(key);
|
2002-10-07 17:49:03 +05:00
|
|
|
break;
|
2003-12-15 17:58:15 +02:00
|
|
|
case HA_KEYTYPE_FLOAT: /* This shouldn't be used */
|
2002-10-07 17:49:03 +05:00
|
|
|
{
|
|
|
|
float f_1;
|
2003-12-15 17:58:15 +02:00
|
|
|
float4get(f_1,key);
|
|
|
|
/* Ignore negative values */
|
|
|
|
value = (f_1 < (float) 0.0) ? 0 : (ulonglong) f_1;
|
2002-10-07 17:49:03 +05:00
|
|
|
break;
|
|
|
|
}
|
2003-12-15 17:58:15 +02:00
|
|
|
case HA_KEYTYPE_DOUBLE: /* This shouldn't be used */
|
2002-10-07 17:49:03 +05:00
|
|
|
{
|
|
|
|
double f_1;
|
2003-12-15 17:58:15 +02:00
|
|
|
float8get(f_1,key);
|
|
|
|
/* Ignore negative values */
|
|
|
|
value = (f_1 < 0.0) ? 0 : (ulonglong) f_1;
|
2002-10-07 17:49:03 +05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case HA_KEYTYPE_LONGLONG:
|
2003-12-15 17:58:15 +02:00
|
|
|
s_value= sint8korr(key);
|
|
|
|
break;
|
2002-10-07 17:49:03 +05:00
|
|
|
case HA_KEYTYPE_ULONGLONG:
|
|
|
|
value= uint8korr(key);
|
|
|
|
break;
|
|
|
|
default:
|
2003-12-15 17:58:15 +02:00
|
|
|
DBUG_ASSERT(0);
|
|
|
|
value=0; /* Error */
|
2002-10-07 17:49:03 +05:00
|
|
|
break;
|
|
|
|
}
|
2003-12-15 17:58:15 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
The following code works becasue if s_value < 0 then value is 0
|
|
|
|
and if s_value == 0 then value will contain either s_value or the
|
|
|
|
correct value.
|
|
|
|
*/
|
|
|
|
set_if_bigger(info->s->auto_increment,
|
|
|
|
(s_value > 0) ? (ulonglong) s_value : value);
|
2002-10-07 17:49:03 +05:00
|
|
|
}
|