| 795 | } |
| 796 | |
| 797 | static std::tuple<ASTPtr, BlockIO> executeQueryImpl( |
| 798 | const char * begin, |
| 799 | const char * end, |
| 800 | ASTPtr input_ast, |
| 801 | ContextMutablePtr context, |
| 802 | bool internal, |
| 803 | QueryProcessingStage::Enum stage, |
| 804 | bool has_query_tail, |
| 805 | ReadBuffer * istr) |
| 806 | { |
| 807 | const auto current_time = std::chrono::system_clock::now(); |
| 808 | context->setQueryContext(context); |
| 809 | |
| 810 | auto & client_info = context->getClientInfo(); |
| 811 | |
| 812 | // If it's not an internal query and we don't see an initial_query_start_time yet, initialize it |
| 813 | // to current time. Internal queries are those executed without an independent client context, |
| 814 | // thus should not set initial_query_start_time, because it might introduce data race. It's also |
| 815 | // possible to have unset initial_query_start_time for non-internal and non-initial queries. For |
| 816 | // example, the query is from an initiator that is running an old version of clickhouse. |
| 817 | if (!internal && client_info.initial_query_start_time == 0) |
| 818 | { |
| 819 | client_info.initial_query_start_time = time_in_seconds(current_time); |
| 820 | client_info.initial_query_start_time_microseconds = time_in_microseconds(current_time); |
| 821 | } |
| 822 | |
| 823 | #if !defined(ARCADIA_BUILD) |
| 824 | assert(internal || CurrentThread::get().getQueryContext()); |
| 825 | assert(internal || CurrentThread::get().getQueryContext()->getCurrentQueryId() == CurrentThread::getQueryId()); |
| 826 | #endif |
| 827 | |
| 828 | const Settings & settings = context->getSettingsRef(); |
| 829 | |
| 830 | /// FIXME: Use global join for cnch join works for sql mode first. |
| 831 | /// Will be replaced by distributed query after @youzhiyuan add query plan runtime. |
| 832 | if (context->getServerType() == ServerType::cnch_server) |
| 833 | { |
| 834 | context->setSetting("distributed_product_mode", String{"global"}); |
| 835 | } |
| 836 | |
| 837 | ASTPtr ast; |
| 838 | const char * query_end; |
| 839 | |
| 840 | /// Don't limit the size of internal queries. |
| 841 | size_t max_query_size = 0; |
| 842 | if (!internal) |
| 843 | max_query_size = settings.max_query_size; |
| 844 | |
| 845 | auto finish_current_transaction = [ast](const ContextPtr & query_context) { |
| 846 | if (auto cur_txn = query_context->getCurrentTransaction(); cur_txn) |
| 847 | { |
| 848 | if (query_context->getServerType() == ServerType::cnch_server) |
| 849 | { |
| 850 | query_context->getCnchTransactionCoordinator().finishTransaction(cur_txn); |
| 851 | } |
| 852 | } |
| 853 | }; |
| 854 |
no test coverage detected