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