Skip to content

Commit 032e740

Browse files
Merge pull request #2 from Percona-Lab/indexes
Added support for Foreign Keys constraints
2 parents 597b87a + 689102c commit 032e740

15 files changed

+49669
-250
lines changed

Gopkg.lock

+81
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
# Gopkg.toml example
3+
#
4+
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
5+
# for detailed Gopkg.toml documentation.
6+
#
7+
# required = ["github.com/user/thing/cmd/thing"]
8+
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
9+
#
10+
# [[constraint]]
11+
# name = "github.com/user/project"
12+
# version = "1.0.0"
13+
#
14+
# [[constraint]]
15+
# name = "github.com/user/project2"
16+
# branch = "dev"
17+
# source = "github.com/myfork/project2"
18+
#
19+
# [[override]]
20+
# name = "github.com/x/y"
21+
# version = "2.4.0"
22+
23+
24+
[[constraint]]
25+
name = "github.com/go-sql-driver/mysql"
26+
version = "1.3.0"
27+
28+
[[constraint]]
29+
branch = "master"
30+
name = "github.com/gosuri/uiprogress"
31+
32+
[[constraint]]
33+
branch = "master"
34+
name = "github.com/icrowley/fake"
35+
36+
[[constraint]]
37+
branch = "master"
38+
name = "github.com/kr/pretty"
39+
40+
[[constraint]]
41+
name = "gopkg.in/alecthomas/kingpin.v2"
42+
version = "2.2.5"

README.md

+37-4
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,32 @@ The program can detect if a field accepts NULLs and if it does, it will generate
5050
## Options
5151
|Option|Description|
5252
|------|-----------|
53+
|--bulk-size|Number of rows per INSERT statement (Default: 1000)|
54+
|--debug|Show some debug information|
55+
|--fk-samples-factor|Percentage used to get random samples for foreign keys fields. Default 0.3|
5356
|--host|Host name/ip|
57+
|--max-fk-samples|Maximum number of samples for fields having foreign keys constarints. Default: 100|
58+
|--max-retries|Maximum number of rows to retry in case of errors. See duplicated keys. Deafult: 100|
59+
|--password|Password|
5460
|--port|Port number|
61+
|--show-progressbar|Show the progress bar. Default: true|
5562
|--user|Username|
56-
|--password|Password|
57-
|--bulk-size|Number of rows per INSERT statement (Default: 1000)|
58-
|--debug|Show some debug information|
63+
64+
## Foreign keys support
65+
If a field has Foreign Keys constraints, `random-data-load` will get up to `--max-fk-samples` random samples from the referenced tables in order to insert valid values for the field.
66+
The number of samples to get follows this rules:
67+
**1.** Get the aproximate number of rows in the referenced table using the `rows` field in:
68+
```
69+
EXPLAIN COUNT(*) FROM <referenced schema>.<referenced table>
70+
```
71+
**1.1** If the number of rows is less than `max-fk-samples`, all rows are retrieved from the referenced table using this query:
72+
```
73+
SELECT <referenced field> FROM <referenced schema>.<referenced table>
74+
```
75+
**1.2** If the number of rows is greater than `max-fk-samples`, samples are retrieved from the referenced table using this query:
76+
```
77+
SELECT <referenced field> FROM <referenced schema>.<referenced table> WHERE RAND() <= <fk-samples-factor> LIMIT <max-fk-samples>
78+
```
5979

6080
### Example
6181
```
@@ -135,6 +155,19 @@ tcol28: 6.12
135155

136156
## To do
137157
- [ ] Add suport for all data types.
138-
- [ ] Add supporrt for foreign keys.
158+
- [X] Add supporrt for foreign keys.
139159
- [ ] Support config files to override default values/ranges.
140160
- [ ] Support custom functions via LUA plugins.
161+
162+
## Versions history
163+
164+
#### 0.1.2
165+
- New table parser able to retrieve all the information for fields, indexes and foreign keys constraints.
166+
- Support for foreign keys constraints
167+
- Added some tests
168+
169+
#### 0.1.1
170+
- Fixed random data generation
171+
172+
#### 0.1.0
173+
- Initial version

0 commit comments

Comments
 (0)