[Commits] Rev 2852: Fix for LP BUG#606013: Adding bit field support for heap tables. in file:///home/bell/maria/bzr/work-maria-5.3-lp606013/

sanja at askmonty.org sanja at askmonty.org
Tue Nov 23 12:35:38 EET 2010


At file:///home/bell/maria/bzr/work-maria-5.3-lp606013/

------------------------------------------------------------
revno: 2852
revision-id: sanja at askmonty.org-20101123103537-4svo6d6m5dc6cpvi
parent: psergey at askmonty.org-20101111123526-tngd0657sv21i8zq
committer: sanja at askmonty.org
branch nick: work-maria-5.3-lp606013
timestamp: Tue 2010-11-23 12:35:37 +0200
message:
  Fix for LP BUG#606013: Adding bit field support for heap tables.
-------------- next part --------------
=== modified file 'mysql-test/r/heap_btree.result'
--- a/mysql-test/r/heap_btree.result	2009-05-06 09:30:14 +0000
+++ b/mysql-test/r/heap_btree.result	2010-11-23 10:35:37 +0000
@@ -344,3 +344,38 @@ INSERT INTO t1 VALUES(1),(1);
 DELETE a1 FROM t1 AS a1, t1 AS a2 WHERE a1.a=a2.a;
 DROP TABLE t1;
 End of 5.0 tests
+# bit index in heap tables
+create table t1 (a bit(63) not null) engine=heap;
+insert into t1 values (869751),(736494),(226312),(802616),(728912);
+alter table t1 add unique uniq_id using BTREE (a);
+select 0+a from t1 where a > 736494;
+0+a
+802616
+869751
+explain select 0+a from t1 where a > 736494;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	range	uniq_id	uniq_id	8	NULL	3	Using where
+select 0+a from t1 where a = 736494;
+0+a
+736494
+explain select 0+a from t1 where a = 736494;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	const	uniq_id	uniq_id	8	const	1	
+select 0+a from t1 where a=869751 or a=736494;
+0+a
+736494
+869751
+explain select 0+a from t1 where a=869751 or a=736494;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	range	uniq_id	uniq_id	8	NULL	2	Using where
+select 0+a from t1 where a in (869751,736494,226312,802616);
+0+a
+226312
+736494
+802616
+869751
+explain select 0+a from t1 where a in (869751,736494,226312,802616);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	range	uniq_id	uniq_id	8	NULL	4	Using where
+drop table t1;
+End of 5.3 tests

=== modified file 'mysql-test/r/heap_hash.result'
--- a/mysql-test/r/heap_hash.result	2007-05-31 12:04:58 +0000
+++ b/mysql-test/r/heap_hash.result	2010-11-23 10:35:37 +0000
@@ -382,3 +382,38 @@ INSERT INTO t1 VALUES('A ', 'A ');
 ERROR 23000: Duplicate entry 'A -A ' for key 'key1'
 DROP TABLE t1;
 End of 5.0 tests
+# bit index in heap tables
+create table t1 (a bit(63) not null) engine=heap;
+insert into t1 values (869751),(736494),(226312),(802616),(728912);
+alter table t1 add unique uniq_id using HASH (a);
+select 0+a from t1 where a > 736494;
+0+a
+869751
+802616
+explain select 0+a from t1 where a > 736494;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	uniq_id	NULL	NULL	NULL	5	Using where
+select 0+a from t1 where a = 736494;
+0+a
+736494
+explain select 0+a from t1 where a = 736494;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	const	uniq_id	uniq_id	8	const	1	
+select 0+a from t1 where a=869751 or a=736494;
+0+a
+736494
+869751
+explain select 0+a from t1 where a=869751 or a=736494;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	range	uniq_id	uniq_id	8	NULL	2	Using where
+select 0+a from t1 where a in (869751,736494,226312,802616);
+0+a
+226312
+736494
+802616
+869751
+explain select 0+a from t1 where a in (869751,736494,226312,802616);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	range	uniq_id	uniq_id	8	NULL	4	Using where
+drop table t1;
+End of 5.3 tests

=== modified file 'mysql-test/t/heap_btree.test'
--- a/mysql-test/t/heap_btree.test	2009-05-06 09:30:14 +0000
+++ b/mysql-test/t/heap_btree.test	2010-11-23 10:35:37 +0000
@@ -263,3 +263,19 @@ DELETE a1 FROM t1 AS a1, t1 AS a2 WHERE
 DROP TABLE t1;
 --echo End of 5.0 tests
 
