Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
5d58a49f
Commit
5d58a49f
authored
Jul 11, 2001
by
monty@tik.mysql.fi
Browse files
Options
Browse Files
Download
Plain Diff
Merge work.mysql.com:/home/bk/mysql-4.0
into tik.mysql.fi:/home/my/mysql-4.0
parents
38d3bf51
539541c5
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
121 additions
and
158 deletions
+121
-158
mysql-test/r/show_check.result
mysql-test/r/show_check.result
+3
-3
sql/ha_myisam.h
sql/ha_myisam.h
+5
-3
sql/mysql_priv.h
sql/mysql_priv.h
+2
-3
sql/sql_base.cc
sql/sql_base.cc
+90
-124
sql/sql_parse.cc
sql/sql_parse.cc
+9
-10
sql/sql_show.cc
sql/sql_show.cc
+12
-15
No files found.
mysql-test/r/show_check.result
View file @
5d58a49f
...
...
@@ -90,6 +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
t
1 cached=1, in_use=
0
Database Table In_use Name_locked
Database Table In_use Name_locked
t
est t1 0
0
sql/ha_myisam.h
View file @
5d58a49f
...
...
@@ -37,17 +37,19 @@ extern ulong myisam_recover_options;
class
ha_myisam
:
public
handler
{
MI_INFO
*
file
;
uint
int_option_flag
,
enable_activate_all_index
;
uint
int_option_flag
;
char
*
data_file_name
,
*
index_file_name
;
bool
enable_activate_all_index
;
int
repair
(
THD
*
thd
,
MI_CHECK
&
param
,
bool
optimize
);
public:
ha_myisam
(
TABLE
*
table
)
:
handler
(
table
),
file
(
0
),
enable_activate_all_index
(
1
),
ha_myisam
(
TABLE
*
table
)
:
handler
(
table
),
file
(
0
),
int_option_flag
(
HA_READ_NEXT
|
HA_READ_PREV
|
HA_READ_RND_SAME
|
HA_KEYPOS_TO_RNDPOS
|
HA_READ_ORDER
|
HA_LASTKEY_ORDER
|
HA_HAVE_KEY_READ_ONLY
|
HA_READ_NOT_EXACT_KEY
|
HA_LONGLONG_KEYS
|
HA_NULL_KEY
|
HA_DUPP_POS
|
HA_BLOB_KEY
|
HA_AUTO_PART_KEY
)
HA_DUPP_POS
|
HA_BLOB_KEY
|
HA_AUTO_PART_KEY
),
enable_activate_all_index
(
1
)
{}
~
ha_myisam
()
{}
const
char
*
table_type
()
const
{
return
"MyISAM"
;
}
...
...
sql/mysql_priv.h
View file @
5d58a49f
...
...
@@ -374,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
*
db
,
const
char
*
wild
);
int
mysqld_show_open_tables
(
THD
*
thd
,
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
,
...
...
@@ -451,8 +451,7 @@ 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
>
*
tables
,
const
char
*
db
,
const
char
*
wild
);
OPEN_TABLE_LIST
*
list_open_tables
(
THD
*
thd
,
const
char
*
wild
);
/* sql_calc.cc */
bool
eval_const_cond
(
COND
*
cond
);
...
...
sql/sql_base.cc
View file @
5d58a49f
...
...
@@ -109,75 +109,71 @@ static void check_unused(void)
#define check_unused()
#endif
int
list_open_tables
(
THD
*
thd
,
List
<
char
>
*
tables
,
const
char
*
db
,
const
char
*
wild
)
OPEN_TABLE_LIST
*
list_open_tables
(
THD
*
thd
,
const
char
*
wild
)
{
int
result
=
0
;
uint
col_access
=
thd
->
col_access
;
OPEN_TABLE_LIST
**
start_list
,
*
open_list
;
TABLE_LIST
table_list
;
char
name
[
NAME_LEN
*
2
];
DBUG_ENTER
(
"list_open_tables"
);
VOID
(
pthread_mutex_lock
(
&
LOCK_open
));
bzero
((
char
*
)
&
table_list
,
sizeof
(
table_list
));
start_list
=
&
open_list
;
open_list
=
0
;
for
(
uint
idx
=
0
;
idx
<
open_cache
.
records
;
idx
++
)
for
(
uint
idx
=
0
;
result
==
0
&&
idx
<
open_cache
.
records
;
idx
++
)
{
OPEN_TABLE_LIST
*
table
;
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
))
if
((
!
entry
->
real_name
))
continue
;
// Shouldn't happen
if
(
wild
)
{
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
;
strxmov
(
name
,
entry
->
table_cache_key
,
"."
,
entry
->
real_name
,
NullS
);
if
(
wild_compare
(
name
,
wild
))
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
++
))
/* Check if user has SELECT privilege for any column in the table */
table_list
.
db
=
(
char
*
)
entry
->
table_cache_key
;
table_list
.
real_name
=
entry
->
real_name
;
table_list
.
grant
.
privilege
=
0
;
if
(
check_table_access
(
thd
,
SELECT_ACL
|
EXTRA_ACL
,
&
table_list
))
continue
;
/* need to check if we haven't already listed it */
for
(
table
=
open_list
;
table
;
table
=
table
->
next
)
{
if
(
!
strcmp
(
table_name
,
entry
->
real_name
))
check
++
;
if
(
!
strcmp
(
table
->
table
,
entry
->
real_name
)
&&
!
strcmp
(
table
->
db
,
entry
->
table_cache_key
))
{
if
(
entry
->
in_use
)
table
->
in_use
++
;
if
(
entry
->
locked_by_name
)
table
->
locked
++
;
break
;
}
}
if
(
check
)
if
(
table
)
continue
;
if
(
tables
->
push_back
(
thd
->
strdup
(
entry
->
real_name
)))
if
(
!
(
*
start_list
=
(
OPEN_TABLE_LIST
*
)
sql_alloc
(
sizeof
(
OPEN_TABLE_LIST
)
+
entry
->
key_length
)))
{
result
=
-
1
;
open_list
=
0
;
// Out of memory
break
;
}
(
*
start_list
)
->
table
=
(
strmov
((
*
start_list
)
->
db
=
(
char
*
)
((
*
start_list
)
+
1
),
entry
->
table_cache_key
)
+
1
,
entry
->
real_name
);
(
*
start_list
)
->
in_use
=
entry
->
in_use
?
1
:
0
;
(
*
start_list
)
->
locked
=
entry
->
locked_by_name
?
1
:
0
;
start_list
=
&
(
*
start_list
)
->
next
;
}
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
);
DBUG_RETURN
(
open_list
);
}
...
...
@@ -257,7 +253,7 @@ send_fields(THD *thd,List<Item> &list,uint flag)
if
(
my_net_write
(
&
thd
->
net
,
(
char
*
)
packet
->
ptr
(),
packet
->
length
()))
break
;
/* purecov: inspected */
}
send_eof
(
&
thd
->
net
,(
test_flags
&
TEST_MIT_THREAD
)
?
0
:
1
);
send_eof
(
&
thd
->
net
);
return
0
;
err:
send_error
(
&
thd
->
net
,
ER_OUT_OF_RESOURCES
);
/* purecov: inspected */
...
...
@@ -405,47 +401,6 @@ 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 */
...
...
@@ -469,40 +424,9 @@ void close_thread_tables(THD *thd, bool locked)
DBUG_PRINT
(
"info"
,
(
"thd->open_tables=%p"
,
thd
->
open_tables
));
for
(
table
=
thd
->
open_tables
;
table
;
table
=
next
)
{
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
;
while
(
thd
->
open_tables
)
found_old_table
|=
close_thread_table
(
thd
,
&
thd
->
open_tables
);
/* Free tables to hold down open files */
while
(
open_cache
.
records
>
table_cache_size
&&
unused_tables
)
VOID
(
hash_delete
(
&
open_cache
,(
byte
*
)
unused_tables
));
/* purecov: tested */
...
...
@@ -518,6 +442,48 @@ void close_thread_tables(THD *thd, bool locked)
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 */
void
close_temporary
(
TABLE
*
table
,
bool
delete_table
)
...
...
sql/sql_parse.cc
View file @
5d58a49f
...
...
@@ -47,7 +47,7 @@ static void mysql_init_query(THD *thd);
static
void
remove_escape
(
char
*
name
);
static
void
refresh_status
(
void
);
static
bool
append_file_to_dir
(
char
**
filename_ptr
,
char
*
table_name
);
static
int
link_in_large_list_and_check_acl
(
THD
*
thd
,
LEX
*
lex
,
SQL_LIST
*
tables
);
static
int
link_in_large_list_and_check_acl
(
THD
*
thd
,
LEX
*
lex
,
SQL_LIST
*
tables
);
const
char
*
any_db
=
"*any*"
;
// Special symbol for check_access
...
...
@@ -663,7 +663,7 @@ int mysql_table_dump(THD* thd, char* db, char* tbl_name, int fd)
int
error
=
0
;
DBUG_ENTER
(
"mysql_table_dump"
);
db
=
(
db
&&
db
[
0
])
?
db
:
thd
->
db
;
if
(
!
(
table_list
=
(
TABLE_LIST
*
)
sql_
calloc
(
sizeof
(
TABLE_LIST
))))
if
(
!
(
table_list
=
(
TABLE_LIST
*
)
thd
->
calloc
(
sizeof
(
TABLE_LIST
))))
DBUG_RETURN
(
1
);
// out of memory
table_list
->
db
=
db
;
table_list
->
real_name
=
table_list
->
name
=
tbl_name
;
...
...
@@ -780,7 +780,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
slow_command
=
TRUE
;
uint
db_len
=
*
(
uchar
*
)
packet
;
uint
tbl_len
=
*
(
uchar
*
)(
packet
+
db_len
+
1
);
char
*
db
=
sql_
alloc
(
db_len
+
tbl_len
+
2
);
char
*
db
=
thd
->
alloc
(
db_len
+
tbl_len
+
2
);
memcpy
(
db
,
packet
+
1
,
db_len
);
char
*
tbl_name
=
db
+
db_len
;
*
tbl_name
++
=
0
;
...
...
@@ -973,7 +973,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
char
buff
[
200
];
ulong
uptime
=
(
ulong
)
(
thd
->
start_time
-
start_time
);
sprintf
((
char
*
)
buff
,
"Uptime: %ld Threads: %d Questions: %lu Slow queries: %ld Opens: %ld Flush tables: %ld Open tables: %
d
Queries per second avg: %.3f"
,
"Uptime: %ld Threads: %d Questions: %lu Slow queries: %ld Opens: %ld Flush tables: %ld Open tables: %
u
Queries per second avg: %.3f"
,
uptime
,
(
int
)
thread_count
,
thd
->
query_id
,
long_query_count
,
opened_tables
,
refresh_version
,
cached_tables
(),
...
...
@@ -1819,7 +1819,6 @@ 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 */
...
...
@@ -1841,10 +1840,7 @@ 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
->
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
)
if
(
select_lex
->
options
&
SELECT_DESCRIBE
)
res
=
mysqld_extend_show_tables
(
thd
,
db
,
(
lex
->
wild
?
lex
->
wild
->
ptr
()
:
NullS
));
else
...
...
@@ -1853,6 +1849,9 @@ 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 */
...
...
@@ -2451,7 +2450,7 @@ void
mysql_new_select
(
LEX
*
lex
)
{
uint
select_no
=
lex
->
select
->
select_number
;
SELECT_LEX
*
select_lex
=
(
SELECT_LEX
*
)
sql_
calloc
(
sizeof
(
SELECT_LEX
));
SELECT_LEX
*
select_lex
=
(
SELECT_LEX
*
)
lex
->
thd
->
calloc
(
sizeof
(
SELECT_LEX
));
lex
->
select
->
next
=
select_lex
;
lex
->
select
=
select_lex
;
lex
->
select
->
select_number
=
++
select_no
;
lex
->
select
->
item_list
=
lex
->
select_lex
.
item_list
;
...
...
sql/sql_show.cc
View file @
5d58a49f
...
...
@@ -95,21 +95,17 @@ 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
)
int
mysqld_show_open_tables
(
THD
*
thd
,
const
char
*
wild
)
{
Item_string
*
field
=
new
Item_string
(
""
,
0
);
List
<
Item
>
field_list
;
char
*
end
,
*
table_name
;
List
<
char
>
tables
;
OPEN_TABLE_LIST
*
open_list
;
CONVERT
*
convert
=
thd
->
convert_set
;
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
));
field_list
.
push_back
(
new
Item_empty_string
(
"Database"
,
NAME_LEN
));
field_list
.
push_back
(
new
Item_empty_string
(
"Table"
,
NAME_LEN
));
field_list
.
push_back
(
new
Item_int
(
"In_use"
,
0
,
4
));
field_list
.
push_back
(
new
Item_int
(
"Name_locked"
,
0
,
4
));
if
(
send_fields
(
thd
,
field_list
,
1
))
DBUG_RETURN
(
1
);
...
...
@@ -117,12 +113,13 @@ int mysqld_show_open_tables(THD *thd,const char *db,const char *wild)
if
(
!
(
list_open_tables
(
thd
,
&
tables
,
db
,
wild
))
&&
thd
->
fatal_error
)
DBUG_RETURN
(
-
1
);
List_iterator
<
char
>
it
(
tables
);
while
((
table_name
=
it
++
))
for
(
;
open_list
;
open_list
=
open_list
->
next
)
{
thd
->
packet
.
length
(
0
);
net_store_data
(
&
thd
->
packet
,
table_name
);
net_store_data
(
&
thd
->
packet
,
query_table_status
(
thd
,
db
,
table_name
));
net_store_data
(
&
thd
->
packet
,
convert
,
open_list
->
db
);
net_store_data
(
&
thd
->
packet
,
convert
,
open_list
->
table
);
net_store_data
(
&
thd
->
packet
,
open_list
->
in_use
);
net_store_data
(
&
thd
->
packet
,
open_list
->
locked
);
if
(
my_net_write
(
&
thd
->
net
,(
char
*
)
thd
->
packet
.
ptr
(),
thd
->
packet
.
length
()))
DBUG_RETURN
(
-
1
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment