From: Jorgen Loland Date: September 20 2011 1:08pm Subject: bzr push into mysql-trunk branch (jorgen.loland:3436 to 3437) List-Archive: http://lists.mysql.com/commits/141022 Message-Id: <20110920130837.83729165@atum21.no.oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 3437 Jorgen Loland 2011-09-20 Cleanup in the optimizer: * Rename JT_NEXT to JT_INDEX_SCAN * Remove JT_MAYBE_REF (unused) * Document what the join_type names mean modified: sql/opt_explain.cc sql/sql_select.cc sql/sql_select.h 3436 Jorgen Loland 2011-09-14 Recorded result files after merge mysql-trunk -> opt-backporting. modified: mysql-test/r/innodb_icp_all.result mysql-test/r/innodb_mrr_all.result mysql-test/r/innodb_mrr_cost_all.result mysql-test/r/myisam_icp_all.result mysql-test/r/subquery_sj_none_bka_nobnl.result === modified file 'sql/opt_explain.cc' --- a/sql/opt_explain.cc 2011-08-29 11:57:44 +0000 +++ b/sql/opt_explain.cc 2011-09-20 13:07:55 +0000 @@ -848,7 +848,7 @@ bool Explain_join::explain_key_and_len() { if (tab->ref.key_parts) return explain_key_and_len_index(tab->ref.key, tab->ref.key_length); - else if (tab->type == JT_NEXT) + else if (tab->type == JT_INDEX_SCAN) return explain_key_and_len_index(tab->index); else if (tab->select && tab->select->quick) return explain_key_and_len_quick(tab->select); @@ -908,7 +908,7 @@ bool Explain_join::explain_rows_and_filt double examined_rows; if (tab->select && tab->select->quick) examined_rows= rows2double(tab->select->quick->records); - else if (tab->type == JT_NEXT || tab->type == JT_ALL) + else if (tab->type == JT_INDEX_SCAN || tab->type == JT_ALL) { if (tab->limit) examined_rows= rows2double(tab->limit); @@ -993,7 +993,7 @@ bool Explain_join::explain_extra() else str_extra.append(STRING_WITH_LEN("; Scanned all databases")); } - if (((tab->type == JT_NEXT || tab->type == JT_CONST) && + if (((tab->type == JT_INDEX_SCAN || tab->type == JT_CONST) && table->covering_keys.is_set(tab->index)) || (quick_type == QUICK_SELECT_I::QS_TYPE_ROR_INTERSECT && !((QUICK_ROR_INTERSECT_SELECT*) select->quick)->need_to_fetch_row) || === modified file 'sql/sql_select.cc' --- a/sql/sql_select.cc 2011-09-14 11:44:36 +0000 +++ b/sql/sql_select.cc 2011-09-20 13:07:55 +0000 @@ -12426,7 +12426,7 @@ make_join_readinfo(JOIN *join, ulonglong if (!tab->loosescan_match_tab) tab->index=find_shortest_key(table, & table->covering_keys); tab->read_first_record= join_read_first; - tab->type=JT_NEXT; // Read with index_first / index_next + tab->type=JT_INDEX_SCAN; // Read with index_first / index_next } } if (tab->select && tab->select->quick && @@ -12434,7 +12434,8 @@ make_join_readinfo(JOIN *join, ulonglong push_index_cond(tab, tab->select->quick->index, icp_other_tables_ok); } trace_refine_table.add_alnum("scan_type", - tab->type == JT_NEXT ? "index" : "table"); + tab->type == JT_INDEX_SCAN ? + "index" : "table"); break; case JT_FT: break; @@ -12442,7 +12443,6 @@ make_join_readinfo(JOIN *join, ulonglong DBUG_PRINT("error",("Table type %d found",tab->type)); /* purecov: deadcode */ break; /* purecov: deadcode */ case JT_UNKNOWN: - case JT_MAYBE_REF: abort(); /* purecov: deadcode */ } // Materialize derived tables prior to accessing them. @@ -21687,7 +21687,7 @@ check_reverse_order: tab->index= best_key; tab->read_first_record= order_direction > 0 ? join_read_first:join_read_last; - tab->type=JT_NEXT; // Read with index_first(), index_next() + tab->type=JT_INDEX_SCAN; // Read with index_first(), index_next() if (table->covering_keys.is_set(best_key)) table->set_keyread(TRUE); @@ -21746,7 +21746,7 @@ check_reverse_order: save_quick= 0; // make_reverse() consumed it select->set_quick(tmp); } - else if (tab->type != JT_NEXT && tab->type != JT_REF_OR_NULL && + else if (tab->type != JT_INDEX_SCAN && tab->type != JT_REF_OR_NULL && tab->ref.key >= 0 && tab->ref.key_parts <= used_key_parts) { /* === modified file 'sql/sql_select.h' --- a/sql/sql_select.h 2011-08-29 11:57:44 +0000 +++ b/sql/sql_select.h 2011-09-20 13:07:55 +0000 @@ -224,9 +224,68 @@ typedef struct st_table_ref : public Sql /* The structs which holds the join connections and join states */ -enum join_type { JT_UNKNOWN,JT_SYSTEM,JT_CONST,JT_EQ_REF,JT_REF,JT_MAYBE_REF, - JT_ALL, JT_RANGE, JT_NEXT, JT_FT, JT_REF_OR_NULL, - JT_UNIQUE_SUBQUERY, JT_INDEX_SUBQUERY, JT_INDEX_MERGE}; +enum join_type { /* + Initial state. Access type has not yet been decided + for the table + */ + JT_UNKNOWN, + /* Table has exactly one row */ + JT_SYSTEM, + /* + Table has at most one matching row. Values read + from this row can be treated as constants. Example: + "WHERE table.pk = 3" + */ + JT_CONST, + /* + '=' operator is used on unique index. At most one + row is read for each combination of rows from + preceding tables + */ + JT_EQ_REF, + /* + '=' operator is used on non-unique index + */ + JT_REF, + /* + Full table scan or range scan. + If select->quick != NULL, it is range access. + Otherwise it is table scan. + */ + JT_ALL, + /* + Range scan. Note that range scan is not indicated + by JT_RANGE but by "JT_ALL + select->quick" except + when printing EXPLAIN output. @see calc_join_type() + */ + JT_RANGE, + /* + Like table scan, but scans index leaves instead of + the table + */ + JT_INDEX_SCAN, + /* Fulltext index is used */ + JT_FT, + /* + Like ref, but with extra search for NULL values. + E.g. used for "WHERE col = ... OR col IS NULL" + */ + JT_REF_OR_NULL, + /* + Like eq_ref for subqueries: Replaces subquery with + index lookup in unique index + */ + JT_UNIQUE_SUBQUERY, + /* + Like unique_subquery but for non-unique index + */ + JT_INDEX_SUBQUERY, + /* + Do multiple range scans over one table and combine + the results into one. The merge can be used to + produce unions and intersections + */ + JT_INDEX_MERGE}; class JOIN; No bundle (reason: useless for push emails).