Commit c93ac0a1 authored by Sergei Golubchik's avatar Sergei Golubchik

cleanups and simplifications

parent 7ca8b4bb
...@@ -70,7 +70,7 @@ int Pushdown_query::execute(JOIN *join) ...@@ -70,7 +70,7 @@ int Pushdown_query::execute(JOIN *join)
} }
/* Check if we can accept the row */ /* Check if we can accept the row */
if (!handler->having || handler->having->val_bool()) if (!having || having->val_bool())
{ {
if (store_data_in_temp_table) if (store_data_in_temp_table)
{ {
......
...@@ -34,22 +34,13 @@ class group_by_handler ...@@ -34,22 +34,13 @@ class group_by_handler
{ {
public: public:
THD *thd; THD *thd;
List<Item> *fields;
TABLE_LIST *table_list;
ORDER *group_by, *order_by;
Item *where, *having;
handlerton *ht; handlerton *ht;
/* Temporary table where all results should be stored in record[0] */ /* Temporary table where all results should be stored in record[0] */
TABLE *table; TABLE *table;
group_by_handler(THD *thd_arg, List<Item> *fields_arg, group_by_handler(THD *thd_arg, handlerton *ht_arg)
TABLE_LIST *table_list_arg, ORDER *group_by_arg, : thd(thd_arg), ht(ht_arg), table(0) {}
ORDER *order_by_arg, Item *where_arg, Item *having_arg,
handlerton *ht_arg)
: thd(thd_arg), fields(fields_arg), table_list(table_list_arg),
group_by(group_by_arg), order_by(order_by_arg), where(where_arg),
having(having_arg), ht(ht_arg), table(0) {}
virtual ~group_by_handler() {} virtual ~group_by_handler() {}
/* /*
...@@ -65,15 +56,17 @@ class group_by_handler ...@@ -65,15 +56,17 @@ class group_by_handler
This is becasue we can't revert back the old having and order_by elements. This is becasue we can't revert back the old having and order_by elements.
*/ */
virtual bool init(TABLE *temporary_table, Item *having_arg, virtual bool init(Item *having_arg, ORDER *order_by_arg)
ORDER *order_by_arg)
{ {
table= temporary_table;
having= having_arg;
order_by= order_by_arg;
return 0; return 0;
} }
bool ha_init(TABLE *temporary_table, Item *having_arg, ORDER *order_by_arg)
{
table= temporary_table;
return init(having_arg, order_by_arg);
}
/* /*
Bits of things the storage engine can do for this query. Bits of things the storage engine can do for this query.
Should be initialized on object creation. Should be initialized on object creation.
......
...@@ -1960,13 +1960,13 @@ JOIN::optimize_inner() ...@@ -1960,13 +1960,13 @@ JOIN::optimize_inner()
DBUG_RETURN(1); DBUG_RETURN(1);
/* Give storage engine access to temporary table */ /* Give storage engine access to temporary table */
if ((err= gbh->init(exec_tmp_table1, if ((err= gbh->ha_init(exec_tmp_table1, having, order)))
having, order)))
{ {
gbh->print_error(err, MYF(0)); gbh->print_error(err, MYF(0));
DBUG_RETURN(1); DBUG_RETURN(1);
} }
pushdown_query->store_data_in_temp_table= need_tmp; pushdown_query->store_data_in_temp_table= need_tmp;
pushdown_query->having= having;
/* /*
If no ORDER BY clause was specified explicitly, we should sort things If no ORDER BY clause was specified explicitly, we should sort things
according to the group_by according to the group_by
...@@ -2080,7 +2080,7 @@ int JOIN::init_execution() ...@@ -2080,7 +2080,7 @@ int JOIN::init_execution()
thd->lex->set_limit_rows_examined(); thd->lex->set_limit_rows_examined();
/* Create a tmp table if distinct or if the sort is too complicated */ /* Create a tmp table if distinct or if the sort is too complicated */
if (need_tmp && !pushdown_query) if (need_tmp && !exec_tmp_table1)
{ {
DBUG_PRINT("info",("Creating tmp table")); DBUG_PRINT("info",("Creating tmp table"));
THD_STAGE_INFO(thd, stage_copying_to_tmp_table); THD_STAGE_INFO(thd, stage_copying_to_tmp_table);
......
...@@ -1971,10 +1971,11 @@ class Pushdown_query: public Sql_alloc ...@@ -1971,10 +1971,11 @@ class Pushdown_query: public Sql_alloc
SELECT_LEX *select_lex; SELECT_LEX *select_lex;
bool store_data_in_temp_table; bool store_data_in_temp_table;
group_by_handler *handler; group_by_handler *handler;
Item *having;
Pushdown_query(SELECT_LEX *select_lex_arg, group_by_handler *handler_arg) Pushdown_query(SELECT_LEX *select_lex_arg, group_by_handler *handler_arg)
: select_lex(select_lex_arg), store_data_in_temp_table(0), : select_lex(select_lex_arg), store_data_in_temp_table(0),
handler(handler_arg) {} handler(handler_arg), having(0) {}
~Pushdown_query() { delete handler; } ~Pushdown_query() { delete handler; }
......
...@@ -359,18 +359,16 @@ static int dummy_ret_int() { return 0; } ...@@ -359,18 +359,16 @@ static int dummy_ret_int() { return 0; }
class ha_seq_group_by_handler: public group_by_handler class ha_seq_group_by_handler: public group_by_handler
{ {
List<Item> *fields;
TABLE_LIST *table_list;
bool first_row; bool first_row;
public: public:
ha_seq_group_by_handler(THD *thd_arg, List<Item> *fields_arg, ha_seq_group_by_handler(THD *thd_arg, List<Item> *fields_arg,
TABLE_LIST *table_list_arg, ORDER *group_by_arg, TABLE_LIST *table_list_arg)
ORDER *order_by_arg, Item *where_arg, : group_by_handler(thd_arg, sequence_hton), fields(fields_arg),
Item *having_arg) table_list(table_list_arg) {}
:group_by_handler(thd_arg, fields_arg, table_list_arg, group_by_arg,
order_by_arg, where_arg, having_arg, sequence_hton) {}
~ha_seq_group_by_handler() {} ~ha_seq_group_by_handler() {}
bool init(TABLE *temporary_table, Item *having_arg,
ORDER *order_by_arg);
int init_scan() { first_row= 1 ; return 0; } int init_scan() { first_row= 1 ; return 0; }
int next_row(); int next_row();
int end_scan() { return 0; } int end_scan() { return 0; }
...@@ -427,21 +425,10 @@ create_group_by_handler(THD *thd, List<Item> *fields, TABLE_LIST *table_list, ...@@ -427,21 +425,10 @@ create_group_by_handler(THD *thd, List<Item> *fields, TABLE_LIST *table_list,
} }
/* Create handler and return it */ /* Create handler and return it */
handler= new ha_seq_group_by_handler(thd, fields, table_list, group_by, handler= new ha_seq_group_by_handler(thd, fields, table_list);
order_by, where, having);
return handler; return handler;
} }
bool ha_seq_group_by_handler::init(TABLE *temporary_table, Item *having_arg,
ORDER *order_by_arg)
{
/*
Here we could add checks if the temporary table was created correctly
*/
return group_by_handler::init(temporary_table, having_arg, order_by_arg);
}
int ha_seq_group_by_handler::next_row() int ha_seq_group_by_handler::next_row()
{ {
List_iterator_fast<Item> it(*fields); List_iterator_fast<Item> it(*fields);
......
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