summaryrefslogtreecommitdiff
blob: a56ae9ae78b113b86ef3e47e5b34a08ce8e48ffc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
diff -r fe944d2c6e1f innobase/btr/btr0btr.c
--- a/innobase/btr/btr0btr.c	Mon Nov 10 19:47:27 2008 -0800
+++ b/innobase/btr/btr0btr.c	Mon Nov 10 19:48:24 2008 -0800
@@ -2989,3 +2989,11 @@
 
 	return(TRUE);
 }
+
+dulint
+btr_page_get_index_id_noninline(
+/*============*/
+        page_t* page)  /* in: index page */
+{
+  return btr_page_get_index_id(page);
+}
diff -r fe944d2c6e1f innobase/buf/buf0buf.c
--- a/innobase/buf/buf0buf.c	Mon Nov 10 19:47:27 2008 -0800
+++ b/innobase/buf/buf0buf.c	Mon Nov 10 19:48:24 2008 -0800
@@ -2629,3 +2629,13 @@
 	buf_block_print(block);
 }
 
+buf_block_t*
+buf_pool_get_nth_block_no_inline(
+/*===================*/
+                                /* out: pointer to block */
+        buf_pool_t*     buf_pool,/* in: buf_pool */
+        ulint           i)      /* in: index of the block */{
+
+return buf_pool_get_nth_block(buf_pool, i);
+
+}
diff -r fe944d2c6e1f innobase/include/btr0btr.h
--- a/innobase/include/btr0btr.h	Mon Nov 10 19:47:27 2008 -0800
+++ b/innobase/include/btr0btr.h	Mon Nov 10 19:48:24 2008 -0800
@@ -69,6 +69,12 @@
 UNIV_INLINE
 dulint
 btr_page_get_index_id(
+/*==================*/
+				/* out: index id */
+	page_t*		page);	/* in: index page */
+
+dulint
+btr_page_get_index_id_noninline(
 /*==================*/
 				/* out: index id */
 	page_t*		page);	/* in: index page */
diff -r fe944d2c6e1f innobase/include/buf0buf.h
--- a/innobase/include/buf0buf.h	Mon Nov 10 19:47:27 2008 -0800
+++ b/innobase/include/buf0buf.h	Mon Nov 10 19:48:24 2008 -0800
@@ -703,6 +703,8 @@
 buf_get_free_list_len(void);
 /*=======================*/
 
+void buf_pool_dump(void);
+buf_block_t* buf_pool_get_nth_block_no_inline(buf_pool_t* pool, ulint i);  
 
 			
 /* The buffer control block structure */
diff -r fe944d2c6e1f innobase/include/page0page.h
--- a/innobase/include/page0page.h	Mon Nov 10 19:47:27 2008 -0800
+++ b/innobase/include/page0page.h	Mon Nov 10 19:48:24 2008 -0800
@@ -260,6 +260,12 @@
 /*============*/
 			/* out: number of user records */
 	page_t*	page);	/* in: index page */
+
+ulint
+page_get_n_recs_noninline(
+/*============*/
+			/* out: number of user records */
+	page_t*	page);	/* in: index page */
 /*******************************************************************
 Returns the number of records before the given record in chain.
 The number includes infimum and supremum records. */
@@ -519,6 +525,12 @@
 UNIV_INLINE
 ulint
 page_get_data_size(
+/*===============*/
+			/* out: data in bytes */
+	page_t*	page);	/* in: index page */
+
+ulint
+page_get_data_size_noninline(
 /*===============*/
 			/* out: data in bytes */
 	page_t*	page);	/* in: index page */
diff -r fe944d2c6e1f innobase/page/page0page.c
--- a/innobase/page/page0page.c	Mon Nov 10 19:47:27 2008 -0800
+++ b/innobase/page/page0page.c	Mon Nov 10 19:48:24 2008 -0800
@@ -1994,3 +1994,25 @@
 		page_cur_move_to_next(&cur);
 	}
 }
