diff options
author | unknown <bell@sanja.is.com.ua> | 2003-10-16 15:54:47 +0300 |
---|---|---|
committer | unknown <bell@sanja.is.com.ua> | 2003-10-16 15:54:47 +0300 |
commit | 724a6c3c6d09891f07352bbc4b041ec960fc8986 (patch) | |
tree | dff4a909ef6eed167999fe596d481efd2e38e613 /sql/sql_select.cc | |
parent | 1d17fd7d51f7100038eaa5fb4cb372c785a44010 (diff) | |
download | mariadb-git-724a6c3c6d09891f07352bbc4b041ec960fc8986.tar.gz |
subqueries made printable
new EXPLAIN parameter to show real query as it was interpreted
(SCRUM) (WL#1274)
mysql-test/r/subselect.result:
new explains
mysql-test/r/union.result:
new explains
mysql-test/t/subselect.test:
new explains
mysql-test/t/union.test:
new explains
sql/item.cc:
fixed printability of Items in SELECT list
sql/item.h:
fixed printability of Items in SELECT list
sql/item_cmpfunc.cc:
fixed print()
sql/item_cmpfunc.h:
fixed print()
sql/item_subselect.cc:
subqueries made printable
sql/item_subselect.h:
subqueries made printable
sql/mysql_priv.h:
union option made looks like options
sql/sql_derived.cc:
now this link is used
sql/sql_lex.cc:
subqueries made printable
sql/sql_lex.h:
subqueries made printable
new EXPLAIN parameter support
sql/sql_parse.cc:
new EXPLAIN parameter
sql/sql_select.cc:
debug output
new EXPLAIN parameter support
sql/sql_select.h:
new EXPLAIN parameter support
sql/sql_yacc.yy:
new EXPLAIN parameter support
SELECT printability support
Diffstat (limited to 'sql/sql_select.cc')
-rw-r--r-- | sql/sql_select.cc | 184 |
1 files changed, 183 insertions, 1 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 4bab97d4a46..f86435e1bb0 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -328,6 +328,20 @@ JOIN::prepare(Item ***rref_pointer_array, having->split_sum_func(ref_pointer_array, all_fields); } +#ifndef DEBUG_OFF + { + char buff[256]; + String str(buff,(uint32) sizeof(buff), system_charset_info); + str.length(0); + if (select_lex->master_unit()->item) + select_lex->master_unit()->item->print(&str); + else + unit->print(&str); + str.append('\0'); + DBUG_PRINT("info", ("(SUB)SELECT: %s", str.ptr())); + } +#endif + // Is it subselect { Item_subselect *subselect; @@ -880,12 +894,12 @@ JOIN::optimize() need_tmp=1; simple_order=simple_group=0; // Force tmp table without sort } + tmp_having= having; if (select_options & SELECT_DESCRIBE) { error= 0; DBUG_RETURN(0); } - tmp_having= having; having= 0; /* Perform FULLTEXT search before all regular searches */ @@ -1547,11 +1561,23 @@ mysql_select(THD *thd, Item ***rref_pointer_array, goto err; // 1 } + if (thd->lex.describe & DESCRIBE_EXTENDED) + { + join->conds_history= join->conds; + join->having_history= (join->having?join->having:join->tmp_having); + } + if (thd->net.report_error) goto err; join->exec(); + if (thd->lex.describe & DESCRIBE_EXTENDED) + { + select_lex->where= join->conds_history; + select_lex->having= join->having_history; + } + err: if (free_join) { @@ -8909,3 +8935,159 @@ int mysql_explain_select(THD *thd, SELECT_LEX *select_lex, char const *type, result, unit, select_lex, 0); DBUG_RETURN(res); } + + +void st_select_lex::print(THD *thd, String *str) +{ + if (!thd) + thd= current_thd; + + str->append("select "); + + //options + if (options & SELECT_STRAIGHT_JOIN) + str->append("straight_join "); + if ((thd->lex.lock_option & TL_READ_HIGH_PRIORITY) && + (this == &thd->lex.select_lex)) + str->append("high_priority "); + if (options & SELECT_DISTINCT) + str->append("distinct "); + if (options & SELECT_SMALL_RESULT) + str->append("small_result "); + if (options & SELECT_BIG_RESULT) + str->append("big_result "); + if (options & OPTION_BUFFER_RESULT) + str->append("buffer_result "); + if (options & OPTION_FOUND_ROWS) + str->append("calc_found_rows "); + if (!thd->lex.safe_to_cache_query) + str->append("no_cache "); + if (options & OPTION_TO_QUERY_CACHE) + str->append("cache "); + + //Item List + bool first= 1; + List_iterator_fast<Item> it(item_list); + Item *item; + while ((item= it++)) + { + if (first) + first= 0; + else + str->append(','); + item->print_item_w_name(str); + } + + /* + from clause + TODO: support USING/FORCE/IGNORE index + */ + if (table_list.elements) + { + str->append(" from "); + Item *next_on= 0; + for (TABLE_LIST *table= (TABLE_LIST *) table_list.first; + table; + table= table->next) + { + if (table->derived) + { + str->append('('); + table->derived->print(str); + str->append(") "); + str->append(table->alias); + } + else + { + str->append(table->db); + str->append('.'); + str->append(table->real_name); + if (strcmp(table->real_name, table->alias)) + { + str->append(' '); + str->append(table->alias); + } + } + + if (table->on_expr && ((table->outer_join & JOIN_TYPE_LEFT) || + !(table->outer_join & JOIN_TYPE_RIGHT))) + next_on= table->on_expr; + + if (next_on) + { + str->append(" on("); + next_on->print(str); + str->append(')'); + next_on= 0; + } + + TABLE_LIST *next; + if ((next= table->next)) + { + if (table->outer_join & JOIN_TYPE_RIGHT) + { + str->append(" right join "); + if (!(table->outer_join & JOIN_TYPE_LEFT) && + table->on_expr) + next_on= table->on_expr; + } + else if (next->straight) + str->append(" straight_join "); + else if (next->outer_join & JOIN_TYPE_LEFT) + str->append(" left join "); + else + str->append(" join "); + } + } + } + + //where + Item *where= this->where; + if (join) + where= join->conds; + if (where) + { + str->append(" where "); + where->print(str); + } + + //group by & olap + if (group_list.elements) + { + str->append(" group by "); + print_order(str, (ORDER *) group_list.first); + switch (olap) + { + case CUBE_TYPE: + str->append(" with cube"); + break; + case ROLLUP_TYPE: + str->append(" with rollup"); + break; + default: + ; //satisfy compiler + } + } + + //having + Item *having= this->having; + if (join) + having= join->having; + + if (having) + { + str->append(" having "); + having->print(str); + } + + if (order_list.elements) + { + str->append(" order by "); + print_order(str, (ORDER *) order_list.first); + } + + // limit + print_limit(thd, str); + + // PROCEDURE unsupported here +} |