Skip to content

Commit

Permalink
feature(StoneDB 8.0): adapt the Tianmu engine query interface to MySQ…
Browse files Browse the repository at this point in the history
…L8.0 (stoneatom#681)

adapt Tianmu engine query interface for CTAS operation
adapt Tianmu engine query interface for query operation
add Query_expression::is_prepared() to to determine whether prepare for unit
change the List<Item> to mem_root_deque<Item *> in Query::Compile function
change the List<Item> to mem_root_deque<Item *> in Query::AddFields function
  • Loading branch information
DandreChen committed Oct 11, 2022
1 parent 502d5fa commit 22e56d2
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 17 deletions.
1 change: 0 additions & 1 deletion sql/conn_handler/socket_connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1337,7 +1337,6 @@ const Listen_socket *Mysqld_socket_listener::get_listen_socket() const {

#endif // HAVE_POLL
return nullptr;
;
}

Channel_info *Mysqld_socket_listener::listen_for_connection_event() {
Expand Down
10 changes: 9 additions & 1 deletion sql/sql_cmd_ddl_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
#include "sql/current_thd.h"
#endif // NDEBUG

#include "../storage/tianmu/handler/ha_my_tianmu.h" // tianmu header file

Sql_cmd_ddl_table::Sql_cmd_ddl_table(Alter_info *alter_info)
: m_alter_info(alter_info) {
#ifndef NDEBUG
Expand Down Expand Up @@ -400,7 +402,13 @@ bool Sql_cmd_create_table::execute(THD *thd) {
else if (thd->is_strict_mode())
thd->push_internal_handler(&strict_handler);

res = populate_table(thd, lex);
int sdb_res, free_join_from_sdb, optimize_after_sdb;
Query_result * result_tianmu = dynamic_cast<Query_result *>(result);
if (Tianmu::DBHandler::Tianm_Handle_Query(thd, lex, result_tianmu, 0, sdb_res, optimize_after_sdb,
free_join_from_sdb, (int)true) == Tianmu::DBHandler::Query_Route_To::TO_MYSQL)
res = populate_table(thd, lex);
else
res = sdb_res;

// Count the number of statements offloaded to a secondary storage engine.
if (using_secondary_storage_engine() && lex->unit->is_executed())
Expand Down
11 changes: 11 additions & 0 deletions sql/sql_select.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@
#include "template_utils.h"
#include "thr_lock.h"

#include "../storage/tianmu/handler/ha_my_tianmu.h" // tianmu header file

using std::max;
using std::min;

Expand Down Expand Up @@ -554,6 +556,14 @@ bool Sql_cmd_dml::execute(THD *thd) {
}
}

if (lex->sql_command == SQLCOM_SELECT) {
int sdb_res, free_join_from_sdb, optimize_after_sdb;
if (Tianmu::DBHandler::Tianm_Handle_Query(thd, lex, result, 0, sdb_res, optimize_after_sdb,
free_join_from_sdb) != Tianmu::DBHandler::Query_Route_To::TO_MYSQL) {
if (sdb_res) goto err; else goto clean;
}
}

if (validate_use_secondary_engine(lex)) goto err;

lex->set_exec_started();
Expand Down Expand Up @@ -596,6 +606,7 @@ bool Sql_cmd_dml::execute(THD *thd) {

THD_STAGE_INFO(thd, stage_end);

clean:
// Do partial cleanup (preserve plans for EXPLAIN).
lex->cleanup(thd, false);
lex->clear_values_map();
Expand Down
2 changes: 1 addition & 1 deletion storage/tianmu/core/query.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ class Query final {
* Query_route_to::to_mysql in case of any problem and Query_route_to::to_tianmu
* otherwise
*/
Query_route_to AddFields(List<Item> &fields, const TabID &tmp_table, const bool group_by_clause,
Query_Route_To AddFields(mem_root_deque<Item *> &fields, const TabID &tmp_table, const bool group_by_clause,
int &num_of_added_fields, bool ignore_minmax, bool &aggr_used);

/*! \brief Generates AddColumn compilation steps for every field on GROUP BY
Expand Down
20 changes: 6 additions & 14 deletions storage/tianmu/core/query_compile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,13 +392,12 @@ Query_route_to Query::AddJoins(mem_root_deque<TABLE_LIST *> join, /*List<TABLE_L
return Query_route_to::TO_TIANMU;
}

Query_route_to Query::AddFields(List<Item> &fields, TabID const &tmp_table, bool const group_by_clause,
Query_Route_To Query::AddFields(mem_root_deque<Item *> &fields, TabID const &tmp_table, bool const group_by_clause,
int &num_of_added_fields, bool ignore_minmax, bool &aggregation_used) {
List_iterator_fast<Item> li(fields);
Item *item;
int added = 0;
item = li++;
while (item) {
for (auto it = fields.begin(); it != fields.end(); ++it) {
item = *it;
WrapStatus ws;
common::ColOperation oper;
bool distinct;
Expand Down Expand Up @@ -476,7 +475,6 @@ Query_route_to Query::AddFields(List<Item> &fields, TabID const &tmp_table, bool
}

added++;
item = li++;
}

num_of_added_fields = added;
Expand Down Expand Up @@ -940,11 +938,9 @@ Query_route_to Query::Compile(CompiledQuery *compiled_query, Query_block *select
if (JudgeErrors(sl) == Query_route_to::TO_MYSQL) return Query_route_to::TO_MYSQL;
SetLimit(sl, sl == selects_list ? 0 : sl->join->query_expression()->global_parameters(), offset_value, limit_value);

// stonedb8
// List<Item> *fields = &sl->fields_list; //mem_root_deque<Item *> *fields = sl->get_fields_list();

Item *conds = sl->where_cond();
ORDER *order = sl->order_list.first;
mem_root_deque<Item *> *fields = sl->get_fields_list();

// if (order) global_order = 0; //we want to zero global order (which
// seems to be always present) if we find a local order by clause
Expand Down Expand Up @@ -997,14 +993,10 @@ Query_route_to Query::Compile(CompiledQuery *compiled_query, Query_block *select
first_table, for_subq_in_where) == Query_route_to::TO_MYSQL)
throw CompilationError();

// stonedb8 start
List<Item> *fields = nullptr;
List<Item> field_list_for_subselect;
if (left_expr_for_subselect && field_for_subselect) {
field_list_for_subselect.push_back(field_for_subselect);
fields = &field_list_for_subselect;
fields->clear();
fields->push_back(field_for_subselect);
}
// stonedb8 end
bool aggr_used = false;
if (AddFields(*fields, tmp_table, group != NULL, col_count, ignore_minmax, aggr_used) == Query_route_to::TO_MYSQL)
throw CompilationError();
Expand Down
1 change: 1 addition & 0 deletions storage/tianmu/types/rc_item_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ my_decimal *Item_sum_int_rcbase::val_decimal(my_decimal *) { return NULL; }
void Item_sum_int_rcbase::int64_value(int64_t &value) {
fixed = 1;
count_ = value;
set_data_type(MYSQL_TYPE_LONGLONG);
}

void Item_sum_int_rcbase::clear() {}
Expand Down

0 comments on commit 22e56d2

Please sign in to comment.