|
1 | 1 | #include <ydb/core/kqp/ut/common/kqp_ut_common.h>
|
2 | 2 | #include <ydb/library/yql/sql/sql.h>
|
3 | 3 | #include <ydb/library/yql/utils/log/log.h>
|
| 4 | +#include <ydb/public/sdk/cpp/client/ydb_proto/accessor.h> |
4 | 5 |
|
5 | 6 | #include <util/folder/filelist.h>
|
6 | 7 |
|
7 | 8 | #include <format>
|
8 | 9 |
|
9 | 10 | using namespace NKikimr;
|
10 | 11 | using namespace NKikimr::NKqp;
|
| 12 | +using namespace NYdb; |
11 | 13 | using namespace NYdb::NTable;
|
12 | 14 |
|
13 | 15 | namespace {
|
@@ -376,4 +378,51 @@ Y_UNIT_TEST_SUITE(TSelectFromViewTest) {
|
376 | 378 | ExecuteDataDefinitionQuery(session, ReadWholeFile(pathPrefix + "drop_view.sql"));
|
377 | 379 | }
|
378 | 380 | }
|
| 381 | + |
| 382 | + Y_UNIT_TEST(QueryCacheIsUpdated) { |
| 383 | + TKikimrRunner kikimr(TKikimrSettings().SetWithSampleTables(false)); |
| 384 | + EnableViewsFeatureFlag(kikimr); |
| 385 | + auto session = kikimr.GetTableClient().CreateSession().GetValueSync().GetSession(); |
| 386 | + |
| 387 | + constexpr const char* viewName = "TheView"; |
| 388 | + |
| 389 | + const auto getCreationQuery = [&viewName](const char* innerQuery) -> TString { |
| 390 | + return std::format(R"( |
| 391 | + CREATE VIEW {} WITH (security_invoker = TRUE) AS {}; |
| 392 | + )", |
| 393 | + viewName, |
| 394 | + innerQuery |
| 395 | + ); |
| 396 | + }; |
| 397 | + constexpr const char* firstInnerQuery = "SELECT 1"; |
| 398 | + ExecuteDataDefinitionQuery(session, getCreationQuery(firstInnerQuery)); |
| 399 | + |
| 400 | + const TString selectFromViewQuery = std::format(R"( |
| 401 | + SELECT * FROM {}; |
| 402 | + )", |
| 403 | + viewName |
| 404 | + ); |
| 405 | + TExecDataQuerySettings queryExecutionSettings; |
| 406 | + queryExecutionSettings.KeepInQueryCache(true); |
| 407 | + queryExecutionSettings.CollectQueryStats(ECollectQueryStatsMode::Basic); |
| 408 | + ExecuteDataModificationQuery(session, selectFromViewQuery, queryExecutionSettings); |
| 409 | + // make sure the server side cache is working by calling the same query twice |
| 410 | + const auto cachedQueryRawResult = ExecuteDataModificationQuery(session, selectFromViewQuery, queryExecutionSettings); |
| 411 | + AssertFromCache(cachedQueryRawResult.GetStats(), true); |
| 412 | + UNIT_ASSERT_VALUES_EQUAL(GetInteger(GetSingleResult(cachedQueryRawResult)), 1); |
| 413 | + |
| 414 | + // recreate the view with a different query inside |
| 415 | + ExecuteDataDefinitionQuery(session, std::format(R"( |
| 416 | + DROP VIEW {}; |
| 417 | + )", |
| 418 | + viewName |
| 419 | + ) |
| 420 | + ); |
| 421 | + constexpr const char* secondInnerQuery = "SELECT 2"; |
| 422 | + ExecuteDataDefinitionQuery(session, getCreationQuery(secondInnerQuery)); |
| 423 | + |
| 424 | + const auto secondCallRawResult = ExecuteDataModificationQuery(session, selectFromViewQuery, queryExecutionSettings); |
| 425 | + AssertFromCache(secondCallRawResult.GetStats(), false); |
| 426 | + UNIT_ASSERT_VALUES_EQUAL(GetInteger(GetSingleResult(secondCallRawResult)), 2); |
| 427 | + } |
379 | 428 | }
|
0 commit comments