与mssql
相比,在mysql
上使用upsert和复合键同步链接表时,性能会下降。
在mysql
上运行此命令时,同步14000条记录大约需要0.7分钟,而使用mssql
到Azure数据库的同步则需要21分钟。
这是我的架构:
students_groups: this.sequelize.define(
'students_groups',
students_groups: {
student: Sequelize.STRING(24),
group: Sequelize.STRING(24),
active: Sequelize.BOOLEAN,
},
{
timestamps: true,
createdAt: 'created_at',
updatedAt: 'updated_at',
indexes: [
{
fields: ['student'],
},
{
fields: ['group'],
},
{
fields: ['student', 'group'],
unique: true
}
],
}
)
这是循环
await this.SQLSchemas['students_groups'].sync().then(async () => {
for(let record of records) {
const where: any = {};
where['student'] = '123456789123';
where['group'] = '234567891234';
await this.SQLSchemas['students_groups'].upsert(
record,
{
where: where
}
);
}
});
示例记录:
{
student: '123456789123',
group: '234567891234',
active: 1
}