Slow performance should shrink faster, what is this error about?

The user can post several comments in the stream, and I'm trying to get a list of threads (individual) that the user makes a comment for him, for example: -

// comment table (relation table) id, thread_id, user_id select comment.thread_id, count(*) from user inner join comment on user.id=comment.user_id where user.id = ? group by comment.thread_id; 

It is quite simple in MySQL.
But to convert to couchdb: -

 // map function(doc) { emit(doc.user_id, doc.thread_id); } // reduce function (key, thread_id) { return thread_id; } 

If I use the map function above, I will get an error, for example: -

  "error": "reduce_overflow_error",
 "reason": "Reduce output must shrink more rapidly: Current output: ...

I think I applied the reduction function incorrectly.

If another method is used, for example: -

 // map function (doc) { emit([doc.user_id, doc.thread_id], 1); } // reduce function(keys, values) { return sum(values); } 

The result of group=true looks like mysql group-by does.
However, I cannot get an ALL list of threads by the user (given that I only have user_id at the time of the request)

Thirdly, I can refuse to use a map reduction and apply directly: -

 emit(doc.user_id, doc.thread_id); 

And make a PHP array like

 foreach ( ... ) { $threads[$thread_id] = TRUE; } array_keys($threads); 

However, it is rather bloated and less effective.

The second method looks more accurate: -

 key=[user_id, *] <-- it does not work, believe only work on exact match key=[user_id, thread_id] <-- return one row 

Is there a way to get the result without knowing thread_id?

(ps: I'm new to couchdb and I could describe the script in a bad way)

Some link I got through @jasonsmith: - http://guide.couchdb.org/draft/cookbook.html

As a rule, the reduction function should be reduced to a single scalar value. That is an integer; line; or a small list or object of a fixed size that includes an aggregated value (or values) from an argument of values. It should never just return values ​​or similar. CouchDB will give you a warning if you try to use the "wrong path":

+4
source share
1 answer

Keep track of what this document says: http://wiki.apache.org/couchdb/View_Snippets#Generating_a_list_of_unique_values

 // map function(doc) { emit([doc.user_id, doc.thread_id], null); } // reduce function (keys, values) { return null; } 

Request: -

 ?startkey=["$uid"]&endkey=["$uid",{}]&group=true 

And the result is now for sure,
therefore, the problem is related to the reduction function and how the query is built.

+1
source

Source: https://habr.com/ru/post/1383836/


All Articles