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
| Attribute | Type | Description |
|---|---|---|
| suffix | string = hash | The 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
| Name | Type | Description |
|---|---|---|
| *expressions | any | Positional arguments representing the expressions to be indexed. |
| fillfactor | int = None | A percentage value between 10 and 100 that determines how full the index pages will be packed. |
| **kwargs | any | Additional keyword arguments passed to the parent PostgresIndex class. |
Signature
def HashIndex(
*expressions: any,
fillfactor: integer,
**kwargs: any
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| *expressions | any | Positional arguments representing the fields or expressions to be indexed |
| fillfactor | integer | The fillfactor percentage (10-100) that determines how packed the index pages will be during creation |
| **kwargs | any | Additional 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
| Type | Description |
|---|---|
tuple | A 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
| Type | Description |
|---|---|
list | A list of strings containing formatted SQL parameters like 'fillfactor = 70' |