Skip to content

Commit

Permalink
Merge pull request #577 from BakeRolls/examples-join-on
Browse files Browse the repository at this point in the history
Added repository_ids in non-natural joins in the examples
  • Loading branch information
ajnavarro authored Oct 23, 2018
2 parents 042dd2c + 0cb3057 commit 6b64e67
Showing 1 changed file with 24 additions and 20 deletions.
44 changes: 24 additions & 20 deletions docs/using-gitbase/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
SELECT refs.repository_id
FROM refs
NATURAL JOIN commits
WHERE commits.commit_author_name = 'Javi Fontan' AND refs.ref_name='HEAD';
WHERE commits.commit_author_name = 'Javi Fontan' AND refs.ref_name = 'HEAD';
```

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

```sql
SELECT
file_path,
ref_commits.repository_id
file_path,
ref_commits.repository_id
FROM
commit_files
commit_files
NATURAL JOIN
ref_commits
ref_commits
WHERE
ref_commits.ref_name = 'HEAD'
AND ref_commits.history_index = 0;
ref_commits.ref_name = 'HEAD'
AND ref_commits.history_index = 0;
```

## Commits that appear in more than one reference
Expand All @@ -37,7 +37,7 @@ SELECT * FROM (
SELECT COUNT(c.commit_hash) AS num, c.commit_hash
FROM ref_commits r
INNER JOIN commits c
ON r.commit_hash = c.commit_hash
ON r.repository_id = c.repository_id AND r.commit_hash = c.commit_hash
GROUP BY c.commit_hash
) t WHERE num > 1;
```
Expand All @@ -48,9 +48,11 @@ SELECT * FROM (
SELECT COUNT(c.commit_hash), c.commit_hash
FROM ref_commits as r
INNER JOIN commits c
ON r.ref_name = 'HEAD' AND r.commit_hash = c.commit_hash
ON r.ref_name = 'HEAD'
AND r.repository_id = c.repository_id
AND r.commit_hash = c.commit_hash
INNER JOIN commit_blobs cb
ON cb.commit_hash = c.commit_hash
ON cb.repository_id = c.repository_id AND cb.commit_hash = c.commit_hash
GROUP BY c.commit_hash;
```

Expand All @@ -65,7 +67,9 @@ FROM (
committer_email
FROM ref_commits r
INNER JOIN commits c
ON YEAR(c.committer_when) = 2015 AND r.commit_hash = c.commit_hash
ON YEAR(c.committer_when) = 2015
AND r.repository_id = c.repository_id
AND r.commit_hash = c.commit_hash
WHERE r.ref_name = 'HEAD'
) as t
GROUP BY committer_email, month, repo_id;
Expand All @@ -75,21 +79,21 @@ GROUP BY committer_email, month, repo_id;

```sql
select
files.file_path,
ref_commits.repository_id,
files.file_path,
ref_commits.repository_id,
files.blob_content
FROM
files
files
NATURAL JOIN
commit_files
commit_files
NATURAL JOIN
ref_commits
ref_commits
WHERE
ref_commits.ref_name = 'HEAD'
AND ref_commits.history_index BETWEEN 0 AND 5
AND is_binary(blob_content) = false
ref_commits.ref_name = 'HEAD'
AND ref_commits.history_index BETWEEN 0 AND 5
AND is_binary(blob_content) = false
AND files.file_path NOT REGEXP '^vendor.*'
AND (
AND (
blob_content REGEXP '(?i)facebook.*[\'\\"][0-9a-f]{32}[\'\\"]'
OR blob_content REGEXP '(?i)twitter.*[\'\\"][0-9a-zA-Z]{35,44}[\'\\"]'
OR blob_content REGEXP '(?i)github.*[\'\\"][0-9a-zA-Z]{35,40}[\'\\"]'
Expand Down

0 comments on commit 6b64e67

Please sign in to comment.