summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSachin <sachin.setiya@mariadb.com>2018-12-31 20:23:15 +0530
committerSachin <sachin.setiya@mariadb.com>2019-01-09 14:13:50 +0530
commite57a5c0e9d7938bd03fa369ac5b9bfa802bbf732 (patch)
tree7533b3ccf5187af0c5673f5a014a2bbec7b12c5e
parentacaf169f08e63231868dfa7be2d620461b73a84e (diff)
downloadmariadb-git-e57a5c0e9d7938bd03fa369ac5b9bfa802bbf732.tar.gz
add_key_part modified
-rw-r--r--mysql-test/main/xyz.test10
-rw-r--r--mysql-test/main/xyz_blob.result62
-rw-r--r--mysql-test/main/xyz_blob.test12
-rw-r--r--sql/sql_select.cc11
4 files changed, 95 insertions, 0 deletions
diff --git a/mysql-test/main/xyz.test b/mysql-test/main/xyz.test
new file mode 100644
index 00000000000..ef98394568f
--- /dev/null
+++ b/mysql-test/main/xyz.test
@@ -0,0 +1,10 @@
+create table t1(a int primary key , b int , c int, unique(b,c));
+insert into t1 values(1,1,1),(2,2,2),(3,3,3),(4,4,4),(5,5,5);
+insert into t1 select a+5, b+5, c+5 from t1;
+insert into t1 select a+10, b+10, c+10 from t1;
+insert into t1 select a+20, b+20, c+20 from t1;
+insert into t1 select a+40, b+40, c+40 from t1;
+ --query_vertical explain select * from t1 where a=34;
+ --query_vertical explain select * from t1 where b=34;
+ --query_vertical explain select * from t1 where c=34;
+drop table t1;
diff --git a/mysql-test/main/xyz_blob.result b/mysql-test/main/xyz_blob.result
new file mode 100644
index 00000000000..e4403b0e169
--- /dev/null
+++ b/mysql-test/main/xyz_blob.result
@@ -0,0 +1,62 @@
+create table t1(a blob unique , b blob , c blob, unique(b,c));
+insert into t1 values(1,1,1),(2,2,2),(3,3,3),(4,4,4),(5,5,5);
+insert into t1 select a+5, b+5, c+5 from t1;
+insert into t1 select a+10, b+10, c+10 from t1;
+insert into t1 select a+20, b+20, c+20 from t1;
+insert into t1 select a+40, b+40, c+40 from t1;
+explain select * from t1 where a="34";;
+id 1
+select_type SIMPLE
+table NULL
+type NULL
+possible_keys NULL
+key NULL
+key_len NULL
+ref NULL
+rows NULL
+Extra Impossible WHERE noticed after reading const tables
+explain select * from t1 where b="34" and c = "34";;
+id 1
+select_type SIMPLE
+table t1
+type ALL
+possible_keys b
+key NULL
+key_len NULL
+ref NULL
+rows 80
+Extra Using where
+explain select * from t1 where c="34" and b="34";;
+id 1
+select_type SIMPLE
+table t1
+type ALL
+possible_keys b
+key NULL
+key_len NULL
+ref NULL
+rows 80
+Extra Using where
+explain select * from t1 where c="34";;
+id 1
+select_type SIMPLE
+table t1
+type ALL
+possible_keys NULL
+key NULL
+key_len NULL
+ref NULL
+rows 80
+Extra Using where
+explain select * from t1 where b="34";;
+id 1
+select_type SIMPLE
+table NULL
+type NULL
+possible_keys NULL
+key NULL
+key_len NULL
+ref NULL
+rows NULL
+Extra Impossible WHERE noticed after reading const tables
+drop table t1;
diff --git a/mysql-test/main/xyz_blob.test b/mysql-test/main/xyz_blob.test
new file mode 100644
index 00000000000..05c5f635ff3
--- /dev/null
+++ b/mysql-test/main/xyz_blob.test
@@ -0,0 +1,12 @@
+create table t1(a blob unique , b blob , c blob, unique(b,c));
+insert into t1 values(1,1,1),(2,2,2),(3,3,3),(4,4,4),(5,5,5);
+insert into t1 select a+5, b+5, c+5 from t1;
+insert into t1 select a+10, b+10, c+10 from t1;
+insert into t1 select a+20, b+20, c+20 from t1;
+insert into t1 select a+40, b+40, c+40 from t1;
+--query_vertical explain select * from t1 where a="34";
+--query_vertical explain select * from t1 where b="34" and c = "34";
+--query_vertical explain select * from t1 where c="34" and b="34";
+--query_vertical explain select * from t1 where c="34";
+--query_vertical explain select * from t1 where b="34";
+drop table t1;
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index c660af38118..0e06ea9a717 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -6058,15 +6058,26 @@ add_key_part(DYNAMIC_ARRAY *keyuse_array, KEY_FIELD *key_field)
KEY *keyinfo= form->key_info+key;
uint key_parts= form->actual_n_key_parts(keyinfo);
+ if (keyinfo->algorithm == HA_KEY_ALG_LONG_HASH)
+ {
+ re_setup_keyinfo_hash(keyinfo);
+ key_parts= keyinfo->user_defined_key_parts;
+ }
for (uint part=0 ; part < key_parts ; part++)
{
if (field->eq(form->key_info[key].key_part[part].field) &&
field->can_optimize_keypart_ref(key_field->cond, key_field->val))
{
if (add_keyuse(keyuse_array, key_field, key, part))
+ {
+ if (keyinfo->algorithm == HA_KEY_ALG_LONG_HASH)
+ setup_keyinfo_hash(keyinfo);
return TRUE;
+ }
}
}
+ if (keyinfo->algorithm == HA_KEY_ALG_LONG_HASH)
+ setup_keyinfo_hash(keyinfo);
}
if (field->hash_join_is_possible() &&
(key_field->optimize & KEY_OPTIMIZE_EQ) &&