data_index
data_index gets the DataIndex for the given key columns on a table. It can also create a DataIndex when none is present. A DataIndex is an index that can make it faster for the engine to locate data by key. Some table operations have improved performance when a data index is present.
Note
When a new data index is created, it is not immediately computed. The index is computed when a table operation first uses it, or when you access its table property. This is an important detail for performance considerations.
Note
Which index an operation can use depends on its key columns. Joins and aggregations need an index whose key columns exactly match theirs. where can use an index whose key columns include the filtered columns. For example, an index on X and Y can speed up a filter on X. A sort can use an index on all of its sort columns, or a single-column index on the first sort column. See Data indexes.
Syntax
Parameters
| Parameter | Type | Description |
|---|---|---|
| table | Table | The table to index. |
| key_cols | List[str] | The names of the key column(s) to index. |
| create_if_absent optional | bool | If |
Returns
A DataIndex or None.
Examples
The following example demonstrates creating a data index on a table using a single key column.
The following example demonstrates creating a data index on a table using multiple key columns.
The following example sets create_if_absent to False, so the operation returns None since the index does not yet exist.