Skip to content

Commit

Permalink
补充并行查询特性单元测试用例
Browse files Browse the repository at this point in the history
补充pq_condition.cc单元测试用例17个
  • Loading branch information
PeterWeiWang committed Jun 10, 2021
1 parent 82272dc commit 4ae9541
Show file tree
Hide file tree
Showing 6 changed files with 457 additions and 51 deletions.
46 changes: 23 additions & 23 deletions sql/pq_condition.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include "sql/opt_range.h"
#include "sql/sql_lex.h"

static const enum_field_types NO_PQ_SUPPORTED_FIELD_TYPES [] = {
const enum_field_types NO_PQ_SUPPORTED_FIELD_TYPES [] = {
MYSQL_TYPE_TINY_BLOB,
MYSQL_TYPE_MEDIUM_BLOB,
MYSQL_TYPE_BLOB,
Expand All @@ -40,7 +40,7 @@ static const enum_field_types NO_PQ_SUPPORTED_FIELD_TYPES [] = {
MYSQL_TYPE_GEOMETRY
};

static const Item_sum::Sumfunctype NO_PQ_SUPPORTED_AGG_FUNC_TYPES [] = {
const Item_sum::Sumfunctype NO_PQ_SUPPORTED_AGG_FUNC_TYPES [] = {
Item_sum::COUNT_DISTINCT_FUNC,
Item_sum::SUM_DISTINCT_FUNC,
Item_sum::AVG_DISTINCT_FUNC,
Expand All @@ -51,7 +51,7 @@ static const Item_sum::Sumfunctype NO_PQ_SUPPORTED_AGG_FUNC_TYPES [] = {
Item_sum::VARIANCE_FUNC
};

static const Item_func::Functype NO_PQ_SUPPORTED_FUNC_TYPES [] = {
const Item_func::Functype NO_PQ_SUPPORTED_FUNC_TYPES [] = {
Item_func::MATCH_FUNC,
Item_func::SUSERVAR_FUNC,
Item_func::FUNC_SP,
Expand All @@ -61,7 +61,7 @@ static const Item_func::Functype NO_PQ_SUPPORTED_FUNC_TYPES [] = {
Item_func::XML_FUNC
};

static const char* NO_PQ_SUPPORTED_FUNC_ARGS [] = {
const char* NO_PQ_SUPPORTED_FUNC_ARGS [] = {
"rand",
"json_valid",
"json_length",
Expand All @@ -80,19 +80,19 @@ static const char* NO_PQ_SUPPORTED_FUNC_ARGS [] = {
"des_decrypt" // Data truncation
};

static const char* NO_PQ_SUPPORTED_FUNC_NO_ARGS [] = {
const char* NO_PQ_SUPPORTED_FUNC_NO_ARGS [] = {
"release_all_locks"
};

static const Item_ref::Ref_Type NO_PQ_SUPPORTED_REF_TYPES[] = {
const Item_ref::Ref_Type NO_PQ_SUPPORTED_REF_TYPES[] = {
Item_ref::OUTER_REF,
Item_ref::AGGREGATE_REF
};

/**
* return true when type is a not_supported_field; return false otherwise.
*/
static bool pq_not_support_datatype(enum_field_types type) {
bool pq_not_support_datatype(enum_field_types type) {
for (const enum_field_types &field_type : NO_PQ_SUPPORTED_FIELD_TYPES) {
if (type == field_type) {
return true;
Expand All @@ -105,7 +105,7 @@ static bool pq_not_support_datatype(enum_field_types type) {
/**
* check PQ supported function type
*/
static bool pq_not_support_functype(Item_func::Functype type) {
bool pq_not_support_functype(Item_func::Functype type) {
for (const Item_func::Functype &func_type : NO_PQ_SUPPORTED_FUNC_TYPES) {
if (type == func_type) {
return true;
Expand All @@ -118,7 +118,7 @@ static bool pq_not_support_functype(Item_func::Functype type) {
/**
* check PQ supported function
*/
static bool pq_not_support_func(Item_func *func) {
bool pq_not_support_func(Item_func *func) {
if (pq_not_support_functype(func->functype())) {
return true;
}
Expand All @@ -141,7 +141,7 @@ static bool pq_not_support_func(Item_func *func) {
/**
* check PQ support aggregation function
*/
static bool pq_not_support_aggr_functype(Item_sum::Sumfunctype type) {
bool pq_not_support_aggr_functype(Item_sum::Sumfunctype type) {
for (const Item_sum::Sumfunctype &sum_func_type : NO_PQ_SUPPORTED_AGG_FUNC_TYPES) {
if (sum_func_type == type) {
return true;
Expand All @@ -154,7 +154,7 @@ static bool pq_not_support_aggr_functype(Item_sum::Sumfunctype type) {
/**
* check PQ supported ref function
*/
static bool pq_not_support_ref(Item_ref *ref) {
bool pq_not_support_ref(Item_ref *ref) {
Item_ref::Ref_Type type = ref->ref_type();
for (auto &ref_type : NO_PQ_SUPPORTED_REF_TYPES) {
if (type == ref_type) {
Expand All @@ -172,9 +172,9 @@ struct PQ_CHECK_ITEM_TYPE {
PQ_CHECK_ITEM_FUN fun_ptr;
};

static bool check_pq_support_fieldtype(Item *item);
bool check_pq_support_fieldtype(Item *item);

static bool check_pq_support_fieldtype_of_field_item(Item *item) {
bool check_pq_support_fieldtype_of_field_item(Item *item) {
Field *field = static_cast<Item_field *>(item)->field;
DBUG_ASSERT(field);
// not supported for generated column
Expand All @@ -186,7 +186,7 @@ static bool check_pq_support_fieldtype_of_field_item(Item *item) {
return true;
}

static bool check_pq_support_fieldtype_of_func_item(Item *item) {
bool check_pq_support_fieldtype_of_func_item(Item *item) {
Item_func *func = static_cast<Item_func *>(item);
DBUG_ASSERT(func);

Expand Down Expand Up @@ -241,7 +241,7 @@ static bool check_pq_support_fieldtype_of_func_item(Item *item) {
return true;
}

static bool check_pq_support_fieldtype_of_cond_item(Item *item) {
bool check_pq_support_fieldtype_of_cond_item(Item *item) {
Item_cond *cond = static_cast<Item_cond *>(item);
DBUG_ASSERT(cond);

Expand All @@ -261,7 +261,7 @@ static bool check_pq_support_fieldtype_of_cond_item(Item *item) {
return true;
}

static bool check_pq_support_fieldtype_of_sum_func_item(Item *item) {
bool check_pq_support_fieldtype_of_sum_func_item(Item *item) {
Item_sum *sum = static_cast<Item_sum *>(item);
if (!sum || pq_not_support_aggr_functype(sum->sum_func())) {
return false;
Expand All @@ -277,7 +277,7 @@ static bool check_pq_support_fieldtype_of_sum_func_item(Item *item) {
return true;
}

static bool check_pq_support_fieldtype_of_ref_item(Item *item) {
bool check_pq_support_fieldtype_of_ref_item(Item *item) {
Item_ref *item_ref = down_cast<Item_ref *>(item);
if (!item_ref || pq_not_support_ref(item_ref)) {
return false;
Expand All @@ -291,7 +291,7 @@ static bool check_pq_support_fieldtype_of_ref_item(Item *item) {
return true;
}

static bool check_pq_support_fieldtype_of_cache_item(Item *item) {
bool check_pq_support_fieldtype_of_cache_item(Item *item) {
Item_cache *item_cache = dynamic_cast<Item_cache*>(item);
if (item_cache == nullptr) {
return false;
Expand All @@ -306,7 +306,7 @@ static bool check_pq_support_fieldtype_of_cache_item(Item *item) {
return true;
}

static bool check_pq_support_fieldtype_of_row_item(Item *item) {
bool check_pq_support_fieldtype_of_row_item(Item *item) {
// check each item in Item_row
Item_row *row_item = down_cast<Item_row *>(item);
for (uint i = 0; i < row_item->cols(); i++) {
Expand All @@ -320,7 +320,7 @@ static bool check_pq_support_fieldtype_of_row_item(Item *item) {
return true;
}

static PQ_CHECK_ITEM_TYPE g_check_item_type[] = {
PQ_CHECK_ITEM_TYPE g_check_item_type[] = {
{Item::INVALID_ITEM, nullptr},
{Item::FIELD_ITEM, check_pq_support_fieldtype_of_field_item},
{Item::FUNC_ITEM, check_pq_support_fieldtype_of_func_item},
Expand Down Expand Up @@ -361,7 +361,7 @@ static PQ_CHECK_ITEM_TYPE g_check_item_type[] = {
* true : supported
* false : not supported
*/
static bool check_pq_support_fieldtype(Item *item) {
bool check_pq_support_fieldtype(Item *item) {
if (item == nullptr || pq_not_support_datatype(item->data_type())) {
return false;
}
Expand All @@ -380,7 +380,7 @@ static bool check_pq_support_fieldtype(Item *item) {
* true: contained
* false:
*/
static bool check_pq_sort_aggregation(const ORDER_with_src &order_list) {
bool check_pq_sort_aggregation(const ORDER_with_src &order_list) {
if (!order_list.order) {
return false;
}
Expand Down Expand Up @@ -812,7 +812,7 @@ bool suite_for_parallel_query(JOIN *join) {
return true;
}

static bool check_pq_running_threads(uint dop, ulong timeout_ms) {
bool check_pq_running_threads(uint dop, ulong timeout_ms) {
bool success = false;
mysql_mutex_lock(&LOCK_pq_threads_running);
if (parallel_threads_running + dop > parallel_max_threads) {
Expand Down
34 changes: 34 additions & 0 deletions sql/sql_class.cc
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,40 @@ void THD::enter_stage(const PSI_stage_info *new_stage,
return;
}

void THD::enter_cond(mysql_cond_t *cond, mysql_mutex_t *mutex,
const PSI_stage_info *stage, PSI_stage_info *old_stage,
const char *src_function, const char *src_file,
int src_line) {
DBUG_TRACE;
mysql_mutex_assert_owner(mutex);
/*
Sic: We don't lock LOCK_current_cond here.
If we did, we could end up in deadlock with THD::awake()
which locks current_mutex while LOCK_current_cond is locked.
*/
current_mutex = mutex;
current_cond = cond;
enter_stage(stage, old_stage, src_function, src_file, src_line);
return;
}

void THD::exit_cond(const PSI_stage_info *stage, const char *src_function,
const char *src_file, int src_line) {
DBUG_TRACE;
/*
current_mutex must be unlocked _before_ LOCK_current_cond is
locked (if that would not be the case, you'll get a deadlock if someone
does a THD::awake() on you).
*/
mysql_mutex_assert_not_owner(current_mutex.load());
mysql_mutex_lock(&LOCK_current_cond);
current_mutex = nullptr;
current_cond = nullptr;
mysql_mutex_unlock(&LOCK_current_cond);
enter_stage(stage, nullptr, src_function, src_file, src_line);
return;
}

void Open_tables_state::set_open_tables_state(Open_tables_state *state) {
this->open_tables = state->open_tables;

Expand Down
30 changes: 2 additions & 28 deletions sql/sql_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -2674,36 +2674,10 @@ class THD : public MDL_context_owner,
void enter_cond(mysql_cond_t *cond, mysql_mutex_t *mutex,
const PSI_stage_info *stage, PSI_stage_info *old_stage,
const char *src_function, const char *src_file,
int src_line) {
DBUG_TRACE;
mysql_mutex_assert_owner(mutex);
/*
Sic: We don't lock LOCK_current_cond here.
If we did, we could end up in deadlock with THD::awake()
which locks current_mutex while LOCK_current_cond is locked.
*/
current_mutex = mutex;
current_cond = cond;
enter_stage(stage, old_stage, src_function, src_file, src_line);
return;
}
int src_line);

void exit_cond(const PSI_stage_info *stage, const char *src_function,
const char *src_file, int src_line) {
DBUG_TRACE;
/*
current_mutex must be unlocked _before_ LOCK_current_cond is
locked (if that would not be the case, you'll get a deadlock if someone
does a THD::awake() on you).
*/
mysql_mutex_assert_not_owner(current_mutex.load());
mysql_mutex_lock(&LOCK_current_cond);
current_mutex = nullptr;
current_cond = nullptr;
mysql_mutex_unlock(&LOCK_current_cond);
enter_stage(stage, nullptr, src_function, src_file, src_line);
return;
}
const char *src_file, int src_line);

virtual int is_killed() const final { return killed; }
virtual THD *get_thd() { return this; }
Expand Down
1 change: 1 addition & 0 deletions unittest/gunit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -363,3 +363,4 @@ ADD_SUBDIRECTORY(group_replication)
ADD_SUBDIRECTORY(libmysqlgcs)
ADD_SUBDIRECTORY(temptable)
ADD_SUBDIRECTORY(binlogevents)
ADD_SUBDIRECTORY(parallel_query)
72 changes: 72 additions & 0 deletions unittest/gunit/parallel_query/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2.0,
# as published by the Free Software Foundation.
#
# This program is also distributed with certain software (including
# but not limited to OpenSSL) that is licensed under separate terms,
# as designated in a particular file or component or in included license
# documentation. The authors of MySQL hereby grant you an additional
# permission to link the program and your derivative works with the
# separately licensed software that they have included with MySQL.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License, version 2.0, for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

SET(TESTS
pq_condition
)

SET(ALL_PARALLEL_TESTS)
FOREACH(test ${TESTS})
LIST(APPEND ALL_PARALLEL_TESTS ${test}-t.cc)
ENDFOREACH()

IF(WIN32)
LIST(APPEND ALL_PARALLEL_TESTS ../../../sql/nt_servc.cc)
ENDIF()
MYSQL_ADD_EXECUTABLE(parallel_tests-t ${ALL_PARALLEL_TESTS}
ENABLE_EXPORTS
EXCLUDE_ON_SOLARIS
ADD_TEST parallel_tests-t)

TARGET_LINK_LIBRARIES(parallel_tests-t
gunit_large
server_unittest_library
)

# Download TBB from https://www.threadingbuildingblocks.org
#SET(TBB_INCDIR /path/to/tbb43_20150611oss/include)
#SET(TBB_LIBDIR /path/to/tbb43_20150611oss/build/linux_intel64_gcc_cc4.9.1_libc2.12_kernel2.6.39_release)
#TARGET_LINK_LIBRARIES(parallel_tests-t tbb -L${TBB_LIBDIR} -Wl,-rpath=${TBB_LIBDIR})
#INCLUDE_DIRECTORIES(${TBB_INCDIR})

TARGET_LINK_LIBRARIES(parallel_tests-t perfschema)

ADD_DEPENDENCIES(parallel_tests-t GenError)

FOREACH(test ${TESTS})
SET(SRC_FILES ${test}-t.cc)
IF(WIN32)
LIST(APPEND SRC_FILES ../../../sql/nt_servc.cc)
ENDIF()

MYSQL_ADD_EXECUTABLE(${test}-t ${SRC_FILES}
ENABLE_EXPORTS SKIP_INSTALL EXCLUDE_FROM_ALL)

TARGET_LINK_LIBRARIES(${test}-t
gunit_large
server_unittest_library
)

ADD_DEPENDENCIES(${test}-t GenError)

ENDFOREACH()

Loading

0 comments on commit 4ae9541

Please sign in to comment.