Skip to content

Commit

Permalink
cleanups and simplifications
Browse files Browse the repository at this point in the history
  • Loading branch information
vuvova committed Oct 5, 2015
1 parent 7ca8b4b commit c93ac0a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 40 deletions.
2 changes: 1 addition & 1 deletion sql/group_by_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ int Pushdown_query::execute(JOIN *join)
}

/* 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)
{
Expand Down
25 changes: 9 additions & 16 deletions sql/group_by_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,13 @@ class group_by_handler
{
public:
THD *thd;
List<Item> *fields;
TABLE_LIST *table_list;
ORDER *group_by, *order_by;
Item *where, *having;
handlerton *ht;

/* Temporary table where all results should be stored in record[0] */
TABLE *table;

group_by_handler(THD *thd_arg, List<Item> *fields_arg,
TABLE_LIST *table_list_arg, ORDER *group_by_arg,
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) {}
group_by_handler(THD *thd_arg, handlerton *ht_arg)
: thd(thd_arg), ht(ht_arg), table(0) {}
virtual ~group_by_handler() {}

/*
Expand All @@ -65,15 +56,17 @@ class group_by_handler
This is becasue we can't revert back the old having and order_by elements.
*/

virtual bool init(TABLE *temporary_table, Item *having_arg,
ORDER *order_by_arg)
virtual bool init(Item *having_arg, ORDER *order_by_arg)
{
table= temporary_table;
having= having_arg;
order_by= order_by_arg;
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.
Should be initialized on object creation.
Expand Down
6 changes: 3 additions & 3 deletions sql/sql_select.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1960,13 +1960,13 @@ JOIN::optimize_inner()
DBUG_RETURN(1);

/* Give storage engine access to temporary table */
if ((err= gbh->init(exec_tmp_table1,
having, order)))
if ((err= gbh->ha_init(exec_tmp_table1, having, order)))
{
gbh->print_error(err, MYF(0));
DBUG_RETURN(1);
}
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
according to the group_by
Expand Down Expand Up @@ -2080,7 +2080,7 @@ int JOIN::init_execution()
thd->lex->set_limit_rows_examined();

/* 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"));
THD_STAGE_INFO(thd, stage_copying_to_tmp_table);
Expand Down
3 changes: 2 additions & 1 deletion sql/sql_select.h
Original file line number Diff line number Diff line change
Expand Up @@ -1971,10 +1971,11 @@ class Pushdown_query: public Sql_alloc
SELECT_LEX *select_lex;
bool store_data_in_temp_table;
group_by_handler *handler;
Item *having;

Pushdown_query(SELECT_LEX *select_lex_arg, group_by_handler *handler_arg)
: select_lex(select_lex_arg), store_data_in_temp_table(0),
handler(handler_arg) {}
handler(handler_arg), having(0) {}

~Pushdown_query() { delete handler; }

Expand Down
25 changes: 6 additions & 19 deletions storage/sequence/sequence.cc
Original file line number Diff line number Diff line change
Expand Up @@ -359,18 +359,16 @@ static int dummy_ret_int() { return 0; }

class ha_seq_group_by_handler: public group_by_handler
{
List<Item> *fields;
TABLE_LIST *table_list;
bool first_row;

public:
ha_seq_group_by_handler(THD *thd_arg, List<Item> *fields_arg,
TABLE_LIST *table_list_arg, ORDER *group_by_arg,
ORDER *order_by_arg, Item *where_arg,
Item *having_arg)
:group_by_handler(thd_arg, fields_arg, table_list_arg, group_by_arg,
order_by_arg, where_arg, having_arg, sequence_hton) {}
TABLE_LIST *table_list_arg)
: group_by_handler(thd_arg, sequence_hton), fields(fields_arg),
table_list(table_list_arg) {}
~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 next_row();
int end_scan() { return 0; }
Expand Down Expand Up @@ -427,21 +425,10 @@ create_group_by_handler(THD *thd, List<Item> *fields, TABLE_LIST *table_list,
}

/* Create handler and return it */
handler= new ha_seq_group_by_handler(thd, fields, table_list, group_by,
order_by, where, having);
handler= new ha_seq_group_by_handler(thd, fields, table_list);
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()
{
List_iterator_fast<Item> it(*fields);
Expand Down

0 comments on commit c93ac0a

Please sign in to comment.