From 37acfe34fd91681fac70eac1add7610dc9b36d62 Mon Sep 17 00:00:00 2001 From: chenlinfeng <723609220@qq.com> Date: Wed, 12 May 2021 09:59:27 +0800 Subject: [PATCH 1/4] add parallel query code --- sql/item.h | 2 ++ sql/pq_clone.cc | 8 ++++---- sql/pq_clone_item.cc | 10 ++++++++++ sql/pq_condition.cc | 8 +------- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/sql/item.h b/sql/item.h index 2c208ce81bca..c7fbd1187e62 100644 --- a/sql/item.h +++ b/sql/item.h @@ -5210,6 +5210,8 @@ class Item_view_ref final : public Item_ref { bool fix_fields(THD *, Item **) override; + Item* pq_clone(THD *thd, SELECT_LEX *select) override; + /** Takes into account whether an Item in a derived table / view is part of an inner table of an outer join. diff --git a/sql/pq_clone.cc b/sql/pq_clone.cc index d984086fb165..32f4fcd0ca98 100644 --- a/sql/pq_clone.cc +++ b/sql/pq_clone.cc @@ -398,8 +398,8 @@ SELECT_LEX *pq_dup_select(THD *thd, SELECT_LEX *orig) { thd->lex->select_lex = select; // phase 1. clone tables and open/lock them - for (TABLE_LIST *tbl_list = orig->table_list.first; tbl_list != nullptr; - tbl_list = tbl_list->next_local) { + for (TABLE_LIST *tbl_list = orig->leaf_tables; tbl_list != nullptr; + tbl_list = tbl_list->next_leaf) { LEX_CSTRING *db_name = new(thd->pq_mem_root) LEX_CSTRING{tbl_list->db, tbl_list->db_length}; if (db_name == nullptr) { @@ -431,8 +431,8 @@ SELECT_LEX *pq_dup_select(THD *thd, SELECT_LEX *orig) { // before setup_fields, propagate_nullability will change table->nullable, // which may affect item->maybe_null, so we copy it here. // see in SELECT_LEX:: prepare - for (TABLE_LIST *tl = orig->table_list.first; tl != nullptr; tl = tl->next_local) { - for (TABLE_LIST *tbl_list = select->table_list.first; tbl_list != nullptr; tbl_list = tbl_list->next_local) { + for (TABLE_LIST *tl = orig->leaf_tables; tl != nullptr; tl = tl->next_leaf) { + for (TABLE_LIST *tbl_list = select->leaf_tables; tbl_list != nullptr; tbl_list = tbl_list->next_leaf) { const char *db = tbl_list->db; const char *table_name = tbl_list->table_name; const char *alias = tbl_list->alias; diff --git a/sql/pq_clone_item.cc b/sql/pq_clone_item.cc index 8e665a132443..0b75ae3cfa2b 100644 --- a/sql/pq_clone_item.cc +++ b/sql/pq_clone_item.cc @@ -326,6 +326,16 @@ PQ_CLONE_DEF(Item_default_value) { } PQ_CLONE_RETURN +Item *Item_view_ref::pq_clone(class THD *thd, class SELECT_LEX *select) { + Item_view_ref *new_item = new (thd->pq_mem_root) + Item_view_ref(&select->context, nullptr, table_name, orig_table_name, + field_name, cached_table); + Item** item_ref = new (thd->pq_mem_root) Item*(); + *item_ref = (*ref)->pq_clone(thd, select); + new_item->ref = item_ref; + return new_item; +} + Item *Item_ref::pq_clone(class THD *thd, class SELECT_LEX *select) { /* * c1: (Name_resolution_context, db_name, table_name, field_name) diff --git a/sql/pq_condition.cc b/sql/pq_condition.cc index 4cf696eca1df..c0ad1801a640 100644 --- a/sql/pq_condition.cc +++ b/sql/pq_condition.cc @@ -85,7 +85,6 @@ static const char* NO_PQ_SUPPORTED_FUNC_NO_ARGS [] = { }; static const Item_ref::Ref_Type NO_PQ_SUPPORTED_REF_TYPES[] = { - Item_ref::VIEW_REF, Item_ref::OUTER_REF, Item_ref::AGGREGATE_REF }; @@ -762,13 +761,8 @@ bool suite_for_parallel_query(SELECT_LEX *select) { for (TABLE_LIST *tbl_list = select->table_list.first; tbl_list != nullptr; tbl_list = tbl_list->next_local) { - // skip derived table or view - if (tbl_list->is_view_or_derived()) { - return false; - } - // skip explicit table lock - if (tbl_list->lock_descriptor().type > TL_READ_DEFAULT || + if (tbl_list->lock_descriptor().type > TL_READ || current_thd->locking_clause) { return false; } From 2e2f81574967b1654ad9e106306548287bb50c89 Mon Sep 17 00:00:00 2001 From: chenlinfeng <723609220@qq.com> Date: Wed, 12 May 2021 14:09:29 +0800 Subject: [PATCH 2/4] add parallel query code --- sql/pq_condition.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sql/pq_condition.cc b/sql/pq_condition.cc index c0ad1801a640..461d3d66ab00 100644 --- a/sql/pq_condition.cc +++ b/sql/pq_condition.cc @@ -761,11 +761,16 @@ bool suite_for_parallel_query(SELECT_LEX *select) { for (TABLE_LIST *tbl_list = select->table_list.first; tbl_list != nullptr; tbl_list = tbl_list->next_local) { + // skip view + if (table_list->is_view()) { + return false; + } + // skip explicit table lock if (tbl_list->lock_descriptor().type > TL_READ || current_thd->locking_clause) { return false; - } + } TABLE *tb = tbl_list->table; if (tb != nullptr && From 38848927571b2419984bba8a50b56ca02d96c539 Mon Sep 17 00:00:00 2001 From: chenlinfeng <723609220@qq.com> Date: Wed, 12 May 2021 14:38:22 +0800 Subject: [PATCH 3/4] add parallel query code --- sql/pq_condition.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/pq_condition.cc b/sql/pq_condition.cc index 461d3d66ab00..8380c0282022 100644 --- a/sql/pq_condition.cc +++ b/sql/pq_condition.cc @@ -762,7 +762,7 @@ bool suite_for_parallel_query(SELECT_LEX *select) { for (TABLE_LIST *tbl_list = select->table_list.first; tbl_list != nullptr; tbl_list = tbl_list->next_local) { // skip view - if (table_list->is_view()) { + if (tbl_list->is_view()) { return false; } From 62d3f6a427d42b8d39f0be3044d3f0e74e2e1fdd Mon Sep 17 00:00:00 2001 From: chenlinfeng <723609220@qq.com> Date: Sat, 22 May 2021 14:21:31 +0800 Subject: [PATCH 4/4] add parallel query code --- sql/pq_condition.cc | 48 ++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/sql/pq_condition.cc b/sql/pq_condition.cc index 2d86524cc897..ddb71e5bdceb 100644 --- a/sql/pq_condition.cc +++ b/sql/pq_condition.cc @@ -750,6 +750,28 @@ bool suite_for_parallel_query(SELECT_LEX_UNIT *unit) { return true; } +bool suite_for_parallel_query(TABLE_LIST *tbl_list) { + if (tbl_list->is_view()) { + return false; + } + + // skip explicit table lock + if (tbl_list->lock_descriptor().type > TL_READ || + current_thd->locking_clause) { + return false; + } + + TABLE *tb = tbl_list->table; + if (tb != nullptr && + (tb->s->tmp_table != NO_TMP_TABLE || // template table + tb->file->ht->db_type != DB_TYPE_INNODB || // Non-InnoDB table + tb->part_info || // partition table + tb->fulltext_searched)) { // fulltext match search + return false; + } + return true; +} + bool suite_for_parallel_query(SELECT_LEX *select) { if (select->first_inner_unit() != nullptr || // nesting subquery, including view〝derived table〝subquery condition and so on. select->outer_select() != nullptr || // nested subquery @@ -761,27 +783,17 @@ bool suite_for_parallel_query(SELECT_LEX *select) { for (TABLE_LIST *tbl_list = select->table_list.first; tbl_list != nullptr; tbl_list = tbl_list->next_local) { - // skip view - if (tbl_list->is_view()) { - return false; + if (!suite_for_parallel_query(tbl_list)) { + return false; } - - // skip explicit table lock - if (tbl_list->lock_descriptor().type > TL_READ || - current_thd->locking_clause) { - return false; + } + + for (TABLE_LIST *tbl_list = select->leaf_tables; tbl_list != nullptr; + tbl_list = tbl_list->next_leaf) { + if (!suite_for_parallel_query(tbl_list)) { + return false; } - - TABLE *tb = tbl_list->table; - if (tb != nullptr && - (tb->s->tmp_table != NO_TMP_TABLE || // template table - tb->file->ht->db_type != DB_TYPE_INNODB || // Non-InnoDB table - tb->part_info || // partition table - tb->fulltext_searched)) { // fulltext match search - return false; - } } - return true; }