NullableIndex() function
Declares a pair of partial indices on a nullable column, one for the rows where it is null and one for the rows where it is not.
Signature:
export declare function NullableIndex(options: Partial<NullableColumnIndexOptions>): FunctionType;
Parameters
|
Parameter |
Type |
Description |
|---|---|---|
|
options |
Partial<NullableColumnIndexOptions> |
Returns:
A property decorator, when used as a factory.
Remarks
Two narrow indices instead of one wide one. Each covers only its half of the table, so WHERE "col" IS NULL and WHERE "col" IS NOT NULL each get an index sized to the rows they actually match — which is the point on a column where one of the two halves is much smaller than the other.
Usable bare or as a factory, exactly like ColumnIndex. The factory form used to build both halves from one options object that it mutated in place, and ColumnIndex stores that object by reference — so both declarations ended up pointing at the same object, both saying IS NOT NULL, and neither carrying a predicate at all. What you got was two identical non-partial indices. It now builds a fresh options object per half, keeps a predicate of your own by combining it with the null test, and suffixes a name of your own so the two halves cannot collide.
Example
@Table
export class Lead extends BaseModel<Lead> {
@NullableIndex
@Column(DataType.DATE)
public closedAt: Date;
@NullableIndex({ name: 'lead_assignee', concurrently: true })
@Column(DataType.BIGINT)
public assigneeId: number;
}