@@ -50,16 +50,16 @@ class TKqpQueryCache {
5050
5151 void InsertAst (const TKqpCompileResult::TConstPtr& compileResult) {
5252 Y_ENSURE (compileResult->Query );
53- Y_ENSURE (compileResult->Ast );
53+ Y_ENSURE (compileResult->GetAst () );
5454
55- AstIndex.emplace (GetQueryIdWithAst (*compileResult->Query , *compileResult->Ast ), compileResult->Uid );
55+ AstIndex.emplace (GetQueryIdWithAst (*compileResult->Query , *compileResult->GetAst () ), compileResult->Uid );
5656 }
5757
5858 bool Insert (const TKqpCompileResult::TConstPtr& compileResult, bool isEnableAstCache, bool isPerStatementExecution) {
5959 if (!isPerStatementExecution) {
6060 InsertQuery (compileResult);
6161 }
62- if (isEnableAstCache && compileResult->Ast ) {
62+ if (isEnableAstCache && compileResult->GetAst () ) {
6363 InsertAst (compileResult);
6464 }
6565
@@ -76,8 +76,8 @@ class TKqpQueryCache {
7676
7777 auto queryId = *removedItem->Value .CompileResult ->Query ;
7878 QueryIndex.erase (queryId);
79- if (removedItem->Value .CompileResult ->Ast ) {
80- AstIndex.erase (GetQueryIdWithAst (queryId, *removedItem->Value .CompileResult ->Ast ));
79+ if (removedItem->Value .CompileResult ->GetAst () ) {
80+ AstIndex.erase (GetQueryIdWithAst (queryId, *removedItem->Value .CompileResult ->GetAst () ));
8181 }
8282 auto indexIt = Index.find (*removedItem);
8383 if (indexIt != Index.end ()) {
@@ -190,8 +190,8 @@ class TKqpQueryCache {
190190 Y_ABORT_UNLESS (item->Value .CompileResult ->Query );
191191 auto queryId = *item->Value .CompileResult ->Query ;
192192 QueryIndex.erase (queryId);
193- if (item->Value .CompileResult ->Ast ) {
194- AstIndex.erase (GetQueryIdWithAst (queryId, *item->Value .CompileResult ->Ast ));
193+ if (item->Value .CompileResult ->GetAst () ) {
194+ AstIndex.erase (GetQueryIdWithAst (queryId, *item->Value .CompileResult ->GetAst () ));
195195 }
196196
197197 Index.erase (it);
@@ -327,6 +327,8 @@ struct TKqpCompileRequest {
327327 NYql::TExprContext* SplitCtx;
328328 NYql::TExprNode::TPtr SplitExpr;
329329
330+ bool FindInCache = true ;
331+
330332 bool IsIntrestedInResult () const {
331333 return IntrestedInResult->load ();
332334 }
@@ -764,8 +766,6 @@ class TKqpCompileService : public TActorBootstrapped<TKqpCompileService> {
764766 }
765767
766768 if (compileResult || request.Query ) {
767- QueryCache.EraseByUid (request.Uid );
768-
769769 Counters->ReportCompileRequestCompile (dbCounters);
770770
771771 NWilson::TSpan compileServiceSpan (TWilsonKqp::CompileService, ev->Get () ? std::move (ev->TraceId ) : NWilson::TTraceId (), " CompileService" );
@@ -790,12 +790,13 @@ class TKqpCompileService : public TActorBootstrapped<TKqpCompileService> {
790790 );
791791 }
792792 }
793- TKqpCompileRequest compileRequest (ev->Sender , request.Uid , query ,
793+ TKqpCompileRequest compileRequest (ev->Sender , request.Uid , compileResult ? *compileResult-> Query : *request. Query ,
794794 compileSettings, request.UserToken , dbCounters, request.GUCSettings , request.ApplicationName ,
795795 ev->Cookie , std::move (ev->Get ()->IntrestedInResult ),
796796 ev->Get ()->UserRequestContext ,
797797 ev->Get () ? std::move (ev->Get ()->Orbit ) : NLWTrace::TOrbit (),
798798 std::move (compileServiceSpan), std::move (ev->Get ()->TempTablesState ));
799+ compileRequest.FindInCache = false ;
799800
800801 if (TableServiceConfig.GetEnableAstCache () && request.QueryAst ) {
801802 return CompileByAst (*request.QueryAst , compileRequest, ctx);
@@ -976,7 +977,7 @@ class TKqpCompileService : public TActorBootstrapped<TKqpCompileService> {
976977 << " , ast: " << queryAst.Ast ->Root ->ToString ());
977978 auto compileResult = QueryCache.FindByAst (compileRequest.Query , *queryAst.Ast , compileRequest.CompileSettings .KeepInCache );
978979
979- if (HasTempTablesNameClashes (compileResult, compileRequest.TempTablesState )) {
980+ if (!compileRequest. FindInCache || HasTempTablesNameClashes (compileResult, compileRequest.TempTablesState )) {
980981 compileResult = nullptr ;
981982 }
982983
@@ -987,7 +988,7 @@ class TKqpCompileService : public TActorBootstrapped<TKqpCompileService> {
987988 << " , sender: " << compileRequest.Sender
988989 << " , queryUid: " << compileResult->Uid );
989990
990- compileResult->Ast ->PgAutoParamValues = std::move (queryAst.Ast ->PgAutoParamValues );
991+ compileResult->GetAst () ->PgAutoParamValues = std::move (queryAst.Ast ->PgAutoParamValues );
991992
992993 ReplyFromCache (compileRequest.Sender , compileResult, ctx, compileRequest.Cookie , std::move (compileRequest.Orbit ), std::move (compileRequest.CompileServiceSpan ));
993994 return ;
@@ -1061,10 +1062,10 @@ class TKqpCompileService : public TActorBootstrapped<TKqpCompileService> {
10611062 if (QueryCache.FindByQuery (query, keepInCache)) {
10621063 return false ;
10631064 }
1064- if (compileResult->Ast && QueryCache.FindByAst (query, *compileResult->Ast , keepInCache)) {
1065+ if (compileResult->GetAst () && QueryCache.FindByAst (query, *compileResult->GetAst () , keepInCache)) {
10651066 return false ;
10661067 }
1067- auto newCompileResult = TKqpCompileResult::Make (CreateGuidAsString (), compileResult->Status , compileResult->Issues , compileResult->MaxReadType , std::move (query), compileResult->Ast );
1068+ auto newCompileResult = TKqpCompileResult::Make (CreateGuidAsString (), compileResult->Status , compileResult->Issues , compileResult->MaxReadType , std::move (query), compileResult->QueryAst );
10681069 newCompileResult->AllowCache = compileResult->AllowCache ;
10691070 newCompileResult->PreparedQuery = compileResult->PreparedQuery ;
10701071 LOG_DEBUG_S (ctx, NKikimrServices::KQP_COMPILE_SERVICE, " Insert preparing query with params, queryId: " << query.SerializeToString ());
0 commit comments