我不认为类型为DOUBLE的22 * 1000值的更新应该需要约4秒。然而,这就是我得到的。以下是查询完成22次。也许这实际上是相提并论?那时它并不能满足我的速度要求。
UPDATE [some table] SET [some column] = (CASE WHEN [column1] = i THEN [some number]
通过i = 1:1:1000连接,以END);
此声明需要约4/22秒。
我试过的补救措施: 更新前锁定表,然后解锁。
帮助(尚未尝试)的想法: 将更新减少为更小的更新查询。
其他信息: 引擎:InnoDB, C ++连接器
编辑1
代码摘录:
Query ="LOCK TABLES CANS_SQL.SortingIndices WRITE;";
stmt = con->createStatement();
bool LOCKBIT = stmt->execute(Query);
delete stmt;
Query.clear();
Query = "UPDATE SortingIndices SET " + Objects.at(Typ).GetMetricNames().at(ObjMetIndex) + "_KVector = ( CASE ";
for (int k = 0; k<kvector.size()-1; k++)
{
while(true)
{
if(InsertCount<KvectorInsertPos.size())
{
if (KvectorInsertPos.at(InsertCount)==k)
{
Query += "WHEN Sort_ID = " + std::to_string(k+1+InsertCount) + " THEN " + std::to_string(KvectorInsertVal.at(InsertCount)+InsertCount) + " ";
InsertCount++;
}
else
break;
}
else
break;
}
Query += "WHEN Sort_ID = " + std::to_string(k+1+InsertCount) + " THEN " + std::to_string(kvector.at(k)+InsertCount) + " ";
}
while(true)
{
if(InsertCount<KvectorInsertPos.size())
{
if (KvectorInsertPos.at(InsertCount)==kvector.size()-1)
{
Query += "WHEN Sort_ID = " + std::to_string(kvector.size()+InsertCount) + " THEN " + std::to_string(KvectorInsertVal.at(InsertCount)+InsertCount) + " ";
InsertCount++;
}
else
break;
}
else
break;
}
Query += "WHEN Sort_ID = " + std::to_string(kvector.size()+InsertCount) + " THEN " + std::to_string(kvector.at(kvector.size()-1)+InsertCount) + " END ) ";
stmt = con->createStatement();
stmt->executeUpdate(Query);
delete stmt;
编辑2
示例查询:
Query = "UPDATE SortingIndices
SET X_Centroid_Sort_Index = (CASE
WHEN Sort_ID = 1 THEN 1.4324
WHEN Sort_ID = 2 THEN 4.234
WHEN Sort_ID = 3 THEN 324
...
WHEN Sort_ID = 1000 THEN 232.4 END);