diff options
author | unknown <timour@mysql.com> | 2004-05-10 15:48:50 +0300 |
---|---|---|
committer | unknown <timour@mysql.com> | 2004-05-10 15:48:50 +0300 |
commit | 188cd4344d38b530719d85efe60f17d3f4f780de (patch) | |
tree | df3a799fcb71add098c537586a4dcd1f6ecd8577 /sql/sql_test.cc | |
parent | 7c8bae291517433c63da0fd224013aa92ba76a5b (diff) | |
download | mariadb-git-188cd4344d38b530719d85efe60f17d3f4f780de.tar.gz |
Complete implementation of WL#1469 "Greedy algorithm to search for an optimal execution plan",
consisting of pos-review fixes and improvements.
mysql-test/r/distinct.result:
Adjusted to account for pre-sorting of tables before optimiziation.
mysql-test/r/func_group.result:
Adjusted to account for pre-sorting of tables before optimiziation.
mysql-test/r/greedy_optimizer.result:
- Adjusted to account for pre-sorting of tables before optimiziation.
- Removed unnecessary test.
- More comments.
mysql-test/r/select.result:
- Adjusted to account for pre-sorting of tables before optimiziation.
mysql-test/t/greedy_optimizer.test:
- Adjusted to account for pre-sorting of tables before optimiziation.
- Removed unnecessary test.
- More comments.
sql/mysql_priv.h:
Moved function print_plan() to sql_test.cc
sql/sql_select.cc:
- Simplified the recursion in best_extension_by_limited_search()
and aligned it with its pseudo-code.
- Renamed functions to better reflect their semantics.
- Post-review changes of function specifications.
- Moved function print_plan() to sql_test.cc.
sql/sql_test.cc:
Moved function print_plan() to sql_test.cc
Diffstat (limited to 'sql/sql_test.cc')
-rw-r--r-- | sql/sql_test.cc | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/sql/sql_test.cc b/sql/sql_test.cc index cd493fcac30..ec6845a74f7 100644 --- a/sql/sql_test.cc +++ b/sql/sql_test.cc @@ -232,6 +232,102 @@ TEST_join(JOIN *join) DBUG_VOID_RETURN; } + +/* + Print the current state during query optimization. + + SYNOPSIS + print_plan() + join pointer to the structure providing all context info for + the query + read_time the cost of the best partial plan + record_count estimate for the number of records returned by the best + partial plan + idx length of the partial QEP in 'join->positions'; + also an index in the array 'join->best_ref'; + info comment string to appear above the printout + + DESCRIPTION + This function prints to the log file DBUG_FILE the members of 'join' that + are used during query optimization (join->positions, join->best_positions, + and join->best_ref) and few other related variables (read_time, + record_count). + Useful to trace query optimizer functions. + + RETURN + None +*/ + +void +print_plan(JOIN* join, double read_time, double record_count, + uint idx, const char *info) +{ + uint i; + POSITION pos; + JOIN_TAB *join_table; + JOIN_TAB **plan_nodes; + TABLE* table; + + if (info == 0) + info= ""; + + DBUG_LOCK_FILE; + if (join->best_read == DBL_MAX) + { + fprintf(DBUG_FILE,"%s; idx:%u, best: DBL_MAX, current:%g\n", + info, idx, read_time); + } + else + { + fprintf(DBUG_FILE,"%s; idx: %u, best: %g, current: %g\n", + info, idx, join->best_read, read_time); + } + + /* Print the tables in JOIN->positions */ + fputs(" POSITIONS: ", DBUG_FILE); + for (i= 0; i < idx ; i++) + { + pos = join->positions[i]; + table= pos.table->table; + if (table) + fputs(table->real_name, DBUG_FILE); + fputc(' ', DBUG_FILE); + } + fputc('\n', DBUG_FILE); + + /* + Print the tables in JOIN->best_positions only if at least one complete plan + has been found. An indicator for this is the value of 'join->best_read'. + */ + fputs("BEST_POSITIONS: ", DBUG_FILE); + if (join->best_read < DBL_MAX) + { + for (i= 0; i < idx ; i++) + { + pos= join->best_positions[i]; + table= pos.table->table; + if (table) + fputs(table->real_name, DBUG_FILE); + fputc(' ', DBUG_FILE); + } + } + fputc('\n', DBUG_FILE); + + /* Print the tables in JOIN->best_ref */ + fputs(" BEST_REF: ", DBUG_FILE); + for (plan_nodes= join->best_ref ; *plan_nodes ; plan_nodes++) + { + join_table= (*plan_nodes); + fputs(join_table->table->real_name, DBUG_FILE); + fprintf(DBUG_FILE, "(%u,%u,%u)", + join_table->found_records, join_table->records, join_table->read_time); + fputc(' ', DBUG_FILE); + } + fputc('\n', DBUG_FILE); + + DBUG_UNLOCK_FILE; +} + #endif typedef struct st_debug_lock |