summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/include/query_cache.inc38
-rw-r--r--mysql-test/r/cache_innodb.result7
-rw-r--r--mysql-test/r/partition_cache.result205
-rw-r--r--mysql-test/t/cache_innodb-master.opt1
-rw-r--r--mysql-test/t/partition_cache.test21
-rw-r--r--sql/ha_partition.cc28
-rw-r--r--sql/ha_partition.h20
7 files changed, 286 insertions, 34 deletions
diff --git a/mysql-test/include/query_cache.inc b/mysql-test/include/query_cache.inc
index 7ce97b42158..ecc5014880c 100644
--- a/mysql-test/include/query_cache.inc
+++ b/mysql-test/include/query_cache.inc
@@ -4,6 +4,9 @@
# $engine_type -- storage engine to be tested
# $test_foreign_keys -- 0, skip foreign key tests
# -- 1, do not skip foreign key tests
+# $partitions_a -- partition by column 'a'
+# $partitions_id -- partition by column 'id'
+# $partitions_s1 -- partition by column 's1'
# have to be set before sourcing this script.
#
# Last update:
@@ -19,47 +22,61 @@ eval SET SESSION STORAGE_ENGINE = $engine_type;
drop table if exists t1,t2,t3;
--enable_warnings
+set @save_query_cache_size = @@global.query_cache_size;
+set GLOBAL query_cache_size = 1355776;
+
#
# Without auto_commit.
#
flush status;
set autocommit=0;
-create table t1 (a int not null);
+eval create table t1 (a int not null)$partitions_a;
insert into t1 values (1),(2),(3);
+--sorted_result
select * from t1;
show status like "Qcache_queries_in_cache";
drop table t1;
commit;
set autocommit=1;
begin;
-create table t1 (a int not null);
+eval create table t1 (a int not null)$partitions_a;
insert into t1 values (1),(2),(3);
+--sorted_result
select * from t1;
show status like "Qcache_queries_in_cache";
drop table t1;
commit;
-create table t1 (a int not null);
-create table t2 (a int not null);
-create table t3 (a int not null);
+eval create table t1 (a int not null)$partitions_a;
+eval create table t2 (a int not null)$partitions_a;
+eval create table t3 (a int not null)$partitions_a;
insert into t1 values (1),(2);
insert into t2 values (1),(2);
insert into t3 values (1),(2);
+--sorted_result
select * from t1;
+--sorted_result
select * from t2;
+--sorted_result
select * from t3;
show status like "Qcache_queries_in_cache";
show status like "Qcache_hits";
begin;
+--sorted_result
select * from t1;
+--sorted_result
select * from t2;
+--sorted_result
select * from t3;
show status like "Qcache_queries_in_cache";
show status like "Qcache_hits";
insert into t1 values (3);
insert into t2 values (3);
insert into t1 values (4);
+--sorted_result
select * from t1;
+--sorted_result
select * from t2;
+--sorted_result
select * from t3;
show status like "Qcache_queries_in_cache";
show status like "Qcache_hits";
@@ -67,7 +84,7 @@ commit;
show status like "Qcache_queries_in_cache";
drop table t3,t2,t1;
-CREATE TABLE t1 (id int(11) NOT NULL auto_increment, PRIMARY KEY (id));
+eval CREATE TABLE t1 (id int(11) NOT NULL auto_increment, PRIMARY KEY (id))$partitions_id;
select count(*) from t1;
insert into t1 (id) values (0);
select count(*) from t1;
@@ -78,8 +95,6 @@ if ($test_foreign_keys)
#
# one statement roll back inside transation
#
-let $save_query_cache_size=`select @@global.query_cache_size`;
-set GLOBAL query_cache_size=1355776;
CREATE TABLE t1 ( id int(10) NOT NULL auto_increment, a varchar(25) default NULL, PRIMARY KEY (id), UNIQUE KEY a (a));
CREATE TABLE t2 ( id int(10) NOT NULL auto_increment, b varchar(25) default NULL, PRIMARY KEY (id), UNIQUE KEY b (b));
CREATE TABLE t3 ( id int(10) NOT NULL auto_increment, t1_id int(10) NOT NULL default '0', t2_id int(10) NOT NULL default '0', state int(11) default NULL, PRIMARY KEY (id), UNIQUE KEY t1_id (t1_id,t2_id), KEY t2_id (t2_id,t1_id), CONSTRAINT `t3_ibfk_1` FOREIGN KEY (`t1_id`) REFERENCES `t1` (`id`), CONSTRAINT `t3_ibfk_2` FOREIGN KEY (`t2_id`) REFERENCES `t2` (`id`));
@@ -95,9 +110,6 @@ insert into t3 VALUES ( NULL, 1, 1, 2 );
commit;
select t1.* from t1, t2, t3 where t3.state & 1 = 0 and t3.t1_id = t1.id and t3.t2_id = t2.id and t1.id = 1 order by t1.a asc;
drop table t3,t2,t1;
---disable_query_log
-eval set GLOBAL query_cache_size=$save_query_cache_size;
---enable_query_log
}
#
@@ -118,7 +130,7 @@ SET GLOBAL query_cache_size = 200000;
flush status;
SET @@autocommit=1;
eval SET SESSION STORAGE_ENGINE = $engine_type;
-CREATE TABLE t2 (s1 int, s2 varchar(1000), key(s1));
+eval CREATE TABLE t2 (s1 int, s2 varchar(1000), key(s1))$partitions_s1;
INSERT INTO t2 VALUES (1,repeat('a',10)),(2,repeat('a',10)),(3,repeat('a',10)),(4,repeat('a',10));
COMMIT;
START TRANSACTION;
@@ -176,8 +188,8 @@ show status like "Qcache_queries_in_cache";
show status like "Qcache_hits";
# Final cleanup
-eval set GLOBAL query_cache_size=$save_query_cache_size;
disconnect connection1;
--source include/wait_until_disconnected.inc
connection default;
+set @@global.query_cache_size = @save_query_cache_size;
drop table t2;
diff --git a/mysql-test/r/cache_innodb.result b/mysql-test/r/cache_innodb.result
index b59298727c5..03989c80b9d 100644
--- a/mysql-test/r/cache_innodb.result
+++ b/mysql-test/r/cache_innodb.result
@@ -1,5 +1,7 @@
SET SESSION STORAGE_ENGINE = InnoDB;
drop table if exists t1,t2,t3;
+set @save_query_cache_size = @@global.query_cache_size;
+set GLOBAL query_cache_size = 1355776;
flush status;
set autocommit=0;
create table t1 (a int not null);
@@ -100,7 +102,7 @@ show status like "Qcache_queries_in_cache";
Variable_name Value
Qcache_queries_in_cache 2
drop table t3,t2,t1;
-CREATE TABLE t1 (id int(11) NOT NULL auto_increment, PRIMARY KEY (id));
+CREATE TABLE t1 (id int(11) NOT NULL auto_increment, PRIMARY KEY (id));
select count(*) from t1;
count(*)
0
@@ -109,7 +111,6 @@ select count(*) from t1;
count(*)
1
drop table t1;
-set GLOBAL query_cache_size=1355776;
CREATE TABLE t1 ( id int(10) NOT NULL auto_increment, a varchar(25) default NULL, PRIMARY KEY (id), UNIQUE KEY a (a));
CREATE TABLE t2 ( id int(10) NOT NULL auto_increment, b varchar(25) default NULL, PRIMARY KEY (id), UNIQUE KEY b (b));
CREATE TABLE t3 ( id int(10) NOT NULL auto_increment, t1_id int(10) NOT NULL default '0', t2_id int(10) NOT NULL default '0', state int(11) default NULL, PRIMARY KEY (id), UNIQUE KEY t1_id (t1_id,t2_id), KEY t2_id (t2_id,t1_id), CONSTRAINT `t3_ibfk_1` FOREIGN KEY (`t1_id`) REFERENCES `t1` (`id`), CONSTRAINT `t3_ibfk_2` FOREIGN KEY (`t2_id`) REFERENCES `t2` (`id`));
@@ -218,5 +219,5 @@ Qcache_queries_in_cache 1
show status like "Qcache_hits";
Variable_name Value
Qcache_hits 1
-set GLOBAL query_cache_size=1048576;
+set @@global.query_cache_size = @save_query_cache_size;
drop table t2;
diff --git a/mysql-test/r/partition_cache.result b/mysql-test/r/partition_cache.result
new file mode 100644
index 00000000000..e4e7cc8a4ac
--- /dev/null
+++ b/mysql-test/r/partition_cache.result
@@ -0,0 +1,205 @@
+SET SESSION STORAGE_ENGINE = InnoDB;
+drop table if exists t1,t2,t3;
+set @save_query_cache_size = @@global.query_cache_size;
+set GLOBAL query_cache_size = 1355776;
+flush status;
+set autocommit=0;
+create table t1 (a int not null) PARTITION BY KEY (a) PARTITIONS 3;
+insert into t1 values (1),(2),(3);
+select * from t1;
+a
+1
+2
+3
+show status like "Qcache_queries_in_cache";
+Variable_name Value
+Qcache_queries_in_cache 0
+drop table t1;
+commit;
+set autocommit=1;
+begin;
+create table t1 (a int not null) PARTITION BY KEY (a) PARTITIONS 3;
+insert into t1 values (1),(2),(3);
+select * from t1;
+a
+1
+2
+3
+show status like "Qcache_queries_in_cache";
+Variable_name Value
+Qcache_queries_in_cache 0
+drop table t1;
+commit;
+create table t1 (a int not null) PARTITION BY KEY (a) PARTITIONS 3;
+create table t2 (a int not null) PARTITION BY KEY (a) PARTITIONS 3;
+create table t3 (a int not null) PARTITION BY KEY (a) PARTITIONS 3;
+insert into t1 values (1),(2);
+insert into t2 values (1),(2);
+insert into t3 values (1),(2);
+select * from t1;
+a
+1
+2
+select * from t2;
+a
+1
+2
+select * from t3;
+a
+1
+2
+show status like "Qcache_queries_in_cache";
+Variable_name Value
+Qcache_queries_in_cache 0
+show status like "Qcache_hits";
+Variable_name Value
+Qcache_hits 0
+begin;
+select * from t1;
+a
+1
+2
+select * from t2;
+a
+1
+2
+select * from t3;
+a
+1
+2
+show status like "Qcache_queries_in_cache";
+Variable_name Value
+Qcache_queries_in_cache 0
+show status like "Qcache_hits";
+Variable_name Value
+Qcache_hits 0
+insert into t1 values (3);
+insert into t2 values (3);
+insert into t1 values (4);
+select * from t1;
+a
+1
+2
+3
+4
+select * from t2;
+a
+1
+2
+3
+select * from t3;
+a
+1
+2
+show status like "Qcache_queries_in_cache";
+Variable_name Value
+Qcache_queries_in_cache 0
+show status like "Qcache_hits";
+Variable_name Value
+Qcache_hits 0
+commit;
+show status like "Qcache_queries_in_cache";
+Variable_name Value
+Qcache_queries_in_cache 0
+drop table t3,t2,t1;
+CREATE TABLE t1 (id int(11) NOT NULL auto_increment, PRIMARY KEY (id)) PARTITION BY HASH (id) PARTITIONS 3;
+select count(*) from t1;
+count(*)
+0
+insert into t1 (id) values (0);
+select count(*) from t1;
+count(*)
+1
+drop table t1;
+SET SESSION STORAGE_ENGINE = InnoDB;
+SET @@autocommit=1;
+connection default
+SHOW VARIABLES LIKE 'have_query_cache';
+Variable_name Value
+have_query_cache YES
+SET GLOBAL query_cache_size = 200000;
+flush status;
+SET @@autocommit=1;
+SET SESSION STORAGE_ENGINE = InnoDB;
+CREATE TABLE t2 (s1 int, s2 varchar(1000), key(s1)) PARTITION BY KEY (s1) PARTITIONS 3;
+INSERT INTO t2 VALUES (1,repeat('a',10)),(2,repeat('a',10)),(3,repeat('a',10)),(4,repeat('a',10));
+COMMIT;
+START TRANSACTION;
+SELECT sql_cache count(*) FROM t2 WHERE s2 = 'w';
+count(*)
+0
+UPDATE t2 SET s2 = 'w' WHERE s1 = 3;
+SELECT sql_cache count(*) FROM t2 WHERE s2 = 'w';
+count(*)
+1
+show status like "Qcache_queries_in_cache";
+Variable_name Value
+Qcache_queries_in_cache 0
+connection connection1
+START TRANSACTION;
+SELECT sql_cache count(*) FROM t2 WHERE s2 = 'w';
+count(*)
+0
+INSERT INTO t2 VALUES (5,'w');
+SELECT sql_cache count(*) FROM t2 WHERE s2 = 'w';
+count(*)
+1
+COMMIT;
+SELECT sql_cache count(*) FROM t2 WHERE s2 = 'w';
+count(*)
+1
+show status like "Qcache_queries_in_cache";
+Variable_name Value
+Qcache_queries_in_cache 0
+connection default
+SELECT sql_cache count(*) FROM t2 WHERE s2 = 'w';
+count(*)
+1
+COMMIT;
+show status like "Qcache_queries_in_cache";
+Variable_name Value
+Qcache_queries_in_cache 0
+SELECT sql_cache count(*) FROM t2 WHERE s2 = 'w';
+count(*)
+2
+show status like "Qcache_queries_in_cache";
+Variable_name Value
+Qcache_queries_in_cache 0
+connection connection1
+SELECT sql_cache count(*) FROM t2 WHERE s2 = 'w';
+count(*)
+2
+START TRANSACTION;
+SELECT sql_cache count(*) FROM t2 WHERE s2 = 'w';
+count(*)
+2
+INSERT INTO t2 VALUES (6,'w');
+SELECT sql_cache count(*) FROM t2 WHERE s2 = 'w';
+count(*)
+3
+connection default
+SELECT sql_cache count(*) FROM t2 WHERE s2 = 'w';
+count(*)
+2
+START TRANSACTION;
+SELECT sql_cache count(*) FROM t2 WHERE s2 = 'w';
+count(*)
+2
+DELETE from t2 WHERE s1=3;
+SELECT sql_cache count(*) FROM t2 WHERE s2 = 'w';
+count(*)
+1
+COMMIT;
+connection connection1
+COMMIT;
+SELECT sql_cache count(*) FROM t2 WHERE s2 = 'w';
+count(*)
+2
+show status like "Qcache_queries_in_cache";
+Variable_name Value
+Qcache_queries_in_cache 0
+show status like "Qcache_hits";
+Variable_name Value
+Qcache_hits 0
+set @@global.query_cache_size = @save_query_cache_size;
+drop table t2;
diff --git a/mysql-test/t/cache_innodb-master.opt b/mysql-test/t/cache_innodb-master.opt
deleted file mode 100644
index 5f0ebff98f6..00000000000
--- a/mysql-test/t/cache_innodb-master.opt
+++ /dev/null
@@ -1 +0,0 @@
---set-variable=query_cache_size=1M
diff --git a/mysql-test/t/partition_cache.test b/mysql-test/t/partition_cache.test
new file mode 100644
index 00000000000..b5d19796b7c
--- /dev/null
+++ b/mysql-test/t/partition_cache.test
@@ -0,0 +1,21 @@
+# t/cache_innodb.test
+#
+# Last update:
+# 2006-07-26 ML test refactored (MySQL 5.1)
+# main code t/innodb_cache.test --> include/query_cache.inc
+# new wrapper t/cache_innodb.test
+#
+
+--source include/have_query_cache.inc
+
+--source include/have_innodb.inc
+--source include/have_partition.inc
+let $engine_type= InnoDB;
+# Using SELECT to get a space as first character.
+let $partitions_a= `SELECT ' PARTITION BY KEY (a) PARTITIONS 3'`;
+let $partitions_id= `SELECT ' PARTITION BY HASH (id) PARTITIONS 3'`;
+let $partitions_s1= `SELECT ' PARTITION BY KEY (s1) PARTITIONS 3'`;
+# partitioning does not support FOREIGN KEYs
+let $test_foreign_keys= 0;
+
+--source include/query_cache.inc
diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc
index 7c7cf5a4302..7e044b5260e 100644
--- a/sql/ha_partition.cc
+++ b/sql/ha_partition.cc
@@ -6494,20 +6494,20 @@ int ha_partition::add_index(TABLE *table_arg, KEY *key_info, uint num_of_keys)
return ret;
err:
if (file > m_file)
- {
- uint *key_numbers= (uint*) ha_thd()->alloc(sizeof(uint) * num_of_keys);
- KEY *old_key_info= table_arg->key_info;
- uint i;
- /* Use the newly added key_info as table->key_info to remove them. */
- for (i= 0; i < num_of_keys; i++)
- key_numbers[i]= i;
- table_arg->key_info= key_info;
- while (--file >= m_file)
- {
- (void) (*file)->prepare_drop_index(table_arg, key_numbers, num_of_keys);
- (void) (*file)->final_drop_index(table_arg);
- }
- table_arg->key_info= old_key_info;
+ {
+ uint *key_numbers= (uint*) ha_thd()->alloc(sizeof(uint) * num_of_keys);
+ KEY *old_key_info= table_arg->key_info;
+ uint i;
+ /* Use the newly added key_info as table->key_info to remove them. */
+ for (i= 0; i < num_of_keys; i++)
+ key_numbers[i]= i;
+ table_arg->key_info= key_info;
+ while (--file >= m_file)
+ {
+ (void) (*file)->prepare_drop_index(table_arg, key_numbers, num_of_keys);
+ (void) (*file)->final_drop_index(table_arg);
+ }
+ table_arg->key_info= old_key_info;
}
return ret;
}
diff --git a/sql/ha_partition.h b/sql/ha_partition.h
index 46e2f447a47..813c0ae8960 100644
--- a/sql/ha_partition.h
+++ b/sql/ha_partition.h
@@ -219,9 +219,9 @@ public:
*/
ha_partition(handlerton *hton, TABLE_SHARE * table);
ha_partition(handlerton *hton, partition_info * part_info);
- ha_partition(handlerton *hton, TABLE_SHARE *share,
- partition_info *part_info_arg,
- ha_partition *clone_arg,
+ ha_partition(handlerton *hton, TABLE_SHARE *share,
+ partition_info *part_info_arg,
+ ha_partition *clone_arg,
MEM_ROOT *clone_mem_root_arg);
~ha_partition();
/*
@@ -553,6 +553,20 @@ public:
virtual int extra(enum ha_extra_function operation);
virtual int extra_opt(enum ha_extra_function operation, ulong cachesize);
virtual int reset(void);
+ /*
+ Do not allow caching of partitioned tables, since we cannot return
+ a callback or engine_data that would work for a generic engine.
+ */
+ virtual my_bool register_query_cache_table(THD *thd, char *table_key,
+ uint key_length,
+ qc_engine_callback
+ *engine_callback,
+ ulonglong *engine_data)
+ {
+ *engine_callback= NULL;
+ *engine_data= 0;
+ return FALSE;
+ }
private:
static const uint NO_CURRENT_PART_ID;