Skip to content

Commit 622322c

Browse files
committed
Excluded in start of range in ListBy when it is not last property of key now works correctly.
1 parent 82c9eaa commit 622322c

File tree

5 files changed

+66
-104
lines changed

5 files changed

+66
-104
lines changed

BTDB/ODBLayer/RelationBuilder.cs

-26
Original file line numberDiff line numberDiff line change
@@ -551,8 +551,6 @@ void BuildRemoveByIdAdvancedParamMethod(MethodInfo method, ParameterInfo[] param
551551
var primaryKeyFields = FilterOutInKeyValues(ClientRelationVersionInfo.PrimaryKeyFields.Span);
552552
var field = primaryKeyFields[prefixParamCount];
553553

554-
if (parameters.Length != primaryKeyFields.Length)
555-
ForbidExcludePropositionInDebug(reqMethod.Generator, advEnumParamOrder, advEnumParam);
556554
ValidateAdvancedEnumParameter(field, advEnumParamType, method.Name);
557555

558556
reqMethod.Generator.Ldarg(0); //manipulator for call RemoveByIdAdvancedParam
@@ -667,8 +665,6 @@ void BuildListByIdMethod(MethodInfo method, IILMethod reqMethod)
667665
var primaryKeyFields = FilterOutInKeyValues(ClientRelationVersionInfo.PrimaryKeyFields.Span);
668666
var field = primaryKeyFields[prefixParamCount];
669667

670-
if (parameters.Length != primaryKeyFields.Length)
671-
ForbidExcludePropositionInDebug(reqMethod.Generator, advEnumParamOrder, advEnumParam);
672668
ValidateAdvancedEnumParameter(field, advEnumParamType, method.Name);
673669

674670
reqMethod.Generator.Ldarg(0).Castclass(typeof(IRelationDbManipulator));
@@ -845,8 +841,6 @@ void PrepareAnyCountByIdWithAep(MethodInfo method, IILMethod reqMethod, Paramete
845841
var primaryKeyFields = FilterOutInKeyValues(ClientRelationVersionInfo.PrimaryKeyFields.Span);
846842
var field = primaryKeyFields[prefixParamCount];
847843

848-
if (parameters.Length != primaryKeyFields.Length)
849-
ForbidExcludePropositionInDebug(reqMethod.Generator, advEnumParamOrder, advEnumParam);
850844
ValidateAdvancedEnumParameter(field, advEnumParamType, method.Name);
851845

852846
WritePrimaryKeyPrefixFinishedByAdvancedEnumeratorWithoutOrder(method, parameters, reqMethod,
@@ -871,8 +865,6 @@ void BuildListByMethod(MethodInfo method, IILMethod reqMethod)
871865
var skFields = ClientRelationVersionInfo.GetSecondaryKeyFields(secondaryKeyIndex);
872866
var field = skFields[prefixParamCount];
873867

874-
if (parameters.Length != skFields.Length)
875-
ForbidExcludePropositionInDebug(reqMethod.Generator, advEnumParamOrder, advEnumParam);
876868
ValidateAdvancedEnumParameter(field, advEnumParamType, method.Name);
877869

878870
reqMethod.Generator
@@ -966,22 +958,6 @@ void BuildListByMethod(MethodInfo method, IILMethod reqMethod)
966958
}
967959
}
968960

969-
[Conditional("DEBUG")]
970-
void ForbidExcludePropositionInDebug(IILGen ilGenerator, ushort advEnumParamOrder, Type advEnumParamType)
971-
{
972-
var propositionCheckFinished = ilGenerator.DefineLabel();
973-
ilGenerator
974-
.LdcI4((int)KeyProposition.Excluded)
975-
.Ldarg(advEnumParamOrder)
976-
.Ldfld(advEnumParamType.GetField(nameof(AdvancedEnumeratorParam<int>.StartProposition))!)
977-
.Ceq()
978-
.Brfalse(propositionCheckFinished)
979-
.Ldstr("Not supported Excluded proposition when listing by partial key.")
980-
.Newobj(() => new InvalidOperationException(null))
981-
.Throw()
982-
.Mark(propositionCheckFinished);
983-
}
984-
985961
void BuildCountByMethod(MethodInfo method, IILMethod reqMethod)
986962
{
987963
var parameters = method.GetParameters();
@@ -1061,8 +1037,6 @@ void PrepareAnyCountByWithAep(MethodInfo method, IILMethod reqMethod, ParameterI
10611037
var skFields = ClientRelationVersionInfo.GetSecondaryKeyFields(secondaryKeyIndex);
10621038
var field = skFields[prefixParamCount];
10631039

1064-
if (parameters.Length != skFields.Length)
1065-
ForbidExcludePropositionInDebug(reqMethod.Generator, advEnumParamOrder, advEnumParam);
10661040
ValidateAdvancedEnumParameter(field, advEnumParamType, method.Name);
10671041

10681042
var (pushWriter, ctxLocFactory) = WriterPushers(reqMethod.Generator);

BTDB/ODBLayer/RelationEnumerator.cs

+20-5
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,15 @@ public RelationAdvancedEnumerator(
829829
}
830830
else
831831
{
832+
if (startKeyProposition == KeyProposition.Excluded)
833+
{
834+
if (_keyValueTr.FindLastKey(startKeyBytes))
835+
{
836+
startIndex = _keyValueTr.GetKeyIndex() - prefixIndex + 1;
837+
goto startIndexFound;
838+
}
839+
}
840+
832841
switch (_keyValueTr.Find(startKeyBytes, (uint)prefixLen))
833842
{
834843
case FindResult.Exact:
@@ -853,6 +862,7 @@ public RelationAdvancedEnumerator(
853862
}
854863
}
855864

865+
startIndexFound:
856866
_count = (uint)Math.Max(0, endIndex - startIndex + 1);
857867
_startPos = (uint)(_ascending ? startIndex : endIndex);
858868
_pos = 0;
@@ -1108,15 +1118,19 @@ public RelationAdvancedOrderedEnumerator(IRelationDbManipulator manipulator,
11081118
}
11091119
else
11101120
{
1121+
if (startKeyProposition == KeyProposition.Excluded)
1122+
{
1123+
if (_keyValueTr.FindLastKey(startKeyBytes))
1124+
{
1125+
startIndex = _keyValueTr.GetKeyIndex() - prefixIndex + 1;
1126+
goto startIndexFound;
1127+
}
1128+
}
1129+
11111130
switch (_keyValueTr.Find(startKeyBytes, (uint)prefixLen))
11121131
{
11131132
case FindResult.Exact:
11141133
startIndex = _keyValueTr.GetKeyIndex() - prefixIndex;
1115-
if (startKeyProposition == KeyProposition.Excluded)
1116-
{
1117-
startIndex++;
1118-
}
1119-
11201134
break;
11211135
case FindResult.Previous:
11221136
startIndex = _keyValueTr.GetKeyIndex() - prefixIndex + 1;
@@ -1132,6 +1146,7 @@ public RelationAdvancedOrderedEnumerator(IRelationDbManipulator manipulator,
11321146
}
11331147
}
11341148

1149+
startIndexFound:
11351150
_count = (uint)Math.Max(0, endIndex - startIndex + 1);
11361151
_startPos = (uint)(_ascending ? startIndex : endIndex);
11371152
_pos = 0;

0 commit comments

Comments
 (0)