You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
drivers/python/rethinkdb/_export.py contains the following line: table_size = r.db(db).table(table).count().run(conn)
Apparently the result is used for computing the relative progress.
There are two problems with this:
count() on a large out-of-memory table can be slow.
In extreme cases it can become so slow that it times out, and users cannot backup their tables anymore.
@wojons encountered this, but with an older version of RethinkDB that did the count() inefficiently. However in general it seems plausible that this could occur with a current version as well, if the table is just large enough.
Ideally, we would expose the approximate table count through ReQL and use that to get an approximate progress bar. Probably it should become part of r.table().info().
Another work-around could be to catch timeout errors during the count, print a message and ignore them, or add a command line option to disable count and progress bar, and on a timeout print a message mentioning that option.
how about something like r.table().count({'appox': true}) and then in r.table().info({'count': appox}) would return appoxmant. and {'count': false} would return no count. i think the more felxable the better to avoid werid issues.
r.table().count({approx: true}) is nice too. A problem with it is that it would only work on plain tables. For example if you have an array or a selection (something like r.table(t).between(a, b).count({approx: true})), count({approx: true}) would fail.
Given that it is really an exclusive property of tables, I think I would prefer having it in info().
@neumino: #1118 would do it, but it seems like it's pretty far away.
@danielmewes the cool think about appox is that it does not need to be anywhere near correct lets pretend you run it though sample. so you look at some random ones and then u get there data size and then you use the average size of that to "Guess" the size of the result set. its appoxmenat even if its really off its there choice to use an appoxmat count
I really think we should just do a constant time count. It's not that much harder than approximate count, and will fix a whole bunch of issues (we use count in the UI, etc.) I'll try to schedule it sooner rather than later.
If we can make sure that it works, I'm on board with making count() always use the stats block when it's applied to a table. I.e. implementing O(1) r.table().count().
@coffeemug duh O(n) would be linear time. if it can be O(1) than i would be on board for that. i thought the way myisam does it is that it just keep track of how many records there are and some other intresting stuff. I thnk innodb still uses an appox for many things
Don't assume that O(1) count would use the stats block.
In fact I'll assume that right now (but will try not to assume that in general, fair enough).
Assuming that we implement O(1) count using the stats block or a similar structure, the general problem is that we must not count documents twice if we have replicas in a cluster by the way. We would probably have to keep counts on a per-shard level, and that would require recomputing/adjusting the per-shard counts when resharding. It needs some thought.
@srh: If we never had replicas, counting the number of documents in a table through the stats block would be very easy: Go to all nodes (yes nodes, not shards), let them get the current number of documents in the btree from the stats block, and sum all of those numbers up. That's the number of documents in the table.
Because we can have replication, documents can be on multiple nodes at the same time. So they would be counted multiple times.
Even worse if one of the replicas is currently backfilling. Then we don't even know how many documents of a shard are on the node being backfilled to (and we can't just ignore that node, because it might have the only consistent copy of some other shard at that time).
To account for this, we would need one count per shard in the stat block. But then we have to maintain that when changing the shard boundaries.
We would probably have to keep counts on a per-shard level, and that would require recomputing/adjusting the per-shard counts when resharding. It needs some thought.
This is why you shouldn't assume we'd have counts in the stats block. It's probably better to maintain them for subtrees in the LBA.
This is why you shouldn't assume we'd have counts in the stats block. It's probably better to maintain them for subtrees in the LBA.
Yeah I assumed that mostly because the count is already there (it's actually the only thing in there as far as I know). If we do it for subtrees, it probably shouldn't be in the LBA either. But we could certainly have a block_id -> subtree count map somewhere (it could just be a second btree).
Activity
danielmewes commentedon Feb 21, 2014
Let's make this a ReQL proposal:
Add an entry
approximate_countto the result ofr.table().info(). It would display the approximation which is used in the web ui.neumino commentedon Feb 21, 2014
#1118 would allow a constant
counttoo. That may be a solution.wojons commentedon Feb 21, 2014
how about something like r.table().count({'appox': true}) and then in r.table().info({'count': appox}) would return appoxmant. and {'count': false} would return no count. i think the more felxable the better to avoid werid issues.
danielmewes commentedon Feb 21, 2014
r.table().count({approx: true})is nice too. A problem with it is that it would only work on plain tables. For example if you have an array or a selection (something liker.table(t).between(a, b).count({approx: true})), count({approx: true}) would fail.Given that it is really an exclusive property of tables, I think I would prefer having it in
info().@neumino: #1118 would do it, but it seems like it's pretty far away.
wojons commentedon Feb 21, 2014
@danielmewes the cool think about appox is that it does not need to be anywhere near correct lets pretend you run it though sample. so you look at some random ones and then u get there data size and then you use the average size of that to "Guess" the size of the result set. its appoxmenat even if its really off its there choice to use an appoxmat count
coffeemug commentedon Feb 21, 2014
I really think we should just do a constant time count. It's not that much harder than approximate count, and will fix a whole bunch of issues (we use
countin the UI, etc.) I'll try to schedule it sooner rather than later.wojons commentedon Feb 21, 2014
@coffeemug when you say "constant time count" you mean O(n)?
coffeemug commentedon Feb 21, 2014
No, I mean
O(1).danielmewes commentedon Feb 21, 2014
If we can make sure that it works, I'm on board with making
count()always use the stats block when it's applied to a table. I.e. implementing O(1)r.table().count().wojons commentedon Feb 21, 2014
@coffeemug duh O(n) would be linear time. if it can be O(1) than i would be on board for that. i thought the way myisam does it is that it just keep track of how many records there are and some other intresting stuff. I thnk innodb still uses an appox for many things
srh commentedon Mar 5, 2014
Don't assume that O(1) count would use the stats block.
danielmewes commentedon Mar 5, 2014
In fact I'll assume that right now (but will try not to assume that in general, fair enough).
Assuming that we implement O(1) count using the stats block or a similar structure, the general problem is that we must not count documents twice if we have replicas in a cluster by the way. We would probably have to keep counts on a per-shard level, and that would require recomputing/adjusting the per-shard counts when resharding. It needs some thought.
srh commentedon Mar 5, 2014
How would having replicas in a cluster be a problem? That wouldn't cause any problems with count in a stats block.
danielmewes commentedon Mar 5, 2014
@srh: If we never had replicas, counting the number of documents in a table through the stats block would be very easy: Go to all nodes (yes nodes, not shards), let them get the current number of documents in the btree from the stats block, and sum all of those numbers up. That's the number of documents in the table.
Because we can have replication, documents can be on multiple nodes at the same time. So they would be counted multiple times.
Even worse if one of the replicas is currently backfilling. Then we don't even know how many documents of a shard are on the node being backfilled to (and we can't just ignore that node, because it might have the only consistent copy of some other shard at that time).
To account for this, we would need one count per shard in the stat block. But then we have to maintain that when changing the shard boundaries.
srh commentedon Mar 5, 2014
This is why you shouldn't assume we'd have counts in the stats block. It's probably better to maintain them for subtrees in the LBA.
danielmewes commentedon Mar 6, 2014
Yeah I assumed that mostly because the count is already there (it's actually the only thing in there as far as I know). If we do it for subtrees, it probably shouldn't be in the LBA either. But we could certainly have a block_id -> subtree count map somewhere (it could just be a second btree).
srh commentedon Mar 8, 2014
It would have to be the LBA, because we don't want to go rewriting an entire spine of blocks every time an insertion happens.
coffeemug commentedon Jul 2, 2014
Closing in favor of #152.