summaryrefslogtreecommitdiff
blob: 4b16731ee198929d824204d2d80739e436f5b969 (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
diff -r 936d427a9a15 innobase/btr/btr0cur.c
--- a/innobase/btr/btr0cur.c	Mon Dec 22 00:33:03 2008 -0800
+++ b/innobase/btr/btr0cur.c	Mon Dec 22 00:33:11 2008 -0800
@@ -516,6 +516,14 @@
 						== index->table->comp);
 			}
 
+			if (level == 0) {
+				/* Initializes status counters */
+				innobase_mysql_thd_init_innodb_scan_cont();
+				innobase_mysql_thd_init_innodb_scan_jump();
+				innobase_mysql_thd_init_innodb_scan_data();
+				innobase_mysql_thd_init_innodb_scan_garbage();
+			}
+
 			break;
 		}
 
@@ -663,6 +671,12 @@
 			        btr_cur_add_path_info(cursor, height,
 						      root_height);
 		        }
+
+			/* Initializes status counters */
+			innobase_mysql_thd_init_innodb_scan_cont();
+			innobase_mysql_thd_init_innodb_scan_jump();
+			innobase_mysql_thd_init_innodb_scan_data();
+			innobase_mysql_thd_init_innodb_scan_garbage();
 
 			break;
 		}