+
+ulint
+page_get_n_recs_noninline(
+/*============*/
+                        /* out: number of user records */
+        page_t* page)  /* in: index page */
+{
+ return page_get_n_recs(page);
+}
+
+
+ulint
+page_get_data_size_noninline(
+/*============*/
+                        /* out: number of user records */
+        page_t* page)  /* in: index page */
+{
+ return page_get_data_size(page);
+}
+
+
+
diff -r fe944d2c6e1f mysql-test/r/information_schema.result
--- a/mysql-test/r/information_schema.result	Mon Nov 10 19:47:27 2008 -0800
+++ b/mysql-test/r/information_schema.result	Mon Nov 10 19:48:25 2008 -0800
@@ -42,6 +42,7 @@
 COLLATION_CHARACTER_SET_APPLICABILITY
 COLUMNS
 COLUMN_PRIVILEGES
+INNODB_BUFFER_POOL_CONTENT
 INDEX_STATISTICS
 KEY_COLUMN_USAGE
 PROCESSLIST
@@ -741,7 +742,7 @@
 CREATE VIEW a1 (t_CRASHME) AS SELECT f1 FROM t_crashme GROUP BY f1;
 CREATE VIEW a2 AS SELECT t_CRASHME FROM a1;
 count(*)
-107
+108
 drop view a2, a1;
 drop table t_crashme;
 select table_schema,table_name, column_name from
@@ -802,6 +803,7 @@
 TABLE_NAME	COLUMN_NAME	PRIVILEGES
 COLUMNS	TABLE_NAME	select
 COLUMN_PRIVILEGES	TABLE_NAME	select
+INNODB_BUFFER_POOL_CONTENT	TABLE_NAME	select
 INDEX_STATISTICS	TABLE_NAME	select
 KEY_COLUMN_USAGE	TABLE_NAME	select
 STATISTICS	TABLE_NAME	select
@@ -815,7 +817,7 @@
 flush privileges;
 SELECT table_schema, count(*) FROM information_schema.TABLES GROUP BY TABLE_SCHEMA;
 table_schema	count(*)
-information_schema	22
+information_schema	23
 mysql	17
 create table t1 (i int, j int);
 create trigger trg1 before insert on t1 for each row
@@ -1206,6 +1208,7 @@
 COLLATION_CHARACTER_SET_APPLICABILITY	COLLATION_NAME
 COLUMNS	TABLE_SCHEMA
 COLUMN_PRIVILEGES	TABLE_SCHEMA
+INNODB_BUFFER_POOL_CONTENT	TABLE_SCHEMA
 INDEX_STATISTICS	TABLE_SCHEMA
 KEY_COLUMN_USAGE	CONSTRAINT_SCHEMA
 PROCESSLIST	ID
@@ -1243,6 +1246,7 @@
 COLLATION_CHARACTER_SET_APPLICABILITY	COLLATION_NAME
 COLUMNS	TABLE_SCHEMA
 COLUMN_PRIVILEGES	TABLE_SCHEMA
+INNODB_BUFFER_POOL_CONTENT	TABLE_SCHEMA
 INDEX_STATISTICS	TABLE_SCHEMA
 KEY_COLUMN_USAGE	CONSTRAINT_SCHEMA
 PROCESSLIST	ID
@@ -1332,6 +1336,7 @@
 COLUMNS	information_schema.COLUMNS	1
 COLUMN_PRIVILEGES	information_schema.COLUMN_PRIVILEGES	1
 INDEX_STATISTICS	information_schema.INDEX_STATISTICS	1
+INNODB_BUFFER_POOL_CONTENT	information_schema.INNODB_BUFFER_POOL_CONTENT	1
 KEY_COLUMN_USAGE	information_schema.KEY_COLUMN_USAGE	1
 PROCESSLIST	information_schema.PROCESSLIST	1
 PROFILING	information_schema.PROFILING	1
