Skip to main content

Create Index

Create database indexes to improve query performance on your Fynd Boltic Database. Indexes provide fast access paths to data, improving SELECT query performance, sorting, and filtering operations.

Method Signature​

addIndex(
tableName: string,
request: AddIndexRequest
): Promise<BolticSuccessResponse<AddIndexResponse> | BolticErrorResponse>

Parameters​

ParameterTypeRequiredDescription
tableNamestring✅Name of the table to create an index on
requestAddIndexRequest✅Index creation configuration with field names and index type

AddIndexRequest​

interface AddIndexRequest {
field_names: string[]; // Columns to include in the index
method: "btree" | "hash" | "spgist" | "gin" | "brin"; // Index type
}
PropertyTypeRequiredDescription
field_namesstring[]✅Array of column names to include in the index
methodstring✅Index type (btree, hash, gin, brin, or spgist)
tip

In composite indexes, column order matters. Filters and sorts are most effective when they follow the same left-to-right order as the index definition.

Index Methods​

Choose the index method based on your query patterns:

  • btree: Best for equality and range queries (=, <, >, BETWEEN)
  • hash: Best for exact equality matches only (=)
  • gin: Best for multi-valued data (e.g., dropdown multi-select) and full-text search
  • brin: Best for large tables with naturally ordered data
  • spgist: Best for specialized data types (geometric, network addresses)

Response​

interface AddIndexResponse {
data: object;
message: str;
}

Examples​

Basic Index Creation​

import { createClient } from "@boltic/sdk";

const client = createClient("your-api-key");

// Create a B-tree index on email field
const { data: index, error } = await client.indexes.addIndex("users", {
field_names: ["email"],
method: "btree",
});

if (error) {
console.error("Failed to create index:", error.message);
} else {
console.log("Index created:", index.index_name);
}

Composite Indexes​

// Multi-column index for complex queries
const compositeIndex = await client.indexes.addIndex("events", {
field_names: ["user_id", "event_type", "created_at"],
method: "btree",
});

Chained Access Method​

// Using chained access pattern
const { data: index } = await client
.from("users")
.indexes()
.addIndex({
field_names: ["email"],
method: "btree",
});