@@ -4020,24 +4020,111 @@ Y_UNIT_TEST_SUITE(KqpNewEngine) {
40204020 Y_UNIT_TEST (AutoChooseIndexOrderByLimit) {
40214021 TKikimrSettings settings;
40224022 NKikimrConfig::TAppConfig appConfig;
4023- appConfig.MutableTableServiceConfig ()->SetIndexAutoChooseMode (NKikimrConfig::TTableServiceConfig_EIndexAutoChooseMode_ONLY_POINTS );
4023+ appConfig.MutableTableServiceConfig ()->SetIndexAutoChooseMode (NKikimrConfig::TTableServiceConfig_EIndexAutoChooseMode_MAX_USED_PREFIX );
40244024 settings.SetAppConfig (appConfig);
40254025
40264026 TKikimrRunner kikimr (settings);
40274027
40284028 auto db = kikimr.GetTableClient ();
40294029 auto session = db.CreateSession ().GetValueSync ().GetSession ();
4030- CreateSampleTablesWithIndex (session);
4030+ {
4031+ auto session = db.CreateSession ().GetValueSync ().GetSession ();
4032+ AssertSuccessResult (session.ExecuteSchemeQuery (R"(
4033+ --!syntax_v1
4034+ CREATE TABLE `/Root/ComplexKey` (
4035+ Key1 Int32,
4036+ Key2 Int32,
4037+ Key3 Int32,
4038+ Value Int32,
4039+ PRIMARY KEY (Key1, Key2, Key3),
4040+ INDEX Index GLOBAL ON (Key2)
4041+ );
4042+ )" ).GetValueSync ());
4043+
4044+ auto result2 = session.ExecuteDataQuery (R"(
4045+ REPLACE INTO `/Root/ComplexKey` (Key1, Key2, Key3, Value) VALUES
4046+ (1, 1, 101, 1),
4047+ (2, 2, 102, 1),
4048+ (2, 2, 103, 3),
4049+ (3, 3, 103, 2);
4050+ )" , TTxControl::BeginTx ().CommitTx ()).GetValueSync ();
4051+ UNIT_ASSERT_C (result2.IsSuccess (), result2.GetIssues ().ToString ());
4052+ }
4053+
4054+ NYdb::NTable::TExecDataQuerySettings querySettings;
4055+ querySettings.CollectQueryStats (ECollectQueryStatsMode::Profile);
4056+
4057+ {
4058+ auto result = session.ExecuteDataQuery (R"(
4059+ --!syntax_v1
4060+ SELECT Key1, Key2, Key3 FROM `/Root/ComplexKey`
4061+ WHERE Key1 = 2 and Key2 = 2;
4062+ )" , TTxControl::BeginTx (TTxSettings::SerializableRW ()), querySettings).GetValueSync ();
4063+ AssertSuccessResult (result);
4064+ AssertTableReads (result, " /Root/ComplexKey/Index/indexImplTable" , 2 );
4065+ }
4066+
4067+ {
4068+ auto result = session.ExecuteDataQuery (R"(
4069+ --!syntax_v1
4070+ SELECT Key1, Key2, Key3 FROM `/Root/ComplexKey`
4071+ WHERE Key1 = 2 and Key2 = 2
4072+ ORDER BY Key1 DESC
4073+ LIMIT 1;
4074+ )" , TTxControl::BeginTx (TTxSettings::SerializableRW ()), querySettings).GetValueSync ();
4075+ AssertSuccessResult (result);
4076+ AssertTableReads (result, " /Root/ComplexKey/Index/indexImplTable" , 0 );
4077+ }
4078+ }
4079+
4080+ Y_UNIT_TEST (AutoChooseIndexOrderByLambda) {
4081+ TKikimrSettings settings;
4082+ NKikimrConfig::TAppConfig appConfig;
4083+ appConfig.MutableTableServiceConfig ()->SetIndexAutoChooseMode (NKikimrConfig::TTableServiceConfig_EIndexAutoChooseMode_MAX_USED_PREFIX);
4084+ settings.SetAppConfig (appConfig);
4085+
4086+ TKikimrRunner kikimr (settings);
4087+
4088+ auto db = kikimr.GetTableClient ();
4089+ auto session = db.CreateSession ().GetValueSync ().GetSession ();
4090+ {
4091+ auto session = db.CreateSession ().GetValueSync ().GetSession ();
4092+ AssertSuccessResult (session.ExecuteSchemeQuery (R"(
4093+ --!syntax_v1
4094+ CREATE TABLE `/Root/ComplexKey` (
4095+ Key Int32,
4096+ Fk Int32,
4097+ Value String,
4098+ PRIMARY KEY (Key, Fk),
4099+ INDEX Index GLOBAL ON (Value)
4100+ );
4101+ )" ).GetValueSync ());
4102+
4103+ auto result2 = session.ExecuteDataQuery (R"(
4104+ REPLACE INTO `/Root/ComplexKey` (Key, Fk, Value) VALUES
4105+ (null, null, "NullValue"),
4106+ (1, 101, "Value1"),
4107+ (2, 102, "Value1"),
4108+ (2, 103, "Value3"),
4109+ (3, 103, "Value2"),
4110+ (4, 104, "Value2"),
4111+ (5, 105, "Value3");
4112+ )" , TTxControl::BeginTx ().CommitTx ()).GetValueSync ();
4113+ UNIT_ASSERT_C (result2.IsSuccess (), result2.GetIssues ().ToString ());
4114+ }
40314115
40324116 NYdb::NTable::TExecDataQuerySettings querySettings;
40334117 querySettings.CollectQueryStats (ECollectQueryStatsMode::Profile);
40344118
40354119 auto result = session.ExecuteDataQuery (R"(
40364120 --!syntax_v1
4037- SELECT Fk, Key FROM `/Root/SecondaryKeys` WHERE Fk = 1 ORDER BY Key DESC LIMIT 1;
4121+ SELECT Key, Fk, Value FROM `/Root/ComplexKey`
4122+ WHERE Key = 2
4123+ ORDER BY Value DESC
4124+ LIMIT 1;
40384125 )" , TTxControl::BeginTx (TTxSettings::SerializableRW ()), querySettings).GetValueSync ();
40394126 AssertSuccessResult (result);
4040- AssertTableReads (result, " /Root/SecondaryKeys/Index/indexImplTable " , 0 );
4127+ AssertTableReads (result, " /Root/ComplexKey " , 2 );
40414128 }
40424129
40434130 Y_UNIT_TEST (MultipleBroadcastJoin) {
0 commit comments