diff -r fe944d2c6e1f mysql-test/r/information_schema_db.result
--- a/mysql-test/r/information_schema_db.result	Mon Nov 10 19:47:27 2008 -0800
+++ b/mysql-test/r/information_schema_db.result	Mon Nov 10 19:48:25 2008 -0800
@@ -11,6 +11,7 @@
 COLLATION_CHARACTER_SET_APPLICABILITY
 COLUMNS
 COLUMN_PRIVILEGES
+INNODB_BUFFER_POOL_CONTENT
 INDEX_STATISTICS
 KEY_COLUMN_USAGE
 PROCESSLIST
diff -r fe944d2c6e1f mysql-test/r/mysqlshow.result
--- a/mysql-test/r/mysqlshow.result	Mon Nov 10 19:47:27 2008 -0800
+++ b/mysql-test/r/mysqlshow.result	Mon Nov 10 19:48:25 2008 -0800
@@ -85,6 +85,7 @@
 | COLLATION_CHARACTER_SET_APPLICABILITY |
 | COLUMNS                               |
 | COLUMN_PRIVILEGES                     |
+| INNODB_BUFFER_POOL_CONTENT            |
 | INDEX_STATISTICS                      |
 | KEY_COLUMN_USAGE                      |
 | PROCESSLIST                           |
@@ -112,6 +113,7 @@
 | COLLATION_CHARACTER_SET_APPLICABILITY |
 | COLUMNS                               |
 | COLUMN_PRIVILEGES                     |
+| INNODB_BUFFER_POOL_CONTENT            |
 | INDEX_STATISTICS                      |
 | KEY_COLUMN_USAGE                      |
 | PROCESSLIST                           |
diff -r fe944d2c6e1f patch_info/innodb_show_bp.info
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/patch_info/innodb_show_bp.info	Mon Nov 10 19:48:25 2008 -0800
@@ -0,0 +1,6 @@
+File=innodb_show_bp.patch
+Name=show innodb buffer pool content
+Version=1.0
+Author=Percona <info@percona.com>
+License=GPL
+Comment=
diff -r fe944d2c6e1f sql/ha_innodb.cc
--- a/sql/ha_innodb.cc	Mon Nov 10 19:47:27 2008 -0800
+++ b/sql/ha_innodb.cc	Mon Nov 10 19:48:25 2008 -0800
@@ -128,10 +128,12 @@
 #include "../innobase/include/lock0lock.h"
 #include "../innobase/include/dict0crea.h"
 #include "../innobase/include/btr0cur.h"
+#include "../innobase/include/buf0buf.h"
 #include "../innobase/include/btr0btr.h"
 #include "../innobase/include/fsp0fsp.h"
 #include "../innobase/include/sync0sync.h"
 #include "../innobase/include/fil0fil.h"
+#include "../innobase/include/page0page.h"
 #include "../innobase/include/trx0xa.h"
 }
 
@@ -6483,6 +6485,116 @@
   	DBUG_RETURN(FALSE);
 }
 
