aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordcherednik <dcherednik@ydb.tech>2023-03-06 15:07:49 +0300
committerdcherednik <dcherednik@ydb.tech>2023-03-06 15:07:49 +0300
commit55060209757c994259968a68420de3126687fa38 (patch)
tree99bf63bf9956672515c4f2103edd19482c86b681
parent5107235a3e72bb766783954ac5cbc77cb2bfd679 (diff)
downloadydb-55060209757c994259968a68420de3126687fa38.tar.gz
Tests for read cost calculation.
-rw-r--r--ydb/core/kqp/ut/CMakeLists.txt1
-rw-r--r--ydb/core/kqp/ut/cost/CMakeLists.darwin.txt78
-rw-r--r--ydb/core/kqp/ut/cost/CMakeLists.linux-aarch64.txt80
-rw-r--r--ydb/core/kqp/ut/cost/CMakeLists.linux.txt82
-rw-r--r--ydb/core/kqp/ut/cost/CMakeLists.txt15
-rw-r--r--ydb/core/kqp/ut/cost/kqp_cost_ut.cpp144
6 files changed, 400 insertions, 0 deletions
diff --git a/ydb/core/kqp/ut/CMakeLists.txt b/ydb/core/kqp/ut/CMakeLists.txt
index fef9ae93219..fc5fecfb140 100644
--- a/ydb/core/kqp/ut/CMakeLists.txt
+++ b/ydb/core/kqp/ut/CMakeLists.txt
@@ -8,6 +8,7 @@
add_subdirectory(arrow)
add_subdirectory(common)
+add_subdirectory(cost)
add_subdirectory(effects)
add_subdirectory(federated_query)
add_subdirectory(indexes)
diff --git a/ydb/core/kqp/ut/cost/CMakeLists.darwin.txt b/ydb/core/kqp/ut/cost/CMakeLists.darwin.txt
new file mode 100644
index 00000000000..917622b8f09
--- /dev/null
+++ b/ydb/core/kqp/ut/cost/CMakeLists.darwin.txt
@@ -0,0 +1,78 @@
+
+# This file was generated by the build system used internally in the Yandex monorepo.
+# Only simple modifications are allowed (adding source-files to targets, adding simple properties
+# like target_include_directories). These modifications will be ported to original
+# ya.make files by maintainers. Any complex modifications which can't be ported back to the
+# original buildsystem will not be accepted.
+
+
+
+add_executable(ydb-core-kqp-ut-cost)
+target_compile_options(ydb-core-kqp-ut-cost PRIVATE
+ -DUSE_CURRENT_UDF_ABI_VERSION
+)
+target_include_directories(ydb-core-kqp-ut-cost PRIVATE
+ ${CMAKE_SOURCE_DIR}/ydb/core/kqp
+)
+target_link_libraries(ydb-core-kqp-ut-cost PUBLIC
+ contrib-libs-cxxsupp
+ yutil
+ cpp-malloc-system
+ library-cpp-cpuid_check
+ cpp-testing-unittest_main
+ ydb-core-kqp
+ kqp-ut-common
+ yql-sql-pg_dummy
+)
+target_link_options(ydb-core-kqp-ut-cost PRIVATE
+ -Wl,-no_deduplicate
+ -Wl,-sdk_version,10.15
+ -fPIC
+ -fPIC
+ -framework
+ CoreFoundation
+)
+target_sources(ydb-core-kqp-ut-cost PRIVATE
+ ${CMAKE_SOURCE_DIR}/ydb/core/kqp/ut/cost/kqp_cost_ut.cpp
+)
+set_property(
+ TARGET
+ ydb-core-kqp-ut-cost
+ PROPERTY
+ SPLIT_FACTOR
+ 50
+)
+add_yunittest(
+ NAME
+ ydb-core-kqp-ut-cost
+ TEST_TARGET
+ ydb-core-kqp-ut-cost
+ TEST_ARG
+ --print-before-suite
+ --print-before-test
+ --fork-tests
+ --print-times
+ --show-fails
+)
+set_yunittest_property(
+ TEST
+ ydb-core-kqp-ut-cost
+ PROPERTY
+ LABELS
+ MEDIUM
+)
+set_yunittest_property(
+ TEST
+ ydb-core-kqp-ut-cost
+ PROPERTY
+ PROCESSORS
+ 1
+)
+set_yunittest_property(
+ TEST
+ ydb-core-kqp-ut-cost
+ PROPERTY
+ TIMEOUT
+ 600
+)
+vcs_info(ydb-core-kqp-ut-cost)
diff --git a/ydb/core/kqp/ut/cost/CMakeLists.linux-aarch64.txt b/ydb/core/kqp/ut/cost/CMakeLists.linux-aarch64.txt
new file mode 100644
index 00000000000..edbef5a4f78
--- /dev/null
+++ b/ydb/core/kqp/ut/cost/CMakeLists.linux-aarch64.txt
@@ -0,0 +1,80 @@
+
+# This file was generated by the build system used internally in the Yandex monorepo.
+# Only simple modifications are allowed (adding source-files to targets, adding simple properties
+# like target_include_directories). These modifications will be ported to original
+# ya.make files by maintainers. Any complex modifications which can't be ported back to the
+# original buildsystem will not be accepted.
+
+
+
+add_executable(ydb-core-kqp-ut-cost)
+target_compile_options(ydb-core-kqp-ut-cost PRIVATE
+ -DUSE_CURRENT_UDF_ABI_VERSION
+)
+target_include_directories(ydb-core-kqp-ut-cost PRIVATE
+ ${CMAKE_SOURCE_DIR}/ydb/core/kqp
+)
+target_link_libraries(ydb-core-kqp-ut-cost PUBLIC
+ contrib-libs-linux-headers
+ contrib-libs-cxxsupp
+ yutil
+ library-cpp-lfalloc
+ cpp-testing-unittest_main
+ ydb-core-kqp
+ kqp-ut-common
+ yql-sql-pg_dummy
+)
+target_link_options(ydb-core-kqp-ut-cost PRIVATE
+ -ldl
+ -lrt
+ -Wl,--no-as-needed
+ -fPIC
+ -fPIC
+ -lpthread
+ -lrt
+ -ldl
+)
+target_sources(ydb-core-kqp-ut-cost PRIVATE
+ ${CMAKE_SOURCE_DIR}/ydb/core/kqp/ut/cost/kqp_cost_ut.cpp
+)
+set_property(
+ TARGET
+ ydb-core-kqp-ut-cost
+ PROPERTY
+ SPLIT_FACTOR
+ 50
+)
+add_yunittest(
+ NAME
+ ydb-core-kqp-ut-cost
+ TEST_TARGET
+ ydb-core-kqp-ut-cost
+ TEST_ARG
+ --print-before-suite
+ --print-before-test
+ --fork-tests
+ --print-times
+ --show-fails
+)
+set_yunittest_property(
+ TEST
+ ydb-core-kqp-ut-cost
+ PROPERTY
+ LABELS
+ MEDIUM
+)
+set_yunittest_property(
+ TEST
+ ydb-core-kqp-ut-cost
+ PROPERTY
+ PROCESSORS
+ 1
+)
+set_yunittest_property(
+ TEST
+ ydb-core-kqp-ut-cost
+ PROPERTY
+ TIMEOUT
+ 600
+)
+vcs_info(ydb-core-kqp-ut-cost)
diff --git a/ydb/core/kqp/ut/cost/CMakeLists.linux.txt b/ydb/core/kqp/ut/cost/CMakeLists.linux.txt
new file mode 100644
index 00000000000..2a0157a62cf
--- /dev/null
+++ b/ydb/core/kqp/ut/cost/CMakeLists.linux.txt
@@ -0,0 +1,82 @@
+
+# This file was generated by the build system used internally in the Yandex monorepo.
+# Only simple modifications are allowed (adding source-files to targets, adding simple properties
+# like target_include_directories). These modifications will be ported to original
+# ya.make files by maintainers. Any complex modifications which can't be ported back to the
+# original buildsystem will not be accepted.
+
+
+
+add_executable(ydb-core-kqp-ut-cost)
+target_compile_options(ydb-core-kqp-ut-cost PRIVATE
+ -DUSE_CURRENT_UDF_ABI_VERSION
+)
+target_include_directories(ydb-core-kqp-ut-cost PRIVATE
+ ${CMAKE_SOURCE_DIR}/ydb/core/kqp
+)
+target_link_libraries(ydb-core-kqp-ut-cost PUBLIC
+ contrib-libs-linux-headers
+ contrib-libs-cxxsupp
+ yutil
+ cpp-malloc-tcmalloc
+ libs-tcmalloc-no_percpu_cache
+ library-cpp-cpuid_check
+ cpp-testing-unittest_main
+ ydb-core-kqp
+ kqp-ut-common
+ yql-sql-pg_dummy
+)
+target_link_options(ydb-core-kqp-ut-cost PRIVATE
+ -ldl
+ -lrt
+ -Wl,--no-as-needed
+ -fPIC
+ -fPIC
+ -lpthread
+ -lrt
+ -ldl
+)
+target_sources(ydb-core-kqp-ut-cost PRIVATE
+ ${CMAKE_SOURCE_DIR}/ydb/core/kqp/ut/cost/kqp_cost_ut.cpp
+)
+set_property(
+ TARGET
+ ydb-core-kqp-ut-cost
+ PROPERTY
+ SPLIT_FACTOR
+ 50
+)
+add_yunittest(
+ NAME
+ ydb-core-kqp-ut-cost
+ TEST_TARGET
+ ydb-core-kqp-ut-cost
+ TEST_ARG
+ --print-before-suite
+ --print-before-test
+ --fork-tests
+ --print-times
+ --show-fails
+)
+set_yunittest_property(
+ TEST
+ ydb-core-kqp-ut-cost
+ PROPERTY
+ LABELS
+ MEDIUM
+)
+set_yunittest_property(
+ TEST
+ ydb-core-kqp-ut-cost
+ PROPERTY
+ PROCESSORS
+ 1
+)
+set_yunittest_property(
+ TEST
+ ydb-core-kqp-ut-cost
+ PROPERTY
+ TIMEOUT
+ 600
+)
+vcs_info(ydb-core-kqp-ut-cost)
diff --git a/ydb/core/kqp/ut/cost/CMakeLists.txt b/ydb/core/kqp/ut/cost/CMakeLists.txt
new file mode 100644
index 00000000000..5bb4faffb40
--- /dev/null
+++ b/ydb/core/kqp/ut/cost/CMakeLists.txt
@@ -0,0 +1,15 @@
+
+# This file was generated by the build system used internally in the Yandex monorepo.
+# Only simple modifications are allowed (adding source-files to targets, adding simple properties
+# like target_include_directories). These modifications will be ported to original
+# ya.make files by maintainers. Any complex modifications which can't be ported back to the
+# original buildsystem will not be accepted.
+
+
+if (CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" AND UNIX AND NOT APPLE AND NOT ANDROID)
+ include(CMakeLists.linux-aarch64.txt)
+elseif (APPLE AND CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
+ include(CMakeLists.darwin.txt)
+elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" AND UNIX AND NOT APPLE AND NOT ANDROID)
+ include(CMakeLists.linux.txt)
+endif()
diff --git a/ydb/core/kqp/ut/cost/kqp_cost_ut.cpp b/ydb/core/kqp/ut/cost/kqp_cost_ut.cpp
new file mode 100644
index 00000000000..6f732f8c434
--- /dev/null
+++ b/ydb/core/kqp/ut/cost/kqp_cost_ut.cpp
@@ -0,0 +1,144 @@
+#include <ydb/core/kqp/ut/common/kqp_ut_common.h>
+
+#include <ydb/core/kqp/counters/kqp_counters.h>
+#include <ydb/public/sdk/cpp/client/ydb_proto/accessor.h>
+
+#include <library/cpp/json/json_reader.h>
+
+namespace NKikimr {
+namespace NKqp {
+
+using namespace NYdb;
+using namespace NYdb::NTable;
+
+static NKikimrConfig::TAppConfig GetAppConfig(bool sourceRead) {
+ auto app = NKikimrConfig::TAppConfig();
+ app.MutableTableServiceConfig()->SetEnableKqpDataQuerySourceRead(sourceRead);
+ app.MutableTableServiceConfig()->SetEnableKqpScanQuerySourceRead(sourceRead);
+ return app;
+}
+
+static NYdb::NTable::TExecDataQuerySettings GetDataQuerySettings() {
+ NYdb::NTable::TExecDataQuerySettings execSettings;
+ execSettings.CollectQueryStats(ECollectQueryStatsMode::Basic);
+ return execSettings;
+}
+
+Y_UNIT_TEST_SUITE(KqpCost) {
+ Y_UNIT_TEST_TWIN(PointLookup, SourceRead) {
+ TKikimrRunner kikimr(GetAppConfig(SourceRead));
+ auto db = kikimr.GetTableClient();
+ auto session = db.CreateSession().GetValueSync().GetSession();
+
+ auto query = Q_(R"(
+ SELECT * FROM `/Root/Test` WHERE Group = 1u AND Name = "Anna";
+ )");
+
+ auto txControl = TTxControl::BeginTx().CommitTx();
+
+ auto result = session.ExecuteDataQuery(query, txControl, GetDataQuerySettings()).ExtractValueSync();
+ UNIT_ASSERT_VALUES_EQUAL(result.GetStatus(), EStatus::SUCCESS);
+
+ CompareYson(R"(
+ [
+ [[3500u];["None"];
+ [1u];["Anna"]]
+ ]
+ )", NYdb::FormatResultSetYson(result.GetResultSet(0)));
+
+ auto stats = NYdb::TProtoAccessor::GetProto(*result.GetStats());
+
+ UNIT_ASSERT_VALUES_EQUAL(stats.query_phases(0).table_access(0).reads().rows(), 1);
+ UNIT_ASSERT_VALUES_EQUAL(stats.query_phases(0).table_access(0).reads().bytes(), 20);
+ }
+
+ Y_UNIT_TEST_TWIN(Range, SourceRead) {
+ TKikimrRunner kikimr(GetAppConfig(SourceRead));
+ auto db = kikimr.GetTableClient();
+ auto session = db.CreateSession().GetValueSync().GetSession();
+
+ auto query = Q_(R"(
+ SELECT * FROM `/Root/Test` WHERE Group < 2u ORDER BY Group;
+ )");
+
+ auto txControl = TTxControl::BeginTx().CommitTx();
+
+ auto result = session.ExecuteDataQuery(query, txControl, GetDataQuerySettings()).ExtractValueSync();
+ UNIT_ASSERT_VALUES_EQUAL(result.GetStatus(), EStatus::SUCCESS);
+
+ CompareYson(R"(
+ [
+ [[3500u];["None"];[1u];["Anna"]];
+ [[300u];["None"];[1u];["Paul"]]
+ ]
+ )", NYdb::FormatResultSetYson(result.GetResultSet(0)));
+
+ auto stats = NYdb::TProtoAccessor::GetProto(*result.GetStats());
+
+ UNIT_ASSERT_VALUES_EQUAL(stats.query_phases(0).table_access(0).reads().rows(), 2);
+ UNIT_ASSERT_VALUES_EQUAL(stats.query_phases(0).table_access(0).reads().bytes(), 40);
+ }
+
+ Y_UNIT_TEST_TWIN(RangeFullScan, SourceRead) {
+ TKikimrRunner kikimr(GetAppConfig(SourceRead));
+
+ auto db = kikimr.GetTableClient();
+ auto session = db.CreateSession().GetValueSync().GetSession();
+
+ auto query = Q_(R"(
+ SELECT * FROM `/Root/Test` WHERE Amount < 5000ul ORDER BY Group LIMIT 1;
+ )");
+
+ auto txControl = TTxControl::BeginTx().CommitTx();
+
+ auto result = session.ExecuteDataQuery(query, txControl, GetDataQuerySettings()).ExtractValueSync();
+ UNIT_ASSERT_VALUES_EQUAL(result.GetStatus(), EStatus::SUCCESS);
+
+ CompareYson(R"(
+ [
+ [[3500u];["None"];[1u];["Anna"]]
+ ]
+ )", NYdb::FormatResultSetYson(result.GetResultSet(0)));
+
+ auto stats = NYdb::TProtoAccessor::GetProto(*result.GetStats());
+
+ Cerr << stats.DebugString() << Endl;
+ UNIT_ASSERT_VALUES_EQUAL(stats.query_phases(0).table_access(0).reads().rows(), 1);
+ UNIT_ASSERT_VALUES_EQUAL(stats.query_phases(0).table_access(0).reads().bytes(), 20);
+ }
+
+ Y_UNIT_TEST_TWIN(ScanQueryRangeFullScan, SourceRead) {
+ TKikimrRunner kikimr(GetAppConfig(SourceRead));
+
+ auto db = kikimr.GetTableClient();
+
+ auto query = Q_(R"(
+ SELECT * FROM `/Root/Test` WHERE Amount < 5000ul ORDER BY Group LIMIT 1;
+ )");
+
+ NYdb::NTable::TStreamExecScanQuerySettings execSettings;
+ execSettings.CollectQueryStats(ECollectQueryStatsMode::Basic);
+
+ auto it = db.StreamExecuteScanQuery(query, execSettings).ExtractValueSync();
+ UNIT_ASSERT_VALUES_EQUAL(it.GetStatus(), EStatus::SUCCESS);
+ auto res = CollectStreamResult(it);
+
+ CompareYson(R"(
+ [
+ [[3500u];["None"];[1u];["Anna"]]
+ ]
+ )", res.ResultSetYson);
+
+/* const auto& stats = *res.QueryStats;
+
+ Cerr << stats.DebugString() << Endl;
+ UNIT_ASSERT_VALUES_EQUAL(stats.query_phases(0).table_access(0).reads().rows(), 1);
+ UNIT_ASSERT_VALUES_EQUAL(stats.query_phases(0).table_access(0).reads().bytes(), 20);
+*/
+ }
+
+
+}
+
+}
+}