Skip to content

Commit eccd4f8

Browse files
committed
Adds support for Foreign keys table in Pstress
https://perconadev.atlassian.net/browse/PSTRESS-152 Introduced support for Foreign key tables in Pstress. * The tables with foreign key references are suffixed with `_fk` while creating the tables. * These FK tables include `ifk_col` column referencing parent table's `ipkey`. * Example : When --fk-prob is 50 --tables 100 options are passed, there is a 50% chance there will be a table tt_N_fk whose parent would be tt_N. * To fully test FK behaviour, use `--fk-prob=100 --pk-prob=100` * The FK tables can be disabled with `--no-fk` option. Renamed some command-line options for clarity: * `--primary-key-probability` -> `--pk-prob` * `--ration-normal-temp` -> `--temp-prob` Fixed transaction behaviour: * Ensured `START TRANSACTION` doesn't block other sessions by running transactions independently. Adjusted the default probabilities of some features: * Decreased the probability of using SAVEPOINT in a transaction from 25% to 10%. * Decreased the probability of partition tables to 10%. * Decreased the probability of temporary tables to 10%. Thanks Rahul Malik for the contribution. (github.com//pull/92)
1 parent e57d733 commit eccd4f8

File tree

4 files changed

+387
-116
lines changed

4 files changed

+387
-116
lines changed

src/common.hpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,8 @@ struct Option {
5959
INDEX_COLUMNS,
6060
NO_AUTO_INC,
6161
NO_DESC_INDEX,
62-
NO_TEMPORARY,
63-
NO_PARTITION,
6462
ONLY_TEMPORARY,
6563
ONLY_PARTITION,
66-
TEMPORARY_TO_NORMAL_RATIO,
6764
INITIAL_RECORDS_IN_TABLE,
6865
NUMBER_OF_SECONDS_WORKLOAD,
6966
ALTER_TABLE_ENCRYPTION,
@@ -121,7 +118,7 @@ struct Option {
121118
MYSQLD_SERVER_OPTION = 'z',
122119
TRANSATION_PRB_K,
123120
TRANSACTIONS_SIZE,
124-
COMMMIT_TO_ROLLBACK_RATIO,
121+
COMMIT_PROB,
125122
SAVEPOINT_PRB_K,
126123
CHECK_TABLE,
127124
CHECK_TABLE_PRELOAD,
@@ -144,6 +141,12 @@ struct Option {
144141
DROP_CREATE,
145142
EXACT_INITIAL_RECORDS,
146143
PREPARE,
144+
NO_TEMPORARY,
145+
NO_PARTITION,
146+
NO_FK,
147+
FK_PROB,
148+
PARTITION_PROB,
149+
TEMPORARY_PROB,
147150
MAX
148151
} option;
149152
Option(Type t, Opt o, std::string n)

src/help.cpp

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,13 @@ void add_options() {
229229
opt->setArgs(no_argument);
230230
opt->setBool(false);
231231

232+
/* No FK tables */
233+
opt = newOption(Option::BOOL, Option::NO_FK, "no-fk-tables");
234+
opt->help = "do not work on foriegn tables";
235+
opt->setArgs(no_argument);
236+
opt->setBool(false);
237+
238+
232239
/* No Partition tables */
233240
opt = newOption(Option::BOOL, Option::NO_PARTITION, "no-partition-tables");
234241
opt->help = "do not work on partition tables";
@@ -241,12 +248,21 @@ void add_options() {
241248
opt->setArgs(no_argument);
242249
opt->setBool(false);
243250

251+
opt = newOption(Option::INT, Option::FK_PROB, "fk-prob");
252+
opt->help = R"(
253+
Probability of each normal table having the FK. Currently, FKs are only linked
254+
to the primary key of the parent table. So, even with 100% probability, a table
255+
will have an FK only if its parent has a primary key.
256+
)";
257+
opt->setInt(50);
258+
259+
opt = newOption(Option::INT, Option::PARTITION_PROB, "partition-prob");
260+
opt->help = "Probability of parititon tables";
261+
opt->setInt(10);
262+
244263
/* Ratio of temporary table to normal table */
245-
opt = newOption(Option::INT, Option::TEMPORARY_TO_NORMAL_RATIO,
246-
"ratio-normal-temp");
247-
opt->help = "ratio of normal to temporary tables. for e.g. if ratio to "
248-
"normal table to temporary is 10 . --tables 40. them only 4 "
249-
"temorary table will be created per session";
264+
opt = newOption(Option::INT, Option::TEMPORARY_PROB, "temporary-prob");
265+
opt->help = "Probability of temporary tables";
250266
opt->setInt(10);
251267

252268
/* Initial Records in table */
@@ -270,7 +286,7 @@ void add_options() {
270286
opt->setInt(1000);
271287

272288
/* primary key probability */
273-
opt = newOption(Option::INT, Option::PRIMARY_KEY, "primary-key-probability");
289+
opt = newOption(Option::INT, Option::PRIMARY_KEY, "pk-prob");
274290
opt->help = "Probability of adding primary key in a table";
275291
opt->setInt(50);
276292

@@ -684,7 +700,7 @@ void add_options() {
684700
opt =
685701
newOption(Option::BOOL, Option::LOG_QUERY_DURATION, "log-query-duration");
686702
opt->help = "Log query duration in milliseconds";
687-
opt->setBool(true);
703+
opt->setBool(false);
688704
opt->setArgs(no_argument);
689705

690706
/* log failed queries */
@@ -714,28 +730,26 @@ void add_options() {
714730
opt->setArgs(no_argument);
715731

716732
/* transaction probability */
717-
opt = newOption(Option::INT, Option::TRANSATION_PRB_K, "trx-prb-k");
733+
opt = newOption(Option::INT, Option::TRANSATION_PRB_K, "trx-prob-k");
718734
opt->help = "probability(out of 1000) of combining sql as single trx";
719-
opt->setInt(10);
735+
opt->setInt(1);
720736

721737
/* tranasaction size */
722738
opt = newOption(Option::INT, Option::TRANSACTIONS_SIZE, "trx-size");
723739
opt->help = "average size of each trx";
724-
opt->setInt(100);
725-
726-
/* commit to rollback ratio */
727-
opt = newOption(Option::INT, Option::COMMMIT_TO_ROLLBACK_RATIO,
728-
"commit-rollback-ratio");
729-
opt->help = "ratio of commit to rollback. e.g.\nif 5, then 5 "
730-
"transactions will be committed and 1 will be rollback.\n"
731-
"if 0 then all transactions will be rollback";
732-
opt->setInt(5);
740+
opt->setInt(10);
741+
742+
/* probability of executing commit */
743+
opt = newOption(Option::INT, Option::COMMIT_PROB, "commit-prob");
744+
opt->help = "probability of executing commit after a transaction. Else it "
745+
"would be rollback ";
746+
opt->setInt(95);
733747

734748
/* number of savepoints in trxs */
735-
opt = newOption(Option::INT, Option::SAVEPOINT_PRB_K, "savepoint-prb-k");
736-
opt->help = "probability of using savepoint in a transaction.\n Also 25% "
749+
opt = newOption(Option::INT, Option::SAVEPOINT_PRB_K, "savepoint-prob-k");
750+
opt->help = "probability of using savepoint in a transaction.\n Also 10% "
737751
"such transaction will be rollback to some savepoint";
738-
opt->setInt(50);
752+
opt->setInt(10);
739753

740754
/* steps */
741755
opt = newOption(Option::INT, Option::STEP, "step");

0 commit comments

Comments
 (0)