Esempio n. 1
0
//creating index with non existing field
//It should fail
int main()
{

    Connection conn;
    DbRetVal rv = conn.open("root", "manager");
    if (rv != OK)
    {
       printf("Error during connection %d\n", rv);
       return -1;
    }
    DatabaseManager *dbMgr = conn.getDatabaseManager();
    if (dbMgr == NULL) { printf("Auth failed\n"); return -1;}
    TableDef tabDef;
    tabDef.addField("f1", typeInt, 0, NULL, true);
    tabDef.addField("f2", typeInt);
    rv = dbMgr->createTable("t1", tabDef);
    if (rv != OK) { printf("Table creation failed\n"); return -1; }
    printf("Table created\n");
    HashIndexInitInfo *idxInfo = new HashIndexInitInfo();
    strcpy(idxInfo->tableName, "t1");
    idxInfo->list.append("notexist");
    idxInfo->indType = hashIndex;
#ifdef TREEINDEX
    idxInfo->indType = treeIndex;
#elif defined TRIEINDEX
    idxInfo->indType = trieIndex;
#endif
    int ret =0;
    rv = dbMgr->createIndex("indx1", idxInfo);
    if (rv == OK) ret =1;
    delete idxInfo;
    dbMgr->dropTable("t1");
    conn.close();
    return ret;
}
Esempio n. 2
0
int main()
{

    Connection conn;
    DbRetVal rv = conn.open("root", "manager");
    if (rv != OK)
    {
       printf("Error during connection %d\n", rv);
       return -1;
    }
    DatabaseManager *dbMgr = conn.getDatabaseManager();
    if (dbMgr == NULL) { printf("Auth failed\n"); return -1;}
    TableDef tabDef;
    tabDef.addField("f1", typeInt, 0, NULL, true, true);
    tabDef.addField("f2", typeString, 12);
    rv = dbMgr->createTable("t1", tabDef);
    if (rv != OK) { printf("Table creation failed\n"); return -1; }
    HashIndexInitInfo *idxInfo = new HashIndexInitInfo();
    strcpy(idxInfo->tableName, "t1");
    idxInfo->list.append("f1");
    idxInfo->isPrimary = true;
    idxInfo->isUnique = true;
#ifdef HASH
    idxInfo->indType = hashIndex;
    rv = dbMgr->createIndex("indx1", idxInfo);
    if (rv != OK) { printf("Index creation failed\n"); return -1; }
#endif
#ifdef TREE
    idxInfo->indType = treeIndex;
    rv = dbMgr->createIndex("indx1", idxInfo);
    if (rv != OK) { printf("Index creation failed\n"); return -1; }
#endif
    delete idxInfo;
    pthread_t thr[THREADS];
    int message[THREADS];
    int status;
    for (int i=0; i <THREADS; i++) {
        message[i] = i;
        pthread_create (&thr[i], NULL,
                  &runInsTest, (void *) &message[i]);
    }
    for (int i=0; i <THREADS; i++) {
        pthread_join(thr[i], (void**)&status);
    }
    
    Table *table = dbMgr->openTable("t1");
    if (table == NULL) { printf("Unable to open table\n"); return -1; }
    table->setCondition(NULL);
    rv = conn.startTransaction();
    if (rv != OK) while (rv !=OK) rv = conn.startTransaction();
    table->execute();
    int count=0;
    void *tuple = NULL;
    while ((tuple = (char*) table->fetch())) {
         count++;
    }
    printf("Tuples found: %d\n", count);
    table->closeScan();
    conn.commit();

#ifdef HASH
    Condition p1;
    int valTerm = 0;
    p1.setTerm("f1", OpEquals, &valTerm);
    table->setCondition(&p1);
    int icount=0;
    for(int i = 0; i< THREADS * ITERATION; i++)
    {
        rv = conn.startTransaction();
        if (rv != OK) while (rv !=OK) rv = conn.startTransaction();
        valTerm = i+1;
        rv = table->execute();
        tuple = (char*)table->fetch() ;
        if (tuple == NULL)  break;
        icount++;
        table->closeScan();
        conn.commit();
        //if (i%ITERATION == 0) printf("%d\n", i);
    }
    printf("Index Tuples found: %d\n", icount);
#endif



    dbMgr->closeTable(table);

    for (int i=0; i <THREADS; i++) {
        message[i] = i;
        pthread_create (&thr[i], NULL,
                  &runSelTest, (void *) &message[i]);
    }
    for (int i=0; i <THREADS; i++) {
        pthread_join(thr[i], (void**)&status);
    }

    dbMgr->dropTable("t1");
    
    conn.close();
    return 0;
}
Esempio n. 3
0
int main()
{

    Connection conn;
    DbRetVal rv = conn.open("root", "manager");
    if (rv != OK)
    {
       printf("Error during connection %d\n", rv);
       return 1;
    }
    DatabaseManager *dbMgr = conn.getDatabaseManager();
    if (dbMgr == NULL) { printf("Auth failed\n"); return 2;}
    TableDef tabDef;
    tabDef.addField("f1", typeLongLong, 0, NULL, true);
    tabDef.addField("f2", typeString, 196);
    rv = dbMgr->createTable("t1", tabDef);
    if (rv != OK) { printf("Table creation failed\n"); return 3; }
    printf("Table created\n");
#ifdef WITHINDEX
    HashIndexInitInfo *idxInfo = new HashIndexInitInfo();
    strcpy(idxInfo->tableName, "t1");
    idxInfo->list.append("f1");
    idxInfo->indType = hashIndex;
    idxInfo->isUnique = true;
    idxInfo->isPrimary = true;
    rv = dbMgr->createIndex("indx1", idxInfo);
    if (rv != OK) { printf("Index creation failed\n"); return -1; }
    printf("Index created\n");
    delete idxInfo;
#endif
#ifdef WITHTREEINDEX
    HashIndexInitInfo *idxInfo = new HashIndexInitInfo();
    strcpy(idxInfo->tableName, "t1");
    idxInfo->list.append("f1");
    idxInfo->indType = treeIndex;
    rv = dbMgr->createIndex("indx1", idxInfo);
    if (rv != OK) { printf("Index creation failed\n"); return -1; }
    printf("Index created\n");
    delete idxInfo;
#endif
#ifdef WITHTRIEINDEX
    HashIndexInitInfo *idxInfo = new HashIndexInitInfo();
    strcpy(idxInfo->tableName, "t1");
    idxInfo->list.append("f1");
    idxInfo->indType = trieIndex;
    rv = dbMgr->createIndex("indx1", idxInfo);
    if (rv != OK) { printf("Index creation failed\n"); return -1; }
    printf("Index created\n");
    delete idxInfo;
#endif


    Table *table = dbMgr->openTable("t1");
    if (table == NULL) { printf("Unable to open table\n"); return 4; }
    table->bindFld("f1", &id);
    table->bindFld("f2", name);
    char *tuple;
    int ret;
    long long i;
    rv =conn.startTransaction();
    for(i = 0; i< 5; i++)
    {
        if (rv != OK) exit(5);
        id= i;
        strcpy(name, "PRABAKARAN0123456750590");
        ret = table->insertTuple();
        if (ret != 0) break;
    }
    conn.commit();

    conn.startTransaction();
    select(table, OpEquals);
    conn.commit();

    conn.startTransaction();
    select(table, OpNotEquals);
    conn.commit();

    conn.startTransaction();
    select(table, OpLessThan);
    conn.commit();

    conn.startTransaction();
    select( table, OpLessThanEquals);
    conn.commit();

    conn.startTransaction();
    select( table, OpGreaterThan);
    conn.commit();

    conn.startTransaction();
    select( table, OpGreaterThanEquals);
    conn.commit();

    dbMgr->closeTable(table);
    dbMgr->dropTable("t1");

    conn.close();
    return 0;
}
Esempio n. 4
0
int main()
{

    Connection conn;
    DbRetVal rv = conn.open("root", "manager");
    if (rv != OK)
    {
       printf("Error during connection %d\n", rv);
       return -1;
    }
    DatabaseManager *dbMgr = conn.getDatabaseManager();
    if (dbMgr == NULL) { printf("Auth failed\n"); return -1;}
    TableDef tabDef;
    tabDef.addField("f1", typeInt, 0, NULL, true);
    tabDef.addField("f2", typeString, 50);
    rv = dbMgr->createTable("t1", tabDef);
    if (rv != OK) { printf("Table creation failed\n"); return -1; }
    printf("Table created\n");
    HashIndexInitInfo *idxInfo = new HashIndexInitInfo();
    strcpy(idxInfo->tableName, "t1");
    idxInfo->list.append("f1");
    idxInfo->indType = hashIndex;
#ifdef F1TREE
    idxInfo->indType = treeIndex;
#endif
#ifdef F2TRIE
    idxInfo->indType = trieIndex;
#endif
    rv = dbMgr->createIndex("indx1", idxInfo);
    if (rv != OK) { printf("Index creation failed\n"); return -1; }
    printf("Index created for f1\n");
    printf("size of index field list %d\n", idxInfo->list.size());
    idxInfo->list.remove("f1");
    printf("size of index field list %d\n", idxInfo->list.size());
    idxInfo->list.append("f2");
    printf("size of index field list %d\n", idxInfo->list.size());
    idxInfo->indType = hashIndex;
#ifdef F2TREE
    idxInfo->indType = treeIndex;
#endif
#ifdef F2TRIE
    idxInfo->indType = trieIndex;
#endif
    rv = dbMgr->createIndex("indx2", idxInfo);
    if (rv != OK) { printf("Index creation failed\n"); return -1; }
    printf("Index created for f2\n");
    delete idxInfo;
    Table *table = dbMgr->openTable("t1");
    if (table == NULL) { printf("Unable to open table\n"); return -1; }
    int id1 = 0;
    char id2[50] ="Aruna";
    table->bindFld("f1", &id1);
    table->bindFld("f2", id2);
    char *tuple;
    int ret;
    int i;
    int icount =0;
    rv = conn.startTransaction();
    if (rv != OK) exit(1);
    for(i = 0; i< 10; i++)
    {
        id1= i;
        sprintf(id2, "Aruna:%d", i);
        ret = table->insertTuple();
        if (ret != 0) break;
        icount++;
    }
    conn.commit();
    printf("Total tuples inserted: %d\n", icount);
    Condition p1, p2;
    int val1 = 0;
    char val2[50];
    p1.setTerm("f1", OpEquals, &val1);
    p2.setTerm("f2", OpEquals, &val2);
    table->setCondition(&p1);
    rv =conn.startTransaction();
    if (rv != OK) exit(1);
    for(i = 0; i< 10; i++)
    {    
        val1 = i;
        table->execute();
        tuple = (char*)table->fetch() ;
        if (tuple == NULL) {printf("loop break in %d\n", i);table->closeScan();break;}
        printf("I:tuple value is %d %s \n", id1, id2);
        table->closeScan();
    }

    table->setCondition(&p2);
    for(i = 0; i< 10; i++)
    {    
        sprintf(val2, "Aruna:%d", i);
        table->execute();
        tuple = (char*)table->fetch() ;
        if (tuple == NULL) {printf("loop break in %d\n", i);table->closeScan();break;}
        printf("II:tuple value is %d %s \n", id1, id2);
        table->closeScan();
    }
    conn.commit();

    rv =conn.startTransaction();
    if (rv != OK) exit(1);
    table->setCondition(&p1);
    val1 = 1;
    table->execute();
    tuple = (char*)table->fetch() ;
    if (tuple != NULL) {
        table->deleteTuple();
    }
    table->closeScan();
    table->setCondition(&p2);
    sprintf(val2, "Aruna:%d", 2);
    table->execute();
    tuple = (char*)table->fetch() ;
    if (tuple != NULL) {
        table->deleteTuple();
    }
    table->closeScan();
    conn.commit();

    int count =0;
    rv = conn.startTransaction();
    table->setCondition(NULL);
    if (rv != OK) exit (1);
    table->execute();
    while((tuple = (char*)table->fetch())!= NULL) {
        printf("tuple value is %d %s \n", id1, id2);
        count++;
    }
    table->closeScan();
    conn.commit();
    printf("Total rows selected %d\n", count);
    dbMgr->closeTable(table);
    dbMgr->dropTable("t1");

    conn.close();
    return 0;
}
Esempio n. 5
0
int main()
{

    Connection conn;
    DbRetVal rv = conn.open("root", "manager");
    if (rv != OK)
    {
       printf("Error during connection %d\n", rv);
       return -1;
    }


    DatabaseManager *dbMgr = conn.getDatabaseManager();
    if (dbMgr == NULL) { printf("Auth failed\n"); return -1;}
    TableDef tabDef;
    tabDef.addField("f1", typeInt, 0, NULL, true );
    tabDef.addField("f2", typeString, 196);
    rv = dbMgr->createTable("t1", tabDef);
    if (rv != OK) { printf("Table creation failed\n"); return -1; }
    printf("Table created\n");
    HashIndexInitInfo *idxInfo = new HashIndexInitInfo();
    strcpy(idxInfo->tableName, "t1");
    idxInfo->list.append("f1");
    idxInfo->indType = hashIndex;
    if (LOAD >0 )
       idxInfo->bucketSize = 100007;
    else
       idxInfo->bucketSize = 10007;
    rv = dbMgr->createIndex("indx1", idxInfo);
    if (rv != OK) { printf("Index creation failed\n"); return -1; }
    printf("Index created\n");
    delete idxInfo;
    Table *table = dbMgr->openTable("t1");
    if (table == NULL) { printf("Unable to open table\n"); return -1; }
    int id = 0;
    char name[196] = "PRABAKARAN";
    table->bindFld("f1", &id);
    table->bindFld("f2", name);
    char *tuple;
    int ret;
    int i;
    int icount =0;
    if (LOAD > 0) {
      TableImpl *impl = (TableImpl*)table;
      impl->setUndoLogging(false);
      strcpy(name, "PRABAKARAN0123456750590");
      rv = conn.startTransaction();
      if (rv != OK) exit(1);
      for(i = 0; i< LOAD; i++)
      {
        id= i;
        ret = table->insertTuple();
        if (ret != 0) break;
        icount++;
        if (i % 100 == 0 ) { rv = conn.commit(); 
                             if (rv != OK) exit(1);
                             rv = conn.startTransaction(); 
                             if (rv != OK) exit(1);
                           }
        if (i %50000 == 0) printf("%d rows inserted\n", i);
      }
      conn.commit();
      impl->setUndoLogging(true);
      printf("Loaded %d records\n", icount);
    }
   
      //TableImpl *impl = (TableImpl*)table;
      //impl->setUndoLogging(false);
    i = 0; 
    NanoTimer timer;
    icount =0;
    for(i = LOAD; i< LOAD+ITERATIONS; i++)
    {
        timer.start();
        rv = conn.startTransaction();
        if (rv != OK) exit(1);
        id= i;
        strcpy(name, "PRABAKARAN0123456750590");
        ret = table->insertTuple();
        if (ret != 0) break;
    //    printf("%d\n ", i);
        icount++;
        conn.commit();
        timer.stop();
    }
   printf("%d rows inserted %lld %lld %lld\n",icount, timer.minc(), timer.maxc(), timer.avg());

    int offset1= os::align(sizeof(int));
    Condition p1;
    int val1 = 0;
    p1.setTerm("f1", OpEquals, &val1);
    table->setCondition(&p1);
    icount=0;
   

    timer.reset();
    for(i = LOAD; i< LOAD+ITERATIONS; i++)
    {    
        timer.start();
        rv =conn.startTransaction();
        if (rv != OK) exit(1);
        val1 = i;
        table->execute();
        tuple = (char*)table->fetch() ;
        if (tuple == NULL) {printf("loop break in %d\n", i);table->closeScan();break;}
  //      printf(" %d tuple value is %d %s \n", i, *((int*)tuple), tuple+offset1);
        table->closeScan();
        icount++;
        conn.commit();
        timer.stop();
    }
    printf("%d rows selected %lld %lld %lld\n", icount, timer.minc(), timer.maxc(), timer.avg());
    timer.reset();

    for(i = LOAD; i< LOAD+ITERATIONS; i++)
    {
        timer.start();
        rv  = conn.startTransaction();
        if (rv != OK) exit (1);
        val1 = i;
        table->execute();
        tuple = (char*)table->fetch() ;
        if (tuple == NULL) {printf("loop break in %d\n", i);table->closeScan();break;}
        strcpy(name, "PRABAKARAN0950576543210");
        table->updateTuple();
        table->closeScan();
        conn.commit();
        timer.stop();
    }
    printf("%d rows updated %lld %lld %lld\n", i- LOAD, timer.minc(), timer.maxc(), timer.avg());


    icount=0;
    for(i = LOAD; i< LOAD+ITERATIONS; i++)
    {
        timer.start();
        rv = conn.startTransaction();
        if (rv != OK) exit (1);
        val1 = i;
        table->execute();
        tuple = (char*)table->fetch() ;
        if (tuple == NULL) {printf("No record for %d\n", i);table->closeScan();break;}
        table->deleteTuple();
        icount++;
        table->closeScan();
        conn.commit();
        timer.stop();
    }
    printf("%d rows deleted %lld %lld %lld\n", icount, timer.minc(), timer.maxc(), timer.avg());


    dbMgr->closeTable(table);
    dbMgr->dropTable("t1");
    printf("Table dropped\n");

    conn.close();
    return 0;
}