2.3.23.1 Using NdbInterpretedCode

2.3.23.1.1 NdbInterpretedCode Methods for Loading Values into Registers
2.3.23.1.2 NdbInterpretedCode Methods for Copying Values Between Registers and Table Columns
2.3.23.1.3 NdbInterpretedCode Register Arithmetic Methods
2.3.23.1.4 NdbInterpretedCode: Labels and Branching
2.3.23.1.5 Register-Based NdbInterpretedCode Branch Operations
2.3.23.1.6 Column-Based NdbInterpretedCode Branch Operations
2.3.23.1.7 Pattern-Based NdbInterpretedCode Branch Operations
2.3.23.1.8 NdbInterpretedCode Bitwise Comparison Operations
2.3.23.1.9 NdbInterpretedCode Result Handling Methods
2.3.23.1.10 NdbInterpretedCode Convenience Methods
2.3.23.1.11 Using Subroutines with NdbInterpretedCode
2.3.23.1.12 NdbInterpretedCode Utility Methods

The next few sections provide information about performing different types of operations with NdbInterpretedCode methods, including resource usage.

2.3.23.1.1 NdbInterpretedCode Methods for Loading Values into Registers

The methods described in this section are used to load constant values into NdbInterpretedCode program registers. The space required by each of these methods is shown in the following table:

MethodBuffer (words)Request message (words)
load_const_null()11
load_const_u16()11
load_const_u32()22
load_const_u64()33
2.3.23.1.2 NdbInterpretedCode Methods for Copying Values Between Registers and Table Columns

NdbInterpretedCode provides two methods for copying values between a column in the current table row and a program register. The read_attr() method is used to copy a table column value into a program register; write_attr() is used to copy a value from a program register into a table column. Both of these methods require that the table being operated on was specified when creating the NdbInterpretedCode object for which they are called.

The space required by each of these methods is shown in the following table:

MethodBuffer (words)Request message (words)
read_attr()11
write_attr()11

For more information, see Section 2.3.23.2.42, “NdbInterpretedCode::read_attr()”, and Section 2.3.23.2.46, “NdbInterpretedCode::write_attr()”.

2.3.23.1.3 NdbInterpretedCode Register Arithmetic Methods

NdbInterpretedCode provides two methods for performing arithmetic operations on registers. Using add_reg(), you can load the sum of two registers into another register; sub_reg() lets you load the difference of two registers into another register.

The space required by each of these methods is shown in the following table:

MethodBuffer (words)Request message (words)
add_reg()11
sub_reg()11

For mroe information, see Section 2.3.23.2.2, “NdbInterpretedCode::add_reg()”, and Section 2.3.23.2.44, “NdbInterpretedCode::sub_reg()”.

2.3.23.1.4 NdbInterpretedCode: Labels and Branching

The NdbInterpretedCode class lets you define labels within interpreted programs and provides a number of methods for performing jumps to these labels based on any of the following types of conditions:

  • Comparison between two register values

  • Comparison between a column value and a given constant

  • Whether or not a column value matches a given pattern

To define a label, use the def_label() method.

To perform an unconditional jump to a label, use the branch_label() method.

To perform a jump to a given label based on a comparison of register values, use one of the branch_*() methods (branch_ge(), branch_gt(), branch_le(), branch_lt(), branch_eq(), branch_ne(), branch_ne_null(), or branch_eq_null()). See Section 2.3.23.1.5, “Register-Based NdbInterpretedCode Branch Operations”.

To perform a jump to a given label based on a comparison of table column values, use one of the branch_col_*() methods (branch_col_ge(), branch_col_gt(), branch_col_le(), branch_col_lt(), branch_col_eq(), branch_col_ne(), branch_col_ne_null(), or branch_col_eq_null()). See Section 2.3.23.1.6, “Column-Based NdbInterpretedCode Branch Operations”.

To perform a jump based on pattern-matching of a table column value, use one of the methods branch_col_like() or branch_col_notlike(). See Section 2.3.23.1.7, “Pattern-Based NdbInterpretedCode Branch Operations”.

2.3.23.1.5 Register-Based NdbInterpretedCode Branch Operations

Most of these are used to branch based on the results of register-to-register comparisons. There are also two methods used to compare a register value with NULL. All of these methods require as a parameter a label defined using the def_label() method.

These methods can be thought of as performing the following logic:

if(register_value1 condition register_value2)
  goto Label

The space required by each of these methods is shown in the following table:

2.3.23.1.6 Column-Based NdbInterpretedCode Branch Operations

The methods described in this section are used to perform branching based on a comparison between a table column value and a given constant value. Each of these methods expects the attribute ID of the column whose value is to be tested rather than a reference to a Column object.

These methods, with the exception of branch_col_eq_null() and branch_col_ne_null(), can be thought of as performing the following logic:

if(constant_value condition column_value)
  goto Label

