Indexes

The index module defines two classes, Index and IndexDict, derived from DbSchemaObject and DbObjectDict, respectively.

Index

Class Index is derived from DbSchemaObject and represents an index on a database table, other than a primary key or unique constraint index. Its keylist attributes are the schema name, the table name and the index name.

An Index has the following attributes: access_method, unique, and keycols.

class pyrseas.dbobject.index.Index(name, schema, table, description, unique=False, access_method='btree', keys=[], predicate=None, tablespace=None, cluster=False, keyexprs=None, defn=None, oid=None)

A physical index definition, other than a primary key or unique constraint index.

An index is identified by its schema name and index name. However, at this time, Pyrseas uses the triple schema-table-index names as the identifier. TODO: This should be fixed in this or a subsequent release.

static Index.from_map(name, table, inobj)

Initialize an index instance from a YAML map

Parameters:
  • name – index name
  • table – map of table
  • inobj – YAML map of the index
Returns:

Index instance

Index.key_expressions()

Return comma-separated list of key column names and qualifiers

Returns:string
Index.to_map(db)

Convert an index definition to a YAML-suitable format

Returns:dictionary
Index.create(obj, *args, **kwargs)

Return a SQL statement to CREATE the index

Returns:SQL statements
Index.alter(inindex)

Generate SQL to transform an existing index

Parameters:inindex – a YAML map defining the new index
Returns:list of SQL statements

Compares the index to an input index and generates SQL statements to transform it into the one represented by the input.

Index.drop()

Generate SQL to drop the current index

Returns:list of SQL statements

Index Dictionary

Class IndexDict is derived from DbObjectDict and represents the collection of indexes in a database.

class pyrseas.dbobject.index.IndexDict(dbconn=None)

The collection of indexes on tables in a database

IndexDict.from_map(table, inindexes)

Initialize the dictionary of indexes by converting the input map

Parameters:
  • table – table owning the indexes
  • inindexes – YAML map defining the indexes