summaryrefslogtreecommitdiff
path: root/sql/table.cc
diff options
context:
space:
mode:
authorunknown <timour@mysql.com>2005-08-19 15:22:30 +0300
committerunknown <timour@mysql.com>2005-08-19 15:22:30 +0300
commit1cb72d7eb96c10fbca5b0cf48e167c6ad6231bc3 (patch)
tree4d9cf87124e8fd22446d08757525073473b44be4 /sql/table.cc
parentbbf391cb5443c820ae62bdb0b423b8346722d161 (diff)
downloadmariadb-git-1cb72d7eb96c10fbca5b0cf48e167c6ad6231bc3.tar.gz
WL#2486 - natural and using join according to SQL:2003
- Corrected problem with N-way nested natural joins in PS mode. - Code cleanup - More asserts to check consistency of name resolution contexts - Fixed potential memory leak of name resolution contexts mysql-test/r/join.result: - Corrected problem with N-way nested natural joins in PS mode. mysql-test/t/join.test: - Corrected problem with N-way nested natural joins in PS mode. sql/item.h: - Fixed potential memory leak. sql/sql_base.cc: - the local context of Item_fields that participate in TABLE_LIST::on_cond for natural joins is correctly set to the tables where the corresponding fields originate from. - removed unused variables - correct allocation of contexts sql/sql_parse.cc: - correct allocation of contexts for JOIN ON conditions. sql/table.cc: - added asserts to check the consistency of name resolution contexts sql/table.h: - added asserts to check the consistency of name resolution contexts
Diffstat (limited to 'sql/table.cc')
-rw-r--r--sql/table.cc50
1 files changed, 38 insertions, 12 deletions
diff --git a/sql/table.cc b/sql/table.cc
index baf44680807..beecd6442e8 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -2296,6 +2296,7 @@ Natural_join_column::Natural_join_column(Field_translator *field_param,
Natural_join_column::Natural_join_column(Field *field_param,
TABLE_LIST *tab)
{
+ DBUG_ASSERT(tab->table == field_param->table);
table_field= field_param;
view_field= NULL;
table_ref= tab;
@@ -2514,6 +2515,18 @@ void Field_iterator_natural_join::set(TABLE_LIST *table_ref)
}
+void Field_iterator_natural_join::next()
+{
+ cur_column_ref= (*column_ref_it)++;
+ DBUG_ASSERT(cur_column_ref ?
+ (cur_column_ref->table_field ?
+ cur_column_ref->table_ref->table ==
+ cur_column_ref->table_field->table :
+ TRUE) :
+ TRUE);
+}
+
+
void Field_iterator_table_ref::set_field_iterator()
{
DBUG_ENTER("Field_iterator_table_ref::set_field_iterator");
@@ -2660,18 +2673,31 @@ Field_iterator_table_ref::get_or_create_column_ref(THD *thd, bool *is_created)
*is_created= TRUE;
if (field_it == &table_field_it)
- return new Natural_join_column(table_field_it.field(), table_ref);
- if (field_it == &view_field_it)
- return new Natural_join_column(view_field_it.field_translator(),
- table_ref);
-
- /*
- This is NATURAL join, we already have created a column reference,
- so just return it.
- */
- *is_created= FALSE;
- nj_col= natural_join_it.column_ref();
- DBUG_ASSERT(nj_col);
+ {
+ /* The field belongs to a stored table. */
+ Field *field= table_field_it.field();
+ nj_col= new Natural_join_column(field, table_ref);
+ }
+ else if (field_it == &view_field_it)
+ {
+ /* The field belongs to a merge view or information schema table. */
+ Field_translator *translated_field= view_field_it.field_translator();
+ nj_col= new Natural_join_column(translated_field, table_ref);
+ }
+ else
+ {
+ /*
+ The field belongs to a NATURAL join, therefore the column reference was
+ already created via one of the two constructor calls above. In this case
+ we just return the already created column reference.
+ */
+ *is_created= FALSE;
+ nj_col= natural_join_it.column_ref();
+ DBUG_ASSERT(nj_col);
+ }
+ DBUG_ASSERT(nj_col->table_field ?
+ nj_col->table_ref->table == nj_col->table_field->table :
+ TRUE);
return nj_col;
}