Skip to content

Commit 17ceb9a

Browse files
committed
Include the secondary keys into the TPC-C example.
1 parent 1f2c833 commit 17ceb9a

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

res/tpcc/tpcc.jsonnet

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ local dbdbgen = import 'dbdbgen.libsonnet';
3030
help: 'Enable foreign keys in the generated schema.',
3131
type: 'bool',
3232
},
33+
secondary_key: {
34+
long: 'secondary-key',
35+
help: 'Enable secondary keys in the generated schema (for MySQL only).',
36+
type: 'bool',
37+
},
3338

3439
// TPC-C output contains no special characters.
3540
escape_backslash:: null,
@@ -44,6 +49,7 @@ local dbdbgen = import 'dbdbgen.libsonnet';
4449
prefix: m.table_prefix,
4550
warehouses: m.warehouses,
4651
fk: if m.foreign_key then '' else '-- ',
52+
sk: if m.secondary_key then '' else '-- ',
4753
};
4854
[
4955
/* 0_config
@@ -372,6 +378,7 @@ local dbdbgen = import 'dbdbgen.libsonnet';
372378
c_data varchar(500),
373379
/*{{ rand.regex('[0-9a-zA-Z]{300,500}') }}*/
374380
%(fk)sforeign key (c_w_id, c_d_id) references %(prefix)sdistrict (d_w_id, d_id),
381+
%(sk)skey (c_w_id, c_d_id, c_last, c_first),
375382
primary key (c_w_id, c_d_id, c_id)
376383
);
377384
||| % format,
@@ -396,15 +403,15 @@ local dbdbgen = import 'dbdbgen.libsonnet';
396403
rows_per_file: 3e6,
397404
template_string: |||
398405
create table %(prefix)shistory (
399-
h_c_id integer,
406+
h_c_id integer not null,
400407
/*{{ mod(rownum-1, 3000)+1 }}*/
401-
h_c_d_id integer,
408+
h_c_d_id integer not null,
402409
/*{{ @d_id := mod(div(rownum-1, 3000), 10)+1 }}*/
403-
h_c_w_id integer,
410+
h_c_w_id integer not null,
404411
/*{{ @w_id := div(rownum-1, 30000)+1 }}*/
405-
h_d_id integer,
412+
h_d_id integer not null,
406413
/*{{ @d_id }}*/
407-
h_w_id integer,
414+
h_w_id integer not null,
408415
/*{{ @w_id }}*/
409416
h_date timestamp,
410417
/*{{ current_timestamp }}*/
@@ -414,6 +421,8 @@ local dbdbgen = import 'dbdbgen.libsonnet';
414421
/*{{ rand.regex('[0-9a-zA-Z]{12,24}') }}*/
415422
%(fk)s,foreign key (h_c_w_id, h_c_d_id, h_c_id) references %(prefix)scustomer (c_w_id, c_d_id, c_id)
416423
%(fk)s,foreign key (h_w_id, h_d_id) references %(prefix)sdistrict (d_w_id, d_id)
424+
%(sk)s,key (h_w_id)
425+
%(sk)s,key (h_c_w_id)
417426
);
418427
||| % format,
419428
},
@@ -478,6 +487,7 @@ local dbdbgen = import 'dbdbgen.libsonnet';
478487
o_entry_d timestamp,
479488
/*{{ @o_entry_d := current_timestamp }}*/
480489
%(fk)sforeign key (o_w_id, o_d_id, o_c_id) references %(prefix)scustomer (c_w_id, c_d_id, c_id),
490+
%(sk)skey (o_w_id, o_d_id, o_c_id, o_id),
481491
primary key (o_w_id, o_d_id, o_id)
482492
);
483493

0 commit comments

Comments
 (0)