1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309
|
.. -*- rst -*-
.. highlightlang:: none
.. groonga-command
.. database: commands_table_remove
``table_remove``
================
Summary
-------
``table_remove`` removes a table and its columns. If there are one or
more indexes against key of the table and its columns, they are also
removed.
.. versionadded:: 6.0.1
You can also remove tables and columns that reference the target
table by using ``dependent`` parameter.
Syntax
------
This command takes two parameters::
table_remove name
[dependent=no]
.. _table-remove-usage:
Usage
-----
You just specify table name that you want to remove. ``table_remove``
removes the table and its columns. If the table and its columns are
indexed, all index columns for the table and its columns are also
removed.
This section describes about the followings:
* Basic usage
* Unremovable cases
* Removes a table with tables and columns that reference the target table
* Decreases used resources
.. _table-remove-basic-usage:
Basic usage
^^^^^^^^^^^
Let's think about the following case:
* There is one table ``Entries``.
* ``Entries`` table has some columns.
* ``Entries`` table's key is indexed.
* A column of ``Entries`` is indexed.
Here are commands that create ``Entries`` table:
.. groonga-command
.. include:: ../../example/reference/commands/table_remove/basic_usage_create_entries_table.log
.. table_create Entries TABLE_HASH_KEY UInt32
.. column_create Entries title COLUMN_SCALAR ShortText
.. column_create Entries content COLUMN_SCALAR Text
Here are commands that create an index for ``Entries`` table's key:
.. groonga-command
.. include:: ../../example/reference/commands/table_remove/basic_usage_create_index_for_entries_table.log
.. table_create EntryKeys TABLE_HASH_KEY UInt32
.. column_create EntryKeys key_index COLUMN_INDEX Entries _key
Here are commands that create an index for ``Entries`` table's column:
.. groonga-command
.. include:: ../../example/reference/commands/table_remove/basic_usage_create_index_for_entries_table_column.log
.. table_create Terms TABLE_PAT_KEY ShortText \
.. --default_tokenizer TokenBigram \
.. --normalizer NormalizerAuto
.. column_create Terms content_index COLUMN_INDEX Entries content
Let's confirm the current schema before running ``table_remove``:
.. groonga-command
.. include:: ../../example/reference/commands/table_remove/basic_usage_dump_before_table_remove.log
.. dump
If you remove ``Entries`` table, the following tables and columns are
removed:
* ``Entries``
* ``Entries.title``
* ``Entries.context``
* ``EntryKeys.key_index``
* ``Terms.content_index``
The following tables (lexicons) aren't removed:
* ``EntryKeys``
* ``Terms``
Let's run ``table_remove``:
.. groonga-command
.. include:: ../../example/reference/commands/table_remove/basic_usage_table_remove.log
.. table_remove Entries
Here is schema after ``table_remove``. Only ``EntryKeys`` and
``Terms`` exist:
.. groonga-command
.. include:: ../../example/reference/commands/table_remove/basic_usage_dump_after_table_remove.log
.. dump
.. _table-remove-unremovable-cases:
Unremovable cases
^^^^^^^^^^^^^^^^^
There are some unremovable cases:
* One or more tables use the table as key type.
* One or more columns use the table as value type.
Both cases blocks dangling references. If the table is referenced as
type and the table is removed, tables and columns that refer the table
are broken.
If the target table satisfies one of them, ``table_remove`` is
failed. The target table and its columns aren't removed.
Here is an example for the table is used as key type case.
The following commands create a table to be removed and a table that
uses the table to be removed as key type:
.. groonga-command
.. include:: ../../example/reference/commands/table_remove/unremovable_cases_key_type_create.log
.. table_create ReferencedByTable TABLE_HASH_KEY ShortText
.. table_create ReferenceTable TABLE_HASH_KEY ReferencedByTable
``table_remove`` against ``ReferencedByTable`` is failed:
.. groonga-command
.. include:: ../../example/reference/commands/table_remove/unremovable_cases_key_type_remove_fail.log
.. table_remove ReferencedByTable
You need to remove ``ReferenceTable`` before you remove
``ReferencedByTable``:
.. groonga-command
.. include:: ../../example/reference/commands/table_remove/unremovable_cases_key_type_remove_success.log
.. table_remove ReferenceTable
.. table_remove ReferencedByTable
Here is an example for the table is used as value type case.
The following commands create a table to be removed and a column that
uses the table to be removed as value type:
.. groonga-command
.. include:: ../../example/reference/commands/table_remove/unremovable_cases_value_type_create.log
.. table_create ReferencedByColumn TABLE_HASH_KEY ShortText
.. table_create Table TABLE_NO_KEY
.. column_create Table reference_column COLUMN_SCALAR ReferencedByColumn
``table_remove`` against ``ReferencedByColumn`` is failed:
.. groonga-command
.. include:: ../../example/reference/commands/table_remove/unremovable_cases_value_type_remove_fail.log
.. table_remove ReferencedByColumn
You need to remove ``Table.reference_column`` before you remove
``ReferencedByColumn``:
.. groonga-command
.. include:: ../../example/reference/commands/table_remove/unremovable_cases_value_type_remove_success.log
.. column_remove Table reference_column
.. table_remove ReferencedByColumn
.. _table-remove-remove-dependents:
Removes a table with tables and columns that reference the target table
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. versionadded:: 6.0.1
If you understand what you'll do, you can also remove tables and
columns that reference the target table with one ``table_remove``
command by using ``--dependent yes`` parameter.
``ReferencedTable`` in the following schema is referenced from a table
and a column:
.. groonga-command
.. include:: ../../example/reference/commands/table_remove/remove_dependents_schema.log
.. table_create ReferencedTable TABLE_HASH_KEY ShortText
.. table_create Table1 TABLE_HASH_KEY ReferencedTable
.. table_create Table2 TABLE_NO_KEY
.. column_create Table2 reference_column COLUMN_SCALAR ReferencedTable
You can't remove ``ReferencedTable`` by default:
.. groonga-command
.. include:: ../../example/reference/commands/table_remove/remove_dependents_default.log
.. table_remove ReferencedTable
You can remove ``ReferencedTable``, ``Table1`` and
``Table2.reference_column`` by using ``--dependent yes``
parameter. ``Table1`` and ``Table2.reference_column`` reference
``ReferencedTable``:
.. groonga-command
.. include:: ../../example/reference/commands/table_remove/remove_dependents_yes.log
.. table_remove ReferencedTable --dependent yes
.. _table-remove-decreases-used-resources:
Decreases used resources
^^^^^^^^^^^^^^^^^^^^^^^^
``table_remove`` opens all tables and columns in database to check
:ref:`table-remove-unremovable-cases`.
If you have many tables and columns, ``table_remove`` may use many
resources. There is a workaround to avoid the case.
``table_remove`` closes temporary opened tables and columns for
checking when the max number of threads is ``1``.
You can confirm and change the current max number of threads by
:doc:`thread_limit`.
.. groonga-command
.. thread_limit 4
The feature is used in the following case:
.. groonga-command
.. include:: ../../example/reference/commands/table_remove/decreases_used_resources_close_temporary_opened_objects.log
.. table_create Entries TABLE_NO_KEY
.. thread_limit 1
.. table_remove Entries
The feature isn't used in the following case:
.. groonga-command
.. include:: ../../example/reference/commands/table_remove/decreases_used_resources_close_temporary_opened_objects.log
.. table_create Entries TABLE_NO_KEY
.. thread_limit 2
.. table_remove Entries
Parameters
----------
This section describes all parameters.
Required parameters
^^^^^^^^^^^^^^^^^^^
There is only one required parameter.
.. _table-remove-name:
``name``
""""""""
Specifies the table name to be removed.
See :ref:`table-remove-usage` how to use this parameter.
Optional parameters
^^^^^^^^^^^^^^^^^^^
There is only one optional parameter.
.. _table-remove-dependent:
``dependent``
"""""""""""""
.. versionadded:: 6.0.1
Specifies whether tables and columns that reference the target table
are also removed or not.
If this value is ``yes``, tables and columns that reference the target
table are also removed. Otherwise, they aren't removed and an error is
returned.
In other words, if there are any tables and columns that reference the
target table, the target table isn't removed by default.
You should use this parameter carefully. This is a danger parameter.
See :ref:`table-remove-remove-dependents` how to use this parameter.
Return value
------------
The command returns ``true`` as body on success such as::
[HEADER, true]
If the command fails, error details are in ``HEADER``.
See :doc:`/reference/command/output_format` for ``HEADER``.
|