1 | /* |
2 | * $Id: dss.h,v 1.10 2008/03/21 18:07:13 jms Exp $ |
3 | * |
4 | * Revision History |
5 | * =================== |
6 | * $Log: dss.h,v $ |
7 | * Revision 1.10 2008/03/21 18:07:13 jms |
8 | * update copyright date |
9 | * |
10 | * Revision 1.9 2006/07/31 17:23:09 jms |
11 | * fix to parallelism problem |
12 | * |
13 | * Revision 1.8 2006/03/09 18:55:29 jms |
14 | * remove vestigial cvs merge marker |
15 | * |
16 | * Revision 1.7 2005/10/28 03:05:05 jms |
17 | * up maximum scale to 100TB |
18 | * |
19 | * Revision 1.6 2005/10/28 02:55:26 jms |
20 | * add release.h changes |
21 | * |
22 | * Revision 1.5 2005/10/27 18:13:03 jms |
23 | * a_rnd() prototype correction |
24 | * |
25 | * Revision 1.4 2005/10/25 17:58:59 jms |
26 | * update version stamp |
27 | * |
28 | * Revision 1.3 2005/03/04 19:48:39 jms |
29 | * Changes from Doug Johnson to address very large scale factors |
30 | * |
31 | * Revision 1.2 2005/01/03 20:08:58 jms |
32 | * change line terminations |
33 | * |
34 | * Revision 1.1.1.1 2004/11/24 23:31:46 jms |
35 | * re-establish external server |
36 | * |
37 | * Revision 1.5 2004/04/08 17:34:15 jms |
38 | * cleanup SOLARIS/SUN ifdefs; now all use SUN |
39 | * |
40 | * Revision 1.4 2004/04/07 20:17:29 jms |
41 | * bug #58 (join fails between order/lineitem) |
42 | * |
43 | * Revision 1.3 2004/03/16 14:37:53 jms |
44 | * update version and copyright date; correct comment typo |
45 | * |
46 | * Revision 1.2 2004/02/18 14:07:20 jms |
47 | * change to version 2.1.0 |
48 | * |
49 | * Revision 1.1.1.1 2003/08/08 21:50:33 jms |
50 | * recreation after CVS crash |
51 | * |
52 | * Revision 1.3 2003/08/08 21:35:26 jms |
53 | * first integration of rng64 for o_custkey and l_partkey |
54 | * |
55 | * Revision 1.2 2003/08/07 17:58:34 jms |
56 | * Convery RNG to 64bit space as preparation for new large scale RNG |
57 | * |
58 | * Revision 1.1.1.1 2003/04/03 18:54:21 jms |
59 | * initial checkin |
60 | * |
61 | * |
62 | */ |
63 | /* |
64 | * general definitions and control information for the DSS code |
65 | * generator; if it controls the data set, it's here |
66 | */ |
67 | #ifndef DSS_H |
68 | #define DSS_H |
69 | #ifdef TPCH |
70 | #define NAME "TPC-H" |
71 | #endif |
72 | #ifdef TPCR |
73 | #define NAME "TPC-R" |
74 | #endif |
75 | #ifndef NAME |
76 | #error Benchmark version must be defined in config.h |
77 | #endif |
78 | #define TPC "Transaction Processing Performance Council" |
79 | #define C_DATES "1994 - 2010" |
80 | |
81 | #include "config.h" |
82 | #include "shared.h" |
83 | |
84 | #include <stdio.h> |
85 | #include <stdlib.h> |
86 | |
87 | #define NONE -1 |
88 | #define PART 0 |
89 | #define PSUPP 1 |
90 | #define SUPP 2 |
91 | #define CUST 3 |
92 | #define ORDER 4 |
93 | #define LINE 5 |
94 | #define ORDER_LINE 6 |
95 | #define PART_PSUPP 7 |
96 | #define NATION 8 |
97 | #define REGION 9 |
98 | #define UPDATE 10 |
99 | #define MAX_TABLE 11 |
100 | #define ONE_STREAM 1 |
101 | #define ADD_AT_END 2 |
102 | |
103 | #ifdef MAX |
104 | #undef MAX |
105 | #endif |
106 | #ifdef MIN |
107 | #undef MIN |
108 | #endif |
109 | #define MAX(a,b) ((a > b )?a:b) |
110 | #define MIN(A,B) ( (A) < (B) ? (A) : (B)) |
111 | |
112 | #define INTERNAL_ERROR(p) {fprintf(stderr,"%s", p);abort();} |
113 | #define LN_CNT 4 |
114 | static char lnoise[4] = {'|', '/', '-', '\\' }; |
115 | #define LIFENOISE(n, var) \ |
116 | if (verbose > 0) fprintf(stderr, "%c\b", lnoise[(var%LN_CNT)]) |
117 | |
118 | #define MALLOC_CHECK(var) \ |
119 | if ((var) == NULL) \ |
120 | { \ |
121 | fprintf(stderr, "Malloc failed at %s:%d\n", \ |
122 | __FILE__, __LINE__); \ |
123 | exit(1);\ |
124 | } |
125 | #define OPEN_CHECK(var, path) \ |
126 | if ((var) == NULL) \ |
127 | { \ |
128 | fprintf(stderr, "Open failed for %s at %s:%d\n", \ |
129 | path, __FILE__, __LINE__); \ |
130 | exit(1);\ |
131 | } |
132 | #ifndef MAX_CHILDREN |
133 | #define MAX_CHILDREN 1000 |
134 | #endif |
135 | |
136 | /* |
137 | * macros that control sparse keys |
138 | * |
139 | * refer to Porting.Notes for a complete explanation |
140 | */ |
141 | #ifndef BITS_PER_LONG |
142 | #define BITS_PER_LONG 32 |
143 | #define MAX_LONG 0x7FFFFFFF |
144 | #endif /* BITS_PER_LONG */ |
145 | #define SPARSE_BITS 2 |
146 | #define SPARSE_KEEP 3 |
147 | #define MK_SPARSE(key, seq) \ |
148 | (((((key>>3)<<2)|(seq & 0x0003))<<3)|(key & 0x0007)) |
149 | |
150 | #define RANDOM(tgt, lower, upper, stream) dss_random(&tgt, lower, upper, stream) |
151 | #define RANDOM64(tgt, lower, upper, stream) dss_random64(&tgt, lower, upper, stream) |
152 | |
153 | |
154 | |
155 | typedef struct |
156 | { |
157 | long weight; |
158 | char *text; |
159 | } set_member; |
160 | |
161 | typedef struct |
162 | { |
163 | int count; |
164 | int max; |
165 | set_member *list; |
166 | long *permute; |
167 | } distribution; |
168 | /* |
169 | * some handy access functions |
170 | */ |
171 | #define DIST_SIZE(d) d->count |
172 | #define DIST_MEMBER(d, i) ((set_member *)((d)->list + i))->text |
173 | #define DIST_PERMUTE(d, i) (d->permute[i]) |
174 | |
175 | typedef struct |
176 | { |
177 | char *name; |
178 | char *; |
179 | DSS_HUGE base; |
180 | int (*loader) (); |
181 | long (*gen_seed)(); |
182 | int child; |
183 | DSS_HUGE vtotal; |
184 | } tdef; |
185 | |
186 | typedef struct SEED_T { |
187 | long table; |
188 | DSS_HUGE value; |
189 | DSS_HUGE usage; |
190 | DSS_HUGE boundary; |
191 | #ifdef RNG_TEST |
192 | DSS_HUGE nCalls; |
193 | #endif |
194 | } seed_t; |
195 | |
196 | |
197 | #if defined(__STDC__) |
198 | #define PROTO(s) s |
199 | #else |
200 | #define PROTO(s) () |
201 | #endif |
202 | |
203 | /* bm_utils.c */ |
204 | char *env_config PROTO((char *var, char *dflt)); |
205 | long yes_no PROTO((char *prompt)); |
206 | void a_rnd PROTO((int min, int max, int column, char *dest)); |
207 | int tx_rnd PROTO((long min, long max, long column, char *tgt)); |
208 | long julian PROTO((long date)); |
209 | long unjulian PROTO((long date)); |
210 | FILE *tbl_open PROTO((int tbl, char *mode)); |
211 | long dssncasecmp PROTO((char *s1, char *s2, int n)); |
212 | long dsscasecmp PROTO((char *s1, char *s2)); |
213 | int pick_str PROTO((distribution * s, int c, char *target)); |
214 | void agg_str PROTO((distribution *set, long count, long col, char *dest)); |
215 | void read_dist PROTO((char *path, char *name, distribution * target)); |
216 | void embed_str PROTO((distribution *d, int min, int max, int stream, char *dest)); |
217 | #ifndef STDLIB_HAS_GETOPT |
218 | int getopt PROTO((int arg_cnt, char **arg_vect, char *oprions)); |
219 | #endif /* STDLIB_HAS_GETOPT */ |
220 | DSS_HUGE set_state PROTO((int t, long scale, long procs, long step, DSS_HUGE *e)); |
221 | |
222 | /* rnd.c */ |
223 | DSS_HUGE NextRand PROTO((DSS_HUGE nSeed)); |
224 | DSS_HUGE UnifInt PROTO((DSS_HUGE nLow, DSS_HUGE nHigh, long nStream)); |
225 | void dss_random(DSS_HUGE *tgt, DSS_HUGE min, DSS_HUGE max, long seed); |
226 | void row_start(int t); |
227 | void row_stop(int t); |
228 | void dump_seeds(int t); |
229 | |
230 | /* text.c */ |
231 | #define MAX_GRAMMAR_LEN 12 /* max length of grammar component */ |
232 | #define MAX_SENT_LEN 256 /* max length of populated sentence */ |
233 | #define RNG_PER_SENT 27 /* max number of RNG calls per sentence */ |
234 | |
235 | void dbg_text PROTO((char * t, int min, int max, int s)); |
236 | |
237 | #ifdef DECLARER |
238 | #define EXTERN |
239 | #else |
240 | #define EXTERN extern |
241 | #endif /* DECLARER */ |
242 | |
243 | |
244 | EXTERN distribution nations; |
245 | EXTERN distribution nations2; |
246 | EXTERN distribution regions; |
247 | EXTERN distribution o_priority_set; |
248 | EXTERN distribution l_instruct_set; |
249 | EXTERN distribution l_smode_set; |
250 | EXTERN distribution l_category_set; |
251 | EXTERN distribution l_rflag_set; |
252 | EXTERN distribution c_mseg_set; |
253 | EXTERN distribution colors; |
254 | EXTERN distribution p_types_set; |
255 | EXTERN distribution p_cntr_set; |
256 | |
257 | /* distributions that control text generation */ |
258 | EXTERN distribution articles; |
259 | EXTERN distribution nouns; |
260 | EXTERN distribution adjectives; |
261 | EXTERN distribution adverbs; |
262 | EXTERN distribution prepositions; |
263 | EXTERN distribution verbs; |
264 | EXTERN distribution terminators; |
265 | EXTERN distribution auxillaries; |
266 | EXTERN distribution np; |
267 | EXTERN distribution vp; |
268 | EXTERN distribution grammar; |
269 | |
270 | |
271 | EXTERN long scale; |
272 | EXTERN int refresh; |
273 | EXTERN int resume; |
274 | EXTERN long verbose; |
275 | EXTERN long force; |
276 | EXTERN long updates; |
277 | EXTERN long table; |
278 | EXTERN long children; |
279 | EXTERN int step; |
280 | EXTERN int set_seeds; |
281 | EXTERN char *d_path; |
282 | |
283 | /* added for segmented updates */ |
284 | EXTERN int insert_segments; |
285 | EXTERN int delete_segments; |
286 | EXTERN int insert_orders_segment; |
287 | EXTERN int insert_lineitem_segment; |
288 | EXTERN int delete_segment; |
289 | |
290 | |
291 | #ifndef DECLARER |
292 | extern tdef tdefs[]; |
293 | |
294 | #endif /* DECLARER */ |
295 | |
296 | |
297 | /***************************************************************** |
298 | ** table level defines use the following naming convention: t_ccc_xxx |
299 | ** with: t, a table identifier |
300 | ** ccc, a column identifier |
301 | ** xxx, a limit type |
302 | **************************************************************** |
303 | */ |
304 | |
305 | /* |
306 | * defines which control the parts table |
307 | */ |
308 | #define P_SIZE 126 |
309 | #define P_NAME_SCL 5 |
310 | #define P_MFG_TAG "Manufacturer#" |
311 | #define P_MFG_FMT "%%s%%0%d%s" |
312 | #define P_MFG_MIN 1 |
313 | #define P_MFG_MAX 5 |
314 | #define P_BRND_TAG "Brand#" |
315 | #define P_BRND_FMT "%%s%%0%d%s" |
316 | #define P_BRND_MIN 1 |
317 | #define P_BRND_MAX 5 |
318 | #define P_SIZE_MIN 1 |
319 | #define P_SIZE_MAX 50 |
320 | #define P_MCST_MIN 100 |
321 | #define P_MCST_MAX 99900 |
322 | #define P_MCST_SCL 100.0 |
323 | #define P_RCST_MIN 90000 |
324 | #define P_RCST_MAX 200000 |
325 | #define P_RCST_SCL 100.0 |
326 | /* |
327 | * defines which control the suppliers table |
328 | */ |
329 | #define S_SIZE 145 |
330 | #define S_NAME_TAG "Supplier#" |
331 | #define S_NAME_FMT "%%s%%0%d%s" |
332 | #define S_ABAL_MIN -99999 |
333 | #define S_ABAL_MAX 999999 |
334 | #define S_CMNT_MAX 101 |
335 | #define S_CMNT_BBB 10 /* number of BBB comments/SF */ |
336 | #define BBB_DEADBEATS 50 /* % that are complaints */ |
337 | #define BBB_BASE "Customer " |
338 | #define BBB_COMPLAIN "Complaints" |
339 | #define BBB_COMMEND "Recommends" |
340 | #define BBB_CMNT_LEN 19 |
341 | #define BBB_BASE_LEN 9 |
342 | #define BBB_TYPE_LEN 10 |
343 | |
344 | /* |
345 | * defines which control the partsupp table |
346 | */ |
347 | #define PS_SIZE 145 |
348 | #define PS_SKEY_MIN 0 |
349 | #define PS_SKEY_MAX ((tdefs[SUPP].base - 1) * scale) |
350 | #define PS_SCST_MIN 100 |
351 | #define PS_SCST_MAX 100000 |
352 | #define PS_QTY_MIN 1 |
353 | #define PS_QTY_MAX 9999 |
354 | /* |
355 | * defines which control the customers table |
356 | */ |
357 | #define C_SIZE 165 |
358 | #define C_NAME_TAG "Customer#" |
359 | #define C_NAME_FMT "%%s%%0%d%s" |
360 | #define C_MSEG_MAX 5 |
361 | #define C_ABAL_MIN -99999 |
362 | #define C_ABAL_MAX 999999 |
363 | /* |
364 | * defines which control the order table |
365 | */ |
366 | #define O_SIZE 109 |
367 | #define O_CKEY_MIN 1 |
368 | #define O_CKEY_MAX (tdefs[CUST].base * scale) |
369 | #define O_ODATE_MIN STARTDATE |
370 | #define O_ODATE_MAX (STARTDATE + TOTDATE - \ |
371 | (L_SDTE_MAX + L_RDTE_MAX) - 1) |
372 | #define O_CLRK_TAG "Clerk#" |
373 | #define O_CLRK_FMT "%%s%%0%d%s" |
374 | #define O_CLRK_SCL 1000 |
375 | #define O_LCNT_MIN 1 |
376 | #define O_LCNT_MAX 7 |
377 | |
378 | /* |
379 | * defines which control the lineitem table |
380 | */ |
381 | #define L_SIZE 144L |
382 | #define L_QTY_MIN 1 |
383 | #define L_QTY_MAX 50 |
384 | #define L_TAX_MIN 0 |
385 | #define L_TAX_MAX 8 |
386 | #define L_DCNT_MIN 0 |
387 | #define L_DCNT_MAX 10 |
388 | #define L_PKEY_MIN 1 |
389 | #define L_PKEY_MAX (tdefs[PART].base * scale) |
390 | #define L_SDTE_MIN 1 |
391 | #define L_SDTE_MAX 121 |
392 | #define L_CDTE_MIN 30 |
393 | #define L_CDTE_MAX 90 |
394 | #define L_RDTE_MIN 1 |
395 | #define L_RDTE_MAX 30 |
396 | /* |
397 | * defines which control the time table |
398 | */ |
399 | #define T_SIZE 30 |
400 | #define T_START_DAY 3 /* wednesday ? */ |
401 | #define LEAP(y) ((!(y % 4) && (y % 100))?1:0) |
402 | |
403 | /******************************************************************* |
404 | ******************************************************************* |
405 | *** |
406 | *** general or inter table defines |
407 | *** |
408 | ******************************************************************* |
409 | *******************************************************************/ |
410 | #define SUPP_PER_PART 4 |
411 | #define ORDERS_PER_CUST 10 /* sync this with CUST_MORTALITY */ |
412 | #define CUST_MORTALITY 3 /* portion with have no orders */ |
413 | #define NATIONS_MAX 90 /* limited by country codes in phone numbers */ |
414 | #define PHONE_FMT "%02d-%03d-%03d-%04d" |
415 | #define STARTDATE 92001 |
416 | #define CURRENTDATE 95168 |
417 | #define ENDDATE 98365 |
418 | #define TOTDATE 2557 |
419 | #define UPD_PCT 10 |
420 | #define MAX_STREAM 47 |
421 | #define V_STR_LOW 0.4 |
422 | #define PENNIES 100 /* for scaled int money arithmetic */ |
423 | #define Q11_FRACTION (double)0.0001 |
424 | /* |
425 | * max and min SF in GB; Larger SF will require changes to the build routines |
426 | */ |
427 | #define MIN_SCALE 1.0 |
428 | #define MAX_SCALE 100000.0 |
429 | /* |
430 | * beyond this point we need to allow for BCD calculations |
431 | */ |
432 | #define MAX_32B_SCALE 1000.0 |
433 | #define LONG2HUGE(src, dst) *dst = (DSS_HUGE)src |
434 | #define HUGE2LONG(src, dst) *dst = (long)src |
435 | #define HUGE_SET(src, dst) *dst = *src |
436 | #define HUGE_MUL(op1, op2) *op1 *= op2 |
437 | #define HUGE_DIV(op1, op2) *op1 /= op2 |
438 | #define HUGE_ADD(op1, op2, dst) *dst = *op1 + op2 |
439 | #define HUGE_SUB(op1, op2, dst) *dst = *op1 - op2 |
440 | #define HUGE_MOD(op1, op2) *op1 % op2 |
441 | #define HUGE_CMP(op1, op2) (*op1 == *op2)?0:(*op1 < *op2)-1:1 |
442 | |
443 | |
444 | /******** environmental variables and defaults ***************/ |
445 | #define DIST_TAG "DSS_DIST" /* environment var to override ... */ |
446 | #define DIST_DFLT "dists.dss" /* default file to hold distributions */ |
447 | #define PATH_TAG "DSS_PATH" /* environment var to override ... */ |
448 | #define PATH_DFLT "." /* default directory to hold tables */ |
449 | #define CONFIG_TAG "DSS_CONFIG" /* environment var to override ... */ |
450 | #define CONFIG_DFLT "." /* default directory to config files */ |
451 | #define ADHOC_TAG "DSS_ADHOC" /* environment var to override ... */ |
452 | #define ADHOC_DFLT "adhoc.dss" /* default file name for adhoc vars */ |
453 | |
454 | /******* output macros ********/ |
455 | #ifndef SEPARATOR |
456 | #define SEPARATOR '|' /* field spearator for generated flat files */ |
457 | #endif |
458 | /* Data type flags for a single print routine */ |
459 | #define DT_STR 0 |
460 | #ifndef MVS |
461 | #define DT_VSTR DT_STR |
462 | #else |
463 | #define DT_VSTR 1 |
464 | #endif /* MVS */ |
465 | #define DT_INT 2 |
466 | #define DT_HUGE 3 |
467 | #define DT_KEY 4 |
468 | #define DT_MONEY 5 |
469 | #define DT_CHR 6 |
470 | |
471 | int dbg_print(int dt, FILE *tgt, void *data, int len, int eol); |
472 | #define PR_STR(f, str, len) dbg_print(DT_STR, f, (void *)str, len, 1) |
473 | #define PR_VSTR(f, str, len) dbg_print(DT_VSTR, f, (void *)str, len, 1) |
474 | #define PR_VSTR_LAST(f, str, len) dbg_print(DT_VSTR, f, (void *)str, len, 0) |
475 | #define PR_INT(f, str) dbg_print(DT_INT, f, (void *)str, 0, 1) |
476 | #define PR_HUGE(f, str) dbg_print(DT_HUGE, f, (void *)str, 0, 1) |
477 | #define PR_KEY(f, str) dbg_print(DT_KEY, f, (void *)str, 0, -1) |
478 | #define PR_MONEY(f, str) dbg_print(DT_MONEY, f, (void *)str, 0, 1) |
479 | #define PR_CHR(f, str) dbg_print(DT_CHR, f, (void *)str, 0, 1) |
480 | #define PR_STRT(fp) /* any line prep for a record goes here */ |
481 | #define PR_END(fp) fprintf(fp, "\n") /* finish the record here */ |
482 | #ifdef MDY_DATE |
483 | #define PR_DATE(tgt, yr, mn, dy) \ |
484 | sprintf(tgt, "%02d-%02d-19%02d", mn, dy, yr) |
485 | #else |
486 | #define PR_DATE(tgt, yr, mn, dy) \ |
487 | sprintf(tgt, "19%02ld-%02ld-%02ld", yr, mn, dy) |
488 | #endif /* DATE_FORMAT */ |
489 | |
490 | /* |
491 | * verification macros |
492 | */ |
493 | #define VRF_STR(t, d) {char *xx = d; while (*xx) tdefs[t].vtotal += *xx++;} |
494 | #define VRF_INT(t,d) tdefs[t].vtotal += d |
495 | #define VRF_HUGE(t,d) tdefs[t].vtotal = *((long *)&d) + *((long *)(&d + 1)) |
496 | /* assume float is a 64 bit quantity */ |
497 | #define VRF_MONEY(t,d) tdefs[t].vtotal = *((long *)&d) + *((long *)(&d + 1)) |
498 | #define VRF_CHR(t,d) tdefs[t].vtotal += d |
499 | #define VRF_STRT(t) |
500 | #define VRF_END(t) |
501 | |
502 | /*********** distribuitons currently defined *************/ |
503 | #define UNIFORM 0 |
504 | |
505 | /* |
506 | * seed indexes; used to separate the generation of individual columns |
507 | */ |
508 | #define P_MFG_SD 0 |
509 | #define P_BRND_SD 1 |
510 | #define P_TYPE_SD 2 |
511 | #define P_SIZE_SD 3 |
512 | #define P_CNTR_SD 4 |
513 | #define P_RCST_SD 5 |
514 | #define PS_QTY_SD 7 |
515 | #define PS_SCST_SD 8 |
516 | #define O_SUPP_SD 10 |
517 | #define O_CLRK_SD 11 |
518 | #define O_ODATE_SD 13 |
519 | #define L_QTY_SD 14 |
520 | #define L_DCNT_SD 15 |
521 | #define L_TAX_SD 16 |
522 | #define L_SHIP_SD 17 |
523 | #define L_SMODE_SD 18 |
524 | #define L_PKEY_SD 19 |
525 | #define L_SKEY_SD 20 |
526 | #define L_SDTE_SD 21 |
527 | #define L_CDTE_SD 22 |
528 | #define L_RDTE_SD 23 |
529 | #define L_RFLG_SD 24 |
530 | #define C_NTRG_SD 27 |
531 | #define C_PHNE_SD 28 |
532 | #define C_ABAL_SD 29 |
533 | #define C_MSEG_SD 30 |
534 | #define S_NTRG_SD 33 |
535 | #define S_PHNE_SD 34 |
536 | #define S_ABAL_SD 35 |
537 | #define P_NAME_SD 37 |
538 | #define O_PRIO_SD 38 |
539 | #define HVAR_SD 39 |
540 | #define O_CKEY_SD 40 |
541 | #define N_CMNT_SD 41 |
542 | #define R_CMNT_SD 42 |
543 | #define O_LCNT_SD 43 |
544 | #define BBB_JNK_SD 44 |
545 | #define BBB_TYPE_SD 45 |
546 | #define BBB_CMNT_SD 46 |
547 | #define BBB_OFFSET_SD 47 |
548 | #endif /* DSS_H */ |
549 | |