summaryrefslogtreecommitdiff
path: root/sql/opt_range.cc
diff options
context:
space:
mode:
authorunknown <dlenev@brandersnatch.localdomain>2004-09-23 13:48:17 +0400
committerunknown <dlenev@brandersnatch.localdomain>2004-09-23 13:48:17 +0400
commitcf9e30b8cb8f5cc14ccca866ba4503cb5d8e914d (patch)
tree72c836976a5eb3e3b63f565445ab8ca1ea26e4d8 /sql/opt_range.cc
parentf7613e9eca0e56dbeef3963f9245cd523cb3616a (diff)
downloadmariadb-git-cf9e30b8cb8f5cc14ccca866ba4503cb5d8e914d.tar.gz
Implementation of Monty's idea about clear_alloc_root() optimization and cleanup of work
with memory roots in THD/Statement/Item_arena. Added assertions preventing memory allocation on bzero'ed MEM_ROOT since it is worked by pure luck and was very ineffective. include/my_sys.h: Reimplementation of Monty's optimization of clear_alloc_root(). Now clear_alloc_root() can be used only for detaching memory associated with MEM_ROOT (e.g. to avoid its freeing). It can not be used for MEM_ROOT initialization any longer (it was bad idea anyway since memory allocation on such MEM_ROOT was very ineffective and worked by pure luck). Introduced ALLOC_ROOT_MIN_BLOCK_SIZE constant. mysys/my_alloc.c: Added description of init_alloc_root(). Added assertions to alloc_root() and reset_root_defaults() so now they can only be used on previosly initialized MEM_ROOT. (It worked for bzeroed MEM_ROOT before but by pure luck and very inefficiently). Calling free_root() on bzero'ed MEM_ROOT is still ok (we can't remove this easily because of static MEM_ROOTs). Also now using ALLOC_ROOT_MIN_BLOCK_SIZE constant inside these functions. sql/opt_range.cc: Fixed get_quick_select_for_ref() function to not use bzero'ed MEM_ROOT for allocation. Also QUICK_RANGEs created in this function should be created in memory root of QUICK_SELECT. sql/sql_class.cc: Implementation of Monty's idea about clear_alloc_root() optimization and cleanup of work with memory roots in THD/Statement/Item_arena. Now we are always initing THD::transaction.mem_root and THD::mem_root in THD constructor (without memory allocation and with minimal block size) and then later change their parameters in THD::init_for_queries() (this is partially because we can't allocate anything on bzero'ed memory roots anymore). Item_arena() constructor is now trivial and is used only then Item_arena is created as backup storage for other Item_arena (we use Item_arena(bool) now if it is part of Statement). Both trivial Item_arena constructor and destructor are now inline. Removed unneeded clear_alloc_root from Item_arena::restore_backup_item_arena(). sql/sql_class.h: Both trivial Item_arena constructor and destructor are now inline. Commented various Item_arena constructors.
Diffstat (limited to 'sql/opt_range.cc')
-rw-r--r--sql/opt_range.cc8
1 files changed, 6 insertions, 2 deletions
diff --git a/sql/opt_range.cc b/sql/opt_range.cc
index 27e8e9c11e7..9c5b0235767 100644
--- a/sql/opt_range.cc
+++ b/sql/opt_range.cc
@@ -2554,7 +2554,8 @@ static bool null_part_in_key(KEY_PART *key_part, const char *key, uint length)
QUICK_SELECT *get_quick_select_for_ref(THD *thd, TABLE *table, TABLE_REF *ref)
{
- QUICK_SELECT *quick=new QUICK_SELECT(thd, table, ref->key, 1);
+ MEM_ROOT *old_root= my_pthread_getspecific_ptr(MEM_ROOT*, THR_MALLOC);
+ QUICK_SELECT *quick= new QUICK_SELECT(thd, table, ref->key);
KEY *key_info = &table->key_info[ref->key];
KEY_PART *key_part;
QUICK_RANGE *range;
@@ -2566,7 +2567,7 @@ QUICK_SELECT *get_quick_select_for_ref(THD *thd, TABLE *table, TABLE_REF *ref)
{
if (thd->is_fatal_error)
goto err; // out of memory
- return quick; // empty range
+ goto ok; // empty range
}
if (!(range= new QUICK_RANGE()))
@@ -2613,9 +2614,12 @@ QUICK_SELECT *get_quick_select_for_ref(THD *thd, TABLE *table, TABLE_REF *ref)
goto err;
}
+ok:
+ my_pthread_setspecific_ptr(THR_MALLOC, old_root);
return quick;
err:
+ my_pthread_setspecific_ptr(THR_MALLOC, old_root);
delete quick;
return 0;
}