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

Most upvoted comments

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

selector: {
}

and

selector: {
  _id: {}
}

To be continued.

@pubkey Can I ask you something?

In the example above you have your selector defined as:

selector: {
  _id: {}
}

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:

selector: {
  _id: 'foobar'
}

I get the document returned (using the default _id index I presume). Also the following (querying on a field that isn’t indexed):

selector: {
  age: 24
}

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.