Skip to content

Commit

Permalink
Excluded in start of range in ListBy when it is not last property…
Browse files Browse the repository at this point in the history
… of key now works correctly.
  • Loading branch information
Bobris committed Jul 6, 2024
1 parent 82c9eaa commit 622322c
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 104 deletions.
26 changes: 0 additions & 26 deletions BTDB/ODBLayer/RelationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -551,8 +551,6 @@ void BuildRemoveByIdAdvancedParamMethod(MethodInfo method, ParameterInfo[] param
var primaryKeyFields = FilterOutInKeyValues(ClientRelationVersionInfo.PrimaryKeyFields.Span);
var field = primaryKeyFields[prefixParamCount];

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

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

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

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

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

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

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

reqMethod.Generator
Expand Down Expand Up @@ -966,22 +958,6 @@ void BuildListByMethod(MethodInfo method, IILMethod reqMethod)
}
}

[Conditional("DEBUG")]
void ForbidExcludePropositionInDebug(IILGen ilGenerator, ushort advEnumParamOrder, Type advEnumParamType)
{
var propositionCheckFinished = ilGenerator.DefineLabel();
ilGenerator
.LdcI4((int)KeyProposition.Excluded)
.Ldarg(advEnumParamOrder)
.Ldfld(advEnumParamType.GetField(nameof(AdvancedEnumeratorParam<int>.StartProposition))!)
.Ceq()
.Brfalse(propositionCheckFinished)
.Ldstr("Not supported Excluded proposition when listing by partial key.")
.Newobj(() => new InvalidOperationException(null))
.Throw()
.Mark(propositionCheckFinished);
}

void BuildCountByMethod(MethodInfo method, IILMethod reqMethod)
{
var parameters = method.GetParameters();
Expand Down Expand Up @@ -1061,8 +1037,6 @@ void PrepareAnyCountByWithAep(MethodInfo method, IILMethod reqMethod, ParameterI
var skFields = ClientRelationVersionInfo.GetSecondaryKeyFields(secondaryKeyIndex);
var field = skFields[prefixParamCount];

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

var (pushWriter, ctxLocFactory) = WriterPushers(reqMethod.Generator);
Expand Down
25 changes: 20 additions & 5 deletions BTDB/ODBLayer/RelationEnumerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,15 @@ public RelationAdvancedEnumerator(
}
else
{
if (startKeyProposition == KeyProposition.Excluded)
{
if (_keyValueTr.FindLastKey(startKeyBytes))
{
startIndex = _keyValueTr.GetKeyIndex() - prefixIndex + 1;
goto startIndexFound;
}
}

switch (_keyValueTr.Find(startKeyBytes, (uint)prefixLen))
{
case FindResult.Exact:
Expand All @@ -853,6 +862,7 @@ public RelationAdvancedEnumerator(
}
}

startIndexFound:
_count = (uint)Math.Max(0, endIndex - startIndex + 1);
_startPos = (uint)(_ascending ? startIndex : endIndex);
_pos = 0;
Expand Down Expand Up @@ -1108,15 +1118,19 @@ public RelationAdvancedOrderedEnumerator(IRelationDbManipulator manipulator,
}
else
{
if (startKeyProposition == KeyProposition.Excluded)
{
if (_keyValueTr.FindLastKey(startKeyBytes))
{
startIndex = _keyValueTr.GetKeyIndex() - prefixIndex + 1;
goto startIndexFound;
}
}

switch (_keyValueTr.Find(startKeyBytes, (uint)prefixLen))
{
case FindResult.Exact:
startIndex = _keyValueTr.GetKeyIndex() - prefixIndex;
if (startKeyProposition == KeyProposition.Excluded)
{
startIndex++;
}

break;
case FindResult.Previous:
startIndex = _keyValueTr.GetKeyIndex() - prefixIndex + 1;
Expand All @@ -1132,6 +1146,7 @@ public RelationAdvancedOrderedEnumerator(IRelationDbManipulator manipulator,
}
}

startIndexFound:
_count = (uint)Math.Max(0, endIndex - startIndex + 1);
_startPos = (uint)(_ascending ? startIndex : endIndex);
_pos = 0;
Expand Down
Loading

0 comments on commit 622322c

Please sign in to comment.