@@ -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
@@ -672,6 +675,8 @@ class TKqpCompileService : public TActorBootstrapped<TKqpCompileService> {
672
675
Y_ENSURE (query.UserSid == userSid);
673
676
}
674
677
678
+ LOG_DEBUG_S (ctx, NKikimrServices::KQP_COMPILE_SERVICE, " Try to find query by queryId, queryId: " << query.SerializeToString ());
679
+
675
680
auto compileResult = QueryCache.FindByQuery (query, request.KeepInCache );
676
681
if (HasTempTablesNameClashes (compileResult, request.TempTablesState )) {
677
682
compileResult = nullptr ;
@@ -853,7 +858,7 @@ class TKqpCompileService : public TActorBootstrapped<TKqpCompileService> {
853
858
try {
854
859
if (compileResult->Status == Ydb::StatusIds::SUCCESS) {
855
860
if (!hasTempTablesNameClashes) {
856
- UpdateQueryCache (compileResult, keepInCache, compileRequest.CompileSettings .IsQueryActionPrepare , isPerStatementExecution);
861
+ UpdateQueryCache (ctx, compileResult, keepInCache, compileRequest.CompileSettings .IsQueryActionPrepare , isPerStatementExecution);
857
862
}
858
863
859
864
if (ev->Get ()->ReplayMessage && !QueryReplayBackend->IsNull ()) {
@@ -935,15 +940,21 @@ class TKqpCompileService : public TActorBootstrapped<TKqpCompileService> {
935
940
return compileResult->PreparedQuery ->HasTempTables (tempTablesState, withSessionId);
936
941
}
937
942
938
- void UpdateQueryCache (TKqpCompileResult::TConstPtr compileResult, bool keepInCache, bool isQueryActionPrepare, bool isPerStatementExecution) {
943
+ void UpdateQueryCache (const TActorContext& ctx, TKqpCompileResult::TConstPtr compileResult, bool keepInCache, bool isQueryActionPrepare, bool isPerStatementExecution) {
939
944
if (QueryCache.FindByUid (compileResult->Uid , false )) {
940
945
QueryCache.Replace (compileResult);
941
946
} else if (keepInCache) {
947
+ if (compileResult->Query ) {
948
+ LOG_DEBUG_S (ctx, NKikimrServices::KQP_COMPILE_SERVICE, " Insert query into compile cache, queryId: " << compileResult->Query ->SerializeToString ());
949
+ if (QueryCache.FindByQuery (*compileResult->Query , keepInCache)) {
950
+ LOG_ERROR_S (ctx, NKikimrServices::KQP_COMPILE_SERVICE, " Trying to insert query into compile cache when it is already there" );
951
+ }
952
+ }
942
953
if (QueryCache.Insert (compileResult, TableServiceConfig.GetEnableAstCache (), isPerStatementExecution)) {
943
954
Counters->CompileQueryCacheEvicted ->Inc ();
944
955
}
945
956
if (compileResult->Query && isQueryActionPrepare) {
946
- if (InsertPreparingQuery (compileResult, true , isPerStatementExecution)) {
957
+ if (InsertPreparingQuery (ctx, compileResult, true , isPerStatementExecution)) {
947
958
Counters->CompileQueryCacheEvicted ->Inc ();
948
959
};
949
960
}
@@ -954,6 +965,8 @@ class TKqpCompileService : public TActorBootstrapped<TKqpCompileService> {
954
965
YQL_ENSURE (queryAst.Ast );
955
966
YQL_ENSURE (queryAst.Ast ->IsOk ());
956
967
YQL_ENSURE (queryAst.Ast ->Root );
968
+ LOG_DEBUG_S (ctx, NKikimrServices::KQP_COMPILE_SERVICE, " Try to find query by ast, queryId: " << compileRequest.Query .SerializeToString ()
969
+ << " , ast: " << queryAst.Ast ->Root ->ToString ());
957
970
auto compileResult = QueryCache.FindByAst (compileRequest.Query , *queryAst.Ast , compileRequest.CompileSettings .KeepInCache );
958
971
959
972
if (HasTempTablesNameClashes (compileResult, compileRequest.TempTablesState )) {
@@ -1022,7 +1035,7 @@ class TKqpCompileService : public TActorBootstrapped<TKqpCompileService> {
1022
1035
}
1023
1036
1024
1037
private:
1025
- bool InsertPreparingQuery (const TKqpCompileResult::TConstPtr& compileResult, bool keepInCache, bool isPerStatementExecution) {
1038
+ bool InsertPreparingQuery (const TActorContext& ctx, const TKqpCompileResult::TConstPtr& compileResult, bool keepInCache, bool isPerStatementExecution) {
1026
1039
YQL_ENSURE (compileResult->Query );
1027
1040
auto query = *compileResult->Query ;
1028
1041
@@ -1047,6 +1060,7 @@ class TKqpCompileService : public TActorBootstrapped<TKqpCompileService> {
1047
1060
auto newCompileResult = TKqpCompileResult::Make (CreateGuidAsString (), compileResult->Status , compileResult->Issues , compileResult->MaxReadType , std::move (query), compileResult->Ast );
1048
1061
newCompileResult->AllowCache = compileResult->AllowCache ;
1049
1062
newCompileResult->PreparedQuery = compileResult->PreparedQuery ;
1063
+ LOG_DEBUG_S (ctx, NKikimrServices::KQP_COMPILE_SERVICE, " Insert preparing query with params, queryId: " << query.SerializeToString ());
1050
1064
return QueryCache.Insert (newCompileResult, TableServiceConfig.GetEnableAstCache (), isPerStatementExecution);
1051
1065
}
1052
1066
0 commit comments