Commit 78564373 authored by Monty's avatar Monty Committed by Sergey Vojtovich

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
parent 3392278c
......@@ -3116,10 +3116,10 @@ ENUM_VALUE_LIST NULL
READ_ONLY NO
COMMAND_LINE_ARGUMENT NULL
VARIABLE_NAME QUERY_ALLOC_BLOCK_SIZE
SESSION_VALUE 8192
GLOBAL_VALUE 8192
SESSION_VALUE 16384
GLOBAL_VALUE 16384
GLOBAL_VALUE_ORIGIN COMPILE-TIME
DEFAULT_VALUE 8192
DEFAULT_VALUE 16384
VARIABLE_SCOPE SESSION
VARIABLE_TYPE BIGINT UNSIGNED
VARIABLE_COMMENT Allocation block size for query parsing and execution
......@@ -3214,14 +3214,14 @@ ENUM_VALUE_LIST OFF,ON
READ_ONLY NO
COMMAND_LINE_ARGUMENT OPTIONAL
VARIABLE_NAME QUERY_PREALLOC_SIZE
SESSION_VALUE 8192
GLOBAL_VALUE 8192
SESSION_VALUE 24576
GLOBAL_VALUE 24576
GLOBAL_VALUE_ORIGIN COMPILE-TIME
DEFAULT_VALUE 8192
DEFAULT_VALUE 24576
VARIABLE_SCOPE SESSION
VARIABLE_TYPE BIGINT UNSIGNED
VARIABLE_COMMENT Persistent buffer for query parsing and execution
NUMERIC_MIN_VALUE 8192
NUMERIC_MIN_VALUE 1024
NUMERIC_MAX_VALUE 4294967295
NUMERIC_BLOCK_SIZE 1024
ENUM_VALUE_LIST NULL
......
......@@ -54,7 +54,7 @@
void Delete_plan::save_explain_data(MEM_ROOT *mem_root, Explain_query *query)
{
Explain_delete* explain= new Explain_delete;
Explain_delete *explain= new (mem_root) Explain_delete(mem_root);
if (deleting_all_rows)
{
......@@ -74,7 +74,7 @@ void Delete_plan::save_explain_data(MEM_ROOT *mem_root, Explain_query *query)
void Update_plan::save_explain_data(MEM_ROOT *mem_root, Explain_query *query)
{
Explain_update* explain= new Explain_update;
Explain_update* explain= new (mem_root) Explain_update(mem_root);
save_explain_data_intern(mem_root, query, explain);
query->add_upd_del_plan(explain);
}
......
......@@ -27,10 +27,11 @@ const char * STR_DELETING_ALL_ROWS= "Deleting all rows";
const char * STR_IMPOSSIBLE_WHERE= "Impossible WHERE";
const char * STR_NO_ROWS_AFTER_PRUNING= "No matching rows after partition pruning";
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;
}
......@@ -140,7 +141,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, lex->describe, lex->analyze_stmt))
return 1;
......@@ -225,7 +226,8 @@ bool print_explain_for_slow_log(LEX *lex, THD *thd, String *str)
Return tabular EXPLAIN output as a text string
*/
bool Explain_query::print_explain_str(THD *thd, String *out_str, bool is_analyze)
bool Explain_query::print_explain_str(THD *thd, String *out_str,
bool is_analyze)
{
List<Item> fields;
thd->make_explain_field_list(fields, thd->lex->describe, is_analyze);
......@@ -551,6 +553,20 @@ int Explain_node::print_explain_for_children(Explain_query *query,
return 0;
}
bool Explain_basic_join::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;
}
/*
This tells whether a child subquery should be printed in JSON output.
......@@ -609,7 +625,6 @@ Explain_basic_join::~Explain_basic_join()
{
for (uint i= 0; i< n_join_tabs; i++)
delete join_tabs[i];
my_free(join_tabs);
}
}
......@@ -1895,9 +1910,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)
......
......@@ -90,6 +90,9 @@ class Json_writer;
class Explain_node : public Sql_alloc
{
public:
Explain_node(MEM_ROOT *root)
:children(root)
{}
/* A type specifying what kind of node this is */
enum explain_node_type
{
......@@ -158,20 +161,10 @@ class Explain_basic_join : public Explain_node
public:
enum explain_node_type get_type() { return EXPLAIN_BASIC_JOIN; }
Explain_basic_join() : join_tabs(NULL) {}
Explain_basic_join(MEM_ROOT *root) : Explain_node(root), join_tabs(NULL) {}
~Explain_basic_join();
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);
int get_select_id() { return select_id; }
......@@ -199,8 +192,8 @@ public:
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_basic_join
......@@ -208,7 +201,8 @@ class Explain_select : public Explain_basic_join
public:
enum explain_node_type get_type() { return EXPLAIN_SELECT; }
Explain_select() :
Explain_select(MEM_ROOT *root) :
Explain_basic_join(root),
message(NULL),
using_temporary(false), using_filesort(false)
{}
......@@ -255,6 +249,10 @@ private:
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()
......@@ -348,7 +346,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 */
......@@ -536,9 +534,10 @@ private:
class Explain_table_access : public Sql_alloc
{
public:
Explain_table_access() :
Explain_table_access(MEM_ROOT *root) :
derived_select_number(0),
non_merged_sjm_number(0),
extra_tags(root),
start_dups_weedout(false),
end_dups_weedout(false),
where_cond(NULL),
......@@ -551,9 +550,13 @@ public:
void push_extra(enum explain_extra_tag extra_tag);
/* Internals */
public:
/* id and 'select_type' are cared-of by the parent Explain_select */
StringBuffer<32> table_name;
StringBuffer<32> used_partitions;
// valid with ET_USING_MRR
StringBuffer<32> mrr_type;
StringBuffer<32> firstmatch_table_name;
/*
Non-zero number means this is a derived table. The number can be used to
......@@ -565,11 +568,15 @@ public:
enum join_type type;
StringBuffer<32> used_partitions;
bool used_partitions_set;
/* Empty means "NULL" will be printed */
String_list possible_keys;
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.
......@@ -589,10 +596,7 @@ public:
String_list ref_list;
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;
/*
......@@ -604,19 +608,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;
bool start_dups_weedout;
bool end_dups_weedout;
......@@ -633,6 +629,12 @@ public:
Explain_basic_join *sjm_nest;
/* ANALYZE members */
/* Tracker for reading the table */
Table_access_tracker tracker;
Table_access_tracker jbuf_tracker;
int print_explain(select_result_sink *output, uint8 explain_flags,
bool is_analyze,
uint select_id, const char *select_type,
......@@ -640,12 +642,6 @@ public:
void print_explain_json(Explain_query *query, Json_writer *writer,
bool is_analyze);
/* ANALYZE members */
/* Tracker for reading the table */
Table_access_tracker tracker;
Table_access_tracker jbuf_tracker;
private:
void append_tag_name(String *str, enum explain_extra_tag tag);
void fill_key_str(String *key_str, bool is_json) const;
......@@ -665,6 +661,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 */ }
......@@ -719,6 +720,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; }
......@@ -738,6 +743,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.
......
......@@ -612,7 +612,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);
......
......@@ -4253,7 +4253,7 @@ void LEX::restore_set_statement_var()
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);
if (derived)
eu->connection_type= Explain_node::EXPLAIN_NODE_DERIVED;
......
......@@ -3413,23 +3413,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;
......@@ -23267,15 +23273,18 @@ int append_possible_keys(MEM_ROOT *alloc, String_list &list, TABLE *table,
return 0;
}
// TODO: this function is only applicable for the first non-const optimization
// join tab.
/*
TODO: this function is only applicable for the first non-const optimization
join tab.
*/
void JOIN_TAB::update_explain_data(uint idx)
{
if (this == first_breadth_first_tab(join, WALK_OPTIMIZATION_TABS) + join->const_tables &&
join->select_lex->select_number != INT_MAX &&
join->select_lex->select_number != UINT_MAX)
{
Explain_table_access *eta= new Explain_table_access();
Explain_table_access *eta= new (join->thd->mem_root) Explain_table_access(join->thd->mem_root);
JOIN_TAB* const first_top_tab= first_breadth_first_tab(join, WALK_OPTIMIZATION_TABS);
save_explain_data(eta, join->const_table_map, join->select_distinct, first_top_tab);
......@@ -23721,7 +23730,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;
......@@ -23740,7 +23749,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);
......@@ -23781,7 +23790,8 @@ 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;
Explain_table_access *eta= (new (output->mem_root)
Explain_table_access(output->mem_root));
if (tab->bush_root_tab != prev_bush_root_tab)
{
......@@ -23790,7 +23800,7 @@ int JOIN::save_explain_data_intern(Explain_query *output, bool need_tmp_table,
/*
We've entered an SJ-Materialization nest. Create an object for it.
*/
cur_parent= new Explain_basic_join;
cur_parent= new (output->mem_root) Explain_basic_join(output->mem_root);
JOIN_TAB *first_child= tab->bush_root_tab->bush_children->start;
cur_parent->select_id=
......@@ -23809,7 +23819,7 @@ int JOIN::save_explain_data_intern(Explain_query *output, bool need_tmp_table,
}
prev_bush_root_tab= tab->bush_root_tab;
cur_parent->add_table(eta);
cur_parent->add_table(eta, output);
tab->save_explain_data(eta, used_tables, distinct, first_top_tab);
if (saved_join_tab)
......
......@@ -785,7 +785,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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment