mirror of
https://github.com/MariaDB/server.git
synced 2025-01-17 12:32:27 +01:00
bd1c2d65c4
Add support for LIMIT # OFFSET # Changed lock handling: Now all locks should be stored in TABLE_LIST instead of passed to functions. Don't call query_cache_invalidate() twice in some cases mysql_change_user() now clears states to be equal to close + connect. Fixed a bug with multi-table-update and multi-table-delete when used with LOCK TABLES Fixed a bug with replicate-do and UPDATE BitKeeper/etc/ignore: added autom4te.cache/* bdb/dist/autom4te.cache/* innobase/autom4te.cache/* include/my_alloc.h: Small improvement to alloc_root libmysql/libmysql.c: Removed compiler warning myisam/mi_page.c: Better DBUG message mysql-test/r/multi_update.result: Added test with lock tables mysql-test/r/rpl_replicate_do.result: Update results mysql-test/r/rpl_rotate_logs.result: Make test independent of if t1 exists mysql-test/t/multi_update.test: Added test with lock tables mysql-test/t/rpl_rotate_logs.test: Make test independent of if t1 exists mysys/my_alloc.c: Small imprevement to alloc_root (Don't free blocks less than ALLOC_MAX_BLOCK_ROOT (4K) sql/ha_innodb.cc: More debug messages sql/ha_myisam.cc: Safety change sql/lex.h: Add support for LIMIT # OFFSET # sql/lock.cc: Added assertion sql/mysql_priv.h: Change of lock handling sql/mysqld.cc: Added function clear_error_messages() sql/sql_base.cc: Change lock handling by open_ltable() and open_and_lock_tables() sql/sql_class.cc: Split THD::THD to two functions Move some code from cleanup() to ~THD:THD Add THD::change_user() sql/sql_class.h: Prototype changes in class THD sql/sql_delete.cc: Remove locking argument from mysql_delete() Locking type is now stored in TABLE_LIST Small code change to not call query_cache_invalidate() twice for transactional tables. sql/sql_insert.cc: Remove locking argument from mysql_insert() Locking type is now stored in TABLE_LIST Small code change to not call query_cache_invalidate() twice for transactional tables. Don't use bulk insert if bulk_insert_buff_size is 0 sql/sql_parse.cc: Changes to make mysql_change_user() work as close+connect Changed command statistics to use statstics_increment to get more speed Update code to handle that locks is now stored in TABLE_LIST sql/sql_update.cc: Remove locking argument from mysql_update() Locking type is now stored in TABLE_LIST Small code change to not call query_cache_invalidate() twice for transactional tables. sql/sql_yacc.yy: Locking type is now stored in TABLE_LIST Added support for LIMIT # OFFSET # syntax Removed some wrong (never true) checks for SQLCOM_MULTI_UPDATE mysql-test/t/rpl_replicate_do-slave.opt: Changed tables to use t1,t2,... mysql-test/t/rpl_replicate_do.test: Changed tables to use t1,t2,...
236 lines
6.2 KiB
C
236 lines
6.2 KiB
C
/* Copyright (C) 2000 MySQL AB
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
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.
|
|
|
|
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 */
|
|
|
|
/* Routines to handle mallocing of results which will be freed the same time */
|
|
|
|
#include <my_global.h>
|
|
#include <my_sys.h>
|
|
#include <m_string.h>
|
|
#undef EXTRA_DEBUG
|
|
#define EXTRA_DEBUG
|
|
|
|
void init_alloc_root(MEM_ROOT *mem_root, uint block_size,
|
|
uint pre_alloc_size __attribute__((unused)))
|
|
{
|
|
mem_root->free= mem_root->used= 0;
|
|
mem_root->min_malloc= 32;
|
|
mem_root->block_size= block_size-MALLOC_OVERHEAD-sizeof(USED_MEM)-8;
|
|
mem_root->error_handler= 0;
|
|
mem_root->block_num= 4; /* We shift this with >>2 */
|
|
mem_root->first_block_usage= 0;
|
|
#if !(defined(HAVE_purify) && defined(EXTRA_DEBUG))
|
|
if (pre_alloc_size)
|
|
{
|
|
if ((mem_root->free= mem_root->pre_alloc=
|
|
(USED_MEM*) my_malloc(pre_alloc_size+ ALIGN_SIZE(sizeof(USED_MEM)),
|
|
MYF(0))))
|
|
{
|
|
mem_root->free->size= pre_alloc_size+ALIGN_SIZE(sizeof(USED_MEM));
|
|
mem_root->free->left= pre_alloc_size;
|
|
mem_root->free->next= 0;
|
|
}
|
|
}
|
|
#endif
|
|
}
|
|
|
|
gptr alloc_root(MEM_ROOT *mem_root,unsigned int Size)
|
|
{
|
|
#if defined(HAVE_purify) && defined(EXTRA_DEBUG)
|
|
reg1 USED_MEM *next;
|
|
Size+=ALIGN_SIZE(sizeof(USED_MEM));
|
|
|
|
if (!(next = (USED_MEM*) my_malloc(Size,MYF(MY_WME))))
|
|
{
|
|
if (mem_root->error_handler)
|
|
(*mem_root->error_handler)();
|
|
return((gptr) 0); /* purecov: inspected */
|
|
}
|
|
next->next= mem_root->used;
|
|
next->size= Size;
|
|
mem_root->used= next;
|
|
return (gptr) (((char*) next)+ALIGN_SIZE(sizeof(USED_MEM)));
|
|
#else
|
|
uint get_size, block_size;
|
|
gptr point;
|
|
reg1 USED_MEM *next= 0;
|
|
reg2 USED_MEM **prev;
|
|
|
|
Size= ALIGN_SIZE(Size);
|
|
if ((*(prev= &mem_root->free)) != NULL)
|
|
{
|
|
if ((*prev)->left < Size &&
|
|
mem_root->first_block_usage++ >= ALLOC_MAX_BLOCK_USAGE_BEFORE_DROP &&
|
|
(*prev)->left < ALLOC_MAX_BLOCK_TO_DROP)
|
|
{
|
|
next= *prev;
|
|
*prev= next->next; /* Remove block from list */
|
|
next->next= mem_root->used;
|
|
mem_root->used= next;
|
|
mem_root->first_block_usage= 0;
|
|
}
|
|
for (next= *prev ; next && next->left < Size ; next= next->next)
|
|
prev= &next->next;
|
|
}
|
|
if (! next)
|
|
{ /* Time to alloc new block */
|
|
block_size= mem_root->block_size * (mem_root->block_num >> 2);
|
|
get_size= Size+ALIGN_SIZE(sizeof(USED_MEM));
|
|
get_size= max(get_size, block_size);
|
|
|
|
if (!(next = (USED_MEM*) my_malloc(get_size,MYF(MY_WME))))
|
|
{
|
|
if (mem_root->error_handler)
|
|
(*mem_root->error_handler)();
|
|
return((gptr) 0); /* purecov: inspected */
|
|
}
|
|
mem_root->block_num++;
|
|
next->next= *prev;
|
|
next->size= get_size;
|
|
next->left= get_size-ALIGN_SIZE(sizeof(USED_MEM));
|
|
*prev=next;
|
|
}
|
|
|
|
point= (gptr) ((char*) next+ (next->size-next->left));
|
|
/*TODO: next part may be unneded due to mem_root->first_block_usage counter*/
|
|
if ((next->left-= Size) < mem_root->min_malloc)
|
|
{ /* Full block */
|
|
*prev= next->next; /* Remove block from list */
|
|
next->next= mem_root->used;
|
|
mem_root->used= next;
|
|
mem_root->first_block_usage= 0;
|
|
}
|
|
return(point);
|
|
#endif
|
|
}
|
|
|
|
/* Mark all data in blocks free for reusage */
|
|
|
|
static inline void mark_blocks_free(MEM_ROOT* root)
|
|
{
|
|
reg1 USED_MEM *next;
|
|
reg2 USED_MEM **last;
|
|
|
|
/* iterate through (partially) free blocks, mark them free */
|
|
last= &root->free;
|
|
for (next= root->free; next; next= *(last= &next->next))
|
|
next->left= next->size - ALIGN_SIZE(sizeof(USED_MEM));
|
|
|
|
/* Combine the free and the used list */
|
|
*last= next=root->used;
|
|
|
|
/* now go through the used blocks and mark them free */
|
|
for (; next; next= next->next)
|
|
next->left= next->size - ALIGN_SIZE(sizeof(USED_MEM));
|
|
|
|
/* Now everything is set; Indicate that nothing is used anymore */
|
|
root->used= 0;
|
|
}
|
|
|
|
|
|
/*
|
|
Deallocate everything used by alloc_root or just move
|
|
used blocks to free list if called with MY_USED_TO_FREE
|
|
*/
|
|
|
|
void free_root(MEM_ROOT *root, myf MyFlags)
|
|
{
|
|
reg1 USED_MEM *next,*old;
|
|
DBUG_ENTER("free_root");
|
|
|
|
if (!root)
|
|
DBUG_VOID_RETURN; /* purecov: inspected */
|
|
if (MyFlags & MY_MARK_BLOCKS_FREE)
|
|
{
|
|
mark_blocks_free(root);
|
|
DBUG_VOID_RETURN;
|
|
}
|
|
if (!(MyFlags & MY_KEEP_PREALLOC))
|
|
root->pre_alloc=0;
|
|
|
|
for (next=root->used; next ;)
|
|
{
|
|
old=next; next= next->next ;
|
|
if (old != root->pre_alloc)
|
|
my_free((gptr) old,MYF(0));
|
|
}
|
|
for (next=root->free ; next ;)
|
|
{
|
|
old=next; next= next->next;
|
|
if (old != root->pre_alloc)
|
|
my_free((gptr) old,MYF(0));
|
|
}
|
|
root->used=root->free=0;
|
|
if (root->pre_alloc)
|
|
{
|
|
root->free=root->pre_alloc;
|
|
root->free->left=root->pre_alloc->size-ALIGN_SIZE(sizeof(USED_MEM));
|
|
root->free->next=0;
|
|
}
|
|
root->block_num= 4;
|
|
root->first_block_usage= 0;
|
|
DBUG_VOID_RETURN;
|
|
}
|
|
|
|
/*
|
|
Find block that contains an object and set the pre_alloc to it
|
|
*/
|
|
|
|
void set_prealloc_root(MEM_ROOT *root, char *ptr)
|
|
{
|
|
USED_MEM *next;
|
|
for (next=root->used; next ; next=next->next)
|
|
{
|
|
if ((char*) next <= ptr && (char*) next + next->size > ptr)
|
|
{
|
|
root->pre_alloc=next;
|
|
return;
|
|
}
|
|
}
|
|
for (next=root->free ; next ; next=next->next)
|
|
{
|
|
if ((char*) next <= ptr && (char*) next + next->size > ptr)
|
|
{
|
|
root->pre_alloc=next;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
char *strdup_root(MEM_ROOT *root,const char *str)
|
|
{
|
|
return strmake_root(root, str, strlen(str));
|
|
}
|
|
|
|
char *strmake_root(MEM_ROOT *root,const char *str, uint len)
|
|
{
|
|
char *pos;
|
|
if ((pos=alloc_root(root,len+1)))
|
|
{
|
|
memcpy(pos,str,len);
|
|
pos[len]=0;
|
|
}
|
|
return pos;
|
|
}
|
|
|
|
|
|
char *memdup_root(MEM_ROOT *root,const char *str,uint len)
|
|
{
|
|
char *pos;
|
|
if ((pos=alloc_root(root,len)))
|
|
memcpy(pos,str,len);
|
|
return pos;
|
|
}
|