Commit b9a9ae56 authored by Davi Arnaut's avatar Davi Arnaut
Browse files

Merge mysql-5.0-bugteam into mysql-5.0

parents 25dd8b33 d5620961
Loading
Loading
Loading
Loading
+56 −81
Original line number Diff line number Diff line
@@ -259,6 +259,10 @@ get_one_option(int optid, const struct my_option *opt,
}


/**
  Run a command using the shell, storing its output in the supplied dynamic
  string.
*/
static int run_command(char* cmd,
                       DYNAMIC_STRING *ds_res)
{
@@ -331,36 +335,16 @@ static int run_tool(char *tool_path, DYNAMIC_STRING *ds_res, ...)
}


/*
  Try to get the full path to this exceutable

  Return 0 if path found

/**
  Look for the filename of given tool, with the presumption that it is in the
  same directory as mysql_upgrade and that the same executable-searching 
  mechanism will be used when we run our sub-shells with popen() later.
*/

static my_bool get_full_path_to_executable(char* path)
static void find_tool(char *tool_executable_name, const char *tool_name, 
                      const char *self_name)
{
  my_bool ret;
  DBUG_ENTER("get_full_path_to_executable");
#ifdef __WIN__
  ret= (GetModuleFileName(NULL, path, FN_REFLEN) == 0);
#else
  /* my_readlink returns 0 if a symlink was read */
  ret= (my_readlink(path, "/proc/self/exe", MYF(0)) != 0);
  /* Might also want to try with /proc/$$/exe if the above fails */
#endif
  DBUG_PRINT("exit", ("path: %s", path));
  DBUG_RETURN(ret);
}


/*
  Look for the tool in the same directory as mysql_upgrade.
*/
  char *last_fn_libchar;

