Comments (11)
You might not be getting a performance increase due to the fact that you are filtering multiple times. Try the following code:
rows, err := r.Table(CensusTableName).GetAllByIndex("Name", name).OrderBy(rethink.Desc("Year")).Run(session)
from rethinkdb-go.
Sorry about that! That was exactly what I was looking for. Will this also work for multiple column index?
from rethinkdb-go.
It should work with compound indexes. For example:
rows, err := r.Table(CensusTableName).GetAllByIndex("Name", field1, field2).OrderBy(rethink.Desc("Year")).Run(session)
Where the index Name contains two fields.
from rethinkdb-go.
Thanks so helpful I will try that next.
from rethinkdb-go.
@lateefj Did you ever get compound indexes working with gorethink? It works in the rethink data explorer but does not appear to work with gorethink at all. That is to say, it returns 0 rows for the exact same query that the data explorer returns rows.
from rethinkdb-go.
@dancannon Does the test suite cover compound indexes? Have other people successfully used them? They really don't seem to work at all. Regular secondary indexes work, and compound indexes work with the javascript driver, but not with gorethink.
from rethinkdb-go.
@wildattire I couldn't get them to work.
from rethinkdb-go.
@wildattire they works for me, but let's move a discussion to #65.
from rethinkdb-go.
@dancannon couldn't get following to work.
rows, err := r.Table(CensusTableName).GetAllByIndex("Name", value).OrderBy(rethink.Desc("Year")).Run(session)
Both Name and Year are indexed. Should they be compound indexed??
from rethinkdb-go.
I just create this simple program which seems to show it working. Could you maybe explain what is going wrong with your program?
package main
import (
r "github.com/dancannon/gorethink"
"github.com/davecgh/go-spew/spew"
)
func main() {
r.SetVerbose(true)
s, err := r.Connect(r.ConnectOpts{
Address: "localhost:28015",
})
if err != nil {
panic(err)
}
r.DB("issues").TableDrop("census").Exec(s)
r.DB("issues").TableCreate("census").Exec(s)
r.DB("issues").Table("census").IndexCreate("Name").Exec(s)
r.DB("issues").Table("census").IndexWait().Exec(s)
if err := r.DB("issues").Table("census").Insert(map[string]interface{}{
"Name": "John Smith",
"Year": 1970,
}).Exec(s); err != nil {
panic(err)
}
cursor, err := r.DB("issues").Table("census").GetAllByIndex("Name", "John Smith").OrderBy(r.Desc("Year")).Run(s)
if err != nil {
panic(err)
}
var v interface{}
err = cursor.One(&v)
if err != nil {
panic(err)
}
spew.Dump(v)
}
from rethinkdb-go.
@dancannon Thanks for quick reply. It turns out that above doesn't work if orderBy
is on indexed field.
r.DB("issues").Table("census").GetAllByIndex("Name", "John Smith").OrderBy(r.Desc("Year")).Run(s)
If Year
is indexed and you give {Index: r.Desc("Year")}
it gives error.
In that case orderBy
should be
r.DB("issues").Table("census").OrderBy(r.OrderByOpts{Index: r.Desc("Year")}).Filter(map[string]interface{}{"Name": "John Smith"}).Run(s)
from rethinkdb-go.
Related Issues (20)
- How to use join HOT 1
- IsEmpty result HOT 1
- v6 is opening ConnectOpts.MaxOpen connections when connecting
- Session.IsConnected not detecting disconnection HOT 8
- v6 read timeout closes connection
- Add support for Change Feed Offsets
- Connection pool performance HOT 5
- `v5` HOT 1
- Panic on session.Close()
- go mod path HOT 3
- Bug: a single string array field is returned as multiple strings. HOT 1
- data race in pool.go HOT 3
- Field("field").Field("field") nil
- Make possibility for Term to be marshalled and unmarshalled (for instance with json or yaml), so Term could be saved/loaded to/from some storage.
- Unable to connect when `TimeOut` is specified HOT 1
- Connection pool is not safe HOT 3
- Contexts not working properly in certain scenarios
- WriteResponse does not return GeneratedKeys
- Utilize MarshalJSON and UnmarshalJSON interface implementations HOT 2
- Go Lang replaces get to install. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rethinkdb-go.