Commit a5fda39d authored by unknown's avatar unknown
Browse files

Merge lthalmann@bk-internal.mysql.com:/home/bk/mysql-5.1-new

into  mysql.com:/users/lthalmann/bkroot/mysql-5.1-new

parents 145cb3ef a22bd444
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -49,6 +49,8 @@ mysqlbinlog_SOURCES = mysqlbinlog.cc $(top_srcdir)/mysys/mf_tempdir.c \
				$(top_srcdir)/mysys/base64.c
mysqlbinlog_LDADD =		$(LDADD) $(CXXLDFLAGS)
mysqlslap_LDADD =		$(LDADD) $(CXXLDFLAGS) $(CLIENT_THREAD_LIBS)
mysqlimport_LDADD =		$(LDADD) $(CXXLDFLAGS) $(CLIENT_THREAD_LIBS) \
				$(top_builddir)/mysys/libmysys.a 
mysqltestmanager_pwgen_SOURCES =   mysqlmanager-pwgen.c 
mysqltestmanagerc_SOURCES=      mysqlmanagerc.c $(yassl_dummy_link_fix)
mysqlcheck_SOURCES=             mysqlcheck.c $(yassl_dummy_link_fix)
@@ -57,7 +59,8 @@ mysqlslap_SOURCES= mysqlslap.c $(top_srcdir)/mysys/my_lock.c \
				$(top_srcdir)/mysys/my_alarm.c \
  				$(yassl_dummy_link_fix)
mysqldump_SOURCES=              mysqldump.c my_user.c $(yassl_dummy_link_fix)
mysqlimport_SOURCES=            mysqlimport.c $(yassl_dummy_link_fix)
mysqlimport_SOURCES=            mysqlimport.c \
				$(yassl_dummy_link_fix)
sql_src=log_event.h mysql_priv.h log_event.cc my_decimal.h my_decimal.cc
strings_src=decimal.c

+1 −0
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@ enum options_client
  OPT_MYSQL_LOCK_DIRECTORY,
  OPT_MYSQL_SLAP_SLAVE,
  OPT_USE_THREADS,
  OPT_IMPORT_USE_THREADS,
  OPT_MYSQL_NUMBER_OF_QUERY,
  OPT_MYSQL_PRESERVE_SCHEMA,
  OPT_IGNORE_TABLE,OPT_INSERT_IGNORE,OPT_SHOW_WARNINGS,OPT_DROP_DATABASE,
+115 −19
Original line number Diff line number Diff line
@@ -29,6 +29,12 @@

#include "client_priv.h"
#include "mysql_version.h"
#include <my_pthread.h>


/* Global Thread counter */
int counter= 0;
pthread_mutex_t counter_mutex;

