Skip to main content

HashIndex

This class provides a PostgreSQL-specific index implementation that uses a hash-based indexing strategy. It allows for the configuration of a fillfactor parameter to optimize the storage and performance of the index. The class integrates with the database schema generation process by providing methods to deconstruct the index state and generate the necessary SQL parameters.

Attributes

AttributeTypeDescription
suffixstring = hashThe storage engine suffix used to identify the index type in generated SQL, set to "hash".

Constructor

Signature

def HashIndex(
*expressions: any,
fillfactor: int = None,
**kwargs: any
)

Parameters

NameTypeDescription
*expressionsanyPositional arguments representing the expressions to be indexed.
fillfactorint = NoneA percentage value between 10 and 100 that determines how full the index pages will be packed.
**kwargsanyAdditional keyword arguments passed to the parent PostgresIndex class.

Signature

def HashIndex(
*expressions: any,
fillfactor: integer,
**kwargs: any
) - > null

Parameters

NameTypeDescription
*expressionsanyPositional arguments representing the fields or expressions to be indexed
fillfactorintegerThe fillfactor percentage (10-100) that determines how packed the index pages will be during creation
**kwargsanyAdditional keyword arguments passed to the base PostgresIndex class

Methods


deconstruct()

@classmethod
def deconstruct() - > tuple

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

Returns

TypeDescription
tupleA tuple of (path, args, kwargs) used by Django's migration framework to reconstruct the index instance

get_with_params()

@classmethod
def get_with_params() - > list

Builds a list of storage parameter strings to be used in the SQL 'WITH' clause of the CREATE INDEX statement.

Returns

TypeDescription
listA list of strings containing formatted SQL parameters like 'fillfactor = 70'