+-- echo # bit index in heap tables
+
+create table t1 (a bit(63) not null) engine=heap;
+insert into t1 values (869751),(736494),(226312),(802616),(728912);
+alter table t1 add unique uniq_id using BTREE (a);
+select 0+a from t1 where a > 736494;
+explain select 0+a from t1 where a > 736494;
+select 0+a from t1 where a = 736494;
+explain select 0+a from t1 where a = 736494;
+select 0+a from t1 where a=869751 or a=736494;
+explain select 0+a from t1 where a=869751 or a=736494;
+select 0+a from t1 where a in (869751,736494,226312,802616);
+explain select 0+a from t1 where a in (869751,736494,226312,802616);
+drop table t1;
+
+--echo End of 5.3 tests

=== modified file 'mysql-test/t/heap_hash.test'
--- a/mysql-test/t/heap_hash.test	2007-06-06 17:57:07 +0000
+++ b/mysql-test/t/heap_hash.test	2010-11-23 10:35:37 +0000
@@ -284,3 +284,20 @@ INSERT INTO t1 VALUES('A ', 'A ');
 DROP TABLE t1;
 
 --echo End of 5.0 tests
+
+-- echo # bit index in heap tables
+
+create table t1 (a bit(63) not null) engine=heap;
+insert into t1 values (869751),(736494),(226312),(802616),(728912);
+alter table t1 add unique uniq_id using HASH (a);
+select 0+a from t1 where a > 736494;
+explain select 0+a from t1 where a > 736494;
+select 0+a from t1 where a = 736494;
+explain select 0+a from t1 where a = 736494;
+select 0+a from t1 where a=869751 or a=736494;
+explain select 0+a from t1 where a=869751 or a=736494;
+select 0+a from t1 where a in (869751,736494,226312,802616);
+explain select 0+a from t1 where a in (869751,736494,226312,802616);
+drop table t1;
+
+--echo End of 5.3 tests

=== modified file 'storage/heap/ha_heap.cc'
--- a/storage/heap/ha_heap.cc	2010-04-01 14:34:51 +0000
+++ b/storage/heap/ha_heap.cc	2010-11-23 10:35:37 +0000
@@ -654,7 +654,8 @@ int ha_heap::create(const char *name, TA
             seg->type != HA_KEYTYPE_VARTEXT1 &&
             seg->type != HA_KEYTYPE_VARTEXT2 &&
             seg->type != HA_KEYTYPE_VARBINARY1 &&
-            seg->type != HA_KEYTYPE_VARBINARY2)
+            seg->type != HA_KEYTYPE_VARBINARY2 &&
+            seg->type != HA_KEYTYPE_BIT)
           seg->type= HA_KEYTYPE_BINARY;
       }
       seg->start=   (uint) key_part->offset;
@@ -686,6 +687,15 @@ int ha_heap::create(const char *name, TA
         auto_key= key+ 1;
 	auto_key_type= field->key_type();
       }
+      if (seg->type == HA_KEYTYPE_BIT)
+      {
+        seg->bit_length= ((Field_bit *) field)->bit_len;
+        seg->bit_start= ((Field_bit *) field)->bit_ofs;
+        seg->bit_pos= (uint) (((Field_bit *) field)->bit_ptr -
+                                          (uchar*) table_arg->record[0]);
+      }
+      else
+        seg->bit_length= seg->bit_start= seg->bit_pos= 0;
     }
   }
   mem_per_row+= MY_ALIGN(share->reclength + 1, sizeof(char*));

=== modified file 'storage/heap/hp_create.c'
--- a/storage/heap/hp_create.c	2010-08-05 19:56:11 +0000
+++ b/storage/heap/hp_create.c	2010-11-23 10:35:37 +0000
@@ -104,6 +104,14 @@ int heap_create(const char *name, uint k
           */
           keyinfo->seg[j].type= HA_KEYTYPE_VARTEXT1;
           break;
+        case HA_KEYTYPE_BIT:
+          /*
+            The odd bits which stored separately (if they are present
+            (bit_pos, bit_length)) are already present in seg[j].length as
+            additional byte.
+            See field.h, function key_length()
+          */
+          break;
 	default:
 	  break;
 	}

