Commit d5390b2d authored by istruewing@stella.local's avatar istruewing@stella.local
Browse files

Bug#33756 - query cache with concurrent_insert=0 appears broken

When concurrent inserts were disabled, statements after an INSERT
were not put into the query cache. This happened because we do not
save the current data file length at statement start when
concurrent inserts are disabled. But we checked the always zero
local length against the real file length anyway.
  
Fixed by doing the check only if concurrent inserts are not diabled.
parent 4a5e91cc
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
@@ -1654,3 +1654,30 @@ set GLOBAL query_cache_type=default;
set GLOBAL query_cache_limit=default;
set GLOBAL query_cache_min_res_unit=default;
set GLOBAL query_cache_size=default;
use test;
FLUSH STATUS;
SET GLOBAL query_cache_size=10*1024*1024;
SET @save_concurrent_insert= @@concurrent_insert;
SET GLOBAL concurrent_insert= 0;
CREATE TABLE t1 (c1 INT NOT NULL) ENGINE=MyISAM;
INSERT INTO t1 (c1) VALUES (1), (2);
SHOW GLOBAL VARIABLES LIKE 'concurrent_insert';
Variable_name	Value
concurrent_insert	0
SHOW STATUS LIKE 'Qcache_hits';
Variable_name	Value
Qcache_hits	0
SELECT * FROM t1;
c1
1
2
SELECT * FROM t1;
c1
1
2
SHOW STATUS LIKE 'Qcache_hits';
Variable_name	Value
Qcache_hits	1
DROP TABLE t1;
SET GLOBAL concurrent_insert= @save_concurrent_insert;
SET GLOBAL query_cache_size= default;
+20 −0
Original line number Diff line number Diff line
@@ -1255,5 +1255,25 @@ set GLOBAL query_cache_type=default;
set GLOBAL query_cache_limit=default;
set GLOBAL query_cache_min_res_unit=default;
set GLOBAL query_cache_size=default;
use test;

#
# Bug#33756 - query cache with concurrent_insert=0 appears broken
#
FLUSH STATUS;
SET GLOBAL query_cache_size=10*1024*1024;
SET @save_concurrent_insert= @@concurrent_insert;
SET GLOBAL concurrent_insert= 0;
CREATE TABLE t1 (c1 INT NOT NULL) ENGINE=MyISAM;
INSERT INTO t1 (c1) VALUES (1), (2);
#
SHOW GLOBAL VARIABLES LIKE 'concurrent_insert';
SHOW STATUS LIKE 'Qcache_hits';
SELECT * FROM t1;
SELECT * FROM t1;
SHOW STATUS LIKE 'Qcache_hits';
DROP TABLE t1;
SET GLOBAL concurrent_insert= @save_concurrent_insert;
SET GLOBAL query_cache_size= default;

# End of 5.0 tests
+37 −27
Original line number Diff line number Diff line
@@ -1954,6 +1954,7 @@ my_bool ha_myisam::register_query_cache_table(THD *thd, char *table_name,
                                              *engine_callback,
                                              ulonglong *engine_data)
{
  DBUG_ENTER("ha_myisam::register_query_cache_table");
  /*
    No call back function is needed to determine if a cached statement
    is valid or not.
@@ -1965,14 +1966,22 @@ my_bool ha_myisam::register_query_cache_table(THD *thd, char *table_name,
  */
  *engine_data= 0;

  if (file->s->concurrent_insert)
  {
    /*
    If a concurrent INSERT has happened just before the currently processed
    SELECT statement, the total size of the table is unknown.
      If a concurrent INSERT has happened just before the currently
      processed SELECT statement, the total size of the table is
      unknown.

    To determine if the table size is known, the current thread's snap shot of
    the table size with the actual table size are compared.
      To determine if the table size is known, the current thread's snap
      shot of the table size with the actual table size are compared.

      If the table size is unknown the SELECT statement can't be cached.

      When concurrent inserts are disabled at table open, mi_open()
      does not assign a get_status() function. In this case the local
      ("current") status is never updated. We would wrongly think that
      we cannot cache the statement.
    */
    ulonglong actual_data_file_length;
    ulonglong current_data_file_length;
@@ -1994,10 +2003,11 @@ my_bool ha_myisam::register_query_cache_table(THD *thd, char *table_name,
    if (current_data_file_length != actual_data_file_length)
    {
      /* Don't cache current statement. */
    return FALSE;
      DBUG_RETURN(FALSE);
    }
  }

  /* It is ok to try to cache current statement. */
  return TRUE;
  DBUG_RETURN(TRUE);
}
#endif