diff -r 936d427a9a15 innobase/btr/btr0pcur.c
--- a/innobase/btr/btr0pcur.c	Mon Dec 22 00:33:03 2008 -0800
+++ b/innobase/btr/btr0pcur.c	Mon Dec 22 00:33:11 2008 -0800
@@ -381,6 +381,7 @@
 				last record of the current page */
 	mtr_t*		mtr)	/* in: mtr */
 {
+	ulint	page_no;
 	ulint	next_page_no;
 	ulint	space;
 	page_t*	page;
@@ -393,11 +394,22 @@
 	cursor->old_stored = BTR_PCUR_OLD_NOT_STORED;
 	
 	page = btr_pcur_get_page(cursor);
+	page_no = buf_frame_get_page_no(page);
 
 	next_page_no = btr_page_get_next(page, mtr);
 	space = buf_frame_get_space_id(page);
 
 	ut_ad(next_page_no != FIL_NULL);	
+
+	if (next_page_no - page_no == 1) {
+		innobase_mysql_thd_increment_innodb_scan_cont(1);
+	} else {
+		innobase_mysql_thd_increment_innodb_scan_jump(1);
+	}
+	innobase_mysql_thd_increment_innodb_scan_data(
+				page_get_data_size(page));
+	innobase_mysql_thd_increment_innodb_scan_garbage(
+				page_header_get_field(page, PAGE_GARBAGE));
 
 	next_page = btr_page_get(space, next_page_no, cursor->latch_mode, mtr);
 	ut_a(page_is_comp(next_page) == page_is_comp(page));
@@ -427,6 +439,7 @@
 				record of the current page */
 	mtr_t*		mtr)	/* in: mtr */
 {
+	ulint	page_no;
 	ulint	prev_page_no;
 	ulint	space;
 	page_t*	page;
@@ -462,9 +475,20 @@
 	btr_pcur_restore_position(latch_mode2, cursor, mtr);	
 
 	page = btr_pcur_get_page(cursor);
+	page_no = buf_frame_get_page_no(page);
 
 	prev_page_no = btr_page_get_prev(page, mtr);
 	space = buf_frame_get_space_id(page);
+
+	if (page_no - prev_page_no == 1) {
+		innobase_mysql_thd_increment_innodb_scan_cont(1);
+	} else {
+		innobase_mysql_thd_increment_innodb_scan_jump(1);
+	}
+	innobase_mysql_thd_increment_innodb_scan_data(
+				page_get_data_size(page));
+	innobase_mysql_thd_increment_innodb_scan_garbage(
+				page_header_get_field(page, PAGE_GARBAGE));
 
 	if (btr_pcur_is_before_first_on_page(cursor, mtr)
 					&& (prev_page_no != FIL_NULL)) {	
diff -r 936d427a9a15 innobase/btr/btr0sea.c
--- a/innobase/btr/btr0sea.c	Mon Dec 22 00:33:03 2008 -0800
+++ b/innobase/btr/btr0sea.c	Mon Dec 22 00:33:11 2008 -0800
@@ -861,6 +861,12 @@
 
 	buf_pool->n_page_gets++;
 
+	/* Initializes status counters */
+	innobase_mysql_thd_init_innodb_scan_cont();
+	innobase_mysql_thd_init_innodb_scan_jump();
+	innobase_mysql_thd_init_innodb_scan_data();
+	innobase_mysql_thd_init_innodb_scan_garbage();
+
 	return(TRUE);	
 
 	/*-------------------------------------------*/
diff -r 936d427a9a15 innobase/include/btr0cur.h
--- a/innobase/include/btr0cur.h	Mon Dec 22 00:33:03 2008 -0800
+++ b/innobase/include/btr0cur.h	Mon Dec 22 00:33:11 2008 -0800
@@ -697,6 +697,17 @@
 extern ulint	btr_cur_n_non_sea_old;
 extern ulint	btr_cur_n_sea_old;
 
+/*--------------------------------------*/
+/* prototypes for new functions added to ha_innodb.cc */
+void innobase_mysql_thd_init_innodb_scan_cont();
+void innobase_mysql_thd_increment_innodb_scan_cont(ulong length);
+void innobase_mysql_thd_init_innodb_scan_jump();
+void innobase_mysql_thd_increment_innodb_scan_jump(ulong length);
+void innobase_mysql_thd_init_innodb_scan_data();
+void innobase_mysql_thd_increment_innodb_scan_data(ulong length);
+void innobase_mysql_thd_init_innodb_scan_garbage();
+void innobase_mysql_thd_increment_innodb_scan_garbage(ulong length);
+
 #ifndef UNIV_NONINL
 #include "btr0cur.ic"
 #endif
diff -r 936d427a9a15 patch_info/innodb_check_fragmentation.info
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/patch_info/innodb_check_fragmentation.info	Mon Dec 22 00:33:11 2008 -0800
@@ -0,0 +1,6 @@
+File=innodb_check_fragmentation.patch
+Name=Session status to check fragmentation of the last InnoDB scan
+Version=1.0
+Author=Percona <info@percona.com>
+License=GPL
+Comment=The names are Innodb_scan_*
diff -r 936d427a9a15 sql/ha_innodb.cc
--- a/sql/ha_innodb.cc	Mon Dec 22 00:33:03 2008 -0800
+++ b/sql/ha_innodb.cc	Mon Dec 22 00:33:11 2008 -0800
@@ -760,6 +760,102 @@
 }
 
 /*************************************************************************
+Initializes Innodb_scan_blocks_contiguous. */
+extern "C"
+void
+innobase_mysql_thd_init_innodb_scan_cont()
+{
+	THD *thd=current_thd;
+	if (likely(thd != 0)) {
+		thd->status_var.innodb_scan_cont = 0;
+	}
+}
+
+/*************************************************************************
+Increments Innodb_scan_blocks_contiguous. */
+extern "C"
+void
+innobase_mysql_thd_increment_innodb_scan_cont(ulong length)
+{
+	THD *thd=current_thd;
+	if (likely(thd != 0)) {
+		thd->status_var.innodb_scan_cont+= length;
+	}
+}
+
+/*************************************************************************
+Initializes Innodb_scan_blocks_jumpy. */
+extern "C"
+void
+innobase_mysql_thd_init_innodb_scan_jump()
+{
+	THD *thd=current_thd;
+	if (likely(thd != 0)) {
+		thd->status_var.innodb_scan_jump = 0;
+	}
+}
+
+/*************************************************************************
+Increments Innodb_scan_blocks_jumpy. */
+extern "C"
+void
+innobase_mysql_thd_increment_innodb_scan_jump(ulong length)
+{
+	THD *thd=current_thd;
+	if (likely(thd != 0)) {
+		thd->status_var.innodb_scan_jump+= length;
+	}
+}
+
+/*************************************************************************
+Initializes Innodb_scan_data_in_pages. */
+extern "C"
+void
+innobase_mysql_thd_init_innodb_scan_data()
+{
+	THD *thd=current_thd;
+	if (likely(thd != 0)) {
+		thd->status_var.innodb_scan_data = 0;
+	}
+}
+
+/*************************************************************************
+Increments Innodb_scan_data_in_pages. */
+extern "C"
+void
+innobase_mysql_thd_increment_innodb_scan_data(ulong length)
+{
+	THD *thd=current_thd;
+	if (likely(thd != 0)) {
+		thd->status_var.innodb_scan_data+= length;
+	}
+}
+
+/*************************************************************************
+Initializes Innodb_scan_garbages_in_pages. */
+extern "C"
+void
+innobase_mysql_thd_init_innodb_scan_garbage()
+{
+	THD *thd=current_thd;
+	if (likely(thd != 0)) {
+		thd->status_var.innodb_scan_garbage = 0;
+	}
+}
+
+/*************************************************************************
+Increments Innodb_scan_garbages_in_pages. */
+extern "C"
+void
+innobase_mysql_thd_increment_innodb_scan_garbage(ulong length)
+{
+	THD *thd=current_thd;
+	if (likely(thd != 0)) {
+		thd->status_var.innodb_scan_garbage+= length;
+	}
+}
+
+/*************************************************************************
 Gets the InnoDB transaction handle for a MySQL handler object, creates
 an InnoDB transaction struct if the corresponding MySQL thread struct still
 lacks one. */
diff -r 936d427a9a15 sql/mysqld.cc
--- a/sql/mysqld.cc	Mon Dec 22 00:33:03 2008 -0800
+++ b/sql/mysqld.cc	Mon Dec 22 00:33:11 2008 -0800
@@ -6673,6 +6673,10 @@
   {"Handler_write",            (char*) offsetof(STATUS_VAR, ha_write_count), SHOW_LONG_STATUS},
 #ifdef HAVE_INNOBASE_DB
   {"Innodb_",                  (char*) &innodb_status_variables, SHOW_VARS},
+  {"Innodb_scan_pages_contiguous",(char*) offsetof(STATUS_VAR, innodb_scan_cont), SHOW_LONGLONG_STATUS},
+  {"Innodb_scan_pages_jumpy",  (char*) offsetof(STATUS_VAR, innodb_scan_jump), SHOW_LONGLONG_STATUS},
+  {"Innodb_scan_data_in_pages",(char*) offsetof(STATUS_VAR, innodb_scan_data), SHOW_LONGLONG_STATUS},
+  {"Innodb_scan_garbages_in_pages",(char*) offsetof(STATUS_VAR, innodb_scan_garbage), SHOW_LONGLONG_STATUS},
 #endif /*HAVE_INNOBASE_DB*/
   {"Key_blocks_not_flushed",   (char*) &dflt_key_cache_var.global_blocks_changed, SHOW_KEY_CACHE_LONG},
   {"Key_blocks_unused",        (char*) &dflt_key_cache_var.blocks_unused, SHOW_KEY_CACHE_CONST_LONG},
diff -r 936d427a9a15 sql/sql_class.h
--- a/sql/sql_class.h	Mon Dec 22 00:33:03 2008 -0800
+++ b/sql/sql_class.h	Mon Dec 22 00:33:11 2008 -0800
@@ -729,6 +729,10 @@
     sense to add to the /global/ status variable counter.
   */
   double last_query_cost;
+  ulonglong innodb_scan_cont;
+  ulonglong innodb_scan_jump;
+  ulonglong innodb_scan_data;
+  ulonglong innodb_scan_garbage;
 } STATUS_VAR;
 
 /*