Metadata Indexes #
The performance of specific queries that include document and event metadata columns Marten provides some predefined indexes you may optionally enable
Last Modified #
Should you be using the ModifiedSince(DateTimeOffset)
or ModifiedBefore(DateTimeOffset)
you can ask Marten to create an index on the document's mt_last_modified
metadata column either using IndexedLastModifiedAttribute
:
cs
[IndexedLastModified]
public class Customer
{
}
Or by using the fluent interface:
cs
DocumentStore.For(_ =>
{
_.Schema.For<User>().IndexLastModified();
});
Soft Delete #
If using the soft deletes functionality you can ask Marten to create a partial index on the deleted documents either using SoftDeletedAttribute
:
cs
[SoftDeleted(Indexed = true)]
public class IndexedSoftDeletedDoc
{
public Guid Id;
}
Or by using the fluent interface:
cs
DocumentStore.For(_ =>
{
_.Schema.For<User>().SoftDeletedWithIndex();
});
This will help Postgres answer queries using IsDeleted()
, DeletedSince(DateTimeOffset)
and DeletedBefore(DateTimeOffset)
much more efficiently, Postgres will only index documents when they are deleted, mt_deleted = true
, which also means that the index does not need to be updated for any insert or update where mt_deleted = false