Skip to content

Count Queries Painfully Slow #1271

Closed
Closed

Description

@dbettin

I talked to @jdoliner about this issue on IRC yesterday. But, I thought it would be worth my time to create an issue regarding the problem.

I have a large table ~30,000 documents, each document is ~150K and when I run a straightforward count query

r.table('mytable').count().run(conn)

it either takes a long time to complete or errors out.

Evidence:

http://snapnote.io/0o4zZT
http://snapnote.io/dw3pRh

In my mind this a major issue and should be addressed before RethinkDB is production ready. Thoughts?

Activity

  1. dbettin commented on Aug 12, 2013

    @dbettin
    Author

    It is no longer "painfully slow", it just doesn't work anymore. It returns the error, mentioned previously, after every query execution. Note: my document count is now around 60,000 for this table.

    Let me know if you need further info.

  2. srh commented on Aug 12, 2013

    @srh
    Contributor

    It seems like you might be seeing the same thing as in #1064 (which is badly titled).

  3. srh commented on Aug 12, 2013

    @srh
    Contributor

    I'm currently looking into #1064. I will include your kind of workload into the testing. It's plausible that .count() could take a long time in general, because it's a naive O(n) function, but it should not fail with such a small table.

  4. ghost assigned on Aug 12, 2013
  5. dbettin commented on Aug 12, 2013

    @dbettin
    Author

    Ok thanks. This is running on a Digital Ocean 32GB/320GB SSD VM

    Also, It is my understanding the naivety of the count query will be addressed in the near term too, is that a correct understanding?

  6. srh commented on Aug 12, 2013

    @srh
    Contributor

    I'm not sure. An efficient count involving a range query that uses the index or primary key, or a count of the entire table, is feasible. It's been something we've meant to do for a while (at least it would improve automatic resharding). This is tracked in issue #152.

  7. coffeemug commented on Aug 12, 2013

    @coffeemug
    Contributor

    I'd like to get better performance for count in, but I'm not sure of the scope yet (i.e. we can obviously do it on the full table, but what can we do for more sophisticated queries). We'll see what we can do here as part of 1.9/2.0 planning.

  8. dbettin commented on Aug 13, 2013

    @dbettin
    Author

    Thanks @coffeemug. This is a pressing issue for us. It would be great to see this resolved in 1.9.

    Also, note, our counts are not that sophisticated; the most complex count query we do is against different values in top level document attributes.

  9. jdoliner commented on Aug 13, 2013

    @jdoliner
    Contributor

    I'm a bit confused about what you mean by: "the most complex count query we do is against different values in top level document attributes" would you mind clarifying?

  10. jdoliner commented on Aug 13, 2013

    @jdoliner
    Contributor

    I'm a bit confused about what you mean by: "the most complex count query we do is against different values in top level document attributes" would you mind clarifying?

  11. dbettin commented on Aug 13, 2013

    @dbettin
    Author

    Sure. We have a requirement to understand the number of documents which match certain states. The table contains a "status" field which the count query would use.

    Ex:

    r.table('table').count(r.row['status'].contains('deployed')).run(conn)

  12. jdoliner commented on Aug 13, 2013

    @jdoliner
    Contributor

    So in order to get that type of query working efficiently we would need to implement #1118. I'm actually starting to think we should just do that for 1.9.

  13. coffeemug commented on Aug 13, 2013

    @coffeemug
    Contributor

    I feel like #1118 might be a bit of an overkill here for a few reasons:

    • People would have to register map/reduce queries to do fast counts. These would also be map/reduce queries that would require inverse functions (we could probably abstract it out, though).
    • Doing incremental map/reduce requires UI/CLI support (so people can list/add/delete jobs), and ReQL support (for same reason, but also to register jobs).
    • It's a non-trivial feature, and adding features before 2.0 worries me.

    An alternative solution might be to implement constant time count for two cases:

    • r.table('foo').count()
    • r.table('foo').between(null, null, index='bar').count()

    This seems relatively easy to do, and the way to speed up the type of queries mentioned by @dbettin (and many other queries) is to just create a secondary index, and do count on that.

    @jdoliner -- would this be hard? Is this schedulable for 1.9?

    Also, I'm going to go to CVS and buy a surgical mask so I don't get people sick, so we may be able to hash this out in person.

  14. coffeemug commented on Aug 13, 2013

    @coffeemug
    Contributor

    On second thought what I said may not actually work (since counting the total number of docs in an index doesn't help with @dbettin's query).

  15. coffeemug commented on Aug 13, 2013

    @coffeemug
    Contributor

    And by that I mean it could work, but would require some gymnastics during index creation on the part of the user.

  16. 41 remaining items

  17. nickpoorman commented on Jul 2, 2014

    @nickpoorman

    ...I should also note, when I'm doing ~2k/sec writes on Ubuntu 13.10, count query from data explorer, appears to always error out. (when run while doing writes)

    RqlRuntimeError: Query interrupted.  Did you shut down the server? in:
    r.db("ml").table("sample_compounds").count()
    
  18. wojons commented on Jul 2, 2014

    @wojons
    Contributor

    @nickpoorman are you on the irc?

  19. nickpoorman commented on Jul 2, 2014

    @nickpoorman
  20. wojons commented on Jul 2, 2014

    @wojons
    Contributor

    @mlucy i have added #2637 i am assuming the count query looks at the btree only but if the btree is large lots of documents, and those documents are small so they are in the index it can lead to slow count perfomance.

  21. coffeemug commented on Jul 2, 2014

    @coffeemug
    Contributor

    This issue is really a dup of #152 (and will be partially improved by #2637 -- thanks @wojons for opening it). Would anyone be opposed if I closed this? I bumped #152 so hopefully it won't be a problem for much longer.

  22. nickpoorman commented on Jul 2, 2014

    @nickpoorman

    I would not be opposed

  23. coffeemug commented on Jul 2, 2014

    @coffeemug
    Contributor

    Closing. Please reopen if there is anything in the scope of this issue that isn't covered by #152/#2637.

  24. modified the milestones: duplicate, subsequent on Jul 2, 2014
  25. mlucy commented on Jul 3, 2014

    @mlucy
    Member

    I think there's another issue here, which is that the performance falls off a cliff under write load. If that's happening for count queries, it's probably happening for all aggregations. I'll open a separate issue for that.

  26. PrakashThapa commented on Apr 18, 2015

    @PrakashThapa

    RethinkDB count() function is always slow.I testing it since 1.12 till the latest stable. the table count might be fine but once there are intermediate opetation it simple cannot be use. very slow.

  27. danielmewes commented on Apr 18, 2015

    @danielmewes
    Member

    @PrakashThapa This is probably because the intermediate operations cause RethinkDB to compute every result item before counting it. For certain types of operations (specifically getAll and between operations), we will make counts very fast with #3949. This is still a few releases away though unfortunately.

  28. lucasjans commented on Apr 19, 2016

    @lucasjans

    @danielmewes is this getting any closer? we need to be able to do .count against indexes (getall or between). our data set has 7mb records and it is far too slow. engineering our own solution outside Rethink is complexity I would prefer to avoid.

  29. danielmewes commented on Apr 21, 2016

    @danielmewes
    Member

    @lucasjans The solution outlined in #3949 (comment) is going to solve your use case. However I can't tell for sure yet when we will ship this, as it's only one among a bunch of other features we are working on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions