Skip to content

Commit 32ab7bf

Browse files
committed
delete query from compile cache if it is existed during insert
1 parent ea7bd23 commit 32ab7bf

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

ydb/core/kqp/compile_service/kqp_compile_service.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ class TKqpQueryCache {
4141
YQL_ENSURE(compileResult->PreparedQuery);
4242

4343
auto queryIt = QueryIndex.emplace(query, compileResult->Uid);
44+
if (!queryIt.second) {
45+
EraseByUid(compileResult->Uid);
46+
}
4447
Y_ENSURE(queryIt.second);
4548
}
4649

@@ -939,15 +942,18 @@ class TKqpCompileService : public TActorBootstrapped<TKqpCompileService> {
939942
return compileResult->PreparedQuery->HasTempTables(tempTablesState, withSessionId);
940943
}
941944

942-
void UpdateQueryCache(TKqpCompileResult::TConstPtr compileResult, bool keepInCache, bool isQueryActionPrepare, bool isPerStatementExecution) {
945+
void UpdateQueryCache(const TActorContext& ctx, TKqpCompileResult::TConstPtr compileResult, bool keepInCache, bool isQueryActionPrepare, bool isPerStatementExecution) {
943946
if (QueryCache.FindByUid(compileResult->Uid, false)) {
944947
QueryCache.Replace(compileResult);
945948
} else if (keepInCache) {
949+
if (QueryCache.FindByQuery(query, keepInCache)) {
950+
LOG_ERROR_S(ctx, NKikimrServices::KQP_COMPILE_SERVICE, "Trying to insert query into compile cache when it is already there");
951+
}
946952
if (QueryCache.Insert(compileResult, TableServiceConfig.GetEnableAstCache(), isPerStatementExecution)) {
947953
Counters->CompileQueryCacheEvicted->Inc();
948954
}
949955
if (compileResult->Query && isQueryActionPrepare) {
950-
if (InsertPreparingQuery(compileResult, true, isPerStatementExecution)) {
956+
if (InsertPreparingQuery(ctx, compileResult, true, isPerStatementExecution)) {
951957
Counters->CompileQueryCacheEvicted->Inc();
952958
};
953959
}
@@ -1026,7 +1032,7 @@ class TKqpCompileService : public TActorBootstrapped<TKqpCompileService> {
10261032
}
10271033

10281034
private:
1029-
bool InsertPreparingQuery(const TKqpCompileResult::TConstPtr& compileResult, bool keepInCache, bool isPerStatementExecution) {
1035+
bool InsertPreparingQuery(const TActorContext& ctx, const TKqpCompileResult::TConstPtr& compileResult, bool keepInCache, bool isPerStatementExecution) {
10301036
YQL_ENSURE(compileResult->Query);
10311037
auto query = *compileResult->Query;
10321038

@@ -1048,6 +1054,7 @@ class TKqpCompileService : public TActorBootstrapped<TKqpCompileService> {
10481054
if (compileResult->Ast && QueryCache.FindByAst(query, *compileResult->Ast, keepInCache)) {
10491055
return false;
10501056
}
1057+
LOG_DEBUG_S(ctx, NKikimrServices::KQP_COMPILE_SERVICE, "Insert preparing query with params");
10511058
auto newCompileResult = TKqpCompileResult::Make(CreateGuidAsString(), compileResult->Status, compileResult->Issues, compileResult->MaxReadType, std::move(query), compileResult->Ast);
10521059
newCompileResult->AllowCache = compileResult->AllowCache;
10531060
newCompileResult->PreparedQuery = compileResult->PreparedQuery;

0 commit comments

Comments
 (0)