NoBrainerORM / nobrainer

Ruby ORM for RethinkDB
http://nobrainer.io/
Other
387 stars 49 forks source link

Using index for attr:defined queries #180

Closed ajselvig closed 8 years ago

ajselvig commented 8 years ago

I can't figure out how to use a field's index to query records that have that field defined:

field :foo, index: true

Seems like this should use the index, but the query uses a regular filter statement and I get the perf warning:

Model.where(:foo.defined => true)

Doesn't it seem like this query should be able to be done with getAll on the index?

nviennot commented 8 years ago

Yeah, I'm not sure what RQL I should generate to use the index. Any suggestions?

ajselvig commented 8 years ago

I believe it's something like:

r.table("models").between( r.minval, r.maxval, {"left_bound" => "open", "index" => "foo"})
ajselvig commented 8 years ago

(this is 50x faster than the corresponding filter statement for my particular dataset)

ajselvig commented 8 years ago

Works perfect, thanks!