@geraldss,
First of all: “There were some gaps in the COUNT() optimizations in 4.1, and we fixed those in 4.5.” sounds very strange, because 4.1.1 is RECOMMENDED now as stable (as 4.1.0 was recommended before), and 4.5 is still beta. I REALLY think, that “gaps fixes” that you’ve mentioned, shoud be backported to 4.1.X branch. Because it’s really weird: to know about a problem, declare “4.1.0/4.1.1 is stable now” and don’t mention this bug as “known issues” for 4.1.0/4.1.1 (Couchbase SDKs). So there is a good chance to backport this to 4.1.2, if, of course, management team will allow this.
ok, technical aspects: i wrote a simple sync-test (code) below, and multiple runs tells me that there are stable 2 errors for COUNT(1) per each 100 calls for separate run:
0 =>[{“msg”:“Encoded plan parameter does not match encoded plan of 3e5d691a6480801871cae0bffb4814ab34d2befc”,“code”:4080}]
1 =>[{“msg”:“Encoded plan parameter does not match encoded plan of 3e5d691a6480801871cae0bffb4814ab34d2befc”,“code”:4080}]
DONE with i = 100
Create 3 indexes like:
“create index i1 on bucket.name(a,b) where a is valued;”
“create index i2 on bucket.name(a,b) where a is valued;”
“create index i3 on bucket.name(a,b) where a is valued;”
You can use even empty buckets. Then run the code :
package n1qlcount;
import com.couchbase.client.java.Bucket;
import com.couchbase.client.java.Cluster;
import com.couchbase.client.java.CouchbaseCluster;
import com.couchbase.client.java.document.json.JsonArray;
import com.couchbase.client.java.env.CouchbaseEnvironment;
import com.couchbase.client.java.env.DefaultCouchbaseEnvironment;
import com.couchbase.client.java.query.N1qlParams;
import com.couchbase.client.java.query.N1qlQuery;
import com.couchbase.client.java.query.N1qlQueryResult;
import com.couchbase.client.java.query.consistency.ScanConsistency;
import java.util.Collections;
import java.util.LinkedList;
public class N1QLCount {
public static void main(String[] args) {
CouchbaseEnvironment ce = DefaultCouchbaseEnvironment.create();
final LinkedList<String> nodes = new LinkedList();
nodes.add("A");
nodes.add("B");
nodes.add("C");
Cluster cluster = CouchbaseCluster.create(ce, nodes);
final String bucketName = "bucket.name";
final String bucketPass = "password";
final String fieldA = "a";
final String fieldB = "b";
Bucket b = cluster.openBucket(bucketName, bucketPass);
final N1qlParams p = N1qlParams
.build()
.adhoc(false)
.consistency(ScanConsistency.REQUEST_PLUS);
final String Q =
"SELECT COUNT(1) from `"
+ bucketName
+ "` WHERE "
+ fieldA
+ "=$1 AND "
+ fieldB
+ "=$2;";
JsonArray ja = null;
N1qlQueryResult r = null;
int count = 100, i = 0;
for(i = 0; i< count; i++) {
ja = JsonArray.empty().add("A" + i).add("B" + i);
r = b.query(N1qlQuery.parameterized(Q, ja , p));
if(r.errors().size() > 0) {
System.out.println(i + " =>" + r.errors().toString());
}
}
System.out.println("DONE with i = " + i);
b.close();
}
}
So, it’s defenetly a bug for 4.1.x. The question is “what we gonna do with this” ?