7.3.55. table_remove
¶
7.3.55.1. 概要¶
table_remove
はテーブルとそのカラムを削除します。もし、テーブルのキーあるいはそのテーブルのカラムにインデックスが張ってある場合はそれらも削除されます。
7.3.55.3. 使い方¶
削除したいテーブルの名前を指定するだけです。 table_remove
は指定されたテーブルとそのテーブルのカラムを削除します。もし、テーブルとそのテーブルのカラムにインデックスが張ってある場合は、張ってあるすべてのインデックスも削除します。
このセクションでは次のことについて説明します。
基本的な使い方
削除できないケース
利用リソースの削減
7.3.55.3.1. 基本的な使い方¶
次のケースを考えてみましょう。
Entries
というテーブルがあります。
Entries
テーブルにはいくつかカラムがあります。
Entries
テーブルのキーにはインデックスが張ってあります。
Entries
のあるカラムにはインデックスが張ってあります。
以下は Entries
テーブルを作成するコマンドです。
実行例:
table_create Entries TABLE_HASH_KEY UInt32
# [[0, 1337566253.89858, 0.000355720520019531], true]
column_create Entries title COLUMN_SCALAR ShortText
# [[0, 1337566253.89858, 0.000355720520019531], true]
column_create Entries content COLUMN_SCALAR Text
# [[0, 1337566253.89858, 0.000355720520019531], true]
以下は Entries
テーブルのキーにインデックスを張るコマンドです。
実行例:
table_create EntryKeys TABLE_HASH_KEY UInt32
# [[0, 1337566253.89858, 0.000355720520019531], true]
column_create EntryKeys key_index COLUMN_INDEX Entries _key
# [[0, 1337566253.89858, 0.000355720520019531], true]
以下は Entries
テーブルのカラムにインデックスを張るコマンドです。
実行例:
table_create Terms TABLE_PAT_KEY ShortText \
--default_tokenizer TokenBigram \
--normalizer NormalizerAuto
# [[0, 1337566253.89858, 0.000355720520019531], true]
column_create Terms content_index COLUMN_INDEX Entries content
# [[0, 1337566253.89858, 0.000355720520019531], true]
table_remove
を実行する前に現在のスキーマを確認しましょう。
実行例:
dump
# table_create Entries TABLE_HASH_KEY UInt32
# column_create Entries content COLUMN_SCALAR Text
# column_create Entries title COLUMN_SCALAR ShortText
#
# table_create EntryKeys TABLE_HASH_KEY UInt32
#
# table_create Terms TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram --normalizer NormalizerAuto
#
# column_create EntryKeys key_index COLUMN_INDEX Entries _key
# column_create Terms content_index COLUMN_INDEX Entries content
Entries
テーブルを削除すると、次のテーブルとカラムが削除されます。
Entries
Entries.title
Entries.context
EntryKeys.key_index
Terms.content_index
次のテーブル(語彙表)は削除されません。
EntryKeys
Terms
table_remove
を実行しましょう。
実行例:
table_remove Entries
# [[0, 1337566253.89858, 0.000355720520019531], true]
以下が table_remove
実行後のスキーマです。 EntryKeys
と Terms
だけが残っています。
実行例:
dump
# table_create EntryKeys TABLE_HASH_KEY UInt32
#
# table_create Terms TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram --normalizer NormalizerAuto
7.3.55.3.2. 削除できないケース¶
以下は削除できないケースです。
1つ以上のテーブルがこの削除対象のテーブルをキーの型として使っている。
1つ以上のカラムがこの削除対象のテーブルを値の型として使っている。
どちらのケースも参照先がなくなることを防ぎます。もし、削除対象のテーブルが型として参照されているままそのテーブルが削除されてしまうと、そのテーブルを参照しているテーブルとカラムは壊れてしまいます。
もし、削除対象のテーブルがどれかの条件を満たしたら table_remove
は失敗します。削除対象のテーブルも削除対象のテーブルのカラムも削除されません。
以下は削除対象のテーブルがキーの型に使われるケースの例です。
次のコマンドは削除対象のテーブルとそのテーブルをキーの型として使うテーブルを作成します。
実行例:
table_create ReferencedByTable TABLE_HASH_KEY ShortText
# [[0, 1337566253.89858, 0.000355720520019531], true]
table_create ReferenceTable TABLE_HASH_KEY ReferencedByTable
# [[0, 1337566253.89858, 0.000355720520019531], true]
ReferencedByTable
に対する table_remove
は失敗します。
実行例:
table_remove ReferencedByTable
# [
# [
# -2,
# 1337566253.89858,
# 0.000355720520019531,
# "[table][remove] a table that references the table exists: <ReferenceTable._key> -> <ReferencedByTable>",
# [
# [
# "is_removable_table",
# "db.c",
# 8480
# ]
# ]
# ],
# false
# ]
ReferencedByTable
を削除する前に ReferenceTable
を削除する必要があります。
実行例:
table_remove ReferenceTable
# [[0, 1337566253.89858, 0.000355720520019531], true]
table_remove ReferencedByTable
# [[0, 1337566253.89858, 0.000355720520019531], true]
以下は削除対象のテーブルが値の型に使われるケースの例です。
次のコマンドは削除対象のテーブルとそのテーブルを値の型として使うカラムを作成します。
実行例:
table_create ReferencedByColumn TABLE_HASH_KEY ShortText
# [[0, 1337566253.89858, 0.000355720520019531], true]
table_create Table TABLE_NO_KEY
# [[0, 1337566253.89858, 0.000355720520019531], true]
column_create Table reference_column COLUMN_SCALAR ReferencedByColumn
# [[0, 1337566253.89858, 0.000355720520019531], true]
ReferencedByColumn
に対する table_remove
は失敗します。
実行例:
table_remove ReferencedByColumn
# [
# [
# -2,
# 1337566253.89858,
# 0.000355720520019531,
# "[table][remove] a column that references the table exists: <Table.reference_column> -> <ReferencedByColumn>",
# [
# [
# "is_removable_table",
# "db.c",
# 8500
# ]
# ]
# ],
# false
# ]
ReferencedByColumn
を削除する前に Table.reference_column
を削除する必要があります。
実行例:
column_remove Table reference_column
# [[0, 1337566253.89858, 0.000355720520019531], true]
table_remove ReferencedByColumn
# [[0, 1337566253.89858, 0.000355720520019531], true]
7.3.55.3.3. 利用リソースの削減¶
table_remove
は 削除できないケース のチェックをするためにデータベース内のすべてのテーブルとカラムを開きます。
もし、大量のテーブルとカラムがある場合、 table_remove
はたくさんのリソースを使うかもしれません。このケース用の回避策があります。
table_remove
は最大スレッド数が 1
のときはチェック用に一時的に開いたテーブルとカラムを閉じます。
thread_limit を使うと現在の最大スレッド数を確認・変更できます。
この機能は次のケースでは使われます。
実行例:
table_create Entries TABLE_NO_KEY
# [[0, 1337566253.89858, 0.000355720520019531], true]
thread_limit 2
# [[0, 1337566253.89858, 0.000355720520019531], 1]
table_remove Entries
# [[0, 1337566253.89858, 0.000355720520019531], true]
この機能は次のケースでは使われません。
実行例:
table_create Entries TABLE_NO_KEY
# [[0, 1337566253.89858, 0.000355720520019531], true]
thread_limit 2
# [[0, 1337566253.89858, 0.000355720520019531], 1]
table_remove Entries
# [[0, 1337566253.89858, 0.000355720520019531], true]
7.3.55.4. 引数¶
このセクションではすべての引数について説明します。