summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSachin <sachin.setiya@mariadb.com>2019-01-09 11:53:13 +0530
committerSachin <sachin.setiya@mariadb.com>2019-01-09 14:13:53 +0530
commit3724a5b5f477df5c562a86024776ec7513193b11 (patch)
treec4f1a67acaf657b969932a4042737e1e34a95c57
parente57a5c0e9d7938bd03fa369ac5b9bfa802bbf732 (diff)
downloadmariadb-git-3724a5b5f477df5c562a86024776ec7513193b11.tar.gz
opt commit 2
-rw-r--r--mysql-test/main/xyz.result40
-rw-r--r--mysql-test/main/xyz.test4
-rw-r--r--mysql-test/main/xyz_blob.result5
-rw-r--r--mysql-test/main/xyz_blob.test5
-rw-r--r--sql/field.cc2
-rw-r--r--sql/handler.cc33
6 files changed, 80 insertions, 9 deletions
diff --git a/mysql-test/main/xyz.result b/mysql-test/main/xyz.result
new file mode 100644
index 00000000000..faef7b01941
--- /dev/null
+++ b/mysql-test/main/xyz.result
@@ -0,0 +1,40 @@
+create table t1(a int primary key , b int , c int, index(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 t1
+type const
+possible_keys PRIMARY
+key PRIMARY
+key_len 4
+ref const
+rows 1
+Extra
+explain select * from t1 where b=34 and c = 34;;
+id 1
+select_type SIMPLE
+table t1
+type ref
+possible_keys b
+key b
+key_len 10
+ref const,const
+rows 1
+Extra
+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
+drop table t1;
diff --git a/mysql-test/main/xyz.test b/mysql-test/main/xyz.test
index ef98394568f..802b3e18bc0 100644
--- a/mysql-test/main/xyz.test
+++ b/mysql-test/main/xyz.test
@@ -1,10 +1,10 @@
-create table t1(a int primary key , b int , c int, unique(b,c));
+create table t1(a int primary key , b int , c int, index(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 b=34 and c = 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
index e4403b0e169..99910225c16 100644
--- a/mysql-test/main/xyz_blob.result
+++ b/mysql-test/main/xyz_blob.result
@@ -1,10 +1,11 @@
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 values(1,1,1);
+insert into t1 values(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";;
+explain select * from t1 where a="1";;
id 1
select_type SIMPLE
table NULL
diff --git a/mysql-test/main/xyz_blob.test b/mysql-test/main/xyz_blob.test
index 05c5f635ff3..cd27f200d33 100644
--- a/mysql-test/main/xyz_blob.test
+++ b/mysql-test/main/xyz_blob.test
@@ -1,10 +1,11 @@
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 values(1,1,1);
+insert into t1 values(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 a="1";
--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";
diff --git a/sql/field.cc b/sql/field.cc
index 0f632aa1fda..46bc1ae6bc1 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -2282,6 +2282,8 @@ int Field::store_time_dec(const MYSQL_TIME *ltime, uint dec)
bool Field::optimize_range(uint idx, uint part) const
{
+ if (table->key_info[idx].algorithm == HA_KEY_ALG_LONG_HASH)
+ return false;
return MY_TEST(table->file->index_flags(idx, part, 1) & HA_READ_RANGE);
}
diff --git a/sql/handler.cc b/sql/handler.cc
index 7c17bd733e5..6dcac49629e 100644
--- a/sql/handler.cc
+++ b/sql/handler.cc
@@ -158,6 +158,9 @@ handlerton *ha_default_tmp_handlerton(THD *thd)
return hton;
}
+static int check_duplicate_long_entry_key(TABLE *table, handler *h, uchar *new_rec,
+ uint key_no);
+int read_long_unique_index(TABLE *table, uint index, const uchar *key);
/** @brief
Return the storage engine handlerton for the supplied name
@@ -2854,8 +2857,11 @@ int handler::ha_index_read_map(uchar *buf, const uchar *key,
DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
m_lock_type != F_UNLCK);
DBUG_ASSERT(inited==INDEX);
-
- TABLE_IO_WAIT(tracker, m_psi, PSI_TABLE_FETCH_ROW, active_index, 0,
+ if (table->key_info[active_index].algorithm == HA_KEY_ALG_LONG_HASH
+ && !(table->key_info[active_index].key_part->field->flags & LONG_UNIQUE_HASH_FIELD))
+ read_long_unique_index(table, active_index, key);
+ else
+ TABLE_IO_WAIT(tracker, m_psi, PSI_TABLE_FETCH_ROW, active_index, 0,
{ result= index_read_map(buf, key, keypart_map, find_flag); })
increment_statistics(&SSV::ha_read_key_count);
if (!result)
@@ -2867,7 +2873,26 @@ int handler::ha_index_read_map(uchar *buf, const uchar *key,
table->status=result ? STATUS_NOT_FOUND: 0;
DBUG_RETURN(result);
}
-
+int read_long_unique_index(TABLE *table, uint index, const uchar *key)
+{
+ KEY *key_info= table->key_info + index;
+ KEY_PART_INFO *key_part;
+ Field *field;
+ //Copy key to table->record , So that we can get long_unique_key
+ re_setup_keyinfo_hash(key_info);
+ key_part= key_info->key_part;
+ for (uint i= 0; i < key_info->user_defined_key_parts; i++)
+ {
+ field= key_part->field;
+ memcpy(field->ptr, key + key_part->offset, field->pack_length());
+ field->set_notnull();
+ key_part++;
+ }
+ setup_keyinfo_hash(key_info);
+ field= key_info->key_part->field;
+ table->update_virtual_field(field);
+ return check_duplicate_long_entry_key(table, table->file, table->record[0], index);
+}
/*
@note: Other index lookup/navigation functions require prior
handler->index_init() call. This function is different, it requires
@@ -2883,6 +2908,8 @@ int handler::ha_index_read_idx_map(uchar *buf, uint index, const uchar *key,
DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
m_lock_type != F_UNLCK);
DBUG_ASSERT(end_range == NULL);
+ if (table->key_info[index].algorithm == HA_KEY_ALG_LONG_HASH)
+ read_long_unique_index(table, index, key);
TABLE_IO_WAIT(tracker, m_psi, PSI_TABLE_FETCH_ROW, index, 0,
{ result= index_read_idx_map(buf, index, key, keypart_map, find_flag); })
increment_statistics(&SSV::ha_read_key_count);