diff options
author | unknown <timour@mysql.com> | 2005-08-19 15:22:30 +0300 |
---|---|---|
committer | unknown <timour@mysql.com> | 2005-08-19 15:22:30 +0300 |
commit | 57e82913b444860ca3273f8a2c37092e2dd77662 (patch) | |
tree | 4d9cf87124e8fd22446d08757525073473b44be4 /sql/table.cc | |
parent | 0450b7708b6cbe83d79604dbd4d3f1b038f2ff6c (diff) | |
download | mariadb-git-57e82913b444860ca3273f8a2c37092e2dd77662.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.cc | 50 |
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; } |