@@ -4062,24 +4062,111 @@ Y_UNIT_TEST_SUITE(KqpNewEngine) {
4062
4062
Y_UNIT_TEST (AutoChooseIndexOrderByLimit) {
4063
4063
TKikimrSettings settings;
4064
4064
NKikimrConfig::TAppConfig appConfig;
4065
- appConfig.MutableTableServiceConfig ()->SetIndexAutoChooseMode (NKikimrConfig::TTableServiceConfig_EIndexAutoChooseMode_ONLY_POINTS );
4065
+ appConfig.MutableTableServiceConfig ()->SetIndexAutoChooseMode (NKikimrConfig::TTableServiceConfig_EIndexAutoChooseMode_MAX_USED_PREFIX );
4066
4066
settings.SetAppConfig (appConfig);
4067
4067
4068
4068
TKikimrRunner kikimr (settings);
4069
4069
4070
4070
auto db = kikimr.GetTableClient ();
4071
4071
auto session = db.CreateSession ().GetValueSync ().GetSession ();
4072
- CreateSampleTablesWithIndex (session);
4072
+ {
4073
+ auto session = db.CreateSession ().GetValueSync ().GetSession ();
4074
+ AssertSuccessResult (session.ExecuteSchemeQuery (R"(
4075
+ --!syntax_v1
4076
+ CREATE TABLE `/Root/ComplexKey` (
4077
+ Key1 Int32,
4078
+ Key2 Int32,
4079
+ Key3 Int32,
4080
+ Value Int32,
4081
+ PRIMARY KEY (Key1, Key2, Key3),
4082
+ INDEX Index GLOBAL ON (Key2)
4083
+ );
4084
+ )" ).GetValueSync ());
4085
+
4086
+ auto result2 = session.ExecuteDataQuery (R"(
4087
+ REPLACE INTO `/Root/ComplexKey` (Key1, Key2, Key3, Value) VALUES
4088
+ (1, 1, 101, 1),
4089
+ (2, 2, 102, 1),
4090
+ (2, 2, 103, 3),
4091
+ (3, 3, 103, 2);
4092
+ )" , TTxControl::BeginTx ().CommitTx ()).GetValueSync ();
4093
+ UNIT_ASSERT_C (result2.IsSuccess (), result2.GetIssues ().ToString ());
4094
+ }
4095
+
4096
+ NYdb::NTable::TExecDataQuerySettings querySettings;
4097
+ querySettings.CollectQueryStats (ECollectQueryStatsMode::Profile);
4098
+
4099
+ {
4100
+ auto result = session.ExecuteDataQuery (R"(
4101
+ --!syntax_v1
4102
+ SELECT Key1, Key2, Key3 FROM `/Root/ComplexKey`
4103
+ WHERE Key1 = 2 and Key2 = 2;
4104
+ )" , TTxControl::BeginTx (TTxSettings::SerializableRW ()), querySettings).GetValueSync ();
4105
+ AssertSuccessResult (result);
4106
+ AssertTableReads (result, " /Root/ComplexKey/Index/indexImplTable" , 2 );
4107
+ }
4108
+
4109
+ {
4110
+ auto result = session.ExecuteDataQuery (R"(
4111
+ --!syntax_v1
4112
+ SELECT Key1, Key2, Key3 FROM `/Root/ComplexKey`
4113
+ WHERE Key1 = 2 and Key2 = 2
4114
+ ORDER BY Key1 DESC
4115
+ LIMIT 1;
4116
+ )" , TTxControl::BeginTx (TTxSettings::SerializableRW ()), querySettings).GetValueSync ();
4117
+ AssertSuccessResult (result);
4118
+ AssertTableReads (result, " /Root/ComplexKey/Index/indexImplTable" , 0 );
4119
+ }
4120
+ }
4121
+
4122
+ Y_UNIT_TEST (AutoChooseIndexOrderByLambda) {
4123
+ TKikimrSettings settings;
4124
+ NKikimrConfig::TAppConfig appConfig;
4125
+ appConfig.MutableTableServiceConfig ()->SetIndexAutoChooseMode (NKikimrConfig::TTableServiceConfig_EIndexAutoChooseMode_MAX_USED_PREFIX);
4126
+ settings.SetAppConfig (appConfig);
4127
+
4128
+ TKikimrRunner kikimr (settings);
4129
+
4130
+ auto db = kikimr.GetTableClient ();
4131
+ auto session = db.CreateSession ().GetValueSync ().GetSession ();
4132
+ {
4133
+ auto session = db.CreateSession ().GetValueSync ().GetSession ();
4134
+ AssertSuccessResult (session.ExecuteSchemeQuery (R"(
4135
+ --!syntax_v1
4136
+ CREATE TABLE `/Root/ComplexKey` (
4137
+ Key Int32,
4138
+ Fk Int32,
4139
+ Value String,
4140
+ PRIMARY KEY (Key, Fk),
4141
+ INDEX Index GLOBAL ON (Value)
4142
+ );
4143
+ )" ).GetValueSync ());
4144
+
4145
+ auto result2 = session.ExecuteDataQuery (R"(
4146
+ REPLACE INTO `/Root/ComplexKey` (Key, Fk, Value) VALUES
4147
+ (null, null, "NullValue"),
4148
+ (1, 101, "Value1"),
4149
+ (2, 102, "Value1"),
4150
+ (2, 103, "Value3"),
4151
+ (3, 103, "Value2"),
4152
+ (4, 104, "Value2"),
4153
+ (5, 105, "Value3");
4154
+ )" , TTxControl::BeginTx ().CommitTx ()).GetValueSync ();
4155
+ UNIT_ASSERT_C (result2.IsSuccess (), result2.GetIssues ().ToString ());
4156
+ }
4073
4157
4074
4158
NYdb::NTable::TExecDataQuerySettings querySettings;
4075
4159
querySettings.CollectQueryStats (ECollectQueryStatsMode::Profile);
4076
4160
4077
4161
auto result = session.ExecuteDataQuery (R"(
4078
4162
--!syntax_v1
4079
- SELECT Fk, Key FROM `/Root/SecondaryKeys` WHERE Fk = 1 ORDER BY Key DESC LIMIT 1;
4163
+ SELECT Key, Fk, Value FROM `/Root/ComplexKey`
4164
+ WHERE Key = 2
4165
+ ORDER BY Value DESC
4166
+ LIMIT 1;
4080
4167
)" , TTxControl::BeginTx (TTxSettings::SerializableRW ()), querySettings).GetValueSync ();
4081
4168
AssertSuccessResult (result);
4082
- AssertTableReads (result, " /Root/SecondaryKeys/Index/indexImplTable " , 0 );
4169
+ AssertTableReads (result, " /Root/ComplexKey " , 2 );
4083
4170
}
4084
4171
4085
4172
Y_UNIT_TEST (MultipleBroadcastJoin) {
0 commit comments