code reorg
[csql.git] / test / performance / DMLTest.c
blob4454c4633a18900a98d90b54a834dcaf16654e50
1 #include<CSql.h>
2 #include<NanoTimer.h>
3 #include<TableImpl.h>
4 #define ITERATIONS 100
5 //#define LOAD 1000000
6 //Note: Set following parameters in csql.conf for this test
7 //MAX_SYS_DB_SIZE=10485760
8 //MAX_DB_SIZE=335544320
9 //you may have to set the kernel.shmmaxc kernel paremeter(login as root) using
10 //$sysctl -w kernel.shmmaxc=1000000000
11 #define LOAD 0
12 int main()
15 Connection conn;
16 DbRetVal rv = conn.open("root", "manager");
17 if (rv != OK)
19 printf("Error during connection %d\n", rv);
20 return -1;
24 DatabaseManager *dbMgr = conn.getDatabaseManager();
25 if (dbMgr == NULL) { printf("Auth failed\n"); return -1;}
26 TableDef tabDef;
27 tabDef.addField("f1", typeInt, 0, NULL, true );
28 tabDef.addField("f2", typeString, 196);
29 rv = dbMgr->createTable("t1", tabDef);
30 if (rv != OK) { printf("Table creation failed\n"); return -1; }
31 printf("Table created\n");
32 HashIndexInitInfo *idxInfo = new HashIndexInitInfo();
33 strcpy(idxInfo->tableName, "t1");
34 idxInfo->list.append("f1");
35 idxInfo->indType = hashIndex;
36 if (LOAD >0 )
37 idxInfo->bucketSize = 100007;
38 else
39 idxInfo->bucketSize = 10007;
40 rv = dbMgr->createIndex("indx1", idxInfo);
41 if (rv != OK) { printf("Index creation failed\n"); return -1; }
42 printf("Index created\n");
43 delete idxInfo;
44 Table *table = dbMgr->openTable("t1");
45 if (table == NULL) { printf("Unable to open table\n"); return -1; }
46 int id = 0;
47 char name[196] = "PRABAKARAN";
48 table->bindFld("f1", &id);
49 table->bindFld("f2", name);
50 char *tuple;
51 int ret;
52 int i;
53 int icount =0;
54 if (LOAD > 0) {
55 TableImpl *impl = (TableImpl*)table;
56 impl->setUndoLogging(false);
57 strcpy(name, "PRABAKARAN0123456750590");
58 rv = conn.startTransaction();
59 if (rv != OK) exit(1);
60 for(i = 0; i< LOAD; i++)
62 id= i;
63 ret = table->insertTuple();
64 if (ret != 0) break;
65 icount++;
66 if (i % 100 == 0 ) { rv = conn.commit();
67 if (rv != OK) exit(1);
68 rv = conn.startTransaction();
69 if (rv != OK) exit(1);
71 if (i %50000 == 0) printf("%d rows inserted\n", i);
73 conn.commit();
74 impl->setUndoLogging(true);
75 printf("Loaded %d records\n", icount);
78 //TableImpl *impl = (TableImpl*)table;
79 //impl->setUndoLogging(false);
80 i = 0;
81 NanoTimer timer;
82 icount =0;
83 for(i = LOAD; i< LOAD+ITERATIONS; i++)
85 timer.start();
86 rv = conn.startTransaction();
87 if (rv != OK) exit(1);
88 id= i;
89 strcpy(name, "PRABAKARAN0123456750590");
90 ret = table->insertTuple();
91 if (ret != 0) break;
92 // printf("%d\n ", i);
93 icount++;
94 conn.commit();
95 timer.stop();
97 printf("%d rows inserted %lld %lld %lld\n",icount, timer.minc(), timer.maxc(), timer.avg());
99 int offset1= os::align(sizeof(int));
100 Condition p1;
101 int val1 = 0;
102 p1.setTerm("f1", OpEquals, &val1);
103 table->setCondition(&p1);
104 icount=0;
107 timer.reset();
108 for(i = LOAD; i< LOAD+ITERATIONS; i++)
110 timer.start();
111 rv =conn.startTransaction();
112 if (rv != OK) exit(1);
113 val1 = i;
114 table->execute();
115 tuple = (char*)table->fetch() ;
116 if (tuple == NULL) {printf("loop break in %d\n", i);table->closeScan();break;}
117 // printf(" %d tuple value is %d %s \n", i, *((int*)tuple), tuple+offset1);
118 table->closeScan();
119 icount++;
120 conn.commit();
121 timer.stop();
123 printf("%d rows selected %lld %lld %lld\n", icount, timer.minc(), timer.maxc(), timer.avg());
124 timer.reset();
126 for(i = LOAD; i< LOAD+ITERATIONS; i++)
128 timer.start();
129 rv = conn.startTransaction();
130 if (rv != OK) exit (1);
131 val1 = i;
132 table->execute();
133 tuple = (char*)table->fetch() ;
134 if (tuple == NULL) {printf("loop break in %d\n", i);table->closeScan();break;}
135 strcpy(name, "PRABAKARAN0950576543210");
136 table->updateTuple();
137 table->closeScan();
138 conn.commit();
139 timer.stop();
141 printf("%d rows updated %lld %lld %lld\n", i- LOAD, timer.minc(), timer.maxc(), timer.avg());
144 icount=0;
145 for(i = LOAD; i< LOAD+ITERATIONS; i++)
147 timer.start();
148 rv = conn.startTransaction();
149 if (rv != OK) exit (1);
150 val1 = i;
151 table->execute();
152 tuple = (char*)table->fetch() ;
153 if (tuple == NULL) {printf("No record for %d\n", i);table->closeScan();break;}
154 table->deleteTuple();
155 icount++;
156 table->closeScan();
157 conn.commit();
158 timer.stop();
160 printf("%d rows deleted %lld %lld %lld\n", icount, timer.minc(), timer.maxc(), timer.avg());
163 dbMgr->closeTable(table);
164 dbMgr->dropTable("t1");
165 printf("Table dropped\n");
167 conn.close();
168 return 0;