summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorunknown <bell@sanja.is.com.ua>2004-07-01 23:46:43 +0300
committerunknown <bell@sanja.is.com.ua>2004-07-01 23:46:43 +0300
commit148eecbd4008b4d47e5167e10503b2cc82f9a3d1 (patch)
tree241036a1db78a5e5d9dd04868679ea2b066ecf65 /sql
parentc92670d80b3674fa025e373e0498eccbb407f873 (diff)
downloadmariadb-git-148eecbd4008b4d47e5167e10503b2cc82f9a3d1.tar.gz
fixed join_nested test independence of environment
spaces at line end in fresh definitions removed fixed printing of nested joins (BUG#4352) mysql-test/r/join_nested.result: fixed join_nested test independence of environment print of nested join test added mysql-test/t/join_nested.test: fixed join_nested test independence of environment print of nested join test added sql/sql_lex.h: space at line end in fresh definition removed sql/sql_select.cc: fixed printing of nested joins sql/table.h: spaces at line end in fresh definitions removed method for table printing
Diffstat (limited to 'sql')
-rw-r--r--sql/sql_lex.h2
-rw-r--r--sql/sql_select.cc174
-rw-r--r--sql/table.h14
3 files changed, 97 insertions, 93 deletions
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index 02b3da55921..8b6500cdacc 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -417,7 +417,7 @@ public:
List<Item_func_match> ftfunc_list_alloc;
JOIN *join; /* after JOIN::prepare it is pointer to corresponding JOIN */
List<TABLE_LIST> top_join_list; /* join list of the top level */
- List<TABLE_LIST> *join_list; /* list for the currently parsed join */
+ List<TABLE_LIST> *join_list; /* list for the currently parsed join */
TABLE_LIST *embedding; /* table embedding to the above list */
const char *type; /* type of select for EXPLAIN */
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index e28ee52c00f..a48c5dda6af 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -11178,6 +11178,92 @@ int mysql_explain_union(THD *thd, SELECT_LEX_UNIT *unit, select_result *result)
}
+/*
+ Print joins from the FROM clause
+
+ SYNOPSIS
+ print_join()
+ thd thread handler
+ str string where table should bbe printed
+ tables list of tables in join
+*/
+
+static void print_join(THD *thd, String *str, List<TABLE_LIST> *tables)
+{
+ /* List is reversed => we should reverse it before using */
+ List_iterator_fast<TABLE_LIST> ti(*tables);
+ TABLE_LIST **table= (TABLE_LIST **)thd->alloc(sizeof(TABLE_LIST*) *
+ tables->elements);
+ if (table == 0)
+ return; // out of memory
+
+ for (TABLE_LIST **t= table + (tables->elements - 1); t >= table; t--)
+ *t= ti++;
+
+ DBUG_ASSERT(tables->elements >= 1);
+ TABLE_LIST *prev= *table;
+ prev->print(thd, str);
+
+ TABLE_LIST **end= table + tables->elements;
+ for(TABLE_LIST **tbl= table + 1; tbl < end; tbl++)
+ {
+ TABLE_LIST *curr= *tbl;
+ if (prev->outer_join & JOIN_TYPE_RIGHT)
+ str->append(" right join ", 12);
+ else if (curr->outer_join & JOIN_TYPE_LEFT)
+ str->append(" left join ", 11);
+ else if (curr->straight)
+ str->append(" straight_join ", 15);
+ else
+ str->append(" join ", 6);
+ curr->print(thd, str);
+ if (curr->on_expr)
+ {
+ str->append(" on(", 4);
+ curr->on_expr->print(str);
+ str->append(')');
+ }
+ prev= curr;
+ }
+}
+
+
+/*
+ Print table as it should be in join list
+
+ SYNOPSIS
+ st_table_list::print();
+ str string where table should bbe printed
+*/
+
+void st_table_list::print(THD *thd, String *str)
+{
+ if (nested_join)
+ {
+ str->append('(');
+ print_join(thd, str, &nested_join->join_list);
+ str->append(')');
+ }
+ else if (derived)
+ {
+ str->append('(');
+ derived->print(str);
+ str->append(") ", 2);
+ str->append(alias);
+ }
+ else
+ {
+ str->append(db);
+ str->append('.');
+ str->append(real_name);
+ if (my_strcasecmp(table_alias_charset, real_name, alias))
+ {
+ str->append(' ');
+ str->append(alias);
+ }
+ }
+}
+
void st_select_lex::print(THD *thd, String *str)
{
if (!thd)
@@ -11226,92 +11312,8 @@ void st_select_lex::print(THD *thd, String *str)
if (table_list.elements)
{
str->append(" from ", 6);
- for (TABLE_LIST *table= (TABLE_LIST *) table_list.first;
- table;
- table= table->next)
- {
- TABLE_LIST *embedded=table;
- TABLE_LIST *embedding= table->embedding;
- while (embedding)
- {
- TABLE_LIST *next;
- NESTED_JOIN *nested_join= table->embedding->nested_join;
- List_iterator_fast<TABLE_LIST> it(nested_join->join_list);
- TABLE_LIST *tab= it++;
- while ((next= it++))
- tab= next;
- if (tab != embedded)
- break;
- str->append('(');
- if (embedded->outer_join & JOIN_TYPE_RIGHT)
- str->append(" right join ", 12);
- else if (embedded->outer_join & JOIN_TYPE_LEFT)
- str->append(" left join ", 11);
- else if (embedded->straight)
- str->append(" straight_join ", 15);
- else
- str->append(" join ", 6);
- embedded= embedding;
- embedding= embedding->embedding;
- }
-
- 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 (my_strcasecmp(table_alias_charset, table->real_name, table->alias))
- {
- str->append(' ');
- str->append(table->alias);
- }
- }
-
- if (table->on_expr)
- {
- str->append(" on(", 4);
- table->on_expr->print(str);
- str->append(')');
- }
-
- TABLE_LIST *next_table;
- if ((next_table= table->next))
- {
- if (next_table->outer_join & JOIN_TYPE_RIGHT)
- str->append(" right join ", 12);
- else if (next_table->outer_join & JOIN_TYPE_LEFT)
- str->append(" left join ", 11);
- else if (next_table->straight)
- str->append(" straight_join ", 15);
- else
- str->append(" join ", 6);
- }
-
- embedded=table;
- embedding= table->embedding;
- while (embedding)
- {
- NESTED_JOIN *nested_join= table->embedding->nested_join;
- if (nested_join->join_list.head() != embedded)
- break;
- str->append(')');
- if (embedding->on_expr)
- {
- str->append(" on(", 4);
- embedding->on_expr->print(str);
- str->append(')');
- }
- embedded= embedding;
- embedding= embedding->embedding;
- }
- }
+ /* go through join tree */
+ print_join(thd, str, &top_join_list);
}
// Where
diff --git a/sql/table.h b/sql/table.h
index c59b5a03bc4..5c54e553d73 100644
--- a/sql/table.h
+++ b/sql/table.h
@@ -173,11 +173,11 @@ typedef struct st_table_list
{
struct st_table_list *next;
char *db, *alias, *real_name;
- char *option; /* Used by cache index */
+ char *option; /* Used by cache index */
Item *on_expr; /* Used with outer join */
struct st_table_list *natural_join; /* natural join on this table*/
/* ... join ... USE INDEX ... IGNORE INDEX */
- List<String> *use_index, *ignore_index;
+ List<String> *use_index, *ignore_index;
TABLE *table; /* opened table */
st_table_list *table_list; /* pointer to node of list of all tables */
class st_select_lex_unit *derived; /* SELECT_LEX_UNIT of derived table */
@@ -191,24 +191,26 @@ typedef struct st_table_list
bool force_index; /* prefer index over table scan */
bool ignore_leaves; /* preload only non-leaf nodes */
table_map dep_tables; /* tables the table depends on */
- table_map on_expr_dep_tables; /* tables on expression depends on */
+ table_map on_expr_dep_tables; /* tables on expression depends on */
struct st_nested_join *nested_join; /* if the element is a nested join */
st_table_list *embedding; /* nested join containing the table */
- List<struct st_table_list> *join_list;/* join list the table belongs to */
+ List<struct st_table_list> *join_list;/* join list the table belongs to */
bool cacheable_table; /* stop PS caching */
/* used in multi-upd privelege check */
bool table_in_update_from_clause;
+
+ void print(THD *thd, String *str);
} TABLE_LIST;
typedef struct st_nested_join
{
List<TABLE_LIST> join_list; /* list of elements in the nested join */
table_map used_tables; /* bitmap of tables in the nested join */
- table_map not_null_tables; /* tables that rejects nulls */
+ table_map not_null_tables; /* tables that rejects nulls */
struct st_join_table *first_nested;/* the first nested table in the plan */
uint counter; /* to count tables in the nested join */
} NESTED_JOIN;
-
+
typedef struct st_changed_table_list
{
struct st_changed_table_list *next;