Commit c3d473ab authored by unknown's avatar unknown
Browse files

Merge bk-internal.mysql.com:/home/bk/mysql-5.0

into  neptunus.(none):/home/msvensson/mysql/bug13231/my50-bug13231


client/mysqltest.c:
  Auto merged
mysql-test/r/mysqltest.result:
  Auto merged
mysql-test/t/query_cache.test:
  Auto merged
sql/mysql_priv.h:
  Auto merged
sql/sql_cache.cc:
  Auto merged
sql/sql_db.cc:
  Auto merged
parents 39ba8376 b4f41433
Loading
Loading
Loading
Loading
+52 −88
Original line number Diff line number Diff line
@@ -3062,12 +3062,6 @@ static int run_query_normal(MYSQL* mysql, struct st_query* q, int flags)
      goto end;
    }

    if (handle_no_error(q))
    {
      error= 1;
      goto end;
    }

    if (!disable_result_log)
    {
      ulong affected_rows;    /* Ok to be undef if 'disable_info' is set */
@@ -3112,12 +3106,9 @@ static int run_query_normal(MYSQL* mysql, struct st_query* q, int flags)
	MYSQL_RES *warn_res=0;
	uint count= mysql_warning_count(mysql);
	if (!mysql_real_query(mysql, "SHOW WARNINGS", 13))
	{
	  warn_res= mysql_store_result(mysql);
	}
	if (!warn_res)
	  verbose_msg("Warning count is %u but didn't get any warnings",
		      count);
	  die("Warning count is %u but didn't get any warnings", count);
	else
	{
	  dynstr_append_mem(ds, "Warnings:\n", 10);
@@ -3155,8 +3146,21 @@ static int run_query_normal(MYSQL* mysql, struct st_query* q, int flags)
    last_result= 0;
    counter++;
  } while (!(err= mysql_next_result(mysql)));
  if (err >= 1)
    mysql_error(mysql);
  if (err > 0)
  {
      /* We got an error from mysql_next_result, maybe expected */
    if (handle_error(query, q, mysql_errno(mysql), mysql_error(mysql),
                     mysql_sqlstate(mysql), ds))
      error= 1;
    goto end;
  }

  // If we come here the query is both executed and read successfully
  if (handle_no_error(q))
  {
    error= 1;
    goto end;
  }

end:
  free_replace();
@@ -3209,8 +3213,7 @@ static int handle_error(const char *query, struct st_query *q,
    abort_not_supported_test();
 
  if (q->abort_on_error)
    die("query '%s' failed: %d: %s", query,
        err_errno, err_error);
    die("query '%s' failed: %d: %s", query, err_errno, err_error);

  for (i= 0 ; (uint) i < q->expected_errors ; i++)
  {
@@ -3249,13 +3252,11 @@ static int handle_error(const char *query, struct st_query *q,
  if (i)
  {
    if (q->expected_errno[0].type == ERR_ERRNO)
      verbose_msg("query '%s' failed with wrong errno %d instead of %d...",
                  q->query, err_errno,
                  q->expected_errno[0].code.errnum);
      die("query '%s' failed with wrong errno %d instead of %d...",
          q->query, err_errno, q->expected_errno[0].code.errnum);
    else
      verbose_msg("query '%s' failed with wrong sqlstate %s instead of %s...",
                  q->query, err_sqlstate,
                  q->expected_errno[0].code.sqlstate);
      die("query '%s' failed with wrong sqlstate %s instead of %s...",
          q->query, err_sqlstate, q->expected_errno[0].code.sqlstate);
    DBUG_RETURN(1);
  }

@@ -3289,7 +3290,7 @@ static int handle_no_error(struct st_query *q)
      q->expected_errno[0].code.errnum != 0)
  {
    /* Error code we wanted was != 0, i.e. not an expected success */
    verbose_msg("query '%s' succeeded - should have failed with errno %d...",
    die("query '%s' succeeded - should have failed with errno %d...",
        q->query, q->expected_errno[0].code.errnum);
    DBUG_RETURN(1);
  }
@@ -3297,7 +3298,7 @@ static int handle_no_error(struct st_query *q)
           strcmp(q->expected_errno[0].code.sqlstate,"00000") != 0)
  {
    /* SQLSTATE we wanted was != "00000", i.e. not an expected success */
    verbose_msg("query '%s' succeeded - should have failed with sqlstate %s...",
    die("query '%s' succeeded - should have failed with sqlstate %s...",
        q->query, q->expected_errno[0].code.sqlstate);
    DBUG_RETURN(1);
  }
@@ -3318,7 +3319,7 @@ static int run_query_stmt(MYSQL *mysql, struct st_query *q, int flags)
{
  int error= 0;             /* Function return code if "goto end;" */
  int err;                  /* Temporary storage of return code from calls */
  int query_len, got_error_on_execute;
  int query_len;
  ulonglong num_rows;
  char *query;
  MYSQL_RES *res= NULL;     /* Note that here 'res' is meta data result set */
@@ -3374,26 +3375,17 @@ static int run_query_stmt(MYSQL *mysql, struct st_query *q, int flags)
    return run_query_normal(mysql, q, flags);

  if (err != 0)
  {
    if (q->abort_on_error)
    {
      die("query '%s' failed: %d: %s", query,
          mysql_stmt_errno(stmt), mysql_stmt_error(stmt));
    }
    else
  {
    /*
      Preparing is part of normal execution and some errors may be expected
    */
      error= handle_error(query, q, mysql_stmt_errno(stmt),
                          mysql_stmt_error(stmt), mysql_stmt_sqlstate(stmt),
                          ds);
    if (handle_error(query, q,  mysql_stmt_errno(stmt),
                     mysql_stmt_error(stmt), mysql_stmt_sqlstate(stmt), ds))
      error= 1;
    goto end;
  }
  }

  /* We may have got warnings already, collect them if any */
  /* FIXME we only want this if the statement succeeds I think */ 
  if (!disable_ps_warnings)
    run_query_stmt_handle_warnings(mysql, ds);

@@ -3407,25 +3399,14 @@ static int run_query_stmt(MYSQL *mysql, struct st_query *q, int flags)
    prepared statement.
  */

  if ((got_error_on_execute= mysql_stmt_execute(stmt)) != 0) /* 0 == Success */
  {
    if (q->abort_on_error)
    {
      /* We got an error, unexpected */
      die("unable to execute statement '%s': "
          "%s (mysql_stmt_errno=%d returned=%d)",
          query, mysql_stmt_error(stmt),
          mysql_stmt_errno(stmt), got_error_on_execute);
    }
    else
  if (mysql_stmt_execute(stmt) != 0) /* 0 == Success */
  {
    /* We got an error, maybe expected */
      error= handle_error(query, q, mysql_stmt_errno(stmt),
                          mysql_stmt_error(stmt), mysql_stmt_sqlstate(stmt),
                          ds);
    if (handle_error(query, q, mysql_stmt_errno(stmt),
                     mysql_stmt_error(stmt), mysql_stmt_sqlstate(stmt), ds))
      error= 1;
    goto end;
  }
  }

  /*
    We instruct that we want to update the "max_length" field in
@@ -3434,11 +3415,10 @@ static int run_query_stmt(MYSQL *mysql, struct st_query *q, int flags)
  */
  {
    my_bool one= 1;
    if (mysql_stmt_attr_set(stmt, STMT_ATTR_UPDATE_MAX_LENGTH,
                            (void*) &one) != 0)
    if ((err= mysql_stmt_attr_set(stmt, STMT_ATTR_UPDATE_MAX_LENGTH,
                                  (void*) &one)) != 0)
      die("unable to set stmt attribute "
          "'STMT_ATTR_UPDATE_MAX_LENGTH': %s (returned=%d)",
          query, err);
          "'STMT_ATTR_UPDATE_MAX_LENGTH' err: %d", err);
  }

  /*
@@ -3446,24 +3426,13 @@ static int run_query_stmt(MYSQL *mysql, struct st_query *q, int flags)
    get data. Note that this can still give errors found during execution!
  */
  if ((err= mysql_stmt_store_result(stmt)) != 0)
  {
    if (q->abort_on_error)
    {
      /* We got an error, unexpected */
      die("unable to execute statement '%s': "
          "%s (mysql_stmt_errno=%d returned=%d)",
          query, mysql_stmt_error(stmt),
          mysql_stmt_errno(stmt), got_error_on_execute);
    }
    else
  {
    /* We got an error, maybe expected */
      error= handle_error(query, q, mysql_stmt_errno(stmt),
                          mysql_stmt_error(stmt), mysql_stmt_sqlstate(stmt),
                          ds);
    if(handle_error(query, q, mysql_stmt_errno(stmt),
                    mysql_stmt_error(stmt), mysql_stmt_sqlstate(stmt), ds))
      error = 1;
    goto end;
  }
  }

  /* If we got here the statement was both executed and read succeesfully */
  if (handle_no_error(q))
@@ -3486,8 +3455,6 @@ static int run_query_stmt(MYSQL *mysql, struct st_query *q, int flags)
    MYSQL_FIELD *field= mysql_fetch_fields(res);
    uint num_fields= mysql_num_fields(res);

    /* FIXME check error from the above? */

    if (display_metadata)
      run_query_display_metadata(field, num_fields, ds);

@@ -3640,9 +3607,6 @@ static int run_query_stmt(MYSQL *mysql, struct st_query *q, int flags)
    mysql_free_result(res);     /* Free normal result set with meta data */
  last_result= 0;               /* FIXME have no idea what this is about... */

  if (err >= 1)
    mysql_error(mysql);         /* FIXME strange, has no effect... */

end:
  free_replace();
  last_result=0;
@@ -3733,7 +3697,7 @@ static void run_query_stmt_handle_warnings(MYSQL *mysql, DYNAMIC_STRING *ds)
    {
      MYSQL_RES *warn_res= mysql_store_result(mysql);
      if (!warn_res)
        verbose_msg("Warning count is %u but didn't get any warnings",
        die("Warning count is %u but didn't get any warnings",
            count);
      else
      {
+0 −2
Original line number Diff line number Diff line
@@ -134,7 +134,6 @@ select 1146 as "after_!errno_masked_error" ;
after_!errno_masked_error
1146
mysqltest: At line 1: query 'select 3 from t1' failed with wrong errno 1146 instead of 1000...
mysqltest: At line 1: query 'select 3 from t1' failed with wrong errno 1146 instead of 1000...
garbage ;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'garbage' at line 1
select 1064 as "after_--enable_abort_on_error" ;
@@ -143,7 +142,6 @@ after_--enable_abort_on_error
select 3 from t1 ;
ERROR 42S02: Table 'test.t1' doesn't exist
mysqltest: At line 1: query 'select 3 from t1' failed with wrong errno 1146 instead of 1064...
mysqltest: At line 1: query 'select 3 from t1' failed: 1146: Table 'test.t1' doesn't exist
hello
hello
;;;;;;;;
+157 −13
Original line number Diff line number Diff line
@@ -1057,42 +1057,64 @@ create table t1 (s1 int)//
create procedure f1 () begin
select sql_cache * from t1;
select sql_cache * from t1;
select sql_cache * from t1;
end;//
create procedure f2 () begin
select sql_cache * from t1 where s1=1;
select sql_cache * from t1;
end;//
create procedure f3 () begin
select sql_cache * from t1;
select sql_cache * from t1 where s1=1;
end;//
create procedure f4 () begin
select sql_cache * from t1;
select sql_cache * from t1 where s1=1;
select sql_cache * from t1;
select sql_cache * from t1 where s1=1;
select sql_cache * from t1 where s1=1;
end;//
call f1();
s1
s1
s1
show status like "Qcache_queries_in_cache";
Variable_name	Value
Qcache_queries_in_cache	1
Qcache_queries_in_cache	3
show status like "Qcache_inserts";
Variable_name	Value
Qcache_inserts	1
Qcache_inserts	3
show status like "Qcache_hits";
Variable_name	Value
Qcache_hits	1
Qcache_hits	0
call f1();
s1
s1
s1
show status like "Qcache_queries_in_cache";
Variable_name	Value
Qcache_queries_in_cache	1
Qcache_queries_in_cache	3
show status like "Qcache_inserts";
Variable_name	Value
Qcache_inserts	1
Qcache_inserts	3
show status like "Qcache_hits";
Variable_name	Value
Qcache_hits	3
call f1();
s1
s1
s1
select sql_cache * from t1;
s1
show status like "Qcache_queries_in_cache";
Variable_name	Value
Qcache_queries_in_cache	2
Qcache_queries_in_cache	4
show status like "Qcache_inserts";
Variable_name	Value
Qcache_inserts	2
Qcache_inserts	4
show status like "Qcache_hits";
Variable_name	Value
Qcache_hits	5
Qcache_hits	6
insert into t1 values (1);
select sql_cache * from t1;
s1
@@ -1102,28 +1124,150 @@ Variable_name Value
Qcache_queries_in_cache	1
show status like "Qcache_inserts";
Variable_name	Value
Qcache_inserts	3
Qcache_inserts	5
show status like "Qcache_hits";
Variable_name	Value
Qcache_hits	5
Qcache_hits	6
call f1();
s1
1
s1
1
s1
1
call f1();
s1
1
s1
1
s1
1
select sql_cache * from t1;
s1
1
show status like "Qcache_queries_in_cache";
Variable_name	Value
Qcache_queries_in_cache	2
Qcache_queries_in_cache	4
show status like "Qcache_inserts";
Variable_name	Value
Qcache_inserts	4
Qcache_inserts	8
show status like "Qcache_hits";
Variable_name	Value
Qcache_hits	9
Qcache_hits	10
flush query cache;
reset query cache;
flush status;
select sql_cache * from t1;
s1
1
select sql_cache * from t1 where s1=1;
s1
1
call f1();
s1
1
s1
1
s1
1
call f2();
s1
1
s1
1
call f3();
s1
1
s1
1
call f4();
s1
1
s1
1
s1
1
s1
1
s1
1
call f4();
s1
1
s1
1
s1
1
s1
1
s1
1
call f3();
s1
1
s1
1
call f2();
s1
1
s1
1
select sql_cache * from t1 where s1=1;
s1
1
insert into t1 values (2);
call f1();
s1
1
2
s1
1
2
s1
1
2
select sql_cache * from t1 where s1=1;
s1
1
select sql_cache * from t1;
s1
1
2
call f1();
s1
1
2
s1
1
2
s1
1
2
call f3();
s1
1
2
s1
1
call f3();
s1
1
2
s1
1
call f1();
s1
1
2
s1
1
2
s1
1
2
drop procedure f1;
drop procedure f2;
drop procedure f3;
drop procedure f4;
drop table t1;
set GLOBAL query_cache_size=0;
+1 −0
Original line number Diff line number Diff line
@@ -692,6 +692,7 @@ END P1|
call SP001();
TEMP_SUM
0
ERROR 24000: Cursor is not open
drop procedure SP001;
drop table t1, t2;
drop function if exists bug11394|
+42 −0
Original line number Diff line number Diff line
@@ -776,6 +776,7 @@ delimiter ;//

#
# query in QC from normal execution and SP (BUG#6897)
# improved to also test BUG#3583 and BUG#12990
#
flush query cache;
reset query cache;
@@ -785,6 +786,22 @@ create table t1 (s1 int)//
create procedure f1 () begin
select sql_cache * from t1;
select sql_cache * from t1;
select sql_cache * from t1;
end;//
create procedure f2 () begin
select sql_cache * from t1 where s1=1;
select sql_cache * from t1;
end;//
create procedure f3 () begin
select sql_cache * from t1;
select sql_cache * from t1 where s1=1;
end;//
create procedure f4 () begin
select sql_cache * from t1;
select sql_cache * from t1 where s1=1;
select sql_cache * from t1;
select sql_cache * from t1 where s1=1;
select sql_cache * from t1 where s1=1;
end;//
delimiter ;//
call f1();
@@ -811,7 +828,32 @@ select sql_cache * from t1;
show status like "Qcache_queries_in_cache";
show status like "Qcache_inserts";
show status like "Qcache_hits";
flush query cache;
reset query cache;
flush status;
select sql_cache * from t1;
select sql_cache * from t1 where s1=1;
call f1();
call f2();
call f3();
call f4();
call f4();
call f3();
call f2();
select sql_cache * from t1 where s1=1;
insert into t1 values (2);
call f1();
select sql_cache * from t1 where s1=1;
select sql_cache * from t1;
call f1();
call f3();
call f3();
call f1();

drop procedure f1;
drop procedure f2;
drop procedure f3;
drop procedure f4;
drop table t1;
set GLOBAL query_cache_size=0;

Loading