summaryrefslogtreecommitdiff
path: root/sql/key.cc
diff options
context:
space:
mode:
authorSergey Petrunya <psergey@askmonty.org>2010-12-13 13:42:40 +0300
committerSergey Petrunya <psergey@askmonty.org>2010-12-13 13:42:40 +0300
commit58b646001a1d9b00ca8e41bd2a6826ed40f81b5f (patch)
tree57c9062984c94b611fc88a13b119ce2fc57149d0 /sql/key.cc
parent419d524ff9013534d522eca8fedee3ead2c403d5 (diff)
parent14ca046833e3cbcd409b6a83c193e5fc16b5e94b (diff)
downloadmariadb-git-58b646001a1d9b00ca8e41bd2a6826ed40f81b5f.tar.gz
Merge DS-MRR/CPK improvements into 5.3-main
Diffstat (limited to 'sql/key.cc')
-rw-r--r--sql/key.cc51
1 files changed, 51 insertions, 0 deletions
diff --git a/sql/key.cc b/sql/key.cc
index a1793e9e5f4..1d27fdcf208 100644
--- a/sql/key.cc
+++ b/sql/key.cc
@@ -567,3 +567,54 @@ next_loop:
} while (key_info); /* no more keys to test */
DBUG_RETURN(0);
}
+
+
+/*
+ Compare two key tuples.
+
+ @brief
+ Compare two key tuples, i.e. two key values in KeyTupleFormat.
+
+ @param part KEY_PART_INFO with key description
+ @param key1 First key to compare
+ @param key2 Second key to compare
+ @param tuple_length Length of key1 (and key2, they are the same) in bytes.
+
+ @return
+ @retval 0 key1 == key2
+ @retval -1 key1 < key2
+ @retval +1 key1 > key2
+*/
+
+int key_tuple_cmp(KEY_PART_INFO *part, uchar *key1, uchar *key2,
+ uint tuple_length)
+{
+ uchar *key1_end= key1 + tuple_length;
+ int len;
+ int res;
+ LINT_INIT(len);
+ for (;key1 < key1_end; key1 += len, key2 += len, part++)
+ {
+ len= part->store_length;
+ if (part->null_bit)
+ {
+ if (*key1) // key1 == NULL
+ {
+ if (!*key2) // key1(NULL) < key2(notNULL)
+ return -1;
+ continue;
+ }
+ else if (*key2) // key1(notNULL) > key2 (NULL)
+ return 1;
+ /* Step over the NULL bytes for key_cmp() call */
+ key1++;
+ key2++;
+ len--;
+ }
+ if ((res= part->field->key_cmp(key1, key2)))
+ return res;
+ }
+ return 0;
+}
+
+