Hi,
I am using ndpapi NdbIndexScanOperation to read data by index.
The application requires data to be sorted by the primary key.
the readTuples() method defines flags for sorting: order_by & order_desc or can use scan_flags
What I am missing here is by which column the sort is performed?
inline int readTuples(LockMode lock_mode,
Uint32 batch,
Uint32 parallel,
bool order_by,
bool order_desc = false,
bool read_range_no = false,
bool keyinfo = false,
bool multi_range = false) {
Uint32 scan_flags =
(SF_OrderBy & -(Int32)order_by) |
(SF_Descending & -(Int32)order_desc) |
(SF_ReadRangeNo & -(Int32)read_range_no) |
(SF_KeyInfo & -(Int32)keyinfo) |
(SF_MultiRange & -(Int32)multi_range);
our table layout:
CREATE TABLE `Bearer_Info` (
`IP` int(11) NOT NULL,
`IP_Index` int(11) NOT NULL,
`Bearer_Info_Index` int(11) NOT NULL,
`Bearer_Identifier` varchar(60) DEFAULT NULL,
`Bearer_Type` int(11) DEFAULT NULL,
`Charging_Rule_Sent_State` int(11) DEFAULT NULL,
`QoS_Info_Sent_State` int(11) DEFAULT NULL,
`Charging_Rule_Name` varchar(60) DEFAULT NULL,
`Charging_Rule_Name_0` varchar(60) DEFAULT NULL,
`QoS_Upgrade` int(11) DEFAULT NULL,
`QoS_Negotiation` int(11) DEFAULT NULL,
`QoS_Class_Identifier` int(11) DEFAULT NULL,
`Received_Max_Requested_Bandwidth_UL` int(11) DEFAULT NULL,
`Received_Max_Requested_Bandwidth_DL` int(11) DEFAULT NULL,
`Received_Guaranteed_Bitrate_UL` int(11) DEFAULT NULL,
`Received_Guaranteed_Bitrate_DL` int(11) DEFAULT NULL,
`Authorized_Max_Requested_Bandwidth_UL` int(11) DEFAULT NULL,
`Authorized_Max_Requested_Bandwidth_DL` int(11) DEFAULT NULL,
`Authorized_Guaranteed_Bitrate_UL` int(11) DEFAULT NULL,
`Authorized_Guaranteed_Bitrate_DL` int(11) DEFAULT NULL,
PRIMARY KEY (`IP`,`IP_Index`,`Bearer_Info_Index`),
KEY `Bearer_Info_INDX` (`IP`)
) ENGINE=ndbcluster DEFAULT CHARSET=ascii
/*!50100 PARTITION BY KEY (IP)
for each IP we have two entries.
My code performs the fetch operation on IP column (the index)
we perform four scan operations yielding four result sets:
When printing the rows, I can see that for the three first result sets, the rows are ordered ascending by the primary key, but the fourth is order descending. flag was set to ascending order.
Printing Row: [ 156303371 | 0 | 0 | 100 | 1 | Default PCC Rule Name | First Primary Rule | 1 | 1 | 8 | 8640000 | 32000000 | 384000 | 384000 | 111000 | 222000 | 333000 | 444000 | ]
Printing Row: [ 156303371 | 0 | 1 | 200 | 2 | Default PCC Rule Name | Default PCC Rule Name | 1 | 1 | 8 | 8640000 | 32000000 | 384000 | 384000 | 555000 | 666000 | 777000 | 888000 | ]
Printing Row: [ 156303372 | 0 | 0 | 100 | 1 | Default PCC Rule Name | First Primary Rule | 1 | 1 | 8 | 8640000 | 32000000 | 384000 | 384000 | 111000 | 222000 | 333000 | 444000 | ]
Printing Row: [ 156303372 | 0 | 1 | 200 | 2 | Default PCC Rule Name | Default PCC Rule Name | 1 | 1 | 8 | 8640000 | 32000000 | 384000 | 384000 | 555000 | 666000 | 777000 | 888000 | ]
Printing Row: [ 156303374 | 0 | 0 | 100 | 1 | Default PCC Rule Name | First Primary Rule | 1 | 1 | 8 | 8640000 | 32000000 | 384000 | 384000 | 111000 | 222000 | 333000 | 444000 | ]
Printing Row: [ 156303374 | 0 | 1 | 200 | 2 | Default PCC Rule Name | Default PCC Rule Name | 1 | 1 | 8 | 8640000 | 32000000 | 384000 | 384000 | 555000 | 666000 | 777000 | 888000 | ]
Printing Row: [ 156303375 | 0 | 1 | 200 | 2 | Default PCC Rule Name | Default PCC Rule Name | 1 | 1 | 8 | 8640000 | 32000000 | 384000 | 384000 | 555000 | 666000 | 777000 | 888000 | ]
Printing Row: [ 156303375 | 0 | 0 | 100 | 1 | Default PCC Rule Name | First Primary Rule | 1 | 1 | 8 | 8640000 | 32000000 | 384000 | 384000 | 111000 | 222000 | 333000 | 444000 | ]
When I changing the flag in the readTuples call to order the rows descending, the first three rows are ordered descending and the fourth row is ordered ascending.
I might be doing something wrong here, but first of all, I would like to know how the ordering is done? and if there is any way to define by which column the order will be done.
Thanks, Oded.
I am using ndpapi NdbIndexScanOperation to read data by index.
The application requires data to be sorted by the primary key.
the readTuples() method defines flags for sorting: order_by & order_desc or can use scan_flags
What I am missing here is by which column the sort is performed?
inline int readTuples(LockMode lock_mode,
Uint32 batch,
Uint32 parallel,
bool order_by,
bool order_desc = false,
bool read_range_no = false,
bool keyinfo = false,
bool multi_range = false) {
Uint32 scan_flags =
(SF_OrderBy & -(Int32)order_by) |
(SF_Descending & -(Int32)order_desc) |
(SF_ReadRangeNo & -(Int32)read_range_no) |
(SF_KeyInfo & -(Int32)keyinfo) |
(SF_MultiRange & -(Int32)multi_range);
our table layout:
CREATE TABLE `Bearer_Info` (
`IP` int(11) NOT NULL,
`IP_Index` int(11) NOT NULL,
`Bearer_Info_Index` int(11) NOT NULL,
`Bearer_Identifier` varchar(60) DEFAULT NULL,
`Bearer_Type` int(11) DEFAULT NULL,
`Charging_Rule_Sent_State` int(11) DEFAULT NULL,
`QoS_Info_Sent_State` int(11) DEFAULT NULL,
`Charging_Rule_Name` varchar(60) DEFAULT NULL,
`Charging_Rule_Name_0` varchar(60) DEFAULT NULL,
`QoS_Upgrade` int(11) DEFAULT NULL,
`QoS_Negotiation` int(11) DEFAULT NULL,
`QoS_Class_Identifier` int(11) DEFAULT NULL,
`Received_Max_Requested_Bandwidth_UL` int(11) DEFAULT NULL,
`Received_Max_Requested_Bandwidth_DL` int(11) DEFAULT NULL,
`Received_Guaranteed_Bitrate_UL` int(11) DEFAULT NULL,
`Received_Guaranteed_Bitrate_DL` int(11) DEFAULT NULL,
`Authorized_Max_Requested_Bandwidth_UL` int(11) DEFAULT NULL,
`Authorized_Max_Requested_Bandwidth_DL` int(11) DEFAULT NULL,
`Authorized_Guaranteed_Bitrate_UL` int(11) DEFAULT NULL,
`Authorized_Guaranteed_Bitrate_DL` int(11) DEFAULT NULL,
PRIMARY KEY (`IP`,`IP_Index`,`Bearer_Info_Index`),
KEY `Bearer_Info_INDX` (`IP`)
) ENGINE=ndbcluster DEFAULT CHARSET=ascii
/*!50100 PARTITION BY KEY (IP)
for each IP we have two entries.
My code performs the fetch operation on IP column (the index)
we perform four scan operations yielding four result sets:
When printing the rows, I can see that for the three first result sets, the rows are ordered ascending by the primary key, but the fourth is order descending. flag was set to ascending order.
Printing Row: [ 156303371 | 0 | 0 | 100 | 1 | Default PCC Rule Name | First Primary Rule | 1 | 1 | 8 | 8640000 | 32000000 | 384000 | 384000 | 111000 | 222000 | 333000 | 444000 | ]
Printing Row: [ 156303371 | 0 | 1 | 200 | 2 | Default PCC Rule Name | Default PCC Rule Name | 1 | 1 | 8 | 8640000 | 32000000 | 384000 | 384000 | 555000 | 666000 | 777000 | 888000 | ]
Printing Row: [ 156303372 | 0 | 0 | 100 | 1 | Default PCC Rule Name | First Primary Rule | 1 | 1 | 8 | 8640000 | 32000000 | 384000 | 384000 | 111000 | 222000 | 333000 | 444000 | ]
Printing Row: [ 156303372 | 0 | 1 | 200 | 2 | Default PCC Rule Name | Default PCC Rule Name | 1 | 1 | 8 | 8640000 | 32000000 | 384000 | 384000 | 555000 | 666000 | 777000 | 888000 | ]
Printing Row: [ 156303374 | 0 | 0 | 100 | 1 | Default PCC Rule Name | First Primary Rule | 1 | 1 | 8 | 8640000 | 32000000 | 384000 | 384000 | 111000 | 222000 | 333000 | 444000 | ]
Printing Row: [ 156303374 | 0 | 1 | 200 | 2 | Default PCC Rule Name | Default PCC Rule Name | 1 | 1 | 8 | 8640000 | 32000000 | 384000 | 384000 | 555000 | 666000 | 777000 | 888000 | ]
Printing Row: [ 156303375 | 0 | 1 | 200 | 2 | Default PCC Rule Name | Default PCC Rule Name | 1 | 1 | 8 | 8640000 | 32000000 | 384000 | 384000 | 555000 | 666000 | 777000 | 888000 | ]
Printing Row: [ 156303375 | 0 | 0 | 100 | 1 | Default PCC Rule Name | First Primary Rule | 1 | 1 | 8 | 8640000 | 32000000 | 384000 | 384000 | 111000 | 222000 | 333000 | 444000 | ]
When I changing the flag in the readTuples call to order the rows descending, the first three rows are ordered descending and the fourth row is ordered ascending.
I might be doing something wrong here, but first of all, I would like to know how the ordering is done? and if there is any way to define by which column the order will be done.
Thanks, Oded.