Skip to content

Commit 6b64e67

Browse files
authored
Merge pull request #577 from BakeRolls/examples-join-on
Added repository_ids in non-natural joins in the examples
2 parents 042dd2c + 0cb3057 commit 6b64e67

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

docs/using-gitbase/examples.md

+24-20
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
SELECT refs.repository_id
77
FROM refs
88
NATURAL JOIN commits
9-
WHERE commits.commit_author_name = 'Javi Fontan' AND refs.ref_name='HEAD';
9+
WHERE commits.commit_author_name = 'Javi Fontan' AND refs.ref_name = 'HEAD';
1010
```
1111

1212
## Get all the HEAD references from all the repositories
@@ -19,15 +19,15 @@ SELECT * FROM refs WHERE ref_name = 'HEAD';
1919

2020
```sql
2121
SELECT
22-
file_path,
23-
ref_commits.repository_id
22+
file_path,
23+
ref_commits.repository_id
2424
FROM
25-
commit_files
25+
commit_files
2626
NATURAL JOIN
27-
ref_commits
27+
ref_commits
2828
WHERE
29-
ref_commits.ref_name = 'HEAD'
30-
AND ref_commits.history_index = 0;
29+
ref_commits.ref_name = 'HEAD'
30+
AND ref_commits.history_index = 0;
3131
```
3232

3333
## Commits that appear in more than one reference
@@ -37,7 +37,7 @@ SELECT * FROM (
3737
SELECT COUNT(c.commit_hash) AS num, c.commit_hash
3838
FROM ref_commits r
3939
INNER JOIN commits c
40-
ON r.commit_hash = c.commit_hash
40+
ON r.repository_id = c.repository_id AND r.commit_hash = c.commit_hash
4141
GROUP BY c.commit_hash
4242
) t WHERE num > 1;
4343
```
@@ -48,9 +48,11 @@ SELECT * FROM (
4848
SELECT COUNT(c.commit_hash), c.commit_hash
4949
FROM ref_commits as r
5050
INNER JOIN commits c
51-
ON r.ref_name = 'HEAD' AND r.commit_hash = c.commit_hash
51+
ON r.ref_name = 'HEAD'
52+
AND r.repository_id = c.repository_id
53+
AND r.commit_hash = c.commit_hash
5254
INNER JOIN commit_blobs cb
53-
ON cb.commit_hash = c.commit_hash
55+
ON cb.repository_id = c.repository_id AND cb.commit_hash = c.commit_hash
5456
GROUP BY c.commit_hash;
5557
```
5658

@@ -65,7 +67,9 @@ FROM (
6567
committer_email
6668
FROM ref_commits r
6769
INNER JOIN commits c
68-
ON YEAR(c.committer_when) = 2015 AND r.commit_hash = c.commit_hash
70+
ON YEAR(c.committer_when) = 2015
71+
AND r.repository_id = c.repository_id
72+
AND r.commit_hash = c.commit_hash
6973
WHERE r.ref_name = 'HEAD'
7074
) as t
7175
GROUP BY committer_email, month, repo_id;
@@ -75,21 +79,21 @@ GROUP BY committer_email, month, repo_id;
7579

7680
```sql
7781
select
78-
files.file_path,
79-
ref_commits.repository_id,
82+
files.file_path,
83+
ref_commits.repository_id,
8084
files.blob_content
8185
FROM
82-
files
86+
files
8387
NATURAL JOIN
84-
commit_files
88+
commit_files
8589
NATURAL JOIN
86-
ref_commits
90+
ref_commits
8791
WHERE
88-
ref_commits.ref_name = 'HEAD'
89-
AND ref_commits.history_index BETWEEN 0 AND 5
90-
AND is_binary(blob_content) = false
92+
ref_commits.ref_name = 'HEAD'
93+
AND ref_commits.history_index BETWEEN 0 AND 5
94+
AND is_binary(blob_content) = false
9195
AND files.file_path NOT REGEXP '^vendor.*'
92-
AND (
96+
AND (
9397
blob_content REGEXP '(?i)facebook.*[\'\\"][0-9a-f]{32}[\'\\"]'
9498
OR blob_content REGEXP '(?i)twitter.*[\'\\"][0-9a-zA-Z]{35,44}[\'\\"]'
9599
OR blob_content REGEXP '(?i)github.*[\'\\"][0-9a-zA-Z]{35,40}[\'\\"]'

0 commit comments

Comments
 (0)