pouchdb: since 7.1.1 a query will not find documents when an index exists but is not used
Issue
Since version 7.1.1 a query will return no documents, when there is an index used.
Info
- Environment: Node.js
- Platform: Linux
- Adapter: memory
Reproduce
I created this test which fails ~9 out of 10 times. I think it is a timing problem~. With the older pouchdb-version, it works.
const PouchDB = require('pouchdb-core');
PouchDB.plugin(require('pouchdb-find'));
PouchDB.plugin(require('pouchdb-adapter-memory'));
const db = new PouchDB(
'things',
{
adapter: 'memory'
}
);
await db.createIndex({
index: {
fields: [
'passportId'
]
}
});
await db.put({
_id: 'foobar',
passportId: 'z3i7q29g4yr1',
firstName: 'Edison',
lastName: 'Keebler',
age: 24
});
const docs = await db.find({
selector: {
_id: {}
},
limit: 1
});
console.dir(docs); // <- empty array
assert.equal(docs.docs.length, 1);
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 1
- Comments: 27 (22 by maintainers)
Commits related to this issue
- ADD test for https://github.com/pouchdb/pouchdb/issues/7810 — committed to pubkey/rxdb by pubkey 5 years ago
- ADD test for #7810 — committed to mardii/pouchdb by pubkey 5 years ago
- ADD test for #7810 — committed to mardii/pouchdb by pubkey 5 years ago
- IMPROVE test for #7810 — committed to mardii/pouchdb by pubkey 4 years ago
- (#7810) - Find documents when index unused — committed to pouchdb/pouchdb by pubkey 5 years ago
- (#7810) - Find documents when index unused Rewrote the test so it is more in line with some of the other tests I found. Also added more variations in test-cases, plus specified the explicit expected ... — committed to pouchdb/pouchdb by deleted user 4 years ago
- (#7810) - Find documents when index unused — committed to sto3psl/pouchdb by pubkey 5 years ago
- (#7810) - Find documents when index unused Rewrote the test so it is more in line with some of the other tests I found. Also added more variations in test-cases, plus specified the explicit expected ... — committed to sto3psl/pouchdb by deleted user 4 years ago
Still valid.
Please remove this useless bot.
No
Fixed in ac03f8a 2a06404
So I’ve been banging my head against this the whole day. @pubkey Cheers for changing the tests and explaining it.
I’m still in the middle of testing a lot, trying to figure out where the problem lies. It doesn’t seem to be an issue with the code differenced of the mentioned change 8aed670. I get the same inconsistencies when undoing those specific changes. I have come through most of the query-planner, but the issue doesn’t seem to be there.
Tomorrow I will try to open up yet another PR to show my tests (I’ve added more scenario’s and moved the test to the find test suites).
I might add inconstancies only popup in the edge cases
and
To be continued.
@pubkey Can I ask you something?
In the example above you have your selector defined as:
I don’t get the syntax of the query. If the selector for
_id
is an empty object, wouldn’t you expect to have 0 results back? It wouldn’t match to any document would it? At least that is my naïve understanding of the syntax.I tried both the jsbin you linked above, and when I do:
I get the document returned (using the default
_id
index I presume). Also the following (querying on a field that isn’t indexed):Gives me back the correct document.
I’m asking because I was looking at this issue after reading your release notes on RxDB (cool stuff!) Lemme know how I can help.
@pubkey the best way to help with this is to start a branch with a failing test that proves the issue. We can then explore a few options to try and fix it.