folays

mysqldump big select MAX_JOIN_SIZE rows

Jul 29th, 2011
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.03 KB | None | 0 0
  1. /*
  2.  * Copyright (c) 2011
  3.  *           Eric Gouyer <folays@folays.net>
  4.  *
  5.  * Permission to use, copy, modify, and distribute this software for any
  6.  * purpose with or without fee is hereby granted, provided that the above
  7.  * copyright notice and this permission notice appear in all copies.
  8.  *
  9.  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10.  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11.  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12.  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14.  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15.  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16.  */
  17.  
  18. /*
  19.  * Compile with:
  20.  * gcc -o libpreload-mysqldump.so -shared libpreload-mysqldump.c -fPIC -ldl
  21.  * Use with:
  22.  * LD_PRELOAD="`dirname $0`/libpreload-mysqldump.so" mysqldump ...
  23.  */
  24.  
  25. #include <stdlib.h>
  26. #include <stdio.h>
  27. #include <string.h>
  28. #include <dlfcn.h>
  29. #include <sys/types.h>
  30. #include <signal.h>
  31. #include <errno.h>
  32.  
  33. #define HOOK_LIB_PATH "/usr/lib/libmysqlclient.so.16"
  34. #define HOOK_INIT(fname) static void *handle, (*f)(); if (!handle) handle = hook_init_ptr(&f, fname);
  35.  
  36. static void *hook_init_ptr(void (**f)(), const char *fname)
  37. {
  38.   static void *handle;
  39.  
  40.   handle = dlopen(HOOK_LIB_PATH, RTLD_LAZY);
  41.   if (!handle)
  42.     err(1, "dlopen %s", HOOK_LIB_PATH);
  43.   *f = dlsym(handle, fname);
  44.   if (!*f)
  45.     err(1, "dlsym %s", fname);
  46.   return handle;
  47. }
  48.  
  49. void *mysql_real_connect(void *mysql, const char *host, const char *user, const char *passwd,
  50.                          const char *db, unsigned int port, const char *unix_socket,
  51.                          unsigned long clientflag)
  52. {
  53.   HOOK_INIT("mysql_real_connect");
  54.  
  55.   void *ret = ((void *(*)())f)(mysql, host, user, passwd, db, port, unix_socket, clientflag);
  56.   printf("mysql_real_connect\n");
  57.   mysql_query(mysql, "SET SQL_BIG_SELECTS=1");
  58.   return ret;
  59. }
Add Comment
Please, Sign In to add comment