Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default index on _id used even though there are better ones available #609

Closed
gvuyk opened this issue Apr 15, 2018 · 0 comments
Closed

Default index on _id used even though there are better ones available #609

gvuyk opened this issue Apr 15, 2018 · 0 comments
Labels

Comments

@gvuyk
Copy link
Contributor

gvuyk commented Apr 15, 2018

Case

Bug

Issue

When querying a collection, the default index on _id is used even though there are other more suitable indexes available. Checked on pouchdb directly and the same query does use another index there.

After a little research, noticed that if no sorting is requested, the default is to sort by _id, which seems to enforce the use of the default index.
When explicitly sorting by another field, a better index is used. Same if I remove the line which forces the sort on _id

Info

  • Environment: Node.js

Code

To reproduce, set env var DEBUG to "pouchdb:find"
First query does not use the index on passportId
Second query does use the index on passportId

const RxDB = require("rxdb");
RxDB.plugin(require("pouchdb-adapter-memory"));

async function test()
{
	var db = await RxDB.create({
		name: "testdb",
		adapter: "memory",
		multiInstance: false
	});
	var mySchema = {
		version: 0,
		disableKeyCompression: true,
		type: "object",
		properties: {
			name: {type: "string"},
			passportId: {type: "string", index: true}
		}
	};
	let collection = await db.collection({name: "person", schema: mySchema});
	await collection.insert({
		name: "abc",
		passportId: "foobar"
	});
	console.log("\nFirst query");
	await collection.findOne({passportId: "foofbar"}).exec();

	console.log("\nSecond query");
	await collection.findOne({passportId: "foofbar"}).sort("passportId").exec();
}
test();

First query
withsorton_id
Second query
withoutsorton_id

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants