@@ -41,6 +41,9 @@ class TKqpQueryCache {
41
41
YQL_ENSURE (compileResult->PreparedQuery );
42
42
43
43
auto queryIt = QueryIndex.emplace (query, compileResult->Uid );
44
+ if (!queryIt.second ) {
45
+ EraseByUid (compileResult->Uid );
46
+ }
44
47
Y_ENSURE (queryIt.second );
45
48
}
46
49
@@ -676,6 +679,7 @@ class TKqpCompileService : public TActorBootstrapped<TKqpCompileService> {
676
679
Y_ENSURE (query.UserSid == userSid);
677
680
}
678
681
682
+ LOG_DEBUG_S (ctx, NKikimrServices::KQP_COMPILE_SERVICE, " Try to find query by queryId, queryId: " << query.SerializeToString ());
679
683
auto compileResult = QueryCache.FindByQuery (query, request.KeepInCache );
680
684
if (HasTempTablesNameClashes (compileResult, request.TempTablesState )) {
681
685
compileResult = nullptr ;
@@ -857,7 +861,7 @@ class TKqpCompileService : public TActorBootstrapped<TKqpCompileService> {
857
861
try {
858
862
if (compileResult->Status == Ydb::StatusIds::SUCCESS) {
859
863
if (!hasTempTablesNameClashes) {
860
- UpdateQueryCache (compileResult, keepInCache, compileRequest.CompileSettings .IsQueryActionPrepare , isPerStatementExecution);
864
+ UpdateQueryCache (ctx, compileResult, keepInCache, compileRequest.CompileSettings .IsQueryActionPrepare , isPerStatementExecution);
861
865
}
862
866
863
867
if (ev->Get ()->ReplayMessage && !QueryReplayBackend->IsNull ()) {
@@ -939,15 +943,21 @@ class TKqpCompileService : public TActorBootstrapped<TKqpCompileService> {
939
943
return compileResult->PreparedQuery ->HasTempTables (tempTablesState, withSessionId);
940
944
}
941
945
942
- void UpdateQueryCache (TKqpCompileResult::TConstPtr compileResult, bool keepInCache, bool isQueryActionPrepare, bool isPerStatementExecution) {
946
+ void UpdateQueryCache (const TActorContext& ctx, TKqpCompileResult::TConstPtr compileResult, bool keepInCache, bool isQueryActionPrepare, bool isPerStatementExecution) {
943
947
if (QueryCache.FindByUid (compileResult->Uid , false )) {
944
948
QueryCache.Replace (compileResult);
945
949
} else if (keepInCache) {
950
+ if (compileResult->Query ) {
951
+ LOG_DEBUG_S (ctx, NKikimrServices::KQP_COMPILE_SERVICE, " Insert query into compile cache, queryId: " << compileResult->Query ->SerializeToString ());
952
+ if (QueryCache.FindByQuery (*compileResult->Query , keepInCache)) {
953
+ LOG_ERROR_S (ctx, NKikimrServices::KQP_COMPILE_SERVICE, " Trying to insert query into compile cache when it is already there" );
954
+ }
955
+ }
946
956
if (QueryCache.Insert (compileResult, TableServiceConfig.GetEnableAstCache (), isPerStatementExecution)) {
947
957
Counters->CompileQueryCacheEvicted ->Inc ();
948
958
}
949
959
if (compileResult->Query && isQueryActionPrepare) {
950
- if (InsertPreparingQuery (compileResult, true , isPerStatementExecution)) {
960
+ if (InsertPreparingQuery (ctx, compileResult, true , isPerStatementExecution)) {
951
961
Counters->CompileQueryCacheEvicted ->Inc ();
952
962
};
953
963
}
@@ -958,6 +968,8 @@ class TKqpCompileService : public TActorBootstrapped<TKqpCompileService> {
958
968
YQL_ENSURE (queryAst.Ast );
959
969
YQL_ENSURE (queryAst.Ast ->IsOk ());
960
970
YQL_ENSURE (queryAst.Ast ->Root );
971
+ LOG_DEBUG_S (ctx, NKikimrServices::KQP_COMPILE_SERVICE, " Try to find query by ast, queryId: " << compileRequest.Query .SerializeToString ()
972
+ << " , ast: " << queryAst.Ast ->Root ->ToString ());
961
973
auto compileResult = QueryCache.FindByAst (compileRequest.Query , *queryAst.Ast , compileRequest.CompileSettings .KeepInCache );
962
974
963
975
if (HasTempTablesNameClashes (compileResult, compileRequest.TempTablesState )) {
@@ -1026,7 +1038,7 @@ class TKqpCompileService : public TActorBootstrapped<TKqpCompileService> {
1026
1038
}
1027
1039
1028
1040
private:
1029
- bool InsertPreparingQuery (const TKqpCompileResult::TConstPtr& compileResult, bool keepInCache, bool isPerStatementExecution) {
1041
+ bool InsertPreparingQuery (const TActorContext& ctx, const TKqpCompileResult::TConstPtr& compileResult, bool keepInCache, bool isPerStatementExecution) {
1030
1042
YQL_ENSURE (compileResult->Query );
1031
1043
auto query = *compileResult->Query ;
1032
1044
@@ -1051,6 +1063,7 @@ class TKqpCompileService : public TActorBootstrapped<TKqpCompileService> {
1051
1063
auto newCompileResult = TKqpCompileResult::Make (CreateGuidAsString (), compileResult->Status , compileResult->Issues , compileResult->MaxReadType , std::move (query), compileResult->Ast );
1052
1064
newCompileResult->AllowCache = compileResult->AllowCache ;
1053
1065
newCompileResult->PreparedQuery = compileResult->PreparedQuery ;
1066
+ LOG_DEBUG_S (ctx, NKikimrServices::KQP_COMPILE_SERVICE, " Insert preparing query with params, queryId: " << query.SerializeToString ());
1054
1067
return QueryCache.Insert (newCompileResult, TableServiceConfig.GetEnableAstCache (), isPerStatementExecution);
1055
1068
}
1056
1069
0 commit comments