From 6bcc6eaff685f196be225ddb7e73f56a6b41f992 Mon Sep 17 00:00:00 2001 From: PeterWeiWang <715533650@qq.com> Date: Thu, 10 Jun 2021 09:11:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B9=B6=E8=A1=8C=E6=9F=A5=E8=AF=A2=E7=89=B9?= =?UTF-8?q?=E6=80=A7mtr=E5=A4=B1=E8=B4=A5=E7=94=A8=E4=BE=8Bquery=5Frewrite?= =?UTF-8?q?=5Fplugins.joins=E4=BF=AE=E6=94=B9=20=E4=BF=AE=E5=A4=8Dquery=5F?= =?UTF-8?q?rewrite=5Fplugins.joins=EF=BC=8Cperfschema.start=5Fserver=5Fno?= =?UTF-8?q?=5Fdigests=EF=BC=8Cperfschema.digest=5Ftable=5Ffull=E7=AD=89?= =?UTF-8?q?=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/item.h | 2 ++ sql/pq_clone_item.cc | 15 +++++++++++++++ sql/sql_base.cc | 8 +++++++- sql/table.h | 3 ++- 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/sql/item.h b/sql/item.h index c7fbd1187e62..22e6f30cf217 100644 --- a/sql/item.h +++ b/sql/item.h @@ -3408,6 +3408,7 @@ class Item_ident : public Item { cached_table should be replaced by table_ref ASAP. */ TABLE_LIST *cached_table; + uint m_tableno{0}; SELECT_LEX *depended_from; Item_ident(Name_resolution_context *context_arg, const char *db_name_arg, @@ -3692,6 +3693,7 @@ class Item_field : public Item_ident { bool itemize(Parse_context *pc, Item **res) override; Item *pq_clone(THD *thd, SELECT_LEX *select) override; + bool pq_copy_from(THD *thd, SELECT_LEX *select, Item *item) override; enum Type type() const override { return FIELD_ITEM; } bool eq(const Item *item, bool binary_cmp) const override; double val_real() override; diff --git a/sql/pq_clone_item.cc b/sql/pq_clone_item.cc index f57021b8616d..a88b82871b13 100644 --- a/sql/pq_clone_item.cc +++ b/sql/pq_clone_item.cc @@ -304,6 +304,21 @@ PQ_COPY_FROM_DEF(Item_ident, Item) { DBUG_EXECUTE_IF("simulate_item_clone_attr_copy_error", return true;); context = &select->context; + + if (orig_item->cached_table == nullptr) { + m_tableno = orig_item->m_tableno; + } else { + m_tableno = orig_item->cached_table->m_tableno; + } + } +PQ_COPY_FROM_RETURN + +PQ_COPY_FROM_DEF(Item_field, Item_ident) { + DBUG_EXECUTE_IF("simulate_item_field_copy_error", return true;); + + if (orig_item->table_ref != nullptr) { + m_tableno = orig_item->table_ref->m_tableno; + } } PQ_COPY_FROM_RETURN diff --git a/sql/sql_base.cc b/sql/sql_base.cc index be1569e680ab..1157f7279121 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -7740,10 +7740,16 @@ Field *find_field_in_tables(THD *thd, Item_ident *item, TABLE_LIST *first_table, auto cur_table = first_table; for (; cur_table != last_table && cur_table != last_table2; cur_table = cur_table->next_name_resolution_table) { - Field *cur_field = find_field_in_table_ref( + Field *cur_field = nullptr; + if (thd->parallel_exec && item->m_tableno != cur_table->m_tableno) { + continue; + } else { + cur_field = find_field_in_table_ref( thd, cur_table, name, length, item->item_name.ptr(), db, table_name, ref, want_privilege, allow_rowid, &(item->cached_field_index), register_tree_change, &actual_table); + } + if ((cur_field == nullptr && thd->is_error()) || cur_field == WRONG_GRANT) return nullptr; diff --git a/sql/table.h b/sql/table.h index 6b3d3e3981ff..d82e7ee076f3 100644 --- a/sql/table.h +++ b/sql/table.h @@ -3162,13 +3162,14 @@ struct TABLE_LIST { const Lock_descriptor &lock_descriptor() const { return m_lock_descriptor; } - private: + public: /** The members below must be kept aligned so that (1 << m_tableno) == m_map. A table that takes part in a join operation must be assigned a unique table number. */ uint m_tableno{0}; ///< Table number within query block + private: table_map m_map{0}; ///< Table map, derived from m_tableno /** If this table or join nest is the Y in "X [LEFT] JOIN Y ON C", this