=== modified file 'storage/heap/hp_hash.c'
--- a/storage/heap/hp_hash.c	2010-08-27 14:12:44 +0000
+++ b/storage/heap/hp_hash.c	2010-11-23 10:35:37 +0000
@@ -349,6 +349,15 @@ ulong hp_rec_hashnr(register HP_KEYDEF *
     }
     else
     {
+      if (seg->type == HA_KEYTYPE_BIT && seg->bit_length)
+      {
+        uchar bits= get_rec_bits(rec + seg->bit_pos,
+                                 seg->bit_start, seg->bit_length);
+	nr^=(ulong) ((((uint) nr & 63)+nr2)*((uint) bits))+ (nr << 8);
+	nr2+=3;
+        end--;
+      }
+
       for (; pos < end ; pos++)
       {
 	nr^=(ulong) ((((uint) nr & 63)+nr2)*((uint) *pos))+ (nr << 8);
@@ -465,6 +474,14 @@ ulong hp_rec_hashnr(register HP_KEYDEF *
     else
     {
       uchar *end= pos+seg->length;
+      if (seg->type == HA_KEYTYPE_BIT && seg->bit_length)
+      {
+        uchar bits= get_rec_bits(rec + seg->bit_pos,
+                                 seg->bit_start, seg->bit_length);
+	nr *=16777619;
+	nr ^=(uint) bits;
+        end--;
+      }
       for ( ; pos < end ; pos++)
       {
 	nr *=16777619; 
@@ -577,7 +594,18 @@ int hp_rec_key_cmp(HP_KEYDEF *keydef, co
     }
     else
     {
-      if (bcmp(rec1+seg->start,rec2+seg->start,seg->length))
+      uint dec= 0;
+      if (seg->type == HA_KEYTYPE_BIT && seg->bit_length)
+      {
+        uchar bits1= get_rec_bits(rec1 + seg->bit_pos,
+                                  seg->bit_start, seg->bit_length);
+        uchar bits2= get_rec_bits(rec2 + seg->bit_pos,
+                                  seg->bit_start, seg->bit_length);
+        if (bits1 != bits2)
+          return 1;
+        dec= 1;
+      }
+      if (bcmp(rec1 + seg->start, rec2 + seg->start, seg->length - dec))
 	return 1;
     }
   }
@@ -660,7 +688,18 @@ int hp_key_cmp(HP_KEYDEF *keydef, const
     }
     else
     {
-      if (bcmp(rec+seg->start,key,seg->length))
+      uint dec= 0;
+      if (seg->type == HA_KEYTYPE_BIT && seg->bit_length)
+      {
+        uchar bits= get_rec_bits(rec + seg->bit_pos,
+                                 seg->bit_start, seg->bit_length);
+        if (bits != (*key))
+          return 1;
+        dec= 1;
+        key++;
+      }
+
+      if (bcmp(rec + seg->start, key, seg->length - dec))
 	return 1;
     }
   }
@@ -689,6 +728,12 @@ void hp_make_key(HP_KEYDEF *keydef, ucha
     }
     if (seg->type == HA_KEYTYPE_VARTEXT1)
       char_length+= seg->bit_start;             /* Copy also length */
+    else if (seg->type == HA_KEYTYPE_BIT && seg->bit_length)
+    {
+      *key++= get_rec_bits(rec + seg->bit_pos,
+                           seg->bit_start, seg->bit_length);
+      char_length--;
+    }
     memcpy(key,rec+seg->start,(size_t) char_length);
     key+= char_length;
   }
@@ -720,7 +765,8 @@ uint hp_rb_make_key(HP_KEYDEF *keydef, u
     {
       uint length= seg->length;
       uchar *pos= (uchar*) rec + seg->start;
-      
+      DBUG_ASSERT(seg->type != HA_KEYTYPE_BIT);
+
 #ifdef HAVE_ISNAN
       if (seg->type == HA_KEYTYPE_FLOAT)
       {
@@ -784,6 +830,12 @@ uint hp_rb_make_key(HP_KEYDEF *keydef, u
         seg->charset->cset->fill(seg->charset, (char*) key + char_length,
                                  seg->length - char_length, ' ');
     }
+    if (seg->type == HA_KEYTYPE_BIT && seg->bit_length)
+    {
+      *key++= get_rec_bits(rec + seg->bit_pos,
+                           seg->bit_start, seg->bit_length);
+      char_length--;
+    }
     memcpy(key, rec + seg->start, (size_t) char_length);
     key+= seg->length;
   }



More information about the commits mailing list