Skip to main content

BrinIndex

This class represents a Block Range Index (BRIN) for PostgreSQL databases, designed for handling very large tables where data has a natural correlation with physical storage order. It allows for the configuration of index-specific parameters such as autosummarization and the number of pages per range. The class provides methods to manage these parameters and integrate them into the database's index creation process.

Attributes

AttributeTypeDescription
suffixstring = "brin"The storage engine suffix used for naming the index on the database.
autosummarizebooleanDefines whether the index should automatically summarize a range when a new page is filled.
pages_per_rangeintegerThe number of table pages that make up one block range for the index, which must be a positive integer.

Constructor

Signature

def BrinIndex(
*expressions: any,
autosummarize: boolean = None,
pages_per_range: integer = None,
**kwargs: any
)

Parameters

NameTypeDescription
*expressionsanyPositional arguments representing the expressions or columns to be indexed.
autosummarizeboolean = NoneDefines whether the index should be automatically summarized when a new page range is filled.
pages_per_rangeinteger = NoneThe number of table pages that make up one block range in the index; must be a positive integer.
**kwargsanyAdditional keyword arguments passed to the parent PostgresIndex class.

Methods


deconstruct()

@classmethod
def deconstruct() - > tuple

Returns a 3-tuple containing the path to the class, positional arguments, and keyword arguments including BRIN-specific settings for serialization.

Returns

TypeDescription
tupleA tuple of (path, args, kwargs) used to reconstruct the index instance during migrations.

get_with_params()

@classmethod
def get_with_params() - > list

Generates a list of SQL parameter strings for the BRIN index, such as autosummarize and pages_per_range settings.

Returns

TypeDescription
listA list of strings representing the WITH clause parameters for the PostgreSQL CREATE INDEX statement.