Table of Contents

Class Index

Namespace
YndigoBlue.Velocity.Model
Assembly
YndigoBlue.Velocity.dll

Represents a database index that improves query performance on table columns.

public class Index : IEquatable<Index>, IComparable<Index>
Inheritance
Index
Implements

Examples

Single-column index:

Table usersTable = schema.CreateTable("users");
usersTable.AddColumn("id", DataType.Integer);
usersTable.AddColumn("email", DataType.VarChar, size: 255);
usersTable.AddColumn("username", DataType.VarChar, size: 100);

// Create index on email column
Index emailIndex = usersTable.AddIndex("idx_email", "email");

// SQL: CREATE INDEX idx_email ON users (email ASC)

Composite index (multiple columns):

Table ordersTable = schema.CreateTable("orders");
ordersTable.AddColumn("id", DataType.Integer);
ordersTable.AddColumn("user_id", DataType.Integer);
ordersTable.AddColumn("status", DataType.VarChar, size: 50);
ordersTable.AddColumn("created_at", DataType.DateTime);

// Create composite index on user_id and status
Index userStatusIndex = ordersTable.AddIndex("idx_user_status", "user_id");
userStatusIndex.AddIndexColumn("status", IndexOrderType.Ascending);

// SQL: CREATE INDEX idx_user_status ON orders (user_id ASC, status ASC)

Index with descending order:

// Create index on created_at in descending order (newest first)
Index dateIndex = ordersTable.AddIndex(
    "idx_created_desc",
    "created_at",
    IndexOrderType.Descending
);

// SQL: CREATE INDEX idx_created_desc ON orders (created_at DESC)

Composite index with mixed ordering:

// Index for sorting by status ASC, then created_at DESC
Index sortIndex = ordersTable.AddIndex("idx_status_date", "status");
sortIndex.AddIndexColumn("created_at", IndexOrderType.Descending);

// This index is optimized for queries like:
// SELECT * FROM orders ORDER BY status ASC, created_at DESC

// SQL: CREATE INDEX idx_status_date ON orders (status ASC, created_at DESC)

Remarks

Indexes are database structures that speed up data retrieval operations on tables. They work like a book's index - allowing the database to find rows quickly without scanning the entire table.

Velocity supports:

  • Single-column indexes - Index on one column
  • Composite indexes - Index spanning multiple columns
  • ASC/DESC ordering - Columns can be indexed in ascending or descending order

Indexes are created on tables using AddIndex(Index). The database creates the index when the schema is built with Engine.Manager.BuildSchema(Schema).

Properties

IndexColumns

Gets the collection of columns included in this index along with their sort order.

Name

Gets the name of the index.

SchemaName

Gets the name of the schema containing this index's table.

SchemaUpdate

Gets or sets whether this index was created during a schema update operation.

TableName

Gets the name of the table this index belongs to.

Methods

AddIndexColumn(string, IndexOrderType)

Adds a column to this index with the specified sort order.

CompareTo(Index)

Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.

Equals(Index)

Indicates whether the current object is equal to another object of the same type.

ToString()

Returns a string that represents the current object.