Path: redb/redb.Core/RedbServiceBase.Indexes.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/RedbServiceBase.Indexes.cs
----
using Microsoft.Extensions.Logging;
using redb.Core.Models;
namespace redb.Core;
// The index check and the repair (CheckBaseIndexesAsync, RepairBaseIndexesAsync, CheckBaseIndexesOnStart). The expected
// indexes are a table per provider, generated from a fresh database of this build and pinned by a test against one; the
// actual ones come from the catalog in one read. Start-up only reports: an operator may have dropped an index on purpose.
public abstract partial class RedbServiceBase
{
///
/// Whether this service moved the database to the module version of this build (created the schema, or applied the
/// module bundle), and from which version: null for a database it created. A Pro module builds its indexes at such a
/// step only, and only when the step comes from below the version that brought them; at any other start a missing
/// one is reported by the index check, not built.
///
protected (bool Applied, string? From) ModuleStep { get; private set; }
///
/// Whether the module step of this start () is the one that brings a set of module indexes
/// introduced at : a database created now, or one coming from a module older than that.
///
protected bool ModuleStepBrings(string since)
=> ModuleStep.Applied && (string.IsNullOrEmpty(ModuleStep.From) || Data.ModuleCompatibility.IsNewer(since, ModuleStep.From));
///
/// The indexes a fresh database of this build has, for the provider (and with Pro, the module indexes in use). Empty
/// where the provider has no table: the check then reports nothing.
///
protected virtual IReadOnlyList ExpectedIndexes => Array.Empty();
///
/// Every index of the redb tables as the catalog has it: name, table, uniqueness, key and included columns, and
/// whether it is valid. Read through .
///
protected virtual async Task> ReadIndexShapesAsync(CancellationToken cancellationToken)
{
var sql = SqlDialect.Schema_SelectIndexShapes();
if (string.IsNullOrEmpty(sql))
return Array.Empty();
var rows = await _context.QueryAsync(sql, Array.Empty