ostafen / clover

A lightweight document-oriented NoSQL database written in pure Golang.
MIT License
633 stars 54 forks source link

GT LT operation very slow #106

Open DreamVersion opened 1 year ago

DreamVersion commented 1 year ago

query like query :=clover.NewQuery("stat"). Where(clover.Field("stat_time").GtEq("2022-11-14"). And(clover.Field("stat_time").LtEq("2022-11-15")). And(clover.Field("ad_id").Eq("1749344214764583"))). Sort(clover.SortOption{Field: "stat_time", Direction: 1}) very fast. but query :=clover.NewQuery("stat"). Where(clover.Field("ad_id").Eq("1749344214764583")). And(clover.Field("stat_time").LtEq("2022-11-15")). And(clover.Field("stat_time").GtEq("2022-11-14")). Sort(clover.SortOption{Field: "stat_time", Direction: 1}) very slow. Why?

ostafen commented 1 year ago

Can you tell me which version of the library you are using and the size of your collection? If the collection is big, you should probably use indexes, which are available in the v2 version Anyway, using string dates is not a good idea for comparison

DreamVersion commented 1 year ago

I'm using v2 version and collection about 140Mb. I try to use time.Time type, but get the same result. I see only support one index, then ad_id is the index. The size of docs when ad_id="1749344214764583" is about 10. Range query of this 10 docs expects to be very fast.

ostafen commented 1 year ago

So do you have an index set on ad_id?