Skip to content

Commit

Permalink
Make correction in value computation
Browse files Browse the repository at this point in the history
  • Loading branch information
igniting committed Jul 26, 2014
1 parent 142ce2b commit 10e4493
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
18 changes: 9 additions & 9 deletions sql/opt_costmodel.cc
Expand Up @@ -64,15 +64,15 @@ void Global_cost_factors::set_global_factor(const char *name, double value)
assign_factor_value(name, value, all_names);
}

void Global_cost_factors::update_global_factor(uint index, double query_time)
void Global_cost_factors::update_global_factor(uint index, ulonglong ops, double value)
{
switch(index)
{
case TIME_FOR_COMPARE:
time_for_compare.add_query_time(query_time);
time_for_compare.add_time(ops, value);
break;
case TIME_FOR_COMPARE_ROWID:
time_for_compare_rowid.add_query_time(query_time);
time_for_compare_rowid.add_time(ops, value);
break;
}
}
Expand All @@ -87,15 +87,15 @@ void Engine_cost_factors::set_engine_factor(const char *name, double value)
assign_factor_value(name, value, all_names);
}

void Engine_cost_factors::update_engine_factor(uint index, double query_time)
void Engine_cost_factors::update_engine_factor(uint index, ulonglong ops, double value)
{
switch(index)
{
case READ_TIME:
read_time.add_query_time(query_time);
read_time.add_time(ops, value);
break;
case SCAN_TIME:
scan_time.add_query_time(query_time);
scan_time.add_time(ops, value);
break;
}
}
Expand Down Expand Up @@ -206,15 +206,15 @@ double Cost_factors::time_for_compare_rowid() const
return global.time_for_compare_rowid.value;
}

void Cost_factors::update_cost_factor(uint index, double query_time)
void Cost_factors::update_cost_factor(uint index, ulonglong ops, double value)
{
if(index < MAX_GLOBAL_CONSTANTS)
global.update_global_factor(index, query_time);
global.update_global_factor(index, ops, value);
else
{
uint engine_no = (index - MAX_GLOBAL_CONSTANTS)/ MAX_ENGINE_CONSTANTS;
uint const_no = (index - MAX_GLOBAL_CONSTANTS) % MAX_ENGINE_CONSTANTS;
engine[engine_no].update_engine_factor(const_no, query_time);
engine[engine_no].update_engine_factor(const_no, ops, value);
}
}

Expand Down
32 changes: 16 additions & 16 deletions sql/opt_costmodel.h
Expand Up @@ -25,29 +25,29 @@ class Cost_factor
{
public:
double value;
ulonglong total_queries;
double total_query_time;
double total_query_time_squared;
ulonglong total_ops;
double total_time;
double total_time_squared;

Cost_factor()
{
total_queries= 0;
total_query_time= 0;
total_query_time_squared= 0;
total_ops= 0;
total_time= 0;
total_time_squared= 0;
}

inline void add_query_time(double query_time)
inline void add_time(ulonglong ops, double value)
{
total_queries++;
total_query_time += query_time;
total_query_time_squared += (query_time*query_time);
total_ops+= ops;
total_time += (ops*value);
total_time_squared += (ops*value)*(ops*value);
}

inline void update_all(Cost_factor that)
{
total_queries+= that.total_queries;
total_query_time+= that.total_query_time;
total_query_time_squared+= that.total_query_time_squared;
total_ops+= that.total_ops;
total_time+= that.total_time;
total_time_squared+= that.total_time_squared;
}
};

Expand All @@ -73,7 +73,7 @@ class Global_cost_factors
}

void set_global_factor(const char *name, double value);
void update_global_factor(uint index, double query_time);
void update_global_factor(uint index, ulonglong ops, double value);
inline void update_global_factor(Global_cost_factors that)
{
time_for_compare.update_all(that.time_for_compare);
Expand All @@ -94,7 +94,7 @@ class Engine_cost_factors
}

void set_engine_factor(const char *name, double value);
void update_engine_factor(uint index, double query_time);
void update_engine_factor(uint index, ulonglong ops, double value);
inline void update_engine_factor(Engine_cost_factors that)
{
read_time.update_all(that.read_time);
Expand Down Expand Up @@ -123,7 +123,7 @@ class Cost_factors
double time_for_compare_rowid() const;

/* Update a cost factor */
void update_cost_factor(uint index, double query_time);
void update_cost_factor(uint index, ulonglong total_ops, double value);

/* Add data from another Cost_factors object */
void add_data(Cost_factors that);
Expand Down
4 changes: 2 additions & 2 deletions sql/sql_class.cc
Expand Up @@ -6531,8 +6531,8 @@ void THD::solve_equation()
{
for(row_indx= 0; row_indx< num_rows; row_indx++)
{
double query_time = coefficients[row_indx][index].value*out->sol_vec->elements[index];
thd_cost_factors.update_cost_factor(index, query_time);
thd_cost_factors.update_cost_factor(index,
coefficients[row_indx][index].value, out->sol_vec->elements[index]);
}
}
}
Expand Down

0 comments on commit 10e4493

Please sign in to comment.