@@ -76,14 +76,14 @@ std::unique_ptr<PreparedStatement> Connection::prepareNoLock(const string& query
76
76
auto compilingTimer = TimeMetric (true /* enable */ );
77
77
compilingTimer.start ();
78
78
unique_ptr<ExecutionContext> executionContext;
79
- unique_ptr<PhysicalPlan> physicalPlan ;
79
+ unique_ptr<LogicalPlan> logicalPlan ;
80
80
try {
81
81
auto statement = Parser::parseQuery (query);
82
82
auto binder = Binder (*database->catalog );
83
83
auto boundStatement = binder.bind (*statement);
84
84
setQuerySummaryAndPreparedStatement (statement.get (), binder, preparedStatement.get ());
85
85
// planning
86
- auto logicalPlan = Planner::getBestPlan (*database->catalog ,
86
+ logicalPlan = Planner::getBestPlan (*database->catalog ,
87
87
database->getStorageManager ()->getNodesStore ().getNodesStatisticsAndDeletedIDs (),
88
88
database->getStorageManager ()->getRelsStore ().getRelsStatistics (), *boundStatement);
89
89
if (logicalPlan->isDDLOrCopyCSV ()) {
@@ -92,17 +92,13 @@ std::unique_ptr<PreparedStatement> Connection::prepareNoLock(const string& query
92
92
} else {
93
93
preparedStatement->createResultHeader (logicalPlan->getExpressionsToCollect ());
94
94
}
95
- // mapping
96
- auto mapper = PlanMapper (
97
- *database->storageManager , database->getMemoryManager (), database->catalog .get ());
98
- physicalPlan = mapper.mapLogicalPlanToPhysical (move (logicalPlan));
99
95
} catch (Exception& exception ) {
100
96
preparedStatement->success = false ;
101
97
preparedStatement->errMsg = exception .what ();
102
98
}
103
99
compilingTimer.stop ();
104
100
preparedStatement->preparedSummary .compilingTime = compilingTimer.getElapsedTimeMS ();
105
- preparedStatement->physicalPlan = move (physicalPlan );
101
+ preparedStatement->logicalPlan = std:: move (logicalPlan );
106
102
return preparedStatement;
107
103
}
108
104
@@ -209,10 +205,7 @@ unique_ptr<QueryResult> Connection::executePlan(unique_ptr<LogicalPlan> logicalP
209
205
lock_t lck{mtx};
210
206
auto preparedStatement = make_unique<PreparedStatement>();
211
207
preparedStatement->createResultHeader (logicalPlan->getExpressionsToCollect ());
212
- auto mapper =
213
- PlanMapper (*database->storageManager , database->getMemoryManager (), database->getCatalog ());
214
- auto physicalPlan = mapper.mapLogicalPlanToPhysical (move (logicalPlan));
215
- preparedStatement->physicalPlan = move (physicalPlan);
208
+ preparedStatement->logicalPlan = std::move (logicalPlan);
216
209
return executeAndAutoCommitIfNecessaryNoLock (preparedStatement.get ());
217
210
}
218
211
@@ -250,6 +243,9 @@ void Connection::bindParametersNoLock(
250
243
251
244
std::unique_ptr<QueryResult> Connection::executeAndAutoCommitIfNecessaryNoLock (
252
245
PreparedStatement* preparedStatement) {
246
+ auto mapper = PlanMapper (
247
+ *database->storageManager , database->getMemoryManager (), database->catalog .get ());
248
+ auto physicalPlan = mapper.mapLogicalPlanToPhysical (preparedStatement->logicalPlan .get ());
253
249
auto queryResult = make_unique<QueryResult>(preparedStatement->preparedSummary );
254
250
auto profiler = make_unique<Profiler>();
255
251
auto executionContext = make_unique<ExecutionContext>(clientContext->numThreadsForExecution ,
@@ -287,8 +283,8 @@ std::unique_ptr<QueryResult> Connection::executeAndAutoCommitIfNecessaryNoLock(
287
283
" transaction or set the transaction mode of the connection to AUTO_COMMIT" );
288
284
}
289
285
executionContext->transaction = activeTransaction.get ();
290
- resultFT = database-> queryProcessor -> execute (
291
- preparedStatement-> physicalPlan .get (), executionContext.get ());
286
+ resultFT =
287
+ database-> queryProcessor -> execute ( physicalPlan.get (), executionContext.get ());
292
288
if (AUTO_COMMIT == transactionMode) {
293
289
commitNoLock ();
294
290
}
@@ -302,8 +298,7 @@ std::unique_ptr<QueryResult> Connection::executeAndAutoCommitIfNecessaryNoLock(
302
298
queryResult->setResultHeaderAndTable (
303
299
preparedStatement->resultHeader ->copy (), move (resultFT));
304
300
}
305
- auto planPrinter =
306
- make_unique<PlanPrinter>(preparedStatement->physicalPlan .get (), move (profiler));
301
+ auto planPrinter = make_unique<PlanPrinter>(physicalPlan.get (), move (profiler));
307
302
queryResult->querySummary ->planInJson = planPrinter->printPlanToJson ();
308
303
queryResult->querySummary ->planInOstream = planPrinter->printPlanToOstream ();
309
304
return queryResult;
0 commit comments