Skip to content

Commit 44c0700

Browse files
committed
*: iterator should visit trees recursively after main tree
There was an inconsistency between the results returned by the iterators and the ones using the tables and joins because the tables look for all trees and visit them. Instead, the iterator chained with commits only visited the main tree. Now, there is another iterator for this case that visits the main tree and puts other trees that are found in a queue to visit them as well. This mimics the behaviour of joinin commits and tree entries. Signed-off-by: Miguel Molina <[email protected]>
1 parent b3d0f64 commit 44c0700

File tree

4 files changed

+338
-29
lines changed

4 files changed

+338
-29
lines changed

internal/rule/squashjoins.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ func buildSquashedTable(
277277
false,
278278
)
279279
case gitbase.CommitsIter:
280+
onlyMainTree := hasMainTreeFilter(filters)
280281
var f sql.Expression
281282
f, filters, err = filtersForJoin(
282283
gitbase.CommitsTableName,
@@ -288,7 +289,11 @@ func buildSquashedTable(
288289
return nil, err
289290
}
290291

291-
iter = gitbase.NewCommitTreeEntriesIter(it, f, false)
292+
if onlyMainTree {
293+
iter = gitbase.NewCommitMainTreeEntriesIter(it, f, false)
294+
} else {
295+
iter = gitbase.NewCommitTreeEntriesIter(it, f, false)
296+
}
292297
case nil:
293298
var f sql.Expression
294299
f, filters, err = filtersForTable(
@@ -342,7 +347,7 @@ func buildSquashedTable(
342347
}
343348

344349
iter = gitbase.NewTreeEntryBlobsIter(
345-
gitbase.NewCommitTreeEntriesIter(
350+
gitbase.NewCommitMainTreeEntriesIter(
346351
it,
347352
nil,
348353
true,
@@ -745,6 +750,19 @@ func hasRefHEADFilter(filters []sql.Expression) bool {
745750
return false
746751
}
747752

753+
func hasMainTreeFilter(filters []sql.Expression) bool {
754+
for _, f := range filters {
755+
ok := isEq(
756+
isCol(gitbase.CommitsTableName, "tree_hash"),
757+
isCol(gitbase.TreeEntriesTableName, "tree_hash"),
758+
)(f)
759+
if ok {
760+
return true
761+
}
762+
}
763+
return false
764+
}
765+
748766
// hasChainableJoinCondition tells whether the given join condition contains
749767
// any filter that can be used to build a chainable iterator.
750768
// t1 with t2. t1 MUST be higher in the table hierarchy than t2.

internal/rule/squashjoins_test.go

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,12 @@ func TestBuildSquashedTable(t *testing.T) {
330330
col(0, gitbase.TreeEntriesTableName, "entry_hash"),
331331
)
332332

333-
commitTreeEntriesRedundantFilter := eq(
333+
commitTreeEntriesRedundantFilter := commitHasTree(
334+
col(0, gitbase.CommitsTableName, "hash"),
335+
col(0, gitbase.TreeEntriesTableName, "tree_hash"),
336+
)
337+
338+
commitMainTreeEntriesRedundantFilter := eq(
334339
col(0, gitbase.CommitsTableName, "tree_hash"),
335340
col(0, gitbase.TreeEntriesTableName, "tree_hash"),
336341
)
@@ -523,6 +528,32 @@ func TestBuildSquashedTable(t *testing.T) {
523528
{
524529
"commits with tree entries",
525530
[]sql.Table{commits, treeEntries},
531+
[]sql.Expression{
532+
commitFilter,
533+
treeEntryFilter,
534+
commitTreeEntriesFilter,
535+
commitMainTreeEntriesRedundantFilter,
536+
},
537+
nil,
538+
newSquashedTable(
539+
gitbase.NewCommitMainTreeEntriesIter(
540+
gitbase.NewAllCommitsIter(
541+
fixIdx(t, commitFilter, gitbase.CommitsSchema),
542+
),
543+
and(
544+
fixIdx(t, treeEntryFilter, commitTreeEntriesSchema),
545+
fixIdx(t, commitTreeEntriesFilter, commitTreeEntriesSchema),
546+
),
547+
false,
548+
),
549+
nil,
550+
gitbase.CommitsTableName,
551+
gitbase.TreeEntriesTableName,
552+
),
553+
},
554+
{
555+
"commits with tree entries using commit_has_tree",
556+
[]sql.Table{commits, treeEntries},
526557
[]sql.Expression{
527558
commitFilter,
528559
treeEntryFilter,
@@ -674,7 +705,7 @@ func TestBuildSquashedTable(t *testing.T) {
674705
nil,
675706
newSquashedTable(
676707
gitbase.NewTreeEntryBlobsIter(
677-
gitbase.NewCommitTreeEntriesIter(
708+
gitbase.NewCommitMainTreeEntriesIter(
678709
gitbase.NewAllCommitsIter(
679710
fixIdx(t, commitFilter, commitBlobsSchema),
680711
),

0 commit comments

Comments
 (0)