Question: I would like the user to perform different tasks via HttpGet/HttpPost actions. 
I would like to save the Cookies so that the user only needs to login after expiration of the cookie. 

When traversing the internet I saw that the "PersistentCookiestore" is a good starting point. 

Question 1: how can I use the (apache) PersistentCookieStore in the HttpClient software? I don't see complete examples, e.g. how to start using the PersistentCookieStore in the first httpclient use. 

See for example: 

```
static PersistentCookieStore cookie_jar = new PersistentCookieStore( getApplicationContext()); 

public void login() { 
    // how to connect the persistent cookie store to the HttpClient? 
    ....
    client2 = new DefaultHttpClient( httpParameters);
    …
    client2.setCookieStore(cookie_jar);
    ....
    HttpGet method2 = new HttpGet(uri2);
    ....
    try {
     res = client2.execute(method2); 
}
catch ( ClientProtocolException e1) { e1.printStackTrace(); return false; }
    ....

```

Question 2: How can I update the cookie after a call, or is this never needed? 
In other words: When I have to update the cookie after a call to HttpGet or HttpPost after calling the client2.execute( ...). 

In the example code of (non-persistent) cookies with httpclient I saw: 

```
cookie_jar = client.getCookieStore(); 
….
HttpGet or HttpPost … 
client.setCookieStore( ....) 
client.execute( .. )  // second call

```

Thank you for helping.

Answer: 
Your attempt will do one sub query for each row in **collections**, that's why it takes a long time. You should be able to see that with `explain update...`if you are using mysql 5.6.

I think the best solution is to either maintain the counts through a trigger or to snapshot them into another table (MySQL is picky about writing and reading the same table in one query). Then you could snapshot like this

```
replace into collections_counts
 select C.id, count(1)
   from collections C
   join collection_users CU on (C.id = CU.collections_id)
  group by C.id;

```

Then just join in that table on every fetch of collection
Do you also have an index on C.id?

I think the problem is with the WHERE CU.collection\_id = C.id which is being executed for each line (with the select count).

P.S. - try checkin the execution plan, make sure it makes sense - it might be that the statistics are not current, so the plan is not using indexes at all...