15 long long int timevalues
[30][3]={0};
30 "The driver reported the following diagnostics whilst running "
36 ret
= SQLGetDiagRec(type
, handle
, ++i
, state
, &native
, text
,
38 if (SQL_SUCCEEDED(ret
))
39 printf("%s:%ld:%ld:%s\n", state
, i
, native
, text
);
41 while( ret
== SQL_SUCCESS
);
45 check_error (SQLSMALLINT handleType
, SQLHANDLE handle
, int rc
, int line
)
49 cout
<< "Error " << rc
<< " at line: " << line
<< endl
;
54 while (SQLGetDiagRec (handleType
, handle
, i
++, state
, &native
, mesg
, 300,
58 cout
<< "state: " << state
<< endl
;
59 cout
<< "native: " << native
<< endl
;
60 cout
<< "mesg: " << mesg
<< endl
;
67 inline void checkrc (int rc
, int line
)
71 cout
<< "Error " << rc
<< " at line: " << line
<< endl
;
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
)
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__
);
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
)
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__
);
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
)
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__
);
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
)
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__
);
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
)
197 //int val[] = {1, 5, 10, 50, 100, 500, 1000, 5000 ,7500, 9500};
198 int val
[10] = {1, 5, 10, 50, 100, 250, 500, 750, 900, 999};
201 char tempval
[124]="Value";
203 readOnlyTrans (hdbc
);
204 rc
= SQLPrepare (hstmt
, (unsigned char *) "SELECT unique1, unique2, stringu1 from big1 where unique1 between ? and ?;", SQL_NTS
);
205 checkrc (rc
, __LINE__
);
206 rc
= SQLBindParameter (hstmt
, 1, SQL_PARAM_INPUT
, SQL_C_LONG
, SQL_INTEGER
, 0, 0, &tempTermVar
, 0, NULL
);
207 checkrc (rc
, __LINE__
);
208 rc
= SQLBindParameter (hstmt
, 2, SQL_PARAM_INPUT
, SQL_C_LONG
, SQL_INTEGER
, 0, 0, &tempTermVar2
, 0, NULL
);
209 checkrc (rc
, __LINE__
);
211 rc
= SQLBindCol (hstmt
, 1, SQL_INTEGER
, &uni1
, 0, NULL
);
212 checkrc (rc
, __LINE__
);
213 rc
= SQLBindCol (hstmt
, 2, SQL_INTEGER
, &uni2
, 0, NULL
);
214 checkrc (rc
, __LINE__
);
215 rc
= SQLBindCol (hstmt
, 3, SQL_C_CHAR
, str1
, sizeof (str1
), NULL
);
216 checkrc (rc
, __LINE__
);
223 for (i
= 0; i
< 10; i
++)
226 strcpy(tempval
,"Value");
227 tempTermVar
= val
[i
] ;
228 tempTermVar2
= val
[i
]+99 ;
230 rc
= SQLExecute (hstmt
);
231 checkrc (rc
, __LINE__
);
232 while(SQL_SUCCEEDED(rc
= SQLFetch(hstmt
)))
236 // printf("Count=%d\n",Count);
237 rc
= SQLCloseCursor (hstmt
);
238 checkrc (rc
, __LINE__
);
239 rc
= SQLTransact (henv
, hdbc
, SQL_COMMIT
);
240 checkrc (rc
, __LINE__
);
243 printf("One % Selection returned %d rows", Count
);
244 readWriteTrans (hdbc
);
248 readWriteTrans (hdbc
);
249 //printf ("Read: 1 %lld\n", timer.avg ());
250 return timer
.avg()/1000;
253 long long int runReadTest (SQLHANDLE henv
, SQLHANDLE hdbc
,SQLHANDLE hstmt
,bool flag
)
260 //int val[] = {1, 10, 100, 500, 1000, 5000 ,7500, 8000, 9000, 9999};
261 int val
[10] = {1, 5, 10, 50, 100, 250, 500, 750, 900, 999};
263 char tempval
[52]="Value";
266 /* Set read-only transaction type */
267 readOnlyTrans (hdbc
);
269 rc
= SQLPrepare (hstmt
, (unsigned char *) "SELECT unique1, unique2, stringu1, stringu2 from big1 where unique1=?;", SQL_NTS
);
272 rc
= SQLPrepare (hstmt
, (unsigned char *) "SELECT unique1, unique2, stringu1, stringu2 from big1 where stringu1=?;", SQL_NTS
);
274 checkrc (rc
, __LINE__
);
277 rc
= SQLBindParameter (hstmt
, 1, SQL_PARAM_INPUT
, SQL_C_LONG
, SQL_INTEGER
, 0, 0, &tempTermVar
, 0, NULL
);
278 checkrc (rc
, __LINE__
);
281 rc
= SQLBindParameter (hstmt
, 1, SQL_PARAM_INPUT
, SQL_C_CHAR
, SQL_C_CHAR
, 196, 0, tempval
, 0, NULL
);
282 checkrc (rc
, __LINE__
);
285 rc
= SQLBindCol (hstmt
, 1, SQL_INTEGER
, &uni1
, 0, NULL
);
286 checkrc (rc
, __LINE__
);
287 rc
= SQLBindCol (hstmt
, 2, SQL_INTEGER
, &uni2
, 0, NULL
);
288 checkrc (rc
, __LINE__
);
289 rc
= SQLBindCol (hstmt
, 3, SQL_C_CHAR
, str1
, sizeof (str1
), NULL
);
290 checkrc (rc
, __LINE__
);
291 rc
= SQLBindCol (hstmt
, 4, SQL_C_CHAR
, str2
, sizeof (str2
), NULL
);
292 checkrc (rc
, __LINE__
);
298 char buf
[10]="Value";
301 for (i
= 0; i
< 10; i
++)
304 tempTermVar
= val
[i
] ;}
306 sprintf(tempval
,"%s%d",buf
, val
[i
]);
309 rc
= SQLExecute (hstmt
);
310 checkrc (rc
, __LINE__
);
311 rc
= SQLFetch (hstmt
);
312 checkrc (rc
, __LINE__
);
314 rc
= SQLCloseCursor (hstmt
);
315 checkrc (rc
, __LINE__
);
316 rc
= SQLTransact (henv
, hdbc
, SQL_COMMIT
);
317 checkrc (rc
, __LINE__
);
320 //printf ("Read: 1 %lld\n", timer.avg ());
321 /* Set read-write transaction type */
322 readWriteTrans (hdbc
);
323 return timer
.avg()/1000;
327 long long int distinct(SQLHANDLE henv
, SQLHANDLE hdbc
,SQLHANDLE hstmt
)
332 readOnlyTrans (hdbc
);
333 rc
= SQLPrepare (hstmt
, (unsigned char *) "SELECT DISTINCT onepercent FROM big1;", SQL_NTS
);
334 checkrc (rc
, __LINE__
);
336 rc
= SQLBindCol (hstmt
, 1, SQL_INTEGER
, &var_onepercent
, 0, NULL
);
337 checkrc (rc
, __LINE__
);
342 for (i
= 0; i
< 10; i
++)
346 rc
= SQLExecute (hstmt
);
347 checkrc (rc
, __LINE__
);
348 while(SQL_SUCCEEDED(rc
= SQLFetch(hstmt
))){
351 //checkrc (rc, __LINE__);
352 rc
= SQLCloseCursor (hstmt
);
353 checkrc (rc
, __LINE__
);
354 rc
= SQLTransact (henv
, hdbc
, SQL_COMMIT
);
355 checkrc (rc
, __LINE__
);
358 printf("distinct returned %d rows\n");
359 readWriteTrans(hdbc
);
363 readWriteTrans(hdbc
);
364 return timer
.avg()/1000;
366 long long int orderBy(SQLHANDLE henv
, SQLHANDLE hdbc
,SQLHANDLE hstmt
)
368 int val
[] = {1, 5, 10, 50, 100, 500, 1000, 5000 ,7500, 9500};
369 int var_two
, var_four
, var_ten
, var_twenty
, var_onepercent
;
371 int tempTermVar
=0, tempTermVar2
=0, tempTermVar3
=0;
374 rc
= SQLPrepare (hstmt
, (unsigned char *) "SELECT two, four, ten, twenty, onepercent, string4 from big1 where unique1 between ? and ? order by unique1;", SQL_NTS
);
375 checkrc (rc
, __LINE__
);
377 readOnlyTrans (hdbc
);
378 rc
= SQLBindParameter (hstmt
, 1, SQL_PARAM_INPUT
, SQL_C_LONG
, SQL_INTEGER
, 0, 0, &tempTermVar
, 0, NULL
);
379 checkrc (rc
, __LINE__
);
380 rc
= SQLBindParameter (hstmt
, 2, SQL_PARAM_INPUT
, SQL_C_LONG
, SQL_INTEGER
, 0, 0, &tempTermVar2
, 0, NULL
);
381 checkrc (rc
, __LINE__
);
384 rc
= SQLBindCol (hstmt
, 1, SQL_INTEGER
, &var_two
, 0, NULL
);
385 checkrc (rc
, __LINE__
);
387 rc
= SQLBindCol (hstmt
, 2, SQL_INTEGER
, &var_four
, 0, NULL
);
388 checkrc (rc
, __LINE__
);
390 rc
= SQLBindCol (hstmt
, 3, SQL_INTEGER
, &var_ten
, 0, NULL
);
391 checkrc (rc
, __LINE__
);
393 rc
= SQLBindCol (hstmt
, 4, SQL_INTEGER
, &var_twenty
, 0, NULL
);
394 checkrc (rc
, __LINE__
);
396 rc
= SQLBindCol (hstmt
, 5, SQL_INTEGER
, &var_onepercent
, 0, NULL
);
397 checkrc (rc
, __LINE__
);
399 rc
= SQLBindCol (hstmt
, 6, SQL_C_CHAR
, str1
, sizeof (str1
), NULL
);
400 checkrc (rc
, __LINE__
);
408 for (i
= 0; i
< 10; i
++)
412 tempTermVar2
= val
[i
]+100 ;
414 rc
= SQLExecute (hstmt
);
415 checkrc (rc
, __LINE__
);
416 rc
= SQLFetch (hstmt
);
417 while(SQL_SUCCEEDED(rc
= SQLFetch(hstmt
))) count
++;
418 //checkrc (rc, __LINE__);
419 rc
= SQLCloseCursor (hstmt
);
420 checkrc (rc
, __LINE__
);
421 rc
= SQLTransact (henv
, hdbc
, SQL_COMMIT
);
422 checkrc (rc
, __LINE__
);
425 printf("orderby returned %d rows \n", count
);
426 readWriteTrans(hdbc
);
430 readWriteTrans(hdbc
);
431 return timer
.avg()/1000;
436 long long int aggregate(SQLHANDLE henv
, SQLHANDLE hdbc
,SQLHANDLE hstmt
,int val
,bool flag
)
438 int summinmax
=0,tempTermVar
=0;
440 /* Set read-only transaction type */
441 readOnlyTrans (hdbc
);
443 rc
= SQLPrepare (hstmt
, (unsigned char *) "SELECT MIN(unique1) from big1;", SQL_NTS
);
445 else if(val
==1 && !flag
)
447 rc
= SQLPrepare (hstmt
, (unsigned char *) "SELECT MIN(unique1) from big1 group by onepercent;", SQL_NTS
);
450 else if(val
==2 && flag
) {
451 rc
= SQLPrepare (hstmt
, (unsigned char *) "SELECT MAX(unique1) from big1;", SQL_NTS
);
453 else if(val
==2 && !flag
){
454 rc
= SQLPrepare (hstmt
, (unsigned char *) "SELECT MAX(unique1) from big1 group by onepercent;", SQL_NTS
);
456 else if(val
==3 && flag
) {
457 rc
= SQLPrepare (hstmt
, (unsigned char *) "SELECT SUM(unique1) from big1;", SQL_NTS
);
459 else if(val
==3 && !flag
){
460 rc
= SQLPrepare (hstmt
, (unsigned char *) "SELECT SUM(unique1) from big1 group by onepercent;", SQL_NTS
);
462 checkrc (rc
, __LINE__
);
464 rc
= SQLBindCol (hstmt
, 1, SQL_INTEGER
, &summinmax
, 0, NULL
);
465 checkrc (rc
, __LINE__
);
471 for (i
= 0; i
< 10; i
++)
474 rc
= SQLExecute (hstmt
);
475 checkrc (rc
, __LINE__
);
476 rc
= SQLFetch (hstmt
);
477 checkrc (rc
, __LINE__
);
479 // printf("value=%d",summin);
480 rc
= SQLCloseCursor (hstmt
);
481 checkrc (rc
, __LINE__
);
482 rc
= SQLTransact (henv
, hdbc
, SQL_COMMIT
);
483 checkrc (rc
, __LINE__
);
486 //printf ("Read: 1 %lld\n", timer.avg ());
487 /* Set read-write transaction type */
488 readWriteTrans (hdbc
);
489 return timer
.avg()/1000;
493 long long int dmlstatement(SQLHANDLE henv
, SQLHANDLE hdbc
,SQLHANDLE hstmt
,int val
)
495 int tempTermVar
=10000,tempTermVar2
=10000;
497 /* Set read-only transaction type */
498 readOnlyTrans (hdbc
);
500 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
);
503 rc
= SQLPrepare (hstmt
, (unsigned char *) "UPDATE big1 SET two=1 WHERE unique1=?;", SQL_NTS
);
506 rc
= SQLPrepare (hstmt
, (unsigned char *) "DELETE FROM big1 WHERE unique1=?;", SQL_NTS
);
508 checkrc (rc
, __LINE__
);
514 for (i
= 0; i
< 100; i
++)
516 rc
= SQLBindParameter (hstmt
, 1, SQL_PARAM_INPUT
, SQL_C_LONG
, SQL_INTEGER
, 0, 0, &tempTermVar
, 0, NULL
);
517 checkrc (rc
, __LINE__
);
521 rc
= SQLBindParameter (hstmt
, 1, SQL_PARAM_INPUT
, SQL_C_LONG
, SQL_INTEGER
, 0, 0, &tempTermVar2
, 0, NULL
);
522 checkrc (rc
, __LINE__
);
525 rc
= SQLExecute (hstmt
);
526 checkrc (rc
, __LINE__
);
527 rc
= SQLTransact (henv
, hdbc
, SQL_COMMIT
);
528 checkrc (rc
, __LINE__
);
530 tempTermVar
=10000;tempTermVar2
=10000;
532 //printf ("Read: 1 %lld\n", timer.avg ());
533 /* Set read-write transaction type */
534 readWriteTrans (hdbc
);
535 return timer
.avg()/1000;
540 long long int joining(SQLHANDLE henv
, SQLHANDLE hdbc
, SQLHANDLE hstmt
,int value
)
543 int uni2
,uni3
,uni4
,uni5
;
547 int val
[10] = {1, 5, 10, 50, 100, 250, 500, 750, 900, 999};
549 char tempval
[124]="Value";
552 /* Set read-only transaction type */
553 readOnlyTrans (hdbc
);
555 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
);
559 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
);
562 checkrc (rc
, __LINE__
);
566 rc
= SQLBindParameter (hstmt
, 1, SQL_PARAM_INPUT
, SQL_C_LONG
, SQL_INTEGER
, 0, 0, &tempTermVar
, 0, NULL
);
567 checkrc (rc
, __LINE__
);
569 rc
= SQLBindCol (hstmt
, 1, SQL_C_LONG
, &uni1
, 0, NULL
);
570 checkrc (rc
, __LINE__
);
571 rc
= SQLBindCol (hstmt
, 2, SQL_C_LONG
, &uni2
, 0, NULL
);
572 checkrc (rc
, __LINE__
);
573 rc
= SQLBindCol (hstmt
, 3, SQL_C_LONG
, &uni3
, 0, NULL
);
574 checkrc (rc
, __LINE__
);
575 rc
= SQLBindCol (hstmt
, 4, SQL_C_CHAR
, str1
, sizeof (str1
), NULL
);
576 checkrc (rc
, __LINE__
);
578 rc
= SQLBindCol (hstmt
, 5, SQL_C_LONG
, &uni4
, 0, NULL
);
579 checkrc (rc
, __LINE__
);
580 rc
= SQLBindCol (hstmt
, 6, SQL_C_LONG
, &uni5
, 0, NULL
);
581 checkrc (rc
, __LINE__
);
588 for (i
= 0; i
< 10; i
++)
590 tempTermVar
= val
[i
];
592 rc
= SQLExecute (hstmt
);
593 checkrc (rc
, __LINE__
);
596 rc
= SQLCloseCursor (hstmt
);
597 checkrc (rc
, __LINE__
);
598 rc
= SQLTransact (henv
, hdbc
, SQL_COMMIT
);
599 checkrc (rc
, __LINE__
);
601 // printf("uni1=%d uni2=%d uni3=%d str1=%s \n",uni1,uni2,uni3,str1);
603 readWriteTrans (hdbc
);
604 return timer
.avg()/1000;
608 long long int joinCondition(SQLHANDLE henv
, SQLHANDLE hdbc
, SQLHANDLE hstmt
,int value
)
611 int uni2
,uni3
,uni4
,uni5
;
615 int searchVal
[] = {1, 5, 10, 50, 100, 200, 250, 500, 750, 800};
617 //Set read-only transaction type
618 readOnlyTrans (hdbc
);
621 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
);
625 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
);
628 checkrc (rc
, __LINE__
);
629 int tempTermVar1
=0, tempTermVar2
=0;
631 rc
= SQLBindParameter (hstmt
, 1, SQL_PARAM_INPUT
, SQL_C_LONG
, SQL_INTEGER
, 0, 0, &tempTermVar1
, 0, NULL
);
632 checkrc (rc
, __LINE__
);
633 rc
= SQLBindParameter (hstmt
, 2, SQL_PARAM_INPUT
, SQL_C_LONG
, SQL_INTEGER
, 0, 0, &tempTermVar2
, 0, NULL
);
634 checkrc (rc
, __LINE__
);
637 rc
= SQLBindCol (hstmt
, 1, SQL_C_SLONG
, &uni1
, 0, NULL
);
638 checkrc (rc
, __LINE__
);
639 rc
= SQLBindCol (hstmt
, 2, SQL_C_SLONG
, &uni2
, 0, NULL
);
640 checkrc (rc
, __LINE__
);
641 rc
= SQLBindCol (hstmt
, 3, SQL_C_SLONG
, &uni3
, 0, NULL
);
642 checkrc (rc
, __LINE__
);
643 rc
= SQLBindCol (hstmt
, 4, SQL_C_CHAR
, str1
, sizeof (str1
), NULL
);
644 checkrc (rc
, __LINE__
);
646 rc
= SQLBindCol (hstmt
, 5, SQL_C_SLONG
, &uni4
, 0, NULL
);
647 checkrc (rc
, __LINE__
);
648 rc
= SQLBindCol (hstmt
, 6, SQL_C_SLONG
, &uni5
, 0, NULL
);
649 checkrc (rc
, __LINE__
);
657 tempTermVar1
= searchVal
[i
];
658 tempTermVar2
= searchVal
[i
]+100;
660 rc
= SQLExecute (hstmt
);
661 checkrc (rc
, __LINE__
);
662 while(SQL_SUCCEEDED(rc
= SQLFetch(hstmt
)))
665 //printf("Uni1:%d uni2=%d uni3=%d \n",uni1,uni2,uni3);
667 rc
= SQLCloseCursor (hstmt
);
668 checkrc (rc
, __LINE__
);
669 rc
= SQLTransact (henv
, hdbc
, SQL_COMMIT
);
670 checkrc (rc
, __LINE__
);
673 printf ("range join returned %d rows\n", count
);
674 readWriteTrans (hdbc
);
678 readWriteTrans (hdbc
);
679 return timer
.avg()/1000;
685 printf("Wisconsin Benchmark Report:\n");
686 printf("*******************************************************\n");
687 printf(" Statement \tNoIndex\tHash\tTree\n");
688 printf("*******************************************************\n");
689 printf(" SelectInt 1 \t%lld\t%lld\t%lld\n",timevalues
[0][0],timevalues
[0][1],timevalues
[0][2]);
690 printf(" SelectStr 1 \t%lld\t%lld\t%lld\n",timevalues
[1][0],timevalues
[1][1],timevalues
[1][2]);
691 printf(" 1Per Sel \t%lld\t%lld\t%lld\n",timevalues
[2][0],timevalues
[2][1],timevalues
[2][2]);
692 printf(" Min All \t%lld\t%lld\t%lld\n",timevalues
[3][0],timevalues
[3][1],timevalues
[3][2]);
693 printf(" Min GrBy 1% \t%lld\t%lld\t%lld\n",timevalues
[4][0],timevalues
[4][1],timevalues
[4][2]);
694 printf(" Max All \t%lld\t%lld\t%lld\n",timevalues
[5][0],timevalues
[5][1],timevalues
[5][2]);
695 printf(" Max GrBy 1 \t%lld\t%lld\t%lld\n",timevalues
[6][0],timevalues
[6][1],timevalues
[6][2]);
696 printf(" Sum All \t%lld\t%lld\t%lld\n",timevalues
[7][0],timevalues
[7][1],timevalues
[7][2]);
697 printf(" Sum GrBy 1% \t%lld\t%lld\t%lld\n",timevalues
[8][0],timevalues
[8][1],timevalues
[8][2]);
698 printf(" Distinct 1% \t%lld\t%lld\t%lld\n",timevalues
[9][0],timevalues
[9][1],timevalues
[9][2]);
699 printf(" Order By 1% \t%lld\t%lld\t%lld\n",timevalues
[10][0],timevalues
[10][1],timevalues
[10][2]);
700 printf(" Insert 1 \t%lld\t%lld\t%lld\n",timevalues
[11][0],timevalues
[11][1],timevalues
[11][2]);
701 printf(" Update 1 \t%lld\t%lld\t%lld\n",timevalues
[12][0],timevalues
[12][1],timevalues
[12][2]);
702 printf(" Delete 1 \t%lld\t%lld\t%lld\n",timevalues
[13][0],timevalues
[13][1],timevalues
[13][2]);
703 printf(" Join(10K*1K)1 \t%lld\t%lld\t%lld\n",timevalues
[14][0],timevalues
[14][1],timevalues
[14][2]);
704 printf(" Join(10K*10K*1K) \t%lld\t%lld\t%lld\n",timevalues
[15][0],timevalues
[15][1],timevalues
[15][2]);
705 printf(" Join(10K*1K)100 \t%lld\t%lld\t%lld\n",timevalues
[16][0],timevalues
[16][1],timevalues
[16][2]);
706 printf(" Join(10K*10K*1K)100 \t%lld\t%lld\t%lld\n",timevalues
[17][0],timevalues
[17][1],timevalues
[17][2]);
709 printf("*******************************************************\n");
713 int main (int ac
, char **av
)
720 if (ac
==2) mysql
= true;
721 //printf("Mysql Set %d \n", ac); return 0;
722 rc
= SQLAllocHandle (SQL_HANDLE_ENV
, SQL_NULL_HANDLE
, &henv
);
723 checkrc (rc
, __LINE__
);
724 SQLSetEnvAttr(henv
, SQL_ATTR_ODBC_VERSION
, (void *) SQL_OV_ODBC3
, 0);
726 rc
= SQLAllocHandle (SQL_HANDLE_DBC
, henv
, &hdbc
);
727 checkrc (rc
, __LINE__
);
729 rc
= SQLConnect (hdbc
,
730 (SQLCHAR
*) "test", (SQLSMALLINT
) strlen ("test"),
732 (SQLSMALLINT
) strlen ("root"),
733 (SQLCHAR
*) "manager",
734 (SQLSMALLINT
) strlen (""));
737 SQLCHAR outstr
[1024];
738 SQLSMALLINT outstrlen
;
739 rc
= SQLDriverConnect(hdbc
, NULL
, (SQLCHAR
*)"DSN=myodbc3;", SQL_NTS
,
740 outstr
, sizeof(outstr
), &outstrlen
,
741 SQL_DRIVER_NOPROMPT
);
745 if (SQL_SUCCEEDED(rc
)) {
746 printf("Connected\n");
747 //printf("Returned connection string was:\n\t%s\n", outstr);
748 if (rc
== SQL_SUCCESS_WITH_INFO
) {
749 printf("Driver reported the following diagnostics\n");
750 extract_error("SQLDriverConnect", hdbc
, SQL_HANDLE_DBC
);
753 fprintf(stderr
, "Failed to connect\n");
754 extract_error("SQLDriverConnect", hdbc
, SQL_HANDLE_DBC
);
757 //check_error (SQL_HANDLE_DBC, hdbc, rc, __LINE__);
758 checkrc (rc
, __LINE__
);
759 rc
= SQLSetConnectOption (hdbc
, SQL_AUTOCOMMIT
, SQL_AUTOCOMMIT_OFF
);
760 checkrc (rc
, __LINE__
);
761 rc
= SQLAllocHandle (SQL_HANDLE_STMT
, hdbc
, &hstmt
);
762 checkrc (rc
, __LINE__
);
763 int ins
=1,upd
=2,del
=3;
764 int min
=1, max
=2, sum
=3;
766 timevalues
[0][0] = runReadTest (henv
, hdbc
, hstmt
,true);
767 timevalues
[1][0] = runReadTest (henv
, hdbc
, hstmt
,false);
768 timevalues
[2][0] = onePerSel(henv
, hdbc
, hstmt
);
769 timevalues
[3][0] = aggregate(henv
, hdbc
, hstmt
,min
,true);
770 timevalues
[4][0] = aggregate(henv
, hdbc
, hstmt
,min
,false);
771 timevalues
[5][0] = aggregate(henv
, hdbc
, hstmt
,max
,true);
772 timevalues
[6][0] = aggregate(henv
, hdbc
, hstmt
,max
,false);
773 timevalues
[7][0] = aggregate(henv
, hdbc
, hstmt
,sum
,true);
774 timevalues
[8][0] = aggregate(henv
, hdbc
, hstmt
,sum
,false);
775 timevalues
[9][0] = distinct(henv
, hdbc
, hstmt
);
776 timevalues
[10][0] = orderBy(henv
, hdbc
, hstmt
);
777 timevalues
[11][0] = dmlstatement(henv
, hdbc
, hstmt
,ins
);
778 timevalues
[12][0] = dmlstatement(henv
, hdbc
, hstmt
,upd
);
779 timevalues
[13][0] = dmlstatement(henv
, hdbc
, hstmt
,del
);
780 timevalues
[14][0] = joining(henv
, hdbc
, hstmt
,1);
781 timevalues
[15][0] = joining(henv
, hdbc
, hstmt
,2);
782 timevalues
[16][0] = joinCondition(henv
, hdbc
, hstmt
,1);
783 timevalues
[17][0] = joinCondition(henv
, hdbc
, hstmt
,2);
784 printf("NON INDEX OVER\n");
786 rc
= SQLExecDirect(hstmt
, (SQLCHAR
*) "FLUSH CACHE", SQL_NTS
);
787 checkrc (rc
, __LINE__
);
791 createHashIndex( hstmt
,true);
793 timevalues
[0][1] = runReadTest (henv
, hdbc
, hstmt
,true);
794 timevalues
[1][1] = runReadTest (henv
, hdbc
, hstmt
,false);
795 timevalues
[2][1] = onePerSel(henv
, hdbc
, hstmt
);
796 timevalues
[3][1] = aggregate(henv
, hdbc
, hstmt
,min
,true);
797 timevalues
[4][1] = 0;
798 timevalues
[5][1] = 0;
799 timevalues
[6][1] = 0;
800 timevalues
[7][1] = 0;
801 timevalues
[8][1] = 0;
802 timevalues
[9][1] = distinct(henv
, hdbc
, hstmt
);
803 timevalues
[10][1] = orderBy(henv
, hdbc
, hstmt
);
804 timevalues
[11][1] = dmlstatement(henv
, hdbc
, hstmt
,ins
);
805 timevalues
[12][1] = dmlstatement(henv
, hdbc
, hstmt
,upd
);
806 timevalues
[13][1] = dmlstatement(henv
, hdbc
, hstmt
,del
);
807 timevalues
[14][1] = joining(henv
, hdbc
, hstmt
,1);
808 timevalues
[15][1] = joining(henv
, hdbc
, hstmt
,2);
810 timevalues
[16][1] = joinCondition(henv
, hdbc
, hstmt
,1);
811 timevalues
[17][1] = joinCondition(henv
, hdbc
, hstmt
,2);
812 dropHashIndex(hstmt
,true);
813 printf("HASH INDEX OVER\n");
818 rc
= SQLExecDirect(hstmt
, (SQLCHAR
*) "FLUSH CACHE", SQL_NTS
);
819 checkrc (rc
, __LINE__
);
824 createTreeIndex(hstmt
,true);
825 timevalues
[0][2] = runReadTest (henv
, hdbc
, hstmt
,true);
826 timevalues
[1][2] = runReadTest (henv
, hdbc
, hstmt
,false);
827 timevalues
[2][2] = onePerSel(henv
, hdbc
, hstmt
);
828 timevalues
[3][2] = aggregate(henv
, hdbc
, hstmt
,min
,true);
829 timevalues
[4][2] = 0;
830 timevalues
[5][2] = 0;
831 timevalues
[6][2] = 0;
832 timevalues
[7][2] = 0;
833 timevalues
[8][2] = 0;
834 timevalues
[9][2] = distinct(henv
, hdbc
, hstmt
);
835 timevalues
[10][2] = orderBy(henv
, hdbc
, hstmt
);
836 timevalues
[11][2] = dmlstatement(henv
, hdbc
, hstmt
,ins
);
837 timevalues
[12][2] = dmlstatement(henv
, hdbc
, hstmt
,upd
);
838 timevalues
[13][2] = dmlstatement(henv
, hdbc
, hstmt
,del
);
839 timevalues
[14][2] = joining(henv
, hdbc
, hstmt
,1);
840 timevalues
[15][2] = joining(henv
, hdbc
, hstmt
,2);
842 timevalues
[16][2] = joinCondition(henv
, hdbc
, hstmt
,1);
843 timevalues
[17][2] = joinCondition(henv
, hdbc
, hstmt
,2);
845 dropTreeIndex(hstmt
,true);
846 printf("TREE INDEX OVER\n");
851 rc
= SQLEndTran(SQL_HANDLE_DBC
, hdbc
, SQL_COMMIT
);
852 checkrc (rc
, __LINE__
);
854 rc
= SQLFreeHandle (SQL_HANDLE_STMT
, hstmt
);
855 checkrc (rc
, __LINE__
);
856 rc
= SQLDisconnect (hdbc
);
857 checkrc (rc
, __LINE__
);
858 rc
= SQLFreeHandle (SQL_HANDLE_DBC
, hdbc
);
859 checkrc (rc
, __LINE__
);
860 rc
= SQLFreeHandle (SQL_HANDLE_ENV
, henv
);
861 checkrc (rc
, __LINE__
);