MCPcopy Create free account
hub / github.com/LadybugDB/ladybug / executeNoLock

Method executeNoLock

src/main/client_context.cpp:555–612  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

553}
554
555std::unique_ptr<QueryResult> ClientContext::executeNoLock(PreparedStatement* preparedStatement,
556 CachedPreparedStatement* cachedStatement, std::optional<uint64_t> queryID,
557 QueryConfig queryConfig) {
558 if (!preparedStatement->isSuccess()) {
559 return QueryResult::getQueryResultWithError(preparedStatement->errMsg);
560 }
561 useInternalCatalogEntry_ = cachedStatement->useInternalCatalogEntry;
562 this->resetActiveQuery();
563 this->startTimer();
564 auto executingTimer = TimeMetric(true /* enable */);
565 executingTimer.start();
566 std::unique_ptr<QueryResult> result;
567 try {
568 bool isTransactionStatement =
569 preparedStatement->getStatementType() == StatementType::TRANSACTION;
570 TransactionHelper::runFuncInTransaction(
571 *transactionContext,
572 [&]() -> void {
573 const auto profiler = std::make_unique<Profiler>();
574 profiler->enabled = cachedStatement->logicalPlan->isProfile();
575 if (!queryID) {
576 queryID = localDatabase->getNextQueryID();
577 }
578 setActiveQueryID(queryID.value());
579 const auto executionContext =
580 std::make_unique<ExecutionContext>(profiler.get(), this, *queryID);
581 auto mapper = PlanMapper(executionContext.get());
582 const auto physicalPlan = mapper.getPhysicalPlan(cachedStatement->logicalPlan.get(),
583 cachedStatement->columns, queryConfig.resultType, queryConfig.arrowConfig);
584 if (isTransactionStatement) {
585 result = localDatabase->queryProcessor->execute(physicalPlan.get(),
586 executionContext.get());
587 } else {
588 if (preparedStatement->getStatementType() == StatementType::COPY_FROM) {
589 // Note: We always force checkpoint for COPY_FROM statement.
590 Transaction::Get(*this)->setForceCheckpoint();
591 }
592 result = localDatabase->queryProcessor->execute(physicalPlan.get(),
593 executionContext.get());
594 }
595 },
596 preparedStatement->isReadOnly(), isTransactionStatement,
597 TransactionHelper::getAction(true /*shouldCommitNewTransaction*/,
598 !isTransactionStatement /*shouldCommitAutoTransaction*/));
599 } catch (std::exception& e) {
600 useInternalCatalogEntry_ = false;
601 return handleFailedExecution(queryID, e);
602 }
603 const auto memoryManager = storage::MemoryManager::Get(*this);
604 memoryManager->getBufferManager()->getSpillerOrSkip([](auto& spiller) { spiller.clearFile(); });
605 executingTimer.stop();
606 result->setColumnNames(cachedStatement->getColumnNames());
607 result->setColumnTypes(cachedStatement->getColumnTypes());
608 auto summary = std::make_unique<QuerySummary>(preparedStatement->preparedSummary);
609 summary->setExecutionTime(executingTimer.getElapsedTimeMS());
610 result->setQuerySummary(std::move(summary));
611 return result;
612}

Callers

nothing calls this directly

Calls 15

startTimerMethod · 0.95
setActiveQueryIDFunction · 0.85
isProfileMethod · 0.80
getNextQueryIDMethod · 0.80
getSpillerOrSkipMethod · 0.80
getBufferManagerMethod · 0.80
clearFileMethod · 0.80
setColumnNamesMethod · 0.80
setColumnTypesMethod · 0.80
setExecutionTimeMethod · 0.80
getElapsedTimeMSMethod · 0.80
setQuerySummaryMethod · 0.80

Tested by

no test coverage detected