List:Commits« Previous MessageNext Message »
From:Martin Skold Date:May 2 2007 10:32am
Subject:bk commit into 5.1 tree (mskold:1.2505) BUG#27980
View as plain text  
Below is the list of changes that have just been committed into a local
5.1 repository of marty. When marty does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet@stripped, 2007-05-02 12:31:53+02:00, mskold@stripped +1 -0
  ha_ndbcluster.cc:
    Bug#27980 INSERT IGNORE wrongly ignores NULLs in unique index: added check for null values

  sql/ha_ndbcluster.cc@stripped, 2007-05-02 12:30:34+02:00, mskold@stripped +38 -1
    Bug#27980 INSERT IGNORE wrongly ignores NULLs in unique index: added check for null values

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	mskold
# Host:	linux.site
# Root:	/windows/Linux_space/MySQL/mysql-5.1-new-ndb

--- 1.444/sql/ha_ndbcluster.cc	2007-05-02 12:32:08 +02:00
+++ 1.445/sql/ha_ndbcluster.cc	2007-05-02 12:32:08 +02:00
@@ -1909,6 +1909,33 @@ bool ha_ndbcluster::check_all_operations
 }
 
 
+/**
+ * Check if record contains any null valued columns that are part of a key
+ */
+static
+int
+check_null_in_record(const KEY* key_info, const byte *record)
+{
+  KEY_PART_INFO *curr_part, *end_part;
+  curr_part= key_info->key_part;
+  end_part= curr_part + key_info->key_parts;
+
+  while (curr_part != end_part)
+  {
+    if (curr_part->null_bit &&
+        (record[curr_part->null_offset] & curr_part->null_bit))
+      return 1;
+    curr_part++;
+  }
+  return 0;
+  /*
+    We could instead pre-compute a bitmask in table_share with one bit for
+    every null-bit in the key, and so check this just by OR'ing the bitmask
+    with the null bitmap in the record.
+    But not sure it's worth it.
+  */
+}
+
 /*
  * Peek to check if any rows already exist with conflicting
  * primary key or unique index values
@@ -1966,7 +1993,17 @@ int ha_ndbcluster::peek_indexed_rows(con
     if (i != table->s->primary_key &&
         key_info->flags & HA_NOSAME)
     {
-      // A unique index is defined on table
+      /*
+        A unique index is defined on table.
+        We cannot look up a NULL field value in a unique index. But since
+        keys with NULLs are not indexed, such rows cannot conflict anyway, so
+        we just skip the index in this case.
+      */
+      if (check_null_in_record(key_info, record))
+      {
+        DBUG_PRINT("info", ("skipping check for key with NULL"));
+        continue;
+      } 
       NdbIndexOperation *iop;
       const NDBINDEX *unique_index = m_index[i].unique_index;
       key_part= key_info->key_part;
Thread
bk commit into 5.1 tree (mskold:1.2505) BUG#27980Martin Skold2 May