Path: redb/redb.Core/Models/UniqueRecomputeReport.cs
Snapshot: redb, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb
Page: https://redbase.app/src/dev-2026-12-06/redb/redb.Core/Models/UniqueRecomputeReport.cs
----
using System.Collections.Generic;
using System.Linq;
namespace redb.Core.Models
{
///
/// What a recomputation of _values._unique for one key structure found. Produced when a
/// [RedbUnique] attribute appears on a populated structure, when the structure's encoder
/// version is behind UniqueKeyEncoder.Version, when rows are found with a value but no key
/// (a SQL-side writer touched them), and on an explicit RecomputeUniqueAsync.
///
///
/// Duplicates are reported, not thrown: the first row of each duplicate group (lowest value id)
/// keeps the key, the others stay with _unique IS NULL — outside the index, visible here,
/// and to a query WHERE _id_structure = … AND _unique IS NULL AND <column> IS NOT NULL.
/// Uniqueness is enforced for every row that has a key from this point on; the losers are the
/// application's to resolve.
///
///
public sealed class UniqueRecomputeReport
{
public long SchemeId { get; init; }
public string SchemeName { get; init; } = string.Empty;
public long StructureId { get; init; }
public string PropertyName { get; init; } = string.Empty;
/// Root scalar rows of the structure that were examined.
public int TotalRows { get; init; }
/// Rows that received a key (rows with a NULL value get none and are not counted).
public int HashedRows { get; init; }
/// Groups of rows sharing one key; each group's first id kept the key.
public IReadOnlyList Duplicates { get; init; } = [];
public bool HasDuplicates => Duplicates.Count > 0;
/// Rows left without a key because another row already holds it.
public int LosingRows => Duplicates.Sum(g => g.ValueIds.Count - 1);
}
/// One set of rows whose values canonicalise to the same key.
public sealed class UniqueDuplicateGroup
{
/// The colliding key.
public System.Guid Key { get; init; }
/// _values._id of every row in the group, lowest first; the first kept the key.
public IReadOnlyList ValueIds { get; init; } = [];
/// _objects._id for the same rows, in the same order.
public IReadOnlyList ObjectIds { get; init; } = [];
}
}