]> git.pld-linux.org Git - packages/mysql.git/blob - mysql-userstatv2.patch
- mysql 5.0.75 by Eero Hänninen
[packages/mysql.git] / mysql-userstatv2.patch
1 diff -r d35bd12bba15 BUILD/Makefile.in
2 --- a/BUILD/Makefile.in Mon Dec 22 22:51:44 2008 -0800
3 +++ b/BUILD/Makefile.in Mon Dec 22 22:53:26 2008 -0800
4 @@ -169,6 +169,7 @@
5  LIBDL = @LIBDL@
6  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
7  LIBOBJS = @LIBOBJS@
8 +LIBRT = @LIBRT@
9  LIBS = @LIBS@
10  LIBTOOL = @LIBTOOL@
11  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
12 diff -r d35bd12bba15 Docs/Makefile.in
13 --- a/Docs/Makefile.in  Mon Dec 22 22:51:44 2008 -0800
14 +++ b/Docs/Makefile.in  Mon Dec 22 22:53:26 2008 -0800
15 @@ -167,6 +167,7 @@
16  LIBDL = @LIBDL@
17  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
18  LIBOBJS = @LIBOBJS@
19 +LIBRT = @LIBRT@
20  LIBS = @LIBS@
21  LIBTOOL = @LIBTOOL@
22  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
23 diff -r d35bd12bba15 Makefile.in
24 --- a/Makefile.in       Mon Dec 22 22:51:44 2008 -0800
25 +++ b/Makefile.in       Mon Dec 22 22:53:26 2008 -0800
26 @@ -191,6 +191,7 @@
27  LIBDL = @LIBDL@
28  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
29  LIBOBJS = @LIBOBJS@
30 +LIBRT = @LIBRT@
31  LIBS = @LIBS@
32  LIBTOOL = @LIBTOOL@
33  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
34 diff -r d35bd12bba15 SSL/Makefile.in
35 --- a/SSL/Makefile.in   Mon Dec 22 22:51:44 2008 -0800
36 +++ b/SSL/Makefile.in   Mon Dec 22 22:53:26 2008 -0800
37 @@ -167,6 +167,7 @@
38  LIBDL = @LIBDL@
39  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
40  LIBOBJS = @LIBOBJS@
41 +LIBRT = @LIBRT@
42  LIBS = @LIBS@
43  LIBTOOL = @LIBTOOL@
44  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
45 diff -r d35bd12bba15 aclocal.m4
46 --- a/aclocal.m4        Mon Dec 22 22:51:44 2008 -0800
47 +++ b/aclocal.m4        Mon Dec 22 22:53:26 2008 -0800
48 @@ -1597,7 +1597,7 @@
49  
50    # Append ld.so.conf contents to the search path
51    if test -f /etc/ld.so.conf; then
52 -    lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s", \[$]2)); skip = 1; } { if (!skip) print \[$]0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;s/[:,   ]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;/^$/d' | tr '\n' ' '`
53 +    lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \[$]2)); skip = 1; } { if (!skip) print \[$]0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;s/[:,       ]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;/^$/d' | tr '\n' ' '`
54      sys_lib_dlsearch_path_spec="/lib${libsuff} /usr/lib${libsuff} $lt_ld_extra"
55    fi
56  
57 @@ -4305,6 +4305,9 @@
58  # Is the compiler the GNU C compiler?
59  with_gcc=$_LT_AC_TAGVAR(GCC, $1)
60  
61 +gcc_dir=\`gcc -print-file-name=. | $SED 's,/\.$,,'\`
62 +gcc_ver=\`gcc -dumpversion\`
63 +
64  # An ERE matcher.
65  EGREP=$lt_EGREP
66  
67 @@ -4438,11 +4441,11 @@
68  
69  # Dependencies to place before the objects being linked to create a
70  # shared library.
71 -predep_objects=$lt_[]_LT_AC_TAGVAR(predep_objects, $1)
72 +predep_objects=\`echo $lt_[]_LT_AC_TAGVAR(predep_objects, $1) | \$SED -e "s@\${gcc_dir}@\\\${gcc_dir}@g;s@\${gcc_ver}@\\\${gcc_ver}@g"\`
73  
74  # Dependencies to place after the objects being linked to create a
75  # shared library.
76 -postdep_objects=$lt_[]_LT_AC_TAGVAR(postdep_objects, $1)
77 +postdep_objects=\`echo $lt_[]_LT_AC_TAGVAR(postdep_objects, $1) | \$SED -e "s@\${gcc_dir}@\\\${gcc_dir}@g;s@\${gcc_ver}@\\\${gcc_ver}@g"\`
78  
79  # Dependencies to place before the objects being linked to create a
80  # shared library.
81 @@ -4454,7 +4457,7 @@
82  
83  # The library search path used internally by the compiler when linking
84  # a shared library.
85 -compiler_lib_search_path=$lt_[]_LT_AC_TAGVAR(compiler_lib_search_path, $1)
86 +compiler_lib_search_path=\`echo $lt_[]_LT_AC_TAGVAR(compiler_lib_search_path, $1) | \$SED -e "s@\${gcc_dir}@\\\${gcc_dir}@g;s@\${gcc_ver}@\\\${gcc_ver}@g"\`
87  
88  # Method to check whether dependent libraries are shared objects.
89  deplibs_check_method=$lt_deplibs_check_method
90 @@ -4534,7 +4537,7 @@
91  link_all_deplibs=$_LT_AC_TAGVAR(link_all_deplibs, $1)
92  
93  # Compile-time system search path for libraries
94 -sys_lib_search_path_spec=$lt_sys_lib_search_path_spec
95 +sys_lib_search_path_spec=\`echo $lt_sys_lib_search_path_spec | \$SED -e "s@\${gcc_dir}@\\\${gcc_dir}@g;s@\${gcc_ver}@\\\${gcc_ver}@g"\`
96  
97  # Run-time system search path for libraries
98  sys_lib_dlsearch_path_spec=$lt_sys_lib_dlsearch_path_spec
99 @@ -6370,6 +6373,7 @@
100      done
101    done
102  done
103 +IFS=$as_save_IFS
104  lt_ac_max=0
105  lt_ac_count=0
106  # Add /usr/xpg4/bin/sed as it is typically found on Solaris
107 @@ -6402,6 +6406,7 @@
108  done
109  ])
110  SED=$lt_cv_path_SED
111 +AC_SUBST([SED])
112  AC_MSG_RESULT([$SED])
113  ])
114  
115 diff -r d35bd12bba15 client/Makefile.in
116 --- a/client/Makefile.in        Mon Dec 22 22:51:44 2008 -0800
117 +++ b/client/Makefile.in        Mon Dec 22 22:53:26 2008 -0800
118 @@ -268,6 +268,7 @@
119  LIBDL = @LIBDL@
120  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
121  LIBOBJS = @LIBOBJS@
122 +LIBRT = @LIBRT@
123  LIBS = @CLIENT_LIBS@
124  LIBTOOL = @LIBTOOL@
125  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
126 diff -r d35bd12bba15 cmd-line-utils/Makefile.in
127 --- a/cmd-line-utils/Makefile.in        Mon Dec 22 22:51:44 2008 -0800
128 +++ b/cmd-line-utils/Makefile.in        Mon Dec 22 22:53:26 2008 -0800
129 @@ -177,6 +177,7 @@
130  LIBDL = @LIBDL@
131  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
132  LIBOBJS = @LIBOBJS@
133 +LIBRT = @LIBRT@
134  LIBS = @LIBS@
135  LIBTOOL = @LIBTOOL@
136  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
137 diff -r d35bd12bba15 cmd-line-utils/libedit/Makefile.in
138 --- a/cmd-line-utils/libedit/Makefile.in        Mon Dec 22 22:51:44 2008 -0800
139 +++ b/cmd-line-utils/libedit/Makefile.in        Mon Dec 22 22:53:26 2008 -0800
140 @@ -197,6 +197,7 @@
141  LIBDL = @LIBDL@
142  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
143  LIBOBJS = @LIBOBJS@
144 +LIBRT = @LIBRT@
145  LIBS = @LIBS@
146  LIBTOOL = @LIBTOOL@
147  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
148 diff -r d35bd12bba15 cmd-line-utils/readline/Makefile.in
149 --- a/cmd-line-utils/readline/Makefile.in       Mon Dec 22 22:51:44 2008 -0800
150 +++ b/cmd-line-utils/readline/Makefile.in       Mon Dec 22 22:53:26 2008 -0800
151 @@ -195,6 +195,7 @@
152  LIBDL = @LIBDL@
153  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
154  LIBOBJS = @LIBOBJS@
155 +LIBRT = @LIBRT@
156  LIBS = @LIBS@
157  LIBTOOL = @LIBTOOL@
158  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
159 diff -r d35bd12bba15 configure
160 --- a/configure Mon Dec 22 22:51:44 2008 -0800
161 +++ b/configure Mon Dec 22 22:53:26 2008 -0800
162 @@ -38236,7 +38236,91 @@
163         # We also disable for SCO for the time being, the headers for the
164         # thread library we use conflicts with other headers.
165      ;;
166 - *)
167 +*)
168 +   # most systems require the program be linked with librt library to use
169 +   # the function clock_gettime
170 +   my_save_LIBS="$LIBS"
171 +   LIBS=""
172 +
173 +echo "$as_me:$LINENO: checking for clock_gettime in -lrt" >&5
174 +echo $ECHO_N "checking for clock_gettime in -lrt... $ECHO_C" >&6
175 +if test "${ac_cv_lib_rt_clock_gettime+set}" = set; then
176 +  echo $ECHO_N "(cached) $ECHO_C" >&6
177 +else
178 +  ac_check_lib_save_LIBS=$LIBS
179 +LIBS="-lrt  $LIBS"
180 +cat >conftest.$ac_ext <<_ACEOF
181 +/* confdefs.h.  */
182 +_ACEOF
183 +cat confdefs.h >>conftest.$ac_ext
184 +cat >>conftest.$ac_ext <<_ACEOF
185 +/* end confdefs.h.  */
186 +
187 +/* Override any gcc2 internal prototype to avoid an error.  */
188 +#ifdef __cplusplus
189 +extern "C"
190 +#endif
191 +/* We use char because int might match the return type of a gcc2
192 +   builtin and then its argument prototype would still apply.  */
193 +char clock_gettime ();
194 +int
195 +main ()
196 +{
197 +clock_gettime ();
198 +  ;
199 +  return 0;
200 +}
201 +_ACEOF
202 +rm -f conftest.$ac_objext conftest$ac_exeext
203 +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
204 +  (eval $ac_link) 2>conftest.er1
205 +  ac_status=$?
206 +  grep -v '^ *+' conftest.er1 >conftest.err
207 +  rm -f conftest.er1
208 +  cat conftest.err >&5
209 +  echo "$as_me:$LINENO: \$? = $ac_status" >&5
210 +  (exit $ac_status); } &&
211 +        { ac_try='test -z "$ac_c_werror_flag"
212 +                        || test ! -s conftest.err'
213 +  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
214 +  (eval $ac_try) 2>&5
215 +  ac_status=$?
216 +  echo "$as_me:$LINENO: \$? = $ac_status" >&5
217 +  (exit $ac_status); }; } &&
218 +        { ac_try='test -s conftest$ac_exeext'
219 +  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
220 +  (eval $ac_try) 2>&5
221 +  ac_status=$?
222 +  echo "$as_me:$LINENO: \$? = $ac_status" >&5
223 +  (exit $ac_status); }; }; then
224 +  ac_cv_lib_rt_clock_gettime=yes
225 +else
226 +  echo "$as_me: failed program was:" >&5
227 +sed 's/^/| /' conftest.$ac_ext >&5
228 +
229 +ac_cv_lib_rt_clock_gettime=no
230 +fi
231 +rm -f conftest.err conftest.$ac_objext \
232 +      conftest$ac_exeext conftest.$ac_ext
233 +LIBS=$ac_check_lib_save_LIBS
234 +fi
235 +echo "$as_me:$LINENO: result: $ac_cv_lib_rt_clock_gettime" >&5
236 +echo "${ECHO_T}$ac_cv_lib_rt_clock_gettime" >&6
237 +if test $ac_cv_lib_rt_clock_gettime = yes; then
238 +  cat >>confdefs.h <<_ACEOF
239 +#define HAVE_LIBRT 1
240 +_ACEOF
241 +
242 +  LIBS="-lrt $LIBS"
243 +
244 +fi
245 +
246 +   LIBRT=$LIBS
247 +   LIBS="$my_save_LIBS"
248 +
249 +
250 +   LIBS="$LIBS $LIBRT"
251 +
252  for ac_func in clock_gettime
253  do
254  as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
255 @@ -41644,7 +41728,7 @@
256  
257  fi
258  
259 -CLIENT_LIBS="$NON_THREADED_LIBS $openssl_libs $ZLIB_LIBS $STATIC_NSS_FLAGS"
260 +CLIENT_LIBS="$NON_THREADED_LIBS $openssl_libs $ZLIB_LIBS $STATIC_NSS_FLAGS $LIBRT"
261  
262  
263  
264 @@ -42984,6 +43068,7 @@
265  s,@MAKE_SHELL@,$MAKE_SHELL,;t t
266  s,@TERMCAP_LIB@,$TERMCAP_LIB,;t t
267  s,@LIBEDIT_LOBJECTS@,$LIBEDIT_LOBJECTS,;t t
268 +s,@LIBRT@,$LIBRT,;t t
269  s,@tools_dirs@,$tools_dirs,;t t
270  s,@openssl_libs@,$openssl_libs,;t t
271  s,@openssl_includes@,$openssl_includes,;t t
272 diff -r d35bd12bba15 configure.in
273 --- a/configure.in      Mon Dec 22 22:51:44 2008 -0800
274 +++ b/configure.in      Mon Dec 22 22:53:26 2008 -0800
275 @@ -2098,7 +2098,18 @@
276         # We also disable for SCO for the time being, the headers for the
277         # thread library we use conflicts with other headers.
278      ;;
279 - *) AC_CHECK_FUNCS(clock_gettime)
280 +*) 
281 +   # most systems require the program be linked with librt library to use
282 +   # the function clock_gettime 
283 +   my_save_LIBS="$LIBS"
284 +   LIBS=""
285 +   AC_CHECK_LIB(rt,clock_gettime)
286 +   LIBRT=$LIBS
287 +   LIBS="$my_save_LIBS"
288 +   AC_SUBST(LIBRT)
289 +
290 +   LIBS="$LIBS $LIBRT"
291 +   AC_CHECK_FUNCS(clock_gettime)
292      ;;
293  esac
294  
295 @@ -2713,7 +2724,7 @@
296    AC_DEFINE([THREAD_SAFE_CLIENT], [1], [Should be client be thread safe])
297  fi
298  
299 -CLIENT_LIBS="$NON_THREADED_LIBS $openssl_libs $ZLIB_LIBS $STATIC_NSS_FLAGS"
300 +CLIENT_LIBS="$NON_THREADED_LIBS $openssl_libs $ZLIB_LIBS $STATIC_NSS_FLAGS $LIBRT"
301  
302  AC_SUBST(CLIENT_LIBS)
303  AC_SUBST(NON_THREADED_LIBS)
304 diff -r d35bd12bba15 dbug/Makefile.in
305 --- a/dbug/Makefile.in  Mon Dec 22 22:51:44 2008 -0800
306 +++ b/dbug/Makefile.in  Mon Dec 22 22:53:26 2008 -0800
307 @@ -214,6 +214,7 @@
308  LIBDL = @LIBDL@
309  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
310  LIBOBJS = @LIBOBJS@
311 +LIBRT = @LIBRT@
312  LIBS = @LIBS@
313  LIBTOOL = @LIBTOOL@
314  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
315 diff -r d35bd12bba15 extra/Makefile.in
316 --- a/extra/Makefile.in Mon Dec 22 22:51:44 2008 -0800
317 +++ b/extra/Makefile.in Mon Dec 22 22:53:26 2008 -0800
318 @@ -259,6 +259,7 @@
319  LIBDL = @LIBDL@
320  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
321  LIBOBJS = @LIBOBJS@
322 +LIBRT = @LIBRT@
323  LIBS = @LIBS@
324  LIBTOOL = @LIBTOOL@
325  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
326 diff -r d35bd12bba15 extra/yassl/Makefile.in
327 --- a/extra/yassl/Makefile.in   Mon Dec 22 22:51:44 2008 -0800
328 +++ b/extra/yassl/Makefile.in   Mon Dec 22 22:53:26 2008 -0800
329 @@ -162,6 +162,7 @@
330  LIBDL = @LIBDL@
331  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
332  LIBOBJS = @LIBOBJS@
333 +LIBRT = @LIBRT@
334  LIBS = @LIBS@
335  LIBTOOL = @LIBTOOL@
336  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
337 diff -r d35bd12bba15 extra/yassl/src/Makefile.in
338 --- a/extra/yassl/src/Makefile.in       Mon Dec 22 22:51:44 2008 -0800
339 +++ b/extra/yassl/src/Makefile.in       Mon Dec 22 22:53:26 2008 -0800
340 @@ -173,6 +173,7 @@
341  LIBDL = @LIBDL@
342  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
343  LIBOBJS = @LIBOBJS@
344 +LIBRT = @LIBRT@
345  LIBS = @LIBS@
346  LIBTOOL = @LIBTOOL@
347  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
348 diff -r d35bd12bba15 extra/yassl/taocrypt/Makefile.in
349 --- a/extra/yassl/taocrypt/Makefile.in  Mon Dec 22 22:51:44 2008 -0800
350 +++ b/extra/yassl/taocrypt/Makefile.in  Mon Dec 22 22:53:26 2008 -0800
351 @@ -162,6 +162,7 @@
352  LIBDL = @LIBDL@
353  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
354  LIBOBJS = @LIBOBJS@
355 +LIBRT = @LIBRT@
356  LIBS = @LIBS@
357  LIBTOOL = @LIBTOOL@
358  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
359 diff -r d35bd12bba15 extra/yassl/taocrypt/benchmark/Makefile.in
360 --- a/extra/yassl/taocrypt/benchmark/Makefile.in        Mon Dec 22 22:51:44 2008 -0800
361 +++ b/extra/yassl/taocrypt/benchmark/Makefile.in        Mon Dec 22 22:53:26 2008 -0800
362 @@ -172,6 +172,7 @@
363  LIBDL = @LIBDL@
364  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
365  LIBOBJS = @LIBOBJS@
366 +LIBRT = @LIBRT@
367  LIBS = @LIBS@
368  LIBTOOL = @LIBTOOL@
369  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
370 diff -r d35bd12bba15 extra/yassl/taocrypt/src/Makefile.in
371 --- a/extra/yassl/taocrypt/src/Makefile.in      Mon Dec 22 22:51:44 2008 -0800
372 +++ b/extra/yassl/taocrypt/src/Makefile.in      Mon Dec 22 22:53:26 2008 -0800
373 @@ -182,6 +182,7 @@
374  LIBDL = @LIBDL@
375  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
376  LIBOBJS = @LIBOBJS@
377 +LIBRT = @LIBRT@
378  LIBS = @LIBS@
379  LIBTOOL = @LIBTOOL@
380  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
381 diff -r d35bd12bba15 extra/yassl/taocrypt/test/Makefile.in
382 --- a/extra/yassl/taocrypt/test/Makefile.in     Mon Dec 22 22:51:44 2008 -0800
383 +++ b/extra/yassl/taocrypt/test/Makefile.in     Mon Dec 22 22:53:26 2008 -0800
384 @@ -172,6 +172,7 @@
385  LIBDL = @LIBDL@
386  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
387  LIBOBJS = @LIBOBJS@
388 +LIBRT = @LIBRT@
389  LIBS = @LIBS@
390  LIBTOOL = @LIBTOOL@
391  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
392 diff -r d35bd12bba15 extra/yassl/testsuite/Makefile.in
393 --- a/extra/yassl/testsuite/Makefile.in Mon Dec 22 22:51:44 2008 -0800
394 +++ b/extra/yassl/testsuite/Makefile.in Mon Dec 22 22:53:26 2008 -0800
395 @@ -175,6 +175,7 @@
396  LIBDL = @LIBDL@
397  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
398  LIBOBJS = @LIBOBJS@
399 +LIBRT = @LIBRT@
400  LIBS = @LIBS@
401  LIBTOOL = @LIBTOOL@
402  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
403 diff -r d35bd12bba15 heap/Makefile.in
404 --- a/heap/Makefile.in  Mon Dec 22 22:51:44 2008 -0800
405 +++ b/heap/Makefile.in  Mon Dec 22 22:53:26 2008 -0800
406 @@ -218,6 +218,7 @@
407  LIBDL = @LIBDL@
408  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
409  LIBOBJS = @LIBOBJS@
410 +LIBRT = @LIBRT@
411  LIBS = @LIBS@
412  LIBTOOL = @LIBTOOL@
413  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
414 diff -r d35bd12bba15 include/Makefile.in
415 --- a/include/Makefile.in       Mon Dec 22 22:51:44 2008 -0800
416 +++ b/include/Makefile.in       Mon Dec 22 22:53:26 2008 -0800
417 @@ -183,6 +183,7 @@
418  LIBDL = @LIBDL@
419  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
420  LIBOBJS = @LIBOBJS@
421 +LIBRT = @LIBRT@
422  LIBS = @LIBS@
423  LIBTOOL = @LIBTOOL@
424  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
425 diff -r d35bd12bba15 include/mysql_com.h
426 --- a/include/mysql_com.h       Mon Dec 22 22:51:44 2008 -0800
427 +++ b/include/mysql_com.h       Mon Dec 22 22:53:26 2008 -0800
428 @@ -106,6 +106,11 @@
429                                            thread */
430  #define REFRESH_MASTER          128     /* Remove all bin logs in the index
431                                            and truncate the index */
432 +#define REFRESH_TABLE_STATS     256     /* Refresh table stats hash table */
433 +#define REFRESH_INDEX_STATS     512     /* Refresh index stats hash table */
434 +#define REFRESH_USER_STATS      1024    /* Refresh user stats hash table */
435 +#define REFRESH_SLOW_QUERY_LOG  4096    /* Flush slow query log and rotate*/
436 +#define REFRESH_CLIENT_STATS    8192    /* Refresh client stats hash table */
437  
438  /* The following can't be set with mysql_refresh() */
439  #define REFRESH_READ_LOCK      16384   /* Lock tables for read */
440 diff -r d35bd12bba15 libmysql/Makefile.in
441 --- a/libmysql/Makefile.in      Mon Dec 22 22:51:44 2008 -0800
442 +++ b/libmysql/Makefile.in      Mon Dec 22 22:53:26 2008 -0800
443 @@ -278,6 +278,7 @@
444  LIBDL = @LIBDL@
445  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
446  LIBOBJS = @LIBOBJS@
447 +LIBRT = @LIBRT@
448  LIBS = @CLIENT_LIBS@ 
449  LIBTOOL = @LIBTOOL@
450  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
451 diff -r d35bd12bba15 libmysql_r/Makefile.in
452 --- a/libmysql_r/Makefile.in    Mon Dec 22 22:51:44 2008 -0800
453 +++ b/libmysql_r/Makefile.in    Mon Dec 22 22:53:26 2008 -0800
454 @@ -275,6 +275,7 @@
455  LIBDL = @LIBDL@
456  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
457  LIBOBJS = @LIBOBJS@
458 +LIBRT = @LIBRT@
459  LIBS = @LIBS@ @ZLIB_LIBS@ @openssl_libs@
460  LIBTOOL = @LIBTOOL@
461  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
462 diff -r d35bd12bba15 libmysqld/Makefile.in
463 --- a/libmysqld/Makefile.in     Mon Dec 22 22:51:44 2008 -0800
464 +++ b/libmysqld/Makefile.in     Mon Dec 22 22:53:26 2008 -0800
465 @@ -264,6 +264,7 @@
466  LIBDL = @LIBDL@
467  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
468  LIBOBJS = @LIBOBJS@
469 +LIBRT = @LIBRT@
470  LIBS = @LIBS@
471  LIBTOOL = @LIBTOOL@
472  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
473 diff -r d35bd12bba15 libmysqld/examples/Makefile.in
474 --- a/libmysqld/examples/Makefile.in    Mon Dec 22 22:51:44 2008 -0800
475 +++ b/libmysqld/examples/Makefile.in    Mon Dec 22 22:53:26 2008 -0800
476 @@ -213,6 +213,7 @@
477  LIBDL = @LIBDL@
478  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
479  LIBOBJS = @LIBOBJS@
480 +LIBRT = @LIBRT@
481  LIBS = @LIBS@ @WRAPLIBS@ @CLIENT_LIBS@ $(yassl_libs)
482  LIBTOOL = @LIBTOOL@
483  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
484 diff -r d35bd12bba15 man/Makefile.in
485 --- a/man/Makefile.in   Mon Dec 22 22:51:44 2008 -0800
486 +++ b/man/Makefile.in   Mon Dec 22 22:53:26 2008 -0800
487 @@ -174,6 +174,7 @@
488  LIBDL = @LIBDL@
489  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
490  LIBOBJS = @LIBOBJS@
491 +LIBRT = @LIBRT@
492  LIBS = @LIBS@
493  LIBTOOL = @LIBTOOL@
494  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
495 diff -r d35bd12bba15 myisam/Makefile.in
496 --- a/myisam/Makefile.in        Mon Dec 22 22:51:44 2008 -0800
497 +++ b/myisam/Makefile.in        Mon Dec 22 22:53:26 2008 -0800
498 @@ -257,6 +257,7 @@
499  LIBDL = @LIBDL@
500  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
501  LIBOBJS = @LIBOBJS@
502 +LIBRT = @LIBRT@
503  LIBS = @LIBS@
504  LIBTOOL = @LIBTOOL@
505  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
506 diff -r d35bd12bba15 myisammrg/Makefile.in
507 --- a/myisammrg/Makefile.in     Mon Dec 22 22:51:44 2008 -0800
508 +++ b/myisammrg/Makefile.in     Mon Dec 22 22:53:26 2008 -0800
509 @@ -205,6 +205,7 @@
510  LIBDL = @LIBDL@
511  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
512  LIBOBJS = @LIBOBJS@
513 +LIBRT = @LIBRT@
514  LIBS = @LIBS@
515  LIBTOOL = @LIBTOOL@
516  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
517 diff -r d35bd12bba15 mysql-test/Makefile.in
518 --- a/mysql-test/Makefile.in    Mon Dec 22 22:51:44 2008 -0800
519 +++ b/mysql-test/Makefile.in    Mon Dec 22 22:53:26 2008 -0800
520 @@ -181,6 +181,7 @@
521  LIBDL = @LIBDL@
522  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
523  LIBOBJS = @LIBOBJS@
524 +LIBRT = @LIBRT@
525  LIBS = @LIBS@
526  LIBTOOL = @LIBTOOL@
527  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
528 diff -r d35bd12bba15 mysql-test/ndb/Makefile.in
529 --- a/mysql-test/ndb/Makefile.in        Mon Dec 22 22:51:44 2008 -0800
530 +++ b/mysql-test/ndb/Makefile.in        Mon Dec 22 22:53:26 2008 -0800
531 @@ -170,6 +170,7 @@
532  LIBDL = @LIBDL@
533  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
534  LIBOBJS = @LIBOBJS@
535 +LIBRT = @LIBRT@
536  LIBS = @LIBS@
537  LIBTOOL = @LIBTOOL@
538  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
539 diff -r d35bd12bba15 mysql-test/r/information_schema.result
540 --- a/mysql-test/r/information_schema.result    Mon Dec 22 22:51:44 2008 -0800
541 +++ b/mysql-test/r/information_schema.result    Mon Dec 22 22:53:26 2008 -0800
542 @@ -37,10 +37,12 @@
543  select * from v1;
544  c
545  CHARACTER_SETS
546 +CLIENT_STATISTICS
547  COLLATIONS
548  COLLATION_CHARACTER_SET_APPLICABILITY
549  COLUMNS
550  COLUMN_PRIVILEGES
551 +INDEX_STATISTICS
552  KEY_COLUMN_USAGE
553  PROFILING
554  ROUTINES
555 @@ -50,8 +52,10 @@
556  TABLES
557  TABLE_CONSTRAINTS
558  TABLE_PRIVILEGES
559 +TABLE_STATISTICS
560  TRIGGERS
561  USER_PRIVILEGES
562 +USER_STATISTICS
563  VIEWS
564  columns_priv
565  db
566 @@ -83,6 +87,7 @@
567  TABLES TABLES
568  TABLE_CONSTRAINTS      TABLE_CONSTRAINTS
569  TABLE_PRIVILEGES       TABLE_PRIVILEGES
570 +TABLE_STATISTICS       TABLE_STATISTICS
571  TRIGGERS       TRIGGERS
572  tables_priv    tables_priv
573  time_zone      time_zone
574 @@ -102,6 +107,7 @@
575  TABLES TABLES
576  TABLE_CONSTRAINTS      TABLE_CONSTRAINTS
577  TABLE_PRIVILEGES       TABLE_PRIVILEGES
578 +TABLE_STATISTICS       TABLE_STATISTICS
579  TRIGGERS       TRIGGERS
580  tables_priv    tables_priv
581  time_zone      time_zone
582 @@ -121,6 +127,7 @@
583  TABLES TABLES
584  TABLE_CONSTRAINTS      TABLE_CONSTRAINTS
585  TABLE_PRIVILEGES       TABLE_PRIVILEGES
586 +TABLE_STATISTICS       TABLE_STATISTICS
587  TRIGGERS       TRIGGERS
588  tables_priv    tables_priv
589  time_zone      time_zone
590 @@ -594,12 +601,13 @@
591  where table_schema='information_schema' limit 2;
592  TABLE_NAME     TABLE_TYPE      ENGINE
593  CHARACTER_SETS SYSTEM VIEW     MEMORY
594 -COLLATIONS     SYSTEM VIEW     MEMORY
595 +CLIENT_STATISTICS      SYSTEM VIEW     MEMORY
596  show tables from information_schema like "T%";
597  Tables_in_information_schema (T%)
598  TABLES
599  TABLE_CONSTRAINTS
600  TABLE_PRIVILEGES
601 +TABLE_STATISTICS
602  TRIGGERS
603  create database information_schema;
604  ERROR 42000: Access denied for user 'root'@'localhost' to database 'information_schema'
605 @@ -609,6 +617,7 @@
606  TABLES SYSTEM VIEW
607  TABLE_CONSTRAINTS      SYSTEM VIEW
608  TABLE_PRIVILEGES       SYSTEM VIEW
609 +TABLE_STATISTICS       SYSTEM VIEW
610  TRIGGERS       SYSTEM VIEW
611  create table t1(a int);
612  ERROR 42S02: Unknown table 't1' in information_schema
613 @@ -621,6 +630,7 @@
614  TABLES
615  TABLE_CONSTRAINTS
616  TABLE_PRIVILEGES
617 +TABLE_STATISTICS
618  TRIGGERS
619  select table_name from tables where table_name='user';
620  table_name
621 @@ -730,7 +740,7 @@
622  CREATE VIEW a1 (t_CRASHME) AS SELECT f1 FROM t_crashme GROUP BY f1;
623  CREATE VIEW a2 AS SELECT t_CRASHME FROM a1;
624  count(*)
625 -102
626 +106
627  drop view a2, a1;
628  drop table t_crashme;
629  select table_schema,table_name, column_name from
630 @@ -790,18 +800,20 @@
631  TABLE_NAME     COLUMN_NAME     PRIVILEGES
632  COLUMNS        TABLE_NAME      select
633  COLUMN_PRIVILEGES      TABLE_NAME      select
634 +INDEX_STATISTICS       TABLE_NAME      select
635  KEY_COLUMN_USAGE       TABLE_NAME      select
636  STATISTICS     TABLE_NAME      select
637  TABLES TABLE_NAME      select
638  TABLE_CONSTRAINTS      TABLE_NAME      select
639  TABLE_PRIVILEGES       TABLE_NAME      select
640 +TABLE_STATISTICS       TABLE_NAME      select
641  VIEWS  TABLE_NAME      select
642  delete from mysql.user where user='mysqltest_4';
643  delete from mysql.db where user='mysqltest_4';
644  flush privileges;
645  SELECT table_schema, count(*) FROM information_schema.TABLES GROUP BY TABLE_SCHEMA;
646  table_schema   count(*)
647 -information_schema     17
648 +information_schema     21
649  mysql  17
650  create table t1 (i int, j int);
651  create trigger trg1 before insert on t1 for each row
652 @@ -1187,10 +1199,12 @@
653          );
654  table_name     column_name
655  CHARACTER_SETS CHARACTER_SET_NAME
656 +CLIENT_STATISTICS      CLIENT
657  COLLATIONS     COLLATION_NAME
658  COLLATION_CHARACTER_SET_APPLICABILITY  COLLATION_NAME
659  COLUMNS        TABLE_SCHEMA
660  COLUMN_PRIVILEGES      TABLE_SCHEMA
661 +INDEX_STATISTICS       TABLE_SCHEMA
662  KEY_COLUMN_USAGE       CONSTRAINT_SCHEMA
663  PROFILING      QUERY_ID
664  ROUTINES       ROUTINE_SCHEMA
665 @@ -1200,8 +1214,10 @@
666  TABLES TABLE_SCHEMA
667  TABLE_CONSTRAINTS      CONSTRAINT_SCHEMA
668  TABLE_PRIVILEGES       TABLE_SCHEMA
669 +TABLE_STATISTICS       TABLE_SCHEMA
670  TRIGGERS       TRIGGER_SCHEMA
671  USER_PRIVILEGES        GRANTEE
672 +USER_STATISTICS        USER
673  VIEWS  TABLE_SCHEMA
674  SELECT t.table_name, c1.column_name
675  FROM information_schema.tables t
676 @@ -1219,10 +1235,12 @@
677          );
678  table_name     column_name
679  CHARACTER_SETS CHARACTER_SET_NAME
680 +CLIENT_STATISTICS      CLIENT
681  COLLATIONS     COLLATION_NAME
682  COLLATION_CHARACTER_SET_APPLICABILITY  COLLATION_NAME
683  COLUMNS        TABLE_SCHEMA
684  COLUMN_PRIVILEGES      TABLE_SCHEMA
685 +INDEX_STATISTICS       TABLE_SCHEMA
686  KEY_COLUMN_USAGE       CONSTRAINT_SCHEMA
687  PROFILING      QUERY_ID
688  ROUTINES       ROUTINE_SCHEMA
689 @@ -1232,8 +1250,10 @@
690  TABLES TABLE_SCHEMA
691  TABLE_CONSTRAINTS      CONSTRAINT_SCHEMA
692  TABLE_PRIVILEGES       TABLE_SCHEMA
693 +TABLE_STATISTICS       TABLE_SCHEMA
694  TRIGGERS       TRIGGER_SCHEMA
695  USER_PRIVILEGES        GRANTEE
696 +USER_STATISTICS        USER
697  VIEWS  TABLE_SCHEMA
698  SELECT MAX(table_name) FROM information_schema.tables;
699  MAX(table_name)
700 @@ -1302,10 +1322,12 @@
701  group by t.table_name order by num1, t.table_name;
702  table_name     group_concat(t.table_schema, '.', t.table_name) num1
703  CHARACTER_SETS information_schema.CHARACTER_SETS       1
704 +CLIENT_STATISTICS      information_schema.CLIENT_STATISTICS    1
705  COLLATIONS     information_schema.COLLATIONS   1
706  COLLATION_CHARACTER_SET_APPLICABILITY  information_schema.COLLATION_CHARACTER_SET_APPLICABILITY        1
707  COLUMNS        information_schema.COLUMNS      1
708  COLUMN_PRIVILEGES      information_schema.COLUMN_PRIVILEGES    1
709 +INDEX_STATISTICS       information_schema.INDEX_STATISTICS     1
710  KEY_COLUMN_USAGE       information_schema.KEY_COLUMN_USAGE     1
711  PROFILING      information_schema.PROFILING    1
712  ROUTINES       information_schema.ROUTINES     1
713 @@ -1315,8 +1337,10 @@
714  TABLES information_schema.TABLES       1
715  TABLE_CONSTRAINTS      information_schema.TABLE_CONSTRAINTS    1
716  TABLE_PRIVILEGES       information_schema.TABLE_PRIVILEGES     1
717 +TABLE_STATISTICS       information_schema.TABLE_STATISTICS     1
718  TRIGGERS       information_schema.TRIGGERS     1
719  USER_PRIVILEGES        information_schema.USER_PRIVILEGES      1
720 +USER_STATISTICS        information_schema.USER_STATISTICS      1
721  VIEWS  information_schema.VIEWS        1
722  show global status like "Uptime_%";
723  Variable_name  Value
724 diff -r d35bd12bba15 mysql-test/r/information_schema_db.result
725 --- a/mysql-test/r/information_schema_db.result Mon Dec 22 22:51:44 2008 -0800
726 +++ b/mysql-test/r/information_schema_db.result Mon Dec 22 22:53:26 2008 -0800
727 @@ -6,10 +6,12 @@
728  show tables;
729  Tables_in_information_schema
730  CHARACTER_SETS
731 +CLIENT_STATISTICS
732  COLLATIONS
733  COLLATION_CHARACTER_SET_APPLICABILITY
734  COLUMNS
735  COLUMN_PRIVILEGES
736 +INDEX_STATISTICS
737  KEY_COLUMN_USAGE
738  PROFILING
739  ROUTINES
740 @@ -19,14 +21,17 @@
741  TABLES
742  TABLE_CONSTRAINTS
743  TABLE_PRIVILEGES
744 +TABLE_STATISTICS
745  TRIGGERS
746  USER_PRIVILEGES
747 +USER_STATISTICS
748  VIEWS
749  show tables from INFORMATION_SCHEMA like 'T%';
750  Tables_in_information_schema (T%)
751  TABLES
752  TABLE_CONSTRAINTS
753  TABLE_PRIVILEGES
754 +TABLE_STATISTICS
755  TRIGGERS
756  create database `inf%`;
757  create database mbase;
758 diff -r d35bd12bba15 mysql-test/r/mysqlshow.result
759 --- a/mysql-test/r/mysqlshow.result     Mon Dec 22 22:51:44 2008 -0800
760 +++ b/mysql-test/r/mysqlshow.result     Mon Dec 22 22:53:26 2008 -0800
761 @@ -80,10 +80,12 @@
762  |                Tables                 |
763  +---------------------------------------+
764  | CHARACTER_SETS                        |
765 +| CLIENT_STATISTICS                     |
766  | COLLATIONS                            |
767  | COLLATION_CHARACTER_SET_APPLICABILITY |
768  | COLUMNS                               |
769  | COLUMN_PRIVILEGES                     |
770 +| INDEX_STATISTICS                      |
771  | KEY_COLUMN_USAGE                      |
772  | PROFILING                             |
773  | ROUTINES                              |
774 @@ -93,8 +95,10 @@
775  | TABLES                                |
776  | TABLE_CONSTRAINTS                     |
777  | TABLE_PRIVILEGES                      |
778 +| TABLE_STATISTICS                      |
779  | TRIGGERS                              |
780  | USER_PRIVILEGES                       |
781 +| USER_STATISTICS                       |
782  | VIEWS                                 |
783  +---------------------------------------+
784  Database: INFORMATION_SCHEMA
785 @@ -102,10 +106,12 @@
786  |                Tables                 |
787  +---------------------------------------+
788  | CHARACTER_SETS                        |
789 +| CLIENT_STATISTICS                     |
790  | COLLATIONS                            |
791  | COLLATION_CHARACTER_SET_APPLICABILITY |
792  | COLUMNS                               |
793  | COLUMN_PRIVILEGES                     |
794 +| INDEX_STATISTICS                      |
795  | KEY_COLUMN_USAGE                      |
796  | PROFILING                             |
797  | ROUTINES                              |
798 @@ -115,8 +121,10 @@
799  | TABLES                                |
800  | TABLE_CONSTRAINTS                     |
801  | TABLE_PRIVILEGES                      |
802 +| TABLE_STATISTICS                      |
803  | TRIGGERS                              |
804  | USER_PRIVILEGES                       |
805 +| USER_STATISTICS                       |
806  | VIEWS                                 |
807  +---------------------------------------+
808  Wildcard: inf_rmation_schema
809 diff -r d35bd12bba15 mysys/Makefile.in
810 --- a/mysys/Makefile.in Mon Dec 22 22:51:44 2008 -0800
811 +++ b/mysys/Makefile.in Mon Dec 22 22:53:26 2008 -0800
812 @@ -249,6 +249,7 @@
813  LIBDL = @LIBDL@
814  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
815  LIBOBJS = @LIBOBJS@
816 +LIBRT = @LIBRT@
817  LIBS = @LIBS@
818  LIBTOOL = @LIBTOOL@
819  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
820 diff -r d35bd12bba15 ndb/Makefile.in
821 --- a/ndb/Makefile.in   Mon Dec 22 22:51:44 2008 -0800
822 +++ b/ndb/Makefile.in   Mon Dec 22 22:53:26 2008 -0800
823 @@ -191,6 +191,7 @@
824  LIBDL = @LIBDL@
825  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
826  LIBOBJS = @LIBOBJS@
827 +LIBRT = @LIBRT@
828  LIBS = @LIBS@
829  LIBTOOL = @LIBTOOL@
830  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
831 diff -r d35bd12bba15 ndb/docs/Makefile.in
832 --- a/ndb/docs/Makefile.in      Mon Dec 22 22:51:44 2008 -0800
833 +++ b/ndb/docs/Makefile.in      Mon Dec 22 22:53:26 2008 -0800
834 @@ -172,6 +172,7 @@
835  LIBDL = @LIBDL@
836  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
837  LIBOBJS = @LIBOBJS@
838 +LIBRT = @LIBRT@
839  LIBS = @LIBS@
840  LIBTOOL = @LIBTOOL@
841  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
842 diff -r d35bd12bba15 ndb/include/Makefile.in
843 --- a/ndb/include/Makefile.in   Mon Dec 22 22:51:44 2008 -0800
844 +++ b/ndb/include/Makefile.in   Mon Dec 22 22:53:26 2008 -0800
845 @@ -202,6 +202,7 @@
846  LIBDL = @LIBDL@
847  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
848  LIBOBJS = @LIBOBJS@
849 +LIBRT = @LIBRT@
850  LIBS = @LIBS@
851  LIBTOOL = @LIBTOOL@
852  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
853 diff -r d35bd12bba15 ndb/src/Makefile.in
854 --- a/ndb/src/Makefile.in       Mon Dec 22 22:51:44 2008 -0800
855 +++ b/ndb/src/Makefile.in       Mon Dec 22 22:53:26 2008 -0800
856 @@ -220,6 +220,7 @@
857  LIBDL = @LIBDL@
858  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
859  LIBOBJS = @LIBOBJS@
860 +LIBRT = @LIBRT@
861  LIBS = @LIBS@
862  LIBTOOL = @LIBTOOL@
863  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
864 diff -r d35bd12bba15 ndb/src/common/Makefile.in
865 --- a/ndb/src/common/Makefile.in        Mon Dec 22 22:51:44 2008 -0800
866 +++ b/ndb/src/common/Makefile.in        Mon Dec 22 22:53:26 2008 -0800
867 @@ -193,6 +193,7 @@
868  LIBDL = @LIBDL@
869  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
870  LIBOBJS = @LIBOBJS@
871 +LIBRT = @LIBRT@
872  LIBS = @LIBS@
873  LIBTOOL = @LIBTOOL@
874  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
875 diff -r d35bd12bba15 ndb/src/common/debugger/Makefile.in
876 --- a/ndb/src/common/debugger/Makefile.in       Mon Dec 22 22:51:44 2008 -0800
877 +++ b/ndb/src/common/debugger/Makefile.in       Mon Dec 22 22:53:26 2008 -0800
878 @@ -225,6 +225,7 @@
879  LIBDL = @LIBDL@
880  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
881  LIBOBJS = @LIBOBJS@
882 +LIBRT = @LIBRT@
883  LIBS = @LIBS@
884  LIBTOOL = @LIBTOOL@
885  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
886 diff -r d35bd12bba15 ndb/src/common/debugger/signaldata/Makefile.in
887 --- a/ndb/src/common/debugger/signaldata/Makefile.in    Mon Dec 22 22:51:44 2008 -0800
888 +++ b/ndb/src/common/debugger/signaldata/Makefile.in    Mon Dec 22 22:53:26 2008 -0800
889 @@ -233,6 +233,7 @@
890  LIBDL = @LIBDL@
891  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
892  LIBOBJS = @LIBOBJS@
893 +LIBRT = @LIBRT@
894  LIBS = @LIBS@
895  LIBTOOL = @LIBTOOL@
896  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
897 diff -r d35bd12bba15 ndb/src/common/logger/Makefile.in
898 --- a/ndb/src/common/logger/Makefile.in Mon Dec 22 22:51:44 2008 -0800
899 +++ b/ndb/src/common/logger/Makefile.in Mon Dec 22 22:53:26 2008 -0800
900 @@ -219,6 +219,7 @@
901  LIBDL = @LIBDL@
902  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
903  LIBOBJS = @LIBOBJS@
904 +LIBRT = @LIBRT@
905  LIBS = @LIBS@
906  LIBTOOL = @LIBTOOL@
907  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
908 diff -r d35bd12bba15 ndb/src/common/mgmcommon/Makefile.in
909 --- a/ndb/src/common/mgmcommon/Makefile.in      Mon Dec 22 22:51:44 2008 -0800
910 +++ b/ndb/src/common/mgmcommon/Makefile.in      Mon Dec 22 22:53:26 2008 -0800
911 @@ -233,6 +233,7 @@
912  LIBDL = @LIBDL@
913  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
914  LIBOBJS = @LIBOBJS@
915 +LIBRT = @LIBRT@
916  LIBS = @LIBS@
917  LIBTOOL = @LIBTOOL@
918  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
919 diff -r d35bd12bba15 ndb/src/common/portlib/Makefile.in
920 --- a/ndb/src/common/portlib/Makefile.in        Mon Dec 22 22:51:44 2008 -0800
921 +++ b/ndb/src/common/portlib/Makefile.in        Mon Dec 22 22:53:26 2008 -0800
922 @@ -243,6 +243,7 @@
923  LIBDL = @LIBDL@
924  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
925  LIBOBJS = @LIBOBJS@
926 +LIBRT = @LIBRT@
927  LIBS = @LIBS@
928  LIBTOOL = @LIBTOOL@
929  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
930 diff -r d35bd12bba15 ndb/src/common/transporter/Makefile.in
931 --- a/ndb/src/common/transporter/Makefile.in    Mon Dec 22 22:51:44 2008 -0800
932 +++ b/ndb/src/common/transporter/Makefile.in    Mon Dec 22 22:53:26 2008 -0800
933 @@ -219,6 +219,7 @@
934  LIBDL = @LIBDL@
935  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
936  LIBOBJS = @LIBOBJS@
937 +LIBRT = @LIBRT@
938  LIBS = @LIBS@
939  LIBTOOL = @LIBTOOL@
940  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
941 diff -r d35bd12bba15 ndb/src/common/util/Makefile.in
942 --- a/ndb/src/common/util/Makefile.in   Mon Dec 22 22:51:44 2008 -0800
943 +++ b/ndb/src/common/util/Makefile.in   Mon Dec 22 22:53:26 2008 -0800
944 @@ -235,6 +235,7 @@
945  LIBDL = @LIBDL@
946  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
947  LIBOBJS = @LIBOBJS@
948 +LIBRT = @LIBRT@
949  LIBS = @LIBS@
950  LIBTOOL = @LIBTOOL@
951  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
952 diff -r d35bd12bba15 ndb/src/cw/Makefile.in
953 --- a/ndb/src/cw/Makefile.in    Mon Dec 22 22:51:44 2008 -0800
954 +++ b/ndb/src/cw/Makefile.in    Mon Dec 22 22:53:26 2008 -0800
955 @@ -176,6 +176,7 @@
956  LIBDL = @LIBDL@
957  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
958  LIBOBJS = @LIBOBJS@
959 +LIBRT = @LIBRT@
960  LIBS = @LIBS@
961  LIBTOOL = @LIBTOOL@
962  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
963 diff -r d35bd12bba15 ndb/src/cw/cpcd/Makefile.in
964 --- a/ndb/src/cw/cpcd/Makefile.in       Mon Dec 22 22:51:44 2008 -0800
965 +++ b/ndb/src/cw/cpcd/Makefile.in       Mon Dec 22 22:53:26 2008 -0800
966 @@ -226,6 +226,7 @@
967  LIBDL = @LIBDL@
968  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
969  LIBOBJS = @LIBOBJS@
970 +LIBRT = @LIBRT@
971  LIBS = @LIBS@
972  LIBTOOL = @LIBTOOL@
973  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
974 diff -r d35bd12bba15 ndb/src/kernel/Makefile.in
975 --- a/ndb/src/kernel/Makefile.in        Mon Dec 22 22:51:44 2008 -0800
976 +++ b/ndb/src/kernel/Makefile.in        Mon Dec 22 22:53:26 2008 -0800
977 @@ -246,6 +246,7 @@
978  LIBDL = @LIBDL@
979  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
980  LIBOBJS = @LIBOBJS@
981 +LIBRT = @LIBRT@
982  LIBS = @LIBS@
983  LIBTOOL = @LIBTOOL@
984  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
985 diff -r d35bd12bba15 ndb/src/kernel/blocks/Makefile.in
986 --- a/ndb/src/kernel/blocks/Makefile.in Mon Dec 22 22:51:44 2008 -0800
987 +++ b/ndb/src/kernel/blocks/Makefile.in Mon Dec 22 22:53:26 2008 -0800
988 @@ -176,6 +176,7 @@
989  LIBDL = @LIBDL@
990  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
991  LIBOBJS = @LIBOBJS@
992 +LIBRT = @LIBRT@
993  LIBS = @LIBS@
994  LIBTOOL = @LIBTOOL@
995  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
996 diff -r d35bd12bba15 ndb/src/kernel/blocks/backup/Makefile.in
997 --- a/ndb/src/kernel/blocks/backup/Makefile.in  Mon Dec 22 22:51:44 2008 -0800
998 +++ b/ndb/src/kernel/blocks/backup/Makefile.in  Mon Dec 22 22:53:26 2008 -0800
999 @@ -218,6 +218,7 @@
1000  LIBDL = @LIBDL@
1001  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
1002  LIBOBJS = @LIBOBJS@
1003 +LIBRT = @LIBRT@
1004  LIBS = @LIBS@
1005  LIBTOOL = @LIBTOOL@
1006  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
1007 diff -r d35bd12bba15 ndb/src/kernel/blocks/cmvmi/Makefile.in
1008 --- a/ndb/src/kernel/blocks/cmvmi/Makefile.in   Mon Dec 22 22:51:44 2008 -0800
1009 +++ b/ndb/src/kernel/blocks/cmvmi/Makefile.in   Mon Dec 22 22:53:26 2008 -0800
1010 @@ -218,6 +218,7 @@
1011  LIBDL = @LIBDL@
1012  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
1013  LIBOBJS = @LIBOBJS@
1014 +LIBRT = @LIBRT@
1015  LIBS = @LIBS@
1016  LIBTOOL = @LIBTOOL@
1017  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
1018 diff -r d35bd12bba15 ndb/src/kernel/blocks/dbacc/Makefile.in
1019 --- a/ndb/src/kernel/blocks/dbacc/Makefile.in   Mon Dec 22 22:51:44 2008 -0800
1020 +++ b/ndb/src/kernel/blocks/dbacc/Makefile.in   Mon Dec 22 22:53:26 2008 -0800
1021 @@ -218,6 +218,7 @@
1022  LIBDL = @LIBDL@
1023  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
1024  LIBOBJS = @LIBOBJS@
1025 +LIBRT = @LIBRT@
1026  LIBS = @LIBS@
1027  LIBTOOL = @LIBTOOL@
1028  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
1029 diff -r d35bd12bba15 ndb/src/kernel/blocks/dbdict/Makefile.in
1030 --- a/ndb/src/kernel/blocks/dbdict/Makefile.in  Mon Dec 22 22:51:44 2008 -0800
1031 +++ b/ndb/src/kernel/blocks/dbdict/Makefile.in  Mon Dec 22 22:53:26 2008 -0800
1032 @@ -228,6 +228,7 @@
1033  LIBDL = @LIBDL@
1034  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
1035  LIBOBJS = @LIBOBJS@
1036 +LIBRT = @LIBRT@
1037  LIBS = @LIBS@
1038  LIBTOOL = @LIBTOOL@
1039  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
1040 diff -r d35bd12bba15 ndb/src/kernel/blocks/dbdih/Makefile.in
1041 --- a/ndb/src/kernel/blocks/dbdih/Makefile.in   Mon Dec 22 22:51:44 2008 -0800
1042 +++ b/ndb/src/kernel/blocks/dbdih/Makefile.in   Mon Dec 22 22:53:26 2008 -0800
1043 @@ -225,6 +225,7 @@
1044  LIBDL = @LIBDL@
1045  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
1046  LIBOBJS = @LIBOBJS@
1047 +LIBRT = @LIBRT@
1048  LIBS = @LIBS@
1049  LIBTOOL = @LIBTOOL@
1050  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
1051 diff -r d35bd12bba15 ndb/src/kernel/blocks/dblqh/Makefile.in
1052 --- a/ndb/src/kernel/blocks/dblqh/Makefile.in   Mon Dec 22 22:51:44 2008 -0800
1053 +++ b/ndb/src/kernel/blocks/dblqh/Makefile.in   Mon Dec 22 22:53:26 2008 -0800
1054 @@ -226,6 +226,7 @@
1055  LIBDL = @LIBDL@
1056  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
1057  LIBOBJS = @LIBOBJS@
1058 +LIBRT = @LIBRT@
1059  LIBS = @LIBS@
1060  LIBTOOL = @LIBTOOL@
1061  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
1062 diff -r d35bd12bba15 ndb/src/kernel/blocks/dbtc/Makefile.in
1063 --- a/ndb/src/kernel/blocks/dbtc/Makefile.in    Mon Dec 22 22:51:44 2008 -0800
1064 +++ b/ndb/src/kernel/blocks/dbtc/Makefile.in    Mon Dec 22 22:53:26 2008 -0800
1065 @@ -218,6 +218,7 @@
1066  LIBDL = @LIBDL@
1067  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
1068  LIBOBJS = @LIBOBJS@
1069 +LIBRT = @LIBRT@
1070  LIBS = @LIBS@
1071  LIBTOOL = @LIBTOOL@
1072  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
1073 diff -r d35bd12bba15 ndb/src/kernel/blocks/dbtup/Makefile.in
1074 --- a/ndb/src/kernel/blocks/dbtup/Makefile.in   Mon Dec 22 22:51:44 2008 -0800
1075 +++ b/ndb/src/kernel/blocks/dbtup/Makefile.in   Mon Dec 22 22:53:26 2008 -0800
1076 @@ -226,6 +226,7 @@
1077  LIBDL = @LIBDL@
1078  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
1079  LIBOBJS = @LIBOBJS@
1080 +LIBRT = @LIBRT@
1081  LIBS = @LIBS@
1082  LIBTOOL = @LIBTOOL@
1083  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
1084 diff -r d35bd12bba15 ndb/src/kernel/blocks/dbtux/Makefile.in
1085 --- a/ndb/src/kernel/blocks/dbtux/Makefile.in   Mon Dec 22 22:51:44 2008 -0800
1086 +++ b/ndb/src/kernel/blocks/dbtux/Makefile.in   Mon Dec 22 22:53:26 2008 -0800
1087 @@ -221,6 +221,7 @@
1088  LIBDL = @LIBDL@
1089  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
1090  LIBOBJS = @LIBOBJS@
1091 +LIBRT = @LIBRT@
1092  LIBS = @LIBS@
1093  LIBTOOL = @LIBTOOL@
1094  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
1095 diff -r d35bd12bba15 ndb/src/kernel/blocks/dbutil/Makefile.in
1096 --- a/ndb/src/kernel/blocks/dbutil/Makefile.in  Mon Dec 22 22:51:44 2008 -0800
1097 +++ b/ndb/src/kernel/blocks/dbutil/Makefile.in  Mon Dec 22 22:53:26 2008 -0800
1098 @@ -218,6 +218,7 @@
1099  LIBDL = @LIBDL@
1100  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
1101  LIBOBJS = @LIBOBJS@
1102 +LIBRT = @LIBRT@
1103  LIBS = @LIBS@
1104  LIBTOOL = @LIBTOOL@
1105  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
1106 diff -r d35bd12bba15 ndb/src/kernel/blocks/ndbcntr/Makefile.in
1107 --- a/ndb/src/kernel/blocks/ndbcntr/Makefile.in Mon Dec 22 22:51:44 2008 -0800
1108 +++ b/ndb/src/kernel/blocks/ndbcntr/Makefile.in Mon Dec 22 22:53:26 2008 -0800
1109 @@ -219,6 +219,7 @@
1110  LIBDL = @LIBDL@
1111  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
1112  LIBOBJS = @LIBOBJS@
1113 +LIBRT = @LIBRT@
1114  LIBS = @LIBS@
1115  LIBTOOL = @LIBTOOL@
1116  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
1117 diff -r d35bd12bba15 ndb/src/kernel/blocks/ndbfs/Makefile.in
1118 --- a/ndb/src/kernel/blocks/ndbfs/Makefile.in   Mon Dec 22 22:51:44 2008 -0800
1119 +++ b/ndb/src/kernel/blocks/ndbfs/Makefile.in   Mon Dec 22 22:53:26 2008 -0800
1120 @@ -219,6 +219,7 @@
1121  LIBDL = @LIBDL@
1122  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
1123  LIBOBJS = @LIBOBJS@
1124 +LIBRT = @LIBRT@
1125  LIBS = @LIBS@
1126  LIBTOOL = @LIBTOOL@
1127  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
1128 diff -r d35bd12bba15 ndb/src/kernel/blocks/qmgr/Makefile.in
1129 --- a/ndb/src/kernel/blocks/qmgr/Makefile.in    Mon Dec 22 22:51:44 2008 -0800
1130 +++ b/ndb/src/kernel/blocks/qmgr/Makefile.in    Mon Dec 22 22:53:26 2008 -0800
1131 @@ -218,6 +218,7 @@
1132  LIBDL = @LIBDL@
1133  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
1134  LIBOBJS = @LIBOBJS@
1135 +LIBRT = @LIBRT@
1136  LIBS = @LIBS@
1137  LIBTOOL = @LIBTOOL@
1138  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
1139 diff -r d35bd12bba15 ndb/src/kernel/blocks/suma/Makefile.in
1140 --- a/ndb/src/kernel/blocks/suma/Makefile.in    Mon Dec 22 22:51:44 2008 -0800
1141 +++ b/ndb/src/kernel/blocks/suma/Makefile.in    Mon Dec 22 22:53:26 2008 -0800
1142 @@ -218,6 +218,7 @@
1143  LIBDL = @LIBDL@
1144  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
1145  LIBOBJS = @LIBOBJS@
1146 +LIBRT = @LIBRT@
1147  LIBS = @LIBS@
1148  LIBTOOL = @LIBTOOL@
1149  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
1150 diff -r d35bd12bba15 ndb/src/kernel/blocks/trix/Makefile.in
1151 --- a/ndb/src/kernel/blocks/trix/Makefile.in    Mon Dec 22 22:51:44 2008 -0800
1152 +++ b/ndb/src/kernel/blocks/trix/Makefile.in    Mon Dec 22 22:53:26 2008 -0800
1153 @@ -218,6 +218,7 @@
1154  LIBDL = @LIBDL@
1155  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
1156  LIBOBJS = @LIBOBJS@
1157 +LIBRT = @LIBRT@
1158  LIBS = @LIBS@
1159  LIBTOOL = @LIBTOOL@
1160  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
1161 diff -r d35bd12bba15 ndb/src/kernel/error/Makefile.in
1162 --- a/ndb/src/kernel/error/Makefile.in  Mon Dec 22 22:51:44 2008 -0800
1163 +++ b/ndb/src/kernel/error/Makefile.in  Mon Dec 22 22:53:26 2008 -0800
1164 @@ -227,6 +227,7 @@
1165  LIBDL = @LIBDL@
1166  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
1167  LIBOBJS = @LIBOBJS@
1168 +LIBRT = @LIBRT@
1169  LIBS = @LIBS@
1170  LIBTOOL = @LIBTOOL@
1171  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
1172 diff -r d35bd12bba15 ndb/src/kernel/vm/Makefile.in
1173 --- a/ndb/src/kernel/vm/Makefile.in     Mon Dec 22 22:51:44 2008 -0800
1174 +++ b/ndb/src/kernel/vm/Makefile.in     Mon Dec 22 22:53:26 2008 -0800
1175 @@ -229,6 +229,7 @@
1176  LIBDL = @LIBDL@
1177  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
1178  LIBOBJS = @LIBOBJS@
1179 +LIBRT = @LIBRT@
1180  LIBS = @LIBS@
1181  LIBTOOL = @LIBTOOL@
1182  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
1183 diff -r d35bd12bba15 ndb/src/mgmapi/Makefile.in
1184 --- a/ndb/src/mgmapi/Makefile.in        Mon Dec 22 22:51:44 2008 -0800
1185 +++ b/ndb/src/mgmapi/Makefile.in        Mon Dec 22 22:53:26 2008 -0800
1186 @@ -226,6 +226,7 @@
1187  LIBDL = @LIBDL@
1188  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
1189  LIBOBJS = @LIBOBJS@
1190 +LIBRT = @LIBRT@
1191  LIBS = @LIBS@
1192  LIBTOOL = @LIBTOOL@
1193  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
1194 diff -r d35bd12bba15 ndb/src/mgmclient/Makefile.in
1195 --- a/ndb/src/mgmclient/Makefile.in     Mon Dec 22 22:51:44 2008 -0800
1196 +++ b/ndb/src/mgmclient/Makefile.in     Mon Dec 22 22:53:26 2008 -0800
1197 @@ -236,6 +236,7 @@
1198  LIBDL = @LIBDL@
1199  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
1200  LIBOBJS = @LIBOBJS@
1201 +LIBRT = @LIBRT@
1202  LIBS = @LIBS@
1203  LIBTOOL = @LIBTOOL@
1204  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
1205 diff -r d35bd12bba15 ndb/src/mgmsrv/Makefile.in
1206 --- a/ndb/src/mgmsrv/Makefile.in        Mon Dec 22 22:51:44 2008 -0800
1207 +++ b/ndb/src/mgmsrv/Makefile.in        Mon Dec 22 22:53:26 2008 -0800
1208 @@ -232,6 +232,7 @@
1209  LIBDL = @LIBDL@
1210  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
1211  LIBOBJS = @LIBOBJS@
1212 +LIBRT = @LIBRT@
1213  LIBS = @LIBS@
1214  LIBTOOL = @LIBTOOL@
1215  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
1216 diff -r d35bd12bba15 ndb/src/ndbapi/Makefile.in
1217 --- a/ndb/src/ndbapi/Makefile.in        Mon Dec 22 22:51:44 2008 -0800
1218 +++ b/ndb/src/ndbapi/Makefile.in        Mon Dec 22 22:53:26 2008 -0800
1219 @@ -236,6 +236,7 @@
1220  LIBDL = @LIBDL@
1221  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
1222  LIBOBJS = @LIBOBJS@
1223 +LIBRT = @LIBRT@
1224  LIBS = @LIBS@
1225  LIBTOOL = @LIBTOOL@
1226  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
1227 diff -r d35bd12bba15 ndb/test/Makefile.in
1228 --- a/ndb/test/Makefile.in      Mon Dec 22 22:51:44 2008 -0800
1229 +++ b/ndb/test/Makefile.in      Mon Dec 22 22:53:26 2008 -0800
1230 @@ -176,6 +176,7 @@
1231  LIBDL = @LIBDL@
1232  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
1233  LIBOBJS = @LIBOBJS@
1234 +LIBRT = @LIBRT@
1235  LIBS = @LIBS@
1236  LIBTOOL = @LIBTOOL@
1237  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
1238 diff -r d35bd12bba15 ndb/test/ndbapi/Makefile.in
1239 --- a/ndb/test/ndbapi/Makefile.in       Mon Dec 22 22:51:44 2008 -0800
1240 +++ b/ndb/test/ndbapi/Makefile.in       Mon Dec 22 22:53:26 2008 -0800
1241 @@ -613,6 +613,7 @@
1242  LIBDL = @LIBDL@
1243  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
1244  LIBOBJS = @LIBOBJS@
1245 +LIBRT = @LIBRT@
1246  LIBS = @LIBS@
1247  LIBTOOL = @LIBTOOL@
1248  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
1249 diff -r d35bd12bba15 ndb/test/ndbapi/bank/Makefile.in
1250 --- a/ndb/test/ndbapi/bank/Makefile.in  Mon Dec 22 22:51:44 2008 -0800
1251 +++ b/ndb/test/ndbapi/bank/Makefile.in  Mon Dec 22 22:53:26 2008 -0800
1252 @@ -305,6 +305,7 @@
1253  LIBDL = @LIBDL@
1254  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
1255  LIBOBJS = @LIBOBJS@
1256 +LIBRT = @LIBRT@
1257  LIBS = @LIBS@
1258  LIBTOOL = @LIBTOOL@
1259  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
1260 diff -r d35bd12bba15 ndb/test/run-test/Makefile.in
1261 --- a/ndb/test/run-test/Makefile.in     Mon Dec 22 22:51:44 2008 -0800
1262 +++ b/ndb/test/run-test/Makefile.in     Mon Dec 22 22:53:26 2008 -0800
1263 @@ -264,6 +264,7 @@
1264  LIBDL = @LIBDL@
1265  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
1266  LIBOBJS = @LIBOBJS@
1267 +LIBRT = @LIBRT@
1268  LIBS = @LIBS@
1269  LIBTOOL = @LIBTOOL@
1270  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
1271 diff -r d35bd12bba15 ndb/test/src/Makefile.in
1272 --- a/ndb/test/src/Makefile.in  Mon Dec 22 22:51:44 2008 -0800
1273 +++ b/ndb/test/src/Makefile.in  Mon Dec 22 22:53:26 2008 -0800
1274 @@ -234,6 +234,7 @@
1275  LIBDL = @LIBDL@
1276  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
1277  LIBOBJS = @LIBOBJS@
1278 +LIBRT = @LIBRT@
1279  LIBS = @LIBS@
1280  LIBTOOL = @LIBTOOL@
1281  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
1282 diff -r d35bd12bba15 ndb/test/tools/Makefile.in
1283 --- a/ndb/test/tools/Makefile.in        Mon Dec 22 22:51:44 2008 -0800
1284 +++ b/ndb/test/tools/Makefile.in        Mon Dec 22 22:53:26 2008 -0800
1285 @@ -347,6 +347,7 @@
1286  LIBDL = @LIBDL@
1287  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
1288  LIBOBJS = @LIBOBJS@
1289 +LIBRT = @LIBRT@
1290  LIBS = @LIBS@
1291  LIBTOOL = @LIBTOOL@
1292  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
1293 diff -r d35bd12bba15 ndb/tools/Makefile.in
1294 --- a/ndb/tools/Makefile.in     Mon Dec 22 22:51:44 2008 -0800
1295 +++ b/ndb/tools/Makefile.in     Mon Dec 22 22:53:26 2008 -0800
1296 @@ -333,6 +333,7 @@
1297  LIBDL = @LIBDL@
1298  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
1299  LIBOBJS = @LIBOBJS@
1300 +LIBRT = @LIBRT@
1301  LIBS = @LIBS@
1302  LIBTOOL = @LIBTOOL@
1303  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
1304 diff -r d35bd12bba15 netware/Makefile.in
1305 --- a/netware/Makefile.in       Mon Dec 22 22:51:44 2008 -0800
1306 +++ b/netware/Makefile.in       Mon Dec 22 22:53:26 2008 -0800
1307 @@ -221,6 +221,7 @@
1308  LIBDL = @LIBDL@
1309  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
1310  LIBOBJS = @LIBOBJS@
1311 +LIBRT = @LIBRT@
1312  LIBS = @LIBS@
1313  LIBTOOL = @LIBTOOL@
1314  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
1315 diff -r d35bd12bba15 os2/Makefile.in
1316 --- a/os2/Makefile.in   Mon Dec 22 22:51:44 2008 -0800
1317 +++ b/os2/Makefile.in   Mon Dec 22 22:53:26 2008 -0800
1318 @@ -176,6 +176,7 @@
1319  LIBDL = @LIBDL@
1320  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
1321  LIBOBJS = @LIBOBJS@
1322 +LIBRT = @LIBRT@
1323  LIBS = @LIBS@
1324  LIBTOOL = @LIBTOOL@
1325  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
1326 diff -r d35bd12bba15 os2/include/Makefile.in
1327 --- a/os2/include/Makefile.in   Mon Dec 22 22:51:44 2008 -0800
1328 +++ b/os2/include/Makefile.in   Mon Dec 22 22:53:26 2008 -0800
1329 @@ -176,6 +176,7 @@
1330  LIBDL = @LIBDL@
1331  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
1332  LIBOBJS = @LIBOBJS@
1333 +LIBRT = @LIBRT@
1334  LIBS = @LIBS@
1335  LIBTOOL = @LIBTOOL@
1336  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
1337 diff -r d35bd12bba15 os2/include/sys/Makefile.in
1338 --- a/os2/include/sys/Makefile.in       Mon Dec 22 22:51:44 2008 -0800
1339 +++ b/os2/include/sys/Makefile.in       Mon Dec 22 22:53:26 2008 -0800
1340 @@ -167,6 +167,7 @@
1341  LIBDL = @LIBDL@
1342  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
1343  LIBOBJS = @LIBOBJS@
1344 +LIBRT = @LIBRT@
1345  LIBS = @LIBS@
1346  LIBTOOL = @LIBTOOL@
1347  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
1348 diff -r d35bd12bba15 patch_info/userstats.info
1349 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
1350 +++ b/patch_info/userstats.info Mon Dec 22 22:53:26 2008 -0800
1351 @@ -0,0 +1,14 @@
1352 +File=userstatsv2.patch
1353 +Name=SHOW USER/TABLE/INDEX statistics
1354 +Version=V2
1355 +Author=Google
1356 +License=GPL
1357 +Comment=Added INFORMATION_SCHEMA.*_STATISTICS
1358 +2008-12-01
1359 +YK: fix behavior for prepared statements
1360 +
1361 +2008-11-26
1362 +YK: add switch variable "userstat_running" to control INFORMATION_SCHEMA.*_STATISTICS (default:OFF)
1363 +
1364 +2008-12-09
1365 +YK: fixed "Row_sent: 0" problem at microslow_innodb.patch
1366 diff -r d35bd12bba15 pstack/Makefile.in
1367 --- a/pstack/Makefile.in        Mon Dec 22 22:51:44 2008 -0800
1368 +++ b/pstack/Makefile.in        Mon Dec 22 22:53:26 2008 -0800
1369 @@ -215,6 +215,7 @@
1370  LIBDL = @LIBDL@
1371  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
1372  LIBOBJS = @LIBOBJS@
1373 +LIBRT = @LIBRT@
1374  LIBS = @LIBS@
1375  LIBTOOL = @LIBTOOL@
1376  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
1377 diff -r d35bd12bba15 pstack/aout/Makefile.in
1378 --- a/pstack/aout/Makefile.in   Mon Dec 22 22:51:44 2008 -0800
1379 +++ b/pstack/aout/Makefile.in   Mon Dec 22 22:53:26 2008 -0800
1380 @@ -157,6 +157,7 @@
1381  LIBDL = @LIBDL@
1382  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
1383  LIBOBJS = @LIBOBJS@
1384 +LIBRT = @LIBRT@
1385  LIBS = @LIBS@
1386  LIBTOOL = @LIBTOOL@
1387  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
1388 diff -r d35bd12bba15 regex/Makefile.in
1389 --- a/regex/Makefile.in Mon Dec 22 22:51:44 2008 -0800
1390 +++ b/regex/Makefile.in Mon Dec 22 22:53:26 2008 -0800
1391 @@ -199,6 +199,7 @@
1392  LIBDL = @LIBDL@
1393  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
1394  LIBOBJS = @LIBOBJS@
1395 +LIBRT = @LIBRT@
1396  LIBS = @LIBS@
1397  LIBTOOL = @LIBTOOL@
1398  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
1399 diff -r d35bd12bba15 scripts/Makefile.in
1400 --- a/scripts/Makefile.in       Mon Dec 22 22:51:44 2008 -0800
1401 +++ b/scripts/Makefile.in       Mon Dec 22 22:53:26 2008 -0800
1402 @@ -198,6 +198,7 @@
1403  LIBDL = @LIBDL@
1404  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
1405  LIBOBJS = @LIBOBJS@
1406 +LIBRT = @LIBRT@
1407  LIBS = @LIBS@
1408  LIBTOOL = @LIBTOOL@
1409  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
1410 diff -r d35bd12bba15 server-tools/Makefile.in
1411 --- a/server-tools/Makefile.in  Mon Dec 22 22:51:44 2008 -0800
1412 +++ b/server-tools/Makefile.in  Mon Dec 22 22:53:26 2008 -0800
1413 @@ -175,6 +175,7 @@
1414  LIBDL = @LIBDL@
1415  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
1416  LIBOBJS = @LIBOBJS@
1417 +LIBRT = @LIBRT@
1418  LIBS = @LIBS@
1419  LIBTOOL = @LIBTOOL@
1420  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
1421 diff -r d35bd12bba15 server-tools/instance-manager/Makefile.in
1422 --- a/server-tools/instance-manager/Makefile.in Mon Dec 22 22:51:44 2008 -0800
1423 +++ b/server-tools/instance-manager/Makefile.in Mon Dec 22 22:53:26 2008 -0800
1424 @@ -223,6 +223,7 @@
1425  LIBDL = @LIBDL@
1426  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
1427  LIBOBJS = @LIBOBJS@
1428 +LIBRT = @LIBRT@
1429  LIBS = @LIBS@
1430  LIBTOOL = @LIBTOOL@
1431  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
1432 diff -r d35bd12bba15 sql/Makefile.in
1433 --- a/sql/Makefile.in   Mon Dec 22 22:51:44 2008 -0800
1434 +++ b/sql/Makefile.in   Mon Dec 22 22:53:26 2008 -0800
1435 @@ -285,6 +285,7 @@
1436  LIBDL = @LIBDL@
1437  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
1438  LIBOBJS = @LIBOBJS@
1439 +LIBRT = @LIBRT@
1440  LIBS = @LIBS@
1441  LIBTOOL = @LIBTOOL@
1442  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
1443 diff -r d35bd12bba15 sql/ha_innodb.cc
1444 --- a/sql/ha_innodb.cc  Mon Dec 22 22:51:44 2008 -0800
1445 +++ b/sql/ha_innodb.cc  Mon Dec 22 22:53:26 2008 -0800
1446 @@ -3316,6 +3316,8 @@
1447  
1448         error = row_insert_for_mysql((byte*) record, prebuilt);
1449  
1450 +        if (error == DB_SUCCESS) rows_changed++;
1451 +
1452         if (error == DB_SUCCESS && auto_inc_used) {
1453  
1454                 /* Fetch the value that was set in the autoincrement field */
1455 @@ -3588,6 +3590,8 @@
1456                 }
1457         }
1458  
1459 +       if (error == DB_SUCCESS) rows_changed++;
1460 +
1461         innodb_srv_conc_exit_innodb(prebuilt->trx);
1462  
1463         error = convert_error_code_to_mysql(error, user_thd);
1464 @@ -3635,6 +3639,8 @@
1465         innodb_srv_conc_enter_innodb(prebuilt->trx);
1466  
1467         error = row_update_for_mysql((byte*) record, prebuilt);
1468 +
1469 +       if (error == DB_SUCCESS) rows_changed++;
1470  
1471         innodb_srv_conc_exit_innodb(prebuilt->trx);
1472  
1473 @@ -4068,6 +4074,9 @@
1474         if (ret == DB_SUCCESS) {
1475                 error = 0;
1476                 table->status = 0;
1477 +                rows_read++;
1478 +                if (active_index >= 0 && active_index < MAX_KEY)
1479 +                        index_rows_read[active_index]++;
1480  
1481         } else if (ret == DB_RECORD_NOT_FOUND) {
1482                 error = HA_ERR_END_OF_FILE;
1483 diff -r d35bd12bba15 sql/ha_myisam.cc
1484 --- a/sql/ha_myisam.cc  Mon Dec 22 22:51:44 2008 -0800
1485 +++ b/sql/ha_myisam.cc  Mon Dec 22 22:53:26 2008 -0800
1486 @@ -670,7 +670,9 @@
1487      if ((error= update_auto_increment()))
1488        return error;
1489    }
1490 -  return mi_write(file,buf);
1491 +  int error=mi_write(file,buf);
1492 +  if (!error) rows_changed++;
1493 +  return error;
1494  }
1495  
1496  int ha_myisam::check(THD* thd, HA_CHECK_OPT* check_opt)
1497 @@ -1518,13 +1520,17 @@
1498    statistic_increment(table->in_use->status_var.ha_update_count,&LOCK_status);
1499    if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_UPDATE)
1500      table->timestamp_field->set_time();
1501 -  return mi_update(file,old_data,new_data);
1502 +  int error=mi_update(file,old_data,new_data);
1503 +  if (!error) rows_changed++;
1504 +  return error;
1505  }
1506  
1507  int ha_myisam::delete_row(const byte * buf)
1508  {
1509    statistic_increment(table->in_use->status_var.ha_delete_count,&LOCK_status);
1510 -  return mi_delete(file,buf);
1511 +  int error=mi_delete(file,buf);
1512 +  if (!error) rows_changed++;
1513 +  return error;
1514  }
1515  
1516  int ha_myisam::index_read(byte * buf, const byte * key,
1517 @@ -1535,6 +1541,13 @@
1518                       &LOCK_status);
1519    int error=mi_rkey(file,buf,active_index, key, key_len, find_flag);
1520    table->status=error ? STATUS_NOT_FOUND: 0;
1521 +  if (!error) {
1522 +    rows_read++;
1523 +
1524 +    int inx = (active_index == -1) ? file->lastinx : active_index;
1525 +    if (inx >= 0 && inx < MAX_KEY)
1526 +      index_rows_read[inx]++;
1527 +  }
1528    return error;
1529  }
1530  
1531 @@ -1545,6 +1558,13 @@
1532                       &LOCK_status);
1533    int error=mi_rkey(file,buf,index, key, key_len, find_flag);
1534    table->status=error ? STATUS_NOT_FOUND: 0;
1535 +  if (!error) {
1536 +    rows_read++;
1537 +
1538 +    int inx = index;
1539 +    if (inx >= 0 && inx < MAX_KEY)
1540 +      index_rows_read[inx]++;
1541 +  }
1542    return error;
1543  }
1544  
1545 @@ -1555,6 +1575,13 @@
1546                       &LOCK_status);
1547    int error=mi_rkey(file,buf,active_index, key, key_len, HA_READ_PREFIX_LAST);
1548    table->status=error ? STATUS_NOT_FOUND: 0;
1549 +  if (!error) {
1550 +    rows_read++;
1551 +
1552 +    int inx = (active_index == -1) ? file->lastinx : active_index;
1553 +    if (inx >= 0 && inx < MAX_KEY)
1554 +      index_rows_read[inx]++;
1555 +  }
1556    return error;
1557  }
1558  
1559 @@ -1565,6 +1592,13 @@
1560                       &LOCK_status);
1561    int error=mi_rnext(file,buf,active_index);
1562    table->status=error ? STATUS_NOT_FOUND: 0;
1563 +  if (!error) {
1564 +    rows_read++;
1565 +
1566 +    int inx = (active_index == -1) ? file->lastinx : active_index;
1567 +    if (inx >= 0 && inx < MAX_KEY)
1568 +      index_rows_read[inx]++;
1569 +  }
1570    return error;
1571  }
1572  
1573 @@ -1575,6 +1609,13 @@
1574                       &LOCK_status);
1575    int error=mi_rprev(file,buf, active_index);
1576    table->status=error ? STATUS_NOT_FOUND: 0;
1577 +  if (!error) {
1578 +    rows_read++;
1579 +
1580 +    int inx = (active_index == -1) ? file->lastinx : active_index;
1581 +    if (inx >= 0 && inx < MAX_KEY)
1582 +      index_rows_read[inx]++;
1583 +  }
1584    return error;
1585  }
1586  
1587 @@ -1585,6 +1626,13 @@
1588                       &LOCK_status);
1589    int error=mi_rfirst(file, buf, active_index);
1590    table->status=error ? STATUS_NOT_FOUND: 0;
1591 +  if (!error) {
1592 +    rows_read++;
1593 +
1594 +    int inx = (active_index == -1) ? file->lastinx : active_index;
1595 +    if (inx >= 0 && inx < MAX_KEY)
1596 +      index_rows_read[inx]++;
1597 +  }
1598    return error;
1599  }
1600  
1601 @@ -1595,6 +1643,13 @@
1602                       &LOCK_status);
1603    int error=mi_rlast(file, buf, active_index);
1604    table->status=error ? STATUS_NOT_FOUND: 0;
1605 +  if (!error) {
1606 +    rows_read++;
1607 +
1608 +    int inx = (active_index == -1) ? file->lastinx : active_index;
1609 +    if (inx >= 0 && inx < MAX_KEY)
1610 +      index_rows_read[inx]++;
1611 +  }
1612    return error;
1613  }
1614  
1615 @@ -1611,6 +1666,13 @@
1616      error= mi_rnext_same(file,buf);
1617    } while (error == HA_ERR_RECORD_DELETED);
1618    table->status=error ? STATUS_NOT_FOUND: 0;
1619 +  if (!error) {
1620 +    rows_read++;
1621 +
1622 +    int inx = (active_index == -1) ? file->lastinx : active_index;
1623 +    if (inx >= 0 && inx < MAX_KEY)
1624 +      index_rows_read[inx]++;
1625 +  }
1626    return error;
1627  }
1628  
1629 @@ -1628,6 +1690,7 @@
1630                       &LOCK_status);
1631    int error=mi_scan(file, buf);
1632    table->status=error ? STATUS_NOT_FOUND: 0;
1633 +  if (!error) rows_read++;
1634    return error;
1635  }
1636  
1637 @@ -1642,6 +1705,7 @@
1638                       &LOCK_status);
1639    int error=mi_rrnd(file, buf, my_get_ptr(pos,ref_length));
1640    table->status=error ? STATUS_NOT_FOUND: 0;
1641 +  if (!error) rows_read++;
1642    return error;
1643  }
1644  
1645 diff -r d35bd12bba15 sql/handler.cc
1646 --- a/sql/handler.cc    Mon Dec 22 22:51:44 2008 -0800
1647 +++ b/sql/handler.cc    Mon Dec 22 22:53:26 2008 -0800
1648 @@ -725,6 +725,8 @@
1649      if (cookie)
1650        tc_log->unlog(cookie, xid);
1651      DBUG_EXECUTE_IF("crash_commit_after", abort(););
1652 +    if (is_real_trans)
1653 +      thd->diff_commit_trans++;
1654  end:
1655      if (is_real_trans)
1656        start_waiting_global_read_lock(thd);
1657 @@ -829,6 +831,7 @@
1658        thd->transaction.cleanup();
1659      }
1660    }
1661 +  thd->diff_rollback_trans++;
1662  #endif /* USING_TRANSACTIONS */
1663    if (all)
1664      thd->transaction_rollback_request= FALSE;
1665 @@ -1212,6 +1215,7 @@
1666      statistic_increment(thd->status_var.ha_rollback_count,&LOCK_status);
1667      *ht=0; // keep it conveniently zero-filled
1668    }
1669 +  thd->diff_rollback_trans++;
1670    DBUG_RETURN(error);
1671  }
1672  
1673 @@ -1442,6 +1446,8 @@
1674      else
1675        dupp_ref=ref+ALIGN_SIZE(ref_length);
1676    }
1677 +  rows_read = rows_changed = 0;
1678 +  memset(index_rows_read, 0, sizeof(index_rows_read));
1679    DBUG_RETURN(error);
1680  }
1681  
1682 @@ -2276,6 +2282,111 @@
1683    return error;
1684  }
1685  
1686 +// Updates the global table stats with the TABLE this handler represents.
1687 +void handler::update_global_table_stats() {
1688 +  if (!opt_userstat_running) {
1689 +    rows_read = rows_changed = 0;
1690 +    return;
1691 +  }
1692 +
1693 +  if (!rows_read && !rows_changed) return;  // Nothing to update.
1694 +  // table_cache_key is db_name + '\0' + table_name + '\0'.
1695 +  if (!table->s || !table->s->table_cache_key || !table->s->table_name) return;
1696 +
1697 +  TABLE_STATS* table_stats;
1698 +  char key[NAME_LEN * 2 + 2];
1699 +  // [db] + '.' + [table]
1700 +  sprintf(key, "%s.%s", table->s->table_cache_key, table->s->table_name);
1701 +
1702 +  pthread_mutex_lock(&LOCK_global_table_stats);
1703 +  // Gets the global table stats, creating one if necessary.
1704 +  if (!(table_stats = (TABLE_STATS*)hash_search(&global_table_stats,
1705 +                                                (byte*)key,
1706 +                                                strlen(key)))) {
1707 +    if (!(table_stats = ((TABLE_STATS*)
1708 +                         my_malloc(sizeof(TABLE_STATS), MYF(MY_WME | MY_ZEROFILL))))) {
1709 +      // Out of memory.
1710 +      sql_print_error("Allocating table stats failed.");
1711 +      goto end;
1712 +    }
1713 +    strncpy(table_stats->table, key, sizeof(table_stats->table));
1714 +    table_stats->rows_read = 0;
1715 +    table_stats->rows_changed = 0;
1716 +    table_stats->rows_changed_x_indexes = 0;
1717 +    table_stats->engine_type = (int) ht->db_type;
1718 +
1719 +    if (my_hash_insert(&global_table_stats, (byte*)table_stats)) {
1720 +      // Out of memory.
1721 +      sql_print_error("Inserting table stats failed.");
1722 +      my_free((char*)table_stats, 0);
1723 +      goto end;
1724 +    }
1725 +  }
1726 +  // Updates the global table stats.
1727 +  table_stats->rows_read += rows_read;
1728 +  table_stats->rows_changed += rows_changed;
1729 +  table_stats->rows_changed_x_indexes +=
1730 +      rows_changed * (table->s->keys ? table->s->keys : 1);
1731 +  current_thd->diff_total_read_rows += rows_read;
1732 +  rows_read = rows_changed = 0;
1733 +end:
1734 +  pthread_mutex_unlock(&LOCK_global_table_stats);
1735 +}
1736 +
1737 +// Updates the global index stats with this handler's accumulated index reads.
1738 +void handler::update_global_index_stats() {
1739 +  // table_cache_key is db_name + '\0' + table_name + '\0'.
1740 +  if (!table->s || !table->s->table_cache_key || !table->s->table_name) return;
1741 +
1742 +  if (!opt_userstat_running) {
1743 +    for (int x = 0; x < table->s->keys; x++) {
1744 +      index_rows_read[x] = 0;
1745 +    }
1746 +    return;
1747 +  }
1748 +
1749 +  for (int x = 0; x < table->s->keys; x++) {
1750 +    if (index_rows_read[x]) {
1751 +      // Rows were read using this index.
1752 +      KEY* key_info = &table->key_info[x];
1753 +
1754 +      if (!key_info->name) continue;
1755 +
1756 +      INDEX_STATS* index_stats;
1757 +      char key[NAME_LEN * 3 + 3];
1758 +      // [db] + '.' + [table] + '.' + [index]
1759 +      sprintf(key, "%s.%s.%s",  table->s->table_cache_key,
1760 +              table->s->table_name, key_info->name);
1761 +
1762 +      pthread_mutex_lock(&LOCK_global_index_stats);
1763 +      // Gets the global index stats, creating one if necessary.
1764 +      if (!(index_stats = (INDEX_STATS*)hash_search(&global_index_stats,
1765 +                                                    (byte*)key,
1766 +                                                    strlen(key)))) {
1767 +        if (!(index_stats = ((INDEX_STATS*)
1768 +                             my_malloc(sizeof(INDEX_STATS), MYF(MY_WME | MY_ZEROFILL))))) {
1769 +          // Out of memory.
1770 +          sql_print_error("Allocating index stats failed.");
1771 +          goto end;
1772 +        }
1773 +        strncpy(index_stats->index, key, sizeof(index_stats->index));
1774 +        index_stats->rows_read = 0;
1775 +
1776 +        if (my_hash_insert(&global_index_stats, (byte*)index_stats)) {
1777 +          // Out of memory.
1778 +          sql_print_error("Inserting index stats failed.");
1779 +          my_free((char*)index_stats, 0);
1780 +          goto end;
1781 +        }
1782 +      }
1783 +      // Updates the global index stats.
1784 +      index_stats->rows_read += index_rows_read[x];
1785 +      index_rows_read[x] = 0;
1786 +end:
1787 +      pthread_mutex_unlock(&LOCK_global_index_stats);
1788 +    }
1789 +  }
1790 +}
1791  
1792  /****************************************************************************
1793  ** Some general functions that isn't in the handler class
1794 diff -r d35bd12bba15 sql/handler.h
1795 --- a/sql/handler.h     Mon Dec 22 22:51:44 2008 -0800
1796 +++ b/sql/handler.h     Mon Dec 22 22:53:26 2008 -0800
1797 @@ -30,6 +30,10 @@
1798  #if defined(HAVE_BERKELEY_DB) || defined(HAVE_INNOBASE_DB) || \
1799      defined(HAVE_NDBCLUSTER_DB)
1800  #define USING_TRANSACTIONS
1801 +#endif
1802 +
1803 +#if MAX_KEY > 128
1804 +#error MAX_KEY is too large.  Values up to 128 are supported.
1805  #endif
1806  
1807  // the following is for checking tables
1808 @@ -604,6 +608,9 @@
1809    bool  auto_increment_column_changed;
1810    bool implicit_emptied;                /* Can be !=0 only if HEAP */
1811    const COND *pushed_cond;
1812 +  ulonglong rows_read;
1813 +  ulonglong rows_changed;
1814 +  ulonglong index_rows_read[MAX_KEY];
1815  
1816    handler(const handlerton *ht_arg, TABLE *table_arg) :table(table_arg),
1817      ht(ht_arg),
1818 @@ -615,8 +622,10 @@
1819      ref_length(sizeof(my_off_t)), block_size(0),
1820      raid_type(0), ft_handler(0), inited(NONE),
1821      locked(FALSE), implicit_emptied(0),
1822 -    pushed_cond(NULL)
1823 -    {}
1824 +    pushed_cond(NULL), rows_read(0), rows_changed(0)
1825 +    {
1826 +      memset(index_rows_read, 0, sizeof(index_rows_read));
1827 +    }
1828    virtual ~handler(void) { DBUG_ASSERT(locked == FALSE); /* TODO: DBUG_ASSERT(inited == NONE); */ }
1829    virtual handler *clone(MEM_ROOT *mem_root);
1830    int ha_open(const char *name, int mode, int test_if_locked);
1831 @@ -625,7 +634,11 @@
1832    virtual void print_error(int error, myf errflag);
1833    virtual bool get_error_message(int error, String *buf);
1834    uint get_dup_key(int error);
1835 -  void change_table_ptr(TABLE *table_arg) { table=table_arg; }
1836 +  void change_table_ptr(TABLE *table_arg) {
1837 +    table=table_arg;
1838 +    rows_read = rows_changed = 0;
1839 +    memset(index_rows_read, 0, sizeof(index_rows_read));
1840 +  }
1841    virtual double scan_time()
1842      { return ulonglong2double(data_file_length) / IO_SIZE + 2; }
1843    virtual double read_time(uint index, uint ranges, ha_rows rows)
1844 @@ -886,6 +899,9 @@
1845    virtual bool is_crashed() const  { return 0; }
1846    virtual bool auto_repair() const { return 0; }
1847  
1848 +  void update_global_table_stats();
1849 +  void update_global_index_stats();
1850 +
1851    /*
1852      default rename_table() and delete_table() rename/delete files with a
1853      given name and extensions from bas_ext()
1854 diff -r d35bd12bba15 sql/lex.h
1855 --- a/sql/lex.h Mon Dec 22 22:51:44 2008 -0800
1856 +++ b/sql/lex.h Mon Dec 22 22:53:26 2008 -0800
1857 @@ -109,6 +109,7 @@
1858    { "CHECKSUM",                SYM(CHECKSUM_SYM)},
1859    { "CIPHER",          SYM(CIPHER_SYM)},
1860    { "CLIENT",          SYM(CLIENT_SYM)},
1861 +  { "CLIENT_STATISTICS", SYM(CLIENT_STATS_SYM)},
1862    { "CLOSE",           SYM(CLOSE_SYM)},
1863    { "CODE",             SYM(CODE_SYM)},
1864    { "COLLATE",         SYM(COLLATE_SYM)},
1865 @@ -238,6 +239,7 @@
1866    { "IN",              SYM(IN_SYM)},
1867    { "INDEX",           SYM(INDEX_SYM)},
1868    { "INDEXES",         SYM(INDEXES)},
1869 +  { "INDEX_STATISTICS",        SYM(INDEX_STATS_SYM)},
1870    { "INFILE",          SYM(INFILE)},
1871    { "INNER",           SYM(INNER_SYM)},
1872    { "INNOBASE",                SYM(INNOBASE_SYM)},
1873 @@ -443,6 +445,7 @@
1874    { "SIGNED",          SYM(SIGNED_SYM)},
1875    { "SIMPLE",          SYM(SIMPLE_SYM)},
1876    { "SLAVE",            SYM(SLAVE)},
1877 +  { "SLOW",             SYM(SLOW_SYM)},
1878    { "SNAPSHOT",         SYM(SNAPSHOT_SYM)},
1879    { "SMALLINT",                SYM(SMALLINT)},
1880    { "SOME",             SYM(ANY_SYM)},
1881 @@ -488,6 +491,7 @@
1882    { "TABLE",           SYM(TABLE_SYM)},
1883    { "TABLES",          SYM(TABLES)},
1884    { "TABLESPACE",      SYM(TABLESPACE)},
1885 +  { "TABLE_STATISTICS",        SYM(TABLE_STATS_SYM)},
1886    { "TEMPORARY",       SYM(TEMPORARY)},
1887    { "TEMPTABLE",       SYM(TEMPTABLE_SYM)},
1888    { "TERMINATED",      SYM(TERMINATED)},
1889 @@ -525,6 +529,7 @@
1890    { "USE",             SYM(USE_SYM)},
1891    { "USER",            SYM(USER)},
1892    { "USER_RESOURCES",  SYM(RESOURCES)},
1893 +  { "USER_STATISTICS", SYM(USER_STATS_SYM)},
1894    { "USE_FRM",         SYM(USE_FRM)},
1895    { "USING",           SYM(USING)},
1896    { "UTC_DATE",         SYM(UTC_DATE_SYM)},
1897 diff -r d35bd12bba15 sql/log.cc
1898 --- a/sql/log.cc        Mon Dec 22 22:51:44 2008 -0800
1899 +++ b/sql/log.cc        Mon Dec 22 22:53:26 2008 -0800
1900 @@ -1899,18 +1899,24 @@
1901                            thd->current_insert_id);
1902         if (e.write(file))
1903           goto err;
1904 +        if (file == &log_file)
1905 +          thd->binlog_bytes_written += e.data_written;
1906        }
1907        if (thd->insert_id_used)
1908        {
1909         Intvar_log_event e(thd,(uchar) INSERT_ID_EVENT,thd->last_insert_id);
1910         if (e.write(file))
1911           goto err;
1912 +        if (file == &log_file)
1913 +          thd->binlog_bytes_written += e.data_written;
1914        }
1915        if (thd->rand_used)
1916        {
1917         Rand_log_event e(thd,thd->rand_saved_seed1,thd->rand_saved_seed2);
1918         if (e.write(file))
1919           goto err;
1920 +        if (file == &log_file)
1921 +          thd->binlog_bytes_written += e.data_written;
1922        }
1923        if (thd->user_var_events.elements)
1924        {
1925 @@ -1926,6 +1932,8 @@
1926                                user_var_event->charset_number);
1927           if (e.write(file))
1928             goto err;
1929 +         if (file == &log_file)
1930 +                 thd->binlog_bytes_written += e.data_written;
1931         }
1932        }
1933      }
1934 @@ -1936,6 +1944,8 @@
1935  
1936      if (event_info->write(file))
1937        goto err;
1938 +    if (file == &log_file)
1939 +           thd->binlog_bytes_written += event_info->data_written;
1940  
1941      if (file == &log_file) // we are writing to the real log (disk)
1942      {
1943 @@ -2057,6 +2067,7 @@
1944      */
1945      if (qinfo.write(&log_file))
1946        goto err;
1947 +    thd->binlog_bytes_written += qinfo.data_written;
1948  
1949      /* Read from the file used to cache the queries .*/
1950      if (reinit_io_cache(cache, READ_CACHE, 0, 0, 0))
1951 @@ -2103,6 +2114,7 @@
1952          /* write the first half of the split header */
1953          if (my_b_write(&log_file, header, carry))
1954            goto err;
1955 +        thd->binlog_bytes_written += carry;
1956  
1957          /*
1958            copy fixed second half of header to cache so the correct
1959 @@ -2171,6 +2183,8 @@
1960        /* Write data to the binary log file */
1961        if (my_b_write(&log_file, cache->read_pos, length))
1962          goto err;
1963 +      thd->binlog_bytes_written += length;
1964 +
1965        cache->read_pos=cache->read_end;         // Mark buffer used up
1966        DBUG_EXECUTE_IF("half_binlogged_transaction", goto DBUG_skip_commit;);
1967      } while ((length=my_b_fill(cache)));
1968 @@ -2179,6 +2193,8 @@
1969  
1970      if (commit_event->write(&log_file))
1971        goto err;
1972 +    thd->binlog_bytes_written += commit_event->data_written;
1973 +
1974  #ifndef DBUG_OFF
1975  DBUG_skip_commit:
1976  #endif
1977 diff -r d35bd12bba15 sql/mysql_priv.h
1978 --- a/sql/mysql_priv.h  Mon Dec 22 22:51:44 2008 -0800
1979 +++ b/sql/mysql_priv.h  Mon Dec 22 22:53:26 2008 -0800
1980 @@ -818,7 +818,15 @@
1981  bool multi_delete_set_locks_and_link_aux_tables(LEX *lex);
1982  void init_max_user_conn(void);
1983  void init_update_queries(void);
1984 +void init_global_user_stats(void);
1985 +void init_global_table_stats(void);
1986 +void init_global_index_stats(void);
1987 +void init_global_client_stats(void);
1988  void free_max_user_conn(void);
1989 +void free_global_user_stats(void);
1990 +void free_global_table_stats(void);
1991 +void free_global_index_stats(void);
1992 +void free_global_client_stats(void);
1993  pthread_handler_t handle_one_connection(void *arg);
1994  pthread_handler_t handle_bootstrap(void *arg);
1995  void end_thread(THD *thd,bool put_in_cache);
1996 @@ -1396,6 +1404,7 @@
1997  extern ulong max_connections,max_connect_errors, connect_timeout;
1998  extern ulong slave_net_timeout, slave_trans_retries;
1999  extern uint max_user_connections;
2000 +extern ulonglong denied_connections;
2001  extern ulong what_to_log,flush_time;
2002  extern ulong query_buff_size, thread_stack;
2003  extern ulong max_prepared_stmt_count, prepared_stmt_count;
2004 @@ -1426,6 +1435,7 @@
2005  extern my_bool opt_safe_show_db, opt_local_infile;
2006  extern my_bool opt_slave_compressed_protocol, use_temp_pool;
2007  extern my_bool opt_readonly, lower_case_file_system;
2008 +extern my_bool opt_userstat_running;
2009  extern my_bool opt_enable_named_pipe, opt_sync_frm, opt_allow_suspicious_udfs;
2010  extern my_bool opt_secure_auth;
2011  extern char* opt_secure_file_priv;
2012 @@ -1472,6 +1482,14 @@
2013  extern struct system_variables max_system_variables;
2014  extern struct system_status_var global_status_var;
2015  extern struct rand_struct sql_rand;
2016 +extern HASH global_user_stats;
2017 +extern HASH global_client_stats;
2018 +extern pthread_mutex_t LOCK_global_user_client_stats;
2019 +extern HASH global_table_stats;
2020 +extern pthread_mutex_t LOCK_global_table_stats;
2021 +extern HASH global_index_stats;
2022 +extern pthread_mutex_t LOCK_global_index_stats;
2023 +extern pthread_mutex_t LOCK_stats;
2024  
2025  extern const char *opt_date_time_formats[];
2026  extern KNOWN_DATE_TIME_FORMAT known_date_time_formats[];
2027 diff -r d35bd12bba15 sql/mysqld.cc
2028 --- a/sql/mysqld.cc     Mon Dec 22 22:51:44 2008 -0800
2029 +++ b/sql/mysqld.cc     Mon Dec 22 22:53:26 2008 -0800
2030 @@ -414,6 +414,7 @@
2031  uint    opt_large_page_size= 0;
2032  my_bool opt_old_style_user_limits= 0, trust_function_creators= 0;
2033  char* opt_slow_logname= 0;
2034 +my_bool opt_userstat_running= 0;
2035  /*
2036    True if there is at least one per-hour limit for some user, so we should
2037    check them before each query (and possibly reset counters when hour is
2038 @@ -450,6 +451,7 @@
2039  ulong binlog_cache_use= 0, binlog_cache_disk_use= 0;
2040  ulong max_connections, max_connect_errors;
2041  uint  max_user_connections= 0;
2042 +ulonglong denied_connections = 0;
2043  /*
2044    Limit of the total number of prepared statements in the server.
2045    Is necessary to protect the server against out-of-memory attacks.
2046 @@ -550,6 +552,10 @@
2047                 LOCK_crypt, LOCK_bytes_sent, LOCK_bytes_received,
2048                 LOCK_global_system_variables,
2049                 LOCK_user_conn, LOCK_slave_list, LOCK_active_mi;
2050 +pthread_mutex_t LOCK_stats;
2051 +pthread_mutex_t LOCK_global_user_client_stats;
2052 +pthread_mutex_t LOCK_global_table_stats;
2053 +pthread_mutex_t LOCK_global_index_stats;
2054  /*
2055    The below lock protects access to two global server variables:
2056    max_prepared_stmt_count and prepared_stmt_count. These variables
2057 @@ -1191,6 +1197,10 @@
2058    x_free(opt_secure_file_priv);
2059    bitmap_free(&temp_pool);
2060    free_max_user_conn();
2061 +  free_global_user_stats();
2062 +  free_global_client_stats();
2063 +  free_global_table_stats();
2064 +  free_global_index_stats();
2065  #ifdef HAVE_REPLICATION
2066    end_slave_list();
2067    free_list(&replicate_do_db);
2068 @@ -1305,6 +1315,10 @@
2069    (void) pthread_cond_destroy(&COND_thread_cache);
2070    (void) pthread_cond_destroy(&COND_flush_thread_cache);
2071    (void) pthread_cond_destroy(&COND_manager);
2072 +  (void) pthread_mutex_destroy(&LOCK_stats);
2073 +  (void) pthread_mutex_destroy(&LOCK_global_user_client_stats);
2074 +  (void) pthread_mutex_destroy(&LOCK_global_table_stats);
2075 +  (void) pthread_mutex_destroy(&LOCK_global_index_stats);
2076  }
2077  
2078  #endif /*EMBEDDED_LIBRARY*/
2079 @@ -3152,6 +3166,10 @@
2080    (void) pthread_mutex_init(&LOCK_rpl_status, MY_MUTEX_INIT_FAST);
2081    (void) pthread_cond_init(&COND_rpl_status, NULL);
2082  #endif
2083 +  (void) pthread_mutex_init(&LOCK_stats, MY_MUTEX_INIT_FAST);
2084 +  (void) pthread_mutex_init(&LOCK_global_user_client_stats, MY_MUTEX_INIT_FAST);
2085 +  (void) pthread_mutex_init(&LOCK_global_table_stats, MY_MUTEX_INIT_FAST);
2086 +  (void) pthread_mutex_init(&LOCK_global_index_stats, MY_MUTEX_INIT_FAST);
2087    sp_cache_init();
2088    /* Parameter for threads created for connections */
2089    (void) pthread_attr_init(&connection_attrib);
2090 @@ -3423,6 +3441,10 @@
2091      sql_print_error("Out of memory");
2092      unireg_abort(1);
2093    }
2094 +
2095 +  init_global_table_stats();
2096 +  init_global_index_stats();
2097 +
2098    if (ha_init())
2099    {
2100      sql_print_error("Can't init databases");
2101 @@ -3505,6 +3527,8 @@
2102  
2103    init_max_user_conn();
2104    init_update_queries();
2105 +  init_global_user_stats();
2106 +  init_global_client_stats();
2107    DBUG_RETURN(0);
2108  }
2109  
2110 @@ -4189,6 +4213,7 @@
2111    {
2112      DBUG_PRINT("error",("Too many connections"));
2113      close_connection(thd, ER_CON_COUNT_ERROR, 1);
2114 +    statistic_increment(denied_connections, &LOCK_status);
2115      delete thd;
2116      DBUG_VOID_RETURN;
2117    }
2118 @@ -5007,6 +5032,7 @@
2119    OPT_PROFILING,
2120    OPT_SLOW_LOG,
2121    OPT_SLOW_QUERY_LOG_FILE,
2122 +  OPT_USERSTAT_RUNNING,
2123    OPT_INNODB_ROLLBACK_ON_TIMEOUT,
2124    OPT_SECURE_FILE_PRIV,
2125    OPT_KEEP_FILES_ON_CREATE,
2126 @@ -6450,6 +6476,10 @@
2127     (gptr*) &max_system_variables.net_wait_timeout, 0, GET_ULONG,
2128     REQUIRED_ARG, NET_WAIT_TIMEOUT, 1, IF_WIN(INT_MAX32/1000, LONG_TIMEOUT),
2129     0, 1, 0},
2130 +  {"userstat_running", OPT_USERSTAT_RUNNING,
2131 +   "Control USER_STATISTICS, CLIENT_STATISTICS, INDEX_STATISTICS and TABLE_STATISTICS running",
2132 +   (gptr*) &opt_userstat_running, (gptr*) &opt_userstat_running,
2133 +   0, GET_BOOL, NO_ARG, 0, 0, 1, 0, 1, 0},
2134    {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
2135  };
2136  
2137 diff -r d35bd12bba15 sql/set_var.cc
2138 --- a/sql/set_var.cc    Mon Dec 22 22:51:44 2008 -0800
2139 +++ b/sql/set_var.cc    Mon Dec 22 22:53:26 2008 -0800
2140 @@ -323,6 +323,7 @@
2141  sys_var_thd_ulong      sys_read_buff_size("read_buffer_size",
2142                                            &SV::read_buff_size);
2143  sys_var_bool_ptr       sys_readonly("read_only", &opt_readonly);
2144 +sys_var_bool_ptr       sys_userstat_running("userstat_running", &opt_userstat_running);
2145  sys_var_thd_ulong      sys_read_rnd_buff_size("read_rnd_buffer_size",
2146                                                &SV::read_rnd_buff_size);
2147  sys_var_thd_ulong      sys_div_precincrement("div_precision_increment",
2148 @@ -825,6 +826,7 @@
2149    &sys_trans_alloc_block_size,
2150    &sys_trans_prealloc_size,
2151    &sys_tx_isolation,
2152 +  &sys_userstat_running,
2153    &sys_version,
2154  #ifdef HAVE_BERKELEY_DB
2155    &sys_version_bdb,
2156 @@ -1171,6 +1173,7 @@
2157    {sys_tx_isolation.name,     (char*) &sys_tx_isolation,           SHOW_SYS},
2158    {sys_updatable_views_with_limit.name,
2159                                (char*) &sys_updatable_views_with_limit,SHOW_SYS},
2160 +  {sys_userstat_running.name, (char*) &sys_userstat_running,        SHOW_SYS},
2161    {sys_version.name,          (char*) &sys_version,                 SHOW_SYS},
2162  #ifdef HAVE_BERKELEY_DB
2163    {sys_version_bdb.name,      (char*) &sys_version_bdb,             SHOW_SYS},
2164 diff -r d35bd12bba15 sql/share/Makefile.in
2165 --- a/sql/share/Makefile.in     Mon Dec 22 22:51:44 2008 -0800
2166 +++ b/sql/share/Makefile.in     Mon Dec 22 22:53:26 2008 -0800
2167 @@ -167,6 +167,7 @@
2168  LIBDL = @LIBDL@
2169  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
2170  LIBOBJS = @LIBOBJS@
2171 +LIBRT = @LIBRT@
2172  LIBS = @LIBS@
2173  LIBTOOL = @LIBTOOL@
2174  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
2175 diff -r d35bd12bba15 sql/sql_base.cc
2176 --- a/sql/sql_base.cc   Mon Dec 22 22:51:44 2008 -0800
2177 +++ b/sql/sql_base.cc   Mon Dec 22 22:53:26 2008 -0800
2178 @@ -624,6 +624,12 @@
2179    DBUG_ENTER("close_thread_table");
2180    DBUG_ASSERT(table->key_read == 0);
2181    DBUG_ASSERT(!table->file || table->file->inited == handler::NONE);
2182 +  
2183 +  if(table->file)
2184 +  {
2185 +    table->file->update_global_table_stats();
2186 +    table->file->update_global_index_stats();
2187 +  }
2188  
2189    *table_ptr=table->next;
2190    if (table->needs_reopen_or_name_lock() ||
2191 @@ -670,6 +676,9 @@
2192  {
2193    DBUG_ENTER("close_temporary");
2194    char path[FN_REFLEN];
2195 +
2196 +  table->file->update_global_table_stats();
2197 +  table->file->update_global_index_stats();
2198    db_type table_type=table->s->db_type;
2199    strmov(path,table->s->path);
2200    free_io_cache(table);
2201 diff -r d35bd12bba15 sql/sql_class.cc
2202 --- a/sql/sql_class.cc  Mon Dec 22 22:51:44 2008 -0800
2203 +++ b/sql/sql_class.cc  Mon Dec 22 22:53:26 2008 -0800
2204 @@ -236,6 +236,13 @@
2205    bzero(ha_data, sizeof(ha_data));
2206    mysys_var=0;
2207    binlog_evt_union.do_union= FALSE;
2208 +  busy_time = 0;
2209 +  cpu_time = 0;
2210 +  bytes_received = 0;
2211 +  bytes_sent = 0;
2212 +  binlog_bytes_written = 0;
2213 +  updated_row_count = 0;
2214 +  sent_row_count_2 = 0;
2215  #ifndef DBUG_OFF
2216    dbug_sentry=THD_SENTRY_MAGIC;
2217  #endif
2218 @@ -369,6 +376,88 @@
2219    total_warn_count= 0;
2220    update_charset();
2221    bzero((char *) &status_var, sizeof(status_var));
2222 +  reset_stats();
2223 +}
2224 +
2225 +// Resets stats in a THD.
2226 +void THD::reset_stats(void) {
2227 +  current_connect_time = time(NULL);
2228 +  last_global_update_time = current_connect_time;
2229 +  reset_diff_stats();
2230 +}
2231 +
2232 +// Resets the 'diff' stats, which are used to update global stats.
2233 +void THD::reset_diff_stats(void) {
2234 +  diff_total_busy_time = 0;
2235 +  diff_total_cpu_time = 0;
2236 +  diff_total_bytes_received = 0;
2237 +  diff_total_bytes_sent = 0;
2238 +  diff_total_binlog_bytes_written = 0;
2239 +  diff_total_sent_rows = 0;
2240 +  diff_total_updated_rows = 0;
2241 +  diff_total_read_rows = 0;
2242 +  diff_select_commands = 0;
2243 +  diff_update_commands = 0;
2244 +  diff_other_commands = 0;
2245 +  diff_commit_trans = 0;
2246 +  diff_rollback_trans = 0;
2247 +  diff_denied_connections = 0;
2248 +  diff_lost_connections = 0;
2249 +  diff_access_denied_errors = 0;
2250 +  diff_empty_queries = 0;
2251 +}
2252 +
2253 +// Updates 'diff' stats of a THD.
2254 +void THD::update_stats(bool ran_command) {
2255 +  if (opt_userstat_running) {
2256 +  diff_total_busy_time += busy_time;
2257 +  diff_total_cpu_time += cpu_time;
2258 +  diff_total_bytes_received += bytes_received;
2259 +  diff_total_bytes_sent += bytes_sent;
2260 +  diff_total_binlog_bytes_written += binlog_bytes_written;
2261 +  diff_total_sent_rows += sent_row_count_2;
2262 +  diff_total_updated_rows += updated_row_count;
2263 +  // diff_total_read_rows is updated in handler.cc.
2264 +
2265 +  if (ran_command) {
2266 +    // The replication thread has the COM_CONNECT command.
2267 +    if ((old_command == COM_QUERY || command == COM_CONNECT) &&
2268 +        (lex->sql_command >= 0 && lex->sql_command < SQLCOM_END)) {
2269 +      // A SQL query.
2270 +      if (lex->sql_command == SQLCOM_SELECT) {
2271 +        if (lex->orig_sql_command == SQLCOM_END) {
2272 +          diff_select_commands++;
2273 +          if (!sent_row_count_2)
2274 +            diff_empty_queries++;
2275 +        } else {
2276 +          // 'SHOW ' commands become SQLCOM_SELECT.
2277 +          diff_other_commands++;
2278 +          // 'SHOW ' commands shouldn't inflate total sent row count.
2279 +          diff_total_sent_rows -= sent_row_count_2;
2280 +        }
2281 +      } else if (is_update_query(lex->sql_command)) {
2282 +        diff_update_commands++;
2283 +      } else {
2284 +        diff_other_commands++;
2285 +      }
2286 +    }
2287 +  }
2288 +  // diff_commit_trans is updated in handler.cc.
2289 +  // diff_rollback_trans is updated in handler.cc.
2290 +  // diff_denied_connections is updated in sql_parse.cc.
2291 +  // diff_lost_connections is updated in sql_parse.cc.
2292 +  // diff_access_denied_errors is updated in sql_parse.cc.
2293 +
2294 +  /* reset counters to zero to avoid double-counting since values
2295 +     are already store in diff_total_*. */
2296 +  }
2297 +  busy_time = 0;
2298 +  cpu_time = 0;
2299 +  bytes_received = 0;
2300 +  bytes_sent = 0;
2301 +  binlog_bytes_written = 0;
2302 +  updated_row_count = 0;
2303 +  sent_row_count_2 = 0;
2304  }
2305  
2306  
2307 @@ -408,6 +497,9 @@
2308  
2309  void THD::change_user(void)
2310  {
2311 +  pthread_mutex_lock(&LOCK_status);
2312 +  add_to_status(&global_status_var, &status_var);
2313 +  pthread_mutex_unlock(&LOCK_status);
2314    cleanup();
2315    cleanup_done= 0;
2316    init();
2317 @@ -892,6 +984,33 @@
2318  }
2319  #endif
2320  
2321 +char *THD::get_client_host_port(THD *client)
2322 +{
2323 +  Security_context *client_sctx= client->security_ctx;
2324 +  char *client_host= NULL;
2325 +
2326 +  if (client->peer_port && (client_sctx->host || client_sctx->ip) &&
2327 +      security_ctx->host_or_ip[0])
2328 +  {
2329 +    if ((client_host= this->alloc(LIST_PROCESS_HOST_LEN+1)))
2330 +      my_snprintf((char *) client_host, LIST_PROCESS_HOST_LEN,
2331 +                  "%s:%u", client_sctx->host_or_ip, client->peer_port);
2332 +  }
2333 +  else
2334 +    client_host= this->strdup(client_sctx->host_or_ip[0] ?
2335 +                              client_sctx->host_or_ip :
2336 +                              client_sctx->host ? client_sctx->host : "");
2337 +
2338 +  return client_host;
2339 +}
2340 +
2341 +const char *get_client_host(THD *client)
2342 +{
2343 +  return client->security_ctx->host_or_ip[0] ?
2344 +      client->security_ctx->host_or_ip :
2345 +      client->security_ctx->host ? client->security_ctx->host : "";
2346 +}
2347 +
2348  
2349  struct Item_change_record: public ilink
2350  {
2351 @@ -1062,6 +1181,7 @@
2352      }
2353    }
2354    thd->sent_row_count++;
2355 +  thd->sent_row_count_2++;
2356    if (!thd->vio_ok())
2357      DBUG_RETURN(0);
2358    if (!thd->net.report_error)
2359 @@ -1154,6 +1274,7 @@
2360  select_export::~select_export()
2361  {
2362    thd->sent_row_count=row_count;
2363 +  thd->sent_row_count_2=row_count;
2364  }
2365  
2366  
2367 @@ -2088,6 +2209,7 @@
2368    if (likely(thd != 0))
2369    { /* current_thd==0 when close_connection() calls net_send_error() */
2370      thd->status_var.bytes_sent+= length;
2371 +    thd->bytes_sent+= length;
2372    }
2373  }
2374  
2375 @@ -2095,6 +2217,7 @@
2376  void thd_increment_bytes_received(ulong length)
2377  {
2378    current_thd->status_var.bytes_received+= length;
2379 +  current_thd->bytes_received+= length;
2380  }
2381  
2382  
2383 diff -r d35bd12bba15 sql/sql_class.h
2384 --- a/sql/sql_class.h   Mon Dec 22 22:51:44 2008 -0800
2385 +++ b/sql/sql_class.h   Mon Dec 22 22:53:26 2008 -0800
2386 @@ -1292,6 +1292,8 @@
2387      first byte of the packet in do_command()
2388    */
2389    enum enum_server_command command;
2390 +  // Used to save the command, before it is set to COM_SLEEP.
2391 +  enum enum_server_command old_command;
2392    uint32     server_id;
2393    uint32     file_id;                  // for LOAD DATA INFILE
2394    /*
2395 @@ -1481,6 +1483,8 @@
2396    /* variables.transaction_isolation is reset to this after each commit */
2397    enum_tx_isolation session_tx_isolation;
2398    enum_check_fields count_cuted_fields;
2399 +  ha_rows    updated_row_count;
2400 +  ha_rows    sent_row_count_2; /* for userstat */
2401  
2402    DYNAMIC_ARRAY user_var_events;        /* For user variables replication */
2403    MEM_ROOT      *user_var_events_alloc; /* Allocate above array elements here */
2404 @@ -1587,6 +1591,49 @@
2405    */
2406    LOG_INFO*  current_linfo;
2407    NET*       slave_net;                        // network connection from slave -> m.
2408 +
2409 +  /*
2410 +    Used to update global user stats.  The global user stats are updated
2411 +    occasionally with the 'diff' variables.  After the update, the 'diff'
2412 +    variables are reset to 0.
2413 +   */
2414 +  // Time when the current thread connected to MySQL.
2415 +  time_t current_connect_time;
2416 +  // Last time when THD stats were updated in global_user_stats.
2417 +  time_t last_global_update_time;
2418 +  // Busy (non-idle) time for just one command.
2419 +  double busy_time;
2420 +  // Busy time not updated in global_user_stats yet.
2421 +  double diff_total_busy_time;
2422 +  // Cpu (non-idle) time for just one thread.
2423 +  double cpu_time;
2424 +  // Cpu time not updated in global_user_stats yet.
2425 +  double diff_total_cpu_time;
2426 +  /* bytes counting */
2427 +  ulonglong bytes_received;
2428 +  ulonglong diff_total_bytes_received;
2429 +  ulonglong bytes_sent;
2430 +  ulonglong diff_total_bytes_sent;
2431 +  ulonglong binlog_bytes_written;
2432 +  ulonglong diff_total_binlog_bytes_written;
2433 +
2434 +  // Number of rows not reflected in global_user_stats yet.
2435 +  ha_rows diff_total_sent_rows, diff_total_updated_rows, diff_total_read_rows;
2436 +  // Number of commands not reflected in global_user_stats yet.
2437 +  ulonglong diff_select_commands, diff_update_commands, diff_other_commands;
2438 +  // Number of transactions not reflected in global_user_stats yet.
2439 +  ulonglong diff_commit_trans, diff_rollback_trans;
2440 +  // Number of connection errors not reflected in global_user_stats yet.
2441 +  ulonglong diff_denied_connections, diff_lost_connections;
2442 +  // Number of db access denied, not reflected in global_user_stats yet.
2443 +  ulonglong diff_access_denied_errors;
2444 +  // Number of queries that return 0 rows
2445 +  ulonglong diff_empty_queries;
2446 +
2447 +  // Per account query delay in miliseconds. When not 0, sleep this number of
2448 +  // milliseconds before every SQL command.
2449 +  ulonglong query_delay_millis;
2450 +
2451    /* Used by the sys_var class to store temporary values */
2452    union
2453    {
2454 @@ -1642,6 +1689,11 @@
2455      alloc_root.
2456    */
2457    void init_for_queries();
2458 +  void reset_stats(void);
2459 +  void reset_diff_stats(void);
2460 +  // ran_command is true when this is called immediately after a
2461 +  // command has been run.
2462 +  void update_stats(bool ran_command);
2463    void change_user(void);
2464    void cleanup(void);
2465    void cleanup_after_query();
2466 @@ -1871,7 +1923,13 @@
2467      if (p_db_length)
2468        *p_db_length= db_length;
2469      return FALSE;
2470 +
2471 +  // Returns string as 'IP:port' for the client-side of the connnection represented
2472 +  // by 'client' as displayed by SHOW PROCESSLIST. Allocates memory from the heap of
2473 +  // this THD and that is not reclaimed immediately, so use sparingly. May return NULL.
2474    }
2475 +
2476 +  char *get_client_host_port(THD *client);
2477  
2478  public:
2479    /**
2480 @@ -1915,6 +1973,11 @@
2481    MEM_ROOT main_mem_root;
2482  };
2483  
2484 +// Returns string as 'IP' for the client-side of the connection represented by
2485 +// 'client'. Does not allocate memory. May return "".
2486 +const char *get_client_host(THD *client);
2487 +
2488 +#define LIST_PROCESS_HOST_LEN 64
2489  
2490  #define tmp_disable_binlog(A)       \
2491    {ulonglong tmp_disable_binlog__save_options= (A)->options; \
2492 diff -r d35bd12bba15 sql/sql_delete.cc
2493 --- a/sql/sql_delete.cc Mon Dec 22 22:51:44 2008 -0800
2494 +++ b/sql/sql_delete.cc Mon Dec 22 22:53:26 2008 -0800
2495 @@ -358,6 +358,7 @@
2496      send_ok(thd,deleted);
2497      DBUG_PRINT("info",("%ld records deleted",(long) deleted));
2498    }
2499 +  thd->updated_row_count += deleted;
2500    DBUG_RETURN(error >= 0 || thd->net.report_error);
2501  }
2502  
2503 @@ -869,6 +870,7 @@
2504      thd->row_count_func= deleted;
2505      ::send_ok(thd, deleted);
2506    }
2507 +  thd->updated_row_count += deleted;
2508    return 0;
2509  }
2510  
2511 diff -r d35bd12bba15 sql/sql_insert.cc
2512 --- a/sql/sql_insert.cc Mon Dec 22 22:51:44 2008 -0800
2513 +++ b/sql/sql_insert.cc Mon Dec 22 22:53:26 2008 -0800
2514 @@ -989,6 +989,7 @@
2515      thd->row_count_func= info.copied + info.deleted + updated;
2516      ::send_ok(thd, (ulong) thd->row_count_func, id, buff);
2517    }
2518 +  thd->updated_row_count += thd->row_count_func;
2519    thd->abort_on_warning= 0;
2520    DBUG_RETURN(FALSE);
2521  
2522 @@ -3036,6 +3037,7 @@
2523      autoinc_value_of_first_inserted_row : thd->insert_id_used ?
2524      thd->last_insert_id : 0;
2525    ::send_ok(thd, (ulong) thd->row_count_func, id, buff);
2526 +  thd->updated_row_count += thd->row_count_func;
2527    DBUG_RETURN(0);
2528  }
2529  
2530 diff -r d35bd12bba15 sql/sql_lex.h
2531 --- a/sql/sql_lex.h     Mon Dec 22 22:51:44 2008 -0800
2532 +++ b/sql/sql_lex.h     Mon Dec 22 22:53:26 2008 -0800
2533 @@ -101,6 +101,9 @@
2534      When a command is added here, be sure it's also added in mysqld.cc
2535      in "struct show_var_st status_vars[]= {" ...
2536    */
2537 +  // TODO(mcallaghan): update status_vars in mysqld to export these
2538 +  SQLCOM_SHOW_USER_STATS, SQLCOM_SHOW_TABLE_STATS, SQLCOM_SHOW_INDEX_STATS,
2539 +  SQLCOM_SHOW_CLIENT_STATS,
2540    /* This should be the last !!! */
2541    SQLCOM_END
2542  };
2543 diff -r d35bd12bba15 sql/sql_parse.cc
2544 --- a/sql/sql_parse.cc  Mon Dec 22 22:51:44 2008 -0800
2545 +++ b/sql/sql_parse.cc  Mon Dec 22 22:53:26 2008 -0800
2546 @@ -78,6 +78,12 @@
2547                                const char *table_name);
2548  static bool check_show_create_table_access(THD *thd, TABLE_LIST *table);
2549  
2550 +// Increments connection count for user.
2551 +static int increment_connection_count(THD* thd, bool use_lock);
2552 +
2553 +// Uses the THD to update the global stats by user name and client IP
2554 +void update_global_user_stats(THD* thd, bool create_user, time_t now);
2555 +
2556  const char *any_db="*any*";    // Special symbol for check_access
2557  
2558  const char *command_name[]={
2559 @@ -145,6 +151,17 @@
2560  #ifndef EMBEDDED_LIBRARY
2561  static bool do_command(THD *thd);
2562  #endif // EMBEDDED_LIBRARY
2563 +
2564 +HASH global_user_stats;
2565 +HASH global_client_stats;
2566 +// Protects global_user_stats and global_client_stats
2567 +extern pthread_mutex_t LOCK_global_user_client_stats;
2568 +
2569 +HASH global_table_stats;
2570 +extern pthread_mutex_t LOCK_global_table_stats;
2571 +
2572 +HASH global_index_stats;
2573 +extern pthread_mutex_t LOCK_global_index_stats;
2574  
2575  #ifdef __WIN__
2576  extern void win_install_sigabrt_handler(void);
2577 @@ -504,6 +521,7 @@
2578      mysql_log.write(thd,COM_CONNECT,ER(ER_NOT_SUPPORTED_AUTH_MODE));
2579      DBUG_RETURN(-1);
2580    }
2581 +  thd->diff_access_denied_errors++;
2582    net_printf_error(thd, ER_ACCESS_DENIED_ERROR,
2583                     thd->main_security_ctx.user,
2584                     thd->main_security_ctx.host_or_ip,
2585 @@ -536,12 +554,190 @@
2586  void init_max_user_conn(void)
2587  {
2588  #ifndef NO_EMBEDDED_ACCESS_CHECKS
2589 -  (void) hash_init(&hash_user_connections,system_charset_info,max_connections,
2590 -                  0,0,
2591 -                  (hash_get_key) get_key_conn, (hash_free_key) free_user,
2592 -                  0);
2593 -#endif
2594 -}
2595 +  if (hash_init(&hash_user_connections,system_charset_info,max_connections,
2596 +                0,0,
2597 +                (hash_get_key) get_key_conn, (hash_free_key) free_user,
2598 +                0)) {
2599 +    sql_print_error("Initializing hash_user_connections failed.");
2600 +    exit(1);
2601 +  }
2602 +#endif
2603 +}
2604 +
2605 +byte *get_key_user_stats(USER_STATS *user_stats, uint *length,
2606 +                         my_bool not_used __attribute__((unused)))
2607 +{
2608 +  *length = strlen(user_stats->user);
2609 +  return (byte*)user_stats->user;
2610 +}
2611 +
2612 +void free_user_stats(USER_STATS* user_stats)
2613 +{
2614 +  my_free((char*)user_stats, MYF(0));
2615 +}
2616 +
2617 +void init_user_stats(USER_STATS *user_stats,
2618 +                     const char *user,
2619 +                     const char *priv_user,
2620 +                     uint total_connections,
2621 +                     uint concurrent_connections,
2622 +                     time_t connected_time,
2623 +                     double busy_time,
2624 +                     double cpu_time,
2625 +                     ulonglong bytes_received,
2626 +                     ulonglong bytes_sent,
2627 +                     ulonglong binlog_bytes_written,
2628 +                     ha_rows rows_fetched,
2629 +                     ha_rows rows_updated,
2630 +                     ha_rows rows_read,
2631 +                     ulonglong select_commands,
2632 +                     ulonglong update_commands,
2633 +                     ulonglong other_commands,
2634 +                     ulonglong commit_trans,
2635 +                     ulonglong rollback_trans,
2636 +                     ulonglong denied_connections,
2637 +                     ulonglong lost_connections,
2638 +                     ulonglong access_denied_errors,
2639 +                     ulonglong empty_queries)
2640 +{
2641 +  DBUG_ENTER("init_user_stats");
2642 +  DBUG_PRINT("info",
2643 +             ("Add user_stats entry for user %s - priv_user %s",
2644 +              user, priv_user));
2645 +  strncpy(user_stats->user, user, sizeof(user_stats->user));
2646 +  strncpy(user_stats->priv_user, priv_user, sizeof(user_stats->priv_user));
2647 +
2648 +  user_stats->total_connections = total_connections;
2649 +  user_stats->concurrent_connections = concurrent_connections;
2650 +  user_stats->connected_time = connected_time;
2651 +  user_stats->busy_time = busy_time;
2652 +  user_stats->cpu_time = cpu_time;
2653 +  user_stats->bytes_received = bytes_received;
2654 +  user_stats->bytes_sent = bytes_sent;
2655 +  user_stats->binlog_bytes_written = binlog_bytes_written;
2656 +  user_stats->rows_fetched = rows_fetched;
2657 +  user_stats->rows_updated = rows_updated;
2658 +  user_stats->rows_read = rows_read;
2659 +  user_stats->select_commands = select_commands;
2660 +  user_stats->update_commands = update_commands;
2661 +  user_stats->other_commands = other_commands;
2662 +  user_stats->commit_trans = commit_trans;
2663 +  user_stats->rollback_trans = rollback_trans;
2664 +  user_stats->denied_connections = denied_connections;
2665 +  user_stats->lost_connections = lost_connections;
2666 +  user_stats->access_denied_errors = access_denied_errors;
2667 +  user_stats->empty_queries = empty_queries;
2668 +  DBUG_VOID_RETURN;
2669 +}
2670 +
2671 +void add_user_stats(USER_STATS *user_stats,
2672 +                    uint total_connections,
2673 +                    uint concurrent_connections,
2674 +                    time_t connected_time,
2675 +                    double busy_time,
2676 +                    double cpu_time,
2677 +                    ulonglong bytes_received,
2678 +                    ulonglong bytes_sent,
2679 +                    ulonglong binlog_bytes_written,
2680 +                    ha_rows rows_fetched,
2681 +                    ha_rows rows_updated,
2682 +                    ha_rows rows_read,
2683 +                    ulonglong select_commands,
2684 +                    ulonglong update_commands,
2685 +                    ulonglong other_commands,
2686 +                    ulonglong commit_trans,
2687 +                    ulonglong rollback_trans,
2688 +                    ulonglong denied_connections,
2689 +                    ulonglong lost_connections,
2690 +                    ulonglong access_denied_errors,
2691 +                    ulonglong empty_queries)
2692 +{
2693 +  user_stats->total_connections += total_connections;
2694 +  user_stats->concurrent_connections += concurrent_connections;
2695 +  user_stats->connected_time += connected_time;
2696 +  user_stats->busy_time += busy_time;
2697 +  user_stats->cpu_time += cpu_time;
2698 +  user_stats->bytes_received += bytes_received;
2699 +  user_stats->bytes_sent += bytes_sent;
2700 +  user_stats->binlog_bytes_written += binlog_bytes_written;
2701 +  user_stats->rows_fetched += rows_fetched;
2702 +  user_stats->rows_updated += rows_updated;
2703 +  user_stats->rows_read += rows_read;
2704 +  user_stats->select_commands += select_commands;
2705 +  user_stats->update_commands += update_commands;
2706 +  user_stats->other_commands += other_commands;
2707 +  user_stats->commit_trans += commit_trans;
2708 +  user_stats->rollback_trans += rollback_trans;
2709 +  user_stats->denied_connections += denied_connections;
2710 +  user_stats->lost_connections += lost_connections;
2711 +  user_stats->access_denied_errors += access_denied_errors;
2712 +  user_stats->empty_queries += empty_queries;
2713 +}
2714 +
2715 +void init_global_user_stats(void)
2716 +{
2717 +  if (hash_init(&global_user_stats, system_charset_info, max_connections,
2718 +                0, 0, (hash_get_key)get_key_user_stats,
2719 +                (hash_free_key)free_user_stats, 0)) {
2720 +    sql_print_error("Initializing global_user_stats failed.");
2721 +    exit(1);
2722 +  }
2723 +}
2724 +
2725 +void init_global_client_stats(void)
2726 +{
2727 +  if (hash_init(&global_client_stats, system_charset_info, max_connections,
2728 +                0, 0, (hash_get_key)get_key_user_stats,
2729 +                (hash_free_key)free_user_stats, 0)) {
2730 +    sql_print_error("Initializing global_client_stats failed.");
2731 +    exit(1);
2732 +  }
2733 +}
2734 +
2735 +extern "C" byte *get_key_table_stats(TABLE_STATS *table_stats, uint *length,
2736 +                                     my_bool not_used __attribute__((unused)))
2737 +{
2738 +  *length = strlen(table_stats->table);
2739 +  return (byte*)table_stats->table;
2740 +}
2741 +
2742 +extern "C" void free_table_stats(TABLE_STATS* table_stats)
2743 +{
2744 +  my_free((char*)table_stats, MYF(0));
2745 +}
2746 +
2747 +void init_global_table_stats(void)
2748 +{
2749 +  if (hash_init(&global_table_stats, system_charset_info, max_connections,
2750 +                0, 0, (hash_get_key)get_key_table_stats,
2751 +                (hash_free_key)free_table_stats, 0)) {
2752 +    sql_print_error("Initializing global_table_stats failed.");
2753 +    exit(1);
2754 +  }
2755 +}
2756 +
2757 +extern "C" byte *get_key_index_stats(INDEX_STATS *index_stats, uint *length,
2758 +                                     my_bool not_used __attribute__((unused)))
2759 +{
2760 +  *length = strlen(index_stats->index);
2761 +  return (byte*)index_stats->index;
2762 +}
2763 +
2764 +extern "C" void free_index_stats(INDEX_STATS* index_stats)
2765 +{
2766 +  my_free((char*)index_stats, MYF(0));
2767 +}
2768 +
2769 +void init_global_index_stats(void)
2770 +{
2771 +  if (hash_init(&global_index_stats, system_charset_info, max_connections,
2772 +                0, 0, (hash_get_key)get_key_index_stats,
2773 +                (hash_free_key)free_index_stats, 0)) {
2774 +    sql_print_error("Initializing global_index_stats failed.");
2775 +    exit(1);
2776 +  }
2777 +}
2778 +
2779  
2780  
2781  /*
2782 @@ -599,7 +795,10 @@
2783  
2784    end:
2785    if (error)
2786 +  {
2787 +    statistic_increment(denied_connections, &LOCK_status);
2788      uc->connections--; // no need for decrease_user_connections() here
2789 +  }
2790    (void) pthread_mutex_unlock(&LOCK_user_conn);
2791    DBUG_RETURN(error);
2792  }
2793 @@ -646,6 +845,25 @@
2794  #endif /* NO_EMBEDDED_ACCESS_CHECKS */
2795  }
2796  
2797 +void free_global_user_stats(void)
2798 +{
2799 +  hash_free(&global_user_stats);
2800 +}
2801 +
2802 +void free_global_table_stats(void)
2803 +{
2804 +  hash_free(&global_table_stats);
2805 +}
2806 +
2807 +void free_global_index_stats(void)
2808 +{
2809 +  hash_free(&global_index_stats);
2810 +}
2811 +
2812 +void free_global_client_stats(void)
2813 +{
2814 +  hash_free(&global_client_stats);
2815 +}
2816  
2817  
2818  /*
2819 @@ -698,6 +916,214 @@
2820    return uc_update_queries[command] != 0;
2821  }
2822  
2823 +// 'mysql_system_user' is used for when the user is not defined for a THD.
2824 +static char mysql_system_user[] = "#mysql_system#";
2825 +
2826 +// Returns 'user' if it's not NULL.  Returns 'mysql_system_user' otherwise.
2827 +static char* get_valid_user_string(char* user) {
2828 +  return user ? user : mysql_system_user;
2829 +}
2830 +
2831 +// Increments the global stats connection count for an entry from
2832 +// global_client_stats or global_user_stats. Returns 0 on success
2833 +// and 1 on error.
2834 +static int increment_count_by_name(const char *name, const char *role_name,
2835 +                                   HASH *users_or_clients, THD *thd)
2836 +{
2837 +  USER_STATS* user_stats;
2838 +
2839 +  if (!(user_stats = (USER_STATS*)hash_search(users_or_clients, name,
2840 +                                              strlen(name))))
2841 +  {
2842 +    // First connection for this user or client
2843 +    if (!(user_stats = ((USER_STATS*)
2844 +                        my_malloc(sizeof(USER_STATS), MYF(MY_WME | MY_ZEROFILL)))))
2845 +    {
2846 +      return 1; // Out of memory
2847 +    }
2848 +
2849 +    init_user_stats(user_stats, name, role_name,
2850 +                    0, 0,      // connections
2851 +                    0, 0, 0,   // time
2852 +                    0, 0, 0,   // bytes sent, received and written
2853 +                    0, 0, 0,   // rows fetched, updated and read
2854 +                    0, 0, 0,   // select, update and other commands
2855 +                    0, 0,      // commit and rollback trans
2856 +                    thd->diff_denied_connections,
2857 +                    0,         // lost connections
2858 +                    0,         // access denied errors
2859 +                    0);        // empty queries
2860 +
2861 +    if (my_hash_insert(users_or_clients, (byte*)user_stats))
2862 +    {
2863 +      my_free((char*)user_stats, 0);
2864 +      return 1; // Out of memory
2865 +    }
2866 +  }
2867 +  user_stats->total_connections++;
2868 +  return 0;
2869 +}
2870 +
2871 +// Increments the global user and client stats connection count.  If 'use_lock'
2872 +// is true, LOCK_global_user_client_stats will be locked/unlocked.  Returns
2873 +// 0 on success, 1 on error.
2874 +static int increment_connection_count(THD* thd, bool use_lock)
2875 +{
2876 +  char* user_string = get_valid_user_string(thd->main_security_ctx.user);
2877 +  const char* client_string = get_client_host(thd);
2878 +  int return_value = 0;
2879 +
2880 +  if (!opt_userstat_running)
2881 +    return return_value;
2882 +
2883 +  if (use_lock) pthread_mutex_lock(&LOCK_global_user_client_stats);
2884 +
2885 +  if (increment_count_by_name(user_string, user_string,
2886 +                              &global_user_stats, thd))
2887 +  {
2888 +    return_value = 1;
2889 +    goto end;
2890 +  }
2891 +  if (increment_count_by_name(client_string,
2892 +                              user_string,
2893 +                              &global_client_stats, thd))
2894 +  {
2895 +    return_value = 1;
2896 +    goto end;
2897 +  }
2898 +
2899 +end:
2900 +  if (use_lock) pthread_mutex_unlock(&LOCK_global_user_client_stats);
2901 +  return return_value;
2902 +}
2903 +
2904 +// Used to update the global user and client stats.
2905 +static void update_global_user_stats_with_user(THD* thd,
2906 +                                               USER_STATS* user_stats,
2907 +                                               time_t now)
2908 +{
2909 +  user_stats->connected_time += now - thd->last_global_update_time;
2910 +  thd->last_global_update_time = now;
2911 +  user_stats->busy_time += thd->diff_total_busy_time;
2912 +  user_stats->cpu_time += thd->diff_total_cpu_time;
2913 +  user_stats->bytes_received += thd->diff_total_bytes_received;
2914 +  user_stats->bytes_sent += thd->diff_total_bytes_sent;
2915 +  user_stats->binlog_bytes_written += thd->diff_total_binlog_bytes_written;
2916 +  user_stats->rows_fetched += thd->diff_total_sent_rows;
2917 +  user_stats->rows_updated += thd->diff_total_updated_rows;
2918 +  user_stats->rows_read += thd->diff_total_read_rows;
2919 +  user_stats->select_commands += thd->diff_select_commands;
2920 +  user_stats->update_commands += thd->diff_update_commands;
2921 +  user_stats->other_commands += thd->diff_other_commands;
2922 +  user_stats->commit_trans += thd->diff_commit_trans;
2923 +  user_stats->rollback_trans += thd->diff_rollback_trans;
2924 +  user_stats->denied_connections += thd->diff_denied_connections;
2925 +  user_stats->lost_connections += thd->diff_lost_connections;
2926 +  user_stats->access_denied_errors += thd->diff_access_denied_errors;
2927 +  user_stats->empty_queries += thd->diff_empty_queries;
2928 +}
2929 +
2930 +// Updates the global stats of a user or client
2931 +void update_global_user_stats(THD* thd, bool create_user, time_t now)
2932 +{
2933 +  if (opt_userstat_running) {
2934 +  char* user_string = get_valid_user_string(thd->main_security_ctx.user);
2935 +  const char* client_string = get_client_host(thd);
2936 +
2937 +  USER_STATS* user_stats;
2938 +  pthread_mutex_lock(&LOCK_global_user_client_stats);
2939 +
2940 +  // Update by user name
2941 +  if ((user_stats = (USER_STATS*)hash_search(&global_user_stats,
2942 +                                             (byte*)user_string,
2943 +                                             strlen(user_string)))) {
2944 +    // Found user.
2945 +    update_global_user_stats_with_user(thd, user_stats, now);
2946 +  } else {
2947 +    // Create the entry
2948 +    if (create_user) {
2949 +      increment_count_by_name(user_string, user_string,
2950 +                              &global_user_stats, thd);
2951 +    }
2952 +  }
2953 +
2954 +  // Update by client IP
2955 +  if ((user_stats = (USER_STATS*)hash_search(&global_client_stats,
2956 +                                             (byte*)client_string,
2957 +                                             strlen(client_string)))) {
2958 +    // Found by client IP
2959 +    update_global_user_stats_with_user(thd, user_stats, now);
2960 +  } else {
2961 +    // Create the entry
2962 +    if (create_user) {
2963 +      increment_count_by_name(client_string,
2964 +                              user_string,
2965 +                              &global_client_stats, thd);
2966 +    }
2967 +  }
2968 +  thd->reset_diff_stats();
2969 +
2970 +  pthread_mutex_unlock(&LOCK_global_user_client_stats);
2971 +  } else {
2972 +  thd->reset_diff_stats();
2973 +  }
2974 +}
2975 +
2976 +// Determines the concurrent number of connections of current threads.
2977 +static void set_connections_stats()
2978 +{
2979 +  USER_STATS* user_stats;
2980 +
2981 +  pthread_mutex_lock(&LOCK_global_user_client_stats);
2982 +  pthread_mutex_lock(&LOCK_thread_count);
2983 +
2984 +  // Resets all concurrent connections to 0.
2985 +  for (int i = 0; i < global_user_stats.records; ++i) {
2986 +    user_stats = (USER_STATS*)hash_element(&global_user_stats, i);
2987 +    user_stats->concurrent_connections = 0;
2988 +  }
2989 +  for (int i = 0; i < global_client_stats.records; ++i) {
2990 +    user_stats = (USER_STATS*)hash_element(&global_client_stats, i);
2991 +    user_stats->concurrent_connections = 0;
2992 +  }
2993 +
2994 +  I_List_iterator<THD> it(threads);
2995 +  THD* thd;
2996 +  time_t now = time(NULL);
2997 +  // Iterates through the current threads.
2998 +  while ((thd = it++)) {
2999 +    char* user_string = get_valid_user_string(thd->main_security_ctx.user);
3000 +    if ((user_stats = (USER_STATS*)hash_search(&global_user_stats,
3001 +                                               (byte*)user_string,
3002 +                                               strlen(user_string)))) {
3003 +      // Found user.
3004 +      user_stats->concurrent_connections++;
3005 +      update_global_user_stats_with_user(thd, user_stats, now);
3006 +    } else {
3007 +      // The user name should exist.
3008 +      if (user_string == mysql_system_user) {
3009 +        // Only create the user if it is the mysql_system_user
3010 +        increment_count_by_name(user_string, user_string,
3011 +                                &global_user_stats, thd);
3012 +      }
3013 +    }
3014 +
3015 +    const char* client_string = get_client_host(thd);
3016 +    if ((user_stats = (USER_STATS*)hash_search(&global_client_stats,
3017 +                                               (byte*)client_string,
3018 +                                               strlen(client_string)))) {
3019 +      // Found user.
3020 +      user_stats->concurrent_connections++;
3021 +      update_global_user_stats_with_user(thd, user_stats, now);
3022 +    } else {
3023 +      // Do nothing, unlike what is done for global_user_stats
3024 +    }
3025 +    thd->reset_diff_stats();
3026 +  }
3027 +  pthread_mutex_unlock(&LOCK_thread_count);
3028 +  pthread_mutex_unlock(&LOCK_global_user_client_stats);
3029 +}
3030 +
3031  /*
3032    Reset per-hour user resource limits when it has been more than
3033    an hour since they were last checked
3034 @@ -1184,6 +1610,8 @@
3035      my_net_set_read_timeout(net, connect_timeout);
3036      my_net_set_write_timeout(net, connect_timeout);
3037  
3038 +    bool create_user = true;
3039 +
3040      if ((error=check_connection(thd)))
3041      {                                          // Wrong permissions
3042        if (error > 0)
3043 @@ -1193,8 +1621,22 @@
3044         my_sleep(1000);                         /* must wait after eof() */
3045  #endif
3046        statistic_increment(aborted_connects,&LOCK_status);
3047 +      thd->diff_denied_connections++;
3048 +      if (error == -2) {
3049 +        // Do not create statistics for a user who does not exist, or failed
3050 +        // to authenticate.
3051 +        create_user = false;
3052 +      }
3053        goto end_thread;
3054      }
3055 +
3056 +    thd->reset_stats();
3057 +    // Updates global user connection stats.
3058 +    if (increment_connection_count(thd, true)) {
3059 +      net_send_error(thd, ER_OUTOFMEMORY);  // Out of memory
3060 +      goto end_thread;
3061 +    }
3062 +
3063  #ifdef __NETWARE__
3064      netware_reg_user(sctx->ip, sctx->user, "MySQL");
3065  #endif
3066 @@ -1251,6 +1693,7 @@
3067          net->vio && net->error && net->report_error)
3068      {
3069        statistic_increment(aborted_threads, &LOCK_status);
3070 +      thd->diff_lost_connections++;
3071      }
3072  
3073      if (net->error && net->vio != 0 && net->report_error)
3074 @@ -1270,6 +1713,8 @@
3075  
3076  end_thread:
3077      close_connection(thd, 0, 1);
3078 +    thd->update_stats(false);
3079 +    update_global_user_stats(thd, create_user, time(NULL));
3080      end_thread(thd,1);
3081      /*
3082        If end_thread returns, we are either running with --one-thread
3083 @@ -1601,6 +2046,13 @@
3084  
3085    thd->clear_error();                          // Clear error message
3086  
3087 +  thd->updated_row_count=0;
3088 +  thd->busy_time=0;
3089 +  thd->cpu_time=0;
3090 +  thd->bytes_received=0;
3091 +  thd->bytes_sent=0;
3092 +  thd->binlog_bytes_written=0;
3093 +
3094    net_new_transaction(net);
3095  
3096    packet_length= my_net_read(net);
3097 @@ -1759,6 +2211,9 @@
3098    }
3099  
3100    thd->command=command;
3101 +  // To increment the corrent command counter for user stats, 'command' must
3102 +  // be saved because it is set to COM_SLEEP at the end of this function.
3103 +  thd->old_command = command;
3104    /*
3105      Commands which always take a long time are logged into
3106      the slow log only if opt_log_slow_admin_statements is set.
3107 @@ -4424,6 +4879,15 @@
3108      if (check_global_access(thd,RELOAD_ACL))
3109        goto error;
3110  
3111 +    if(lex->type & REFRESH_SLOW_QUERY_LOG) {
3112 +        /* We are only flushing slow query log */
3113 +        mysql_slow_log.new_file(1);
3114 +    
3115 +        send_ok(thd);
3116 +        break;
3117 +    }
3118 +
3119 +
3120      /*
3121        reload_acl_and_cache() will tell us if we are allowed to write to the
3122        binlog or not.
3123 @@ -4731,6 +5195,7 @@
3124      {
3125        if (check_global_access(thd, SUPER_ACL))
3126        {
3127 +        thd->diff_access_denied_errors++;
3128          my_error(ER_SPECIFIC_ACCESS_DENIED_ERROR, MYF(0), "SUPER");
3129          goto create_sp_error;
3130        }
3131 @@ -5567,6 +6032,7 @@
3132        if (!no_errors)
3133        {
3134          const char *db_name= db ? db : thd->db;
3135 +        thd->diff_access_denied_errors++;
3136          my_error(ER_DBACCESS_DENIED_ERROR, MYF(0),
3137                   sctx->priv_user, sctx->priv_host, db_name);
3138        }
3139 @@ -5602,6 +6068,7 @@
3140    {                                            // We can never grant this
3141      DBUG_PRINT("error",("No possible access"));
3142      if (!no_errors)
3143 +      thd->diff_access_denied_errors++;
3144        my_error(ER_ACCESS_DENIED_ERROR, MYF(0),
3145                 sctx->priv_user,
3146                 sctx->priv_host,
3147 @@ -5634,11 +6101,15 @@
3148  
3149    DBUG_PRINT("error",("Access denied"));
3150    if (!no_errors)
3151 +  {
3152 +    // increment needs !no_errors condition, otherwise double counting.
3153 +    thd->diff_access_denied_errors++;
3154      my_error(ER_DBACCESS_DENIED_ERROR, MYF(0),
3155               sctx->priv_user, sctx->priv_host,
3156               (db ? db : (thd->db ?
3157                           thd->db :
3158                           "unknown")));          /* purecov: tested */
3159 +  }
3160    DBUG_RETURN(TRUE);                           /* purecov: tested */
3161  #endif /* NO_EMBEDDED_ACCESS_CHECKS */
3162  }
3163 @@ -5672,6 +6143,7 @@
3164    if ((thd->security_ctx->master_access & want_access))
3165      return 0;
3166    get_privilege_desc(command, sizeof(command), want_access);
3167 +  thd->diff_access_denied_errors++;
3168    my_error(ER_SPECIFIC_ACCESS_DENIED_ERROR, MYF(0), command);
3169    return 1;
3170  #endif /* NO_EMBEDDED_ACCESS_CHECKS */
3171 @@ -5704,6 +6176,7 @@
3172  
3173        if (!thd->col_access && check_grant_db(thd, dst_db_name))
3174        {
3175 +        thd->diff_access_denied_errors++;
3176          my_error(ER_DBACCESS_DENIED_ERROR, MYF(0),
3177                   thd->security_ctx->priv_user,
3178                   thd->security_ctx->priv_host,
3179 @@ -5735,6 +6208,12 @@
3180               check_grant(thd, SELECT_ACL, dst_table, 2, UINT_MAX, FALSE);
3181      }
3182  
3183
3184 +  case SCH_USER_STATS:
3185 +  case SCH_CLIENT_STATS:
3186 +     return check_global_access(thd, SUPER_ACL | PROCESS_ACL);
3187 +  case SCH_TABLE_STATS:
3188 +  case SCH_INDEX_STATS:
3189    case SCH_OPEN_TABLES:
3190    case SCH_VARIABLES:
3191    case SCH_STATUS:
3192 @@ -5788,8 +6267,8 @@
3193  #ifndef NO_EMBEDDED_ACCESS_CHECKS
3194    TABLE_LIST *org_tables= tables;
3195  #endif
3196 +  Security_context *sctx= thd->security_ctx, *backup_ctx= thd->security_ctx;
3197    TABLE_LIST *first_not_own_table= thd->lex->first_not_own_table();
3198 -  Security_context *sctx= thd->security_ctx, *backup_ctx= thd->security_ctx;
3199    /*
3200      The check that first_not_own_table is not reached is for the case when
3201      the given table list refers to the list for prelocking (contains tables
3202 @@ -5806,9 +6285,12 @@
3203          (want_access & ~(SELECT_ACL | EXTRA_ACL | FILE_ACL)))
3204      {
3205        if (!no_errors)
3206 +      {
3207 +        thd->diff_access_denied_errors++;
3208          my_error(ER_DBACCESS_DENIED_ERROR, MYF(0),
3209                   sctx->priv_user, sctx->priv_host,
3210                   INFORMATION_SCHEMA_NAME.str);
3211 +      }
3212        return TRUE;
3213      }
3214      /*
3215 @@ -6317,6 +6799,30 @@
3216    */
3217    lex_start(thd);
3218    mysql_reset_thd_for_next_command(thd);
3219 +
3220 +  int start_time_error = 0;
3221 +  int end_time_error = 0;
3222 +  struct timeval start_time, end_time;
3223 +  double start_usecs = 0;
3224 +  double end_usecs = 0;
3225 +  /* cpu time */
3226 +  int cputime_error = 0;
3227 +  struct timespec tp;
3228 +  double start_cpu_nsecs = 0;
3229 +  double end_cpu_nsecs = 0;
3230 +
3231 +  if (opt_userstat_running) {
3232 +#ifdef HAVE_CLOCK_GETTIME
3233 +    /* get start cputime */ 
3234 +    if (!(cputime_error = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp)))
3235 +      start_cpu_nsecs = tp.tv_sec*1000000000.0+tp.tv_nsec;
3236 +#endif
3237 +
3238 +    // Gets the start time, in order to measure how long this command takes.
3239 +    if (!(start_time_error = gettimeofday(&start_time, NULL))) {
3240 +      start_usecs = start_time.tv_sec * 1000000.0 + start_time.tv_usec;
3241 +    }
3242 +  }
3243  
3244    if (query_cache_send_result_to_client(thd, (char*) inBuf, length) <= 0)
3245    {
3246 @@ -6396,6 +6902,39 @@
3247      *found_semicolon= NULL;
3248    }
3249  
3250 +  if (opt_userstat_running) {
3251 +    // Gets the end time.
3252 +    if (!(end_time_error = gettimeofday(&end_time, NULL))) {
3253 +      end_usecs = end_time.tv_sec * 1000000.0 + end_time.tv_usec;
3254 +    }
3255 +
3256 +    // Calculates the difference between the end and start times.
3257 +    if (start_usecs && end_usecs >= start_usecs && !start_time_error && !end_time_error) {
3258 +      thd->busy_time = (end_usecs - start_usecs) / 1000000;
3259 +      // In case there are bad values, 2629743 is the #seconds in a month.
3260 +      if (thd->busy_time > 2629743) {
3261 +        thd->busy_time = 0;
3262 +      }
3263 +    } else {
3264 +      // end time went back in time, or gettimeofday() failed.
3265 +      thd->busy_time = 0;
3266 +    }
3267 +
3268 +#ifdef HAVE_CLOCK_GETTIME
3269 +    /* get end cputime */
3270 +    if (!cputime_error &&
3271 +        !(cputime_error = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp)))
3272 +      end_cpu_nsecs = tp.tv_sec*1000000000.0+tp.tv_nsec;
3273 +#endif
3274 +    if (start_cpu_nsecs && !cputime_error)
3275 +      thd->cpu_time = (end_cpu_nsecs - start_cpu_nsecs) / 1000000000;
3276 +    else
3277 +      thd->cpu_time = 0;
3278 +  }
3279 +  // Updates THD stats and the global user stats.
3280 +  thd->update_stats(true);
3281 +  update_global_user_stats(thd, true, time(NULL));
3282 +
3283    DBUG_VOID_RETURN;
3284  }
3285  
3286 @@ -7407,8 +7946,35 @@
3287     pthread_mutex_unlock(&LOCK_active_mi);
3288   }
3289  #endif
3290 - if (options & REFRESH_USER_RESOURCES)
3291 -   reset_mqh((LEX_USER *) NULL);
3292 +  if (options & REFRESH_TABLE_STATS)
3293 +  {
3294 +    pthread_mutex_lock(&LOCK_global_table_stats);
3295 +    free_global_table_stats();
3296 +    init_global_table_stats();
3297 +    pthread_mutex_unlock(&LOCK_global_table_stats);
3298 +  }
3299 +  if (options & REFRESH_INDEX_STATS)
3300 +  {
3301 +    pthread_mutex_lock(&LOCK_global_index_stats);
3302 +    free_global_index_stats();
3303 +    init_global_index_stats();
3304 +    pthread_mutex_unlock(&LOCK_global_index_stats);
3305 +  }
3306 +  if (options & (REFRESH_USER_STATS | REFRESH_CLIENT_STATS))
3307 +  {
3308 +    pthread_mutex_lock(&LOCK_global_user_client_stats);
3309 +    if (options & REFRESH_USER_STATS)
3310 +    {
3311 +      free_global_user_stats();
3312 +      init_global_user_stats();
3313 +    }
3314 +    if (options & REFRESH_CLIENT_STATS)
3315 +    {
3316 +      free_global_client_stats();
3317 +      init_global_client_stats();
3318 +    }
3319 +    pthread_mutex_unlock(&LOCK_global_user_client_stats);
3320 +  }
3321   *write_to_binlog= tmp_write_to_binlog;
3322   return result;
3323  }
3324 diff -r d35bd12bba15 sql/sql_prepare.cc
3325 --- a/sql/sql_prepare.cc        Mon Dec 22 22:51:44 2008 -0800
3326 +++ b/sql/sql_prepare.cc        Mon Dec 22 22:53:26 2008 -0800
3327 @@ -80,6 +80,9 @@
3328  #else
3329  #include <mysql_com.h>
3330  #endif
3331 +
3332 +// Uses the THD to update the global stats by user name and client IP
3333 +void update_global_user_stats(THD* thd, bool create_user, time_t now);
3334  
3335  /* A result class used to send cursor rows using the binary protocol. */
3336  
3337 @@ -1910,8 +1913,32 @@
3338    /* First of all clear possible warnings from the previous command */
3339    mysql_reset_thd_for_next_command(thd);
3340  
3341 +  int start_time_error = 0;
3342 +  int end_time_error = 0;
3343 +  struct timeval start_time, end_time;
3344 +  double start_usecs = 0;
3345 +  double end_usecs = 0;
3346 +  /* cpu time */
3347 +  int cputime_error = 0;
3348 +  struct timespec tp;
3349 +  double start_cpu_nsecs = 0;
3350 +  double end_cpu_nsecs = 0;
3351 +
3352 +  if (opt_userstat_running) {
3353 +#ifdef HAVE_CLOCK_GETTIME
3354 +    /* get start cputime */
3355 +    if (!(cputime_error = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp)))
3356 +      start_cpu_nsecs = tp.tv_sec*1000000000.0+tp.tv_nsec;
3357 +#endif
3358 +
3359 +    // Gets the start time, in order to measure how long this command takes.
3360 +    if (!(start_time_error = gettimeofday(&start_time, NULL))) {
3361 +      start_usecs = start_time.tv_sec * 1000000.0 + start_time.tv_usec;
3362 +    }
3363 +  }
3364 +
3365    if (! (stmt= new Prepared_statement(thd, &thd->protocol_prep)))
3366 -    DBUG_VOID_RETURN; /* out of memory: error is set in Sql_alloc */
3367 +    goto end; /* out of memory: error is set in Sql_alloc */
3368  
3369    if (thd->stmt_map.insert(thd, stmt))
3370    {
3371 @@ -1919,7 +1946,7 @@
3372        The error is set in the insert. The statement itself
3373        will be also deleted there (this is how the hash works).
3374      */
3375 -    DBUG_VOID_RETURN;
3376 +    goto end;
3377    }
3378  
3379    /* Reset warnings from previous command */
3380 @@ -1941,6 +1968,40 @@
3381      thd->stmt_map.erase(stmt);
3382    }
3383    /* check_prepared_statemnt sends the metadata packet in case of success */
3384 +end:
3385 +  if (opt_userstat_running) {
3386 +    // Gets the end time.
3387 +    if (!(end_time_error = gettimeofday(&end_time, NULL))) {
3388 +      end_usecs = end_time.tv_sec * 1000000.0 + end_time.tv_usec;
3389 +    }
3390 +
3391 +    // Calculates the difference between the end and start times.
3392 +    if (start_usecs && end_usecs >= start_usecs && !start_time_error && !end_time_error) {
3393 +      thd->busy_time = (end_usecs - start_usecs) / 1000000;
3394 +      // In case there are bad values, 2629743 is the #seconds in a month.
3395 +      if (thd->busy_time > 2629743) {
3396 +        thd->busy_time = 0;
3397 +      }
3398 +    } else {
3399 +      // end time went back in time, or gettimeofday() failed.
3400 +      thd->busy_time = 0;
3401 +    }
3402 +
3403 +#ifdef HAVE_CLOCK_GETTIME
3404 +    /* get end cputime */
3405 +    if (!cputime_error &&
3406 +        !(cputime_error = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp)))
3407 +      end_cpu_nsecs = tp.tv_sec*1000000000.0+tp.tv_nsec;
3408 +#endif
3409 +    if (start_cpu_nsecs && !cputime_error)
3410 +      thd->cpu_time = (end_cpu_nsecs - start_cpu_nsecs) / 1000000000;
3411 +    else
3412 +      thd->cpu_time = 0;
3413 +  }
3414 +  // Updates THD stats and the global user stats.
3415 +  thd->update_stats(true);
3416 +  update_global_user_stats(thd, true, time(NULL));
3417 +
3418    DBUG_VOID_RETURN;
3419  }
3420  
3421 @@ -2281,8 +2342,32 @@
3422    /* First of all clear possible warnings from the previous command */
3423    mysql_reset_thd_for_next_command(thd);
3424  
3425 +  int start_time_error = 0;
3426 +  int end_time_error = 0;
3427 +  struct timeval start_time, end_time;
3428 +  double start_usecs = 0;
3429 +  double end_usecs = 0;
3430 +  /* cpu time */
3431 +  int cputime_error = 0;
3432 +  struct timespec tp;
3433 +  double start_cpu_nsecs = 0;
3434 +  double end_cpu_nsecs = 0;
3435 +
3436 +  if (opt_userstat_running) {
3437 +#ifdef HAVE_CLOCK_GETTIME
3438 +    /* get start cputime */
3439 +    if (!(cputime_error = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp)))
3440 +      start_cpu_nsecs = tp.tv_sec*1000000000.0+tp.tv_nsec;
3441 +#endif
3442 +
3443 +    // Gets the start time, in order to measure how long this command takes.
3444 +    if (!(start_time_error = gettimeofday(&start_time, NULL))) {
3445 +      start_usecs = start_time.tv_sec * 1000000.0 + start_time.tv_usec;
3446 +    }
3447 +  }
3448 +
3449    if (!(stmt= find_prepared_statement(thd, stmt_id, "mysql_stmt_execute")))
3450 -    DBUG_VOID_RETURN;
3451 +    goto end;
3452  
3453  #ifdef ENABLED_PROFILING
3454    thd->profiling.set_query_source(stmt->query, stmt->query_length);
3455 @@ -2325,11 +2410,46 @@
3456                         test(flags & (ulong) CURSOR_TYPE_READ_ONLY));
3457    if (!(specialflag & SPECIAL_NO_PRIOR))
3458      my_pthread_setprio(pthread_self(), WAIT_PRIOR);
3459 -  DBUG_VOID_RETURN;
3460 +  goto end;
3461  
3462  set_params_data_err:
3463    my_error(ER_WRONG_ARGUMENTS, MYF(0), "mysql_stmt_execute");
3464    reset_stmt_params(stmt);
3465 +
3466 +end:
3467 +  if (opt_userstat_running) {
3468 +    // Gets the end time.
3469 +    if (!(end_time_error = gettimeofday(&end_time, NULL))) {
3470 +      end_usecs = end_time.tv_sec * 1000000.0 + end_time.tv_usec;
3471 +    }
3472 +
3473 +    // Calculates the difference between the end and start times.
3474 +    if (start_usecs && end_usecs >= start_usecs && !start_time_error && !end_time_error) {
3475 +      thd->busy_time = (end_usecs - start_usecs) / 1000000;
3476 +      // In case there are bad values, 2629743 is the #seconds in a month.
3477 +      if (thd->busy_time > 2629743) {
3478 +        thd->busy_time = 0;
3479 +      }
3480 +    } else {
3481 +      // end time went back in time, or gettimeofday() failed.
3482 +      thd->busy_time = 0;
3483 +    }
3484 +
3485 +#ifdef HAVE_CLOCK_GETTIME
3486 +    /* get end cputime */
3487 +    if (!cputime_error &&
3488 +        !(cputime_error = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp)))
3489 +      end_cpu_nsecs = tp.tv_sec*1000000000.0+tp.tv_nsec;
3490 +#endif
3491 +    if (start_cpu_nsecs && !cputime_error)
3492 +      thd->cpu_time = (end_cpu_nsecs - start_cpu_nsecs) / 1000000000;
3493 +    else
3494 +      thd->cpu_time = 0;
3495 +  }
3496 +  // Updates THD stats and the global user stats.
3497 +  thd->update_stats(true);
3498 +  update_global_user_stats(thd, true, time(NULL));
3499 +
3500    DBUG_VOID_RETURN;
3501  }
3502  
3503 @@ -2423,6 +2543,31 @@
3504  
3505    /* First of all clear possible warnings from the previous command */
3506    mysql_reset_thd_for_next_command(thd);
3507 +
3508 +  int start_time_error = 0;
3509 +  int end_time_error = 0;
3510 +  struct timeval start_time, end_time;
3511 +  double start_usecs = 0;
3512 +  double end_usecs = 0;
3513 +  /* cpu time */
3514 +  int cputime_error = 0;
3515 +  struct timespec tp;
3516 +  double start_cpu_nsecs = 0;
3517 +  double end_cpu_nsecs = 0;
3518 +
3519 +  if (opt_userstat_running) {
3520 +#ifdef HAVE_CLOCK_GETTIME
3521 +    /* get start cputime */
3522 +    if (!(cputime_error = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp)))
3523 +      start_cpu_nsecs = tp.tv_sec*1000000000.0+tp.tv_nsec;
3524 +#endif
3525 +
3526 +    // Gets the start time, in order to measure how long this command takes.
3527 +    if (!(start_time_error = gettimeofday(&start_time, NULL))) {
3528 +      start_usecs = start_time.tv_sec * 1000000.0 + start_time.tv_usec;
3529 +    }
3530 +  }
3531 +
3532    statistic_increment(thd->status_var.com_stmt_fetch, &LOCK_status);
3533    if (!(stmt= find_prepared_statement(thd, stmt_id, "mysql_stmt_fetch")))
3534      DBUG_VOID_RETURN;
3535 @@ -2455,6 +2600,39 @@
3536    thd->restore_backup_statement(stmt, &stmt_backup);
3537    thd->stmt_arena= thd;
3538  
3539 +  if (opt_userstat_running) {
3540 +    // Gets the end time.
3541 +    if (!(end_time_error = gettimeofday(&end_time, NULL))) {
3542 +      end_usecs = end_time.tv_sec * 1000000.0 + end_time.tv_usec;
3543 +    }
3544 +
3545 +    // Calculates the difference between the end and start times.
3546 +    if (start_usecs && end_usecs >= start_usecs && !start_time_error && !end_time_error) {
3547 +      thd->busy_time = (end_usecs - start_usecs) / 1000000;
3548 +      // In case there are bad values, 2629743 is the #seconds in a month.
3549 +      if (thd->busy_time > 2629743) {
3550 +        thd->busy_time = 0;
3551 +      }
3552 +    } else {
3553 +      // end time went back in time, or gettimeofday() failed.
3554 +      thd->busy_time = 0;
3555 +    }
3556 +
3557 +#ifdef HAVE_CLOCK_GETTIME
3558 +    /* get end cputime */
3559 +    if (!cputime_error &&
3560 +        !(cputime_error = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp)))
3561 +      end_cpu_nsecs = tp.tv_sec*1000000000.0+tp.tv_nsec;
3562 +#endif
3563 +    if (start_cpu_nsecs && !cputime_error)
3564 +      thd->cpu_time = (end_cpu_nsecs - start_cpu_nsecs) / 1000000000;
3565 +    else
3566 +      thd->cpu_time = 0;
3567 +  }
3568 +  // Updates THD stats and the global user stats.
3569 +  thd->update_stats(true);
3570 +  update_global_user_stats(thd, true, time(NULL));
3571 +
3572    DBUG_VOID_RETURN;
3573  }
3574  
3575 @@ -2487,6 +2665,30 @@
3576    /* First of all clear possible warnings from the previous command */
3577    mysql_reset_thd_for_next_command(thd);
3578  
3579 +  int start_time_error = 0;
3580 +  int end_time_error = 0;
3581 +  struct timeval start_time, end_time;
3582 +  double start_usecs = 0;
3583 +  double end_usecs = 0;
3584 +  /* cpu time */
3585 +  int cputime_error = 0;
3586 +  struct timespec tp;
3587 +  double start_cpu_nsecs = 0;
3588 +  double end_cpu_nsecs = 0;
3589 +
3590 +  if (opt_userstat_running) {
3591 +#ifdef HAVE_CLOCK_GETTIME
3592 +    /* get start cputime */
3593 +    if (!(cputime_error = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp)))
3594 +      start_cpu_nsecs = tp.tv_sec*1000000000.0+tp.tv_nsec;
3595 +#endif
3596 +
3597 +    // Gets the start time, in order to measure how long this command takes.
3598 +    if (!(start_time_error = gettimeofday(&start_time, NULL))) {
3599 +      start_usecs = start_time.tv_sec * 1000000.0 + start_time.tv_usec;
3600 +    }
3601 +  }
3602 +
3603    statistic_increment(thd->status_var.com_stmt_reset, &LOCK_status);
3604    if (!(stmt= find_prepared_statement(thd, stmt_id, "mysql_stmt_reset")))
3605      DBUG_VOID_RETURN;
3606 @@ -2502,6 +2704,39 @@
3607    stmt->state= Query_arena::PREPARED;
3608  
3609    send_ok(thd);
3610 +
3611 +  if (opt_userstat_running) {
3612 +    // Gets the end time.
3613 +    if (!(end_time_error = gettimeofday(&end_time, NULL))) {
3614 +      end_usecs = end_time.tv_sec * 1000000.0 + end_time.tv_usec;
3615 +    }
3616 +
3617 +    // Calculates the difference between the end and start times.
3618 +    if (start_usecs && end_usecs >= start_usecs && !start_time_error && !end_time_error) {
3619 +      thd->busy_time = (end_usecs - start_usecs) / 1000000;
3620 +      // In case there are bad values, 2629743 is the #seconds in a month.
3621 +      if (thd->busy_time > 2629743) {
3622 +        thd->busy_time = 0;
3623 +      }
3624 +    } else {
3625 +      // end time went back in time, or gettimeofday() failed.
3626 +      thd->busy_time = 0;
3627 +    }
3628 +
3629 +#ifdef HAVE_CLOCK_GETTIME
3630 +    /* get end cputime */
3631 +    if (!cputime_error &&
3632 +        !(cputime_error = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp)))
3633 +      end_cpu_nsecs = tp.tv_sec*1000000000.0+tp.tv_nsec;
3634 +#endif
3635 +    if (start_cpu_nsecs && !cputime_error)
3636 +      thd->cpu_time = (end_cpu_nsecs - start_cpu_nsecs) / 1000000000;
3637 +    else
3638 +      thd->cpu_time = 0;
3639 +  }
3640 +  // Updates THD stats and the global user stats.
3641 +  thd->update_stats(true);
3642 +  update_global_user_stats(thd, true, time(NULL));
3643  
3644    DBUG_VOID_RETURN;
3645  }
3646 diff -r d35bd12bba15 sql/sql_show.cc
3647 --- a/sql/sql_show.cc   Mon Dec 22 22:51:44 2008 -0800
3648 +++ b/sql/sql_show.cc   Mon Dec 22 22:53:26 2008 -0800
3649 @@ -530,6 +530,7 @@
3650                 sctx->master_access);
3651    if (!(db_access & DB_ACLS) && (!grant_option || check_grant_db(thd,dbname)))
3652    {
3653 +    thd->diff_access_denied_errors++;
3654      my_error(ER_DBACCESS_DENIED_ERROR, MYF(0),
3655               sctx->priv_user, sctx->host_or_ip, dbname);
3656      mysql_log.write(thd,COM_INIT_DB,ER(ER_DBACCESS_DENIED_ERROR),
3657 @@ -1858,6 +1859,300 @@
3658    DBUG_RETURN(FALSE);
3659  }
3660  
3661 +/*
3662 +   Aggregate values for mapped_user entries by their role.
3663 +
3664 +   SYNOPSIS
3665 +     aggregate_user_stats
3666 +       all_user_stats - input to aggregate
3667 +       agg_user_stats - returns aggregated values
3668 +
3669 +   RETURN
3670 +     0 - OK
3671 +     1 - error
3672 + */
3673 +static int
3674 +aggregate_user_stats(HASH *all_user_stats, HASH *agg_user_stats)
3675 +{
3676 +  DBUG_ENTER("aggregate_user_stats");
3677 +  if (hash_init(agg_user_stats, system_charset_info,
3678 +                max(all_user_stats->records, 1),
3679 +                0, 0, (hash_get_key)get_key_user_stats,
3680 +                (hash_free_key)free_user_stats, 0))
3681 +  {
3682 +    sql_print_error("Malloc in aggregate_user_stats failed");
3683 +    DBUG_RETURN(1);
3684 +  }
3685 +
3686 +  for (int i = 0; i < all_user_stats->records; ++i) {
3687 +    USER_STATS *user = (USER_STATS*)hash_element(all_user_stats, i);
3688 +    USER_STATS *agg_user;
3689 +    if (!(agg_user = (USER_STATS*)hash_search(agg_user_stats,
3690 +                                              (byte*)user->priv_user,
3691 +                                              strlen(user->priv_user))))
3692 +    {
3693 +      // First entry for this role.
3694 +      if (!(agg_user =
3695 +            (USER_STATS*) my_malloc(sizeof(USER_STATS), MYF(MY_WME | MY_ZEROFILL))))
3696 +      {
3697 +        sql_print_error("Malloc in aggregate_user_stats failed");
3698 +        DBUG_RETURN(1);
3699 +      }
3700 +
3701 +      init_user_stats(agg_user, user->priv_user, user->priv_user,
3702 +                      user->total_connections, user->concurrent_connections,
3703 +                      user->connected_time, user->busy_time, user->cpu_time,
3704 +                      user->bytes_received, user->bytes_sent,
3705 +                      user->binlog_bytes_written,
3706 +                      user->rows_fetched, user->rows_updated, user->rows_read,
3707 +                      user->select_commands, user->update_commands,
3708 +                      user->other_commands,
3709 +                      user->commit_trans, user->rollback_trans,
3710 +                      user->denied_connections, user->lost_connections,
3711 +                      user->access_denied_errors, user->empty_queries);
3712 +
3713 +      if (my_hash_insert(agg_user_stats, (byte*)agg_user))
3714 +      {
3715 +        // Out of memory.
3716 +        my_free((char*)agg_user, 0);
3717 +        sql_print_error("Malloc in aggregate_user_stats failed");
3718 +        DBUG_RETURN(1);
3719 +      }
3720 +    }
3721 +    else
3722 +    {
3723 +      // Aggregate with existing values for this role.
3724 +      add_user_stats(agg_user,
3725 +                     user->total_connections, user->concurrent_connections,
3726 +                     user->connected_time, user->busy_time, user->cpu_time,
3727 +                     user->bytes_received, user->bytes_sent,
3728 +                     user->binlog_bytes_written,
3729 +                     user->rows_fetched, user->rows_updated, user->rows_read,
3730 +                     user->select_commands, user->update_commands,
3731 +                     user->other_commands,
3732 +                     user->commit_trans, user->rollback_trans,
3733 +                     user->denied_connections, user->lost_connections,
3734 +                     user->access_denied_errors, user->empty_queries);
3735 +    }
3736 +  }
3737 +  DBUG_PRINT("exit", ("aggregated %d input into %d output entries",
3738 +                      all_user_stats->records, agg_user_stats->records));
3739 +  DBUG_RETURN(0);
3740 +}
3741 +
3742 +/*
3743 +   Write result to network for SHOW USER_STATISTICS
3744 +
3745 +   SYNOPSIS
3746 +     send_user_stats
3747 +       all_user_stats - values to return
3748 +       table - I_S table
3749 +
3750 +   RETURN
3751 +     0 - OK
3752 +     1 - error
3753 + */
3754 +int send_user_stats(THD* thd, HASH *all_user_stats, TABLE *table)
3755 +{
3756 +  DBUG_ENTER("send_user_stats");
3757 +  for (int i = 0; i < all_user_stats->records; ++i) {
3758 +    restore_record(table, s->default_values);
3759 +    USER_STATS *user_stats = (USER_STATS*)hash_element(all_user_stats, i);
3760 +      table->field[0]->store(user_stats->user, strlen(user_stats->user), system_charset_info);
3761 +      table->field[1]->store((longlong)user_stats->total_connections);
3762 +      table->field[2]->store((longlong)user_stats->concurrent_connections);
3763 +      table->field[3]->store((longlong)user_stats->connected_time);
3764 +      table->field[4]->store((longlong)user_stats->busy_time);
3765 +      table->field[5]->store((longlong)user_stats->cpu_time);
3766 +      table->field[6]->store((longlong)user_stats->bytes_received);
3767 +      table->field[7]->store((longlong)user_stats->bytes_sent);
3768 +      table->field[8]->store((longlong)user_stats->binlog_bytes_written);
3769 +      table->field[9]->store((longlong)user_stats->rows_fetched);
3770 +      table->field[10]->store((longlong)user_stats->rows_updated);
3771 +      table->field[11]->store((longlong)user_stats->rows_read);
3772 +      table->field[12]->store((longlong)user_stats->select_commands);
3773 +      table->field[13]->store((longlong)user_stats->update_commands);
3774 +      table->field[14]->store((longlong)user_stats->other_commands);
3775 +      table->field[15]->store((longlong)user_stats->commit_trans);
3776 +      table->field[16]->store((longlong)user_stats->rollback_trans);
3777 +      table->field[17]->store((longlong)user_stats->denied_connections);
3778 +      table->field[18]->store((longlong)user_stats->lost_connections);
3779 +      table->field[19]->store((longlong)user_stats->access_denied_errors);
3780 +      table->field[20]->store((longlong)user_stats->empty_queries);
3781 +      if (schema_table_store_record(thd, table))
3782 +      {
3783 +             DBUG_PRINT("error", ("store record error"));
3784 +             DBUG_RETURN(1);
3785 +      }
3786 +  }
3787 +  DBUG_RETURN(0);
3788 +}
3789 +
3790 +/*
3791 +   Process SHOW USER_STATISTICS
3792 +
3793 +   SYNOPSIS
3794 +     mysqld_show_user_stats
3795 +       thd - current thread
3796 +       wild - limit results to the entry for this user
3797 +       with_roles - when true, display role for mapped users
3798 +
3799 +   RETURN
3800 +     0 - OK
3801 +     1 - error
3802 + */
3803 +
3804 +
3805 +int fill_schema_user_stats(THD* thd, TABLE_LIST* tables, COND* cond)
3806 +{
3807 +  TABLE *table= tables->table;
3808 +  DBUG_ENTER("fill_schema_user_stats");
3809 +
3810 +  if (check_global_access(thd, SUPER_ACL | PROCESS_ACL))
3811 +          DBUG_RETURN(1);
3812 +
3813 +  // Iterates through all the global stats and sends them to the client.
3814 +  // Pattern matching on the client IP is supported.
3815 +
3816 +  pthread_mutex_lock(&LOCK_global_user_client_stats);
3817 +  int result= send_user_stats(thd, &global_user_stats, table);
3818 +  pthread_mutex_unlock(&LOCK_global_user_client_stats);
3819 +  if (result)
3820 +    goto err;
3821 +
3822 +  DBUG_PRINT("exit", ("fill_schema_user_stats result is 0"));
3823 +  DBUG_RETURN(0);
3824 +
3825 + err:
3826 +  DBUG_PRINT("exit", ("fill_schema_user_stats result is 1"));
3827 +  DBUG_RETURN(1);
3828 +}
3829 +
3830 +/*
3831 +   Process SHOW CLIENT_STATISTICS
3832 +
3833 +   SYNOPSIS
3834 +     mysqld_show_client_stats
3835 +       thd - current thread
3836 +       wild - limit results to the entry for this client
3837 +
3838 +   RETURN
3839 +     0 - OK
3840 +     1 - error
3841 + */
3842 +
3843 +
3844 +int fill_schema_client_stats(THD* thd, TABLE_LIST* tables, COND* cond)
3845 +{
3846 +  TABLE *table= tables->table;
3847 +  DBUG_ENTER("fill_schema_client_stats");
3848 +
3849 +  if (check_global_access(thd, SUPER_ACL | PROCESS_ACL))
3850 +          DBUG_RETURN(1);
3851 +
3852 +  // Iterates through all the global stats and sends them to the client.
3853 +  // Pattern matching on the client IP is supported.
3854 +
3855 +  pthread_mutex_lock(&LOCK_global_user_client_stats);
3856 +  int result= send_user_stats(thd, &global_client_stats, table);
3857 +  pthread_mutex_unlock(&LOCK_global_user_client_stats);
3858 +  if (result)
3859 +    goto err;
3860 +
3861 +  DBUG_PRINT("exit", ("mysqld_show_client_stats result is 0"));
3862 +  DBUG_RETURN(0);
3863 +
3864 + err:
3865 +  DBUG_PRINT("exit", ("mysqld_show_client_stats result is 1"));
3866 +  DBUG_RETURN(1);
3867 +}
3868 +
3869 +
3870 +// Sends the global table stats back to the client.
3871 +int fill_schema_table_stats(THD* thd, TABLE_LIST* tables, COND* cond)
3872 +{
3873 +  TABLE *table= tables->table;
3874 +  DBUG_ENTER("fill_schema_table_stats");
3875 +  char *table_full_name, *table_schema;
3876 +
3877 +  pthread_mutex_lock(&LOCK_global_table_stats);
3878 +  for (int i = 0; i < global_table_stats.records; ++i) {
3879 +    restore_record(table, s->default_values);
3880 +    TABLE_STATS *table_stats = 
3881 +      (TABLE_STATS*)hash_element(&global_table_stats, i);
3882 +
3883 +    table_full_name= thd->strdup(table_stats->table);
3884 +    table_schema= strsep(&table_full_name, ".");
3885 +
3886 +    TABLE_LIST tmp_table;
3887 +    bzero((char*) &tmp_table,sizeof(tmp_table));
3888 +    tmp_table.table_name= table_full_name;
3889 +    tmp_table.db= table_schema;
3890 +    tmp_table.grant.privilege= 0;
3891 +    if (check_access(thd, SELECT_ACL | EXTRA_ACL, tmp_table.db,
3892 +                      &tmp_table.grant.privilege, 0, 0,
3893 +                      is_schema_db(table_schema)) ||
3894 +         grant_option && check_grant(thd, SELECT_ACL, &tmp_table, 1, UINT_MAX, 1))
3895 +        continue;
3896 +
3897 +    table->field[0]->store(table_schema, strlen(table_schema), system_charset_info);
3898 +    table->field[1]->store(table_full_name, strlen(table_full_name), system_charset_info);
3899 +    table->field[2]->store((longlong)table_stats->rows_read, TRUE);
3900 +    table->field[3]->store((longlong)table_stats->rows_changed, TRUE);
3901 +    table->field[4]->store((longlong)table_stats->rows_changed_x_indexes, TRUE);
3902 +
3903 +    if (schema_table_store_record(thd, table))
3904 +    {
3905 +      VOID(pthread_mutex_unlock(&LOCK_global_table_stats));
3906 +      DBUG_RETURN(1);
3907 +    }
3908 +  }
3909 +  pthread_mutex_unlock(&LOCK_global_table_stats);
3910 +  DBUG_RETURN(0);
3911 +}
3912 +
3913 +// Sends the global index stats back to the client.
3914 +int fill_schema_index_stats(THD* thd, TABLE_LIST* tables, COND* cond)
3915 +{
3916 +  TABLE *table= tables->table;
3917 +  DBUG_ENTER("fill_schema_index_stats");
3918 +  char *index_full_name, *table_schema, *table_name;
3919 +
3920 +  pthread_mutex_lock(&LOCK_global_index_stats);
3921 +  for (int i = 0; i < global_index_stats.records; ++i) {
3922 +    restore_record(table, s->default_values);
3923 +    INDEX_STATS *index_stats =
3924 +      (INDEX_STATS*)hash_element(&global_index_stats, i);
3925 +
3926 +    index_full_name= thd->strdup(index_stats->index);
3927 +    table_schema= strsep(&index_full_name, ".");
3928 +    table_name= strsep(&index_full_name, ".");
3929 +
3930 +    TABLE_LIST tmp_table;
3931 +    bzero((char*) &tmp_table,sizeof(tmp_table));
3932 +    tmp_table.table_name= table_name;
3933 +    tmp_table.db= table_schema;
3934 +    tmp_table.grant.privilege= 0;
3935 +    if (check_access(thd, SELECT_ACL | EXTRA_ACL, tmp_table.db,
3936 +                      &tmp_table.grant.privilege, 0, 0,
3937 +                      is_schema_db(table_schema)) ||
3938 +         grant_option && check_grant(thd, SELECT_ACL, &tmp_table, 1, UINT_MAX, 1))
3939 +        continue;
3940 +
3941 +    table->field[0]->store(table_schema, strlen(table_schema), system_charset_info);
3942 +    table->field[1]->store(table_name, strlen(table_name), system_charset_info);
3943 +    table->field[2]->store(index_full_name, strlen(index_full_name), system_charset_info);
3944 +    table->field[3]->store((longlong)index_stats->rows_read, TRUE);
3945 +
3946 +    if (schema_table_store_record(thd, table))
3947 +    { 
3948 +      VOID(pthread_mutex_unlock(&LOCK_global_index_stats));
3949 +      DBUG_RETURN(1);
3950 +    }
3951 +  }
3952 +  pthread_mutex_unlock(&LOCK_global_index_stats);
3953 +  DBUG_RETURN(0);
3954 +}
3955  
3956  /* collect status for all running threads */
3957  
3958 @@ -4468,6 +4763,77 @@
3959    {0, 0, MYSQL_TYPE_STRING, 0, 0, 0}
3960  };
3961  
3962 +ST_FIELD_INFO user_stats_fields_info[]=
3963 +{
3964 +  {"USER", 16, MYSQL_TYPE_STRING, 0, 0, "User"},
3965 +  {"TOTAL_CONNECTIONS", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Total_connections"},
3966 +  {"CONCURRENT_CONNECTIONS", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Concurrent_connections"},
3967 +  {"CONNECTED_TIME", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Connected_time"},
3968 +  {"BUSY_TIME", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Busy_time"},
3969 +  {"CPU_TIME", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Cpu_time"},
3970 +  {"BYTES_RECEIVED", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Bytes_received"},
3971 +  {"BYTES_SENT", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Bytes_sent"},
3972 +  {"BINLOG_BYTES_WRITTEN", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Binlog_bytes_written"},
3973 +  {"ROWS_FETCHED", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Rows_fetched"},
3974 +  {"ROWS_UPDATED", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Rows_updated"},
3975 +  {"TABLE_ROWS_READ", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Table_rows_read"},
3976 +  {"SELECT_COMMANDS", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Select_commands"},
3977 +  {"UPDATE_COMMANDS", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Update_commands"},
3978 +  {"OTHER_COMMANDS", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Other_commands"},
3979 +  {"COMMIT_TRANSACTIONS", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Commit_transactions"},
3980 +  {"ROLLBACK_TRANSACTIONS", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Rollback_transactions"},
3981 +  {"DENIED_CONNECTIONS", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Denied_connections"},
3982 +  {"LOST_CONNECTIONS", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Lost_connections"},
3983 +  {"ACCESS_DENIED", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Access_denied"},
3984 +  {"EMPTY_QUERIES", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Empty_queries"},
3985 +  {0, 0, MYSQL_TYPE_STRING, 0, 0, 0}
3986 +};
3987 +
3988 +ST_FIELD_INFO client_stats_fields_info[]=
3989 +{
3990 +  {"CLIENT", 16, MYSQL_TYPE_STRING, 0, 0, "Client"},
3991 +  {"TOTAL_CONNECTIONS", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Total_connections"},
3992 +  {"CONCURRENT_CONNECTIONS", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Concurrent_connections"},
3993 +  {"CONNECTED_TIME", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Connected_time"},
3994 +  {"BUSY_TIME", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Busy_time"},
3995 +  {"CPU_TIME", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Cpu_time"},
3996 +  {"BYTES_RECEIVED", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Bytes_received"},
3997 +  {"BYTES_SENT", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Bytes_sent"},
3998 +  {"BINLOG_BYTES_WRITTEN", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Binlog_bytes_written"},
3999 +  {"ROWS_FETCHED", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Rows_fetched"},
4000 +  {"ROWS_UPDATED", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Rows_updated"},
4001 +  {"TABLE_ROWS_READ", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Table_rows_read"},
4002 +  {"SELECT_COMMANDS", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Select_commands"},
4003 +  {"UPDATE_COMMANDS", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Update_commands"},
4004 +  {"OTHER_COMMANDS", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Other_commands"},
4005 +  {"COMMIT_TRANSACTIONS", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Commit_transactions"},
4006 +  {"ROLLBACK_TRANSACTIONS", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Rollback_transactions"},
4007 +  {"DENIED_CONNECTIONS", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Denied_connections"},
4008 +  {"LOST_CONNECTIONS", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Lost_connections"},
4009 +  {"ACCESS_DENIED", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Access_denied"},
4010 +  {"EMPTY_QUERIES", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Empty_queries"},
4011 +  {0, 0, MYSQL_TYPE_STRING, 0, 0, 0}
4012 +};
4013 +
4014 +
4015 +ST_FIELD_INFO table_stats_fields_info[]=
4016 +{
4017 +  {"TABLE_SCHEMA", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, "Table_schema"},
4018 +  {"TABLE_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, "Table_name"},
4019 +  {"ROWS_READ", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Rows_read"},
4020 +  {"ROWS_CHANGED", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Rows_changed"},
4021 +  {"ROWS_CHANGED_X_INDEXES", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Rows_changed_x_#indexes"},
4022 +  {0, 0, MYSQL_TYPE_STRING, 0, 0, 0}
4023 +};
4024 +
4025 +ST_FIELD_INFO index_stats_fields_info[]=
4026 +{
4027 +  {"TABLE_SCHEMA", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, "Table_schema"},
4028 +  {"TABLE_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, "Table_name"},
4029 +  {"INDEX_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, "Index_name"},
4030 +  {"ROWS_READ", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Rows_read"},
4031 +  {0, 0, MYSQL_TYPE_STRING, 0, 0, 0}
4032 +};
4033  
4034  /*
4035    Description of ST_FIELD_INFO in table.h
4036 @@ -4477,6 +4843,8 @@
4037  {
4038    {"CHARACTER_SETS", charsets_fields_info, create_schema_table, 
4039     fill_schema_charsets, make_character_sets_old_format, 0, -1, -1, 0},
4040 +  {"CLIENT_STATISTICS", client_stats_fields_info, create_schema_table, 
4041 +    fill_schema_client_stats, make_old_format, 0, -1, -1, 0},
4042    {"COLLATIONS", collation_fields_info, create_schema_table, 
4043     fill_schema_collation, make_old_format, 0, -1, -1, 0},
4044    {"COLLATION_CHARACTER_SET_APPLICABILITY", coll_charset_app_fields_info,
4045 @@ -4485,6 +4853,8 @@
4046     get_all_tables, make_columns_old_format, get_schema_column_record, 1, 2, 0},
4047    {"COLUMN_PRIVILEGES", column_privileges_fields_info, create_schema_table,
4048      fill_schema_column_privileges, 0, 0, -1, -1, 0},
4049 +  {"INDEX_STATISTICS", index_stats_fields_info, create_schema_table,
4050 +   fill_schema_index_stats, make_old_format, 0, -1, -1, 0},
4051    {"KEY_COLUMN_USAGE", key_column_usage_fields_info, create_schema_table,
4052      get_all_tables, 0, get_schema_key_column_usage_record, 4, 5, 0},
4053    {"OPEN_TABLES", open_tables_fields_info, create_schema_table,
4054 @@ -4510,10 +4880,14 @@
4055     get_all_tables, make_table_names_old_format, 0, 1, 2, 1},
4056    {"TABLE_PRIVILEGES", table_privileges_fields_info, create_schema_table,
4057      fill_schema_table_privileges, 0, 0, -1, -1, 0},
4058 +  {"TABLE_STATISTICS", table_stats_fields_info, create_schema_table,
4059 +    fill_schema_table_stats, make_old_format, 0, -1, -1, 0},
4060    {"TRIGGERS", triggers_fields_info, create_schema_table,
4061     get_all_tables, make_old_format, get_schema_triggers_record, 5, 6, 0},
4062    {"USER_PRIVILEGES", user_privileges_fields_info, create_schema_table, 
4063      fill_schema_user_privileges, 0, 0, -1, -1, 0},
4064 +  {"USER_STATISTICS", user_stats_fields_info, create_schema_table, 
4065 +    fill_schema_user_stats, make_old_format, 0, -1, -1, 0},
4066    {"VARIABLES", variables_fields_info, create_schema_table, fill_variables,
4067     make_old_format, 0, -1, -1, 1},
4068    {"VIEWS", view_fields_info, create_schema_table, 
4069 diff -r d35bd12bba15 sql/sql_update.cc
4070 --- a/sql/sql_update.cc Mon Dec 22 22:51:44 2008 -0800
4071 +++ b/sql/sql_update.cc Mon Dec 22 22:53:26 2008 -0800
4072 @@ -601,7 +601,8 @@
4073        (thd->client_capabilities & CLIENT_FOUND_ROWS) ? found : updated;
4074      send_ok(thd, (ulong) thd->row_count_func,
4075             thd->insert_id_used ? thd->last_insert_id : 0L,buff);
4076 -    DBUG_PRINT("info",("%ld records updated", (long) updated));
4077 +    thd->updated_row_count += thd->row_count_func;
4078 +    DBUG_PRINT("info",("%d records updated",updated));
4079    }
4080    thd->count_cuted_fields= CHECK_FIELD_IGNORE;         /* calc cuted fields */
4081    thd->abort_on_warning= 0;
4082 @@ -1832,5 +1833,6 @@
4083      (thd->client_capabilities & CLIENT_FOUND_ROWS) ? found : updated;
4084    ::send_ok(thd, (ulong) thd->row_count_func,
4085             thd->insert_id_used ? thd->last_insert_id : 0L,buff);
4086 +  thd->updated_row_count += thd->row_count_func;
4087    return FALSE;
4088  }
4089 diff -r d35bd12bba15 sql/sql_yacc.yy
4090 --- a/sql/sql_yacc.yy   Mon Dec 22 22:51:44 2008 -0800
4091 +++ b/sql/sql_yacc.yy   Mon Dec 22 22:53:26 2008 -0800
4092 @@ -523,6 +523,7 @@
4093  %token  CHECK_SYM
4094  %token  CIPHER_SYM
4095  %token  CLIENT_SYM
4096 +%token CLIENT_STATS_SYM
4097  %token  CLOSE_SYM
4098  %token  COALESCE
4099  %token  CODE_SYM
4100 @@ -680,6 +681,7 @@
4101  %token  IMPORT
4102  %token  INDEXES
4103  %token  INDEX_SYM
4104 +%token INDEX_STATS_SYM
4105  %token  INFILE
4106  %token  INNER_SYM
4107  %token  INNOBASE_SYM
4108 @@ -909,6 +911,7 @@
4109  %token  SIGNED_SYM
4110  %token  SIMPLE_SYM
4111  %token  SLAVE
4112 +%token  SLOW_SYM
4113  %token  SMALLINT
4114  %token  SNAPSHOT_SYM
4115  %token  SOUNDS_SYM
4116 @@ -949,6 +952,7 @@
4117  %token  TABLES
4118  %token  TABLESPACE
4119  %token  TABLE_SYM
4120 +%token TABLE_STATS_SYM
4121  %token  TEMPORARY
4122  %token  TEMPTABLE_SYM
4123  %token  TERMINATED
4124 @@ -991,6 +995,7 @@
4125  %token  UPGRADE_SYM
4126  %token  USAGE
4127  %token  USER
4128 +%token USER_STATS_SYM
4129  %token  USE_FRM
4130  %token  USE_SYM
4131  %token  USING
4132 @@ -8244,6 +8249,38 @@
4133            {
4134             Lex->sql_command = SQLCOM_SHOW_SLAVE_STAT;
4135            }
4136 +        | CLIENT_STATS_SYM wild_and_where 
4137 +          {
4138 +           LEX *lex= Lex;
4139 +          Lex->sql_command = SQLCOM_SELECT;
4140 +           lex->orig_sql_command= SQLCOM_SHOW_CLIENT_STATS;
4141 +           if (prepare_schema_table(YYTHD, lex, 0, SCH_CLIENT_STATS))
4142 +             MYSQL_YYABORT;
4143 +          }
4144 +        | USER_STATS_SYM wild_and_where 
4145 +          {
4146 +           LEX *lex= Lex;
4147 +          lex->sql_command = SQLCOM_SELECT;
4148 +           lex->orig_sql_command= SQLCOM_SHOW_USER_STATS;
4149 +           if (prepare_schema_table(YYTHD, lex, 0, SCH_USER_STATS))
4150 +             MYSQL_YYABORT;
4151 +          }
4152 +        | TABLE_STATS_SYM wild_and_where
4153 +          {
4154 +           LEX *lex= Lex;
4155 +           lex->sql_command= SQLCOM_SELECT;
4156 +           lex->orig_sql_command= SQLCOM_SHOW_TABLE_STATS;
4157 +           if (prepare_schema_table(YYTHD, lex, 0, SCH_TABLE_STATS))
4158 +             MYSQL_YYABORT;
4159 +          }
4160 +        | INDEX_STATS_SYM wild_and_where
4161 +          {
4162 +           LEX *lex= Lex;
4163 +           lex->sql_command= SQLCOM_SELECT;
4164 +           lex->orig_sql_command= SQLCOM_SHOW_INDEX_STATS;
4165 +           if (prepare_schema_table(YYTHD, lex, 0, SCH_INDEX_STATS))
4166 +             MYSQL_YYABORT;
4167 +          }
4168         | CREATE PROCEDURE sp_name
4169           {
4170             LEX *lex= Lex;
4171 @@ -8448,9 +8485,14 @@
4172         | LOGS_SYM      { Lex->type|= REFRESH_LOG; }
4173         | STATUS_SYM    { Lex->type|= REFRESH_STATUS; }
4174          | SLAVE         { Lex->type|= REFRESH_SLAVE; }
4175 +       | SLOW_SYM QUERY_SYM LOGS_SYM { Lex->type |= REFRESH_SLOW_QUERY_LOG; }
4176          | MASTER_SYM    { Lex->type|= REFRESH_MASTER; }
4177         | DES_KEY_FILE  { Lex->type|= REFRESH_DES_KEY_FILE; }
4178 -       | RESOURCES     { Lex->type|= REFRESH_USER_RESOURCES; };
4179 +       | RESOURCES     { Lex->type|= REFRESH_USER_RESOURCES; }
4180 +       | CLIENT_STATS_SYM { Lex->type|= REFRESH_CLIENT_STATS; }
4181 +       | USER_STATS_SYM { Lex->type|= REFRESH_USER_STATS; }
4182 +       | TABLE_STATS_SYM { Lex->type|= REFRESH_TABLE_STATS; }
4183 +       | INDEX_STATS_SYM { Lex->type|= REFRESH_INDEX_STATS; };
4184  
4185  opt_table_list:
4186         /* empty */  {;}
4187 @@ -9439,6 +9481,7 @@
4188         | CHAIN_SYM             {}
4189         | CHANGED               {}
4190         | CIPHER_SYM            {}
4191 +       | CLIENT_STATS_SYM      {}
4192         | CLIENT_SYM            {}
4193          | CODE_SYM              {}
4194         | COLLATION_SYM         {}
4195 @@ -9491,6 +9534,7 @@
4196         | HOSTS_SYM             {}
4197         | HOUR_SYM              {}
4198         | IDENTIFIED_SYM        {}
4199 +       | INDEX_STATS_SYM       {}
4200         | INVOKER_SYM           {}
4201         | IMPORT                {}
4202         | INDEXES               {}
4203 @@ -9600,6 +9644,7 @@
4204         | SIMPLE_SYM            {}
4205         | SHARE_SYM             {}
4206         | SHUTDOWN              {}
4207 +       | SLOW_SYM              {}
4208         | SNAPSHOT_SYM          {}
4209         | SOUNDS_SYM            {}
4210         | SOURCE_SYM            {}
4211 @@ -9616,6 +9661,7 @@
4212          | SUSPEND_SYM           {}
4213          | SWAPS_SYM             {}
4214         | SWITCHES_SYM          {}
4215 +       | TABLE_STATS_SYM       {}
4216          | TABLES                {}
4217         | TABLESPACE            {}
4218         | TEMPORARY             {}
4219 @@ -9636,6 +9682,7 @@
4220         | UNKNOWN_SYM           {}
4221         | UNTIL_SYM             {}
4222         | USER                  {}
4223 +       | USER_STATS_SYM        {}
4224         | USE_FRM               {}
4225         | VARIABLES             {}
4226         | VIEW_SYM              {}
4227 diff -r d35bd12bba15 sql/structs.h
4228 --- a/sql/structs.h     Mon Dec 22 22:51:44 2008 -0800
4229 +++ b/sql/structs.h     Mon Dec 22 22:53:26 2008 -0800
4230 @@ -273,6 +273,98 @@
4231    time_t intime;
4232  } USER_CONN;
4233  
4234 +typedef struct st_user_stats {
4235 +  char user[USERNAME_LENGTH + 1];
4236 +  // Account name the user is mapped to when this is a user from mapped_user.
4237 +  // Otherwise, the same value as user.
4238 +  char priv_user[USERNAME_LENGTH + 1];
4239 +  uint total_connections;
4240 +  uint concurrent_connections;
4241 +  time_t connected_time;  // in seconds
4242 +  double busy_time;       // in seconds
4243 +  double cpu_time;        // in seconds
4244 +  ulonglong bytes_received;
4245 +  ulonglong bytes_sent;
4246 +  ulonglong binlog_bytes_written;
4247 +  ha_rows rows_fetched, rows_updated, rows_read;
4248 +  ulonglong select_commands, update_commands, other_commands;
4249 +  ulonglong commit_trans, rollback_trans;
4250 +  ulonglong denied_connections, lost_connections;
4251 +  ulonglong access_denied_errors;
4252 +  ulonglong empty_queries;
4253 +} USER_STATS;
4254 +
4255 +/* Lookup function for hash tables with USER_STATS entries */
4256 +extern byte *get_key_user_stats(USER_STATS *user_stats, uint *length,
4257 +                                my_bool not_used __attribute__((unused)));
4258 +
4259 +/* Free all memory for a hash table with USER_STATS entries */
4260 +extern void free_user_stats(USER_STATS* user_stats);
4261 +
4262 +/* Intialize an instance of USER_STATS */
4263 +extern void
4264 +init_user_stats(USER_STATS *user_stats,
4265 +                const char *user,
4266 +                const char *priv_user,
4267 +                uint total_connections,
4268 +                uint concurrent_connections,
4269 +                time_t connected_time,
4270 +                double busy_time,
4271 +                double cpu_time,
4272 +                ulonglong bytes_received,
4273 +                ulonglong bytes_sent,
4274 +                ulonglong binlog_bytes_written,
4275 +                ha_rows rows_fetched,
4276 +                ha_rows rows_updated,
4277 +                ha_rows rows_read,
4278 +                ulonglong select_commands,
4279 +                ulonglong update_commands,
4280 +                ulonglong other_commands,
4281 +                ulonglong commit_trans,
4282 +                ulonglong rollback_trans,
4283 +                ulonglong denied_connections,
4284 +                ulonglong lost_connections,
4285 +                ulonglong access_denied_errors,
4286 +                ulonglong empty_queries);
4287 +
4288 +/* Increment values of an instance of USER_STATS */
4289 +extern void
4290 +add_user_stats(USER_STATS *user_stats,
4291 +               uint total_connections,
4292 +               uint concurrent_connections,
4293 +               time_t connected_time,
4294 +               double busy_time,
4295 +               double cpu_time,
4296 +               ulonglong bytes_received,
4297 +               ulonglong bytes_sent,
4298 +               ulonglong binlog_bytes_written,
4299 +               ha_rows rows_fetched,
4300 +               ha_rows rows_updated,
4301 +               ha_rows rows_read,
4302 +               ulonglong select_commands,
4303 +               ulonglong update_commands,
4304 +               ulonglong other_commands,
4305 +               ulonglong commit_trans,
4306 +               ulonglong rollback_trans,
4307 +               ulonglong denied_connections,
4308 +               ulonglong lost_connections,
4309 +               ulonglong access_denied_errors,
4310 +               ulonglong empty_queries);
4311 +
4312 +typedef struct st_table_stats {
4313 +  char table[NAME_LEN * 2 + 2];  // [db] + '.' + [table] + '\0'
4314 +  ulonglong rows_read, rows_changed;
4315 +  ulonglong rows_changed_x_indexes;
4316 +  /* Stores enum db_type, but forward declarations cannot be done */
4317 +  int engine_type;
4318 +} TABLE_STATS;
4319 +
4320 +typedef struct st_index_stats {
4321 +  char index[NAME_LEN * 3 + 3];  // [db] + '.' + [table] + '.' + [index] + '\0'
4322 +  ulonglong rows_read;
4323 +} INDEX_STATS;
4324 +
4325 +
4326         /* Bits in form->update */
4327  #define REG_MAKE_DUPP          1       /* Make a copy of record when read */
4328  #define REG_NEW_RECORD         2       /* Write a new record if not found */
4329 diff -r d35bd12bba15 sql/table.h
4330 --- a/sql/table.h       Mon Dec 22 22:51:44 2008 -0800
4331 +++ b/sql/table.h       Mon Dec 22 22:53:26 2008 -0800
4332 @@ -371,10 +371,12 @@
4333  enum enum_schema_tables
4334  {
4335    SCH_CHARSETS= 0,
4336 +  SCH_CLIENT_STATS,
4337    SCH_COLLATIONS,
4338    SCH_COLLATION_CHARACTER_SET_APPLICABILITY,
4339    SCH_COLUMNS,
4340    SCH_COLUMN_PRIVILEGES,
4341 +  SCH_INDEX_STATS,
4342    SCH_KEY_COLUMN_USAGE,
4343    SCH_OPEN_TABLES,
4344    SCH_PROFILES,
4345 @@ -387,8 +389,10 @@
4346    SCH_TABLE_CONSTRAINTS,
4347    SCH_TABLE_NAMES,
4348    SCH_TABLE_PRIVILEGES,
4349 +  SCH_TABLE_STATS,
4350    SCH_TRIGGERS,
4351    SCH_USER_PRIVILEGES,
4352 +  SCH_USER_STATS,
4353    SCH_VARIABLES,
4354    SCH_VIEWS
4355  };
4356 diff -r d35bd12bba15 strings/Makefile.in
4357 --- a/strings/Makefile.in       Mon Dec 22 22:51:44 2008 -0800
4358 +++ b/strings/Makefile.in       Mon Dec 22 22:53:26 2008 -0800
4359 @@ -361,6 +361,7 @@
4360  LIBDL = @LIBDL@
4361  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
4362  LIBOBJS = @LIBOBJS@
4363 +LIBRT = @LIBRT@
4364  LIBS = @LIBS@
4365  LIBTOOL = @LIBTOOL@
4366  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
4367 diff -r d35bd12bba15 support-files/MacOSX/Makefile.in
4368 --- a/support-files/MacOSX/Makefile.in  Mon Dec 22 22:51:44 2008 -0800
4369 +++ b/support-files/MacOSX/Makefile.in  Mon Dec 22 22:53:26 2008 -0800
4370 @@ -171,6 +171,7 @@
4371  LIBDL = @LIBDL@
4372  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
4373  LIBOBJS = @LIBOBJS@
4374 +LIBRT = @LIBRT@
4375  LIBS = @LIBS@
4376  LIBTOOL = @LIBTOOL@
4377  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
4378 diff -r d35bd12bba15 support-files/Makefile.in
4379 --- a/support-files/Makefile.in Mon Dec 22 22:51:44 2008 -0800
4380 +++ b/support-files/Makefile.in Mon Dec 22 22:53:26 2008 -0800
4381 @@ -191,6 +191,7 @@
4382  LIBDL = @LIBDL@
4383  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
4384  LIBOBJS = @LIBOBJS@
4385 +LIBRT = @LIBRT@
4386  LIBS = @LIBS@
4387  LIBTOOL = @LIBTOOL@
4388  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
4389 diff -r d35bd12bba15 support-files/RHEL4-SElinux/Makefile.in
4390 --- a/support-files/RHEL4-SElinux/Makefile.in   Mon Dec 22 22:51:44 2008 -0800
4391 +++ b/support-files/RHEL4-SElinux/Makefile.in   Mon Dec 22 22:53:26 2008 -0800
4392 @@ -169,6 +169,7 @@
4393  LIBDL = @LIBDL@
4394  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
4395  LIBOBJS = @LIBOBJS@
4396 +LIBRT = @LIBRT@
4397  LIBS = @LIBS@
4398  LIBTOOL = @LIBTOOL@
4399  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
4400 diff -r d35bd12bba15 tests/Makefile.in
4401 --- a/tests/Makefile.in Mon Dec 22 22:51:44 2008 -0800
4402 +++ b/tests/Makefile.in Mon Dec 22 22:53:26 2008 -0800
4403 @@ -215,6 +215,7 @@
4404  LIBDL = @LIBDL@
4405  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
4406  LIBOBJS = @LIBOBJS@
4407 +LIBRT = @LIBRT@
4408  LIBS = @CLIENT_LIBS@
4409  LIBTOOL = @LIBTOOL@
4410  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
4411 diff -r d35bd12bba15 tools/Makefile.in
4412 --- a/tools/Makefile.in Mon Dec 22 22:51:44 2008 -0800
4413 +++ b/tools/Makefile.in Mon Dec 22 22:53:26 2008 -0800
4414 @@ -189,6 +189,7 @@
4415  LIBDL = @LIBDL@
4416  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
4417  LIBOBJS = @LIBOBJS@
4418 +LIBRT = @LIBRT@
4419  LIBS = @LIBS@
4420  LIBTOOL = @LIBTOOL@
4421  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
4422 diff -r d35bd12bba15 vio/Makefile.in
4423 --- a/vio/Makefile.in   Mon Dec 22 22:51:44 2008 -0800
4424 +++ b/vio/Makefile.in   Mon Dec 22 22:53:26 2008 -0800
4425 @@ -198,6 +198,7 @@
4426  LIBDL = @LIBDL@
4427  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
4428  LIBOBJS = @LIBOBJS@
4429 +LIBRT = @LIBRT@
4430  LIBS = @LIBS@
4431  LIBTOOL = @LIBTOOL@
4432  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
4433 diff -r d35bd12bba15 win/Makefile.in
4434 --- a/win/Makefile.in   Mon Dec 22 22:51:44 2008 -0800
4435 +++ b/win/Makefile.in   Mon Dec 22 22:53:26 2008 -0800
4436 @@ -167,6 +167,7 @@
4437  LIBDL = @LIBDL@
4438  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
4439  LIBOBJS = @LIBOBJS@
4440 +LIBRT = @LIBRT@
4441  LIBS = @LIBS@
4442  LIBTOOL = @LIBTOOL@
4443  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
4444 diff -r d35bd12bba15 zlib/Makefile.in
4445 --- a/zlib/Makefile.in  Mon Dec 22 22:51:44 2008 -0800
4446 +++ b/zlib/Makefile.in  Mon Dec 22 22:53:26 2008 -0800
4447 @@ -206,6 +206,7 @@
4448  LIBDL = @LIBDL@
4449  LIBEDIT_LOBJECTS = @LIBEDIT_LOBJECTS@
4450  LIBOBJS = @LIBOBJS@
4451 +LIBRT = @LIBRT@
4452  LIBS = $(NON_THREADED_LIBS)
4453  LIBTOOL = @LIBTOOL@
4454  LIB_EXTRA_CCFLAGS = @LIB_EXTRA_CCFLAGS@
This page took 2.081226 seconds and 4 git commands to generate.