This section provides information about the
NdbScanOperation class.
- Parent class
- Child classes
- Description
The
NdbScanOperationclass represents a scanning operation used in a transaction. This class inherits fromNdbOperation.- Methods
-
The following table lists the public methods of this class and the purpose or use of each method:
Table 2.62 NdbScanOperation class methods and descriptions
Name Description close()Closes the scan deleteCurrentTuple()Deletes the current tuple lockCurrentTuple()Locks the current tuple nextResult()Gets the next tuple getNdbTransaction()Gets the NdbTransactionobject for this scangetPruned()Used to find out whether this scan is pruned to a single partition readTuples()Reads tuples restart()Restarts the scan updateCurrentTuple()Updates the current tuple This class has no public constructor. To create an instance of
NdbScanOperation, it is necessary to use theNdbTransaction::getNdbScanOperation()method. - Types
-
This class defines two public types, which are listed here:
For more information about the use of
NdbScanOperation, see
Section 1.4.2.3.3, “Scan Operations”, and
Section 1.4.2.3.4, “Using Scans to Update or Delete Rows”.
- Description
-
Calling this method closes a scan. Rows returned by this scan are no longer available after the scan has been closed using this method.
See Scans with exclusive locks, for information about multiple threads attempting to perform the same scan with an exclusive lock and how this can affect closing the scans.
- Signature
void close ( bool forceSend = false, bool releaseOp = false )- Parameters
-
This method takes the two parameters listed here:
forceSenddefaults tofalse; callclose()with this parameter set totruein order to force transactions to be sent.-
releaseOpalso defaults tofalse; set this totruein order to release the operation.The buffer allocated by an
NdbScanOperationfor receiving the scanned rows is released whenever the cursor navigating the result set is closed using theclose()method, regardless of the value of thereleaseOpargument.
- Return value
None.
- Description
This method is used to delete the current tuple.
- Signature
-
const NdbOperation* deleteCurrentTuple ( NdbTransaction* takeOverTrans, const NdbRecord* record, char* row = 0, const unsigned char* mask = 0, const NdbOperation::OperationOptions* opts = 0, Uint32 sizeOfOpts = 0 )For more information, see Section 2.3.22, “The NdbRecord Interface”.
- Parameters
-
When used with the
NdbRecordinterface, this method takes the parameters listed here:The transaction (
takeOverTrans) that should perform the lock; when usingNdbRecordwith scans, this parameter is not optional.The
NdbRecordreferenced by the scan. Thisrecordvalue is required, even if no records are being read.The
rowfrom which to read. Set this toNULLif no read is to occur.The
maskpointer is optional. If it is present, then only columns for which the corresponding bit in the mask is set are retrieved by the scan.-
OperationOptions(opts) can be used to provide more finely-grained control of operation definitions. AnOperationOptionsstructure is passed with flags indicating which operation definition options are present. Not all operation types support all operation options; the options supported for each type of operation are shown in the following table:Table 2.63 Operation types for the NdbRecord OperationOptions
Operation type (Method) OperationOptionsFlags SupportedreadTuple()OO_ABORTOPTION,OO_GETVALUE,OO_PARTITION_ID,OO_INTERPRETEDinsertTuple()OO_ABORTOPTION,OO_SETVALUE,OO_PARTITION_ID,OO_ANYVALUEupdateTuple()OO_ABORTOPTION,OO_SETVALUE,OO_PARTITION_ID,OO_INTERPRETED,OO_ANYVALUEwriteTuple()OO_ABORTOPTION,OO_SETVALUE,OO_PARTITION_ID,OO_ANYVALUEdeleteTuple()OO_ABORTOPTION,OO_GETVALUE,OO_PARTITION_ID,OO_INTERPRETED,OO_ANYVALUE
The optional
sizeOfOptionsparameter is used to preserve backward compatibility of this interface with previous definitions of theOperationOptionsstructure. If an unusual size is detected by the interface implementation, it can use this to determine how to interpret the passedOperationOptionsstructure. To enable this functionality, the caller should passsizeof(NdbOperation::OperationOptions)for the value of this argument.If options are specified, their length (
sizeOfOpts) must be specified as well.
- Return value
Returns
0on success, or-1on failure.
- Description
Gets the
NdbTransactionobject for this scan.- Signature
NdbTransaction* getNdbTransaction ( void ) const- Parameters
None.
- Return value
A pointer to an
NdbTransactionobject.
- Description
This method is used to determine whether or not a given scan operation has been pruned to a single partition. For scans defined using NdbRecord, this method can be called before or after the scan is executed. For scans not defined using
NdbRecord,getPruned()is valid only after the scan has been executed.- Signature
bool getPruned ( void ) const- Parameters
None.
- Return value
Returns
true, if the scan is pruned to a single table partition.
- Description
This method locks the current tuple.
- Signature
-
This method can be called with an optional single parameter, in either of the two ways shown here:
NdbOperation* lockCurrentTuple ( void ) NdbOperation* lockCurrentTuple ( NdbTransaction* lockTrans )The following signature is also supported for this method, when using
NdbRecord:NdbOperation *lockCurrentTuple ( NdbTransaction* takeOverTrans, const NdbRecord* record, char* row = 0, const unsigned char* mask = 0 )This method also supports specifying one or more
OperationOptions(also when usingNdbRecord):NdbOperation *lockCurrentTuple ( NdbTransaction* takeOverTrans, const NdbRecord* record, char* row = 0, const unsigned char* mask = 0, const NdbOperation::OperationOptions* opts = 0, Uint32 sizeOfOptions = 0 ) - Parameters (without NdbRecord)
This method takes a single, optional parameter—the transaction that should perform the lock. If this is omitted, the transaction is the current one.
- Parameters (using NdbRecord)
-
When using the
NdbRecordinterface, this method takes these parameters, as described in the following list:The transaction (
takeOverTrans) that should perform the lock; when usingNdbRecordwith scans, this parameter is not optional.The
NdbRecordreferenced by the scan. This is required, even if no records are being read.The
rowfrom which to read. Set this toNULLif no read is to occur.The
maskpointer is optional. If it is present, then only columns for which the corresponding bit in the mask is set are retrieved by the scan.The
optsargument can take on any of the followingOperationOptionsvalues:OO_ABORTOPTION,OO_GETVALUE, andOO_ANYVALUE.If options are specified, their length (
sizeOfOptions) must be specified as well.
Calling an
NdbRecordscan lock takeover on anNdbRecAttr-style scan is not valid, nor is calling anNdbRecAttr-style scan lock takeover on anNdbRecord-style scan. - Return value
This method returns a pointer to an
NdbOperationobject, orNULL.
- Description
-
This method is used to fetch the next tuple in a scan transaction. Following each call to
nextResult(), the buffers andNdbRecAttrobjects defined inNdbOperation::getValue()are updated with values from the scanned tuple.When
nextResult()is executed following end-of-file,NDBreturns error code 4210 (Ndb sent more info than length specified) and the extra transaction object is freed by returning it to the idle list for the right TC node. - Signatures
-
This method can be invoked in one of two ways. The first of these is shown here:
int nextResult ( bool fetchAllowed = true, bool forceSend = false )It is also possible to use this method as shown here:
int nextResult ( const char*& outRow, bool fetchAllowed = true, bool forceSend = false ) - Parameters (2-parameter version)
-
This method takes the following two parameters:
-
Normally, the NDB API contacts the
NDBkernel for more tuples whenever it is necessary; settingfetchAllowedtofalsekeeps this from happening.Disabling
fetchAllowedby setting it tofalseforcesNDBto process any records it already has in its caches. When there are no more cached records it returns2. You must then callnextResult()withfetchAllowedequal totruein order to contactNDBfor more records.While
nextResult(false)returns0, you should transfer the record to another transaction usingexecute(NdbTransaction::NoCommit). WhennextResult(false)returns2, you should normally execute and commit the other transaction. This causes any locks to be transferred to the other transaction, updates or deletes to be made, and then, the locks to be released. Following this, you can callnextResult(true)to have more records fetched and cached in the NDB API.NoteIf you do not transfer the records to another transaction, the locks on those records will be released the next time that the
NDBKernel is contacted for more records.Disabling
fetchAllowedcan be useful when you want to update or delete all of the records obtained in a given transaction, as doing so saves time and speeds up updates or deletes of scanned records. forceSenddefaults tofalse, and can normally be omitted. However, setting this parameter totruemeans that transactions are sent immediately. See Section 1.4.4, “The Adaptive Send Algorithm”, for more information.
-
- Parameters (3-parameter version)
-
This method can also be called with the following three parameters:
Calling
nextResult()sets a pointer to the next row inoutRow(if returning 0). This pointer is valid (only) until the next call tonextResult()whenfetchAllowedis true. TheNdbRecordobject defining the row format must be specified beforehand usingNdbTransaction::scanTable()(orNdbTransaction::scanIndex().When false,
fetchAllowedforcesNDBto process any records it already has in its caches. See the description for this parameter in the previous Parameters subsection for more details.Setting
forceSendtotruemeans that transactions are sent immediately, as described in the previous Parameters subsection, as well as in Section 1.4.4, “The Adaptive Send Algorithm”.
- Return value
-
This method returns one of the following 4 integer values, interpreted as shown in the following list:
-1: Indicates that an error has occurred.0: Another tuple has been received.1: There are no more tuples to scan.2: There are no more cached records (invokenextResult(true)to fetch more records).
- Example
- Description
This method is used to perform a scan.
- Signature
virtual int readTuples ( LockMode mode = LM_Read, Uint32 flags = 0, Uint32 parallel = 0, Uint32 batch = 0 )- Parameters
-
This method takes the four parameters listed here:
-
The lock
mode; this is aLockModevalue.Scans with exclusive locks. When scanning with an exclusive lock, extra care must be taken due to the fact that, if two threads perform this scan simultaneously over the same range, then there is a significant probability of causing a deadlock. The likelihood of a deadlock is increased if the scan is also ordered (that is, using
SF_OrderByorSF_Descending).The
NdbScanOperation::close()method is also affected by this deadlock, since all outstanding requests are serviced before the scan is actually closed. One or more
ScanFlagvalues. Multiple values areOR'ed togetherThe number of fragments to scan in
parallel; use0to require that the maximum possible number be used.The
batchparameter specifies how many records will be returned to the client from the server by the nextNdbScanOperation::nextResult(true)method call. Use0to specify the maximum automatically.
-
- Return value
Returns
0on success,-1on failure.
- Description
Use this method to restart a scan without changing any of its
getValue()calls or search conditions.- Signature
int restart ( bool forceSend = false )- Parameters
Call this method with
forceSendset totruein order to force the transaction to be sent.- Return value
0on success;-1on failure.
This section provides information about the
ScanFlag data type.
- Description
Values of this type are the scan flags used with the
readTuples()method. More than one may be used, in which case, they areOR'ed together as the second argument to that method. See NdbScanOperation::readTuples(), for more information.- Enumeration values
-
Possible values are shown, along with descriptions, in the following table:
Table 2.64 NdbScanOperation::ScanFlag values and descriptions
Value Description SF_TupScanScan in TUP order (that is, in the order of the rows in memory). Applies to table scans only. SF_DiskScanScan in disk order (order of rows on disk). Applies to table scans only. SF_OrderByOrdered index scan (ascending); rows returned from an index scan are sorted, and ordered on the index key. Scans in either ascending or descending order are affected by this flag, which causes the API to perform a merge-sort among the ordered scans of each fragment to obtain a single sorted result set.
Notes:
Ordered indexes are distributed, with one ordered index for each fragment of a table.
Range scans are often parallel across all index fragments. Occasionally, they can be pruned to one index fragment.
Each index fragment range scan can return results in either ascending or descending order. Ascending is the default; to choose descending order, set the
SF_Descendingflag.When multiple index fragments are scanned in parallel, the results are sent back to NDB where they can optionally be merge-sorted before being returned to the user. This merge sorting is controlled using the
SF_OrderByandSF_OrderByFullflags.If
SF_OrderByorSF_OrderByFullis not used, the results from each index fragment are in order (either ascending or descending), but results from different fragments may be interleaved.-
When using
SF_OrderByorSF_OrderByFull, some extra constraints are imposed internally; these are listed here:If the range scan is not pruned to one index fragment then all index fragments must be scanned in parallel. (Unordered scans can be executed with less than full parallelism.)
Results from every index fragment must be available before returning any rows, to ensure a correct merge sort. This serialises the “scrolling” of the scan, potentially resulting in lower row throughput.
Unordered scans can return rows to the API client before all index fragments have returned any batches, and can overlap next-batch requests with row processing.
SF_OrderByFullThis is the same as SF_OrderBy, except that all key columns are added automatically to the read bitmask.SF_DescendingCauses an ordered index scan to be performed in descending order. SF_ReadRangeNoFor index scans, when this flag is set, NdbIndexScanOperation::get_range_no()can be called to read back therange_nodefined inNdbIndexScanOperation::setBound(). In addition, when this flag is set, andSF_OrderByorSF_OrderByFullis also set, results from ranges are returned in their entirety before any results are returned from subsequent ranges.SF_MultiRangeIndicates that this scan is part of a multirange scan; each range is scanned separately. SF_KeyInfoRequests KeyInfoto be sent back to the caller. This enables the option to take over the row lock taken by the scan, usinglockCurrentTuple(), by making sure that the kernel sends back the information needed to identify the row and the lock. This flag is enabled by default for scans usingLM_Exclusive, but must be explicitly specified to enable the taking over ofLM_Readlocks. (See theLockModedocumentation for more information.)
This section provides information about the
ScanOptions data structure.
- Parent class
- Description
-
This data structure is used to pass options to the
NdbRecord-basedscanTable()andscanIndex()methods of theNdbTransactionclass. Each option type is marked as present by setting the corresponding bit in theoptionsPresentfield. Only the option types marked in theoptionsPresentfield need have sensible data.All data is copied out of the
ScanOptionsstructure (and any subtended structures) at operation definition time. If no options are required, thenNULLmay be passed as theScanOptionspointer. - Members
-
The elements making up this structure are shown in the following table:
Table 2.65 NdbScanOperation::ScanOptions attributes, with types and descriptions
Name Type Description optionsPresentUint64Which options are present. [...] Type:SO_SCANFLAGS:0x01SO_PARALLEL:0x02SO_BATCH:0x04SO_GETVALUE:0x08SO_PARTITION_ID:0x10SO_INTERPRETED:0x20SO_CUSTOMDATA:0x40SO_PARTINFO:0x80
Type of options. scan_flagsUint32Flags controlling scan behavior; see NdbScanOperation::ScanFlag, for more information. parallelUint32Scan parallelism; 0 (the default) sets maximum parallelism. batchUint32Batch size for transfers from data nodes to API nodes; 0 (the default) enables this to be selected automatically. extraGetValuesGetValueSpecExtra values to be read for each row matching the sdcan criteria. numExtraGetValuesUint32Number of extra values to be read. partitionIdUint32Limit the scan to the partition having this ID; alternatively, you can supply an PartitionSpechere. For index scans, partitioning information can be supplied for each range.interpretedCodeNdbInterpretedCodeInterpeted code to execute as part of the scan. customDatavoid*Data pointer to associate with this scan operation. partitionInfoPartitionSpecPartition information for bounding this scan. sizeOfPartInfoUint32Size of the bounding partition information. For more information, see Section 2.3.22, “The NdbRecord Interface”.
- Description
This method is used to update the current tuple.
- Signature
-
Originally, this method could be called with a single. optional parameter, in either of the ways shown here:
NdbOperation* updateCurrentTuple ( void ) NdbOperation* updateCurrentTuple ( NdbTransaction* updateTrans )It is also possible to employ this method, when using
NdbRecordwith scans, as shown here:NdbOperation* updateCurrentTuple ( NdbTransaction* takeOverTrans, const NdbRecord* record, const char* row, const unsigned char* mask = 0 )See Section 2.3.22, “The NdbRecord Interface”, for more information.
- Parameters (original)
This method takes a single, optional parameter—the transaction that should perform the lock. If this is omitted, the transaction is the current one.
- Parameters (using NdbRecord)
-
When using the
NdbRecordinterface, this method takes the following parameters, as described in the following list:The takeover transaction (
takeOverTrans).The
record(NdbRecordobject) referencing the column used for the scan.The
rowto read from. If no attributes are to be read, set this equal toNULL.The
maskpointer is optional. If it is present, then only columns for which the corresponding bit in the mask is set are retrieved by the scan.
- Return value
This method returns an
NdbOperationobject orNULL.