Skip to content

Conversation

@erizocosmico
Copy link
Contributor

Closes #450

@erizocosmico erizocosmico requested a review from a team September 4, 2018 13:55
DisableSquash bool `long:"no-squash" description:"Disables the table squashing."`
TraceEnabled bool `long:"trace" env:"GITBASE_TRACE" description:"Enables jaeger tracing"`
ReadOnly bool `short:"r" long:"readonly" description:"Only allow read queries. This disables creating and deleting indexes as well." env:"GITBASE_READONLY"`
Parallelism uint `long:"parallelism" default:"4" description:"Maximum number of parallel threads per table."`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe default GOMAXPROCS

func NewDatabaseEngine(
readonly bool,
version string,
parallelism int,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uint?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only needs to be uint in the flag, so the user can't input less than 0, after that it doesn't matter

ab = ab.ReadOnly()
}

if parallelism > 1 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe 0 means by default, 1 - no parallelize

if len(i.repos) == 0 || stringContains(i.repos, repo.ID) {
var err error
commits, err = NewCommitsByHashIter(repo, i.commitHashes)
var commitTreesHashIdx = CommitTreesSchema.IndexOf("commit_hash", CommitTreesTableName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why it's a package var? Can be a function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this value will be used in other functions

Copy link
Contributor

@mcarmonaa mcarmonaa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like how the new interfaces make simpler the table's implementation.

Apart from the questions, LGTM

func (r *blobsTable) TransformUp(f sql.TransformNodeFunc) (sql.Node, error) {
return f(r)
func (r *blobsTable) WithFilters(filters []sql.Expression) sql.Table {
nt := *r
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've seen this in the rest of the tables too, why can't r be used directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it returns a new instance. By deref-ing the table, it makes a copy, so we don't have to manually create a table with all the fields, just modify the ones needed in the copy and return it as a pointer.
If in the future the table has more fields, we don't have to go to these methods and add the fields to the new instance.

commit_blobs.go Outdated
func (t *commitBlobsTable) TransformExpressionsUp(f sql.TransformExprFunc) (sql.Node, error) {
return t, nil
func (t *commitBlobsTable) WithProjection(colNames []string) sql.Table {
return t
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't accept this table pushdowns of projections?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, only blobs and files, which don't read the blob if the blob_content is not pushed down

commit_files.go Outdated
func (t *commitFilesTable) TransformExpressionsUp(f sql.TransformExprFunc) (sql.Node, error) {
return t, nil
func (t *commitFilesTable) WithProjection(colNames []string) sql.Table {
return t
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't accept this table pushdowns of projections?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same answer

commit_trees.go Outdated
func (t *commitTreesTable) TransformExpressionsUp(f sql.TransformExprFunc) (sql.Node, error) {
return t, nil
func (t *commitTreesTable) WithProjection(colNames []string) sql.Table {
return t
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't accept this table pushdowns of projections?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same answer

commits.go Outdated

return sql.NewSpanIter(span, repoIter), nil
func (r *commitsTable) WithProjection(colNames []string) sql.Table {
return r
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't accept this table pushdowns of projections?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same answer

ref_commits.go Outdated
func (t *refCommitsTable) TransformExpressionsUp(f sql.TransformExprFunc) (sql.Node, error) {
return t, nil
func (t *refCommitsTable) WithProjection(colNames []string) sql.Table {
return t
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't accept this table pushdowns of projections?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same answer

references.go Outdated
func (r *referencesTable) TransformExpressionsUp(f sql.TransformExprFunc) (sql.Node, error) {
return r, nil
func (r *referencesTable) WithProjection(colNames []string) sql.Table {
return r
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't accept this table pushdowns of projections?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could maybe just remove this methods so the tables don't implement ProjctedTable

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@erizocosmico yep, that is a good idea.

remotes.go Outdated
func (r *remotesTable) TransformExpressionsUp(f sql.TransformExprFunc) (sql.Node, error) {
return r, nil
func (r *remotesTable) WithProjection(colNames []string) sql.Table {
return r
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't accept this table pushdowns of projections?

repositories.go Outdated

return sql.NewSpanIter(span, rowRepoIter), nil
func (r *repositoriesTable) WithProjection(colNames []string) sql.Table {
return r
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't accept this table pushdowns of projections?

tree_entries.go Outdated

return sql.NewSpanIter(span, repoIter), nil
func (r *treeEntriesTable) WithProjection(colNames []string) sql.Table {
return r
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't accept this table pushdowns of projections?

@ajnavarro
Copy link
Contributor

@erizocosmico I would say to remove all the table methods that are not being used (WithFilter, WithProjects and so on). The new API is modular and we don't need them if the table is not making use of them.

@erizocosmico
Copy link
Contributor Author

Only WithProjection is not being used. The rest is. Will remove that from all tables that don't need it

@erizocosmico
Copy link
Contributor Author

Done @ajnavarro @mcarmonaa

@erizocosmico
Copy link
Contributor Author

Changed the default parallelism @kuba--

@erizocosmico
Copy link
Contributor Author

Tests will pass once src-d/go-mysql-server#345 is merged and go-mysql-server upgraded.

@erizocosmico
Copy link
Contributor Author

Tests should be passing now

Copy link
Contributor

@ajnavarro ajnavarro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some problems regarding the usage of partitions and join pushdown. Per example, this query:

SELECT count(*) FROM commits c NATURAL JOIN ref_commits r WHERE r.ref_name = 'HEAD';

It's using exchange nodes, but the pushdown node disappear compared to the previous version.

@erizocosmico
Copy link
Contributor Author

Just fixed the issue with the exchanges and the squashed tables

@ajnavarro
Copy link
Contributor

ajnavarro commented Sep 7, 2018

More bugs found:

Results are not the same:

Query: SELECT count(*) FROM commits c NATURAL JOIN ref_commits r WHERE r.ref_name = 'HEAD';

OLD

+----------+
| COUNT(*) |
+----------+
|   116393 |
+----------+
1 row in set (1 min 28,39 sec)

NEW

+----------+
| COUNT(*) |
+----------+
|   115735 |
+----------+
1 row in set (45,18 sec)

Result of DESCRIBE TABLE ref_commits:

mysql> describe table ref_commits;
+---------------+-------+
| name          | type  |
+---------------+-------+
| repository_id | TEXT  |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| history_index | INT64 |
| repository_id | TEXT  |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| history_index | INT64 |
| repository_id | TEXT  |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| history_index | INT64 |
| repository_id | TEXT  |
| repository_id | TEXT  |
| commit_hash   | TEXT  |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| ref_name      | TEXT  |
| history_index | INT64 |
| history_index | INT64 |
| repository_id | TEXT  |
| commit_hash   | TEXT  |
| repository_id | TEXT  |
| repository_id | TEXT  |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| history_index | INT64 |
| ref_name      | TEXT  |
| repository_id | TEXT  |
| history_index | INT64 |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| history_index | INT64 |
| repository_id | TEXT  |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| history_index | INT64 |
| repository_id | TEXT  |
| repository_id | TEXT  |
| commit_hash   | TEXT  |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| commit_hash   | TEXT  |
| history_index | INT64 |
| ref_name      | TEXT  |
| history_index | INT64 |
| ref_name      | TEXT  |
| history_index | INT64 |
| repository_id | TEXT  |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| history_index | INT64 |
| repository_id | TEXT  |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| history_index | INT64 |
| repository_id | TEXT  |
| repository_id | TEXT  |
| commit_hash   | TEXT  |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| ref_name      | TEXT  |
| history_index | INT64 |
| history_index | INT64 |
| repository_id | TEXT  |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| history_index | INT64 |
| repository_id | TEXT  |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| history_index | INT64 |
| repository_id | TEXT  |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| history_index | INT64 |
| repository_id | TEXT  |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| history_index | INT64 |
| repository_id | TEXT  |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| history_index | INT64 |
| repository_id | TEXT  |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| history_index | INT64 |
| repository_id | TEXT  |
| repository_id | TEXT  |
| commit_hash   | TEXT  |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| ref_name      | TEXT  |
| history_index | INT64 |
| history_index | INT64 |
| repository_id | TEXT  |
| commit_hash   | TEXT  |
| repository_id | TEXT  |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| history_index | INT64 |
| repository_id | TEXT  |
| repository_id | TEXT  |
| repository_id | TEXT  |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| ref_name      | TEXT  |
| repository_id | TEXT  |
| commit_hash   | TEXT  |
| commit_hash   | TEXT  |
| history_index | INT64 |
| repository_id | TEXT  |
| repository_id | TEXT  |
| repository_id | TEXT  |
| commit_hash   | TEXT  |
| history_index | INT64 |
| ref_name      | TEXT  |
| ref_name      | TEXT  |
| repository_id | TEXT  |
| commit_hash   | TEXT  |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| commit_hash   | TEXT  |
| history_index | INT64 |
| commit_hash   | TEXT  |
| history_index | INT64 |
| repository_id | TEXT  |
| history_index | INT64 |
| ref_name      | TEXT  |
| ref_name      | TEXT  |
| ref_name      | TEXT  |
| commit_hash   | TEXT  |
| repository_id | TEXT  |
| ref_name      | TEXT  |
| ref_name      | TEXT  |
| commit_hash   | TEXT  |
| history_index | INT64 |
| history_index | INT64 |
| repository_id | TEXT  |
| repository_id | TEXT  |
| history_index | INT64 |
| history_index | INT64 |
| history_index | INT64 |
| repository_id | TEXT  |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| history_index | INT64 |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| history_index | INT64 |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| history_index | INT64 |
| ref_name      | TEXT  |
| repository_id | TEXT  |
| repository_id | TEXT  |
| commit_hash   | TEXT  |
| repository_id | TEXT  |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| history_index | INT64 |
| repository_id | TEXT  |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| history_index | INT64 |
| repository_id | TEXT  |
| commit_hash   | TEXT  |
| history_index | INT64 |
| repository_id | TEXT  |
| ref_name      | TEXT  |
| commit_hash   | TEXT  |
| commit_hash   | TEXT  |
| history_index | INT64 |
| ref_name      | TEXT  |
| ref_name      | TEXT  |
| history_index | INT64 |
| history_index | INT64 |
| repository_id | TEXT  |
| ref_name      | TEXT  |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| history_index | INT64 |
| history_index | INT64 |
| repository_id | TEXT  |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| history_index | INT64 |
| repository_id | TEXT  |
| repository_id | TEXT  |
| commit_hash   | TEXT  |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| ref_name      | TEXT  |
| repository_id | TEXT  |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| history_index | INT64 |
| history_index | INT64 |
| history_index | INT64 |
| repository_id | TEXT  |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| history_index | INT64 |
| repository_id | TEXT  |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| history_index | INT64 |
| repository_id | TEXT  |
| repository_id | TEXT  |
| repository_id | TEXT  |
| repository_id | TEXT  |
| repository_id | TEXT  |
| repository_id | TEXT  |
| repository_id | TEXT  |
| repository_id | TEXT  |
| commit_hash   | TEXT  |
| commit_hash   | TEXT  |
| commit_hash   | TEXT  |
| commit_hash   | TEXT  |
| commit_hash   | TEXT  |
| commit_hash   | TEXT  |
| commit_hash   | TEXT  |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| ref_name      | TEXT  |
| ref_name      | TEXT  |
| ref_name      | TEXT  |
| ref_name      | TEXT  |
| ref_name      | TEXT  |
| ref_name      | TEXT  |
| ref_name      | TEXT  |
| history_index | INT64 |
| history_index | INT64 |
| history_index | INT64 |
| history_index | INT64 |
| history_index | INT64 |
| history_index | INT64 |
| repository_id | TEXT  |
| history_index | INT64 |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| history_index | INT64 |
| repository_id | TEXT  |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| history_index | INT64 |
| history_index | INT64 |
| repository_id | TEXT  |
| repository_id | TEXT  |
| repository_id | TEXT  |
| commit_hash   | TEXT  |
| commit_hash   | TEXT  |
| repository_id | TEXT  |
| repository_id | TEXT  |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| history_index | INT64 |
| ref_name      | TEXT  |
| repository_id | TEXT  |
| history_index | INT64 |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| ref_name      | TEXT  |
| history_index | INT64 |
| history_index | INT64 |
| repository_id | TEXT  |
| repository_id | TEXT  |
| commit_hash   | TEXT  |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| history_index | INT64 |
| ref_name      | TEXT  |
| repository_id | TEXT  |
| commit_hash   | TEXT  |
| repository_id | TEXT  |
| history_index | INT64 |
| ref_name      | TEXT  |
| commit_hash   | TEXT  |
| history_index | INT64 |
| ref_name      | TEXT  |
| commit_hash   | TEXT  |
| history_index | INT64 |
| repository_id | TEXT  |
| repository_id | TEXT  |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| ref_name      | TEXT  |
| history_index | INT64 |
| history_index | INT64 |
| repository_id | TEXT  |
| commit_hash   | TEXT  |
| repository_id | TEXT  |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| history_index | INT64 |
| repository_id | TEXT  |
| commit_hash   | TEXT  |
| commit_hash   | TEXT  |
| repository_id | TEXT  |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| ref_name      | TEXT  |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| repository_id | TEXT  |
| history_index | INT64 |
| ref_name      | TEXT  |
| repository_id | TEXT  |
| history_index | INT64 |
| history_index | INT64 |
| repository_id | TEXT  |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| repository_id | TEXT  |
| history_index | INT64 |
| commit_hash   | TEXT  |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| history_index | INT64 |
| commit_hash   | TEXT  |
| repository_id | TEXT  |
| history_index | INT64 |
| repository_id | TEXT  |
| ref_name      | TEXT  |
| ref_name      | TEXT  |
| ref_name      | TEXT  |
| repository_id | TEXT  |
| repository_id | TEXT  |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| history_index | INT64 |
| history_index | INT64 |
| history_index | INT64 |
| commit_hash   | TEXT  |
| repository_id | TEXT  |
| ref_name      | TEXT  |
| commit_hash   | TEXT  |
| history_index | INT64 |
| ref_name      | TEXT  |
| history_index | INT64 |
| history_index | INT64 |
| commit_hash   | TEXT  |
| repository_id | TEXT  |
| commit_hash   | TEXT  |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| repository_id | TEXT  |
| repository_id | TEXT  |
| ref_name      | TEXT  |
| ref_name      | TEXT  |
| repository_id | TEXT  |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| history_index | INT64 |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| history_index | INT64 |
| history_index | INT64 |
| history_index | INT64 |
| repository_id | TEXT  |
| commit_hash   | TEXT  |
| history_index | INT64 |
| repository_id | TEXT  |
| repository_id | TEXT  |
| commit_hash   | TEXT  |
| repository_id | TEXT  |
| repository_id | TEXT  |
| repository_id | TEXT  |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| history_index | INT64 |
| commit_hash   | TEXT  |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| repository_id | TEXT  |
| ref_name      | TEXT  |
| history_index | INT64 |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| history_index | INT64 |
| repository_id | TEXT  |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| ref_name      | TEXT  |
| history_index | INT64 |
| history_index | INT64 |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| repository_id | TEXT  |
| history_index | INT64 |
| ref_name      | TEXT  |
| history_index | INT64 |
| history_index | INT64 |
| history_index | INT64 |
| commit_hash   | TEXT  |
| ref_name      | TEXT  |
| history_index | INT64 |
+---------------+-------+
400 rows in set (0,00 sec)

@ajnavarro
Copy link
Contributor

@erizocosmico can you rebase and update go-mysql-server with the new fixes please?

@erizocosmico
Copy link
Contributor Author

yup

Signed-off-by: Miguel Molina <miguel@erizocosmi.co>
Signed-off-by: Miguel Molina <miguel@erizocosmi.co>
Signed-off-by: Miguel Molina <miguel@erizocosmi.co>
Signed-off-by: Miguel Molina <miguel@erizocosmi.co>
Signed-off-by: Miguel Molina <miguel@erizocosmi.co>
Signed-off-by: Miguel Molina <miguel@erizocosmi.co>
Signed-off-by: Miguel Molina <miguel@erizocosmi.co>
Signed-off-by: Miguel Molina <miguel@erizocosmi.co>
Signed-off-by: Miguel Molina <miguel@erizocosmi.co>
@erizocosmico
Copy link
Contributor Author

Rebased and upgraded

Signed-off-by: Miguel Molina <miguel@erizocosmi.co>
Signed-off-by: Miguel Molina <miguel@erizocosmi.co>
@erizocosmico
Copy link
Contributor Author

@ajnavarro I cannot reproduce the discrepancy in results with the query you gave me. Can you try again now to see if this was maybe fixed by the update of go-mysql-server?

@ajnavarro
Copy link
Contributor

@erizocosmico having the same problem. I'm using $HOME/work/src/github.com/ to get the discrepancy.

@erizocosmico
Copy link
Contributor Author

@ajnavarro with or without indexes?

@ajnavarro
Copy link
Contributor

@erizocosmico without indexes.

@erizocosmico
Copy link
Contributor Author

I thought I had reproduced this but turns out the discrepancy was because I was running the old one on master, which does not have the commits from this branch.

So, still can't reproduce this running it over all my $HOME/go/src/github.com.

Are you running both or the result of the old version is what you got when you ran it back then?

Copy link
Contributor

@ajnavarro ajnavarro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all bugs resolved.

@ajnavarro ajnavarro merged commit 466a785 into src-d:master Sep 10, 2018
@erizocosmico erizocosmico deleted the feature/partitions branch September 18, 2018 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants