Skip to content

Commit

Permalink
feat(StoneDB 8.0): support view query, port mtr "issue342". (stoneato…
Browse files Browse the repository at this point in the history
…m#743)

[summary]
1 add condition push down logic in optimize phrase;
2 replace original_field_name function instead of get_result_field;
3 remove unused variable tianmu_bootstrap;
4 eliminate some compile warning;
  • Loading branch information
lujiashun committed Oct 19, 2022
1 parent da23ed2 commit ac32eb6
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 63 deletions.
8 changes: 4 additions & 4 deletions mysql-test/suite/tianmu/r/issue342.result
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
USE test;
CREATE TABLE `lineitem_i342` (
`l_orderkey` int(11) NOT NULL,
`l_partkey` int(11) NOT NULL,
`l_suppkey` int(11) NOT NULL,
`l_linenumber` int(11) NOT NULL,
`l_orderkey` int NOT NULL,
`l_partkey` int NOT NULL,
`l_suppkey` int NOT NULL,
`l_linenumber` int NOT NULL,
`l_quantity` decimal(15,2) NOT NULL,
`l_extendedprice` decimal(15,2) NOT NULL,
`l_discount` decimal(15,2) NOT NULL,
Expand Down
36 changes: 0 additions & 36 deletions mysql-test/suite/tianmu/t/issue342.testbak

This file was deleted.

13 changes: 11 additions & 2 deletions sql/sql_optimizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9710,6 +9710,15 @@ static bool make_join_query_block(JOIN *join, Item *cond) {
NO_PLAN_IDX)))
return true;
tab->set_condition(tmp);
/* Push condition to storage engine if this is enabled
and the condition is not guarded */
if (thd->optimizer_switch_flag(OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN) && first_inner == NO_PLAN_IDX) {
Item *push_cond = make_cond_for_table(thd, tmp, tab->table_ref->map(), tab->table_ref->map(), 0);
if (push_cond) {
/* Push condition to handler */
if (!tab->table()->file->cond_push(push_cond)) tab->table()->file->pushed_cond = push_cond;
}
}
} else {
tab->set_condition(nullptr);
}
Expand Down Expand Up @@ -10381,7 +10390,7 @@ bool optimize_cond(THD *thd, Item **cond, COND_EQUAL **cond_equal,
/*
change field = field to field = const for each found field = const
Note: Since we disable multi-equalities in the hypergraph optimizer for now,
we also cannot run this optimization; it causes spurious Impossible WHERE
we also cannot run this optimization; it causes spurious "Impossible WHERE"
in e.g. main.select_none.
*/
if (*cond && !thd->lex->using_hypergraph_optimizer) {
Expand Down Expand Up @@ -10761,7 +10770,7 @@ ORDER *create_order_from_distinct(THD *thd, Ref_item_array ref_item_array,
BIT type and will be returned to a client.
@note setup_ref_array() needs to account for the extra space.
@note We need to defer the actual adding to after the loop,
or we will invalidate the iterator to fields.
or we will invalidate the iterator to "fields".
*/
Item_field *new_item = new Item_field(thd, (Item_field *)item);
ord->item = &item; // Temporary; for the duplicate check above.
Expand Down
11 changes: 5 additions & 6 deletions storage/tianmu/core/query_compile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ bool Query::FieldUnmysterify(Item *item, TabID &tab, AttrID &col) {
// Physical table in FROM - RCTable
int field_num;
for (field_num = 0; mysql_table->field[field_num]; field_num++)
if (mysql_table->field[field_num]->field_name == ifield->get_result_field()->field_name) break;
if (mysql_table->field[field_num]->field_name == ifield->original_field_name()) break;
if (!mysql_table->field[field_num]) continue;
col = AttrID(field_num);
return true;
Expand Down Expand Up @@ -303,11 +303,10 @@ Query_route_to Query::AddJoins(mem_root_deque<TABLE_LIST *> join, /*List<TABLE_L
// we are in the second select in the union
// stonedb8 start
// while ((join_ptr = li++) != nullptr) reversed.push_back(join_ptr);
// size_t size = reversed.size();
// for (unsigned int i = 0; i < size; i++) {
for (TABLE_LIST *join_ptr : join) {
// join_ptr = reversed[size - i - 1];
// stonedb8 end

size_t size = join.size();
for (size_t i = 0; i < size; i++) {
auto join_ptr = join[size - i - 1];
if (join_ptr->nested_join) {
std::vector<TabID> local_left, local_right;
if (AddJoins(join_ptr->nested_join->join_list, tmp_table, local_left, local_right, in_subquery, first_table,
Expand Down
8 changes: 4 additions & 4 deletions storage/tianmu/handler/ha_my_tianmu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ Query_route_to Tianmu_Handle_Query(THD *thd, Query_expression *qe, Query_result
if (ret == DBHandler::Query_route_to::TO_MYSQL && AtLeastOneTianmuTableInvolved(qe) &&
ForbiddenMySQLQueryPath(qe)) {
my_message(static_cast<int>(common::ErrorCode::UNKNOWN_ERROR),
"The query includes syntax that is not supported by the storage engine. \
Either restructure the query with supported syntax, or enable the MySQL core::Query Path \
in config file to execute the query with reduced performance.",
"The query includes syntax that is not supported by the storage engine. "
"Either restructure the query with supported syntax, or enable the MySQL core::Query Path "
"in config file to execute the query with reduced performance.",
MYF(0));
ret = Query_route_to::TO_TIANMU;
}
Expand Down Expand Up @@ -165,6 +165,6 @@ bool Tianmu_Load(THD *thd, sql_exchange *ex, TABLE_LIST *table_list, void *arg)
return false;
}

bool Tianmu_Get_Insert_Delayed_Flag(THD *thd) { return tianmu_sysvar_insert_delayed; }
bool Tianmu_Get_Insert_Delayed_Flag([[maybe_unused]] THD *thd) { return tianmu_sysvar_insert_delayed; }
} // namespace DBHandler
} // namespace Tianmu
2 changes: 1 addition & 1 deletion storage/tianmu/handler/ha_my_tianmu.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void Tianmu_UpdateAndStoreColumnComment(TABLE *table, int field_id, Field *sourc
// processing the load operation.
bool Tianmu_Load(THD *thd, sql_exchange *ex, TABLE_LIST *table_list, void *arg);

bool Tianmu_Get_Insert_Delayed_Flag(THD *thd);
bool Tianmu_Get_Insert_Delayed_Flag([[maybe_unused]] THD *thd);

} // namespace DBHandler
} // namespace Tianmu
Expand Down
10 changes: 0 additions & 10 deletions storage/tianmu/handler/ha_tianmu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@
namespace Tianmu {
namespace DBHandler {

extern bool tianmu_bootstrap = 0;

char *strmov_str(char *dst, const char *src) {
while ((*dst++ = *src++))
;
Expand Down Expand Up @@ -1714,8 +1712,6 @@ handler *rcbase_create_handler(handlerton *hton, TABLE_SHARE *table, bool partit
}

int rcbase_panic_func([[maybe_unused]] handlerton *hton, enum ha_panic_function flag) {
if (tianmu_bootstrap) return 0;

if (flag == HA_PANIC_CLOSE) {
delete ha_rcengine_;
ha_rcengine_ = nullptr;
Expand Down Expand Up @@ -1823,8 +1819,6 @@ bool rcbase_show_status([[maybe_unused]] handlerton *hton, THD *thd, stat_print_
return false;
}

extern bool tianmu_bootstrap;

static int init_variables() {
opt_binlog_order_commits = false;
return 0;
Expand Down Expand Up @@ -1857,10 +1851,6 @@ int rcbase_init_func(void *p) {
tianmu_hton->show_status = rcbase_show_status;
tianmu_hton->file_extensions = ha_tianmu_exts;

// When mysqld runs as bootstrap mode, we do not need to initialize
// memmanager.
if (tianmu_bootstrap) DBUG_RETURN(0);

int ret = 1;
ha_rcengine_ = nullptr;

Expand Down

0 comments on commit ac32eb6

Please sign in to comment.