@@ -2992,9 +2992,9 @@ Y_UNIT_TEST_SUITE(KqpOlap) {
29922992 UNIT_ASSERT_VALUES_EQUAL (result.GetStatus (), EStatus::SUCCESS);
29932993 }
29942994
2995- Y_UNIT_TEST_TWIN (DeleteAbsent, Reboot ) {
2996- // This test tries to DELETE from a table with WHERE condition that matches no rows
2997- // It corresponds to a SCAN, then NO write then COMMIT
2995+ void TestDeleteAbsent ( const size_t shardCount, bool reboot ) {
2996+ // This test tries to DELETE from a table when there is no rows to delete at some shard
2997+ // It corresponds to a SCAN, then NO write then COMMIT on that shard
29982998 auto csController = NYDBTest::TControllers::RegisterCSControllerGuard<NYDBTest::NColumnShard::TController>();
29992999
30003000 NKikimrConfig::TAppConfig appConfig;
@@ -3006,20 +3006,73 @@ Y_UNIT_TEST_SUITE(KqpOlap) {
30063006 TTestHelper::TColumnSchema ().SetName (" value" ).SetType (NScheme::NTypeIds::Int32).SetNullable (true ),
30073007 };
30083008 TTestHelper::TColumnTable testTable;
3009- testTable.SetName (" /Root/ttt" ).SetPrimaryKey ({ " id" }).SetSharding ({ " id" }).SetSchema (schema);
3009+ testTable.SetName (" /Root/ttt" ).SetPrimaryKey ({ " id" }).SetSharding ({ " id" }).SetSchema (schema). SetMinPartitionsCount (shardCount) ;
30103010 testHelper.CreateTable (testTable);
3011+ auto client = testHelper.GetKikimr ().GetQueryClient ();
3012+ // 1. Insert exactlly one row into a table, so the only shard will contain a row
3013+ const auto result = client
3014+ .ExecuteQuery (
3015+ R"(
3016+ INSERT INTO `/Root/ttt` (id, value) VALUES
3017+ (1, 11)
3018+ )" ,
3019+ NYdb::NQuery::TTxControl::BeginTx ().CommitTx ())
3020+ .GetValueSync ();
3021+ UNIT_ASSERT_C (result.IsSuccess (), result.GetIssues ().ToString ());
3022+ // 2. Ensure that there is actually 1 row in the table
3023+ {
3024+ const auto resultSelect = client
3025+ .ExecuteQuery (
3026+ " SELECT * FROM `/Root/ttt`" ,
3027+ NYdb::NQuery::TTxControl::BeginTx ().CommitTx ())
3028+ .GetValueSync ();
30113029
3012- if (Reboot) {
3030+ UNIT_ASSERT_C (resultSelect.IsSuccess (), resultSelect.GetIssues ().ToString ());
3031+ const auto resultSets = resultSelect.GetResultSets ();
3032+ UNIT_ASSERT_VALUES_EQUAL (resultSets.size (), 1 );
3033+ const auto resultSet = resultSets[0 ];
3034+ UNIT_ASSERT_VALUES_EQUAL (resultSet.RowsCount (), 1 );
3035+ }
3036+ if (reboot) {
30133037 csController->SetRestartOnLocalTxCommitted (" TProposeWriteTransaction" );
30143038 }
3015- auto client = testHelper. GetKikimr (). GetQueryClient ();
3039+ // DELETE 1 row from one shard and 0 rows from others
30163040 const auto resultDelete =
30173041 client
30183042 .ExecuteQuery (
3019- " DELETE from `/Root/ttt` WHERE value % 2 == 1; " ,
3043+ " DELETE from `/Root/ttt` " ,
30203044 NYdb::NQuery::TTxControl::BeginTx ().CommitTx ())
30213045 .GetValueSync ();
3022- UNIT_ASSERT_C (resultDelete.IsSuccess (), resultDelete.GetIssues ().ToString ());
3046+ UNIT_ASSERT_C (resultDelete.IsSuccess () != reboot, resultDelete.GetIssues ().ToString ());
3047+ {
3048+ const auto resultSelect = client
3049+ .ExecuteQuery (
3050+ " SELECT * FROM `/Root/ttt`" ,
3051+ NYdb::NQuery::TTxControl::BeginTx ().CommitTx ())
3052+ .GetValueSync ();
3053+
3054+ UNIT_ASSERT_C (resultSelect.IsSuccess (), resultSelect.GetIssues ().ToString ());
3055+ const auto resultSets = resultSelect.GetResultSets ();
3056+ UNIT_ASSERT_VALUES_EQUAL (resultSets.size (), 1 );
3057+ const auto resultSet = resultSets[0 ];
3058+ UNIT_ASSERT_VALUES_EQUAL (resultSet.RowsCount (), reboot ? 1 : 0 );
3059+
3060+ }
3061+ // DELETE 0 rows from every shard
3062+ const auto resultDelete2 =
3063+ client
3064+ .ExecuteQuery (
3065+ " DELETE from `/Root/ttt` WHERE id < 100" ,
3066+ NYdb::NQuery::TTxControl::BeginTx ().CommitTx ())
3067+ .GetValueSync ();
3068+ UNIT_ASSERT_C (resultDelete2.IsSuccess () != reboot, result.GetIssues ().ToString ());
3069+ }
3070+ Y_UNIT_TEST_TWIN (DeleteAbsentSingleShard, Reboot) {
3071+ TestDeleteAbsent (1 , Reboot);
3072+ }
3073+
3074+ Y_UNIT_TEST_TWIN (DeleteAbsentMultipleShards, Reboot) {
3075+ TestDeleteAbsent (2 , Reboot);
30233076 }
30243077}
30253078
0 commit comments