Skip to main content

BTreeIndex

This class represents a B-tree index for PostgreSQL databases, providing a standard tree-based data structure for efficient data retrieval. It supports specialized configuration options such as fillfactor to control page packing and deduplicate_items to manage index storage efficiency. The class integrates with the database backend to generate the appropriate SQL for index creation and maintenance.

Attributes

AttributeTypeDescription
suffixstring = btreeThe storage engine type identifier used in the SQL command to create the index.
fillfactorintegerThe percentage of each index page that will be filled during index creation to allow for future growth.
deduplicate_itemsbooleanA boolean flag that enables or disables B-tree duplicate suppression to reduce the size of the index.

Constructor

Signature

def BTreeIndex(
*expressions: any,
fillfactor: int = None,
deduplicate_items: boolean,
**kwargs: any
)

Parameters

NameTypeDescription
*expressionsanyPositional arguments representing the expressions or fields to be indexed.
fillfactorint = NoneThe fillfactor for the index, which determines the percentage of space on each index-leaf page that will be filled with data.
deduplicate_itemsbooleanA boolean indicating whether to enable B-tree deduplication for the index. (PostgreSQL 13+).
**kwargsanyAdditional keyword arguments passed to the parent PostgresIndex class.

Methods


deconstruct()

@classmethod
def deconstruct() - > tuple

Returns a 3-tuple containing the import path, positional arguments, and keyword arguments required to recreate the BTreeIndex instance.

Returns

TypeDescription
tupleA tuple of (path, args, kwargs) used for serializing the index during migrations.

get_with_params()

@classmethod
def get_with_params() - > list

Generates a list of storage parameter strings specifically for B-tree indexes, such as fillfactor and deduplicate_items settings.

Returns

TypeDescription
listA list of SQL-formatted strings representing the WITH clause parameters for the index creation.