#At file:///home/frazer/bzr/mysql-5.1-telco-6.2/
2880 Frazer Clement 2009-03-17
Bug#38793 NDBAPI : EQ never sent for Index scan bounds
NdbRecord ordered index scans currently express an EQ range as separate
lower and upper bounds. This results in 2 copies of EQ column values
being sent to the kernel which is inefficient.
This patch detects when an equal range is specified by comparing the
passed pointers, key lengths and inclusive bits and sending only one
copy of the equal key columns. This halves the amount of KeyInfo
sent for an EQ range.
modified:
storage/ndb/src/ndbapi/NdbScanOperation.cpp
=== modified file 'storage/ndb/src/ndbapi/NdbScanOperation.cpp'
--- a/storage/ndb/src/ndbapi/NdbScanOperation.cpp 2009-03-16 18:08:48 +0000
+++ b/storage/ndb/src/ndbapi/NdbScanOperation.cpp 2009-03-17 10:48:38 +0000
@@ -670,26 +670,55 @@ NdbIndexScanOperation::setBound(const Nd
if (likely(!openRange))
{
- for (j= 0; j<key_count; j++)
+ /* If low and high key pointers are the same and key counts are
+ * the same, we send as an Eq bound to save bandwidth.
+ * This will not send an EQ bound if :
+ * - Different numbers of high and low keys are EQ
+ * - High and low keys are EQ, but use different ptrs
+ * This could be improved in future with another setBound() variant.
+ */
+ const bool isEqRange=
+ (bound.low_key == bound.high_key) &&
+ (bound.low_key_count == bound.high_key_count) &&
+ (bound.low_inclusive && bound.high_inclusive); // Does this matter?
+
+ if (isEqRange)
{
- Uint32 bound_type;
- /* If key is part of lower bound */
- if (bound.low_key && j<bound.low_key_count)
+ /* Using BoundEQ will result in bound being sent only once */
+ for (j= 0; j<key_count; j++)
{
- /* Inclusive if defined, or matching rows can include this value */
- bound_type= bound.low_inclusive || j+1 < bound.low_key_count ?
- BoundLE : BoundLT;
ndbrecord_insert_bound(key_record, key_record->key_indexes[j],
- bound.low_key, bound_type);
+ bound.low_key, BoundEQ);
}
- /* If key is part of upper bound */
- if (bound.high_key && j<bound.high_key_count)
+ }
+ else
+ {
+ /* Distinct upper and lower bounds, must specify them independently */
+ /* Note : Protocol allows individual columns to be specified as EQ
+ * or some prefix of columns. This is not currently supported from
+ * NDBAPI.
+ */
+ for (j= 0; j<key_count; j++)
{
- /* Inclusive if defined, or matching rows can include this value */
- bound_type= bound.high_inclusive || j+1 < bound.high_key_count ?
- BoundGE : BoundGT;
- ndbrecord_insert_bound(key_record, key_record->key_indexes[j],
- bound.high_key, bound_type);
+ Uint32 bound_type;
+ /* If key is part of lower bound */
+ if (bound.low_key && j<bound.low_key_count)
+ {
+ /* Inclusive if defined, or matching rows can include this value */
+ bound_type= bound.low_inclusive || j+1 < bound.low_key_count ?
+ BoundLE : BoundLT;
+ ndbrecord_insert_bound(key_record, key_record->key_indexes[j],
+ bound.low_key, bound_type);
+ }
+ /* If key is part of upper bound */
+ if (bound.high_key && j<bound.high_key_count)
+ {
+ /* Inclusive if defined, or matching rows can include this value */
+ bound_type= bound.high_inclusive || j+1 < bound.high_key_count ?
+ BoundGE : BoundGT;
+ ndbrecord_insert_bound(key_record, key_record->key_indexes[j],
+ bound.high_key, bound_type);
+ }
}
}
}
| Thread |
|---|
| • bzr commit into mysql-5.1-telco-6.2 branch (frazer:2880) Bug#38793 | Frazer Clement | 17 Mar |