インデックス

□未翻訳

□翻訳中

■翻訳完了(細田謙二)

■レビュー(Omi Chiba)

インデックス

現在、DALのAPIはテーブルにインデックスを作成するコマンドを提供していませんが、これはexecutesqlコマンドによって行うことができます。その理由は、既存のインデックスではマイグレーションが複雑になり、それを明示的に扱ったほうが良いからです。インデックスは、クエリで頻繁に使用されているフィールドに対して必要になります。

Currently the DAL API does not provide a command to create indexes on tables, but this can be done using the executesql command. This is because the existence of indexes can make migrations complex, and it is better to deal with them explicitly. Indexes may be needed for those fields that are used in recurrent queries.

次に示すのは、SQLiteにおいてSQLを使用してインデックスを作成する例です:

Here is an example of how to create an index using SQL in SQLite:

1.

2.

3.

>>> db = DAL('sqlite://storage.db')

>>> db.define_table('person', Field('name'))

>>> db.executesql('CREATE INDEX IF NOT EXISTS myidx ON person (name);')

他のデータベースの方言は非常に良く似た構文を持っていますが、オプション的な"IF NOT EXISTS"宣言をサポートしていないことがあります。

Other database dialects have very similar syntaxes but may not support the optional "IF NOT EXISTS" directive.