64 bit build fix
[csql.git] / test / performance / wisc / odbcBench.c
blob10b3e3a041a9f59fa042d467397cfba0c8494f75
2 #include <iostream>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include <time.h>
7 #include <sql.h>
8 #include <sqlext.h>
9 #include "NanoTimer.h"
10 #define ITERATION 100
11 using namespace std;
12 bool mysql;
14 NanoTimer timer;
15 long long int timevalues[30][3]={0};
16 void extract_error(
17 char *fn,
18 SQLHANDLE handle,
19 SQLSMALLINT type)
21 SQLINTEGER i = 0;
22 SQLINTEGER native;
23 SQLCHAR state[ 7 ];
24 SQLCHAR text[256];
25 SQLSMALLINT len;
26 SQLRETURN ret;
28 fprintf(stderr,
29 "\n"
30 "The driver reported the following diagnostics whilst running "
31 "%s\n\n",
32 fn);
36 ret = SQLGetDiagRec(type, handle, ++i, state, &native, text,
37 sizeof(text), &len );
38 if (SQL_SUCCEEDED(ret))
39 printf("%s:%ld:%ld:%s\n", state, i, native, text);
41 while( ret == SQL_SUCCESS );
44 inline void
45 check_error (SQLSMALLINT handleType, SQLHANDLE handle, int rc, int line)
47 if (rc)
49 cout << "Error " << rc << " at line: " << line << endl;
50 SQLCHAR state[10];
51 SQLINTEGER native;
52 SQLCHAR mesg[300];
53 int i=0;
54 while (SQLGetDiagRec (handleType, handle, i++, state, &native, mesg, 300,
55 NULL) == SQL_SUCCESS)
57 mesg[299] = '\0';
58 cout << "state: " << state << endl;
59 cout << "native: " << native << endl;
60 cout << "mesg: " << mesg << endl;
62 exit (1);
67 inline void checkrc (int rc, int line)
69 if (rc)
71 cout << "Error " << rc << " at line: " << line << endl;
72 exit (1);
76 void readWriteTrans (SQLHDBC hdbc)
78 int rc = SQLSetConnectAttr (hdbc, SQL_ATTR_ACCESS_MODE,
79 (SQLPOINTER) SQL_MODE_READ_WRITE, 0);
80 checkrc (rc, __LINE__);
81 rc = SQLEndTran (SQL_HANDLE_DBC, hdbc, SQL_COMMIT);
82 checkrc (rc, __LINE__);
85 void readOnlyTrans (SQLHDBC hdbc)
87 int rc = SQLSetConnectAttr (hdbc, SQL_ATTR_ACCESS_MODE,
88 (SQLPOINTER) SQL_MODE_READ_ONLY, 0);
89 checkrc (rc, __LINE__);
90 rc = SQLEndTran (SQL_HANDLE_DBC, hdbc, SQL_COMMIT);
91 checkrc (rc, __LINE__);
94 void createHashIndex(SQLHANDLE hstmt,bool flag)
96 int rc;
97 if (mysql) {
98 rc = SQLExecDirect(hstmt, (SQLCHAR*) "CREATE INDEX idx1 USING HASH ON big1(unique1);", SQL_NTS );
99 checkrc (rc, __LINE__);
100 rc = SQLExecDirect(hstmt, (SQLCHAR*) "CREATE INDEX idx2 USING HASH ON big2(unique1);", SQL_NTS );
101 checkrc (rc, __LINE__);
102 rc = SQLExecDirect(hstmt, (SQLCHAR*) "CREATE INDEX idx3 USING HASH ON small(unique1)", SQL_NTS );
103 checkrc (rc, __LINE__);
104 rc = SQLExecDirect(hstmt, (SQLCHAR*) "CREATE INDEX idx4 USING HASH ON big1(stringu1)", SQL_NTS );
105 checkrc (rc, __LINE__);
106 } else {
107 rc = SQLExecDirect(hstmt, (SQLCHAR*) "CREATE INDEX idx1 ON big1(unique1) HASH;", SQL_NTS );
108 checkrc (rc, __LINE__);
109 rc = SQLExecDirect(hstmt, (SQLCHAR*) "CREATE INDEX idx2 ON big2(unique1) HASH;", SQL_NTS );
110 checkrc (rc, __LINE__);
111 rc = SQLExecDirect(hstmt, (SQLCHAR*) "CREATE INDEX idx3 ON small(unique1) HASH", SQL_NTS );
112 checkrc (rc, __LINE__);
113 rc = SQLExecDirect(hstmt, (SQLCHAR*) "CREATE INDEX idx4 ON big1(stringu1) HASH", SQL_NTS );
114 checkrc (rc, __LINE__);
117 void createTreeIndex(SQLHANDLE hstmt,bool flag)
119 int rc;
120 if (mysql)
122 rc = SQLExecDirect(hstmt, (SQLCHAR*) "CREATE INDEX idx5 USING BTREE ON big1(unique1);", SQL_NTS );
123 checkrc (rc, __LINE__);
124 rc = SQLExecDirect(hstmt, (SQLCHAR*) "CREATE INDEX idx6 USING BTREE ON big2(unique1);", SQL_NTS );
125 checkrc (rc, __LINE__);
126 rc = SQLExecDirect(hstmt, (SQLCHAR*) "CREATE INDEX idx7 USING BTREE ON small(unique1);", SQL_NTS );
127 checkrc (rc, __LINE__);
128 rc = SQLExecDirect(hstmt, (SQLCHAR*) "CREATE INDEX idx8 USING BTREE ON big1(stringu1);", SQL_NTS );
129 checkrc (rc, __LINE__);
130 }else {
131 rc = SQLExecDirect(hstmt, (SQLCHAR*) "CREATE INDEX idx5 ON big1(unique1) TREE;", SQL_NTS );
132 checkrc (rc, __LINE__);
133 rc = SQLExecDirect(hstmt, (SQLCHAR*) "CREATE INDEX idx6 ON big2(unique1) TREE;", SQL_NTS );
134 checkrc (rc, __LINE__);
135 rc = SQLExecDirect(hstmt, (SQLCHAR*) "CREATE INDEX idx7 ON small(unique1) TREE;", SQL_NTS );
136 checkrc (rc, __LINE__);
137 rc = SQLExecDirect(hstmt, (SQLCHAR*) "CREATE INDEX idx8 ON big1(stringu1) TREE;", SQL_NTS );
138 checkrc (rc, __LINE__);
142 void dropHashIndex(SQLHANDLE hstmt,bool flag)
144 int rc;
145 if (mysql) {
146 rc = SQLExecDirect(hstmt, (SQLCHAR*) "DROP INDEX idx1 on big1 ;", SQL_NTS );
147 checkrc (rc, __LINE__);
148 rc = SQLExecDirect(hstmt, (SQLCHAR*) "DROP INDEX idx2 on big2;", SQL_NTS );
149 checkrc (rc, __LINE__);
150 rc = SQLExecDirect(hstmt, (SQLCHAR*) "DROP INDEX idx3 on small", SQL_NTS );
151 checkrc (rc, __LINE__);
152 rc = SQLExecDirect(hstmt, (SQLCHAR*) "DROP INDEX idx4 on big1;", SQL_NTS );
153 checkrc (rc, __LINE__);
154 } else {
155 rc = SQLExecDirect(hstmt, (SQLCHAR*) "DROP INDEX idx1 ;", SQL_NTS );
156 checkrc (rc, __LINE__);
157 rc = SQLExecDirect(hstmt, (SQLCHAR*) "DROP INDEX idx2 ;", SQL_NTS );
158 checkrc (rc, __LINE__);
159 rc = SQLExecDirect(hstmt, (SQLCHAR*) "DROP INDEX idx3 ;", SQL_NTS );
160 checkrc (rc, __LINE__);
161 rc = SQLExecDirect(hstmt, (SQLCHAR*) "DROP INDEX idx4 ;", SQL_NTS );
162 checkrc (rc, __LINE__);
165 void dropTreeIndex(SQLHANDLE hstmt,bool flag)
167 int rc;
168 if (mysql)
170 rc = SQLExecDirect(hstmt, (SQLCHAR*) "DROP INDEX idx5 on big1 ;", SQL_NTS );
171 checkrc (rc, __LINE__);
172 rc = SQLExecDirect(hstmt, (SQLCHAR*) "DROP INDEX idx6 on big2;", SQL_NTS );
173 checkrc (rc, __LINE__);
174 rc = SQLExecDirect(hstmt, (SQLCHAR*) "DROP INDEX idx7 on small;", SQL_NTS );
175 checkrc (rc, __LINE__);
176 rc = SQLExecDirect(hstmt, (SQLCHAR*) "DROP INDEX idx8 on big1;", SQL_NTS );
177 checkrc (rc, __LINE__);
178 }else {
179 rc = SQLExecDirect(hstmt, (SQLCHAR*) "DROP INDEX idx5 ;", SQL_NTS );
180 checkrc (rc, __LINE__);
181 rc = SQLExecDirect(hstmt, (SQLCHAR*) "DROP INDEX idx6 ;", SQL_NTS );
182 checkrc (rc, __LINE__);
183 rc = SQLExecDirect(hstmt, (SQLCHAR*) "DROP INDEX idx7 ;", SQL_NTS );
184 checkrc (rc, __LINE__);
185 rc = SQLExecDirect(hstmt, (SQLCHAR*) "DROP INDEX idx8 ;", SQL_NTS );
186 checkrc (rc, __LINE__);
191 long long int onePerSel(SQLHANDLE henv, SQLHANDLE hdbc, SQLHANDLE hstmt)
193 int uni1;
194 int uni2;
195 char str1[52];
196 char str2[52];
197 int val[] = {1, 5, 10, 50, 100, 500, 1000, 5000 ,7500, 9500};
198 int tempTermVar=0;
199 int tempTermVar2=0;
200 char tempval[124]="Value";
201 int rc;
202 readOnlyTrans (hdbc);
203 rc = SQLPrepare (hstmt, (unsigned char *) "SELECT unique1, unique2, stringu1 from big1 where unique1 between ? and ?;", SQL_NTS);
204 checkrc (rc, __LINE__);
205 rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &tempTermVar, 0, NULL);
206 checkrc (rc, __LINE__);
207 rc = SQLBindParameter (hstmt, 2, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &tempTermVar2, 0, NULL);
208 checkrc (rc, __LINE__);
210 rc = SQLBindCol (hstmt, 1, SQL_INTEGER, &uni1, 0, NULL);
211 checkrc (rc, __LINE__);
212 rc = SQLBindCol (hstmt, 2, SQL_INTEGER, &uni2, 0, NULL);
213 checkrc (rc, __LINE__);
214 rc = SQLBindCol (hstmt, 3, SQL_C_CHAR, str1, sizeof (str1), NULL);
215 checkrc (rc, __LINE__);
217 int i, j, k;
218 int Count;
220 timer.reset ();
222 for (i = 0; i < 10; i++)
224 Count=0;
225 strcpy(tempval,"Value");
226 tempTermVar = val[i] ;
227 tempTermVar2 = val[i]+99 ;
228 timer.start ();
229 rc = SQLExecute (hstmt);
230 checkrc (rc, __LINE__);
231 while(SQL_SUCCEEDED(rc = SQLFetch(hstmt)))
233 Count++;
235 // printf("Count=%d\n",Count);
236 rc = SQLCloseCursor (hstmt);
237 checkrc (rc, __LINE__);
238 rc = SQLTransact (henv, hdbc, SQL_COMMIT);
239 checkrc (rc, __LINE__);
240 timer.stop ();
241 if (Count != 100) {
242 printf("One % Selection returned %d rows", Count);
243 readWriteTrans (hdbc);
244 return 0;
247 readWriteTrans (hdbc);
248 //printf ("Read: 1 %lld\n", timer.avg ());
249 return timer.avg()/1000;
252 long long int runReadTest (SQLHANDLE henv, SQLHANDLE hdbc,SQLHANDLE hstmt,bool flag)
254 int uni1;
255 int uni2;
256 char str1[52];
257 char str2[52];
259 int val[] = {1, 10, 100, 500, 1000, 5000 ,7500, 8000, 9000, 9999};
260 int tempTermVar=0;
261 char tempval[52]="Value";
262 int rc;
264 /* Set read-only transaction type */
265 readOnlyTrans (hdbc);
266 if(flag){
267 rc = SQLPrepare (hstmt, (unsigned char *) "SELECT unique1, unique2, stringu1, stringu2 from big1 where unique1=?;", SQL_NTS);
269 else {
270 rc = SQLPrepare (hstmt, (unsigned char *) "SELECT unique1, unique2, stringu1, stringu2 from big1 where stringu1=?;", SQL_NTS);
272 checkrc (rc, __LINE__);
273 long sz = 0;
274 if(flag){
275 rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &tempTermVar, 0, NULL);
276 checkrc (rc, __LINE__);
278 else{
279 rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_C_CHAR, 196, 0, tempval, 0, NULL);
280 checkrc (rc, __LINE__);
283 rc = SQLBindCol (hstmt, 1, SQL_INTEGER, &uni1, 0, NULL);
284 checkrc (rc, __LINE__);
285 rc = SQLBindCol (hstmt, 2, SQL_INTEGER, &uni2, 0, NULL);
286 checkrc (rc, __LINE__);
287 rc = SQLBindCol (hstmt, 3, SQL_C_CHAR, str1, sizeof (str1), NULL);
288 checkrc (rc, __LINE__);
289 rc = SQLBindCol (hstmt, 4, SQL_C_CHAR, str2, sizeof (str2), NULL);
290 checkrc (rc, __LINE__);
292 int i, j, k;
293 int Count;
295 timer.reset ();
296 char buf[10]="Value";
298 /* Run 1per Test */
299 for (i = 0; i < 10; i++)
301 if(flag){
302 tempTermVar = val[i] ;}
303 else{
304 sprintf(tempval,"%s%d",buf, val[i]);
306 timer.start ();
307 rc = SQLExecute (hstmt);
308 checkrc (rc, __LINE__);
309 rc = SQLFetch (hstmt);
310 checkrc (rc, __LINE__);
311 Count++;
312 rc = SQLCloseCursor (hstmt);
313 checkrc (rc, __LINE__);
314 rc = SQLTransact (henv, hdbc, SQL_COMMIT);
315 checkrc (rc, __LINE__);
316 timer.stop ();
318 //printf ("Read: 1 %lld\n", timer.avg ());
319 /* Set read-write transaction type */
320 readWriteTrans (hdbc);
321 return timer.avg()/1000;
324 //DISTINCT
325 long long int distinct(SQLHANDLE henv, SQLHANDLE hdbc,SQLHANDLE hstmt)
327 int var_onepercent;
328 int rc;
330 readOnlyTrans (hdbc);
331 rc = SQLPrepare (hstmt, (unsigned char *) "SELECT DISTINCT onepercent FROM big1;", SQL_NTS);
332 checkrc (rc, __LINE__);
334 rc = SQLBindCol (hstmt, 1, SQL_INTEGER, &var_onepercent, 0, NULL);
335 checkrc (rc, __LINE__);
337 int i,count;
338 timer.reset ();
340 for (i = 0; i < 10; i++)
342 count=0;
343 timer.start ();
344 rc = SQLExecute (hstmt);
345 checkrc (rc, __LINE__);
346 while(SQL_SUCCEEDED(rc = SQLFetch(hstmt))){
347 count++;
349 //checkrc (rc, __LINE__);
350 rc = SQLCloseCursor (hstmt);
351 checkrc (rc, __LINE__);
352 rc = SQLTransact (henv, hdbc, SQL_COMMIT);
353 checkrc (rc, __LINE__);
354 timer.stop ();
355 if (count != 100) {
356 printf("distinct returned %d rows\n");
357 readWriteTrans(hdbc);
358 return 0;
361 readWriteTrans(hdbc);
362 return timer.avg()/1000;
364 long long int orderBy(SQLHANDLE henv, SQLHANDLE hdbc,SQLHANDLE hstmt)
366 int val[] = {1, 5, 10, 50, 100, 500, 1000, 5000 ,7500, 9500};
367 int var_two, var_four, var_ten, var_twenty, var_onepercent;
368 char str1[52];
369 int tempTermVar=0, tempTermVar2=0, tempTermVar3=0;
370 int rc;
372 rc = SQLPrepare (hstmt, (unsigned char *) "SELECT two, four, ten, twenty, onepercent, string4 from big1 where unique1 between ? and ? order by unique1;", SQL_NTS);
373 checkrc (rc, __LINE__);
375 readOnlyTrans (hdbc);
376 rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &tempTermVar, 0, NULL);
377 checkrc (rc, __LINE__);
378 rc = SQLBindParameter (hstmt, 2, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &tempTermVar2, 0, NULL);
379 checkrc (rc, __LINE__);
382 rc = SQLBindCol (hstmt, 1, SQL_INTEGER, &var_two, 0, NULL);
383 checkrc (rc, __LINE__);
385 rc = SQLBindCol (hstmt, 2, SQL_INTEGER, &var_four, 0, NULL);
386 checkrc (rc, __LINE__);
388 rc = SQLBindCol (hstmt, 3, SQL_INTEGER, &var_ten, 0, NULL);
389 checkrc (rc, __LINE__);
391 rc = SQLBindCol (hstmt, 4, SQL_INTEGER, &var_twenty, 0, NULL);
392 checkrc (rc, __LINE__);
394 rc = SQLBindCol (hstmt, 5, SQL_INTEGER, &var_onepercent, 0, NULL);
395 checkrc (rc, __LINE__);
397 rc = SQLBindCol (hstmt, 6, SQL_C_CHAR, str1, sizeof (str1), NULL);
398 checkrc (rc, __LINE__);
401 int i, j, k;
402 int count;
404 timer.reset ();
406 for (i = 0; i < 10; i++)
408 count=0;
409 tempTermVar=val[i];
410 tempTermVar2 = val[i]+100 ;
411 timer.start ();
412 rc = SQLExecute (hstmt);
413 checkrc (rc, __LINE__);
414 rc = SQLFetch (hstmt);
415 while(SQL_SUCCEEDED(rc = SQLFetch(hstmt))) count++;
416 //checkrc (rc, __LINE__);
417 rc = SQLCloseCursor (hstmt);
418 checkrc (rc, __LINE__);
419 rc = SQLTransact (henv, hdbc, SQL_COMMIT);
420 checkrc (rc, __LINE__);
421 timer.stop ();
422 if (count != 100) {
423 printf("orderby returned %d rows \n", count);
424 readWriteTrans(hdbc);
425 return 0;
428 readWriteTrans(hdbc);
429 return timer.avg()/1000;
433 //aggregate
434 long long int aggregate(SQLHANDLE henv, SQLHANDLE hdbc,SQLHANDLE hstmt,int val,bool flag)
436 int summinmax=0,tempTermVar=0;
437 int rc;
438 /* Set read-only transaction type */
439 readOnlyTrans (hdbc);
440 if(val==1 && flag){
441 rc = SQLPrepare (hstmt, (unsigned char *) "SELECT MIN(unique1) from big1;", SQL_NTS);
443 else if(val==1 && !flag)
445 rc = SQLPrepare (hstmt, (unsigned char *) "SELECT MIN(unique1) from big1 group by onepercent;", SQL_NTS);
448 else if(val==2 && flag) {
449 rc = SQLPrepare (hstmt, (unsigned char *) "SELECT MAX(unique1) from big1;", SQL_NTS);
451 else if(val==2 && !flag){
452 rc = SQLPrepare (hstmt, (unsigned char *) "SELECT MAX(unique1) from big1 group by onepercent;", SQL_NTS);
454 else if(val==3 && flag) {
455 rc = SQLPrepare (hstmt, (unsigned char *) "SELECT SUM(unique1) from big1;", SQL_NTS);
457 else if(val==3 && !flag){
458 rc = SQLPrepare (hstmt, (unsigned char *) "SELECT SUM(unique1) from big1 group by onepercent;", SQL_NTS);
460 checkrc (rc, __LINE__);
462 rc = SQLBindCol (hstmt, 1, SQL_INTEGER, &summinmax, 0, NULL);
463 checkrc (rc, __LINE__);
465 int i, j, k;
466 int Count;
468 timer.reset ();
469 for (i = 0; i < 10; i++)
471 timer.start ();
472 rc = SQLExecute (hstmt);
473 checkrc (rc, __LINE__);
474 rc = SQLFetch (hstmt);
475 checkrc (rc, __LINE__);
476 Count++;
477 // printf("value=%d",summin);
478 rc = SQLCloseCursor (hstmt);
479 checkrc (rc, __LINE__);
480 rc = SQLTransact (henv, hdbc, SQL_COMMIT);
481 checkrc (rc, __LINE__);
482 timer.stop ();
484 //printf ("Read: 1 %lld\n", timer.avg ());
485 /* Set read-write transaction type */
486 readWriteTrans (hdbc);
487 return timer.avg()/1000;
491 long long int dmlstatement(SQLHANDLE henv, SQLHANDLE hdbc,SQLHANDLE hstmt,int val)
493 int tempTermVar=10000,tempTermVar2=10000;
494 int rc;
495 /* Set read-only transaction type */
496 readOnlyTrans (hdbc);
497 if(val==1){
498 rc = SQLPrepare (hstmt, (unsigned char *) "insert into big1 values(?,?,0,2,0,10,50,688,1950,4950,9950,1,100,'MXXXXXXXXXXXXXXXXXXXXXXXXXGXXXXXXXXXXXXXXXXXXXXXXXXC','GXXXXXXXXXXXXXXXXXXXXXXXXXCXXXXXXXXXXXXXXXXXXXXXXXXA','OXXXXXXXXXXXXXXXXXXXXXXXXXOXXXXXXXXXXXXXXXXXXXXXXXXO');", SQL_NTS);
500 else if(val==2){
501 rc = SQLPrepare (hstmt, (unsigned char *) "UPDATE big1 SET two=1 WHERE unique1=?;", SQL_NTS);
502 }else
504 rc = SQLPrepare (hstmt, (unsigned char *) "DELETE FROM big1 WHERE unique1=?;", SQL_NTS);
506 checkrc (rc, __LINE__);
508 int i, j, k;
509 int Count;
511 timer.reset ();
512 for (i = 0; i < 100; i++)
513 { tempTermVar+=i;
514 rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &tempTermVar, 0, NULL);
515 checkrc (rc, __LINE__);
516 if(val==1)
518 tempTermVar2+=i;
519 rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &tempTermVar2, 0, NULL);
520 checkrc (rc, __LINE__);
522 timer.start ();
523 rc = SQLExecute (hstmt);
524 checkrc (rc, __LINE__);
525 rc = SQLTransact (henv, hdbc, SQL_COMMIT);
526 checkrc (rc, __LINE__);
527 timer.stop ();
528 tempTermVar=10000;tempTermVar2=10000;
530 //printf ("Read: 1 %lld\n", timer.avg ());
531 /* Set read-write transaction type */
532 readWriteTrans (hdbc);
533 return timer.avg()/1000;
537 //Joining
538 long long int joining(SQLHANDLE henv, SQLHANDLE hdbc, SQLHANDLE hstmt,int value)
540 int uni1;
541 int uni2,uni3,uni4,uni5;
542 char str1[52];
543 char str2[52];
545 int val[10] = {1, 5, 10, 50, 100, 250, 500, 750, 900, 999};
546 int tempTermVar=0;
547 char tempval[124]="Value";
548 int rc;
550 /* Set read-only transaction type */
551 readOnlyTrans (hdbc);
552 if(value==1 ){
553 rc = SQLPrepare (hstmt, (unsigned char *) "SELECT big1.unique1, big1.unique2, small.unique1, small.stringu1 FROM big1,small WHERE big1.unique1=small.unique1 AND big1.unique1=?;", SQL_NTS);
556 else {
557 rc = SQLPrepare (hstmt, (unsigned char *) "SELECT small.unique1, big1.unique1, big2.unique1, small.stringu1, big1.unique2, big2.unique2 FROM big1, big2, small WHERE small.unique1=big1.unique2 AND big1.unique2=big2.unique1 AND big1.unique1 = ?;", SQL_NTS);
560 checkrc (rc, __LINE__);
561 long sz = 0;
564 rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &tempTermVar, 0, NULL);
565 checkrc (rc, __LINE__);
567 rc = SQLBindCol (hstmt, 1, SQL_C_LONG, &uni1, 0, NULL);
568 checkrc (rc, __LINE__);
569 rc = SQLBindCol (hstmt, 2, SQL_C_LONG, &uni2, 0, NULL);
570 checkrc (rc, __LINE__);
571 rc = SQLBindCol (hstmt, 3, SQL_C_LONG, &uni3, 0, NULL);
572 checkrc (rc, __LINE__);
573 rc = SQLBindCol (hstmt, 4, SQL_C_CHAR, str1, sizeof (str1), NULL);
574 checkrc (rc, __LINE__);
575 if(value==2 ){
576 rc = SQLBindCol (hstmt, 5, SQL_C_LONG, &uni4, 0, NULL);
577 checkrc (rc, __LINE__);
578 rc = SQLBindCol (hstmt, 6, SQL_C_LONG, &uni5, 0, NULL);
579 checkrc (rc, __LINE__);
581 int i, j, k;
582 int Count=0;
584 timer.reset ();
586 for (i = 0; i < 10; i++)
588 tempTermVar = val[i];
589 timer.start ();
590 rc = SQLExecute (hstmt);
591 checkrc (rc, __LINE__);
592 rc=SQLFetch(hstmt);
593 Count++;
594 rc = SQLCloseCursor (hstmt);
595 checkrc (rc, __LINE__);
596 rc = SQLTransact (henv, hdbc, SQL_COMMIT);
597 checkrc (rc, __LINE__);
598 timer.stop ();
599 // printf("uni1=%d uni2=%d uni3=%d str1=%s \n",uni1,uni2,uni3,str1);
601 readWriteTrans (hdbc);
602 return timer.avg()/1000;
604 //JOINCondition
606 long long int joinCondition(SQLHANDLE henv, SQLHANDLE hdbc, SQLHANDLE hstmt,int value)
608 int uni1;
609 int uni2,uni3,uni4,uni5;
610 char str1[52];
611 char str2[52];
612 int rc;
613 int searchVal[] = {1, 5, 10, 50, 100, 200, 250, 500, 750, 800};
615 //Set read-only transaction type
616 readOnlyTrans (hdbc);
617 if(value==1 )
619 rc = SQLPrepare (hstmt, (unsigned char *) "SELECT big1.unique1, big1.unique2, small.unique1, small.stringu1 FROM big1,small WHERE big1.unique1=small.unique1 AND big1.unique1 > ? and big1.unique1 <= ?;", SQL_NTS);
622 else {
623 rc = SQLPrepare (hstmt, (unsigned char *) "SELECT small.unique1, big1.unique1, big2.unique1, small.stringu1, big1.unique2, big2.unique2 FROM big1, big2, small WHERE big1.unique1=small.unique1 AND big1.unique1=big2.unique1 AND big1.unique1 > ? and big1.unique1 <= ?;", SQL_NTS);
626 checkrc (rc, __LINE__);
627 int tempTermVar1 =0, tempTermVar2=0;
629 rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &tempTermVar1, 0, NULL);
630 checkrc (rc, __LINE__);
631 rc = SQLBindParameter (hstmt, 2, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &tempTermVar2, 0, NULL);
632 checkrc (rc, __LINE__);
634 long sz = 0;
635 rc = SQLBindCol (hstmt, 1, SQL_C_SLONG, &uni1, 0, NULL);
636 checkrc (rc, __LINE__);
637 rc = SQLBindCol (hstmt, 2, SQL_C_SLONG, &uni2, 0, NULL);
638 checkrc (rc, __LINE__);
639 rc = SQLBindCol (hstmt, 3, SQL_C_SLONG, &uni3, 0, NULL);
640 checkrc (rc, __LINE__);
641 rc = SQLBindCol (hstmt, 4, SQL_C_CHAR, str1, sizeof (str1), NULL);
642 checkrc (rc, __LINE__);
643 if(value==2){
644 rc = SQLBindCol (hstmt, 5, SQL_C_SLONG, &uni4, 0, NULL);
645 checkrc (rc, __LINE__);
646 rc = SQLBindCol (hstmt, 6, SQL_C_SLONG, &uni5, 0, NULL);
647 checkrc (rc, __LINE__);
649 int i, j, k;
650 int count=0;
652 timer.reset ();
653 for(i=0;i<10;i++){
654 count=0;
655 tempTermVar1 = searchVal[i];
656 tempTermVar2 = searchVal[i]+100;
657 timer.start ();
658 rc = SQLExecute (hstmt);
659 checkrc (rc, __LINE__);
660 while(SQL_SUCCEEDED(rc = SQLFetch(hstmt)))
662 count++;
663 //printf("Uni1:%d uni2=%d uni3=%d \n",uni1,uni2,uni3);
665 rc = SQLCloseCursor (hstmt);
666 checkrc (rc, __LINE__);
667 rc = SQLTransact (henv, hdbc, SQL_COMMIT);
668 checkrc (rc, __LINE__);
669 timer.stop ();
670 if (count != 100) {
671 printf ("range join returned %d rows\n", count);
672 readWriteTrans (hdbc);
673 return 0;
676 readWriteTrans (hdbc);
677 return timer.avg()/1000;
681 void printTime()
683 printf("Wisconsin Benchmark Report:\n");
684 printf("*******************************************************\n");
685 printf(" Statement \tNoIndex\tHash\tTree\n");
686 printf("*******************************************************\n");
687 printf(" SelectInt 1 \t%lld\t%lld\t%lld\n",timevalues[0][0],timevalues[0][1],timevalues[0][2]);
688 printf(" SelectStr 1 \t%lld\t%lld\t%lld\n",timevalues[1][0],timevalues[1][1],timevalues[1][2]);
689 printf(" 1Per Sel \t%lld\t%lld\t%lld\n",timevalues[2][0],timevalues[2][1],timevalues[2][2]);
690 printf(" Min All \t%lld\t%lld\t%lld\n",timevalues[3][0],timevalues[3][1],timevalues[3][2]);
691 printf(" Min GrBy 1% \t%lld\t%lld\t%lld\n",timevalues[4][0],timevalues[4][1],timevalues[4][2]);
692 printf(" Max All \t%lld\t%lld\t%lld\n",timevalues[5][0],timevalues[5][1],timevalues[5][2]);
693 printf(" Max GrBy 1 \t%lld\t%lld\t%lld\n",timevalues[6][0],timevalues[6][1],timevalues[6][2]);
694 printf(" Sum All \t%lld\t%lld\t%lld\n",timevalues[7][0],timevalues[7][1],timevalues[7][2]);
695 printf(" Sum GrBy 1% \t%lld\t%lld\t%lld\n",timevalues[8][0],timevalues[8][1],timevalues[8][2]);
696 printf(" Distinct 1% \t%lld\t%lld\t%lld\n",timevalues[9][0],timevalues[9][1],timevalues[9][2]);
697 printf(" Order By 1% \t%lld\t%lld\t%lld\n",timevalues[10][0],timevalues[10][1],timevalues[10][2]);
698 printf(" Insert 1 \t%lld\t%lld\t%lld\n",timevalues[11][0],timevalues[11][1],timevalues[11][2]);
699 printf(" Update 1 \t%lld\t%lld\t%lld\n",timevalues[12][0],timevalues[12][1],timevalues[12][2]);
700 printf(" Delete 1 \t%lld\t%lld\t%lld\n",timevalues[13][0],timevalues[13][1],timevalues[13][2]);
701 printf(" Join(10K*1K)1 \t%lld\t%lld\t%lld\n",timevalues[14][0],timevalues[14][1],timevalues[14][2]);
702 printf(" Join(10K*10K*1K) \t%lld\t%lld\t%lld\n",timevalues[15][0],timevalues[15][1],timevalues[15][2]);
703 printf(" Join(10K*1K)100 \t%lld\t%lld\t%lld\n",timevalues[16][0],timevalues[16][1],timevalues[16][2]);
704 printf(" Join(10K*10K*1K)100 \t%lld\t%lld\t%lld\n",timevalues[17][0],timevalues[17][1],timevalues[17][2]);
707 printf("*******************************************************\n");
711 int main (int ac, char **av)
713 int rc;
714 SQLHENV henv;
715 SQLHDBC hdbc;
716 SQLHSTMT hstmt;
717 mysql=false;
718 if (ac ==2) mysql = true;
719 //printf("Mysql Set %d \n", ac); return 0;
720 rc = SQLAllocHandle (SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv);
721 checkrc (rc, __LINE__);
722 SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0);
724 rc = SQLAllocHandle (SQL_HANDLE_DBC, henv, &hdbc);
725 checkrc (rc, __LINE__);
726 if (!mysql) {
727 rc = SQLConnect (hdbc,
728 (SQLCHAR *) "test", (SQLSMALLINT) strlen ("test"),
729 (SQLCHAR *) "root",
730 (SQLSMALLINT) strlen ("root"),
731 (SQLCHAR *) "manager",
732 (SQLSMALLINT) strlen (""));
733 }else {
735 SQLCHAR outstr[1024];
736 SQLSMALLINT outstrlen;
737 rc = SQLDriverConnect(hdbc, NULL, (SQLCHAR*)"DSN=myodbc3;", SQL_NTS,
738 outstr, sizeof(outstr), &outstrlen,
739 SQL_DRIVER_NOPROMPT);
743 if (SQL_SUCCEEDED(rc)) {
744 printf("Connected\n");
745 //printf("Returned connection string was:\n\t%s\n", outstr);
746 if (rc == SQL_SUCCESS_WITH_INFO) {
747 printf("Driver reported the following diagnostics\n");
748 extract_error("SQLDriverConnect", hdbc, SQL_HANDLE_DBC);
750 } else {
751 fprintf(stderr, "Failed to connect\n");
752 extract_error("SQLDriverConnect", hdbc, SQL_HANDLE_DBC);
755 //check_error (SQL_HANDLE_DBC, hdbc, rc, __LINE__);
756 checkrc (rc, __LINE__);
757 rc = SQLSetConnectOption (hdbc, SQL_AUTOCOMMIT, SQL_AUTOCOMMIT_OFF);
758 checkrc (rc, __LINE__);
759 rc = SQLAllocHandle (SQL_HANDLE_STMT, hdbc, &hstmt);
760 checkrc (rc, __LINE__);
761 int ins=1,upd=2,del=3;
762 int min=1, max=2, sum=3;
764 timevalues[0][0] = runReadTest (henv, hdbc, hstmt,true);
765 timevalues[1][0] = runReadTest (henv, hdbc, hstmt,false);
766 timevalues[2][0] = onePerSel(henv, hdbc, hstmt);
767 timevalues[3][0] = aggregate(henv, hdbc, hstmt,min,true);
768 timevalues[4][0] = aggregate(henv, hdbc, hstmt,min,false);
769 timevalues[5][0] = aggregate(henv, hdbc, hstmt,max,true);
770 timevalues[6][0] = aggregate(henv, hdbc, hstmt,max,false);
771 timevalues[7][0] = aggregate(henv, hdbc, hstmt,sum,true);
772 timevalues[8][0] = aggregate(henv, hdbc, hstmt,sum,false);
773 timevalues[9][0] = distinct(henv, hdbc, hstmt);
774 timevalues[10][0] = orderBy(henv, hdbc, hstmt);
775 timevalues[11][0] = dmlstatement(henv, hdbc, hstmt,ins);
776 timevalues[12][0] = dmlstatement(henv, hdbc, hstmt,upd);
777 timevalues[13][0] = dmlstatement(henv, hdbc, hstmt,del);
778 timevalues[14][0] = joining(henv, hdbc, hstmt,1);
779 timevalues[15][0] = joining(henv, hdbc, hstmt,2);
780 timevalues[16][0] = joinCondition(henv, hdbc, hstmt,1);
781 timevalues[17][0] = joinCondition(henv, hdbc, hstmt,2);
782 printf("NON INDEX OVER\n");
783 if (!mysql){
784 rc = SQLExecDirect(hstmt, (SQLCHAR*) "FLUSH CACHE", SQL_NTS );
785 checkrc (rc, __LINE__);
788 //Hash
789 createHashIndex( hstmt,true);
791 timevalues[0][1] = runReadTest (henv, hdbc, hstmt,true);
792 timevalues[1][1] = runReadTest (henv, hdbc, hstmt,false);
793 timevalues[2][1] = onePerSel(henv, hdbc, hstmt);
794 timevalues[3][1] = aggregate(henv, hdbc, hstmt,min,true);
795 timevalues[4][1] = 0;
796 timevalues[5][1] = 0;
797 timevalues[6][1] = 0;
798 timevalues[7][1] = 0;
799 timevalues[8][1] = 0;
800 timevalues[9][1] = distinct(henv, hdbc, hstmt);
801 timevalues[10][1] = orderBy(henv, hdbc, hstmt);
802 timevalues[11][1] = dmlstatement(henv, hdbc, hstmt,ins);
803 timevalues[12][1] = dmlstatement(henv, hdbc, hstmt,upd);
804 timevalues[13][1] = dmlstatement(henv, hdbc, hstmt,del);
805 timevalues[14][1] = joining(henv, hdbc, hstmt,1);
806 timevalues[15][1] = joining(henv, hdbc, hstmt,2);
808 timevalues[16][1] = joinCondition(henv, hdbc, hstmt,1);
809 timevalues[17][1] = joinCondition(henv, hdbc, hstmt,2);
810 dropHashIndex(hstmt,true);
811 printf("HASH INDEX OVER\n");
812 //printTime();
815 if (!mysql){
816 rc = SQLExecDirect(hstmt, (SQLCHAR*) "FLUSH CACHE", SQL_NTS );
817 checkrc (rc, __LINE__);
821 //TREE
822 createTreeIndex(hstmt,true);
823 timevalues[0][2] = runReadTest (henv, hdbc, hstmt,true);
824 timevalues[1][2] = runReadTest (henv, hdbc, hstmt,false);
825 timevalues[2][2] = onePerSel(henv, hdbc, hstmt);
826 timevalues[3][2] = aggregate(henv, hdbc, hstmt,min,true);
827 timevalues[4][2] = 0;
828 timevalues[5][2] = 0;
829 timevalues[6][2] = 0;
830 timevalues[7][2] = 0;
831 timevalues[8][2] = 0;
832 timevalues[9][2] = distinct(henv, hdbc, hstmt);
833 timevalues[10][2] = orderBy(henv, hdbc, hstmt);
834 timevalues[11][2] = dmlstatement(henv, hdbc, hstmt,ins);
835 timevalues[12][2] = dmlstatement(henv, hdbc, hstmt,upd);
836 timevalues[13][2] = dmlstatement(henv, hdbc, hstmt,del);
837 timevalues[14][2] = joining(henv, hdbc, hstmt,1);
838 timevalues[15][2] = joining(henv, hdbc, hstmt,2);
840 timevalues[16][2] = joinCondition(henv, hdbc, hstmt,1);
841 timevalues[17][2] = joinCondition(henv, hdbc, hstmt,2);
843 dropTreeIndex(hstmt,true);
844 printf("TREE INDEX OVER\n");
847 //printTime
848 printTime();
849 rc = SQLEndTran(SQL_HANDLE_DBC, hdbc, SQL_COMMIT );
850 checkrc (rc, __LINE__);
852 rc = SQLFreeHandle (SQL_HANDLE_STMT, hstmt);
853 checkrc (rc, __LINE__);
854 rc = SQLDisconnect (hdbc);
855 checkrc (rc, __LINE__);
856 rc = SQLFreeHandle (SQL_HANDLE_DBC, hdbc);
857 checkrc (rc, __LINE__);
858 rc = SQLFreeHandle (SQL_HANDLE_ENV, henv);
859 checkrc (rc, __LINE__);
860 exit (0);