Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support simple query pushdown for Tigris #897

Closed
seeforschauer opened this issue Jul 15, 2022 · 0 comments · Fixed by #1091
Closed

Support simple query pushdown for Tigris #897

seeforschauer opened this issue Jul 15, 2022 · 0 comments · Fixed by #1091
Assignees
Labels
code/feature Some user-visible feature is not implemented yet
Milestone

Comments

@seeforschauer
Copy link
Contributor

The goal of this task is to enable a simple query pushdown for querier that looks like {_id: <ObjectID>}.
Only that field name (_id) is supported, and only that value type (ObjectID).

In the future, we will add support for other fields (starting with simple scalar fields),
other values (starting with strings, numbers, and other simple scalar values),
other conditions like {_id: <ObjectID>, field: value} (so only the first part is pushed down).

Tigris

Support tables where the primary key is only one field.

The tjson package ensures that primary key is always ["_id"] and always 1 length.
So no need to check:

  • it's not necessary to get the schema description to check Primary Key fields and it's count.
  • if len(schema.PrimaryKey) > 1 raise error.
    • because user expects single one value in _id.
    • to comply and be compatible with MongoDB.
  • if len(schema.PrimaryKey) == 0 raise error.

But need to check if valaue type if not ObjectID (raise error in that case).

Proof of concept for a {_id: <ObjectID>} pushdown query, Tigris, see example.

_, err = db.Insert(ctx, "coll1", []driver.Document{[]byte(`{"$k":["_id","int32"],"_id":"AAECBAUGBwgJCgsM","int32":42}`)})
if err != nil {
	panic(err)
}
doc, _ := types.NewDocument("_id", types.ObjectID{0x00, 0x01, 0x02, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c})
id := must.NotFail(doc.Get("_id")).(types.ObjectID)
f := must.NotFail(filter.Eq("_id", tjson.ObjectID(id)).Build())
it, err := db.Read(ctx, "coll1", f, nil)
if err != nil {
	panic(err)
}

var tdoc driver.Document
for it.Next(&tdoc) {
	fmt.Println("found:")
	fmt.Printf("%s\n", string(tdoc))
}
if err := it.Err(); err != nil {
	panic(err)
}

Test

Integration tests.
Provide a new test flag that enables a query pushdown.
Run with and without flag: results must be the same.
When explain feature will be ready, compare the query plan.

Links

Issue analysis: #847

@seeforschauer seeforschauer added the code/feature Some user-visible feature is not implemented yet label Jul 15, 2022
@AlekSi AlekSi self-assigned this Aug 22, 2022
@AlekSi AlekSi added this to the v0.6.0 Alpha milestone Aug 22, 2022
AlekSi added a commit that referenced this issue Sep 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code/feature Some user-visible feature is not implemented yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants