Performance 如何提高数据库查找查询的性能?
我在react native中使用couchDB的PockDB复制。这是my package.json:Performance 如何提高数据库查找查询的性能?,performance,indexing,couchdb,pouchdb,Performance,Indexing,Couchdb,Pouchdb,我在react native中使用couchDB的PockDB复制。这是my package.json: "pouchdb": "^6.3.4", "pouchdb-find": "^6.3.4", "pouchdb-react-native": "^6.3.4", 我有一个名为“databaseA”的数据库,其中一列是“col1”。我已经使用PockDB find编写了一个查询,以获取数据库中所有匹配的记录 col1中的值 const localDB = new PouchDB('datab
"pouchdb": "^6.3.4",
"pouchdb-find": "^6.3.4",
"pouchdb-react-native": "^6.3.4",
我有一个名为“databaseA”的数据库,其中一列是“col1”。我已经使用PockDB find编写了一个查询,以获取数据库中所有匹配的记录
col1中的值
const localDB = new PouchDB('databaseA');
const remoteDB = new PouchDB('databaseA');
PouchDB.plugin(findPlugin);
localDB.replicate.from(
remoteDB,
(err, response) => {
if (err) {
return console.log(err);
}
},
);
localDB.createIndex({
index: {
fields: ['col1', 'col2'],
ddoc: 'col1-col2-index',
},
});
localDB.find({
selector: {
col1: {
$eq: '1',
},
col2: true,
},
fields: ['_id', 'col1', 'col2' ],
limit: 0,
// sort: [‘_id’],
use_index: 'col1-col2-index',
}).then((results) => {
alert(`Index called to increase speed: ${results.docs.length}`);
}).catch((ex) => {
// alert(`Index called to increase speed: Exception: ${JSON.stringify(ex)}`);
});
export function getItems(col1) {
const startTime = new Date();
return (dispatch, getState) => {
return localDB.find({
selector: {
col1: {
$eq: col1,
},
col2: true,
},
fields: ['_id', 'col2', 'col1' ],
// sort: [‘_id’],
use_index: 'col1-col2-index',
}).then((results) => {
const time = new Date().getTime() - startTime;
alert(`Total time ${time}`);
}).catch((ex) => {
console.log(ex);
});
};
}
我在数据库里有大约900条记录。查询大约需要20分钟,这是相当高的。如何提高此查询的性能?请帮助createIndex是异步的。所以我认为当执行查询时,索引还没有建立。所以它会执行完整的数据库扫描。@AlexisCôté,谢谢你的回复。这就是我编写一个find查询以返回0个结果的原因。因此,已经在那里创建了索引。我希望查询至少现在会很快。不是吗?