summaryrefslogtreecommitdiff
path: root/sql/table.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/table.cc')
-rw-r--r--sql/table.cc110
1 files changed, 42 insertions, 68 deletions
diff --git a/sql/table.cc b/sql/table.cc
index 07ca236854c..268d7a0be49 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -2606,60 +2606,6 @@ GRANT_INFO *Natural_join_column::grant()
}
-
-#ifndef NO_EMBEDDED_ACCESS_CHECKS
-
-/*
- Check the access rights for the current join column.
- columns.
-
- SYNOPSIS
- Natural_join_column::check_grants()
-
- DESCRIPTION
- Check the access rights to a column from a natural join in a generic
- way that hides the heterogeneity of the column representation - whether
- it is a view or a stored table colum.
-
- RETURN
- FALSE The column can be accessed
- TRUE There are no access rights to all equivalent columns
-*/
-
-bool
-Natural_join_column::check_grants(THD *thd, const char *name, uint length)
-{
- GRANT_INFO *grant;
- const char *db_name;
- const char *table_name;
- Security_context *save_security_ctx= thd->security_ctx;
- Security_context *new_sctx= table_ref->security_ctx;
- bool res;
-
- if (view_field)
- {
- DBUG_ASSERT(table_field == NULL);
- grant= &(table_ref->grant);
- db_name= table_ref->view_db.str;
- table_name= table_ref->view_name.str;
- }
- else
- {
- DBUG_ASSERT(table_field && view_field == NULL);
- grant= &(table_ref->table->grant);
- db_name= table_ref->table->s->db;
- table_name= table_ref->table->s->table_name;
- }
-
- if (new_sctx)
- thd->security_ctx= new_sctx;
- res= check_grant_column(thd, grant, db_name, table_name, name, length);
- thd->security_ctx= save_security_ctx;
- return res;
-}
-#endif
-
-
void Field_iterator_view::set(TABLE_LIST *table)
{
DBUG_ASSERT(table->field_translation);
@@ -2702,8 +2648,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 +2682,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 +2816,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 +2828,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 +2862,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
*****************************************************************************/