Commit 50c1d251 authored by unknown's avatar unknown
Browse files

Merge bk-internal.mysql.com:/home/bk/mysql-5.0-runtime

into  mysql.com:/home/dlenev/src/mysql-5.0-bg16593


sql/sql_base.cc:
  Auto merged
sql/sql_prepare.cc:
  Auto merged
sql/sql_update.cc:
  Auto merged
parents 4628da29 e1c8d9c9
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -981,7 +981,7 @@ void free_io_cache(TABLE *entry);
void intern_close_table(TABLE *entry);
bool close_thread_table(THD *thd, TABLE **table_ptr);
void close_temporary_tables(THD *thd);
void close_tables_for_reopen(THD *thd, TABLE_LIST *tables);
void close_tables_for_reopen(THD *thd, TABLE_LIST **tables);
TABLE_LIST *find_table_in_list(TABLE_LIST *table,
                               uint offset_to_list,
                               const char *db_name,
+27 −57
Original line number Diff line number Diff line
@@ -1982,22 +1982,11 @@ int open_tables(THD *thd, TABLE_LIST **start, uint *counter, uint flags)
    statement for which table list for prelocking is already built, let
    us cache routines and try to build such table list.

    NOTE: We can't delay prelocking until we will met some sub-statement
    which really uses tables, since this will imply that we have to restore
    its table list to be able execute it in some other context.
    And current views implementation assumes that view tables are added to
    global table list only once during PS preparing/first SP execution.
    Also locking at earlier stage is probably faster altough may decrease
    concurrency a bit.

    NOTE: We will mark statement as requiring prelocking only if we will
    have non empty table list. But this does not guarantee that in prelocked
    mode we will have some locked tables, because queries which use only
    derived/information schema tables and views possible. Thus "counter"
    may be still zero for prelocked statement...

    NOTE: The above notes may be out of date. Please wait for psergey to
          document new prelocked behavior.
  */

  if (!thd->prelocked_mode && !thd->lex->requires_prelocking() &&
@@ -2083,48 +2072,23 @@ int open_tables(THD *thd, TABLE_LIST **start, uint *counter, uint flags)

      if (refresh)				// Refresh in progress
      {
	/* close all 'old' tables used by this thread */
	pthread_mutex_lock(&LOCK_open);
	// if query_id is not reset, we will get an error
	// re-opening a temp table
	thd->version=refresh_version;
	TABLE **prev_table= &thd->open_tables;
	bool found=0;
	for (TABLE_LIST *tmp= *start; tmp; tmp= tmp->next_global)
	{
	  /* Close normal (not temporary) changed tables */
	  if (tmp->table && ! tmp->table->s->tmp_table)
	  {
	    if (tmp->table->s->version != refresh_version ||
		! tmp->table->db_stat)
	    {
	      VOID(hash_delete(&open_cache,(byte*) tmp->table));
	      tmp->table=0;
	      found=1;
	    }
	    else
	    {
	      *prev_table= tmp->table;		// Relink open list
	      prev_table= &tmp->table->next;
	    }
	  }
	}
	*prev_table=0;
	pthread_mutex_unlock(&LOCK_open);
	if (found)
	  VOID(pthread_cond_broadcast(&COND_refresh)); // Signal to refresh
        /*
          Let us prepare for recalculation of set of prelocked tables.
          First we pretend that we have finished calculation which we
          were doing currently. Then we restore list of tables to be
          opened and set of used routines to the state in which they were
          before first open_tables() call for this statement (i.e. before
          we have calculated current set of tables for prelocking).
          We have met name-locked or old version of table. Now we have
          to close all tables which are not up to date. We also have to
          throw away set of prelocked tables (and thus close tables from
          this set that were open by now) since it possible that one of
          tables which determined its content was changed.

          Instead of implementing complex/non-robust logic mentioned
          above we simply close and then reopen all tables.

          In order to prepare for recalculation of set of prelocked tables
          we pretend that we have finished calculation which we were doing
          currently.
        */
        if (query_tables_last_own)
          thd->lex->mark_as_requiring_prelocking(query_tables_last_own);
        thd->lex->chop_off_not_own_tables();
        sp_remove_not_own_routines(thd->lex);
        close_tables_for_reopen(thd, start);
	goto restart;
      }
      result= -1;				// Fatal error
@@ -2335,7 +2299,7 @@ int simple_open_n_lock_tables(THD *thd, TABLE_LIST *tables)
      break;
    if (!need_reopen)
      DBUG_RETURN(-1);
    close_tables_for_reopen(thd, tables);
    close_tables_for_reopen(thd, &tables);
  }
  DBUG_RETURN(0);
}
@@ -2372,7 +2336,7 @@ bool open_and_lock_tables(THD *thd, TABLE_LIST *tables)
      break;
    if (!need_reopen)
      DBUG_RETURN(-1);
    close_tables_for_reopen(thd, tables);
    close_tables_for_reopen(thd, &tables);
  }
  if (mysql_handle_derived(thd->lex, &mysql_derived_prepare) ||
      (thd->fill_derived_tables() &&
@@ -2600,18 +2564,24 @@ int lock_tables(THD *thd, TABLE_LIST *tables, uint count, bool *need_reopen)

  SYNOPSIS
    close_tables_for_reopen()
      thd     Thread context
      tables  List of tables which we were trying to open and lock
      thd    in     Thread context
      tables in/out List of tables which we were trying to open and lock

*/

void close_tables_for_reopen(THD *thd, TABLE_LIST *tables)
void close_tables_for_reopen(THD *thd, TABLE_LIST **tables)
{
  /*
    If table list consists only from tables from prelocking set, table list
    for new attempt should be empty, so we have to update list's root pointer.
  */
  if (thd->lex->first_not_own_table() == *tables)
    *tables= 0;
  thd->lex->chop_off_not_own_tables();
  sp_remove_not_own_routines(thd->lex);
  for (TABLE_LIST *tmp= tables; tmp; tmp= tmp->next_global)
    if (tmp->table && !tmp->table->s->tmp_table)
  for (TABLE_LIST *tmp= *tables; tmp; tmp= tmp->next_global)
    tmp->table= 0;
  mark_used_tables_as_free_for_reuse(thd, thd->temporary_tables);
  close_thread_tables(thd);
}

+1 −1
Original line number Diff line number Diff line
@@ -1135,7 +1135,7 @@ static int mysql_test_update(Prepared_statement *stmt,
      break;
    if (!need_reopen)
      goto error;
    close_tables_for_reopen(thd, table_list);
    close_tables_for_reopen(thd, &table_list);
  }

  /*
+2 −2
Original line number Diff line number Diff line
@@ -158,7 +158,7 @@ int mysql_update(THD *thd,
      break;
    if (!need_reopen)
      DBUG_RETURN(1);
    close_tables_for_reopen(thd, table_list);
    close_tables_for_reopen(thd, &table_list);
  }

  if (mysql_handle_derived(thd->lex, &mysql_derived_prepare) ||
@@ -823,7 +823,7 @@ bool mysql_multi_update_prepare(THD *thd)
    for (TABLE_LIST *tbl= table_list; tbl; tbl= tbl->next_global)
      tbl->cleanup_items();

    close_tables_for_reopen(thd, table_list);
    close_tables_for_reopen(thd, &table_list);
    goto reopen_tables;
  }