Re: NDB API:: use B-TREE index issue
Posted by:
liu huil
Date: September 15, 2015 12:48AM
Hi
thank for your reply. I can create the indexs, but can not use this index query record by ndb api.
mysql> select version();
+------------------------------+
| version() |
+------------------------------+
| 5.6.24-ndb-7.4.6-cluster-gpl |
+------------------------------+
1 row in set (0.11 sec)
create table:
mysql> CREATE TABLE TEST(
ID VARCHAR(100) NOT NULL,
NUM VARCHAR(20) NOT NULL,
CALLED_NUM VARCHAR(20) NOT NULL,
PRIMARY KEY (ID, NUM)
)ENGINE NDB PARTITION BY key(NUM);
create index:
CREATE INDEX IDX_CALLED_NUM ON TEST(CALLED_NUM);
error msg:
clunm:3
name:ID, StorageType:0, type:15,getPartSize:0,getInlineSize:0
name:NUM, StorageType:0, type:15,getPartSize:0,getInlineSize:0
name:CALLED_NUM, StorageType:0, type:15,getPartSize:0,getInlineSize:0
clunm:2
name:ID
name:NUM
indexCount:2
index name:PRIMARY
index name:IDX_CALLED_NUM
Error in use_index.cpp, line: 187, code: 4003, msg: Function not implemented yet.
test code:
//g++ -g -I/usr/local/mysql/include/ -I/usr/local/mysql/include/storage/ndb/ndbapi/ -I/usr/local/mysql/include/storage/ndb/ -L/usr/local/mysql/lib/ -lmysqlclient_r -lndbclient use_index.cpp -o use_index.out
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/time.h>
#include <mysqld_error.h>
#include <NdbApi.hpp>
#include <iostream>
#include <NdbDictionary.hpp>
#define PRINT_ERROR(code,msg) \
std::cout << "Error in " << __FILE__ << ", line: " << __LINE__ \
<< ", code: " << code \
<< ", msg: " << msg << "." << std::endl
#define APIERROR(error) { \
PRINT_ERROR(error.code,error.message); \
return -1; }
Ndb_cluster_connection *g_cluster_connection = NULL;
Ndb *g_myNdb = NULL;
const NdbDictionary::Index *g_CsSessionPrimary = NULL;
const NdbDictionary::Table *g_myCsSessionTable = NULL;
//NdbDictionary::Table *g_myCsSessionTable = NULL;
// 删除数据
int deleteByParam(char *session_id, char *calling_num, struct timeval *begin, struct timeval *end);
// 打印数据库服务器信息
void printMySqlInfo();
int usage(){return 0;};
void make_ndb_varchar(char *buffer, char *str, int len)
{
int hlen = (len > 255) ? 2 : 1;
buffer[0] = len % 256;
if( len > 255 )
buffer[1] = (len / 256);
memcpy(buffer+hlen, str, len);
}
//初始化sql
int inisql();
int dropsql();
int main(int argc, char * const argv[])
{
ndb_init();
/* inisql();
exit(0);
*/
int ch, addflag=0, selflag = 0, delflag = 0, sleeptime = 1000, num = 10000, record_size = 512, pid = 0, del_flag = 0;
unsigned int port = 3306 ;
char *connectIp, *szkey = NULL, *number =NULL;
struct timeval begin, end;
printf("connect:%s, port:%u, sleeptime:%d, record_size:%d, num:%d\n", connectIp, port, sleeptime, record_size, num);
//printMySqlInfo();
if(inisql() != 0)
{
return 0;
}
if(g_myNdb != NULL)
delete g_myNdb;
if( g_cluster_connection != NULL)
delete g_cluster_connection;
ndb_end(0);
return 0;
}
int inisql()
{
g_cluster_connection = new Ndb_cluster_connection("192.168.0.103:1186"); // Object representing the cluster
if (g_cluster_connection->connect(5,3,1))
{
std::cout << "Connect to cluster management server failed.\n";
std::cout << g_cluster_connection->get_latest_error_msg() <<"\n";
return -1;
}
if (g_cluster_connection->wait_until_ready(30,30))
{
std::cout << "Cluster was not ready within 30 secs.\n";
std::cout << g_cluster_connection->get_latest_error_msg() <<"\n";
return -1;
}
g_myNdb = new Ndb( g_cluster_connection,
"ocs_ps" ); // Object representing the database
if (g_myNdb->init(1024) == -1) {
APIERROR(g_myNdb->getNdbError());
}
//const NdbDictionary::Dictionary* myDict= g_myNdb->getDictionary();
NdbDictionary::Dictionary* myDict= g_myNdb->getDictionary();
g_myCsSessionTable= myDict->getTable("TEST");
if (g_myCsSessionTable == NULL)
APIERROR(myDict->getNdbError());
//NdbDictionary::Column *tmpBlob = g_myCsSessionTable->getColumn("DATA_BODY");
int clunm = g_myCsSessionTable->getNoOfColumns();
printf("clunm:%d\n", clunm);
for(int i = 0; i < clunm; i++)
{
const NdbDictionary::Column *tmp = g_myCsSessionTable->getColumn(i);
if(tmp == NULL)
APIERROR(myDict->getNdbError());
printf("name:%s, StorageType:%d, type:%d,getPartSize:%d,getInlineSize:%d\n", tmp->getName(), tmp->getStorageType(), tmp->getType(), tmp->getPartSize(), tmp->getInlineSize());
}
clunm = g_myCsSessionTable->getNoOfPrimaryKeys();
printf("clunm:%d\n", clunm);
for(int i = 0; i < clunm; i++)
{
printf("name:%s\n", g_myCsSessionTable->getPrimaryKey(i));
}
NdbDictionary::Dictionary::List indexList;
if(myDict->listIndexes(indexList, "TEST") != 0)
{
APIERROR(myDict->getNdbError());
}
printf("indexCount:%d\n", indexList.count);
for(int i = 0; i < indexList.count; i++)
{
NdbDictionary::Dictionary::List::Element item = indexList.elements;
printf("index name:%s\n", item.name);
}
const NdbDictionary::Index *myIndex= myDict->getIndex("IDX_CALLED_NUM","TEST");
if (myIndex == NULL)
APIERROR(myDict->getNdbError());
NdbTransaction *myTransaction= g_myNdb->startTransaction();
if (myTransaction == NULL) APIERROR(g_myNdb->getNdbError());
NdbIndexOperation *myIndexOperation=
myTransaction->getNdbIndexOperation(myIndex);
if (myIndexOperation == NULL) APIERROR(myTransaction->getNdbError());
return 0;
}