summaryrefslogtreecommitdiff
path: root/sql/table.cc
diff options
context:
space:
mode:
authorunknown <timour@mysql.com>2005-11-28 21:57:50 +0200
committerunknown <timour@mysql.com>2005-11-28 21:57:50 +0200
commit4fd41f7c0bd7e61265e219aecada2e7b36df88c3 (patch)
treee240ac23234a12c571460f2d81c1fa3ad1bfb391 /sql/table.cc
parent97bfd41fe1382ff33a9fc458c0bd092342b217e5 (diff)
downloadmariadb-git-4fd41f7c0bd7e61265e219aecada2e7b36df88c3.tar.gz
WL#2486 - Natural/using join according to SQL:2003.
Post-review fixes according to Monty's review. sql/item.h: Unite all code that stores and restores the state of a name resolution context into a class to represent the state, and methods to save/restore that state. sql/mysql_priv.h: Reorder parameters so that length is after the name of a field, and database is before table name. sql/sql_acl.cc: Reorder parameters so that length is after the name of a field, and database is before table name. sql/sql_base.cc: * Reorder parameters so that length is after the name of a field, and database is before table name. * Added new method - Field_iterator_table_ref::get_natural_column_ref to avoid unnecessary code when it is knwon that no new columns will be created when accessing natural join columns. sql/sql_insert.cc: Unite all code that stores and restores the state of a name resolution context into a class to represent the state, and methods to save/restore that state. sql/sql_lex.cc: Removed obsolete comment. sql/sql_lex.h: Return error from push_contex() if there is no memory. sql/sql_list.h: Extended base_list_iterator, List_iterator, and List_iterator_fast with an empty constructor, and init() methods, so that one doesn't have to construct a new iterator object every time one needs to iterate over a new list. sql/sql_parse.cc: Moved common functionality from the parser into one function, and renamed the function to better reflect what it does. sql/sql_yacc.yy: Moved common functionality from the parser into one function, and renamed the function to better reflect what it does. sql/table.cc: * Extended base_list_iterator, List_iterator, and List_iterator_fast with an empty constructor, and init() methods, so that one doesn't have to construct a new iterator object every time one needs to iterate over a new list. * Added new method Field_iterator_table_ref::get_natural_column_ref to be used in cases when it is known for sure that no new columns should be created. sql/table.h: - column_ref_it no longer allocated for each new list of columns - new method get_natural_join_column for faster/simpler access to natural join columns.
Diffstat (limited to 'sql/table.cc')
-rw-r--r--sql/table.cc56
1 files changed, 42 insertions, 14 deletions
diff --git a/sql/table.cc b/sql/table.cc
index 8068a839052..4cc94439143 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -2702,8 +2702,9 @@ Item *create_view_field(THD *thd, TABLE_LIST *view, Item **field_ref,
if (view->schema_table_reformed)
{
/*
- In case of SHOW command (schema_table_reformed set) all items are
- fixed
+ Translation table items are always Item_fields and already fixed
+ ('mysql_schema_table' function). So we can return directly the
+ field. This case happens only for 'show & where' commands.
*/
DBUG_ASSERT(field && field->fixed);
DBUG_RETURN(field);
@@ -2735,21 +2736,14 @@ Item *create_view_field(THD *thd, TABLE_LIST *view, Item **field_ref,
void Field_iterator_natural_join::set(TABLE_LIST *table_ref)
{
DBUG_ASSERT(table_ref->join_columns);
- delete column_ref_it;
-
- /*
- TODO: try not to allocate new iterator every time. If we have to,
- then check for out of memory condition.
- */
- column_ref_it= new List_iterator_fast<Natural_join_column>
- (*(table_ref->join_columns));
- cur_column_ref= (*column_ref_it)++;
+ column_ref_it.init(*(table_ref->join_columns));
+ cur_column_ref= column_ref_it++;
}
void Field_iterator_natural_join::next()
{
- cur_column_ref= (*column_ref_it)++;
+ 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);
@@ -2876,7 +2870,6 @@ GRANT_INFO *Field_iterator_table_ref::grant()
SYNOPSIS
Field_iterator_table_ref::get_or_create_column_ref()
- thd [in] pointer to current thread
is_created [out] set to TRUE if the column was created,
FALSE if we return an already created colum
@@ -2889,7 +2882,7 @@ GRANT_INFO *Field_iterator_table_ref::grant()
*/
Natural_join_column *
-Field_iterator_table_ref::get_or_create_column_ref(THD *thd, bool *is_created)
+Field_iterator_table_ref::get_or_create_column_ref(bool *is_created)
{
Natural_join_column *nj_col;
@@ -2923,6 +2916,41 @@ Field_iterator_table_ref::get_or_create_column_ref(THD *thd, bool *is_created)
}
+/*
+ Return an existing reference to a column of a natural/using join.
+
+ SYNOPSIS
+ Field_iterator_table_ref::get_natural_column_ref()
+
+ DESCRIPTION
+ The method should be called in contexts where it is expected that
+ all natural join columns are already created, and that the column
+ being retrieved is a Natural_join_column.
+
+ RETURN
+ # Pointer to a column of a natural join (or its operand)
+ NULL No memory to allocate the column
+*/
+
+Natural_join_column *
+Field_iterator_table_ref::get_natural_column_ref()
+{
+ Natural_join_column *nj_col;
+
+ DBUG_ASSERT(field_it == &natural_join_it);
+ /*
+ 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.
+ */
+ nj_col= natural_join_it.column_ref();
+ DBUG_ASSERT(nj_col &&
+ (!nj_col->table_field ||
+ nj_col->table_ref->table == nj_col->table_field->table));
+ return nj_col;
+}
+
+
/*****************************************************************************
** Instansiate templates
*****************************************************************************/