mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
fully functional HANDLER table CLOSE
This commit is contained in:
@ -430,6 +430,7 @@ bool send_fields(THD *thd,List<Item> &item,uint send_field_count);
|
|||||||
void free_io_cache(TABLE *entry);
|
void free_io_cache(TABLE *entry);
|
||||||
void intern_close_table(TABLE *entry);
|
void intern_close_table(TABLE *entry);
|
||||||
void close_thread_tables(THD *thd,bool locked=0);
|
void close_thread_tables(THD *thd,bool locked=0);
|
||||||
|
bool close_thread_table(THD *thd, TABLE **table_ptr);
|
||||||
void close_temporary_tables(THD *thd);
|
void close_temporary_tables(THD *thd);
|
||||||
TABLE **find_temporary_table(THD *thd, const char *db, const char *table_name);
|
TABLE **find_temporary_table(THD *thd, const char *db, const char *table_name);
|
||||||
bool close_temporary_table(THD *thd, const char *db, const char *table_name);
|
bool close_temporary_table(THD *thd, const char *db, const char *table_name);
|
||||||
|
@ -421,40 +421,9 @@ void close_thread_tables(THD *thd, bool locked)
|
|||||||
|
|
||||||
DBUG_PRINT("info", ("thd->open_tables=%p", thd->open_tables));
|
DBUG_PRINT("info", ("thd->open_tables=%p", thd->open_tables));
|
||||||
|
|
||||||
for (table=thd->open_tables ; table ; table=next)
|
while (thd->open_tables)
|
||||||
{
|
found_old_table|=close_thread_table(thd, &thd->open_tables);
|
||||||
next=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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
thd->open_tables=0;
|
|
||||||
/* Free tables to hold down open files */
|
/* Free tables to hold down open files */
|
||||||
while (open_cache.records > table_cache_size && unused_tables)
|
while (open_cache.records > table_cache_size && unused_tables)
|
||||||
VOID(hash_delete(&open_cache,(byte*) unused_tables)); /* purecov: tested */
|
VOID(hash_delete(&open_cache,(byte*) unused_tables)); /* purecov: tested */
|
||||||
@ -470,6 +439,48 @@ void close_thread_tables(THD *thd, bool locked)
|
|||||||
DBUG_VOID_RETURN;
|
DBUG_VOID_RETURN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
|
|
||||||
/* Close and delete temporary tables */
|
/* Close and delete temporary tables */
|
||||||
|
|
||||||
void close_temporary(TABLE *table,bool delete_table)
|
void close_temporary(TABLE *table,bool delete_table)
|
||||||
|
@ -43,7 +43,7 @@
|
|||||||
thd->open_tables=thd->handler_tables; \
|
thd->open_tables=thd->handler_tables; \
|
||||||
thd->handler_tables=tmp; }
|
thd->handler_tables=tmp; }
|
||||||
|
|
||||||
static TABLE *find_table_by_name(THD *thd, char *db, char *table_name);
|
static TABLE **find_table_ptr_by_name(THD *thd, char *db, char *table_name);
|
||||||
|
|
||||||
int mysql_ha_open(THD *thd, TABLE_LIST *tables)
|
int mysql_ha_open(THD *thd, TABLE_LIST *tables)
|
||||||
{
|
{
|
||||||
@ -59,11 +59,11 @@ int mysql_ha_open(THD *thd, TABLE_LIST *tables)
|
|||||||
|
|
||||||
int mysql_ha_close(THD *thd, TABLE_LIST *tables)
|
int mysql_ha_close(THD *thd, TABLE_LIST *tables)
|
||||||
{
|
{
|
||||||
/* Perhaps, we should close table here.
|
TABLE **ptr=find_table_ptr_by_name(thd, tables->db, tables->name);
|
||||||
But it's not easy - *tables is a single-linked list, designed
|
|
||||||
to be closed at all once.
|
if (*ptr)
|
||||||
So, why bother ? All the tables will be closed at thread exit.
|
close_thread_table(thd, ptr);
|
||||||
*/
|
|
||||||
send_ok(&thd->net);
|
send_ok(&thd->net);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -77,7 +77,7 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables,
|
|||||||
ha_rows select_limit,ha_rows offset_limit)
|
ha_rows select_limit,ha_rows offset_limit)
|
||||||
{
|
{
|
||||||
int err, keyno=-1;
|
int err, keyno=-1;
|
||||||
TABLE *table=find_table_by_name(thd, tables->db, tables->name);
|
TABLE *table=*find_table_ptr_by_name(thd, tables->db, tables->name);
|
||||||
if (!table)
|
if (!table)
|
||||||
{
|
{
|
||||||
my_printf_error(ER_UNKNOWN_TABLE,ER(ER_UNKNOWN_TABLE),MYF(0),
|
my_printf_error(ER_UNKNOWN_TABLE,ER(ER_UNKNOWN_TABLE),MYF(0),
|
||||||
@ -231,19 +231,22 @@ err:
|
|||||||
/* Note: this function differs from find_locked_table() because we're looking
|
/* Note: this function differs from find_locked_table() because we're looking
|
||||||
here for alias, not real table name
|
here for alias, not real table name
|
||||||
*/
|
*/
|
||||||
static TABLE *find_table_by_name(THD *thd, char *db, char *table_name)
|
static TABLE **find_table_ptr_by_name(THD *thd, char *db, char *table_name)
|
||||||
{
|
{
|
||||||
int dblen;
|
int dblen;
|
||||||
|
TABLE **ptr;
|
||||||
|
|
||||||
if (!db || ! *db) db=thd->db;
|
if (!db || ! *db) db=thd->db;
|
||||||
if (!db || ! *db) db="";
|
if (!db || ! *db) db="";
|
||||||
dblen=strlen(db);
|
dblen=strlen(db);
|
||||||
|
ptr=&(thd->handler_tables);
|
||||||
|
|
||||||
for (TABLE *table=thd->handler_tables; table ; table=table->next)
|
for (TABLE *table=*ptr; table ; table=*ptr)
|
||||||
{
|
{
|
||||||
if (!memcmp(table->table_cache_key, db, dblen) &&
|
if (!memcmp(table->table_cache_key, db, dblen) &&
|
||||||
!my_strcasecmp(table->table_name,table_name))
|
!my_strcasecmp(table->table_name,table_name))
|
||||||
return table;
|
break;
|
||||||
|
ptr=&(table->next);
|
||||||
}
|
}
|
||||||
return(0);
|
return ptr;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user