| 407 | } |
| 408 | |
| 409 | std::unique_ptr<QueryResult> ClientContext::queryNoLock(std::string_view query, |
| 410 | std::optional<uint64_t> queryID, QueryConfig config) { |
| 411 | auto parsedStatements = std::vector<std::shared_ptr<Statement>>(); |
| 412 | try { |
| 413 | parsedStatements = parseQuery(query); |
| 414 | } catch (std::exception& exception) { |
| 415 | return QueryResult::getQueryResultWithError(exception.what()); |
| 416 | } |
| 417 | std::unique_ptr<QueryResult> queryResult; |
| 418 | QueryResult* lastResult = nullptr; |
| 419 | double internalCompilingTime = 0.0, internalExecutionTime = 0.0; |
| 420 | for (const auto& statement : parsedStatements) { |
| 421 | auto [preparedStatement, cachedStatement] = |
| 422 | prepareNoLock(statement, false /*shouldCommitNewTransaction*/); |
| 423 | auto currentQueryResult = |
| 424 | executeNoLock(preparedStatement.get(), cachedStatement.get(), queryID, config); |
| 425 | if (!currentQueryResult->isSuccess()) { |
| 426 | if (!lastResult) { |
| 427 | queryResult = std::move(currentQueryResult); |
| 428 | } else { |
| 429 | queryResult->addNextResult(std::move(currentQueryResult)); |
| 430 | } |
| 431 | break; |
| 432 | } |
| 433 | auto currentQuerySummary = currentQueryResult->getQuerySummary(); |
| 434 | if (statement->isInternal()) { |
| 435 | // The result of internal statements should be invisible to end users. Skip chaining the |
| 436 | // result of internal statements to the final result to end users. |
| 437 | internalCompilingTime += currentQuerySummary->getCompilingTime(); |
| 438 | internalExecutionTime += currentQuerySummary->getExecutionTime(); |
| 439 | continue; |
| 440 | } |
| 441 | currentQuerySummary->incrementCompilingTime(internalCompilingTime); |
| 442 | currentQuerySummary->incrementExecutionTime(internalExecutionTime); |
| 443 | if (!lastResult) { |
| 444 | // first result of the query |
| 445 | queryResult = std::move(currentQueryResult); |
| 446 | lastResult = queryResult.get(); |
| 447 | } else { |
| 448 | auto current = currentQueryResult.get(); |
| 449 | lastResult->addNextResult(std::move(currentQueryResult)); |
| 450 | lastResult = current; |
| 451 | } |
| 452 | } |
| 453 | useInternalCatalogEntry_ = false; |
| 454 | return queryResult; |
| 455 | } |
| 456 | |
| 457 | std::vector<std::shared_ptr<Statement>> ClientContext::parseQuery(std::string_view query) { |
| 458 | if (query.empty()) { |
no test coverage detected