#include <my_global.h>#include <my_sys.h>#include <hash.h>#include <m_string.h>Include dependency graph for testhash.c:

Go to the source code of this file.
Defines | |
| #define | MAX_RECORDS 100000 |
| #define | MAX_KEYS 3 |
Functions | |
| static int | get_options (int argc, char *argv[]) |
| static int | do_test () |
| static int | rnd (int max_value) |
| my_bool | hash_check (HASH *hash) |
| void | free_record (void *record) |
| static byte * | hash2_key (const byte *rec, uint *length, my_bool not_used __attribute__((unused))) |
| int | main (int argc, char *argv[]) |
| static int | get_options (int argc, char **argv) |
Variables | |
| static uint | testflag = 0 |
| static uint | recant = 10000 |
| static uint | reclength = 37 |
| static uint16 | key1 [1000] |
| #define MAX_KEYS 3 |
| #define MAX_RECORDS 100000 |
| static int do_test | ( | ) | [static] |
Definition at line 61 of file testhash.c.
References atoi(), bzero, DBUG_ENTER, DBUG_RETURN, default_charset_info, err, free_record(), hash(), hash2_key(), hash_check(), hash_delete(), hash_element(), hash_first(), hash_free(), hash_init, hash_next(), hash_search(), hash_update(), key, key1, MAX_RECORDS, memcpy, min, my_end(), my_errno, MY_FAE, MY_GIVE_INFO, my_hash_insert(), my_malloc(), MYF, pos(), recant, reclength, rnd, testflag, and update.
Referenced by main().
00062 { 00063 register uint i,j; 00064 uint n1,n2,n3; 00065 uint write_count,update,delete; 00066 ulong pos; 00067 unsigned long key_check; 00068 char *record,*recpos,oldrecord[120],key[10]; 00069 HASH hash,hash2; 00070 DBUG_ENTER("do_test"); 00071 00072 write_count=update=delete=0; 00073 key_check=0; 00074 bzero((char*) key1,sizeof(key1[0])*1000); 00075 00076 printf("- Creating hash\n"); 00077 if (hash_init(&hash, default_charset_info, recant/2, 0, 6, 0, free_record, 0)) 00078 goto err; 00079 printf("- Writing records:\n"); 00080 00081 for (i=0 ; i < recant ; i++) 00082 { 00083 n1=rnd(1000); n2=rnd(100); n3=rnd(min(recant*5,MAX_RECORDS)); 00084 record= (char*) my_malloc(reclength,MYF(MY_FAE)); 00085 sprintf(record,"%6d:%4d:%8d:Pos: %4d ",n1,n2,n3,write_count); 00086 if (my_hash_insert(&hash,record)) 00087 { 00088 printf("Error: %d in write at record: %d\n",my_errno,i); 00089 goto err; 00090 } 00091 key1[n1]++; 00092 key_check+=n1; 00093 write_count++; 00094 } 00095 if (hash_check(&hash)) 00096 { 00097 puts("Heap keys crashed"); 00098 goto err; 00099 } 00100 printf("- Delete\n"); 00101 for (i=0 ; i < write_count/10 ; i++) 00102 { 00103 for (j=rnd(1000) ; j>0 && key1[j] == 0 ; j--) ; 00104 if (j != 0) 00105 { 00106 sprintf(key,"%6d",j); 00107 if (!(recpos=hash_search(&hash,key,0))) 00108 { 00109 printf("can't find key1: \"%s\"\n",key); 00110 goto err; 00111 } 00112 key1[atoi(recpos)]--; 00113 key_check-=atoi(recpos); 00114 memcpy(oldrecord,recpos,reclength); 00115 if (hash_delete(&hash,recpos)) 00116 { 00117 printf("error: %d; can't delete record: \"%s\"\n", my_errno,oldrecord); 00118 goto err; 00119 } 00120 delete++; 00121 if (testflag == 2 && hash_check(&hash)) 00122 { 00123 puts("Heap keys crashed"); 00124 goto err; 00125 } 00126 } 00127 } 00128 if (hash_check(&hash)) 00129 { 00130 puts("Hash keys crashed"); 00131 goto err; 00132 } 00133 00134 printf("- Update\n"); 00135 for (i=0 ; i < write_count/10 ; i++) 00136 { 00137 n1=rnd(1000); n2=rnd(100); n3=rnd(min(recant*2,MAX_RECORDS)); 00138 for (j=rnd(1000) ; j>0 && key1[j] == 0 ; j--) ; 00139 if (j) 00140 { 00141 sprintf(key,"%6d",j); 00142 if (!(recpos=hash_search(&hash,key,0))) 00143 { 00144 printf("can't find key1: \"%s\"\n",key); 00145 goto err; 00146 } 00147 key1[atoi(recpos)]--; 00148 key_check=key_check-atoi(recpos)+n1; 00149 key1[n1]++; 00150 sprintf(recpos,"%6d:%4d:%8d:XXX: %4d ",n1,n2,n3,update); 00151 update++; 00152 if (hash_update(&hash,recpos,key,0)) 00153 { 00154 printf("can't update key1: \"%s\"\n",key); 00155 goto err; 00156 } 00157 if (testflag == 3 && hash_check(&hash)) 00158 { 00159 printf("Heap keys crashed for %d update\n",update); 00160 goto err; 00161 } 00162 } 00163 } 00164 if (hash_check(&hash)) 00165 { 00166 puts("Heap keys crashed"); 00167 goto err; 00168 } 00169 00170 for (j=0 ; j < 1000 ; j++) 00171 if (key1[j] > 1) 00172 break; 00173 if (key1[j] > 1) 00174 { 00175 HASH_SEARCH_STATE state; 00176 printf("- Testing identical read\n"); 00177 sprintf(key,"%6d",j); 00178 pos=1; 00179 if (!(recpos= hash_first(&hash, key, 0, &state))) 00180 { 00181 printf("can't find key1: \"%s\"\n",key); 00182 goto err; 00183 } 00184 while (hash_next(&hash, key, 0, &state) && pos < (ulong) (key1[j]+10)) 00185 pos++; 00186 if (pos != (ulong) key1[j]) 00187 { 00188 printf("Found %ld copies of key: %s. Should be %d",pos,key,key1[j]); 00189 goto err; 00190 } 00191 } 00192 printf("- Creating output heap-file 2\n"); 00193 if (hash_init(&hash2, default_charset_info, hash.records, 0, 0, hash2_key, free_record,0)) 00194 goto err; 00195 00196 printf("- Copying and removing records\n"); 00197 pos=0; 00198 while ((recpos=hash_element(&hash,0))) 00199 { 00200 record=(byte*) my_malloc(reclength,MYF(MY_FAE)); 00201 memcpy(record,recpos,reclength); 00202 record[reclength-1]=rnd(5)+1; 00203 if (my_hash_insert(&hash2,record)) 00204 { 00205 printf("Got error when inserting record: %*s",reclength,record); 00206 goto err; 00207 } 00208 key_check-=atoi(record); 00209 write_count++; 00210 if (hash_delete(&hash,recpos)) 00211 { 00212 printf("Got error when deleting record: %*s",reclength,recpos); 00213 goto err; 00214 } 00215 if (testflag==4) 00216 { 00217 if (hash_check(&hash) || hash_check(&hash2)) 00218 { 00219 puts("Hash keys crashed"); 00220 goto err; 00221 } 00222 } 00223 pos++; 00224 } 00225 if (hash_check(&hash) || hash_check(&hash2)) 00226 { 00227 puts("Hash keys crashed"); 00228 goto err; 00229 } 00230 if (key_check != 0) 00231 { 00232 printf("Key check didn't get to 0 (%ld)\n",key_check); 00233 } 00234 00235 printf("\nFollowing test have been made:\n"); 00236 printf("Write records: %d\nUpdate records: %d\nDelete records: %d\n", write_count, 00237 update,delete); 00238 hash_free(&hash); hash_free(&hash2); 00239 my_end(MY_GIVE_INFO); 00240 DBUG_RETURN(0); 00241 err: 00242 printf("Got error: %d when using hashing\n",my_errno); 00243 DBUG_RETURN(-1); 00244 } /* main */
Here is the call graph for this function:

