summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMonty <monty@mariadb.org>2014-08-29 14:07:43 +0300
committerSergey Vojtovich <svoj@mariadb.org>2015-03-06 12:36:55 +0400
commitd4076bad363e314d246ca41550c62d0e98b5458c (patch)
tree10403deb80c7a081d2a5c8e468c4799498b0ab69
parentb96a7e2ef786c580ba6691230d92a40bc4ea02e1 (diff)
downloadmariadb-git-d4076bad363e314d246ca41550c62d0e98b5458c.tar.gz
my_alloc.c
- Changed 0x%lx -> %p array.c: - Static (preallocated) buffer can now be anywhere my_sys.h - Define MY_INIT_BUFFER_USED sql_delete.cc & sql_lex.cc - Use memroot when allocating classes (avoids call to current_thd) sql_explain.h: - Use preallocated buffers sql_explain.cc: - Use preallocated buffers and memroot sql_select.cc: - Use multi_alloc_root() instead of many alloc_root() - Update calls to Explain Conflicts: mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result sql/sql_delete.cc sql/sql_explain.cc sql/sql_explain.h sql/sql_select.cc
-rw-r--r--sql/sql_delete.cc6
-rw-r--r--sql/sql_explain.cc31
-rw-r--r--sql/sql_explain.h86
-rw-r--r--sql/sql_insert.cc2
-rw-r--r--sql/sql_lex.cc2
-rw-r--r--sql/sql_select.cc37
-rw-r--r--sql/sql_select.h2
7 files changed, 100 insertions, 66 deletions
diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc
index 99b44e6008c..b494c850a32 100644
--- a/sql/sql_delete.cc
+++ b/sql/sql_delete.cc
@@ -54,7 +54,8 @@
void Delete_plan::save_explain_data(Explain_query *query)
{
- Explain_delete* explain= new Explain_delete;
+ Explain_delete *explain= (new (query->mem_root)
+ Explain_delete(query->mem_root));
if (deleting_all_rows)
{
@@ -74,7 +75,8 @@ void Delete_plan::save_explain_data(Explain_query *query)
void Update_plan::save_explain_data(Explain_query *query)
{
- Explain_update* explain= new Explain_update;
+ Explain_update* explain= (new (query->mem_root)
+ Explain_update(query->mem_root));
save_explain_data_intern(query, explain);
query->add_upd_del_plan(explain);
}
diff --git a/sql/sql_explain.cc b/sql/sql_explain.cc
index 75f6689ab98..b0084c0b02e 100644
--- a/sql/sql_explain.cc
+++ b/sql/sql_explain.cc
@@ -23,10 +23,11 @@
#include "sql_select.h"
-Explain_query::Explain_query(THD *thd_arg) :
- upd_del_plan(NULL), insert_plan(NULL), thd(thd_arg), apc_enabled(false)
+Explain_query::Explain_query(THD *thd_arg, MEM_ROOT *root) :
+ mem_root(root), upd_del_plan(NULL), insert_plan(NULL),
+ unions(root), selects(root), thd(thd_arg), apc_enabled(false),
+ operations(0)
{
- operations= 0;
}
@@ -136,7 +137,7 @@ int Explain_query::send_explain(THD *thd)
select_result *result;
LEX *lex= thd->lex;
- if (!(result= new select_send()) ||
+ if (!(result= new (thd->mem_root) select_send()) ||
thd->send_explain_fields(result))
return 1;
@@ -334,10 +335,23 @@ Explain_select::~Explain_select()
{
for (uint i= 0; i< n_join_tabs; i++)
delete join_tabs[i];
- my_free(join_tabs);
}
}
+bool Explain_select::add_table(Explain_table_access *tab, Explain_query *query)
+{
+ if (!join_tabs)
+ {
+ n_join_tabs= 0;
+ if (!(join_tabs= ((Explain_table_access**)
+ alloc_root(query->mem_root,
+ sizeof(Explain_table_access*) *
+ MAX_TABLES))))
+ return true;
+ }
+ join_tabs[n_join_tabs++]= tab;
+ return false;
+}
int Explain_select::print_explain(Explain_query *query,
select_result_sink *output,
@@ -937,9 +951,12 @@ void delete_explain_query(LEX *lex)
void create_explain_query(LEX *lex, MEM_ROOT *mem_root)
{
DBUG_ASSERT(!lex->explain);
- lex->explain= new Explain_query(lex->thd);
+ DBUG_ENTER("create_explain_query");
+
+ lex->explain= new (mem_root) Explain_query(lex->thd, mem_root);
DBUG_ASSERT(mem_root == current_thd->mem_root);
- lex->explain->mem_root= mem_root;
+
+ DBUG_VOID_RETURN;
}
void create_explain_query_if_not_exists(LEX *lex, MEM_ROOT *mem_root)
diff --git a/sql/sql_explain.h b/sql/sql_explain.h
index b9f381b867b..0febd2d5add 100644
--- a/sql/sql_explain.h
+++ b/sql/sql_explain.h
@@ -37,6 +37,9 @@ class Explain_query;
class Explain_node : public Sql_alloc
{
public:
+ Explain_node(MEM_ROOT *root)
+ :children(root)
+ {}
enum explain_node_type
{
EXPLAIN_UNION,
@@ -82,8 +85,8 @@ class Explain_table_access;
In the non-degenerate case, a SELECT may have a GROUP BY/ORDER BY operation.
- In both cases, the select may have children nodes. class Explain_node provides
- a way get node's children.
+ In both cases, the select may have children nodes. class Explain_node
+ provides a way get node's children.
*/
class Explain_select : public Explain_node
@@ -91,24 +94,15 @@ class Explain_select : public Explain_node
public:
enum explain_node_type get_type() { return EXPLAIN_SELECT; }
- Explain_select() :
+ Explain_select(MEM_ROOT *root) :
+ Explain_node(root),
message(NULL), join_tabs(NULL),
using_temporary(false), using_filesort(false)
{}
~Explain_select();
- bool add_table(Explain_table_access *tab)
- {
- if (!join_tabs)
- {
- join_tabs= (Explain_table_access**) my_malloc(sizeof(Explain_table_access*) *
- MAX_TABLES, MYF(0));
- n_join_tabs= 0;
- }
- join_tabs[n_join_tabs++]= tab;
- return false;
- }
+ bool add_table(Explain_table_access *tab, Explain_query *query);
public:
int select_id;
@@ -147,6 +141,10 @@ public:
class Explain_union : public Explain_node
{
public:
+ Explain_union(MEM_ROOT *root) :
+ Explain_node(root)
+ {}
+
enum explain_node_type get_type() { return EXPLAIN_UNION; }
int get_select_id()
@@ -221,7 +219,7 @@ class Explain_insert;
class Explain_query : public Sql_alloc
{
public:
- Explain_query(THD *thd);
+ Explain_query(THD *thd, MEM_ROOT *root);
~Explain_query();
/* Add a new node */
@@ -389,26 +387,37 @@ private:
class Explain_table_access : public Sql_alloc
{
public:
+ Explain_table_access(MEM_ROOT *root) :
+ extra_tags(root)
+ {}
+
void push_extra(enum explain_extra_tag extra_tag);
/* Internals */
-public:
- /*
- 0 means this tab is not inside SJM nest and should use Explain_select's id
- other value means the tab is inside an SJM nest.
- */
- int sjm_nest_select_id;
/* id and 'select_type' are cared-of by the parent Explain_select */
StringBuffer<32> table_name;
+ StringBuffer<32> used_partitions;
+ /* Empty string means "NULL" will be printed */
+ StringBuffer<32> possible_keys_str;
+ StringBuffer<32> ref;
+ // valid with ET_USING_MRR
+ StringBuffer<32> mrr_type;
+ StringBuffer<32> firstmatch_table_name;
enum join_type type;
+ /*
+ 0 means this tab is not inside SJM nest and should use Explain_select's id
+ other value means the tab is inside an SJM nest.
+ */
+ int sjm_nest_select_id;
- StringBuffer<32> used_partitions;
bool used_partitions_set;
-
- /* Empty string means "NULL" will be printed */
- StringBuffer<32> possible_keys_str;
+ bool ref_set; /* not set means 'NULL' should be printed */
+ bool rows_set; /* not set means 'NULL' should be printed */
+ bool filtered_set; /* not set means 'NULL' should be printed */
+ // Valid if ET_USING_INDEX_FOR_GROUP_BY is present
+ bool loose_scan_is_scanning;
/*
Index use: key name and length.
@@ -426,13 +435,7 @@ public:
*/
Explain_index_use hash_next_key;
- bool ref_set; /* not set means 'NULL' should be printed */
- StringBuffer<32> ref;
-
- bool rows_set; /* not set means 'NULL' should be printed */
ha_rows rows;
-
- bool filtered_set; /* not set means 'NULL' should be printed */
double filtered;
/*
@@ -444,19 +447,11 @@ public:
// Valid if ET_USING tag is present
Explain_quick_select *quick_info;
- // Valid if ET_USING_INDEX_FOR_GROUP_BY is present
- bool loose_scan_is_scanning;
-
// valid with ET_RANGE_CHECKED_FOR_EACH_RECORD
key_map range_checked_map;
- // valid with ET_USING_MRR
- StringBuffer<32> mrr_type;
-
// valid with ET_USING_JOIN_BUFFER
EXPLAIN_BKA_TYPE bka_type;
-
- StringBuffer<32> firstmatch_table_name;
int print_explain(select_result_sink *output, uint8 explain_flags,
uint select_id, const char *select_type,
@@ -476,6 +471,11 @@ private:
class Explain_update : public Explain_node
{
public:
+
+ Explain_update(MEM_ROOT *root) :
+ Explain_node(root)
+ {}
+
virtual enum explain_node_type get_type() { return EXPLAIN_UPDATE; }
virtual int get_select_id() { return 1; /* always root */ }
@@ -517,6 +517,10 @@ public:
class Explain_insert : public Explain_node
{
public:
+ Explain_insert(MEM_ROOT *root) :
+ Explain_node(root)
+ {}
+
StringBuffer<64> table_name;
enum explain_node_type get_type() { return EXPLAIN_INSERT; }
@@ -534,6 +538,10 @@ public:
class Explain_delete: public Explain_update
{
public:
+ Explain_delete(MEM_ROOT *root) :
+ Explain_update(root)
+ {}
+
/*
TRUE means we're going to call handler->delete_all_rows() and not read any
rows.
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index 1ec33a0a0ac..c5ca3682206 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -615,7 +615,7 @@ create_insert_stmt_from_insert_delayed(THD *thd, String *buf)
static void save_insert_query_plan(THD* thd, TABLE_LIST *table_list)
{
- Explain_insert* explain= new Explain_insert;
+ Explain_insert* explain= new (thd->mem_root) Explain_insert(thd->mem_root);
explain->table_name.append(table_list->table->alias);
thd->lex->explain->add_insert_plan(explain);
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index 697988a6bf8..f26d05f4cc5 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -4219,7 +4219,7 @@ int LEX::print_explain(select_result_sink *output, uint8 explain_flags,
int st_select_lex_unit::save_union_explain(Explain_query *output)
{
SELECT_LEX *first= first_select();
- Explain_union *eu= new (output->mem_root) Explain_union;
+ Explain_union *eu= new (output->mem_root) Explain_union(output->mem_root);
for (SELECT_LEX *sl= first; sl; sl= sl->next_select())
eu->add_select(sl->select_number);
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 871ae267c87..512f5febdac 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -3404,23 +3404,29 @@ make_join_statistics(JOIN *join, List<TABLE_LIST> &tables_list,
LINT_INIT(table); /* inited in all loops */
table_count=join->table_count;
- stat=(JOIN_TAB*) join->thd->calloc(sizeof(JOIN_TAB)*(table_count));
- stat_ref=(JOIN_TAB**) join->thd->alloc(sizeof(JOIN_TAB*)*
- (MAX_TABLES + table_count + 1));
- stat_vector= stat_ref + MAX_TABLES;
- table_vector=(TABLE**) join->thd->calloc(sizeof(TABLE*)*(table_count*2));
- join->positions= new (join->thd->mem_root) POSITION[(table_count+1)];
/*
best_positions is ok to allocate with alloc() as we copy things to it with
memcpy()
*/
- join->best_positions= (POSITION*) join->thd->alloc(sizeof(POSITION)*
- (table_count +1));
- if (join->thd->is_fatal_error)
- DBUG_RETURN(1); // Eom /* purecov: inspected */
+ if (!multi_alloc_root(join->thd->mem_root,
+ &stat, sizeof(JOIN_TAB)*(table_count),
+ &stat_ref, sizeof(JOIN_TAB*)* MAX_TABLES,
+ &stat_vector, sizeof(JOIN_TAB*)* (table_count +1),
+ &table_vector, sizeof(TABLE*)*(table_count*2),
+ &join->positions, sizeof(POSITION)*(table_count + 1),
+ &join->best_positions,
+ sizeof(POSITION)*(table_count + 1),
+ NullS))
+ DBUG_RETURN(1);
+
+ /* The following should be optimized to only clear critical things */
+ bzero(stat, sizeof(JOIN_TAB)* table_count);
+ /* Initialize POSITION objects */
+ for (i=0 ; i <= table_count ; i++)
+ (void) new ((char*) (join->positions + i)) POSITION;
- join->best_ref=stat_vector;
+ join->best_ref= stat_vector;
stat_end=stat+table_count;
found_const_table_map= all_table_map=0;
@@ -23437,7 +23443,7 @@ int JOIN::save_explain_data_intern(Explain_query *output, bool need_tmp_table,
if (message)
{
Explain_select *xpl_sel;
- explain_node= xpl_sel= new (output->mem_root) Explain_select;
+ explain_node= xpl_sel= new (output->mem_root) Explain_select(output->mem_root);
join->select_lex->set_explain_type(true);
xpl_sel->select_id= join->select_lex->select_number;
@@ -23454,7 +23460,7 @@ int JOIN::save_explain_data_intern(Explain_query *output, bool need_tmp_table,
join->select_lex->master_unit()->derived->is_materialized_derived())
{
Explain_select *xpl_sel;
- explain_node= xpl_sel= new (output->mem_root) Explain_select;
+ explain_node= xpl_sel= new (output->mem_root) Explain_select(output->mem_root);
table_map used_tables=0;
join->select_lex->set_explain_type(true);
@@ -23502,8 +23508,9 @@ int JOIN::save_explain_data_intern(Explain_query *output, bool need_tmp_table,
tab= pre_sort_join_tab;
}
- Explain_table_access *eta= new (output->mem_root) Explain_table_access;
- xpl_sel->add_table(eta);
+ Explain_table_access *eta= (new (output->mem_root)
+ Explain_table_access(output->mem_root));
+ xpl_sel->add_table(eta, output);
eta->key.set(thd->mem_root, NULL, (uint)-1);
eta->quick_info= NULL;
diff --git a/sql/sql_select.h b/sql/sql_select.h
index 45041def28f..4227401484a 100644
--- a/sql/sql_select.h
+++ b/sql/sql_select.h
@@ -763,7 +763,7 @@ public:
Information about a position of table within a join order. Used in join
optimization.
*/
-typedef struct st_position :public Sql_alloc
+typedef struct st_position
{
/* The table that's put into join order */
JOIN_TAB *table;