diff --git a/src/SharpCoreDB/DataStructures/Table.CRUD.cs b/src/SharpCoreDB/DataStructures/Table.CRUD.cs index 9fed2d10..dd36bdb2 100644 --- a/src/SharpCoreDB/DataStructures/Table.CRUD.cs +++ b/src/SharpCoreDB/DataStructures/Table.CRUD.cs @@ -2525,13 +2525,7 @@ this.storage is null || continue; } - foreach (var colIdx in repoints) - { - if (!indexedColumns.Contains(colIdx)) - { - indexedColumns.Add(colIdx); - } - } + indexedColumns.AddRange(repoints.Where(colIdx => !indexedColumns.Contains(colIdx))); } foreach (var colIdx in indexedColumns) @@ -3745,7 +3739,7 @@ this.storage is null || /// whole-file snapshot. Returns null when the position/length is not fully contained in the /// snapshot (caller falls back to the per-record read). /// - private byte[]? TrySlicePayloadFromFile(byte[] wholeFile, long position) + private static byte[]? TrySlicePayloadFromFile(byte[] wholeFile, long position) { if (position < 0 || position + 4 > wholeFile.Length) { @@ -3973,12 +3967,9 @@ this.storage is null || { // Transactional delete: buffer the physical offsets so the in-place marker is applied // at COMMIT (see DeleteRecordsCore — rollback discards the buffer). - foreach (var position in positions) + foreach (var position in positions.Where(static position => position >= 0)) { - if (position >= 0) - { - this.storage.BufferTombstoneForCommit(DataFile, position); - } + this.storage.BufferTombstoneForCommit(DataFile, position); } } else diff --git a/src/SharpCoreDB/Services/SqlParser.Core.cs b/src/SharpCoreDB/Services/SqlParser.Core.cs index ffbcca77..dca178bf 100644 --- a/src/SharpCoreDB/Services/SqlParser.Core.cs +++ b/src/SharpCoreDB/Services/SqlParser.Core.cs @@ -311,20 +311,19 @@ public List> ExecuteQuery(CachedQueryPlan plan, Dicti // B8: direct hash-index point lookup for `WHERE indexed_col = @param|literal`. This // skips building a WHERE string and re-parsing it inside SelectInternal — the single // biggest overhead difference vs the Direct API (FindByIndex) on point reads. - if (TryResolveWhereValue(simple, parameters, out var whereValue) && whereValue is not null) + if (TryResolveWhereValue(simple, parameters, out var whereValue) && + whereValue is not null && + table is DataStructures.Table concrete && + concrete.TrySelectIndexedPointLookup(simple.WhereColumn, whereValue, out var indexRows)) { - if (table is DataStructures.Table concrete && - concrete.TrySelectIndexedPointLookup(simple.WhereColumn, whereValue, out var indexRows)) - { - if (simple.Offset.HasValue && simple.Offset.Value > 0) - indexRows = [.. indexRows.Skip(simple.Offset.Value)]; + if (simple.Offset.HasValue && simple.Offset.Value > 0) + indexRows = [.. indexRows.Skip(simple.Offset.Value)]; - if (simple.Limit.HasValue && simple.Limit.Value > 0) - indexRows = [.. indexRows.Take(simple.Limit.Value)]; + if (simple.Limit.HasValue && simple.Limit.Value > 0) + indexRows = [.. indexRows.Take(simple.Limit.Value)]; - results = concrete.DeduplicateByPrimaryKey(indexRows); - return true; - } + results = concrete.DeduplicateByPrimaryKey(indexRows); + return true; } // Fallback: build the WHERE string exactly like the legacy binder and let the table