@@ -85,9 +85,7 @@ func TestIntegration(t *testing.T) {
8585 `SELECT COUNT(first_commit_year), first_commit_year
8686 FROM (
8787 SELECT YEAR(c.commit_author_when) AS first_commit_year
88- FROM repositories r
89- INNER JOIN ref_commits rc
90- ON r.repository_id = rc.repository_id
88+ FROM ref_commits rc
9189 INNER JOIN commits c
9290 ON rc.commit_hash = c.commit_hash
9391 ORDER BY c.commit_author_when
@@ -101,13 +99,11 @@ func TestIntegration(t *testing.T) {
10199 FROM (
102100 SELECT
103101 MONTH(committer_when) as month,
104- r .repository_id as repo_id,
102+ rc .repository_id as repo_id,
105103 committer_email
106- FROM repositories r
107- INNER JOIN ref_commits rc ON rc.repository_id = r.repository_id
108- AND rc.ref_name = 'refs/heads/master'
104+ FROM ref_commits rc
109105 INNER JOIN commits c ON rc.commit_hash = c.commit_hash
110- WHERE YEAR(committer_when) = 2015
106+ WHERE YEAR(committer_when) = 2015 AND rc.ref_name = 'refs/heads/master'
111107 ) as t
112108 GROUP BY committer_email, month, repo_id` ,
113109 []sql.Row {
@@ -184,13 +180,13 @@ func TestUastQueries(t *testing.T) {
184180 FROM tree_entries te
185181 INNER JOIN blobs b
186182 ON b.blob_hash = te.blob_hash
187- WHERE te.tree_entry_name = 'php/ crappy.php'` ,
183+ WHERE te.tree_entry_name = 'crappy.php'` ,
188184 )
189185 require .NoError (err )
190186
191187 rows , err := sql .RowIterToRows (iter )
192188 require .NoError (err )
193- require .Len (rows , 3 )
189+ require .Len (rows , 1 )
194190}
195191
196192func TestSquashCorrectness (t * testing.T ) {
@@ -226,9 +222,9 @@ func TestSquashCorrectness(t *testing.T) {
226222 `SELECT * FROM refs r INNER JOIN remotes re ON r.repository_id = re.repository_id` ,
227223 `SELECT * FROM refs r INNER JOIN commits c ON r.commit_hash = c.commit_hash` ,
228224 `SELECT * FROM ref_commits r INNER JOIN commits c ON r.commit_hash = c.commit_hash` ,
229- `SELECT * FROM refs r INNER JOIN tree_entries te ON commit_has_tree( r.commit_hash, te.tree_hash) ` ,
225+ `SELECT * FROM refs r INNER JOIN commit_trees t ON r.commit_hash = t.commit_hash ` ,
230226 `SELECT * FROM refs r INNER JOIN blobs b ON commit_has_blob(r.commit_hash, b.blob_hash)` ,
231- `SELECT * FROM commits c INNER JOIN tree_entries te ON commit_has_tree( c.commit_hash, te .tree_hash) ` ,
227+ `SELECT * FROM commits c INNER JOIN commit_trees t ON c.commit_hash = t .tree_hash` ,
232228 `SELECT * FROM commits c INNER JOIN tree_entries te ON c.tree_hash = te.tree_hash` ,
233229 `SELECT * FROM commits c INNER JOIN blobs b ON commit_has_blob(c.commit_hash, b.blob_hash)` ,
234230 `SELECT * FROM tree_entries te INNER JOIN blobs b ON te.blob_hash = b.blob_hash` ,
@@ -241,8 +237,10 @@ func TestSquashCorrectness(t *testing.T) {
241237 WHERE re.ref_name = 'HEAD'` ,
242238
243239 `SELECT * FROM commits c
240+ INNER JOIN commit_trees t
241+ ON c.commit_hash = t.commit_hash
244242 INNER JOIN tree_entries te
245- ON c .tree_hash = te.tree_hash
243+ ON t .tree_hash = te.tree_hash
246244 INNER JOIN blobs b
247245 ON te.blob_hash = b.blob_hash
248246 WHERE te.tree_entry_name = 'LICENSE'` ,
@@ -323,9 +321,9 @@ func BenchmarkQueries(b *testing.B) {
323321 {
324322 "query with commit_has_blob" ,
325323 `SELECT COUNT(c.commit_hash), c.commit_hash
326- FROM refs r
324+ FROM ref_commits r
327325 INNER JOIN commits c
328- ON r.ref_name = 'HEAD' AND history_idx( r.commit_hash, c.commit_hash) >= 0
326+ ON r.ref_name = 'HEAD' AND r.commit_hash = c.commit_hash
329327 INNER JOIN blobs b
330328 ON commit_has_blob(c.commit_hash, b.blob_hash)
331329 GROUP BY c.commit_hash` ,
@@ -335,11 +333,9 @@ func BenchmarkQueries(b *testing.B) {
335333 `SELECT COUNT(first_commit_year), first_commit_year
336334 FROM (
337335 SELECT YEAR(c.commit_author_when) AS first_commit_year
338- FROM repositories r
339- INNER JOIN refs
340- ON r.repository_id = refs.repository_id
336+ FROM ref_commits r
341337 INNER JOIN commits c
342- ON history_idx(refs .commit_hash, c.commit_hash) >= 0
338+ ON r .commit_hash = c.commit_hash
343339 ORDER BY c.commit_author_when
344340 LIMIT 1
345341 ) repo_years
@@ -349,9 +345,9 @@ func BenchmarkQueries(b *testing.B) {
349345 "query with history_idx" ,
350346 `SELECT * FROM (
351347 SELECT COUNT(c.commit_hash) AS num, c.commit_hash
352- FROM refs r
348+ FROM ref_commits r
353349 INNER JOIN commits c
354- ON history_idx( r.commit_hash, c.commit_hash) >= 0
350+ ON r.commit_hash = c.commit_hash
355351 GROUP BY c.commit_hash
356352 ) t WHERE num > 1` ,
357353 },
0 commit comments