static void find_tool(char *tool_path, const char *tool_name)
{
  char path[FN_REFLEN];
  DYNAMIC_STRING ds_tmp;
  DBUG_ENTER("find_tool");
  DBUG_PRINT("enter", ("progname: %s", my_progname));
@@ -368,36 +352,24 @@ static void find_tool(char *tool_path, const char *tool_name)
  if (init_dynamic_string(&ds_tmp, "", 32, 32))
    die("Out of memory");

  /* Initialize path with the full path to this program */
  if (get_full_path_to_executable(path))
  last_fn_libchar= strrchr(self_name, FN_LIBCHAR);

  if (last_fn_libchar == NULL)
  {
    /*
      Easy way to get full executable path failed, try
      other methods
      mysql_upgrade was found by the shell searching the path.  A sibling
      next to us should be found the same way.
    */
    if (my_progname[0] == FN_LIBCHAR)
    {
      /* 1. my_progname contains full path */
      strmake(path, my_progname, FN_REFLEN);
    }
    else if (my_progname[0] == '.')
    {
      /* 2. my_progname contains relative path, prepend wd */
      char buf[FN_REFLEN];
      my_getwd(buf, FN_REFLEN, MYF(0));
      my_snprintf(path, FN_REFLEN, "%s%s", buf, my_progname);
    strncpy(tool_executable_name, tool_name, FN_REFLEN);
  }
  else
  {
      /* 3. Just go for it and hope tool is in path */
      path[0]= 0;
    }
  }
    int len;

  DBUG_PRINT("info", ("path: '%s'", path));

  /* Chop off binary name (i.e mysql-upgrade) from path */
  dirname_part(path, path);
    /*
      mysql_upgrade was run absolutely or relatively.  We can find a sibling
      by replacing our name after the LIBCHAR with the new tool name.
    */

    /*
      When running in a not yet installed build and using libtool,
@@ -407,38 +379,32 @@ static void find_tool(char *tool_path, const char *tool_name)
      mysqlcheck). Thus if path ends in .libs/, step up one directory
      and execute the tools from there
    */
  path[max((strlen(path)-1), 0)]= 0;   /* Chop off last / */
  if (strncmp(path + dirname_length(path), ".libs", 5) == 0)
    if (((last_fn_libchar - 6) >= self_name) &&
        (strncmp(last_fn_libchar - 5, ".libs", 5) == 0) &&
        (*(last_fn_libchar - 6) == FN_LIBCHAR))
    {
    DBUG_PRINT("info", ("Chopping off .libs from '%s'", path));

    /* Chop off .libs */
    dirname_part(path, path);
      DBUG_PRINT("info", ("Chopping off \".libs\" from end of path"));
      last_fn_libchar -= 6;
    }

    len= last_fn_libchar - self_name;

  DBUG_PRINT("info", ("path: '%s'", path));

  /* Format name of the tool to search for */
  fn_format(tool_path, tool_name,
            path, "", MYF(MY_REPLACE_DIR));

  verbose("Looking for '%s' in: %s", tool_name, tool_path);
    my_snprintf(tool_executable_name, FN_REFLEN, "%.*s%c%s",
                len, self_name, FN_LIBCHAR, tool_name);
  }

  /* Make sure the tool exists */
  if (my_access(tool_path, F_OK) != 0)
    die("Can't find '%s'", tool_path);
  verbose("Looking for '%s' as: %s", tool_name, tool_executable_name);

  /*
    Make sure it can be executed
  */
  if (run_tool(tool_path,
  if (run_tool(tool_executable_name,
               &ds_tmp, /* Get output from command, discard*/
               "--help",
               "2>&1",
               IF_WIN("> NUL", "> /dev/null"),
               NULL))
    die("Can't execute '%s'", tool_path);
    die("Can't execute '%s'", tool_executable_name);

  dynstr_free(&ds_tmp);

@@ -748,11 +714,20 @@ static const char *load_default_groups[]=

int main(int argc, char **argv)
{
  char self_name[FN_REFLEN];

  MY_INIT(argv[0]);
#ifdef __NETWARE__
  setscreenmode(SCR_AUTOCLOSE_ON_EXIT);
#endif

#if __WIN__
  if (GetModuleFileName(NULL, self_name, FN_REFLEN) == 0)
#endif
  {
    strncpy(self_name, argv[0], FN_REFLEN);
  }

  if (init_dynamic_string(&ds_args, "", 512, 256))
    die("Out of memory");

@@ -774,10 +749,10 @@ int main(int argc, char **argv)
  dynstr_append(&ds_args, " ");

  /* Find mysql */
  find_tool(mysql_path, IF_WIN("mysql.exe", "mysql"));
  find_tool(mysql_path, IF_WIN("mysql.exe", "mysql"), self_name);

  /* Find mysqlcheck */
  find_tool(mysqlcheck_path, IF_WIN("mysqlcheck.exe", "mysqlcheck"));
  find_tool(mysqlcheck_path, IF_WIN("mysqlcheck.exe", "mysqlcheck"), self_name);

  /*
    Read the mysql_upgrade_info file to check if mysql_upgrade
+46 −0
Original line number Diff line number Diff line
@@ -131,3 +131,49 @@ drop table t1;
select if(0, 18446744073709551610, 18446744073709551610);
if(0, 18446744073709551610, 18446744073709551610)
18446744073709551610
CREATE TABLE t1(a DECIMAL(10,3));
SELECT t1.a,
IF((ROUND(t1.a,2)=1), 2,
IF((ROUND(t1.a,2)=1), 2,
IF((ROUND(t1.a,2)=1), 2,
IF((ROUND(t1.a,2)=1), 2,
IF((ROUND(t1.a,2)=1), 2,
IF((ROUND(t1.a,2)=1), 2,
IF((ROUND(t1.a,2)=1), 2,
IF((ROUND(t1.a,2)=1), 2,
IF((ROUND(t1.a,2)=1), 2,
IF((ROUND(t1.a,2)=1), 2,
IF((ROUND(t1.a,2)=1), 2,
IF((ROUND(t1.a,2)=1), 2,
IF((ROUND(t1.a,2)=1), 2,
IF((ROUND(t1.a,2)=1), 2,
IF((ROUND(t1.a,2)=1), 2,
IF((ROUND(t1.a,2)=1), 2,
IF((ROUND(t1.a,2)=1), 2,
IF((ROUND(t1.a,2)=1), 2,
IF((ROUND(t1.a,2)=1), 2,
IF((ROUND(t1.a,2)=1), 2,
IF((ROUND(t1.a,2)=1), 2,
IF((ROUND(t1.a,2)=1), 2,
IF((ROUND(t1.a,2)=1), 2,
IF((ROUND(t1.a,2)=1), 2,
IF((ROUND(t1.a,2)=1), 2,
IF((ROUND(t1.a,2)=1), 2,
IF((ROUND(t1.a,2)=1), 2,
IF((ROUND(t1.a,2)=1), 2,
IF((ROUND(t1.a,2)=1), 2,
IF((ROUND(t1.a,2)=1), 2,0)))))))))))))))))))))))))))))) + 1
FROM t1;
a	IF((ROUND(t1.a,2)=1), 2,
IF((ROUND(t1.a,2)=1), 2,
IF((ROUND(t1.a,2)=1), 2,
IF((ROUND(t1.a,2)=1), 2,
IF((ROUND(t1.a,2)=1), 2,
IF((ROUND(t1.a,2)=1), 2,
IF((ROUND(t1.a,2)=1), 2,
IF((ROUND(t1.a,2)=1), 2,
IF((ROUND(t1.a,2)=1), 2,
IF((ROUND(t1.a,2)=1), 2,
IF((R
DROP TABLE t1;
End of 5.0 tests
+15 −0
Original line number Diff line number Diff line
@@ -1246,4 +1246,19 @@ set global innodb_autoextend_increment=@my_innodb_autoextend_increment;
set @my_innodb_commit_concurrency=@@global.innodb_commit_concurrency;
set global innodb_commit_concurrency=0;
set global innodb_commit_concurrency=@my_innodb_commit_concurrency;
CREATE TABLE t1 (a int, b int, c int, PRIMARY KEY (a), KEY t1_b (b))
ENGINE=InnoDB;
INSERT INTO t1 (a,b,c) VALUES (1,1,1), (2,1,1), (3,1,1), (4,1,1);
INSERT INTO t1 (a,b,c) SELECT a+4,b,c FROM t1;
EXPLAIN SELECT a, b, c FROM t1 WHERE b = 1 ORDER BY a DESC LIMIT 5;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	range	t1_b	t1_b	5	NULL	4	Using where
SELECT a, b, c FROM t1 WHERE b = 1 ORDER BY a DESC LIMIT 5;
a	b	c
8	1	1
7	1	1
6	1	1
5	1	1
4	1	1
DROP TABLE t1;
End of 5.0 tests
+1672 −0

File changed.

Preview size limit exceeded, changes collapsed.

+11 −0
Original line number Diff line number Diff line
@@ -4396,4 +4396,15 @@ id select_type table type possible_keys key key_len ref rows Extra
Warnings:
Note	1003	select 1 AS `1` from `test`.`t1` where <in_optimizer>(1,<exists>(select 1 AS `1` from `test`.`t1` where (`test`.`t1`.`a` > 3) group by `test`.`t1`.`a` having (<cache>(1) = <ref_null_helper>(1))))
DROP TABLE t1;
CREATE TABLE t1(pk int PRIMARY KEY, a int, INDEX idx(a));
INSERT INTO t1 VALUES (1, 10), (3, 30), (2, 20);
CREATE TABLE t2(pk int PRIMARY KEY, a int, b int, INDEX idxa(a));
INSERT INTO t2 VALUES (2, 20, 700), (1, 10, 200), (4, 10, 100);
SELECT * FROM t1
WHERE EXISTS (SELECT DISTINCT a FROM t2 WHERE t1.a < t2.a ORDER BY b);
pk	a
1	10
3	30
2	20
DROP TABLE t1,t2;
End of 5.0 tests.
Loading