慢查询
- 发布:2024-09-03 10:50
- 更新:2024-09-09 15:01
- 阅读:162
产品分类: uniCloud/App
操作步骤:
预期结果:
查询在100ms内完成
查询在100ms内完成
实际结果:
慢查询
慢查询
bug描述:
最简单的一个字段的查询都出现问题慢查询,代码如下:
const res = await uniCloud.httpProxyForEip.get('https://api.weixin.qq.com/cgi-bin/token',
{
grant_type: 'client_credential',
appid: wxConfig.config('public-account.appid'),
secret: wxConfig.config('public-account.appsecret')
}
)
await accessTokenTable.where({
name:'access_token'
}).update({
token: res.body.access_token
})
数据库表结构如下:
const res = await uniCloud.httpProxyForEip.get('https://api.weixin.qq.com/cgi-bin/token',
{
grant_type: 'client_credential',
appid: wxConfig.config('public-account.appid'),
secret: wxConfig.config('public-account.appsecret')
}
)
await accessTokenTable.where({
name:'access_token'
}).update({
token: res.body.access_token
})
索引设置如附件:
慢查询如日志如附件:
慢查询语句如下:
{"op":"update","ns":"db_UNIJGBNDLV_mp-b9e5b8a7-8469-4e81-9cf0-0ff9f1ce6d24.access-token","command":{"q":{"name":"access_token"},"u":{"$set":{"token":"84_BWBq4aLQsKaat1SF1PSlCm3S8Hv8_VeovRqEAip35Xldvc9FcqBXHBCf71ZhBEsjYG0Plx6z-FFpgbssRPBu0JpVM4HSlnN5-7Vu6a9QLYUPz5CFB7OXYhILnl4COFeABATFW"}},"multi":true,"upsert":false},"keysExamined":1,"keysExaminedBySizeInBytes":24,"docsExamined":1,"docsExaminedBySizeInBytes":193,"keysWrittenBySizeInBytes":282,"docsWrittenBySizeInBytes":193,"nMatched":1,"nModified":1,"keysInserted":1,"keysDeleted":1,"numYield":1,"queryHash":"01AEE5EC","planCacheKey":"4C5AEA2C","locks":{"ParallelBatchWriterMode":{"acquireCount":{"r":{"$numberLong":"3"}}},"ReplicationStateTransition":{"acquireCount":{"w":{"$numberLong":"3"}}},"Global":{"acquireCount":{"r":{"$numberLong":"1"},"w":{"$numberLong":"2"}}},"Database":{"acquireCount":{"w":{"$numberLong":"2"}}},"Collection":{"acquireCount":{"w":{"$numberLong":"2"}}},"Mutex":{"acquireCount":{"r":{"$numberLong":"2"}}}},"flowControl":{"acquireCount":{"$numberLong":"2"},"timeAcquiringMicros":{"$numberLong":"1"}},"storage":{"data":{"bytesRead":{"$numberLong":"1142"},"timeReadingMicros":{"$numberLong":"17"}},"timeWaitingMicros":{"handleLock":{"$numberLong":"1300"},"schemaLock":{"$numberLong":"7307867"}}},"millis":7312,"planSummary":"IXSCAN { name: 1 }","replRole":{"stateStr":"PRIMARY","_id":3}}
3***@qq.com (作者)
表结构代码复制错误,具体表结构如下:
{
"bsonType": "object",
"required": [
],
"properties": {
"_id": {
"description": "存储文档 ID,系统自动生成"
},
"name": {
"title": "name",
"bsonType": "string",
"description": "用这个来唯一查找",
"trim": "both"
},
"token": {
"title": "access_token",
"bsonType": "string",
"description": "角色唯一标识,不可修改,不允许重复",
"trim": "both"
}
},
"version": "0.0.1"
}