Merge lp:~mydb08/maria/maria-5.1 into lp:~maria-captains/maria/5.1-converting

Proposed by Venu Anuganti
Status: Rejected
Rejected by: Sergei Golubchik
Proposed branch: lp:~mydb08/maria/maria-5.1
Merge into: lp:~maria-captains/maria/5.1-converting
Diff against target: 527 lines (+395/-1)
8 files modified
mysql-test/r/show_temp_tables.result (+62/-0)
mysql-test/t/show_temp_tables.test (+64/-0)
sql/mysqld.cc (+1/-0)
sql/sql_lex.h (+1/-1)
sql/sql_parse.cc (+8/-0)
sql/sql_show.cc (+248/-0)
sql/sql_yacc.yy (+9/-0)
sql/table.h (+2/-0)
To merge this branch: bzr merge lp:~mydb08/maria/maria-5.1
Reviewer Review Type Date Requested Status
Sergei Golubchik Pending
Review via email: mp+20003@code.launchpad.net

Commit message

Draft implementation of show temporary tables

To post a comment you must log in.
Revision history for this message
Venu Anuganti (mydb08) wrote :

Initial SHOW [GLOBAL] TEMPORARY TABLES [FROM/IN db] implementation along with associated Information Schema tables.

Its been a while (probably 6 yrs+) I pushed any code to MySQL, so review is a must even though am working actively on MySQL code for last few years for developing storage engines.

Give me the feedback in case if I missed anything.

Todo:

- ACL check on global temp tables, need an advice on what priv to use
- InnoDB has some issues on stat(tmp_file) as its not generating the full path, will work on a fix.

Questions:

Do we need to expose internal temp tables to this implementation ? I don't see any benefit doing so as it should be really part of slow query implementation.

lp:~mydb08/maria/maria-5.1 updated
2823. By Venu Anuganti

added a test case for show temp tables

Revision history for this message
Venu Anuganti (mydb08) wrote :
Download full text (15.6 KiB)

Looks like the diff is in-complete.. but you should get the updated
one from here..
https://code.launchpad.net/~mydb08/maria/maria-5.1/+merge/20003

On Tue, Feb 23, 2010 at 1:17 PM, Venu Anuganti <email address hidden> wrote:
> Venu Anuganti has proposed merging lp:~mydb08/maria/maria-5.1 into lp:maria.
>
>    Requested reviews:
>    Maria-captains (maria-captains)
>
>
> Initial SHOW [GLOBAL] TEMPORARY TABLES [FROM/IN db] implementation along with associated Information Schema tables.
>
> Its been a while (probably 6 yrs+) I pushed any code to MySQL, so review is a must even though am working actively on MySQL code for last few years for developing storage engines.
>
> Give me the feedback in case if I missed anything.
>
> Todo:
>
> - ACL check on global temp tables, need an advice on what priv to use
> - InnoDB has some issues on stat(tmp_file) as its not generating the full path, will work on a fix.
>
> Questions:
>
> Do we need to expose internal temp tables to this implementation ? I don't see any benefit doing so as it should be really part of slow query implementation.
>
> --
> https://code.launchpad.net/~mydb08/maria/maria-5.1/+merge/20003
> You are the owner of lp:~mydb08/maria/maria-5.1.
>
> === modified file 'sql/mysqld.cc'
> --- sql/mysqld.cc       2010-02-11 19:15:24 +0000
> +++ sql/mysqld.cc       2010-02-23 21:17:16 +0000
> @@ -3272,6 +3272,7 @@
>   {"show_storage_engines", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_STORAGE_ENGINES]), SHOW_LONG_STATUS},
>   {"show_table_status",    (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_TABLE_STATUS]), SHOW_LONG_STATUS},
>   {"show_tables",          (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_TABLES]), SHOW_LONG_STATUS},
> +  {"show_temporary_tables",(char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_TEMPORARY_TABLES]), SHOW_LONG_STATUS},
>   {"show_triggers",        (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_TRIGGERS]), SHOW_LONG_STATUS},
>   {"show_variables",       (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_VARIABLES]), SHOW_LONG_STATUS},
>   {"show_warnings",        (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_WARNS]), SHOW_LONG_STATUS},
>
> === modified file 'sql/sql_lex.h'
> --- sql/sql_lex.h       2009-12-03 11:19:05 +0000
> +++ sql/sql_lex.h       2010-02-23 21:17:16 +0000
> @@ -67,7 +67,7 @@
>   SQLCOM_UPDATE, SQLCOM_INSERT, SQLCOM_INSERT_SELECT,
>   SQLCOM_DELETE, SQLCOM_TRUNCATE, SQLCOM_DROP_TABLE, SQLCOM_DROP_INDEX,
>
> -  SQLCOM_SHOW_DATABASES, SQLCOM_SHOW_TABLES, SQLCOM_SHOW_FIELDS,
> +  SQLCOM_SHOW_DATABASES, SQLCOM_SHOW_TABLES, SQLCOM_SHOW_TEMPORARY_TABLES, SQLCOM_SHOW_FIELDS,
>   SQLCOM_SHOW_KEYS, SQLCOM_SHOW_VARIABLES, SQLCOM_SHOW_STATUS,
>   SQLCOM_SHOW_ENGINE_LOGS, SQLCOM_SHOW_ENGINE_STATUS, SQLCOM_SHOW_ENGINE_MUTEX,
>   SQLCOM_SHOW_PROCESSLIST, SQLCOM_SHOW_MASTER_STAT, SQLCOM_SHOW_SLAVE_STAT,
>
> === modified file 'sql/sql_parse.cc'
> --- sql/sql_parse.cc    2010-01-29 10:42:31 +0000
> +++ sql/sql_parse.cc    2010-02-23 21:17:16 +0000
> @@ -342,6 +342,9 @@
>    sql_command_flags[SQLCOM_SHOW_TABLES]=       (CF_STATUS_COMMAND |
>                                                  CF_SHOW_TABL...

lp:~mydb08/maria/maria-5.1 updated
2824. By Venu Anuganti

merge changes

2825. By Venu Anuganti

add ACL check on DB names when selecting global temporary tables + formatting

Revision history for this message
Sergei Golubchik (sergii) wrote :
Download full text (17.6 KiB)

Hi, Venu!

On Feb 23, Venu Anuganti wrote:
> Venu Anuganti has proposed merging lp:~mydb08/maria/maria-5.1 into lp:maria.
>
> Requested reviews:
> Maria-captains (maria-captains)
>
> Initial SHOW [GLOBAL] TEMPORARY TABLES [FROM/IN db] implementation
> along with associated Information Schema tables.

And immediately a question - should there be a "SHOW TEMPORARY TABLES"
command or temporary tables should simply be shown in SHOW TABLES ?

Right, one cannot do a SHOW GLOBAL TEMPORARY TABLES this way,
but perhaps we don't need it ?

[later addition: you have problems with your SHOW GLOBAL TEMPORARY
TABLES implementation, I'm not sure it can be made to work. If it cannot
and you remove it completely, then putting all temporary tables in SHOW
TABLES is a viable solution. see below]

> Its been a while (probably 6 yrs+) I pushed any code to MySQL, so
> review is a must even though am working actively on MySQL code for
> last few years for developing storage engines.

don't worry :)

> - ACL check on global temp tables, need an advice on what priv to use

PROCESS ?

> Questions:
>
> Do we need to expose internal temp tables to this implementation ? I
> don't see any benefit doing so as it should be really part of slow
> query implementation.

No, we do not.

The detailed review follows:

> === added file 'mysql-test/t/show_temp_tables.test'
> --- mysql-test/t/show_temp_tables.test 1970-01-01 00:00:00 +0000
> +++ mysql-test/t/show_temp_tables.test 2010-03-17 05:39:27 +0000
> @@ -0,0 +1,64 @@
> +# Uses GRANT commands that usually disabled in embedded server
> +-- source include/not_embedded.inc

1. I don't see where you use GRANT command in this test.
2. Even if you did, you would need to test that SHOW TEMPORARY TABLES
works in embedded. But as you don't use GRANT, you can simply remove
include/not_embedded.inc

> +
> +# Save the initial number of concurrent sessions
> +--source include/count_sessions.inc

there are no concurrent sessions here, where can they come from ?
no need to include/count_sessions.inc

> +
> +#
> +# Test of SHOW [GLOBAL] TEMPORARY TABLES [FROM/IN] DB and
> +# Information_schema.temporary_tables and global_temporary_tables
> +#
> +
> +connect(stcon1,localhost,root,,test);
> +connect(stcon2,localhost,root,,test);
> +
> +connection stcon1;
> +
> +--disable_warnings
> +drop table if exists t1,t2,t3;
> +drop database if exists showtemp;
> +create database if not exists showtemp;

use mysqltest1 database name

> +--enable_warnings
> +
> +use test;
> +create temporary table t1(id int);
> +create temporary table t2(id int);
> +create temporary table showtemp.t3(id int);
> +insert into t1 values(10),(20),(30),(40);
> +insert into showtemp.t3 values(999);
> +
> +show temporary tables;
> +show global temporary tables;
> +show temporary tables from test;
> +show temporary tables in showtemp;
> +select table_schema, table_name, engine, table_rows from Information_schema.temporary_tables;
> +select table_schema, table_name, engine, table_rows from Information_schema.global_temporary_tables;
> +select table_schema, table_name, engine, table_rows from Information_schema.global_temporary_tables where table_schema='showtemp';
> +s...

Unmerged revisions

2825. By Venu Anuganti

add ACL check on DB names when selecting global temporary tables + formatting

2824. By Venu Anuganti

merge changes

2823. By Venu Anuganti

added a test case for show temp tables

2822. By Venu Anuganti

initial show temp tables implementation

2821. By Sergei Golubchik

fix for a possible DoS in the my_net_skip_rest()

2820. By Michael Widenius

Fixed LP#524679: make test ORDER BY date_ord ASC
(Problem was missing time_zone setting)

2819. By Sergey Petrunia

LPBUG#523593: Merge

2818. By Hakan Küçükyılmaz

Increased loop counts of sql-bench tests to get run times around
5 minutes on current machines. Tested on a Xeon machine and a new dual core laptop.

2817. By Michael Widenius

Fix for LPBUG#516148 Test maria.maria3 fails when --without-maria-tmp-tables is set

2816. By Michael Widenius

Fix for LPBug#520243: useability bug of thread pool configuration
Now mysqld --help --verbose shows the value for thread-handling
Fixed also that mysqld --one-thread works as expected.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'mysql-test/r/show_temp_tables.result'
2--- mysql-test/r/show_temp_tables.result 1970-01-01 00:00:00 +0000
3+++ mysql-test/r/show_temp_tables.result 2010-03-17 05:39:27 +0000
4@@ -0,0 +1,62 @@
5+drop table if exists t1,t2,t3;
6+drop database if exists showtemp;
7+create database if not exists showtemp;
8+use test;
9+create temporary table t1(id int);
10+create temporary table t2(id int);
11+create temporary table showtemp.t3(id int);
12+insert into t1 values(10),(20),(30),(40);
13+insert into showtemp.t3 values(999);
14+show temporary tables;
15+Temp_tables_in_test
16+t2
17+t1
18+show global temporary tables;
19+Session Temp_tables_in_test
20+3 t2
21+3 t1
22+show temporary tables from test;
23+Temp_tables_in_test
24+t2
25+t1
26+show temporary tables in showtemp;
27+Temp_tables_in_showtemp
28+t3
29+select table_schema, table_name, engine, table_rows from Information_schema.temporary_tables;
30+table_schema table_name engine table_rows
31+showtemp t3 MyISAM 1
32+test t2 MyISAM 0
33+test t1 MyISAM 4
34+select table_schema, table_name, engine, table_rows from Information_schema.global_temporary_tables;
35+table_schema table_name engine table_rows
36+showtemp t3 MyISAM 1
37+test t2 MyISAM 0
38+test t1 MyISAM 4
39+select table_schema, table_name, engine, table_rows from Information_schema.global_temporary_tables where table_schema='showtemp';
40+table_schema table_name engine table_rows
41+showtemp t3 MyISAM 1
42+select table_schema, table_name, engine, table_rows from Information_schema.global_temporary_tables where table_schema='temp';
43+table_schema table_name engine table_rows
44+drop table if exists showtemp.t2;
45+create temporary table t1(id int);
46+create temporary table showtemp.t2(id int);
47+show temporary tables;
48+Temp_tables_in_test
49+t1
50+select table_schema, table_name, engine, table_rows from Information_schema.global_temporary_tables;
51+table_schema table_name engine table_rows
52+showtemp t2 MyISAM 0
53+test t1 MyISAM 0
54+showtemp t3 MyISAM 1
55+test t2 MyISAM 0
56+test t1 MyISAM 4
57+drop table showtemp.t2;
58+drop table t1;
59+select table_schema, table_name, engine, table_rows from Information_schema.global_temporary_tables;
60+table_schema table_name engine table_rows
61+showtemp t3 MyISAM 1
62+test t2 MyISAM 0
63+test t1 MyISAM 4
64+drop table t1, t2;
65+drop table showtemp.t3;
66+drop database showtemp;
67
68=== added file 'mysql-test/t/show_temp_tables.test'
69--- mysql-test/t/show_temp_tables.test 1970-01-01 00:00:00 +0000
70+++ mysql-test/t/show_temp_tables.test 2010-03-17 05:39:27 +0000
71@@ -0,0 +1,64 @@
72+# Uses GRANT commands that usually disabled in embedded server
73+-- source include/not_embedded.inc
74+
75+# Save the initial number of concurrent sessions
76+--source include/count_sessions.inc
77+
78+#
79+# Test of SHOW [GLOBAL] TEMPORARY TABLES [FROM/IN] DB and
80+# Information_schema.temporary_tables and global_temporary_tables
81+#
82+
83+connect(stcon1,localhost,root,,test);
84+connect(stcon2,localhost,root,,test);
85+
86+connection stcon1;
87+
88+--disable_warnings
89+drop table if exists t1,t2,t3;
90+drop database if exists showtemp;
91+create database if not exists showtemp;
92+--enable_warnings
93+
94+use test;
95+create temporary table t1(id int);
96+create temporary table t2(id int);
97+create temporary table showtemp.t3(id int);
98+insert into t1 values(10),(20),(30),(40);
99+insert into showtemp.t3 values(999);
100+
101+show temporary tables;
102+show global temporary tables;
103+show temporary tables from test;
104+show temporary tables in showtemp;
105+select table_schema, table_name, engine, table_rows from Information_schema.temporary_tables;
106+select table_schema, table_name, engine, table_rows from Information_schema.global_temporary_tables;
107+select table_schema, table_name, engine, table_rows from Information_schema.global_temporary_tables where table_schema='showtemp';
108+select table_schema, table_name, engine, table_rows from Information_schema.global_temporary_tables where table_schema='temp';
109+
110+connection stcon2;
111+
112+--disable_warnings
113+drop table if exists showtemp.t2;
114+--enable_warnings
115+create temporary table t1(id int);
116+create temporary table showtemp.t2(id int);
117+show temporary tables;
118+select table_schema, table_name, engine, table_rows from Information_schema.global_temporary_tables;
119+drop table showtemp.t2;
120+drop table t1;
121+
122+disconnect stcon2;
123+
124+connection stcon1;
125+select table_schema, table_name, engine, table_rows from Information_schema.global_temporary_tables;
126+
127+drop table t1, t2;
128+drop table showtemp.t3;
129+drop database showtemp;
130+
131+connection default;
132+disconnect stcon1;
133+
134+# Wait till all disconnects are completed
135+--source include/wait_until_count_sessions.inc
136
137=== modified file 'sql/mysqld.cc'
138--- sql/mysqld.cc 2010-03-10 09:12:23 +0000
139+++ sql/mysqld.cc 2010-03-17 05:39:27 +0000
140@@ -3271,6 +3271,7 @@
141 {"show_storage_engines", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_STORAGE_ENGINES]), SHOW_LONG_STATUS},
142 {"show_table_status", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_TABLE_STATUS]), SHOW_LONG_STATUS},
143 {"show_tables", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_TABLES]), SHOW_LONG_STATUS},
144+ {"show_temporary_tables",(char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_TEMPORARY_TABLES]), SHOW_LONG_STATUS},
145 {"show_triggers", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_TRIGGERS]), SHOW_LONG_STATUS},
146 {"show_variables", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_VARIABLES]), SHOW_LONG_STATUS},
147 {"show_warnings", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_WARNS]), SHOW_LONG_STATUS},
148
149=== modified file 'sql/sql_lex.h'
150--- sql/sql_lex.h 2010-03-04 08:03:07 +0000
151+++ sql/sql_lex.h 2010-03-17 05:39:27 +0000
152@@ -67,7 +67,7 @@
153 SQLCOM_UPDATE, SQLCOM_INSERT, SQLCOM_INSERT_SELECT,
154 SQLCOM_DELETE, SQLCOM_TRUNCATE, SQLCOM_DROP_TABLE, SQLCOM_DROP_INDEX,
155
156- SQLCOM_SHOW_DATABASES, SQLCOM_SHOW_TABLES, SQLCOM_SHOW_FIELDS,
157+ SQLCOM_SHOW_DATABASES, SQLCOM_SHOW_TABLES, SQLCOM_SHOW_TEMPORARY_TABLES, SQLCOM_SHOW_FIELDS,
158 SQLCOM_SHOW_KEYS, SQLCOM_SHOW_VARIABLES, SQLCOM_SHOW_STATUS,
159 SQLCOM_SHOW_ENGINE_LOGS, SQLCOM_SHOW_ENGINE_STATUS, SQLCOM_SHOW_ENGINE_MUTEX,
160 SQLCOM_SHOW_PROCESSLIST, SQLCOM_SHOW_MASTER_STAT, SQLCOM_SHOW_SLAVE_STAT,
161
162=== modified file 'sql/sql_parse.cc'
163--- sql/sql_parse.cc 2010-03-04 08:03:07 +0000
164+++ sql/sql_parse.cc 2010-03-17 05:39:27 +0000
165@@ -342,6 +342,9 @@
166 sql_command_flags[SQLCOM_SHOW_TABLES]= (CF_STATUS_COMMAND |
167 CF_SHOW_TABLE_COMMAND |
168 CF_REEXECUTION_FRAGILE);
169+ sql_command_flags[SQLCOM_SHOW_TEMPORARY_TABLES]= (CF_STATUS_COMMAND |
170+ CF_SHOW_TABLE_COMMAND |
171+ CF_REEXECUTION_FRAGILE);
172 sql_command_flags[SQLCOM_SHOW_TABLE_STATUS]= (CF_STATUS_COMMAND |
173 CF_SHOW_TABLE_COMMAND |
174 CF_REEXECUTION_FRAGILE);
175@@ -1776,6 +1779,8 @@
176
177 case SCH_TABLE_NAMES:
178 case SCH_TABLES:
179+ case SCH_TEMPORARY_TABLES:
180+ case SCH_GLOBAL_TEMPORARY_TABLES:
181 case SCH_VIEWS:
182 case SCH_TRIGGERS:
183 case SCH_EVENTS:
184@@ -2264,6 +2269,7 @@
185 }
186 case SQLCOM_SHOW_DATABASES:
187 case SQLCOM_SHOW_TABLES:
188+ case SQLCOM_SHOW_TEMPORARY_TABLES:
189 case SQLCOM_SHOW_TRIGGERS:
190 case SQLCOM_SHOW_TABLE_STATUS:
191 case SQLCOM_SHOW_OPEN_TABLES:
192@@ -5355,6 +5361,8 @@
193
194 case SCH_TABLE_NAMES:
195 case SCH_TABLES:
196+ case SCH_TEMPORARY_TABLES:
197+ case SCH_GLOBAL_TEMPORARY_TABLES:
198 case SCH_VIEWS:
199 case SCH_TRIGGERS:
200 case SCH_EVENTS:
201
202=== modified file 'sql/sql_show.cc'
203--- sql/sql_show.cc 2010-03-04 08:03:07 +0000
204+++ sql/sql_show.cc 2010-03-17 05:39:27 +0000
205@@ -2715,6 +2715,7 @@
206 return 0;
207 case SQLCOM_SHOW_TABLES:
208 case SQLCOM_SHOW_TABLE_STATUS:
209+ case SQLCOM_SHOW_TEMPORARY_TABLES:
210 case SQLCOM_SHOW_TRIGGERS:
211 case SQLCOM_SHOW_EVENTS:
212 lookup_field_values->db_value.str= lex->select_lex.db;
213@@ -3170,6 +3171,228 @@
214 return (uint) OPEN_FULL_TABLE;
215 }
216
217+/**
218+ @brief Change I_S table item list for SHOW [GLOBAL] TEMPORARY TABLES [FROM/IN db]
219+
220+ @param[in] thd thread handler
221+ @param[in] schema_table I_S table
222+
223+ @return Operation status
224+ @retval 0 success
225+ @retval 1 error
226+*/
227+int make_temporary_tables_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
228+{
229+ char tmp[128];
230+ String buffer(tmp,sizeof(tmp), thd->charset());
231+ LEX *lex= thd->lex;
232+ Name_resolution_context *context= &lex->select_lex.context;
233+
234+ if (thd->lex->option_type == OPT_GLOBAL) {
235+ ST_FIELD_INFO *field_info= &schema_table->fields_info[0];
236+ Item_field *field= new Item_field(context, NullS, NullS, field_info->field_name);
237+ if (add_item_to_list(thd, field))
238+ return 1;
239+ field->set_name(field_info->old_name, strlen(field_info->old_name), system_charset_info);
240+ }
241+
242+ ST_FIELD_INFO *field_info= &schema_table->fields_info[2];
243+ buffer.length(0);
244+ buffer.append(field_info->old_name);
245+ buffer.append(lex->select_lex.db);
246+
247+ if (lex->wild && lex->wild->ptr())
248+ {
249+ buffer.append(STRING_WITH_LEN(" ("));
250+ buffer.append(lex->wild->ptr());
251+ buffer.append(')');
252+ }
253+
254+ Item_field *field= new Item_field(context, NullS, NullS, field_info->field_name);
255+ if (add_item_to_list(thd, field))
256+ return 1;
257+
258+ field->set_name(buffer.ptr(), buffer.length(), system_charset_info);
259+ return 0;
260+}
261+
262+/**
263+ @brief Fill records for temporary tables by reading info from table object
264+
265+ @param[in] thd thread handler
266+ @param[in] table I_S table
267+ @param[in] tmp_table temporary table
268+ @param[in] db database name
269+
270+ @return Operation status
271+ @retval 0 success
272+ @retval 1 error
273+*/
274+
275+static int store_temporary_table_record(THD *thd, TABLE *table, TABLE *tmp_table, const char *db, bool table_name_only)
276+{
277+ CHARSET_INFO *cs= system_charset_info;
278+ DBUG_ENTER("store_temporary_table_record");
279+
280+ if (db && my_strcasecmp(cs, db, tmp_table->s->db.str))
281+ DBUG_RETURN(0);
282+
283+ restore_record(table, s->default_values);
284+
285+ //session_id
286+ table->field[0]->store((longlong) thd->thread_id, TRUE);
287+
288+ //database
289+ table->field[1]->store(tmp_table->s->db.str, tmp_table->s->db.length, cs);
290+
291+ //table
292+ table->field[2]->store(tmp_table->s->table_name.str, tmp_table->s->table_name.length, cs);
293+
294+ if (table_name_only)
295+ DBUG_RETURN(schema_table_store_record(thd, table));
296+
297+ //engine
298+ handler *handle= tmp_table->file;
299+ char *engineType = (char *)(handle ? handle->table_type() : "UNKNOWN");
300+ table->field[3]->store(engineType, strlen(engineType), cs);
301+
302+ //name
303+ if (tmp_table->s->path.str) {
304+ char *p=strstr(tmp_table->s->path.str, "#sql");
305+ int len=tmp_table->s->path.length-(p-tmp_table->s->path.str);
306+ table->field[4]->store(p, min(FN_REFLEN, len), cs);
307+ }
308+
309+ // file stats
310+ handler *file= tmp_table->file;
311+
312+ if (file) {
313+
314+ MYSQL_TIME time;
315+
316+ /**
317+ TODO: InnoDB stat(file) checks file on short names within data dictionary
318+ rather than using full path, because of that, temp files created in
319+ TMPDIR will not have access/create time as it will not find the file
320+
321+ The fix is to patch InnoDB to use full path
322+ */
323+ file->info(HA_STATUS_VARIABLE | HA_STATUS_TIME | HA_STATUS_NO_LOCK);
324+
325+ table->field[5]->store((longlong) file->stats.records, TRUE);
326+ table->field[5]->set_notnull();
327+
328+ table->field[6]->store((longlong) file->stats.mean_rec_length, TRUE);
329+ table->field[7]->store((longlong) file->stats.data_file_length, TRUE);
330+ table->field[8]->store((longlong) file->stats.index_file_length, TRUE);
331+ if (file->stats.create_time)
332+ {
333+ thd->variables.time_zone->gmt_sec_to_TIME(&time,
334+ (my_time_t) file->stats.create_time);
335+ table->field[9]->store_time(&time, MYSQL_TIMESTAMP_DATETIME);
336+ table->field[9]->set_notnull();
337+ }
338+ if (file->stats.update_time)
339+ {
340+ thd->variables.time_zone->gmt_sec_to_TIME(&time,
341+ (my_time_t) file->stats.update_time);
342+ table->field[10]->store_time(&time, MYSQL_TIMESTAMP_DATETIME);
343+ table->field[10]->set_notnull();
344+ }
345+ }
346+
347+ DBUG_RETURN(schema_table_store_record(thd, table));
348+}
349+
350+/**
351+ @brief Fill I_S tables with global temporary tables
352+
353+ @param[in] thd thread handler
354+ @param[in] tables I_S table
355+ @param[in] cond 'WHERE' condition
356+
357+ @return Operation status
358+ @retval 0 success
359+ @retval 1 error
360+*/
361+
362+static int fill_global_temporary_tables(THD *thd, TABLE_LIST *tables, COND *cond)
363+{
364+ DBUG_ENTER("fill_global_temporary_tables");
365+
366+ pthread_mutex_lock(&LOCK_thread_count);
367+
368+ bool table_names_only= (thd->lex->sql_command == SQLCOM_SHOW_TEMPORARY_TABLES) ? 1 : 0;
369+ I_List_iterator<THD> it(threads);
370+ THD *thd_item;
371+ TABLE *tmp;
372+
373+#ifndef NO_EMBEDDED_ACCESS_CHECKS
374+ Security_context *sctx= thd->security_ctx;
375+ uint db_access;
376+#endif
377+
378+ while ((thd_item=it++)) {
379+ for (tmp=thd_item->temporary_tables; tmp; tmp=tmp->next) {
380+
381+#ifndef NO_EMBEDDED_ACCESS_CHECKS
382+ if (test_all_bits(sctx->master_access, DB_ACLS))
383+ db_access=DB_ACLS;
384+ else
385+ db_access= (acl_get(sctx->host, sctx->ip, sctx->priv_user, tmp->s->db.str, 0) | sctx->master_access);
386+
387+ if (!(db_access & DB_ACLS) && check_grant_db(thd,tmp->s->db.str)) {
388+ //no access for temp tables within this db for user
389+ continue;
390+ }
391+#endif
392+
393+ THD *t= tmp->in_use;
394+ tmp->in_use= thd;
395+
396+ if (store_temporary_table_record(thd_item, tables->table, tmp, thd->lex->select_lex.db, table_names_only)) {
397+ tmp->in_use= t;
398+ pthread_mutex_unlock(&LOCK_thread_count);
399+ DBUG_RETURN(1);
400+ }
401+
402+ tmp->in_use= t;
403+ }
404+ }
405+
406+ pthread_mutex_unlock(&LOCK_thread_count);
407+ DBUG_RETURN(0);
408+}
409+
410+/**
411+ @brief Fill I_S tables with session temporary tables
412+
413+ @param[in] thd thread handler
414+ @param[in] tables I_S table
415+ @param[in] cond 'WHERE' condition
416+
417+ @return Operation status
418+ @retval 0 success
419+ @retval 1 error
420+*/
421+
422+int fill_temporary_tables(THD *thd, TABLE_LIST *tables, COND *cond)
423+{
424+ DBUG_ENTER("fill_temporary_tables");
425+
426+ if (thd->lex->option_type == OPT_GLOBAL)
427+ DBUG_RETURN(fill_global_temporary_tables(thd, tables, cond));
428+
429+ bool table_names_only= (thd->lex->sql_command == SQLCOM_SHOW_TEMPORARY_TABLES) ? 1 : 0;
430+ TABLE *tmp;
431+
432+ for (tmp=thd->temporary_tables; tmp; tmp=tmp->next) {
433+ if (store_temporary_table_record(thd, tables->table, tmp, thd->lex->select_lex.db, table_names_only)) {
434+ DBUG_RETURN(1);
435+ }
436+ }
437+ DBUG_RETURN(0);
438+}
439
440 /**
441 @brief Fill I_S table with data from FRM file only
442@@ -6258,6 +6481,25 @@
443 {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE}
444 };
445
446+ST_FIELD_INFO temporary_table_fields_info[]=
447+{
448+ {"SESSION_ID", 4, MYSQL_TYPE_LONGLONG, 0, 0, "Session", SKIP_OPEN_TABLE},
449+ {"TABLE_SCHEMA", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, "Db", SKIP_OPEN_TABLE},
450+ {"TABLE_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, "Temp_tables_in_", SKIP_OPEN_TABLE},
451+ {"ENGINE", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, "Engine", OPEN_FRM_ONLY},
452+ {"NAME", FN_REFLEN, MYSQL_TYPE_STRING, 0, 0, "Name", SKIP_OPEN_TABLE},
453+ {"TABLE_ROWS", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0,
454+ MY_I_S_UNSIGNED, "Rows", OPEN_FULL_TABLE},
455+ {"AVG_ROW_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0,
456+ MY_I_S_UNSIGNED, "Avg Row", OPEN_FULL_TABLE},
457+ {"DATA_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0,
458+ MY_I_S_UNSIGNED, "Data Length", OPEN_FULL_TABLE},
459+ {"INDEX_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0,
460+ MY_I_S_UNSIGNED, "Index Size", OPEN_FULL_TABLE},
461+ {"CREATE_TIME", 0, MYSQL_TYPE_DATETIME, 0, 1, "Create Time", OPEN_FULL_TABLE},
462+ {"UPDATE_TIME", 0, MYSQL_TYPE_DATETIME, 0, 1, "Update Time", OPEN_FULL_TABLE},
463+ {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE}
464+};
465
466 ST_FIELD_INFO columns_fields_info[]=
467 {
468@@ -6816,6 +7058,9 @@
469 fill_schema_files, 0, 0, -1, -1, 0, 0},
470 {"GLOBAL_STATUS", variables_fields_info, create_schema_table,
471 fill_status, make_old_format, 0, 0, -1, 0, 0},
472+ {"GLOBAL_TEMPORARY_TABLES", temporary_table_fields_info, create_schema_table,
473+ fill_global_temporary_tables, make_temporary_tables_old_format, 0, 2, 3, 0,
474+ OPEN_TABLE_ONLY|OPTIMIZE_I_S_TABLE},
475 {"GLOBAL_VARIABLES", variables_fields_info, create_schema_table,
476 fill_variables, make_old_format, 0, 0, -1, 0, 0},
477 {"KEY_COLUMN_USAGE", key_column_usage_fields_info, create_schema_table,
478@@ -6859,6 +7104,9 @@
479 get_all_tables, make_table_names_old_format, 0, 1, 2, 1, 0},
480 {"TABLE_PRIVILEGES", table_privileges_fields_info, create_schema_table,
481 fill_schema_table_privileges, 0, 0, -1, -1, 0, 0},
482+ {"TEMPORARY_TABLES", temporary_table_fields_info, create_schema_table,
483+ fill_temporary_tables, make_temporary_tables_old_format, 0, 2, 3, 0,
484+ OPEN_TABLE_ONLY|OPTIMIZE_I_S_TABLE},
485 {"TRIGGERS", triggers_fields_info, create_schema_table,
486 get_all_tables, make_old_format, get_schema_triggers_record, 5, 6, 0,
487 OPEN_TABLE_ONLY},
488
489=== modified file 'sql/sql_yacc.yy'
490--- sql/sql_yacc.yy 2010-03-04 08:03:07 +0000
491+++ sql/sql_yacc.yy 2010-03-17 05:39:27 +0000
492@@ -10088,6 +10088,15 @@
493 if (prepare_schema_table(YYTHD, lex, 0, SCH_TABLE_NAMES))
494 MYSQL_YYABORT;
495 }
496+ | opt_var_type TEMPORARY TABLES opt_db
497+ {
498+ LEX *lex= Lex;
499+ lex->sql_command= SQLCOM_SHOW_TEMPORARY_TABLES;
500+ lex->option_type= $1;
501+ lex->select_lex.db= $4;
502+ if (prepare_schema_table(YYTHD, lex, 0, SCH_TEMPORARY_TABLES))
503+ MYSQL_YYABORT;
504+ }
505 | opt_full TRIGGERS_SYM opt_db wild_and_where
506 {
507 LEX *lex= Lex;
508
509=== modified file 'sql/table.h'
510--- sql/table.h 2010-02-10 19:06:24 +0000
511+++ sql/table.h 2010-03-17 05:39:27 +0000
512@@ -942,6 +942,7 @@
513 SCH_FILES,
514 SCH_GLOBAL_STATUS,
515 SCH_GLOBAL_VARIABLES,
516+ SCH_GLOBAL_TEMPORARY_TABLES,
517 SCH_KEY_COLUMN_USAGE,
518 SCH_OPEN_TABLES,
519 SCH_PARTITIONS,
520@@ -960,6 +961,7 @@
521 SCH_TABLE_CONSTRAINTS,
522 SCH_TABLE_NAMES,
523 SCH_TABLE_PRIVILEGES,
524+ SCH_TEMPORARY_TABLES,
525 SCH_TRIGGERS,
526 SCH_USER_PRIVILEGES,
527 SCH_VARIABLES,

Subscribers

People subscribed via source and target branches