14 long long int timevalues
[30]={0};
29 "The driver reported the following diagnostics whilst running "
35 ret
= SQLGetDiagRec(type
, handle
, ++i
, state
, &native
, text
,
37 if (SQL_SUCCEEDED(ret
))
38 printf("%s:%ld:%ld:%s\n", state
, i
, native
, text
);
40 while( ret
== SQL_SUCCESS
);
44 check_error (SQLSMALLINT handleType
, SQLHANDLE handle
, int rc
, int line
)
48 cout
<< "Error " << rc
<< " at line: " << line
<< endl
;
53 while (SQLGetDiagRec (handleType
, handle
, i
++, state
, &native
, mesg
, 300,
57 cout
<< "state: " << state
<< endl
;
58 cout
<< "native: " << native
<< endl
;
59 cout
<< "mesg: " << mesg
<< endl
;
66 inline void checkrc (int rc
, int line
)
70 cout
<< "Error " << rc
<< " at line: " << line
<< endl
;
75 void readWriteTrans (SQLHDBC hdbc
)
77 int rc
= SQLSetConnectAttr (hdbc
, SQL_ATTR_ACCESS_MODE
,
78 (SQLPOINTER
) SQL_MODE_READ_WRITE
, 0);
79 checkrc (rc
, __LINE__
);
80 rc
= SQLEndTran (SQL_HANDLE_DBC
, hdbc
, SQL_COMMIT
);
81 checkrc (rc
, __LINE__
);
84 void readOnlyTrans (SQLHDBC hdbc
)
86 int rc
= SQLSetConnectAttr (hdbc
, SQL_ATTR_ACCESS_MODE
,
87 (SQLPOINTER
) SQL_MODE_READ_ONLY
, 0);
88 checkrc (rc
, __LINE__
);
89 rc
= SQLEndTran (SQL_HANDLE_DBC
, hdbc
, SQL_COMMIT
);
90 checkrc (rc
, __LINE__
);
93 void createHashIndex(SQLHANDLE hstmt
,bool flag
)
96 rc
= SQLExecDirect(hstmt
, (SQLCHAR
*) "CREATE INDEX idx1 ON big1(unique1) HASH;", SQL_NTS
);
97 checkrc (rc
, __LINE__
);
98 rc
= SQLExecDirect(hstmt
, (SQLCHAR
*) "CREATE INDEX idx2 ON big2(unique1) HASH;", SQL_NTS
);
99 checkrc (rc
, __LINE__
);
100 rc
= SQLExecDirect(hstmt
, (SQLCHAR
*) "CREATE INDEX idx3 ON small(unique1) HASH", SQL_NTS
);
101 checkrc (rc
, __LINE__
);
102 rc
= SQLExecDirect(hstmt
, (SQLCHAR
*) "CREATE INDEX idx4 ON big1(stringu1) HASH", SQL_NTS
);
103 checkrc (rc
, __LINE__
);
105 void createTreeIndex(SQLHANDLE hstmt
,bool flag
)
108 rc
= SQLExecDirect(hstmt
, (SQLCHAR
*) "CREATE INDEX idx5 ON big1(unique1) TREE;", SQL_NTS
);
109 checkrc (rc
, __LINE__
);
110 rc
= SQLExecDirect(hstmt
, (SQLCHAR
*) "CREATE INDEX idx6 ON big2(unique1) TREE;", SQL_NTS
);
111 checkrc (rc
, __LINE__
);
112 rc
= SQLExecDirect(hstmt
, (SQLCHAR
*) "CREATE INDEX idx7 ON small(unique1) TREE;", SQL_NTS
);
113 checkrc (rc
, __LINE__
);
114 rc
= SQLExecDirect(hstmt
, (SQLCHAR
*) "CREATE INDEX idx8 ON big1(stringu1) TREE;", SQL_NTS
);
115 checkrc (rc
, __LINE__
);
118 void dropHashIndex(SQLHANDLE hstmt
,bool flag
)
121 rc
= SQLExecDirect(hstmt
, (SQLCHAR
*) "DROP INDEX idx1 ;", SQL_NTS
);
122 checkrc (rc
, __LINE__
);
123 rc
= SQLExecDirect(hstmt
, (SQLCHAR
*) "DROP INDEX idx2 ;", SQL_NTS
);
124 checkrc (rc
, __LINE__
);
125 rc
= SQLExecDirect(hstmt
, (SQLCHAR
*) "DROP INDEX idx3 ;", SQL_NTS
);
126 checkrc (rc
, __LINE__
);
127 rc
= SQLExecDirect(hstmt
, (SQLCHAR
*) "DROP INDEX idx4 ;", SQL_NTS
);
128 checkrc (rc
, __LINE__
);
130 void dropTreeIndex(SQLHANDLE hstmt
,bool flag
)
133 rc
= SQLExecDirect(hstmt
, (SQLCHAR
*) "DROP INDEX idx5 ;", SQL_NTS
);
134 checkrc (rc
, __LINE__
);
135 rc
= SQLExecDirect(hstmt
, (SQLCHAR
*) "DROP INDEX idx6 ;", SQL_NTS
);
136 checkrc (rc
, __LINE__
);
137 rc
= SQLExecDirect(hstmt
, (SQLCHAR
*) "DROP INDEX idx7 ;", SQL_NTS
);
138 checkrc (rc
, __LINE__
);
139 rc
= SQLExecDirect(hstmt
, (SQLCHAR
*) "DROP INDEX idx8 ;", SQL_NTS
);
140 checkrc (rc
, __LINE__
);
144 long long int onePerSel(SQLHANDLE henv
, SQLHANDLE hdbc
, SQLHANDLE hstmt
)
150 int val
[] = {1, 5, 10, 50, 100, 500, 1000, 5000 ,7500, 9900};;
153 char tempval
[124]="Value";
155 readOnlyTrans (hdbc
);
156 rc
= SQLPrepare (hstmt
, (unsigned char *) "SELECT unique1, unique2, stringu1 from big1 where unique1 between ? and ?;", SQL_NTS
);
157 checkrc (rc
, __LINE__
);
158 rc
= SQLBindParameter (hstmt
, 1, SQL_PARAM_INPUT
, SQL_C_LONG
, SQL_INTEGER
, 0, 0, &tempTermVar
, 0, NULL
);
159 checkrc (rc
, __LINE__
);
160 rc
= SQLBindParameter (hstmt
, 2, SQL_PARAM_INPUT
, SQL_C_LONG
, SQL_INTEGER
, 0, 0, &tempTermVar2
, 0, NULL
);
161 checkrc (rc
, __LINE__
);
163 rc
= SQLBindCol (hstmt
, 1, SQL_INTEGER
, &uni1
, 0, NULL
);
164 checkrc (rc
, __LINE__
);
165 rc
= SQLBindCol (hstmt
, 2, SQL_INTEGER
, &uni2
, 0, NULL
);
166 checkrc (rc
, __LINE__
);
167 rc
= SQLBindCol (hstmt
, 3, SQL_C_CHAR
, str1
, sizeof (str1
), NULL
);
168 checkrc (rc
, __LINE__
);
169 //rc = SQLBindCol (hstmt, 4, SQL_C_CHAR, str2, sizeof (str2), NULL);
170 //checkrc (rc, __LINE__);
178 for (i
= 0; i
< 10; i
++)
181 strcpy(tempval
,"Value");
182 tempTermVar
= val
[i
] ;
183 tempTermVar2
= val
[i
]+99 ;
185 rc
= SQLExecute (hstmt
);
186 checkrc (rc
, __LINE__
);
187 while(SQL_SUCCEEDED(rc
= SQLFetch(hstmt
)))
191 // printf("Count=%d\n",Count);
192 rc
= SQLCloseCursor (hstmt
);
193 checkrc (rc
, __LINE__
);
194 rc
= SQLTransact (henv
, hdbc
, SQL_COMMIT
);
195 checkrc (rc
, __LINE__
);
198 readWriteTrans (hdbc
);
199 //printf ("Read: 1 %lld\n", timer.avg ());
200 return timer
.avg()/1000;
203 long long int runReadTest (SQLHANDLE henv
, SQLHANDLE hdbc
,SQLHANDLE hstmt
,bool flag
)
210 int val
[] = {1, 5, 10, 50, 100, 500, 1000, 5000 ,7500, 9999};;
212 char tempval
[124]="Value";
215 /* Set read-only transaction type */
216 readOnlyTrans (hdbc
);
218 rc
= SQLPrepare (hstmt
, (unsigned char *) "SELECT unique1, unique2, stringu1, stringu2 from big1 where unique1=?;", SQL_NTS
);
221 rc
= SQLPrepare (hstmt
, (unsigned char *) "SELECT unique1, unique2, stringu1, stringu2 from big1 where stringu1=?;", SQL_NTS
);
223 checkrc (rc
, __LINE__
);
226 rc
= SQLBindParameter (hstmt
, 1, SQL_PARAM_INPUT
, SQL_C_LONG
, SQL_INTEGER
, 0, 0, &tempTermVar
, 0, NULL
);
227 checkrc (rc
, __LINE__
);
230 rc
= SQLBindParameter (hstmt
, 1, SQL_PARAM_INPUT
, SQL_C_CHAR
, SQL_C_CHAR
, 196, 0, tempval
, 0, NULL
);
231 checkrc (rc
, __LINE__
);
234 rc
= SQLBindCol (hstmt
, 1, SQL_INTEGER
, &uni1
, 0, NULL
);
235 checkrc (rc
, __LINE__
);
236 rc
= SQLBindCol (hstmt
, 2, SQL_INTEGER
, &uni2
, 0, NULL
);
237 checkrc (rc
, __LINE__
);
238 rc
= SQLBindCol (hstmt
, 3, SQL_C_CHAR
, str1
, sizeof (str1
), NULL
);
239 checkrc (rc
, __LINE__
);
240 rc
= SQLBindCol (hstmt
, 4, SQL_C_CHAR
, str2
, sizeof (str2
), NULL
);
241 checkrc (rc
, __LINE__
);
249 for (i
= 0; i
< 10; i
++)
251 strcpy(tempval
,"Value");
253 tempTermVar
= val
[i
] ;}
256 sprintf(buf
,"%d",val
[i
]);
260 rc
= SQLExecute (hstmt
);
261 checkrc (rc
, __LINE__
);
262 rc
= SQLFetch (hstmt
);
263 checkrc (rc
, __LINE__
);
265 rc
= SQLCloseCursor (hstmt
);
266 checkrc (rc
, __LINE__
);
267 rc
= SQLTransact (henv
, hdbc
, SQL_COMMIT
);
268 checkrc (rc
, __LINE__
);
271 //printf ("Read: 1 %lld\n", timer.avg ());
272 /* Set read-write transaction type */
273 readWriteTrans (hdbc
);
274 return timer
.avg()/1000;
279 long long int aggregate(SQLHANDLE henv
, SQLHANDLE hdbc
,SQLHANDLE hstmt
,bool flag
)
283 /* Set read-only transaction type */
284 readOnlyTrans (hdbc
);
286 rc
= SQLPrepare (hstmt
, (unsigned char *) "SELECT MIN(unique1) from big1;", SQL_NTS
);
289 rc
= SQLPrepare (hstmt
, (unsigned char *) "SELECT SUM(unique1) from big1;", SQL_NTS
);
291 checkrc (rc
, __LINE__
);
292 rc
= SQLBindCol (hstmt
, 1, SQL_INTEGER
, &summin
, 0, NULL
);
293 checkrc (rc
, __LINE__
);
299 for (i
= 0; i
< 10; i
++)
302 rc
= SQLExecute (hstmt
);
303 checkrc (rc
, __LINE__
);
304 rc
= SQLFetch (hstmt
);
305 checkrc (rc
, __LINE__
);
307 // printf("value=%d",summin);
308 rc
= SQLCloseCursor (hstmt
);
309 checkrc (rc
, __LINE__
);
310 rc
= SQLTransact (henv
, hdbc
, SQL_COMMIT
);
311 checkrc (rc
, __LINE__
);
314 //printf ("Read: 1 %lld\n", timer.avg ());
315 /* Set read-write transaction type */
316 readWriteTrans (hdbc
);
317 return timer
.avg()/1000;
321 long long int dmlstatement(SQLHANDLE henv
, SQLHANDLE hdbc
,SQLHANDLE hstmt
,int val
)
323 int tempTermVar
=10000,tempTermVar2
=10000;
325 /* Set read-only transaction type */
326 readOnlyTrans (hdbc
);
328 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
);
331 rc
= SQLPrepare (hstmt
, (unsigned char *) "UPDATE big1 SET two=1 WHERE unique1=?;", SQL_NTS
);
334 rc
= SQLPrepare (hstmt
, (unsigned char *) "DELETE FROM big1 WHERE unique1=?;", SQL_NTS
);
336 checkrc (rc
, __LINE__
);
342 for (i
= 0; i
< 100; i
++)
344 rc
= SQLBindParameter (hstmt
, 1, SQL_PARAM_INPUT
, SQL_C_LONG
, SQL_INTEGER
, 0, 0, &tempTermVar
, 0, NULL
);
345 checkrc (rc
, __LINE__
);
349 rc
= SQLBindParameter (hstmt
, 1, SQL_PARAM_INPUT
, SQL_C_LONG
, SQL_INTEGER
, 0, 0, &tempTermVar2
, 0, NULL
);
350 checkrc (rc
, __LINE__
);
353 rc
= SQLExecute (hstmt
);
354 checkrc (rc
, __LINE__
);
355 rc
= SQLTransact (henv
, hdbc
, SQL_COMMIT
);
356 checkrc (rc
, __LINE__
);
358 tempTermVar
=10000;tempTermVar2
=10000;
360 //printf ("Read: 1 %lld\n", timer.avg ());
361 /* Set read-write transaction type */
362 readWriteTrans (hdbc
);
363 return timer
.avg()/1000;
368 long long int joining(SQLHANDLE henv
, SQLHANDLE hdbc
, SQLHANDLE hstmt
,int flag
)
371 int uni2
,uni3
,uni4
,uni5
;
375 int val
[] = {1, 5, 10, 50, 100, 250, 500, 750, 900, 999};
377 char tempval
[124]="Value";
380 /* Set read-only transaction type */
381 readOnlyTrans (hdbc
);
383 rc
= SQLPrepare (hstmt
, (unsigned char *) "SELECT big1.unique1, big1.unique2, small.unique1, small.stringu1 FROM small,big1 WHERE big1.unique1=small.unique1 AND small.unique1=?;", SQL_NTS
);
386 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.unique1 AND big1.unique1=big2.unique1 AND big1.unique1 = ?;", SQL_NTS
);
388 checkrc (rc
, __LINE__
);
390 rc
= SQLBindParameter (hstmt
, 1, SQL_PARAM_INPUT
, SQL_C_LONG
, SQL_INTEGER
, 0, 0, &tempTermVar
, 0, NULL
);
391 checkrc (rc
, __LINE__
);
392 rc
= SQLBindCol (hstmt
, 1, SQL_INTEGER
, &uni1
, 0, NULL
);
393 checkrc (rc
, __LINE__
);
394 rc
= SQLBindCol (hstmt
, 2, SQL_INTEGER
, &uni2
, 0, NULL
);
395 checkrc (rc
, __LINE__
);
396 rc
= SQLBindCol (hstmt
, 2, SQL_INTEGER
, &uni3
, 0, NULL
);
397 checkrc (rc
, __LINE__
);
398 rc
= SQLBindCol (hstmt
, 4, SQL_C_CHAR
, str1
, sizeof (str1
), NULL
);
399 checkrc (rc
, __LINE__
);
401 rc
= SQLBindCol (hstmt
, 5, SQL_INTEGER
, &uni4
, 0, NULL
);
402 checkrc (rc
, __LINE__
);
403 rc
= SQLBindCol (hstmt
, 6, SQL_INTEGER
, &uni5
, 0, NULL
);
404 checkrc (rc
, __LINE__
);
412 for (i
= 0; i
< 10; i
++)
414 tempTermVar
= val
[i
] ;
416 rc
= SQLExecute (hstmt
);
417 checkrc (rc
, __LINE__
);
418 rc
= SQLFetch(hstmt
);
420 // printf("%d,%d\n",uni1,uni3);
421 rc
= SQLCloseCursor (hstmt
);
422 checkrc (rc
, __LINE__
);
423 rc
= SQLTransact (henv
, hdbc
, SQL_COMMIT
);
424 checkrc (rc
, __LINE__
);
427 //printf ("Read: 1 %lld\n", timer.avg ());
428 /* Set read-write transaction type */
429 readWriteTrans (hdbc
);
430 return timer
.avg()/1000;
436 printf("Wisconsin Benchmark Report:\n");
437 printf("*******************************************************\n");
438 printf(" Statement \t NoIndex Hash\t Tree\n");
439 printf("*******************************************************\n");
440 printf(" SelectInt 1 \t %lld\t %lld \t %lld\n",timevalues
[0],timevalues
[1],timevalues
[2]);
441 printf(" SelectStr 1 \t %lld\t %lld \t %lld\n",timevalues
[3],timevalues
[4],timevalues
[5]);
442 printf(" 1Per Sel \t %lld\t %lld \t %lld\n\n",timevalues
[6],timevalues
[7],timevalues
[8]);
443 printf(" Min All \t %lld\t %lld \t %lld\n",timevalues
[9],timevalues
[10],timevalues
[11]);
444 printf(" Sum All \t %lld\t %lld \t %lld\n\n",timevalues
[12],timevalues
[13],timevalues
[14]);
445 printf(" Insert 1 \t %lld\t %lld \t %lld\n",timevalues
[15],timevalues
[16],timevalues
[17]);
446 printf(" Update 1 \t %lld\t %lld \t %lld\n",timevalues
[18],timevalues
[19],timevalues
[20]);
447 printf(" Delete 1 \t %lld\t %lld \t %lld\n\n",timevalues
[21],timevalues
[22],timevalues
[23]);
448 printf(" Join(10K*1K)1 \t %lld\t %lld \t %lld\n",timevalues
[24],timevalues
[25],timevalues
[26]);
449 printf(" Join(10K*10K*1K)1 \t %lld\t %lld \t %lld\n",timevalues
[27],timevalues
[28],timevalues
[29]);
450 printf("*******************************************************\n");
455 int main (int ac
, char **av
)
462 rc
= SQLAllocHandle (SQL_HANDLE_ENV
, SQL_NULL_HANDLE
, &henv
);
463 checkrc (rc
, __LINE__
);
464 SQLSetEnvAttr(henv
, SQL_ATTR_ODBC_VERSION
, (void *) SQL_OV_ODBC3
, 0);
466 rc
= SQLAllocHandle (SQL_HANDLE_DBC
, henv
, &hdbc
);
467 checkrc (rc
, __LINE__
);
468 rc
= SQLConnect (hdbc
,
469 (SQLCHAR
*) "test", (SQLSMALLINT
) strlen ("test"),
471 (SQLSMALLINT
) strlen ("root"),
472 (SQLCHAR
*) "manager",
473 (SQLSMALLINT
) strlen (""));
475 if (SQL_SUCCEEDED(rc
)) {
476 printf("Connected\n");
477 //printf("Returned connection string was:\n\t%s\n", outstr);
478 if (rc
== SQL_SUCCESS_WITH_INFO
) {
479 printf("Driver reported the following diagnostics\n");
480 extract_error("SQLDriverConnect", hdbc
, SQL_HANDLE_DBC
);
483 fprintf(stderr
, "Failed to connect\n");
484 extract_error("SQLDriverConnect", hdbc
, SQL_HANDLE_DBC
);
487 //check_error (SQL_HANDLE_DBC, hdbc, rc, __LINE__);
488 checkrc (rc
, __LINE__
);
489 rc
= SQLSetConnectOption (hdbc
, SQL_AUTOCOMMIT
, SQL_AUTOCOMMIT_OFF
);
490 checkrc (rc
, __LINE__
);
491 rc
= SQLAllocHandle (SQL_HANDLE_STMT
, hdbc
, &hstmt
);
492 checkrc (rc
, __LINE__
);
493 int ins
=1,upd
=2,del
=3;
495 timevalues
[0] = runReadTest (henv
, hdbc
, hstmt
,true);
496 timevalues
[3] = runReadTest (henv
, hdbc
, hstmt
,false);
497 timevalues
[6] = onePerSel(henv
, hdbc
, hstmt
);
498 timevalues
[9] = aggregate(henv
, hdbc
, hstmt
,true);
499 timevalues
[12] = aggregate(henv
, hdbc
, hstmt
,false);
500 timevalues
[15] = dmlstatement(henv
, hdbc
, hstmt
,ins
);
501 timevalues
[18] = dmlstatement(henv
, hdbc
, hstmt
,upd
);
502 timevalues
[21] = dmlstatement(henv
, hdbc
, hstmt
,del
);
503 timevalues
[24] = joining(henv
, hdbc
, hstmt
,1);
504 timevalues
[27] = joining(henv
, hdbc
, hstmt
,2);
505 printf("NON INDEX OVER\n");
508 createHashIndex( hstmt
,true);
509 timevalues
[1] = runReadTest (henv
, hdbc
, hstmt
,true);
510 timevalues
[4] = runReadTest (henv
, hdbc
, hstmt
,false);
511 timevalues
[7] = onePerSel(henv
, hdbc
, hstmt
);
512 timevalues
[10] = aggregate(henv
, hdbc
, hstmt
,true);
513 timevalues
[13] = aggregate(henv
, hdbc
, hstmt
,false);
514 timevalues
[16] = dmlstatement(henv
, hdbc
, hstmt
,ins
);
515 timevalues
[19] = dmlstatement(henv
, hdbc
, hstmt
,upd
);
516 timevalues
[22] = dmlstatement(henv
, hdbc
, hstmt
,del
);
517 timevalues
[25] = joining(henv
, hdbc
, hstmt
,1);
518 timevalues
[28] = joining(henv
, hdbc
, hstmt
,2);
519 dropHashIndex(hstmt
,true);
520 printf("HASH INDEX OVER\n");
524 createTreeIndex(hstmt
,true);
525 timevalues
[2] = runReadTest (henv
, hdbc
, hstmt
,true);
526 timevalues
[5] = runReadTest (henv
, hdbc
, hstmt
,false);
527 timevalues
[8] = onePerSel(henv
, hdbc
, hstmt
);
528 timevalues
[11] = aggregate(henv
, hdbc
, hstmt
,true);
529 timevalues
[14] = aggregate(henv
, hdbc
, hstmt
,false);
530 timevalues
[17] = dmlstatement(henv
, hdbc
, hstmt
,ins
);
531 timevalues
[20] = dmlstatement(henv
, hdbc
, hstmt
,upd
);
532 timevalues
[23] = dmlstatement(henv
, hdbc
, hstmt
,del
);
533 timevalues
[26] = joining(henv
, hdbc
,hstmt
,1);
534 timevalues
[29] = joining(henv
, hdbc
,hstmt
,2);
535 dropTreeIndex(hstmt
,true);
536 printf("TREE INDEX OVER\n");
539 rc
= SQLEndTran(SQL_HANDLE_DBC
, hdbc
, SQL_COMMIT
);
540 checkrc (rc
, __LINE__
);
542 rc
= SQLFreeHandle (SQL_HANDLE_STMT
, hstmt
);
543 checkrc (rc
, __LINE__
);
544 rc
= SQLDisconnect (hdbc
);
545 checkrc (rc
, __LINE__
);
546 rc
= SQLFreeHandle (SQL_HANDLE_DBC
, hdbc
);
547 checkrc (rc
, __LINE__
);
548 rc
= SQLFreeHandle (SQL_HANDLE_ENV
, henv
);
549 checkrc (rc
, __LINE__
);