windows client library changes
[csql.git] / test / performance / DMLThroughput.c
blobc7f4b5b5a2bd7ea1e015c7d6ae91399213401c5e
1 #include<CSql.h>
2 #include<NanoTimer.h>
3 #include<TableImpl.h>
4 //MAX_SYS_DB_SIZE=10485760
5 //MAX_DB_SIZE=335544320
6 //you may have to set the kernel.shmmaxc kernel paremeter(login as root) using
7 //$sysctl -w kernel.shmmaxc=1000000000
8 #define LOAD 0
9 int main()
12 Connection conn;
13 DbRetVal rv = conn.open("root", "manager");
14 if (rv != OK)
16 printf("Error during connection %d\n", rv);
17 return -1;
21 DatabaseManager *dbMgr = conn.getDatabaseManager();
22 if (dbMgr == NULL) { printf("Auth failed\n"); return -1;}
23 TableDef tabDef;
24 tabDef.addField("f1", typeInt, 0, NULL, true );
25 tabDef.addField("f2", typeString, 6);
26 rv = dbMgr->createTable("t1", tabDef);
27 if (rv != OK) { printf("Table creation failed\n"); return -1; }
28 printf("Table created\n");
29 HashIndexInitInfo *idxInfo = new HashIndexInitInfo();
30 strcpy(idxInfo->tableName, "t1");
31 idxInfo->list.append("f1");
32 idxInfo->indType = hashIndex;
33 idxInfo->bucketSize = 100007;
34 rv = dbMgr->createIndex("indx1", idxInfo);
35 if (rv != OK) { printf("Index creation failed\n"); return -1; }
36 printf("Index created\n");
37 delete idxInfo;
38 Table *table = dbMgr->openTable("t1");
39 if (table == NULL) { printf("Unable to open table\n"); return -1; }
40 int id = 0;
41 char name[6] = "PRABA";
42 table->bindFld("f1", &id);
43 table->bindFld("f2", name);
44 char *tuple;
45 int ret;
46 int i;
47 int icount =0;
48 i = 0;
49 NanoTimer timer;
50 icount =0;
51 for(i = 0; i < 20; i++)
53 timer.start();
54 for (int j =0; j < 100000; j++)
56 rv = conn.startTransaction();
57 //if (rv != OK) exit(1);
58 if (rv != OK) {
59 dbMgr->closeTable(table);
60 dbMgr->dropTable("t1");
61 conn.close();
62 return 1;
64 id= i*100000+j;
65 strcpy(name, "KARAN");
66 ret = table->insertTuple();
67 if (ret != 0) break;
68 icount++;
69 conn.commit();
71 timer.stop();
72 printf("Insert: %d %lld\n", icount, timer.last());
74 printf("%d rows inserted %lld %lld %lld\n",icount, timer.minc(), timer.maxc(), timer.avg());
76 int offset1= os::align(sizeof(int));
77 Condition p1;
78 int val1 = 0;
79 p1.setTerm("f1", OpEquals, &val1);
80 table->setCondition(&p1);
81 icount=0;
84 timer.reset();
85 for(i = 0; i< 20; i++)
87 timer.start();
88 for (int j=0 ; j <100000; j++)
90 rv =conn.startTransaction();
91 if (rv != OK) exit(1);
92 val1 = i *100000 + j;
93 table->execute();
94 tuple = (char*)table->fetch() ;
95 if (tuple == NULL) {printf("loop break in %d\n", i);table->closeScan();break;}
96 // printf(" %d tuple value is %d %s \n", i, *((int*)tuple), tuple+offset1);
97 table->closeScan();
98 icount++;
99 conn.commit();
101 timer.stop();
102 printf("Select: %d %lld\n", icount, timer.last());
104 printf("%d rows selected %lld %lld %lld\n", icount, timer.minc(), timer.maxc(), timer.avg());
105 timer.reset();
107 dbMgr->closeTable(table);
108 dbMgr->dropTable("t1");
109 printf("Table dropped\n");
112 conn.close();
113 return 0;