- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我在 Sequelize 中有以下查询
Providers.findAll({
attributes: [
"provider_id"
],
include: [{
model: ProvidersInsurance,
attributes: ["insurance_id"],
include: [{
model: Insurance,
attributes: ["insurance_id", "insurance_name"]
}, ]
},
{
model: ProvidersClients,
attributes: ["client_id"],
include: [{
model: Clients,
attributes: ["client_id", "client_name"]
}, ]
},
{
model: ProvidersCounties,
attributes: ["county_id"],
include: [{
model: Counties,
attributes: ["county_id", "county_name"]
}, ]
},
{
model: ProvidersSpecialities,
attributes: ["speciality_id"],
include: [{
model: Specialities,
attributes: ["speciality_id", "speciality_name"]
}, ]
},
{
model: ProvidersCategories,
attributes: ["category_id"],
include: [{
model: Categories,
attributes: ["category_id", "category_name"]
}, ]
}, {
model: Telehealth,
attributes: ["telehealth_name"]
}
],
where: {
updatedAt: {
[Op.between]: [req.query.fromdate, toDate]
}
}
}).then(providerData => {
console.log(providerData)
}).catch(err => {
console.log(err);
res.status(404).send({
reason: err.message
})
});
执行时间超过 4 分钟。上面的原始查询是
SELECT `providers`.`provider_id`,
`providers`.`providerFirstName`,
`providers`.`providerLastName`,
`providers`.`email`,
`providers`.`phoneNumber`,
`providers`.`address`,
`providers`.`agencyName`,
`providers`.`practiceCounty`,
`providers`.`city`,
`providers`.`state`,
`providers`.`zip`,
`providers`.`mondayHours`,
`providers`.`tuesdayHours`,
`providers`.`wednesdayHours`,
`providers`.`thursdayHours`,
`providers`.`fridayHours`,
`providers`.`saturdayHours`,
`providers`.`sundayHours`,
`providers`.`additionalInfo`,
`providers`.`website`,
`providers`.`newClientsAcceptance`,
`providers`.`updatedBy`,
`providers`.`otherCategories`,
`providers`.`otherInsurances`,
`providers`.`otherTelehealthServices`,
`providers`.`createdAt`,
`providers`.`updatedAt`,
`ProviderInsurances`.`provider_insurance_id` AS `ProviderInsurances.provider_insurance_id`,
`ProviderInsurances`.`insurance_id` AS `ProviderInsurances.insurance_id`,
`ProviderInsurances->Insurance`.`insurance_id` AS `ProviderInsurances.Insurance.insurance_id`,
`ProviderInsurances->Insurance`.`insurance_name` AS `ProviderInsurances.Insurance.insurance_name`,
`ProviderClients`.`provider_client_id` AS `ProviderClients.provider_client_id`,
`ProviderClients`.`client_id` AS `ProviderClients.client_id`,
`ProviderClients->Client`.`client_id` AS `ProviderClients.Client.client_id`,
`ProviderClients->Client`.`client_name` AS `ProviderClients.Client.client_name`,
`ProviderCounties`.`provider_county_id` AS `ProviderCounties.provider_county_id`,
`ProviderCounties`.`county_id` AS `ProviderCounties.county_id`,
`ProviderCounties->County`.`county_id` AS `ProviderCounties.County.county_id`,
`ProviderCounties->County`.`county_name` AS `ProviderCounties.County.county_name`,
`ProviderSpecialities`.`provider_speciality_id` AS `ProviderSpecialities.provider_speciality_id`,
`ProviderSpecialities`.`speciality_id` AS `ProviderSpecialities.speciality_id`,
`ProviderSpecialities->Speciality`.`speciality_id` AS `ProviderSpecialities.Speciality.speciality_id`,
`ProviderSpecialities->Speciality`.`speciality_name` AS `ProviderSpecialities.Speciality.speciality_name`,
`ProviderCategories`.`provider_category_id` AS `ProviderCategories.provider_category_id`,
`ProviderCategories`.`category_id` AS `ProviderCategories.category_id`,
`ProviderCategories->Category`.`category_id` AS `ProviderCategories.Category.category_id`,
`ProviderCategories->Category`.`category_name` AS `ProviderCategories.Category.category_name`,
`Telehealths`.`telehealth_id` AS `Telehealths.telehealth_id`,
`Telehealths`.`telehealth_name` AS `Telehealths.telehealth_name`
FROM `providers` AS `providers`
LEFT OUTER JOIN `provider_insurances` AS `ProviderInsurances` ON `providers`.`provider_id` = `ProviderInsurances`.`provider_id`
LEFT OUTER JOIN `insurance` AS `ProviderInsurances->Insurance` ON `ProviderInsurances`.`insurance_id` = `ProviderInsurances->Insurance`.`insurance_id`
LEFT OUTER JOIN `provider_clients` AS `ProviderClients` ON `providers`.`provider_id` = `ProviderClients`.`provider_id`
LEFT OUTER JOIN `clients` AS `ProviderClients->Client` ON `ProviderClients`.`client_id` = `ProviderClients->Client`.`client_id`
LEFT OUTER JOIN `provider_counties` AS `ProviderCounties` ON `providers`.`provider_id` = `ProviderCounties`.`provider_id`
LEFT OUTER JOIN `counties` AS `ProviderCounties->County` ON `ProviderCounties`.`county_id` = `ProviderCounties->County`.`county_id`
LEFT OUTER JOIN `provider_specialities` AS `ProviderSpecialities` ON `providers`.`provider_id` = `ProviderSpecialities`.`provider_id`
LEFT OUTER JOIN `specialities` AS `ProviderSpecialities->Speciality` ON `ProviderSpecialities`.`speciality_id` = `ProviderSpecialities->Speciality`.`speciality_id`
LEFT OUTER JOIN `provider_categories` AS `ProviderCategories` ON `providers`.`provider_id` = `ProviderCategories`.`provider_id`
LEFT OUTER JOIN `categories` AS `ProviderCategories->Category` ON `ProviderCategories`.`category_id` = `ProviderCategories->Category`.`category_id`
LEFT OUTER JOIN `telehealth` AS `Telehealths` ON `providers`.`provider_id` = `Telehealths`.`provider_id`
WHERE `providers`.`updatedAt` BETWEEN '2019-08-06 18:30:00' AND '2019-08-08 00:00:00';
当我在 mysql 服务器中执行上述查询时,它会在不到 1 秒的时间内给出结果。然而,当我通过 Node 执行并 Sequelize 时,它花费了太多时间,即大约 4 分钟
我想知道为什么sequelize查询花费的时间太长
最佳答案
如果您使用 sequlize
最新版本,您可以使用以下选项,这肯定会减少很多时间,因为 raw:true
将停止 sequlize
从结果构建模型实例:
{
raw : true, // sequelize will not try to format the results of the query, or build an instance of a model from the result
nest : true // this will format your data
}
<小时/>
Providers.findAll({
attributes: [
...
],
include: [
....
],
where: {
...
},
raw : true, // <---- HERE
nest : true // <---- HERE
})
.then(providerData => {
console.log(providerData)
}).catch(err => {
console.log(err);
res.status(404).send({
reason: err.message
})
});
关于node.js - 序列化查询花费太长时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57417141/
在我们的服务出现一些预期的增长之后,突然间一些更新花费了非常长的时间,这些过去非常快,直到表达到大约 2MM 记录,现在它们每个需要大约 40-60 秒。 update table1 set fiel
我在服务中实现了一个传感器事件监听器,只要采样周期和最大报告延迟低于 1 秒,该监听器就可以正常工作,但一旦我将采样周期增加到超过 1 秒,传感器就根本不会更新。 我希望采样周期为 10 秒(可能是
我使用 Tkinter GUI 来启动测量和分析过程,基本上只需单击一个按钮即可开始。由于这些测量可能需要一段时间,我尝试添加一个进度条,即这个: http://tkinter.unpythonic.
我正在尝试使用套接字发送数据包,但出现错误。 invalid conversion from ‘omnetpp::cPacket*’ to ‘inet::Packet*’ [-fpermissive]
我刚刚发现 String#split 有以下奇怪的行为: "a\tb c\nd".split => ["a", "b", "c", "d"] "a\tb c\nd".split(' ') => ["a
您好,我正在尝试 ClojureScript,我正在使用 Klipse作为我的 REPL 差不多。这可能不是它的预期用途,但因为我没有做任何太复杂的事情,所以现在没问题。 我遇到的一个问题是尝试设置计
根据下面的数据,ClockKit 会生成一次 future 的 CLKComplicationTimelineEntry 项,但对于过去的时间点,会进行 24 次调用!这是为什么? 更多详情: 我注意
我有一个 MySQL 表,这个表有一个名为 datetime_utc 的 DATETIME 列。如您所料,它是 UTC 日期和时间。在我的 Bookshelf 模型中,我定义了一个虚拟 getter,
大家好,我是二哥呀! 昨天,一位球友问我能不能给他解释一下 @SpringBootApplication 注解是什么意思,还有 Spring Boot 的运行原理,于是我就带着他扒拉了一下这个注解的源
我是一名优秀的程序员,十分优秀!