+bool
+innodb_I_S_buffer_pool_content(THD* thd, TABLE_LIST *tables)
+{
+	ulint		size;
+	ulint		i;
+	dulint		id;
+	ulint		n_found;
+	buf_frame_t* 	frame;
+	dict_index_t*	index;
+	buf_block_t*    block;
+
+	char *p;
+	char db_name_raw[NAME_LEN*5+1];
+	char table_name_raw[NAME_LEN*5+1];
+
+        DBUG_ENTER("innodb_I_S_buffer_pool_content");
+
+
+	size = buf_pool->curr_size;
+
+	n_found = 0;
+
+	TABLE *table= tables->table;
+
+
+	//buf_pool_dump();
+
+
+	for (i = 0; i < size; i++) {
+		block = buf_pool_get_nth_block_no_inline(buf_pool, i);
+		frame = block->frame;
+		if (fil_page_get_type(frame)==0) continue;
+
+		char page_type[64];
+
+		switch(fil_page_get_type(frame))
+		{
+			case FIL_PAGE_INDEX:
+				strcpy(page_type, "index");
+				break;
+			case FIL_PAGE_UNDO_LOG:
+				strcpy(page_type, "undo_log");
+				break;
+			case FIL_PAGE_INODE:
+				strcpy(page_type, "inode");
+				break;
+			case FIL_PAGE_IBUF_FREE_LIST:
+				strcpy(page_type, "ibuf_free_list");
+				break;
+			default:
+				sprintf(page_type, "unknown", fil_page_get_type(frame));
+		}
+
+		table->field[0]->store((longlong)i, TRUE);
+		table->field[1]->store((longlong)block->space, TRUE);
+		table->field[2]->store((longlong)block->offset, TRUE);
+		table->field[3]->store((longlong)page_get_n_recs_noninline(block->frame), TRUE);
+		table->field[4]->store( ( fil_page_get_type(frame) == FIL_PAGE_INDEX ) ?  (longlong)page_get_data_size_noninline(block->frame):0, TRUE);
+		table->field[5]->store((longlong)block->flush_type, TRUE);
+		table->field[6]->store((longlong)block->buf_fix_count, TRUE);
+		table->field[7]->store((longlong)block->LRU_position, TRUE);
+		table->field[8]->store((longlong)fil_page_get_type(frame), TRUE);
+
+		table->field[9]->store(page_type, strlen(page_type), system_charset_info);
+
+		//fprintf(stderr, "block N %d, space %d, offset %d, records %d, datasize %d, page_type %s, flush_type %d, buf_fix_count %d, LRU_position %d", i, block->space, block->offset, page_get_n_recs_noninline(block->frame), page_get_data_size_noninline(block->frame), page_type,block->flush_type, block->buf_fix_count, block->LRU_position);
+
+		// flush_type, buf_fix_count, LRU_position
+
+		if (fil_page_get_type(frame) == FIL_PAGE_INDEX) {
+
+			id = btr_page_get_index_id_noninline(frame);
+			index = dict_index_get_if_in_cache(id);
+			if (index) {
+				table->field[10]->store(index->name, strlen(index->name), system_charset_info);
+				// fprintf(stderr, " index %s, table %s", index->name, index->table_name);
+
+				if((p = strchr(index->table_name, '/')))
+				{
+					strncpy(db_name_raw, index->table_name, p-index->table_name);
+					db_name_raw[p-index->table_name] = 0;
+					table->field[11]->store(db_name_raw, strlen(db_name_raw), system_charset_info);
+					p++;            
+				} else {
+					table->field[11]->store(NULL, 0, system_charset_info);
+					p = (char *)index->table_name;
+				}
+				strcpy(table_name_raw, p);
+
+				table->field[12]->store(table_name_raw, strlen(table_name_raw), system_charset_info);
+			} else {
+				table->field[10]->store(NULL, 0, system_charset_info);
+				table->field[11]->store(NULL, 0, system_charset_info);
+				table->field[12]->store(NULL, 0, system_charset_info);
+			}
+		}else{
+			table->field[10]->store(NULL, 0, system_charset_info);
+			table->field[11]->store(NULL, 0, system_charset_info);
+			table->field[12]->store(NULL, 0, system_charset_info);
+		}
+		//fprintf(stderr, "\n");
+		if (schema_table_store_record(thd, table))
+		{
+			DBUG_RETURN(1);
+		}
+	}
+
+	DBUG_RETURN(0);
+}
+
 /****************************************************************************
 Implements the SHOW MUTEX STATUS command. . */
 
diff -r fe944d2c6e1f sql/ha_innodb.h
--- a/sql/ha_innodb.h	Mon Nov 10 19:47:27 2008 -0800
+++ b/sql/ha_innodb.h	Mon Nov 10 19:48:25 2008 -0800
@@ -263,6 +263,7 @@
 
 int innobase_drop_database(char *path);
 bool innodb_show_status(THD* thd);
+bool innodb_I_S_buffer_pool_content(THD* thd, TABLE_LIST *tables);
 bool innodb_mutex_show_status(THD* thd);
 void innodb_export_status(void);
 
diff -r fe944d2c6e1f sql/sql_parse.cc
--- a/sql/sql_parse.cc	Mon Nov 10 19:47:27 2008 -0800
+++ b/sql/sql_parse.cc	Mon Nov 10 19:48:25 2008 -0800
@@ -2926,6 +2926,7 @@
   case SCH_COLUMN_PRIVILEGES:
   case SCH_TABLE_CONSTRAINTS:
   case SCH_KEY_COLUMN_USAGE:
+  case SCH_INNODB_I_S_BUFFER_POOL_CONTENT:
   default:
     break;
   }
diff -r fe944d2c6e1f sql/sql_show.cc
--- a/sql/sql_show.cc	Mon Nov 10 19:47:27 2008 -0800
+++ b/sql/sql_show.cc	Mon Nov 10 19:48:25 2008 -0800
@@ -27,6 +27,10 @@
 
 #ifdef HAVE_BERKELEY_DB
 #include "ha_berkeley.h"			// For berkeley_show_logs
+#endif
+
+#ifdef HAVE_INNOBASE_DB
+#include "ha_innodb.h"
 #endif
 
 #ifndef NO_EMBEDDED_ACCESS_CHECKS
@@ -4042,6 +4046,13 @@
   DBUG_RETURN(res);
 }
 
+int fill_innodb_bp_content(THD *thd, TABLE_LIST *tables, COND *cond)
+{
+  DBUG_ENTER("fill_innodb_bp_content");
+  int res= 0;
+  innodb_I_S_buffer_pool_content(thd, tables);
+  DBUG_RETURN(res);
+}
 
 /*
   Find schema_tables elment by name
@@ -4951,6 +4962,24 @@
 };
 
 
+ST_FIELD_INFO innodb_bp_content_fields_info[]=
+{
+  {"BLOCK_NUM", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Block_num"},
+  {"SPACE", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Space"},
+  {"OFFSET", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Offset"},
+  {"RECORDS", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Records"},
+  {"DATASIZE", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Datasize"},
+  {"FLUSH_TYPE", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Flush_type"},
+  {"FIX_COUNT", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Fix_count"},
+  {"LRU_POSITION", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "LRU_position"},
+  {"PAGE_TYPE_ID", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Page_type_id"},
+  {"PAGE_TYPE", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, "Page_type"},
+  {"INDEX_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, "Index_name"},
+  {"TABLE_SCHEMA", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, "Table_schem"},
+  {"TABLE_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, "Table_name"},
+  {0, 0, MYSQL_TYPE_STRING, 0, 0, 0}
+};
+
 /*
   Description of ST_FIELD_INFO in table.h
 */
@@ -4969,6 +4998,8 @@
    get_all_tables, make_columns_old_format, get_schema_column_record, 1, 2, 0},
   {"COLUMN_PRIVILEGES", column_privileges_fields_info, create_schema_table,
     fill_schema_column_privileges, 0, 0, -1, -1, 0},
+  {"INNODB_BUFFER_POOL_CONTENT", innodb_bp_content_fields_info, create_schema_table,
+    fill_innodb_bp_content, 0, 0, -1, -1, 0},
   {"INDEX_STATISTICS", index_stats_fields_info, create_schema_table,
    fill_schema_index_stats, make_old_format, 0, -1, -1, 0},
   {"KEY_COLUMN_USAGE", key_column_usage_fields_info, create_schema_table,
diff -r fe944d2c6e1f sql/table.h
--- a/sql/table.h	Mon Nov 10 19:47:27 2008 -0800
+++ b/sql/table.h	Mon Nov 10 19:48:25 2008 -0800
@@ -375,6 +375,7 @@
   SCH_COLLATION_CHARACTER_SET_APPLICABILITY,
   SCH_COLUMNS,
   SCH_COLUMN_PRIVILEGES,
+  SCH_INNODB_I_S_BUFFER_POOL_CONTENT,
   SCH_INDEX_STATS,
   SCH_KEY_COLUMN_USAGE,
   SCH_OPEN_TABLES,