Here is the caller graph for this function:

| void free_record | ( | void * | record | ) |
| static int get_options | ( | int | argc, | |
| char ** | argv | |||
| ) | [static] |
Definition at line 250 of file testhash.c.
References atoi(), DBUG_PUSH, exit, MACHINE_TYPE, pos(), progname, recant, SYSTEM_TYPE, and testflag.
00251 { 00252 char *pos,*progname; 00253 00254 progname= argv[0]; 00255 00256 while (--argc >0 && *(pos = *(++argv)) == '-' ) { 00257 switch(*++pos) { 00258 case 'm': /* records */ 00259 recant=atoi(++pos); 00260 break; 00261 case 't': 00262 testflag=atoi(++pos); /* testmod */ 00263 break; 00264 case 'V': 00265 case 'I': 00266 case '?': 00267 printf("%s Ver 1.0 for %s at %s\n",progname,SYSTEM_TYPE,MACHINE_TYPE); 00268 printf("MySQL AB, by Monty\n\n"); 00269 printf("Usage: %s [-?ABIKLWv] [-m#] [-t#]\n",progname); 00270 exit(0); 00271 case '#': 00272 DBUG_PUSH (++pos); 00273 break; 00274 } 00275 } 00276 return 0; 00277 } /* get_options */
Here is the call graph for this function:

| static int get_options | ( | int | argc, | |
| char * | argv[] | |||
| ) | [static] |
Definition at line 615 of file hash.c.
References data, DBUG_PRINT, dynamic_element, error, hash(), hash_rec_mask(), st_hash_link::next, NO_RECORD, and records.
00616 { 00617 int error; 00618 uint i,rec_link,found,max_links,seek,links,idx; 00619 uint records,blength; 00620 HASH_LINK *data,*hash_info; 00621 00622 records=hash->records; blength=hash->blength; 00623 data=dynamic_element(&hash->array,0,HASH_LINK*); 00624 error=0; 00625 00626 for (i=found=max_links=seek=0 ; i < records ; i++) 00627 { 00628 if (hash_rec_mask(hash,data+i,blength,records) == i) 00629 { 00630 found++; seek++; links=1; 00631 for (idx=data[i].next ; 00632 idx != NO_RECORD && found < records + 1; 00633 idx=hash_info->next) 00634 { 00635 if (idx >= records) 00636 { 00637 DBUG_PRINT("error", 00638 ("Found pointer outside array to %d from link starting at %d", 00639 idx,i)); 00640 error=1; 00641 } 00642 hash_info=data+idx; 00643 seek+= ++links; 00644 if ((rec_link=hash_rec_mask(hash,hash_info,blength,records)) != i) 00645 { 00646 DBUG_PRINT("error", 00647 ("Record in wrong link at %d: Start %d Record: 0x%lx Record-link %d", idx,i,hash_info->data,rec_link)); 00648 error=1; 00649 } 00650 else 00651 found++; 00652 } 00653 if (links > max_links) max_links=links; 00654 } 00655 } 00656 if (found != records) 00657 { 00658 DBUG_PRINT("error",("Found %ld of %ld records")); 00659 error=1; 00660 } 00661 if (records) 00662 DBUG_PRINT("info", 00663 ("records: %ld seeks: %d max links: %d hitrate: %.2f", 00664 records,seek,max_links,(float) seek / (float) records)); 00665 return error; 00666 }
Here is the call graph for this function:

| int main | ( | int | argc, | |
| char * | argv[] | |||
| ) |
Definition at line 51 of file testhash.c.
References DBUG_PROCESS, do_test(), exit, get_options(), and MY_INIT.
00052 { 00053 MY_INIT(argv[0]); 00054 DBUG_PROCESS(argv[0]); 00055 00056 get_options(argc,argv); 00057 00058 exit(do_test()); 00059 }
Here is the call graph for this function:

| static int rnd | ( | int | max_value | ) | [static] |
Definition at line 32 of file testhash.c.
Referenced by and_all_keys(), do_test(), key_and(), key_or(), main(), operator>=(), NdbIndexStat::records_in_range(), sel_add(), sel_trees_can_be_ored(), tree_and(), and tree_or().
Definition at line 31 of file testhash.c.
Referenced by _mi_cmp_dynamic_record(), _mi_update_blob_record(), _mi_write_blob_record(), _mi_write_dynamic_record(), create_tmp_table(), do_test(), get_statistic(), hash2_key(), main(), make_record(), mi_create(), mysql_create_frm(), pack_header(), remove_dup_with_compare(), remove_duplicates(), and sort_write_record().
Definition at line 31 of file testhash.c.
Referenced by do_test(), get_options(), main(), and ha_myisam::repair().
1.4.7

