using tree index
[csql.git] / test / performance / Range.c
blob569b46728bdac83731bf2dae60643f9150c3d689
1 #include<CSql.h>
2 #include<NanoTimer.h>
3 int main()
6 Connection conn;
7 DbRetVal rv = conn.open("root", "manager");
8 if (rv != OK)
10 printf("Error during connection %d\n", rv);
11 return -1;
13 DatabaseManager *dbMgr = conn.getDatabaseManager();
14 if (dbMgr == NULL) { printf("Auth failed\n"); return -1;}
15 TableDef tabDef;
16 tabDef.addField("f1", typeInt, 0, NULL, true);
17 tabDef.addField("f2", typeString, 196);
18 rv = dbMgr->createTable("t1", tabDef);
19 if (rv != OK) { printf("Table creation failed\n"); return -1; }
20 printf("Table created\n");
21 HashIndexInitInfo *idxInfo = new HashIndexInitInfo();
22 strcpy(idxInfo->tableName, "t1");
23 idxInfo->list.append("f1");
24 idxInfo->indType = treeIndex;
25 rv = dbMgr->createIndex("indx1", idxInfo);
26 if (rv != OK) { printf("Index creation failed\n"); return -1; }
27 printf("Index created\n");
28 Table *table = dbMgr->openTable("t1");
29 if (table == NULL) { printf("Unable to open table\n"); return -1; }
30 int id = 0;
31 char name[196] = "PRABAKARAN";
32 table->bindFld("f1", &id);
33 table->bindFld("f2", name);
34 char *tuple;
35 int ret;
36 int i;
37 int icount =0;
38 NanoTimer timer;
39 for(i = 0; i< 1000; i++)
41 timer.start();
42 rv = conn.startTransaction();
43 if (rv != OK) exit(1);
44 id= i;
45 strcpy(name, "PRABAKARAN0123456750590");
46 //printf("%d\n ", i);
47 ret = table->insertTuple();
48 if (ret != 0) break;
49 icount++;
50 conn.commit();
51 timer.stop();
53 char msgBuf[1024];
54 sprintf(msgBuf,"Total rows inserted %d %lld %lld %lld\n",icount, timer.min(), timer.max(), timer.avg());
55 os::write(1,msgBuf,strlen(msgBuf));
57 int offset1= os::align(sizeof(int));
58 Condition p1;
59 int val1 = 0;
60 p1.setTerm("f1", OpGreaterThan, &val1);
61 table->setCondition(&p1);
62 icount=0;
63 timer.reset();
64 val1 = 899;
65 for(i = 0; i< 100; i++)
67 int cnt = 0;
68 timer.start();
69 rv =conn.startTransaction();
70 if (rv != OK) exit(1);
71 table->execute();
72 while ((tuple = (char*)table->fetch()) != NULL) {
73 //printf("tuple value is %d %s \n", *((int*)tuple), tuple+offset1);
74 cnt++;
76 if (cnt != 100) printf("Error in fetching %d\n", cnt);
77 icount++;
78 conn.commit();
79 table->close();
80 timer.stop();
82 sprintf(msgBuf,"%d rows selected %lld %lld %lld\n", icount, timer.min(), timer.max(), timer.avg());
83 os::write(1,msgBuf,strlen(msgBuf));
84 timer.reset();
85 dbMgr->closeTable(table);
86 dbMgr->dropTable("t1");
88 conn.close();
89 return 0;