Skip to content

Commit 4fdf2ce

Browse files
authored
Merge pull request #650 from erizocosmico/fix/index-explain
gitbase: show pushed down properties to tables in explain
2 parents 19fdc30 + 0ba16e7 commit 4fdf2ce

13 files changed

+135
-25
lines changed

blobs.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,14 @@ var _ Squashable = (*blobsTable)(nil)
5050
func (blobsTable) isSquashable() {}
5151
func (blobsTable) isGitbaseTable() {}
5252

53-
func (blobsTable) String() string {
54-
return printTable(BlobsTableName, BlobsSchema)
53+
func (r blobsTable) String() string {
54+
return printTable(
55+
BlobsTableName,
56+
BlobsSchema,
57+
r.projection,
58+
r.filters,
59+
r.index,
60+
)
5561
}
5662

5763
func (blobsTable) Name() string {

commit_blobs.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,14 @@ var _ Squashable = (*blobsTable)(nil)
3333
func (commitBlobsTable) isSquashable() {}
3434
func (commitBlobsTable) isGitbaseTable() {}
3535

36-
func (commitBlobsTable) String() string {
37-
return printTable(CommitBlobsTableName, CommitBlobsSchema)
36+
func (t commitBlobsTable) String() string {
37+
return printTable(
38+
CommitBlobsTableName,
39+
CommitBlobsSchema,
40+
nil,
41+
t.filters,
42+
t.index,
43+
)
3844
}
3945

4046
func (commitBlobsTable) Name() string { return CommitBlobsTableName }

commit_files.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,14 @@ var _ Squashable = (*commitFilesTable)(nil)
3838
func (commitFilesTable) isSquashable() {}
3939
func (commitFilesTable) isGitbaseTable() {}
4040

41-
func (commitFilesTable) String() string {
42-
return printTable(CommitFilesTableName, CommitFilesSchema)
41+
func (t commitFilesTable) String() string {
42+
return printTable(
43+
CommitFilesTableName,
44+
CommitFilesSchema,
45+
nil,
46+
t.filters,
47+
t.index,
48+
)
4349
}
4450

4551
func (commitFilesTable) Name() string { return CommitFilesTableName }

commit_trees.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,14 @@ var _ Squashable = (*commitTreesTable)(nil)
3434
func (commitTreesTable) isSquashable() {}
3535
func (commitTreesTable) isGitbaseTable() {}
3636

37-
func (commitTreesTable) String() string {
38-
return printTable(CommitTreesTableName, CommitTreesSchema)
37+
func (t commitTreesTable) String() string {
38+
return printTable(
39+
CommitTreesTableName,
40+
CommitTreesSchema,
41+
nil,
42+
t.filters,
43+
t.index,
44+
)
3945
}
4046

4147
func (commitTreesTable) Name() string { return CommitTreesTableName }

commits.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,14 @@ var _ Squashable = (*commitsTable)(nil)
4040
func (commitsTable) isSquashable() {}
4141
func (commitsTable) isGitbaseTable() {}
4242

43-
func (commitsTable) String() string {
44-
return printTable(CommitsTableName, CommitsSchema)
43+
func (r commitsTable) String() string {
44+
return printTable(
45+
CommitsTableName,
46+
CommitsSchema,
47+
nil,
48+
r.filters,
49+
r.index,
50+
)
4551
}
4652

4753
func (commitsTable) Name() string {

files.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,14 @@ func (filesTable) handledColumns() []string {
149149
return []string{"repository_id", "tree_hash", "blob_hash", "file_path"}
150150
}
151151

152-
func (filesTable) String() string {
153-
return printTable(FilesTableName, FilesSchema)
152+
func (r filesTable) String() string {
153+
return printTable(
154+
FilesTableName,
155+
FilesSchema,
156+
r.projection,
157+
r.filters,
158+
r.index,
159+
)
154160
}
155161

156162
// IndexKeyValues implements the sql.IndexableTable interface.

ref_commits.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,14 @@ var _ Squashable = (*refCommitsTable)(nil)
3737
func (refCommitsTable) isSquashable() {}
3838
func (refCommitsTable) isGitbaseTable() {}
3939

40-
func (refCommitsTable) String() string {
41-
return printTable(RefCommitsTableName, RefCommitsSchema)
40+
func (t refCommitsTable) String() string {
41+
return printTable(
42+
RefCommitsTableName,
43+
RefCommitsSchema,
44+
nil,
45+
t.filters,
46+
t.index,
47+
)
4248
}
4349

4450
func (refCommitsTable) Name() string { return RefCommitsTableName }

references.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,13 @@ func (referencesTable) isSquashable() {}
3636
func (referencesTable) isGitbaseTable() {}
3737

3838
func (r referencesTable) String() string {
39-
return printTable(ReferencesTableName, RefsSchema)
39+
return printTable(
40+
ReferencesTableName,
41+
RefsSchema,
42+
nil,
43+
r.filters,
44+
r.index,
45+
)
4046
}
4147

4248
func (referencesTable) Name() string {

remotes.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@ func (remotesTable) Schema() sql.Schema {
4444
}
4545

4646
func (r remotesTable) String() string {
47-
return printTable(RemotesTableName, RemotesSchema)
47+
return printTable(
48+
RemotesTableName,
49+
RemotesSchema,
50+
nil,
51+
r.filters,
52+
r.index,
53+
)
4854
}
4955

5056
func (r *remotesTable) WithFilters(filters []sql.Expression) sql.Table {

repositories.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,13 @@ func (repositoriesTable) Schema() sql.Schema {
3636
}
3737

3838
func (r repositoriesTable) String() string {
39-
return printTable(RepositoriesTableName, RepositoriesSchema)
39+
return printTable(
40+
RepositoriesTableName,
41+
RepositoriesSchema,
42+
nil,
43+
r.filters,
44+
r.index,
45+
)
4046
}
4147

4248
func (repositoriesTable) HandledFilters(filters []sql.Expression) []sql.Expression {

table.go

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,62 @@ type gitBase interface {
2222
isGitbaseTable()
2323
}
2424

25-
func printTable(name string, tableSchema sql.Schema) string {
25+
func printTable(
26+
name string,
27+
tableSchema sql.Schema,
28+
projection []string,
29+
filters []sql.Expression,
30+
index sql.IndexLookup,
31+
) string {
2632
p := sql.NewTreePrinter()
2733
_ = p.WriteNode("Table(%s)", name)
28-
var schema = make([]string, len(tableSchema))
34+
var children = make([]string, len(tableSchema))
2935
for i, col := range tableSchema {
30-
schema[i] = fmt.Sprintf(
36+
children[i] = fmt.Sprintf(
3137
"Column(%s, %s, nullable=%v)",
3238
col.Name,
3339
col.Type.Type().String(),
3440
col.Nullable,
3541
)
3642
}
37-
_ = p.WriteChildren(schema...)
43+
44+
if len(projection) > 0 {
45+
children = append(children, printableProjection(projection))
46+
}
47+
48+
if len(filters) > 0 {
49+
children = append(children, printableFilters(filters))
50+
}
51+
52+
if index != nil {
53+
children = append(children, printableIndexes(index))
54+
}
55+
56+
_ = p.WriteChildren(children...)
57+
return p.String()
58+
}
59+
60+
func printableFilters(filters []sql.Expression) string {
61+
p := sql.NewTreePrinter()
62+
_ = p.WriteNode("Filters")
63+
var fs = make([]string, len(filters))
64+
for i, f := range filters {
65+
fs[i] = f.String()
66+
}
67+
_ = p.WriteChildren(fs...)
68+
return p.String()
69+
}
70+
71+
func printableProjection(projection []string) string {
72+
p := sql.NewTreePrinter()
73+
_ = p.WriteNode("Projected")
74+
_ = p.WriteChildren(projection...)
75+
return p.String()
76+
}
77+
78+
func printableIndexes(idx sql.IndexLookup) string {
79+
p := sql.NewTreePrinter()
80+
_ = p.WriteNode("Indexes")
81+
_ = p.WriteChildren(idx.Indexes()...)
3882
return p.String()
3983
}

table_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ const expectedString = `Table(foo)
1515
func TestTableString(t *testing.T) {
1616
require := require.New(t)
1717
schema := sql.Schema{
18-
{"col1", sql.Text, nil, true, ""},
19-
{"col2", sql.Int64, nil, false, ""},
18+
{Name: "col1", Type: sql.Text, Nullable: true},
19+
{Name: "col2", Type: sql.Int64},
2020
}
21-
require.Equal(expectedString, printTable("foo", schema))
21+
require.Equal(expectedString, printTable("foo", schema, nil, nil, nil))
2222
}

tree_entries.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,13 @@ func (treeEntriesTable) handledColumns() []string {
122122
}
123123

124124
func (r treeEntriesTable) String() string {
125-
return printTable(TreeEntriesTableName, TreeEntriesSchema)
125+
return printTable(
126+
TreeEntriesTableName,
127+
TreeEntriesSchema,
128+
nil,
129+
r.filters,
130+
r.index,
131+
)
126132
}
127133

128134
// IndexKeyValues implements the sql.IndexableTable interface.

0 commit comments

Comments
 (0)