In each case (once again excepting branch_col_eq_null() and branch_col_ne_null()), the arbitrary constant is the first parameter passed to the method.

The space requirements for each of these methods is shown in the following table, where L represents the length of the constant value:

MethodBuffer (words)Request message (words)
branch_col_eq_null()22
branch_col_ne_null()22
branch_col_eq()22 + CEIL(L / 8)
branch_col_ne()22 + CEIL(L / 8)
branch_col_lt()22 + CEIL(L / 8)
branch_col_le()22 + CEIL(L / 8)
branch_col_gt()22 + CEIL(L / 8)
branch_col_ge()22 + CEIL(L / 8)
Note

The expression CEIL(L / 8) is the number of whole 8-byte words required to hold the constant value to be compared.

2.3.23.1.7 Pattern-Based NdbInterpretedCode Branch Operations

The NdbInterpretedCode class provides two methods which can be used to branch based on a comparison between a column containing character data (that is, a CHAR, VARCHAR, BINARY, or VARBINARY column) and a regular expression pattern.

The pattern syntax supported by the regular expression is the same as that supported by the MySQL Server's LIKE and NOT LIKE operators, including the _ and % metacharacters. For more information about these, see String Comparison Functions.

Note

This is the same regular expression pattern syntax that is supported by NdbScanFilter; see Section 2.3.27.2.3, “NdbScanFilter::cmp()”, for more information.

The table being operated upon must be supplied when the NdbInterpretedCode object is instantiated. The regular expression pattern should be in plain CHAR format, even if the column is actually a VARCHAR (in other words, there should be no leading length bytes).

These functions behave as shown here:

if (column_value [NOT] LIKE pattern)
  goto Label;

The space requirements for these methods are shown in the following table, where L represents the length of the constant value:

MethodBuffer (words)Request message (words)
branch_col_like()22 + CEIL(L / 8)
branch_col_notlike()22 + CEIL(L / 8)
Note

The expression CEIL(L / 8) is the number of whole 8-byte words required to hold the constant value to be compared.

2.3.23.1.8 NdbInterpretedCode Bitwise Comparison Operations

These instructions are available beginning with MySQL Cluster NDB 6.3.20. They are used to branch based on the result of a logical AND comparison between a BIT column value and a bitmask pattern.

Use of these methods requires that the table being operated upon was supplied when the NdbInterpretedCode object was constructed. The mask value should be the same size as the bit column being compared. BIT values are passed into and out of the NDB API as 32-bit words with bits set in order from the least significant bit to the most significant bit. The endianness of the platform on which the instructions are executed controls which byte contains the least significant bits. On x86, this is the first byte (byte 0); on SPARC and PPC, it is the last byte.

The buffer length and the request length for each of the methods listed here each requires an amount of space equal to 2 words plus the column width rounded (up) to the nearest whole word:

2.3.23.1.9 NdbInterpretedCode Result Handling Methods

The methods described in this section are used to tell the interpreter that processing of the current row is complete, and—in the case of scans—whether or not to include this row in the results of the scan.

The space requirements for these methods are shown in the following table, where L represents the length of the constant value:

MethodBuffer (words)Request message (words)
interpret_exit_ok()11
interpret_exit_nok()11
interpret_exit_last_row()11
2.3.23.1.10 NdbInterpretedCode Convenience Methods

The methods described in this section can be used to insert multiple instructions (using specific registers) into an interpreted program.

Important

In addition to updating the table column, these methods use interpreter registers 6 and 7, replacing any existing contents of register 6 with the original column value and any existing contents of register 7 with the modified column value. The table itself must be previously defined when instantiating the NdbInterpretedCode object for which the method is invoked.

The space requirements for these methods are shown in the following table, where L represents the length of the constant value:

MethodBuffer (words)Request message (words)
add_val()41; if the supplied value >= 216: 2; if >= 232: 3
sub_val()41; if the supplied value >= 216: 2; if >= 232: 3
2.3.23.1.11 Using Subroutines with NdbInterpretedCode

NdbInterpretedCode supports subroutines which can be invoked from within interpreted programs, with each subroutine being identified by a unique number. Subroutines can be defined only following all main program instructions.

Important

Numbers used to identify subroutines must be contiguous; however, they do not have to be in any particular order.

  • The beginning of a subroutine is indicated by invoking the def_sub() method;

  • ret_sub() terminates the subroutine; all instructions following the call to def_sub() belong to the subroutine until it is terminated using this method.

  • A subroutine is called using the call_sub() method.

Once the subroutine has completed, the program resumes execution with the instruction immediately following the one which invoked the subroutine. Subroutines can also be invoked from other subroutines; currently, the maximum subroutine stack depth is 32.

2.3.23.1.12 NdbInterpretedCode Utility Methods

Some additional utility methods supplied by NdbInterpretedCode are listed here: