2 * Copyright (C) 1994-1999, Index Data
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.12 1999-07-06 12:28:04 adam
8 * Updated record index structure. Format includes version ID. Compression
9 * algorithm ID is stored for each record block.
11 * Revision 1.11 1999/05/15 14:36:38 adam
12 * Updated dictionary. Implemented "compression" of dictionary.
14 * Revision 1.10 1999/05/12 13:08:06 adam
15 * First version of ISAMS.
17 * Revision 1.9 1999/02/12 13:29:23 adam
18 * Implemented position-flag for registers.
20 * Revision 1.8 1999/02/02 14:50:53 adam
21 * Updated WIN32 code specific sections. Changed header.
23 * Revision 1.7 1998/03/13 15:30:50 adam
24 * New functions isc_block_used and isc_block_size. Fixed 'leak'
27 * Revision 1.6 1998/03/06 13:54:02 adam
28 * Fixed two nasty bugs in isc_merge.
30 * Revision 1.5 1997/09/17 12:19:13 adam
31 * Zebra version corresponds to YAZ version 1.4.
32 * Changed Zebra server so that it doesn't depend on global common_resource.
34 * Revision 1.4 1996/11/08 11:10:21 adam
35 * Buffers used during file match got bigger.
36 * Compressed ISAM support everywhere.
37 * Bug fixes regarding masking characters in queries.
38 * Redesigned Regexp-2 queries.
40 * Revision 1.3 1996/06/04 10:18:58 adam
41 * Minor changes - removed include of ctype.h.
43 * Revision 1.2 1996/05/22 08:25:56 adam
46 * Revision 1.1 1996/05/14 14:04:34 adam
47 * In zebraidx, the 'stat' command is improved. Statistics about ISAM/DICT
58 struct inv_stat_info {
62 int no_isam_entries[8];
66 int isam_occurrences[20];
70 static int inv_stat_handle (char *name, const char *info, int pos,
75 struct inv_stat_info *stat_info = (struct inv_stat_info*) client;
78 stat_info->no_dict_entries++;
79 stat_info->no_dict_bytes += strlen(name);
81 assert (*info == sizeof(ISAM_P));
82 memcpy (&isam_p, info+1, sizeof(ISAM_P));
89 ispt = is_position (stat_info->isam, isam_p);
90 occur = is_numkeys (ispt);
99 pp = isc_pp_open (stat_info->isamc, isam_p);
100 occur = isc_pp_num (pp);
101 while (isc_pp_read(pp, &key))
103 printf ("sysno=%d seqno=%d\n", key.sysno, key.seqno);
106 assert (occurx == occur);
107 stat_info->no_isam_entries[isc_type(isam_p)] += occur;
110 if (stat_info->isams)
116 pp = isams_pp_open (stat_info->isams, isam_p);
117 occur = isams_pp_num (pp);
118 while (isams_pp_read(pp, &key))
120 printf ("sysno=%d seqno=%d\n", key.sysno, key.seqno);
123 assert (occurx == occur);
124 stat_info->no_isam_entries[isc_type(isam_p)] += occur;
128 while (occur > stat_info->isam_bounds[i] && stat_info->isam_bounds[i])
130 ++(stat_info->isam_occurrences[i]);
134 void inv_prstat (BFiles bfs)
143 int after = 1000000000;
144 struct inv_stat_info stat_info;
145 char term_dict[2*IT_MAX_WORD+2];
150 dict = dict_open (bfs, FNAME_DICT, 100, 0, 0);
153 logf (LOG_FATAL, "dict_open fail");
156 if (res_get_match (common_resource, "isam", "i", NULL))
158 isam = is_open (bfs, FNAME_ISAM, key_compare, 0,
159 sizeof(struct it_key), common_resource);
162 logf (LOG_FATAL, "is_open fail");
166 else if (res_get_match (common_resource, "isam", "s", NULL))
168 isams = isams_open (bfs, FNAME_ISAMS, 0, key_isams_m(common_resource));
171 logf (LOG_FATAL, "isams_open fail");
177 isamc = isc_open (bfs, FNAME_ISAMC, 0, key_isamc_m (common_resource));
180 logf (LOG_FATAL, "isc_open fail");
184 records = rec_open (bfs, 0, 0);
186 for (i = 0; i<8; i++)
187 stat_info.no_isam_entries[i] = 0;
188 stat_info.no_dict_entries = 0;
189 stat_info.no_dict_bytes = 0;
190 stat_info.isam = isam;
191 stat_info.isamc = isamc;
192 stat_info.isams = isams;
193 stat_info.isam_bounds[0] = 1;
194 stat_info.isam_bounds[1] = 2;
195 stat_info.isam_bounds[2] = 3;
196 stat_info.isam_bounds[3] = 6;
197 stat_info.isam_bounds[4] = 10;
198 stat_info.isam_bounds[5] = 20;
199 stat_info.isam_bounds[6] = 30;
200 stat_info.isam_bounds[7] = 50;
201 stat_info.isam_bounds[8] = 100;
202 stat_info.isam_bounds[9] = 200;
203 stat_info.isam_bounds[10] = 5000;
204 stat_info.isam_bounds[11] = 10000;
205 stat_info.isam_bounds[12] = 20000;
206 stat_info.isam_bounds[13] = 50000;
207 stat_info.isam_bounds[14] = 100000;
208 stat_info.isam_bounds[15] = 200000;
209 stat_info.isam_bounds[16] = 500000;
210 stat_info.isam_bounds[17] = 1000000;
211 stat_info.isam_bounds[18] = 0;
213 for (i = 0; i<20; i++)
214 stat_info.isam_occurrences[i] = 0;
216 dict_scan (dict, term_dict, &before, &after, &stat_info, inv_stat_handle);
220 fprintf (stderr, " Blocks Occur Size KB Bytes/Entry\n");
221 for (i = 0; isc_block_used (isamc, i) >= 0; i++)
223 fprintf (stderr, " %8d %8d", isc_block_used (isamc, i),
224 stat_info.no_isam_entries[i]);
226 if (stat_info.no_isam_entries[i])
227 fprintf (stderr, " %8d %f",
228 (int) ((1023.0 + (double) isc_block_used(isamc, i) *
229 isc_block_size(isamc,i))/1024),
230 ((double) isc_block_used(isamc, i) *
231 isc_block_size(isamc,i))/
232 stat_info.no_isam_entries[i]);
233 fprintf (stderr, "\n");
237 fprintf (stderr, "\n%d words using %d bytes\n",
238 stat_info.no_dict_entries, stat_info.no_dict_bytes);
239 fprintf (stderr, " Occurrences Words\n");
241 for (i = 0; stat_info.isam_bounds[i]; i++)
243 int here = stat_info.isam_bounds[i];
244 fprintf (stderr, "%7d-%-7d %7d\n",
245 prev, here, stat_info.isam_occurrences[i]);
248 fprintf (stderr, "%7d- %7d\n",
249 prev, stat_info.isam_occurrences[i]);
251 rec_close (&records);