=== modified file 'sql/ha_ndbcluster.cc' --- sql/ha_ndbcluster.cc 2008-10-14 14:06:02 +0000 +++ sql/ha_ndbcluster.cc 2008-10-15 16:18:18 +0000 @@ -9218,9 +9218,83 @@ ha_ndbcluster::read_multi_range_first(KE { /* Do a multi-range index scan for ranges not done by primary/unique key. */ NdbScanOperation::ScanOptions options; + + options.optionsPresent= 0; + + /* Check if partition pruning possible for this scan */ + if (m_use_partition_pruning && + (part_spec.start_part == part_spec.end_part)) + { + /* First scannable range can be pruned to a single partition, + * but can the others? + */ + DBUG_PRINT("info", ("Checking %u ranges to check if partition " + "pruning possible", + range_count -i - 1)); + bool allScanRangesSamePartition= true; + Uint32 colocatedRanges= 1; + for (Uint32 otherRangeNum= i+1; + otherRangeNum < range_count; + otherRangeNum++) + { + KEY_MULTI_RANGE *otherRange= &ranges[ otherRangeNum ]; + part_id_range otherPartSpec; + + if (otherRangeNum > NdbIndexScanOperation::MaxRangeNo) + break; + + /* Ignore non-scan ranges */ + if (read_multi_needs_scan(cur_index_type, key_info, otherRange)) + { + get_partition_set(table, table->record[0], active_index, + &otherRange->start_key, &otherPartSpec); + DBUG_PRINT("info", ("Scannable range %u start part: %u end part: %u", + otherRangeNum, otherPartSpec.start_part, + otherPartSpec.end_part)); + + if (otherPartSpec.start_part > otherPartSpec.end_part) + continue; /* Skip range */ + + if ((otherPartSpec.start_part == part_spec.start_part) && + (otherPartSpec.start_part == otherPartSpec.end_part)) + { + /* This range is bounded to the same partition as the + * previous range(s), continue to examine + * next + */ + DBUG_PRINT("info", ("Scannable range %u shares partition bound", + otherRangeNum)); + colocatedRanges++; + continue; + } + else + { + /* This range uses a different partition, or is not + * bounded to a single partition, no pruning possible + */ + DBUG_PRINT("info", ("Scannable range %u does not share " + "partition bound - no pruning possible", + otherRangeNum)); + allScanRangesSamePartition= false; + break; + } + } // read_multi_needs_scan + } // for (otherRangeNum) + + if (allScanRangesSamePartition) + { + DBUG_PRINT("info", ("Pruning scan to partition %u " + "as all %u relevant ranges are found there", + part_spec.start_part, + colocatedRanges)); + options.partitionId = part_spec.start_part; + options.optionsPresent |= NdbScanOperation::ScanOptions::SO_PARTITION_ID; + } + } // if (m_use_partition_pruning) + NdbInterpretedCode code(m_table); - options.optionsPresent= + options.optionsPresent|= NdbScanOperation::ScanOptions::SO_SCANFLAGS | NdbScanOperation::ScanOptions::SO_PARALLEL;