summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorunknown <tim@cane.mysql.fi>2000-12-18 23:34:51 +0200
committerunknown <tim@cane.mysql.fi>2000-12-18 23:34:51 +0200
commit82b9e4e7c56520c1bca3958972ceafa943777cd0 (patch)
treec32441c27c7e6943a88e8123adfdbd455907d280 /sql
parent791d4ea04da4ac8ed5051bd97c2a9cc717f5380e (diff)
parent08d8d2adebc58f87a5198fc1c6f20bb27c3dffb1 (diff)
downloadmariadb-git-82b9e4e7c56520c1bca3958972ceafa943777cd0.tar.gz
Merge
Docs/manual.texi: Auto merged sql/sql_show.cc: Auto merged BUILD/compile-pentium: SCCS merged
Diffstat (limited to 'sql')
-rw-r--r--sql/gen_lex_hash.cc2
-rw-r--r--sql/lex.h1
-rw-r--r--sql/mysql_priv.h3
-rw-r--r--sql/sql_base.cc68
-rw-r--r--sql/sql_lex.h3
-rw-r--r--sql/sql_parse.cc9
-rw-r--r--sql/sql_show.cc45
-rw-r--r--sql/sql_yacc.yy7
8 files changed, 132 insertions, 6 deletions
diff --git a/sql/gen_lex_hash.cc b/sql/gen_lex_hash.cc
index 1ba8c321ae7..e77081c64a0 100644
--- a/sql/gen_lex_hash.cc
+++ b/sql/gen_lex_hash.cc
@@ -472,7 +472,7 @@ int main(int argc,char **argv)
int error;
MY_INIT(argv[0]);
- start_value=2610463L; best_t1=8358376L; best_t2=860646L; best_type=2; /* mode=4111 add=8 func_type: 0 */
+ start_value=5206280L; best_t1=590774L; best_t2=5977654L; best_type=1; /* mode=6229 add=2 func_type: 0 */
if (get_options(argc,(char **) argv))
exit(1);
diff --git a/sql/lex.h b/sql/lex.h
index 503ce6998bb..399106bfd77 100644
--- a/sql/lex.h
+++ b/sql/lex.h
@@ -223,6 +223,7 @@ static SYMBOL symbols[] = {
{ "NOT", SYM(NOT),0,0},
{ "NULL", SYM(NULL_SYM),0,0},
{ "ON", SYM(ON),0,0},
+ { "OPEN", SYM(OPEN_SYM),0,0},
{ "OPTIMIZE", SYM(OPTIMIZE),0,0},
{ "OPTION", SYM(OPTION),0,0},
{ "OPTIONALLY", SYM(OPTIONALLY),0,0},
diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h
index 067e17c4356..0980c91e444 100644
--- a/sql/mysql_priv.h
+++ b/sql/mysql_priv.h
@@ -354,6 +354,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 *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);
@@ -418,6 +419,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);
+int list_open_tables(THD *thd,List<char> *files, const char *db,const char *wild);
+char* query_table_status(THD *thd,const char *db,const char *table_name);
/* sql_calc.cc */
bool eval_const_cond(COND *cond);
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index 623ed5dc0b6..74e8dccd4d7 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -112,6 +112,74 @@ static void check_unused(void)
#define check_unused()
#endif
+int list_open_tables(THD *thd,List<char> *tables, const char *db,const char *wild)
+{
+ int result = 0;
+ uint col_access=thd->col_access;
+ TABLE_LIST table_list;
+ DBUG_ENTER("list_open_tables");
+ VOID(pthread_mutex_lock(&LOCK_open));
+ bzero((char*) &table_list,sizeof(table_list));
+
+ for (uint idx=0 ; result == 0 && idx < open_cache.records; idx++)
+ {
+ TABLE *entry=(TABLE*) hash_element(&open_cache,idx);
+ if ((!entry->real_name) || strcmp(entry->table_cache_key,db))
+ continue;
+ if (wild && wild[0] && wild_compare(entry->real_name,wild))
+ continue;
+ if (db && !(col_access & TABLE_ACLS))
+ {
+ table_list.db= (char*) db;
+ table_list.real_name= entry->real_name;/*real name*/
+ table_list.grant.privilege=col_access;
+ if (check_grant(thd,TABLE_ACLS,&table_list,1))
+ continue;
+ }
+ /* need to check if he have't already listed it */
+
+ List_iterator<char> it(*tables);
+ char *table_name;
+ int check = 0;
+ while (check == 0 && (table_name=it++))
+ {
+ if (!strcmp(table_name,entry->real_name))
+ check++;
+ }
+ if (check)
+ continue;
+
+ if (tables->push_back(thd->strdup(entry->real_name)))
+ {
+ result = -1;
+ }
+ }
+
+ VOID(pthread_mutex_unlock(&LOCK_open));
+ DBUG_RETURN(result);
+}
+
+char*
+query_table_status(THD *thd,const char *db,const char *table_name)
+{
+ int cached = 0, in_use = 0;
+ char info[256];
+
+ for (uint idx=0 ; idx < open_cache.records; idx++)
+ {
+ TABLE *entry=(TABLE*) hash_element(&open_cache,idx);
+ if (strcmp(entry->table_cache_key,db) ||
+ strcmp(entry->real_name,table_name))
+ continue;
+
+ cached++;
+ if (entry->in_use)
+ in_use++;
+ }
+
+ sprintf(info, "cached=%d, in_use=%d", cached, in_use);
+ return thd->strdup(info);
+}
/******************************************************************************
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index 46ff08e0a47..7f52cc3e84c 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -52,7 +52,8 @@ enum enum_sql_command {
SQLCOM_ROLLBACK, SQLCOM_COMMIT, SQLCOM_SLAVE_START, SQLCOM_SLAVE_STOP,
SQLCOM_BEGIN, SQLCOM_LOAD_MASTER_TABLE, SQLCOM_CHANGE_MASTER,
SQLCOM_RENAME_TABLE, SQLCOM_BACKUP_TABLE, SQLCOM_RESTORE_TABLE,
- SQLCOM_RESET, SQLCOM_PURGE, SQLCOM_SHOW_BINLOGS
+ SQLCOM_RESET, SQLCOM_PURGE, SQLCOM_SHOW_BINLOGS,
+ SQLCOM_SHOW_OPEN_TABLES
};
enum lex_states { STATE_START, STATE_CHAR, STATE_IDENT,
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index fef35ed88d0..30b45cb18df 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -1488,6 +1488,8 @@ mysql_execute_command(void)
}
#endif
case SQLCOM_SHOW_TABLES:
+ /* FALL THROUGH */
+ case SQLCOM_SHOW_OPEN_TABLES:
#ifdef DONT_ALLOW_SHOW_COMMANDS
send_error(&thd->net,ER_NOT_ALLOWED_COMMAND); /* purecov: inspected */
DBUG_VOID_RETURN;
@@ -1508,8 +1510,11 @@ 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 (lex->options & SELECT_DESCRIBE)
- res= mysqld_extend_show_tables(thd,db,
+ if (lex->sql_command == SQLCOM_SHOW_OPEN_TABLES)
+ res= mysqld_show_open_tables(thd,db,
+ (lex->wild ? lex->wild->ptr() : NullS));
+ else if (lex->options & SELECT_DESCRIBE)
+ res= mysqld_extend_show_tables(thd,db,
(lex->wild ? lex->wild->ptr() : NullS));
else
res= mysqld_show_tables(thd,db,
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index 3094ff26d89..d4643505ced 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -87,6 +87,47 @@ mysqld_show_dbs(THD *thd,const char *wild)
}
/***************************************************************************
+** List all open tables in a database
+***************************************************************************/
+
+int mysqld_show_open_tables(THD *thd,const char *db,const char *wild)
+{
+ Item_string *field=new Item_string("",0);
+ List<Item> field_list;
+ char *end,*table_name;
+ List<char> tables;
+ DBUG_ENTER("mysqld_show_open_tables");
+
+ field->name=(char*) thd->alloc(20+(uint) strlen(db)+(wild ? (uint) strlen(wild)+4:0));
+ end=strxmov(field->name,"Open_tables_in_",db,NullS);
+ if (wild && wild[0])
+ strxmov(end," (",wild,")",NullS);
+ field->max_length=NAME_LEN;
+ field_list.push_back(field);
+ field_list.push_back(new Item_empty_string("Comment",80));
+
+ if (send_fields(thd,field_list,1))
+ DBUG_RETURN(1);
+
+ if (list_open_tables(thd,&tables,db,wild))
+ DBUG_RETURN(-1);
+
+ List_iterator<char> it(tables);
+ while ((table_name=it++))
+ {
+ thd->packet.length(0);
+ net_store_data(&thd->packet,table_name);
+ net_store_data(&thd->packet,query_table_status(thd,db,table_name));
+ if (my_net_write(&thd->net,(char*) thd->packet.ptr(),thd->packet.length()))
+ DBUG_RETURN(-1);
+ }
+
+
+ send_eof(&thd->net);
+ DBUG_RETURN(0);
+}
+
+/***************************************************************************
** List all tables in a database (fast version)
** A table is a .frm file in the current databasedir
***************************************************************************/
@@ -161,9 +202,9 @@ mysql_find_files(THD *thd,List<char> *files, const char *db,const char *path,
}
else
{
- // Return only .frm files which isn't temp files.
+ // Return only .frm files which aren't temp files.
if (my_strcasecmp(ext=fn_ext(file->name),reg_ext) ||
- is_prefix(file->name,tmp_file_prefix)) // Mysql temp table
+ is_prefix(file->name,tmp_file_prefix))
continue;
*ext=0;
if (wild && wild[0] && wild_compare(file->name,wild))
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 84e55d46c71..94c1ea943e7 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -216,6 +216,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
%token NULL_SYM
%token NUM
%token ON
+%token OPEN_SYM
%token OPTION
%token OPTIONALLY
%token OR
@@ -2151,6 +2152,11 @@ show_param:
Lex->options|= SELECT_DESCRIBE;
Lex->db= $3;
}
+ | OPEN_SYM TABLES opt_db wild
+ { Lex->sql_command= SQLCOM_SHOW_OPEN_TABLES;
+ Lex->db= $3;
+ Lex->options=0;
+ }
| COLUMNS FROM table_ident opt_db wild
{
Lex->sql_command= SQLCOM_SHOW_FIELDS;
@@ -2513,6 +2519,7 @@ keyword:
| NATIONAL_SYM {}
| NCHAR_SYM {}
| NO_SYM {}
+ | OPEN_SYM {}
| PACK_KEYS_SYM {}
| PASSWORD {}
| PROCESS {}