Commit d80451c8 authored by sasha@mysql.sashanet.com's avatar sasha@mysql.sashanet.com
Browse files

post-merge fixes

test SHOW OPEN TABLES
parent 27561841
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -90,3 +90,6 @@ t1 CREATE TABLE `t1` (
  `a` int(11) NOT NULL default '0',
  PRIMARY KEY  (`a`)
) TYPE=MyISAM
Open_tables_in_test	Comment
Open_tables_in_test	Comment
t1	cached=1, in_use=0
+7 −0
Original line number Diff line number Diff line
@@ -72,3 +72,10 @@ drop table t1;
create table t1 (a int not null, primary key (a));
show create table t1;
drop table t1;

flush tables;
show open tables;
create table t1(n int);
insert into t1 values (1);
show open tables;
drop table t1;
+4 −2
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ char *sql_strmake(const char *str,uint len);
gptr sql_memdup(const void * ptr,unsigned size);
void sql_element_free(void *ptr);
void kill_one_thread(THD *thd, ulong id);
char* query_table_status(THD *thd,const char *db,const char *table_name);

#define x_free(A)	{ my_free((gptr) (A),MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR)); }
#define safeFree(x)	{ if(x) { my_free((gptr) x,MYF(0)); x = NULL; } }
@@ -373,7 +374,7 @@ Field *find_field_in_table(THD *thd,TABLE *table,const char *name,uint length,

/* sql_list.c */
int mysqld_show_dbs(THD *thd,const char *wild);
int mysqld_show_open_tables(THD *thd,const char *wild);
int mysqld_show_open_tables(THD *thd,const char *db,const char *wild);
int mysqld_show_tables(THD *thd,const char *db,const char *wild);
int mysqld_extend_show_tables(THD *thd,const char *db,const char *wild);
int mysqld_show_fields(THD *thd,TABLE_LIST *table, const char *wild,
@@ -450,7 +451,8 @@ bool close_cached_tables(THD *thd, bool wait_for_refresh, TABLE_LIST *tables);
void copy_field_from_tmp_record(Field *field,int offset);
int fill_record(List<Item> &fields,List<Item> &values);
int fill_record(Field **field,List<Item> &values);
OPEN_TABLE_LIST *list_open_tables(THD *thd,const char *wild);
int list_open_tables(THD *thd,List<char> *tables, const char *db,
		     const char *wild);

/* sql_calc.cc */
bool eval_const_cond(COND *cond);
+42 −3
Original line number Diff line number Diff line
@@ -34,8 +34,6 @@ HASH open_cache; /* Used by mysql_test */

static int open_unireg_entry(THD *thd,TABLE *entry,const char *db,
			     const char *name, const char *alias, bool locked);
static bool insert_fields(THD *thd,TABLE_LIST *tables, const char *db_name,
			  const char *table_name, List_iterator<Item> *it);
static void free_cache_entry(TABLE *entry);
static void mysql_rm_tmp_tables(void);
static key_map get_key_map_from_key_list(TABLE *table,
@@ -407,6 +405,47 @@ bool close_cached_tables(THD *thd, bool if_wait_for_refresh,
  DBUG_RETURN(result);
}

/* move one table to free list */
 
bool close_thread_table(THD *thd, TABLE **table_ptr)
{
  DBUG_ENTER("close_thread_table");
 
  bool found_old_table=0;
  TABLE *table=*table_ptr;
 
  *table_ptr=table->next;
  if (table->version != refresh_version ||
      thd->version != refresh_version || !table->db_stat)
  {
    VOID(hash_delete(&open_cache,(byte*) table));
    found_old_table=1;
  }
  else
  {
    if (table->flush_version != flush_version)
    {
      table->flush_version=flush_version;
      table->file->extra(HA_EXTRA_FLUSH);
    }
    else
    {
      // Free memory and reset for next loop
      table->file->extra(HA_EXTRA_RESET);
    }
    table->in_use=0;
    if (unused_tables)
    {
      table->next=unused_tables;                /* Link in last */
      table->prev=unused_tables->prev;
      unused_tables->prev=table;
      table->prev->next=table;
    }
    else
      unused_tables=table->next=table->prev=table;
  }
  DBUG_RETURN(found_old_table);
}

/* Put all tables used by thread in free list */

@@ -1832,7 +1871,7 @@ static key_map get_key_map_from_key_list(TABLE *table,
**	Returns pointer to last inserted field if ok
****************************************************************************/

static bool
bool
insert_fields(THD *thd,TABLE_LIST *tables, const char *db_name,
	      const char *table_name, List_iterator<Item> *it)
{
+5 −4
Original line number Diff line number Diff line
@@ -1819,6 +1819,7 @@ mysql_execute_command(void)
    }
#endif
  case SQLCOM_SHOW_TABLES:
  case SQLCOM_SHOW_OPEN_TABLES:
    /* FALL THROUGH */
#ifdef DONT_ALLOW_SHOW_COMMANDS
    send_error(&thd->net,ER_NOT_ALLOWED_COMMAND);	/* purecov: inspected */
@@ -1840,7 +1841,10 @@ mysql_execute_command(void)
      if (check_access(thd,SELECT_ACL,db,&thd->col_access))
	goto error;				/* purecov: inspected */
      /* grant is checked in mysqld_show_tables */
      if (select_lex->options & SELECT_DESCRIBE)
       if (lex->sql_command == SQLCOM_SHOW_OPEN_TABLES) 
         res= mysqld_show_open_tables(thd, db,
				 (lex->wild ? lex->wild->ptr() : NullS));
      else if (select_lex->options & SELECT_DESCRIBE)
        res= mysqld_extend_show_tables(thd,db,
				       (lex->wild ? lex->wild->ptr() : NullS));
      else
@@ -1849,9 +1853,6 @@ mysql_execute_command(void)
      break;
    }
#endif
  case SQLCOM_SHOW_OPEN_TABLES:
    res= mysqld_show_open_tables(thd,(lex->wild ? lex->wild->ptr() : NullS));
    break;
  case SQLCOM_SHOW_FIELDS:
#ifdef DONT_ALLOW_SHOW_COMMANDS
    send_error(&thd->net,ER_NOT_ALLOWED_COMMAND);	/* purecov: inspected */