records_in_block= 10;
--- a/storage/heap/hp_delete.c
+++ b/storage/heap/hp_delete.c
-@@ -22,6 +22,8 @@
+@@ -22,6 +22,7 @@
uchar *pos;
HP_SHARE *share=info->s;
HP_KEYDEF *keydef, *end, *p_lastinx;
-+ uint rec_length, chunk_count;
+
DBUG_ENTER("heap_delete");
DBUG_PRINT("enter",("info: 0x%lx record: 0x%lx", (long) info, (long) record));
-@@ -31,6 +33,8 @@
- DBUG_RETURN(my_errno); /* Record changed */
- share->changed=1;
-
-+ rec_length = hp_get_encoded_data_length(share, record, &chunk_count);
-+
- if ( --(share->records) < share->blength >> 1) share->blength>>=1;
- pos=info->current_ptr;
-
-@@ -43,10 +47,7 @@
+@@ -43,10 +44,7 @@
}
info->update=HA_STATE_DELETED;
info->current_hash_ptr=0;
#if !defined(DBUG_OFF) && defined(EXTRA_HEAP_DEBUG)
DBUG_EXECUTE("check_heap",heap_check_heap(info, 0););
-@@ -75,7 +76,8 @@
+@@ -75,7 +73,8 @@
info->last_pos= NULL; /* For heap_rnext/heap_rprev */
custom_arg.keyseg= keyinfo->seg;
custom_arg.search_flag= SEARCH_SAME;
old_allocated= keyinfo->rb_tree.allocated;
res= tree_delete(&keyinfo->rb_tree, info->recbuf, custom_arg.key_length,
-@@ -112,6 +114,7 @@
+@@ -112,6 +111,7 @@
blength=share->blength;
if (share->records+1 == blength)
blength+= blength;
#define MAX_RECORDS 100000
#define MAX_KEYS 4
-@@ -44,6 +45,7 @@
- register uint i,j;
- uint ant,n1,n2,n3;
- uint write_count,update,opt_delete,check2,dupp_keys,found_key;
-+ uint mem_per_keys;
- int error;
- ulong pos;
- unsigned long key_check;
-@@ -53,6 +55,7 @@
+@@ -53,6 +54,7 @@
HP_SHARE *tmp_share;
HP_KEYDEF keyinfo[MAX_KEYS];
HA_KEYSEG keyseg[MAX_KEYS*5];
HEAP_PTR UNINIT_VAR(position);
HP_CREATE_INFO hp_create_info;
CHARSET_INFO *cs= &my_charset_latin1;
-@@ -65,12 +68,16 @@
+@@ -65,12 +67,16 @@
get_options(argc,argv);
bzero(&hp_create_info, sizeof(hp_create_info));
write_count=update=opt_delete=0;
key_check=0;
-@@ -118,11 +125,30 @@
+@@ -118,11 +124,28 @@
keyinfo[3].seg[0].null_pos=38;
keyinfo[3].seg[0].charset=cs;
+ columndef[3].length= 1;
+ columndef[3].null_bit= 1;
+ columndef[3].null_pos= 38;
-+
-+ mem_per_keys= (sizeof(char*) * 2) * 4;
+
bzero((char*) key1,sizeof(key1));
bzero((char*) key3,sizeof(key3));
HP_KEYDEF *keydef, *end;
uchar *pos;
HP_SHARE *share=info->s;
-+ uint rec_length, chunk_count;
++ uint chunk_count;
+
DBUG_ENTER("heap_write");
#ifndef DBUG_OFF
+ DBUG_RETURN(my_errno);
+ }
+
-+ rec_length= hp_get_encoded_data_length(share, record, &chunk_count);
++ hp_get_encoded_data_length(share, record, &chunk_count);
+
+ if (!(pos= hp_allocate_chunkset(&share->recordspace, chunk_count)))
DBUG_RETURN(my_errno);
Write a hash-key to the hash-index
--- a/storage/heap/hp_update.c
+++ b/storage/heap/hp_update.c
-@@ -17,43 +17,66 @@
+@@ -17,43 +17,65 @@
#include "heapdef.h"
uchar *pos;
my_bool auto_key_changed= 0;
HP_SHARE *share= info->s;
-+ uint old_length, new_length;
+ uint old_chunk_count, new_chunk_count;
+
DBUG_ENTER("heap_update");
+ if (info->opt_flag & READ_CHECK_USED && hp_rectest(info, old_record))
DBUG_RETURN(my_errno); /* Record changed */
+
-+ old_length = hp_get_encoded_data_length(share, old_record, &old_chunk_count);
-+ new_length = hp_get_encoded_data_length(share, new_record, &new_chunk_count);
++ hp_get_encoded_data_length(share, old_record, &old_chunk_count);
++ hp_get_encoded_data_length(share, new_record, &new_chunk_count);
+
+ if (new_chunk_count > old_chunk_count)
+ {
DBUG_RETURN(0);
err:
-@@ -63,7 +86,7 @@
+@@ -63,7 +85,7 @@
if (keydef->algorithm == HA_KEY_ALG_BTREE)
{
/* we don't need to delete non-inserted key from rb-tree */
{
if (++(share->records) == share->blength)
share->blength+= share->blength;
-@@ -73,10 +96,10 @@
+@@ -73,10 +95,10 @@
}
while (keydef >= share->keydef)
{
break;
}
keydef--;
-@@ -84,5 +107,12 @@
+@@ -84,5 +106,12 @@
}
if (++(share->records) == share->blength)
share->blength+= share->blength;
} /* heap_update */
--- /dev/null
+++ b/mysql-test/r/percona_heap_blob.result
-@@ -0,0 +1,952 @@
+@@ -0,0 +1,956 @@
+SET @old_default_storage_engine=@@default_storage_engine;
+SET default_storage_engine=MEMORY;
+drop table if exists t1,t2,t3,t4,t5,t6,t7;
+a
+Where
+drop table t1;
-+create table t1 (t text,c char(10),b blob, d varbinary(10));
++create table t1 (t text,c char(10),b blob, d varbinary(10)) collate latin1_general_cs;
+insert into t1 values (NULL,NULL,NULL,NULL);
+insert into t1 values ("","","","");
+insert into t1 values ("hello","hello","hello","hello");
+lock tables t1 READ;
+show full fields from t1;
+Field Type Collation Null Key Default Extra Privileges Comment
-+t text latin1_swedish_ci YES NULL #
-+c char(10) latin1_swedish_ci YES NULL #
++t text latin1_general_cs YES NULL #
++c char(10) latin1_general_cs YES NULL #
+b blob NULL YES NULL #
+d varbinary(10) NULL YES NULL #
+lock tables t1 WRITE;
+show full fields from t1;
+Field Type Collation Null Key Default Extra Privileges Comment
-+t text latin1_swedish_ci YES NULL #
-+c char(10) latin1_swedish_ci YES NULL #
++t text latin1_general_cs YES NULL #
++c char(10) latin1_general_cs YES NULL #
+b blob NULL YES NULL #
+d varbinary(10) NULL YES NULL #
+unlock tables;
+select t from t1 where t like "hello";
+t
+hello
-+HELLO
+select c from t1 where c like "hello";
+c
+hello
-+HELLO
+select b from t1 where b like "hello";
+b
+hello
+select c from t1 having c like "hello";
+c
+hello
-+HELLO
+select d from t1 having d like "hello";
+d
+hello
+select t from t1 where t like "%HELLO%";
+t
-+hello
+HELLO
+HELLO MY
+select c from t1 where c like "%HELLO%";
+c
-+hello
+HELLO
+HELLO MY
+select b from t1 where b like "%HELLO%";
+HELLO MY
+select c from t1 having c like "%HELLO%";
+c
-+hello
+HELLO
+HELLO MY
+select d from t1 having d like "%HELLO%";
+
+1
+a
-+hello
+HELLO
+HELLO MY
++hello
+select c from t1 order by c;
+c
+NULL
+
+
+a
-+hello
+HELLO
+HELLO MY
++hello
+select b from t1 order by b;
+b
+NULL
+NULL
+
+hello
++HELLO
+HELLO MY
+a
+1
+
+1
+a
-+hello
++HELLO
+HELLO MY
++hello
+select distinct b from t1 order by b;
+b
+NULL
+
+1
+a
-+hello
++HELLO
+HELLO MY
++hello
+select b from t1 group by b;
+b
+NULL
+NULL
+
+hello
++HELLO
+HELLO MY
+a
+1
+
+1
+a
-+hello
++HELLO
+HELLO MY
++hello
+select distinct b from t1 order by b;
+b
+NULL
+NULL
+
+hello
++HELLO
+HELLO MY
+a
+select distinct d from t1;
+NULL
+
+a
-+hello
++HELLO
+HELLO MY
++hello
+select distinct d from t1 order by d;
+d
+NULL
+NULL
+
+a
-+hello
++HELLO
+HELLO MY
++hello
+select d from t1 group by d;
+d
+NULL
+ 1
+1 1
+a 1
-+hello 2
++HELLO 1
+HELLO MY 1
++hello 1
+select b,count(*) from t1 group by b;
+b count(*)
+NULL 3
+NULL 2
+ 2
+a 1
-+hello 2
++HELLO 1
+HELLO MY 1
++hello 1
+select d,count(*) from t1 group by d;
+d count(*)
+NULL 2
+2
+DROP FUNCTION f1;
+DROP TABLE t1;
-+SET default_storage_engine=@old_default_storage_engine;
+SET @old_max_heap_table_size = @@global.max_heap_table_size;
+SET @old_max_allowed_packet = @@global.max_allowed_packet;
+SET GLOBAL max_heap_table_size = 18 * 1024 * 1024;
+SET GLOBAL max_allowed_packet = 24 * 1024 * 1024;
+drop table if exists t1;
-+CREATE TABLE t1 (data LONGBLOB) ENGINE=memory;
++CREATE TABLE t1 (data LONGBLOB);
+INSERT INTO t1 (data) VALUES (NULL);
+UPDATE t1 set data=repeat('a',18*1024*1024);
+select length(data) from t1;
+length(data)
+0
+drop table t1;
-+CREATE TABLE t1 (data BLOB) ENGINE=myisam;
++CREATE TABLE t1 (data BLOB);
+INSERT INTO t1 (data) VALUES (NULL);
+UPDATE t1 set data=repeat('a',18*1024*1024);
+Warnings:
+drop table t1;
+SET GLOBAL max_allowed_packet = @old_max_allowed_packet;
+SET GLOBAL max_heap_table_size = @old_max_heap_table_size;
++SET default_storage_engine=@old_default_storage_engine;
--- /dev/null
+++ b/mysql-test/r/percona_heap_bug783366.result
@@ -0,0 +1,14 @@
+#
+# test of blob, text, char and varbinary
+#
-+create table t1 (t text,c char(10),b blob, d varbinary(10));
++create table t1 (t text,c char(10),b blob, d varbinary(10)) collate latin1_general_cs;
+insert into t1 values (NULL,NULL,NULL,NULL);
+insert into t1 values ("","","","");
+insert into t1 values ("hello","hello","hello","hello");
+
+
+
-+SET default_storage_engine=@old_default_storage_engine;
+
+
+########################################################################
+
+# Bug #2159 (Problem with update of blob to > 16M)
+
-+CREATE TABLE t1 (data LONGBLOB) ENGINE=memory;
++CREATE TABLE t1 (data LONGBLOB);
+INSERT INTO t1 (data) VALUES (NULL);
+UPDATE t1 set data=repeat('a',18*1024*1024);
+select length(data) from t1;
+select length(data) from t1;
+drop table t1;
+
-+CREATE TABLE t1 (data BLOB) ENGINE=myisam;
++CREATE TABLE t1 (data BLOB);
+INSERT INTO t1 (data) VALUES (NULL);
+UPDATE t1 set data=repeat('a',18*1024*1024);
+select length(data) from t1;
+
+SET GLOBAL max_allowed_packet = @old_max_allowed_packet;
+SET GLOBAL max_heap_table_size = @old_max_heap_table_size;
++SET default_storage_engine=@old_default_storage_engine;
--- /dev/null
+++ b/mysql-test/t/percona_heap_bug783366.test
@@ -0,0 +1,19 @@