Documentation Home
MySQL NDB Cluster API Developer Guide
Download this Manual NdbTransaction::scanIndex()

Description.  Perform an index range scan of a table, with optional ordering.


NdbIndexScanOperation* scanIndex
      const NdbRecord* key_record,
      const NdbRecord* result_record,
      NdbOperation::LockMode lock_mode = NdbOperation::LM_Read,
      const unsigned char* result_mask = 0,
      const NdbIndexScanOperation::IndexBound* bound = 0,
      const NdbScanOperation::ScanOptions* options = 0,
      Uint32 sizeOfOptions = 0

Parameters.  The key_record describes the index to be scanned. It must be a key record for the index; that is, it must specify, at a minimum, all of the key columns of the index. The key_record must be created from the index to be scanned (and not from the underlying table).

The result_record describes the rows to be returned from the scan. For an ordered index scan, result_record must be a key record for the index to be scanned; that is, it must include (at a minimum) all of the columns in the index (the full index key is needed by the NDB API for merge-sorting the ordered rows returned from each fragment).

Like the key_record, the result_record must be created from the underlying table, and not from the index to be scanned. Both the key_record and result_record NdbRecord structures must stay in place until the scan operation is closed.

A single IndexBound can be specified either in this call or in a separate call to NdbIndexScanOperation::setBound(). To perform a multi-range read, the scan_flags in the ScanOptions structure must include SF_MULTIRANGE. Additional bounds can be added using successive calls to NdbIndexScanOperation::setBound().

To specify an equals bound, use the same row pointer for the low_key and high_key with the low and high inclusive bits set.

To specify additional options, pass a ScanOptions structure.

The sizeOfOptions exists To enable backward compatability for this interface. This parameter indicates the size of the ScanOptions structure at the time the client was compiled, and enables detection of the use of an old-style ScanOptions structure. If this functionality is not required, this argument can be left set to 0.


For multi-range scans, the low_key and high_key pointers must be unique. In other words, it is not permissible to reuse the same row buffer for several different range bounds within a single scan. However, it is permissible to use the same row pointer as low_key and high_key in order to specify an equals bound; it is also permissible to reuse the rows after the scanIndex() method returns—that is, they need not remain valid until execute() time (unlike the NdbRecord pointers).

Return value.  The current NdbIndexScanOperation, which can be used for error checking.