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
| Attribute | Type | Description |
|---|---|---|
| suffix | string = btree | The storage engine type identifier used in the SQL command to create the index. |
| fillfactor | integer | The percentage of each index page that will be filled during index creation to allow for future growth. |
| deduplicate_items | boolean | A 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
| Name | Type | Description |
|---|---|---|
| *expressions | any | Positional arguments representing the expressions or fields to be indexed. |
| fillfactor | int = None | The fillfactor for the index, which determines the percentage of space on each index-leaf page that will be filled with data. |
| deduplicate_items | boolean | A boolean indicating whether to enable B-tree deduplication for the index. (PostgreSQL 13+). |
| **kwargs | any | Additional 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
| Type | Description |
|---|---|
tuple | A 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
| Type | Description |
|---|---|
list | A list of SQL-formatted strings representing the WITH clause parameters for the index creation. |