static void db_error_with_table(MYSQL *mysql, char *table);
static void db_error(MYSQL *mysql);
@@ -39,6 +45,7 @@ static char *add_load_option(char *ptr,const char *object,
static my_bool	verbose=0,lock_tables=0,ignore_errors=0,opt_delete=0,
		replace=0,silent=0,ignore=0,opt_compress=0,
                opt_low_priority= 0, tty_password= 0;
static my_bool opt_use_threads= 0;
static uint     opt_local_file=0;
static MYSQL	mysql_connection;
static char	*opt_password=0, *current_user=0,
@@ -108,8 +115,9 @@ static struct my_option my_long_options[] =
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
  {"local", 'L', "Read all files through the client.", (gptr*) &opt_local_file,
   (gptr*) &opt_local_file, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
  {"lock-tables", 'l', "Lock all tables for write.", (gptr*) &lock_tables,
   (gptr*) &lock_tables, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
  {"lock-tables", 'l', "Lock all tables for write (this disables threads).",
    (gptr*) &lock_tables, (gptr*) &lock_tables, 0, GET_BOOL, NO_ARG, 
    0, 0, 0, 0, 0, 0},
  {"low-priority", OPT_LOW_PRIORITY,
   "Use LOW_PRIORITY when updating the table.", (gptr*) &opt_low_priority,
   (gptr*) &opt_low_priority, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
@@ -138,6 +146,11 @@ static struct my_option my_long_options[] =
   (gptr*) &opt_mysql_unix_port, (gptr*) &opt_mysql_unix_port, 0, GET_STR,
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
#include <sslopt-longopts.h>
  {"use-threads", OPT_USE_THREADS,
    "Parrelize the loading of files. Requires an arguement for the number \
      threads to use for loading of data.",
      (gptr*) &opt_use_threads, (gptr*) &opt_use_threads, 0, 
      GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
#ifndef DONT_ALLOW_USER_CHANGE
  {"user", 'u', "User for login if not current user.", (gptr*) &current_user,
   (gptr*) &current_user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
@@ -287,7 +300,7 @@ static int write_to_table(char *filename, MYSQL *sock)
  {
    if (verbose)
      fprintf(stdout, "Deleting the old data from table %s\n", tablename);
    sprintf(sql_statement, "DELETE FROM %s", tablename);
    snprintf(sql_statement, FN_REFLEN*16+256, "DELETE FROM %s", tablename);
    if (mysql_query(sock, sql_statement))
    {
      db_error_with_table(sock, tablename);
@@ -497,12 +510,41 @@ static char *field_escape(char *to,const char *from,uint length)
}


int
worker_thread(char *raw_table_name)
{
  MYSQL *sock= 0;
  if (!(sock= db_connect(current_host,current_db,current_user,opt_password)))
  {
    goto error;
  }

  if (mysql_query(sock, "set @@character_set_database=binary;"))
  {
    db_error(sock); /* We shall countinue here, if --force was given */
    goto error;
  }

  /*
    We should do something about the error
  */
  write_to_table(raw_table_name, sock);

error:
  if (sock)
    db_disconnect(current_host, sock);

  pthread_mutex_lock(&counter_mutex);
  counter--;
  pthread_mutex_unlock(&counter_mutex);
  return 0;
}


int main(int argc, char **argv)
{
  int exitcode=0, error=0;
  char **argv_to_free;
  MYSQL *sock=0;
  MY_INIT(argv[0]);

  load_defaults("my",load_default_groups,&argc,&argv);
@@ -513,6 +555,59 @@ int main(int argc, char **argv)
    free_defaults(argv_to_free);
    return(1);
  }

  if (opt_use_threads && !lock_tables)
  {
    pthread_t mainthread;            /* Thread descriptor */
    pthread_attr_t attr;          /* Thread attributes */
    VOID(pthread_mutex_init(&counter_mutex, NULL));

    for (; *argv != NULL; argv++) // Loop through tables
    {
      /*
        If we hit thread count limit we loop until some threads exit.
        We sleep for a second, so that we don't chew up a lot of 
        CPU in the loop.
      */
sanity_label:
      if (counter == opt_use_threads)
      {
        sleep(1);
        goto sanity_label;
      }
      pthread_mutex_lock(&counter_mutex);
      counter++;
      pthread_mutex_unlock(&counter_mutex);
      pthread_attr_init(&attr);
      pthread_attr_setdetachstate(&attr,
                                   PTHREAD_CREATE_DETACHED);

      /* now create the thread */
      if (pthread_create(&mainthread, &attr, (void *)worker_thread, 
                         (void *)*argv) != 0)
      {
        pthread_mutex_lock(&counter_mutex);
        counter--;
        pthread_mutex_unlock(&counter_mutex);
        fprintf(stderr,"%s: Could not create thread\n",
                my_progname);
      }
    }

    /*
      We loop until we know that all children have cleaned up.
    */
loop_label:
    if (counter)
    {
      sleep(1);
      goto loop_label;
    }
    VOID(pthread_mutex_destroy(&counter_mutex));
  }
  else
  {
    MYSQL *sock= 0;
    if (!(sock= db_connect(current_host,current_db,current_user,opt_password)))
    {
      free_defaults(argv_to_free);
@@ -532,6 +627,7 @@ int main(int argc, char **argv)
        if (exitcode == 0)
          exitcode = error;
    db_disconnect(current_host, sock);
  }
  my_free(opt_password,MYF(MY_ALLOW_ZERO_PTR));
#ifdef HAVE_SMEM
  my_free(shared_memory_base_name,MYF(MY_ALLOW_ZERO_PTR));
+32 −0
Original line number Diff line number Diff line
@@ -2650,3 +2650,35 @@ DELIMITER ;

DROP TRIGGER tr1;
DROP TABLE t1;
create table t1 (a text , b text);
create table t2 (a text , b text);
insert t1 values ("Duck, Duck", "goose");
insert t1 values ("Duck, Duck", "pidgeon");
insert t2 values ("We the people", "in order to perform");
insert t2 values ("a more perfect", "union");
select * from t1;
a	b
Duck, Duck	goose
Duck, Duck	pidgeon
select * from t2;
a	b
We the people	in order to perform
a more perfect	union
test.t1: Records: 2  Deleted: 0  Skipped: 0  Warnings: 0
test.t2: Records: 2  Deleted: 0  Skipped: 0  Warnings: 0
test.t1: Records: 2  Deleted: 0  Skipped: 0  Warnings: 0
test.t2: Records: 2  Deleted: 0  Skipped: 0  Warnings: 0
select * from t1;
a	b
Duck, Duck	goose
Duck, Duck	pidgeon
Duck, Duck	goose
Duck, Duck	pidgeon
select * from t2;
a	b
We the people	in order to perform
a more perfect	union
We the people	in order to perform
a more perfect	union
drop table t1;
drop table t2;
+29 −0
Original line number Diff line number Diff line
drop database if exists testdb1;
create database testdb1 default character set latin2;
use testdb1;
create table t1 (a int);
insert into t1 values (1),(2),(3);
show create database testdb1;
Database	Create Database
testdb1	CREATE DATABASE `testdb1` /*!40100 DEFAULT CHARACTER SET latin2 */
show tables;
Tables_in_testdb1
t1
rename database testdb1 to testdb2;
show create database testdb1;
ERROR 42000: Unknown database 'testdb1'
show create database testdb2;
Database	Create Database
testdb2	CREATE DATABASE `testdb2` /*!40100 DEFAULT CHARACTER SET latin2 */
select database();
database()
testdb2
show tables;
Tables_in_testdb2
t1
select a from t1 order by a;
a
1
2
3
drop database testdb2;
Loading