2006-12-31 01:02:27 +01:00
|
|
|
/* Copyright (C) 2000-2002, 2004-2006 MySQL AB
|
2001-12-06 13:10:51 +01: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 13:10:51 +01: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 13:10:51 +01: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 */
|
|
|
|
|
|
|
|
/* Write a record to heap-databas */
|
|
|
|
|
|
|
|
#include "heapdef.h"
|
|
|
|
#ifdef __WIN__
|
|
|
|
#include <fcntl.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define LOWFIND 1
|
|
|
|
#define LOWUSED 2
|
|
|
|
#define HIGHFIND 4
|
|
|
|
#define HIGHUSED 8
|
|
|
|
|
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 11:59:39 +02:00
|
|
|
static uchar *next_free_record_pos(HP_SHARE *info);
|
2002-04-25 10:36:55 +02:00
|
|
|
static HASH_INFO *hp_find_free_hash(HP_SHARE *info, HP_BLOCK *block,
|
2000-07-31 21:29:14 +02:00
|
|
|
ulong records);
|
|
|
|
|
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 11:59:39 +02:00
|
|
|
int heap_write(HP_INFO *info, const uchar *record)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2002-04-25 10:36:55 +02:00
|
|
|
HP_KEYDEF *keydef, *end;
|
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 11:59:39 +02:00
|
|
|
uchar *pos;
|
2000-07-31 21:29:14 +02:00
|
|
|
HP_SHARE *share=info->s;
|
|
|
|
DBUG_ENTER("heap_write");
|
|
|
|
#ifndef DBUG_OFF
|
2001-09-12 22:53:31 +02:00
|
|
|
if (info->mode & O_RDONLY)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
DBUG_RETURN(my_errno=EACCES);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (!(pos=next_free_record_pos(share)))
|
|
|
|
DBUG_RETURN(my_errno);
|
|
|
|
share->changed=1;
|
|
|
|
|
2002-04-25 10:36:55 +02:00
|
|
|
for (keydef = share->keydef, end = keydef + share->keys; keydef < end;
|
|
|
|
keydef++)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2002-04-25 10:36:55 +02:00
|
|
|
if ((*keydef->write_key)(info, keydef, record, pos))
|
2000-07-31 21:29:14 +02:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(pos,record,(size_t) share->reclength);
|
|
|
|
pos[share->reclength]=1; /* Mark record as not deleted */
|
|
|
|
if (++share->records == share->blength)
|
|
|
|
share->blength+= share->blength;
|
|
|
|
info->current_ptr=pos;
|
|
|
|
info->current_hash_ptr=0;
|
|
|
|
info->update|=HA_STATE_AKTIV;
|
2002-11-29 15:40:18 +01:00
|
|
|
#if !defined(DBUG_OFF) && defined(EXTRA_HEAP_DEBUG)
|
|
|
|
DBUG_EXECUTE("check_heap",heap_check_heap(info, 0););
|
|
|
|
#endif
|
2002-10-07 14:49:03 +02:00
|
|
|
if (share->auto_key)
|
|
|
|
heap_update_auto_increment(info, record);
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_RETURN(0);
|
2002-11-29 15:40:18 +01:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
err:
|
2007-01-09 10:24:25 +01:00
|
|
|
if (my_errno == HA_ERR_FOUND_DUPP_KEY)
|
2007-01-09 11:07:39 +01:00
|
|
|
DBUG_PRINT("info",("Duplicate key: %d", (int) (keydef - share->keydef)));
|
2009-02-10 23:47:54 +01:00
|
|
|
info->errkey= (int) (keydef - share->keydef);
|
2007-01-09 10:24:25 +01:00
|
|
|
/*
|
2007-01-09 10:39:05 +01:00
|
|
|
We don't need to delete non-inserted key from rb-tree. Also, if
|
|
|
|
we got ENOMEM, the key wasn't inserted, so don't try to delete it
|
|
|
|
either. Otherwise for HASH index on HA_ERR_FOUND_DUPP_KEY the key
|
|
|
|
was inserted and we have to delete it.
|
2007-01-09 10:24:25 +01:00
|
|
|
*/
|
2007-01-09 10:39:05 +01:00
|
|
|
if (keydef->algorithm == HA_KEY_ALG_BTREE || my_errno == ENOMEM)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2002-04-25 10:36:55 +02:00
|
|
|
keydef--;
|
|
|
|
}
|
|
|
|
while (keydef >= share->keydef)
|
|
|
|
{
|
|
|
|
if ((*keydef->delete_key)(info, keydef, record, pos, 0))
|
2000-07-31 21:29:14 +02:00
|
|
|
break;
|
2002-04-25 10:36:55 +02:00
|
|
|
keydef--;
|
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
share->deleted++;
|
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 11:59:39 +02:00
|
|
|
*((uchar**) pos)=share->del_link;
|
2000-07-31 21:29:14 +02:00
|
|
|
share->del_link=pos;
|
|
|
|
pos[share->reclength]=0; /* Record deleted */
|
2002-11-29 15:40:18 +01:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_RETURN(my_errno);
|
|
|
|
} /* heap_write */
|
|
|
|
|
2002-04-25 10:36:55 +02:00
|
|
|
/*
|
|
|
|
Write a key to rb_tree-index
|
|
|
|
*/
|
|
|
|
|
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 11:59:39 +02:00
|
|
|
int hp_rb_write_key(HP_INFO *info, HP_KEYDEF *keyinfo, const uchar *record,
|
|
|
|
uchar *recpos)
|
2002-04-25 10:36:55 +02:00
|
|
|
{
|
|
|
|
heap_rb_param custom_arg;
|
2004-02-19 21:33:16 +01:00
|
|
|
uint old_allocated;
|
2002-04-25 10:36:55 +02:00
|
|
|
|
2002-05-21 18:54:08 +02:00
|
|
|
custom_arg.keyseg= keyinfo->seg;
|
|
|
|
custom_arg.key_length= hp_rb_make_key(keyinfo, info->recbuf, record, recpos);
|
2002-05-28 17:46:35 +02:00
|
|
|
if (keyinfo->flag & HA_NOSAME)
|
2002-04-25 10:36:55 +02:00
|
|
|
{
|
2006-05-11 18:15:37 +02:00
|
|
|
custom_arg.search_flag= SEARCH_FIND | SEARCH_UPDATE;
|
2002-05-28 17:46:35 +02:00
|
|
|
keyinfo->rb_tree.flag= TREE_NO_DUPS;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
custom_arg.search_flag= SEARCH_SAME;
|
|
|
|
keyinfo->rb_tree.flag= 0;
|
|
|
|
}
|
2004-02-19 21:33:16 +01:00
|
|
|
old_allocated= keyinfo->rb_tree.allocated;
|
2002-05-28 17:46:35 +02:00
|
|
|
if (!tree_insert(&keyinfo->rb_tree, (void*)info->recbuf,
|
|
|
|
custom_arg.key_length, &custom_arg))
|
|
|
|
{
|
|
|
|
my_errno= HA_ERR_FOUND_DUPP_KEY;
|
|
|
|
return 1;
|
2002-04-25 10:36:55 +02:00
|
|
|
}
|
2004-02-19 21:33:16 +01:00
|
|
|
info->s->index_length+= (keyinfo->rb_tree.allocated-old_allocated);
|
2002-05-28 17:46:35 +02:00
|
|
|
return 0;
|
2002-04-25 10:36:55 +02:00
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
/* Find where to place new 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 11:59:39 +02:00
|
|
|
static uchar *next_free_record_pos(HP_SHARE *info)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
int block_pos;
|
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 11:59:39 +02:00
|
|
|
uchar *pos;
|
|
|
|
size_t length;
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_ENTER("next_free_record_pos");
|
|
|
|
|
|
|
|
if (info->del_link)
|
|
|
|
{
|
|
|
|
pos=info->del_link;
|
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 11:59:39 +02:00
|
|
|
info->del_link= *((uchar**) pos);
|
2000-07-31 21:29:14 +02:00
|
|
|
info->deleted--;
|
2006-11-20 21:42:06 +01:00
|
|
|
DBUG_PRINT("exit",("Used old position: 0x%lx",(long) pos));
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_RETURN(pos);
|
|
|
|
}
|
|
|
|
if (!(block_pos=(info->records % info->block.records_in_block)))
|
|
|
|
{
|
2005-01-14 19:49:45 +01:00
|
|
|
if ((info->records > info->max_records && info->max_records) ||
|
|
|
|
(info->data_length + info->index_length >= info->max_table_size))
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
my_errno=HA_ERR_RECORD_FILE_FULL;
|
|
|
|
DBUG_RETURN(NULL);
|
|
|
|
}
|
2002-04-25 10:36:55 +02:00
|
|
|
if (hp_get_new_block(&info->block,&length))
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_RETURN(NULL);
|
|
|
|
info->data_length+=length;
|
|
|
|
}
|
2006-11-20 21:42:06 +01:00
|
|
|
DBUG_PRINT("exit",("Used new position: 0x%lx",
|
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 11:59:39 +02:00
|
|
|
(long) ((uchar*) info->block.level_info[0].last_blocks+
|
2006-11-20 21:42:06 +01:00
|
|
|
block_pos * info->block.recbuffer)));
|
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 11:59:39 +02:00
|
|
|
DBUG_RETURN((uchar*) info->block.level_info[0].last_blocks+
|
2000-07-31 21:29:14 +02:00
|
|
|
block_pos*info->block.recbuffer);
|
|
|
|
}
|
|
|
|
|
2004-10-12 16:21:25 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
Write a hash-key to the hash-index
|
|
|
|
SYNOPSIS
|
|
|
|
info Heap table info
|
|
|
|
keyinfo Key info
|
|
|
|
record Table record to added
|
|
|
|
recpos Memory buffer where the table record will be stored if added
|
|
|
|
successfully
|
|
|
|
NOTE
|
|
|
|
Hash index uses HP_BLOCK structure as a 'growable array' of HASH_INFO
|
|
|
|
structs. Array size == number of entries in hash index.
|
|
|
|
hp_mask(hp_rec_hashnr()) maps hash entries values to hash array positions.
|
|
|
|
If there are several hash entries with the same hash array position P,
|
|
|
|
they are connected in a linked list via HASH_INFO::next_key. The first
|
|
|
|
list element is located at position P, next elements are located at
|
|
|
|
positions for which there is no record that should be located at that
|
|
|
|
position. The order of elements in the list is arbitrary.
|
|
|
|
|
|
|
|
RETURN
|
|
|
|
0 - OK
|
|
|
|
-1 - Out of memory
|
|
|
|
HA_ERR_FOUND_DUPP_KEY - Duplicate record on unique key. The record was
|
|
|
|
still added and the caller must call hp_delete_key for it.
|
|
|
|
*/
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2002-04-25 10:36:55 +02:00
|
|
|
int hp_write_key(HP_INFO *info, HP_KEYDEF *keyinfo,
|
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 11:59:39 +02:00
|
|
|
const uchar *record, uchar *recpos)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2002-04-25 10:36:55 +02:00
|
|
|
HP_SHARE *share = info->s;
|
2000-07-31 21:29:14 +02:00
|
|
|
int flag;
|
|
|
|
ulong halfbuff,hashnr,first_index;
|
2009-09-17 17:25:52 +02:00
|
|
|
uchar *UNINIT_VAR(ptr_to_rec),*UNINIT_VAR(ptr_to_rec2);
|
2009-09-17 17:10:30 +02:00
|
|
|
HASH_INFO *empty,*UNINIT_VAR(gpos),*UNINIT_VAR(gpos2),*pos;
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_ENTER("hp_write_key");
|
|
|
|
|
|
|
|
flag=0;
|
2002-04-25 10:36:55 +02:00
|
|
|
if (!(empty= hp_find_free_hash(share,&keyinfo->block,share->records)))
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_RETURN(-1); /* No more memory */
|
2002-04-25 10:36:55 +02:00
|
|
|
halfbuff= (long) share->blength >> 1;
|
|
|
|
pos= hp_find_hash(&keyinfo->block,(first_index=share->records-halfbuff));
|
2004-09-08 00:07:53 +02:00
|
|
|
|
|
|
|
/*
|
2004-10-12 16:21:25 +02:00
|
|
|
We're about to add one more hash array position, with hash_mask=#records.
|
|
|
|
The number of hash positions will change and some entries might need to
|
|
|
|
be relocated to the newly added position. Those entries are currently
|
|
|
|
members of the list that starts at #first_index position (this is
|
|
|
|
guaranteed by properties of hp_mask(hp_rec_hashnr(X)) mapping function)
|
|
|
|
At #first_index position currently there may be either:
|
|
|
|
a) An entry with hashnr != first_index. We don't need to move it.
|
|
|
|
or
|
|
|
|
b) A list of items with hash_mask=first_index. The list contains entries
|
|
|
|
of 2 types:
|
2004-09-08 00:07:53 +02:00
|
|
|
1) entries that should be relocated to the list that starts at new
|
2004-10-12 16:21:25 +02:00
|
|
|
position we're adding ('uppper' list)
|
2004-09-08 00:07:53 +02:00
|
|
|
2) entries that should be left in the list starting at #first_index
|
2004-10-12 16:21:25 +02:00
|
|
|
position ('lower' list)
|
2004-09-08 00:07:53 +02:00
|
|
|
*/
|
2000-07-31 21:29:14 +02:00
|
|
|
if (pos != empty) /* If some records */
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
2002-04-25 10:36:55 +02:00
|
|
|
hashnr = hp_rec_hashnr(keyinfo, pos->ptr_to_rec);
|
2004-10-12 16:21:25 +02:00
|
|
|
if (flag == 0)
|
2004-09-08 00:07:53 +02:00
|
|
|
{
|
2004-10-12 16:21:25 +02:00
|
|
|
/*
|
|
|
|
First loop, bail out if we're dealing with case a) from above
|
|
|
|
comment
|
|
|
|
*/
|
2002-04-25 10:36:55 +02:00
|
|
|
if (hp_mask(hashnr, share->blength, share->records) != first_index)
|
2000-07-31 21:29:14 +02:00
|
|
|
break;
|
2004-09-08 00:07:53 +02:00
|
|
|
}
|
2004-10-12 16:21:25 +02:00
|
|
|
/*
|
|
|
|
flag & LOWFIND - found a record that should be put into lower position
|
|
|
|
flag & LOWUSED - lower position occupied by the record
|
|
|
|
Same for HIGHFIND and HIGHUSED and 'upper' position
|
|
|
|
|
|
|
|
gpos - ptr to last element in lower position's list
|
|
|
|
gpos2 - ptr to last element in upper position's list
|
|
|
|
|
|
|
|
ptr_to_rec - ptr to last entry that should go into lower list.
|
|
|
|
ptr_to_rec2 - same for upper list.
|
|
|
|
*/
|
2000-07-31 21:29:14 +02:00
|
|
|
if (!(hashnr & halfbuff))
|
2004-10-12 16:21:25 +02:00
|
|
|
{
|
|
|
|
/* Key should be put into 'lower' list */
|
2000-07-31 21:29:14 +02:00
|
|
|
if (!(flag & LOWFIND))
|
|
|
|
{
|
2004-10-12 16:21:25 +02:00
|
|
|
/* key is the first element to go into lower position */
|
2000-07-31 21:29:14 +02:00
|
|
|
if (flag & HIGHFIND)
|
|
|
|
{
|
|
|
|
flag=LOWFIND | HIGHFIND;
|
|
|
|
/* key shall be moved to the current empty position */
|
|
|
|
gpos=empty;
|
|
|
|
ptr_to_rec=pos->ptr_to_rec;
|
|
|
|
empty=pos; /* This place is now free */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-10-12 16:21:25 +02:00
|
|
|
/*
|
|
|
|
We can only get here at first iteration: key is at 'lower'
|
|
|
|
position pos and should be left here.
|
|
|
|
*/
|
|
|
|
flag=LOWFIND | LOWUSED;
|
2000-07-31 21:29:14 +02:00
|
|
|
gpos=pos;
|
|
|
|
ptr_to_rec=pos->ptr_to_rec;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2004-10-12 16:21:25 +02:00
|
|
|
{
|
|
|
|
/* Already have another key for lower position */
|
2000-07-31 21:29:14 +02:00
|
|
|
if (!(flag & LOWUSED))
|
|
|
|
{
|
2004-10-12 16:21:25 +02:00
|
|
|
/* Change link of previous lower-list key */
|
2000-07-31 21:29:14 +02:00
|
|
|
gpos->ptr_to_rec=ptr_to_rec;
|
|
|
|
gpos->next_key=pos;
|
|
|
|
flag= (flag & HIGHFIND) | (LOWFIND | LOWUSED);
|
|
|
|
}
|
|
|
|
gpos=pos;
|
|
|
|
ptr_to_rec=pos->ptr_to_rec;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2004-10-12 16:21:25 +02:00
|
|
|
{
|
|
|
|
/* key will be put into 'higher' list */
|
2000-07-31 21:29:14 +02:00
|
|
|
if (!(flag & HIGHFIND))
|
|
|
|
{
|
|
|
|
flag= (flag & LOWFIND) | HIGHFIND;
|
|
|
|
/* key shall be moved to the last (empty) position */
|
2004-10-12 16:21:25 +02:00
|
|
|
gpos2= empty;
|
|
|
|
empty= pos;
|
2000-07-31 21:29:14 +02:00
|
|
|
ptr_to_rec2=pos->ptr_to_rec;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!(flag & HIGHUSED))
|
|
|
|
{
|
2004-10-12 16:21:25 +02:00
|
|
|
/* Change link of previous upper-list key and save */
|
2000-07-31 21:29:14 +02:00
|
|
|
gpos2->ptr_to_rec=ptr_to_rec2;
|
|
|
|
gpos2->next_key=pos;
|
|
|
|
flag= (flag & LOWFIND) | (HIGHFIND | HIGHUSED);
|
|
|
|
}
|
|
|
|
gpos2=pos;
|
|
|
|
ptr_to_rec2=pos->ptr_to_rec;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while ((pos=pos->next_key));
|
2004-09-08 00:07:53 +02:00
|
|
|
|
2004-10-12 16:21:25 +02:00
|
|
|
if ((flag & (LOWFIND | HIGHFIND)) == (LOWFIND | HIGHFIND))
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
If both 'higher' and 'lower' list have at least one element, now
|
|
|
|
there are two hash buckets instead of one.
|
|
|
|
*/
|
2004-09-08 00:07:53 +02:00
|
|
|
keyinfo->hash_buckets++;
|
2004-10-12 16:21:25 +02:00
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
if ((flag & (LOWFIND | LOWUSED)) == LOWFIND)
|
|
|
|
{
|
|
|
|
gpos->ptr_to_rec=ptr_to_rec;
|
|
|
|
gpos->next_key=0;
|
|
|
|
}
|
|
|
|
if ((flag & (HIGHFIND | HIGHUSED)) == HIGHFIND)
|
|
|
|
{
|
|
|
|
gpos2->ptr_to_rec=ptr_to_rec2;
|
|
|
|
gpos2->next_key=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Check if we are at the empty position */
|
|
|
|
|
2002-04-25 10:36:55 +02:00
|
|
|
pos=hp_find_hash(&keyinfo->block, hp_mask(hp_rec_hashnr(keyinfo, record),
|
|
|
|
share->blength, share->records + 1));
|
2000-07-31 21:29:14 +02:00
|
|
|
if (pos == empty)
|
|
|
|
{
|
|
|
|
pos->ptr_to_rec=recpos;
|
|
|
|
pos->next_key=0;
|
2004-09-08 00:07:53 +02:00
|
|
|
keyinfo->hash_buckets++;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Check if more records in same hash-nr family */
|
|
|
|
empty[0]=pos[0];
|
|
|
|
gpos=hp_find_hash(&keyinfo->block,
|
2002-04-25 10:36:55 +02:00
|
|
|
hp_mask(hp_rec_hashnr(keyinfo, pos->ptr_to_rec),
|
|
|
|
share->blength, share->records + 1));
|
2000-07-31 21:29:14 +02:00
|
|
|
if (pos == gpos)
|
|
|
|
{
|
|
|
|
pos->ptr_to_rec=recpos;
|
|
|
|
pos->next_key=empty;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-09-08 00:07:53 +02:00
|
|
|
keyinfo->hash_buckets++;
|
2000-07-31 21:29:14 +02:00
|
|
|
pos->ptr_to_rec=recpos;
|
|
|
|
pos->next_key=0;
|
2002-04-25 10:36:55 +02:00
|
|
|
hp_movelink(pos, gpos, empty);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2002-01-15 23:42:52 +01:00
|
|
|
/* Check if duplicated keys */
|
2002-01-12 14:42:54 +01:00
|
|
|
if ((keyinfo->flag & HA_NOSAME) && pos == gpos &&
|
|
|
|
(!(keyinfo->flag & HA_NULL_PART_KEY) ||
|
|
|
|
!hp_if_null_in_key(keyinfo, record)))
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
pos=empty;
|
|
|
|
do
|
|
|
|
{
|
2004-12-06 01:00:37 +01:00
|
|
|
if (! hp_rec_key_cmp(keyinfo, record, pos->ptr_to_rec, 1))
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
DBUG_RETURN(my_errno=HA_ERR_FOUND_DUPP_KEY);
|
|
|
|
}
|
|
|
|
} while ((pos=pos->next_key));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns ptr to block, and allocates block if neaded */
|
|
|
|
|
2002-04-25 10:36:55 +02:00
|
|
|
static HASH_INFO *hp_find_free_hash(HP_SHARE *info,
|
2000-07-31 21:29:14 +02:00
|
|
|
HP_BLOCK *block, ulong records)
|
|
|
|
{
|
|
|
|
uint block_pos;
|
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 11:59:39 +02:00
|
|
|
size_t length;
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
if (records < block->last_allocated)
|
|
|
|
return hp_find_hash(block,records);
|
|
|
|
if (!(block_pos=(records % block->records_in_block)))
|
|
|
|
{
|
2002-04-25 10:36:55 +02:00
|
|
|
if (hp_get_new_block(block,&length))
|
2000-07-31 21:29:14 +02:00
|
|
|
return(NULL);
|
|
|
|
info->index_length+=length;
|
|
|
|
}
|
|
|
|
block->last_allocated=records+1;
|
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 11:59:39 +02:00
|
|
|
return((HASH_INFO*) ((uchar*) block->level_info[0].last_blocks+
|
2000-07-31 21:29:14 +02:00
|
|
|
block_pos*block->recbuffer));
|
|
|
|
}
|