Debian Codegraph @

doc/source/reference/commands/logical_table_remove.rst

raw
1 .. -*- rst -*-
2
3 .. groonga-command
4 .. database: logical_table_remove
5
6 ``logical_table_remove``
7 ========================
8
9 Summary
10 -------
11
12 .. versionadded:: 5.0.5
13
14 ``logical_table_remove`` removes tables and their columns for the
15 specified logical table. If there are one or more indexes against key
16 of the tables and their columns, they are also removed.
17
18 If you specify the part of a shard, table of the shard isn't
19 removed. ``logical_table_remove`` just deletes records in the table.
20
21 For example, there are the following records in a table:
22
23 * Record1: ``2016-03-18 00:30:00``
24 * Record2: ``2016-03-18 01:00:00``
25 * Record3: ``2016-03-18 02:00:00``
26
27 ``logical_table_remove`` deletes "Record1" and "Record2" when you
28 specify range as between ``2016-03-18 00:00:00`` and ``2016-03-18
29 01:30:00``. ``logical_table_remove`` doesn't delete
30 "Record3". ``logical_table_remove`` doesn't remove the table.
31
32 .. versionadded:: 6.0.1
33
34 You can also remove tables and columns that reference the target
35 table and tables related with the target shard by using
36 ``dependent`` parameter.
37
38 .. versionadded:: 6.0.9
39
40 You can remove broken tables and columns as much as possible by
41 using ``force`` parameter.
42
43 Syntax
44 ------
45
46 This command takes many parameters.
47
48 The required parameters are ``logical_table`` and ``shard_key``::
49
50 logical_table_remove logical_table
51 shard_key
52 [min=null]
53 [min_border="include"]
54 [max=null]
55 [max_border="include"]
56 [dependent=no]
57 [force=no]
58
59 .. _logical-table-remove-usage:
60
61 Usage
62 -----
63
64 You specify logical table name and shard key what you want to remove.
65
66 This section describes about the followings:
67
68 * Basic usage
69 * Removes parts of a logical table
70 * Unremovable cases
71 * Removes with related tables
72 * Removes broken tables as much as possible
73 * Decreases used resources
74
75 .. _logical-table-remove-basic-usage:
76
77 Basic usage
78 ^^^^^^^^^^^
79
80 Register ``sharding`` plugin to use this command in advance.
81
82 .. groonga-command
83 .. include:: ../../example/reference/commands/logical_table_remove/usage_register.log
84 .. plugin_register sharding
85
86 You can remove all tables for the logical table by specifying only
87 ``logical_table`` and ``shard_key``.
88
89 Here are commands to create 2 shards:
90
91 .. groonga-command
92 .. include:: ../../example/reference/commands/logical_table_remove/basic_usage_create_shards.log
93 .. table_create Logs_20160318 TABLE_NO_KEY
94 .. column_create Logs_20160318 timestamp COLUMN_SCALAR Time
95 ..
96 .. table_create Logs_20160319 TABLE_NO_KEY
97 .. column_create Logs_20160319 timestamp COLUMN_SCALAR Time
98
99 You can confirm existing shards by :doc:`logical_shard_list`:
100
101 .. groonga-command
102 .. include:: ../../example/reference/commands/logical_table_remove/basic_usage_list_shards_before.log
103 .. logical_shard_list --logical_table Logs
104
105 You can remove all shards:
106
107 .. groonga-command
108 .. include:: ../../example/reference/commands/logical_table_remove/basic_usage_remove_all.log
109 .. logical_table_remove \
110 .. --logical_table Logs \
111 .. --shard_key timestamp
112
113 There are no shards after you remove all shards:
114
115 .. groonga-command
116 .. include:: ../../example/reference/commands/logical_table_remove/basic_usage_list_shards_after.log
117 .. logical_shard_list --logical_table Logs
118
119 .. _logical-table-remove-removes-parts:
120
121 Removes parts of a logical table
122 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
123
124 You can specify range of shards by the following parameters:
125
126 * ``min``
127 * ``min_border``
128 * ``max``
129 * ``max_border``
130
131 See the following documents of :doc:`logical_select` for each
132 parameter:
133
134 * :ref:`logical-select-min`
135 * :ref:`logical-select-min-border`
136 * :ref:`logical-select-max`
137 * :ref:`logical-select-max-border`
138
139 If the specified range doesn't cover all records in a shard, table for
140 the shard isn't removed. Target records in the table are only deleted.
141
142 If the specified range covers all records in a shard, table for the
143 shard is removed.
144
145 Here is a logical table to show the behavior. The logical table has two
146 shards:
147
148 .. groonga-command
149 .. include:: ../../example/reference/commands/logical_table_remove/remove_parts_create_shards.log
150 .. table_create Logs_20160318 TABLE_NO_KEY
151 .. column_create Logs_20160318 timestamp COLUMN_SCALAR Time
152 .. load --table Logs_20160318
153 .. [
154 .. {"timestamp": "2016-03-18 00:30:00"},
155 .. {"timestamp": "2016-03-18 01:00:00"},
156 .. {"timestamp": "2016-03-18 02:00:00"}
157 .. ]
158 ..
159 .. table_create Logs_20160319 TABLE_NO_KEY
160 .. column_create Logs_20160319 timestamp COLUMN_SCALAR Time
161 .. load --table Logs_20160319
162 .. [
163 .. {"timestamp": "2016-03-19 00:30:00"},
164 .. {"timestamp": "2016-03-19 01:00:00"}
165 .. ]
166
167 There are the following records in ``Logs_20160318`` table:
168
169 * Record1: ``"2016-03-18 00:30:00"``
170 * Record2: ``"2016-03-18 01:00:00"``
171 * Record3: ``"2016-03-18 02:00:00"``
172
173 There are the following records in ``Logs_20160319`` table:
174
175 * Record1: ``"2016-03-19 00:30:00"``
176 * Record2: ``"2016-03-19 01:00:00"``
177
178 The following range doesn't cover "Record1" in ``Logs_20160318`` table
179 but covers all records in ``Logs_20160319`` table:
180
181 .. list-table::
182 :header-rows: 1
183
184 * - Parameter
185 - Value
186 * - ``min``
187 - ``"2016-03-18 01:00:00"``
188 * - ``min_border``
189 - ``"include"``
190 * - ``max``
191 - ``"2016-03-19 01:30:00"``
192 * - ``max_border``
193 - ``"include"``
194
195 ``logical_table_remove`` with the range deletes "Record2" and
196 "Record3" in ``Logs_20160318`` table but doesn't remove
197 ``Logs_20160318`` table. Because there is "Record1" in
198 ``Logs_20160318`` table.
199
200 ``logical_table_remove`` with the range removes ``Logs_20160319``
201 table because the range covers all records in ``Logs_20160319`` table.
202
203 Here is an example to use ``logical_table_remove`` with the range:
204
205 .. groonga-command
206 .. include:: ../../example/reference/commands/logical_table_remove/remove_parts_remove.log
207 .. logical_table_remove \
208 .. --logical_table Logs \
209 .. --shard_key timestamp \
210 .. --min "2016-03-18 01:00:00" \
211 .. --min_border "include" \
212 .. --max "2016-03-19 01:30:00" \
213 .. --max_border "include"
214
215 :doc:`dump` shows that there is "Record1" in ``Logs_20160318`` table:
216
217 .. groonga-command
218 .. include:: ../../example/reference/commands/logical_table_remove/remove_parts_dump.log
219 .. dump
220
221 .. _logical-table-remove-unremovable-cases:
222
223 Unremovable cases
224 ^^^^^^^^^^^^^^^^^
225
226 There are some unremovable cases. See
227 :ref:`table-remove-unremovable-cases` for details. Because
228 ``logical_table_remove`` uses the same checks.
229
230 .. _logical-table-remove-removes-with-related-tables:
231
232 Removes with related tables
233 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
234
235 .. versionadded:: 6.0.1
236
237 If you understand what you'll do, you can also remove tables and
238 columns that depend on the target shard with one
239 ``logical_table_remove`` command by using ``--dependent yes``
240 parameter.
241
242 Here are conditions for dependent. If table or column satisfies one of
243 the conditions, the table or column depends on the target shard:
244
245 * Tables and columns that reference the target shard
246 * Tables for the shard (= The table has the same ``_YYYYMMDD``
247 postfix as the target shard and is referenced from the target
248 shard)
249
250 If there are one or more tables and columns that reference the target
251 shard, ``logical_table_remove`` is failed. It's for avoiding dangling
252 references.
253
254 ``Bookmarks.log_20160320`` column in the following is the column that
255 references the target shard:
256
257 .. groonga-command
258 .. include:: ../../example/reference/commands/logical_table_remove/remove_with_reference_create.log
259 .. table_create Logs_20160320 TABLE_NO_KEY
260 .. column_create Logs_20160320 timestamp COLUMN_SCALAR Time
261 ..
262 .. table_create Bookmarks TABLE_HASH_KEY ShortText
263 .. column_create Bookmarks log_20160320 COLUMN_SCALAR Logs_20160320
264
265 You can't remove ``Logs_20160320`` by ``logical_table_remove`` by
266 default:
267
268 .. groonga-command
269 .. include:: ../../example/reference/commands/logical_table_remove/remove_with_reference_default.log
270 .. logical_table_remove \
271 .. --logical_table Logs \
272 .. --shard_key timestamp
273
274 You can remove ``Logs_20160320`` by ``logical_table_remove`` with
275 ``--dependent yes`` parameter. ``Bookmarks.log_20160320`` is also
276 removed:
277
278 .. groonga-command
279 .. include:: ../../example/reference/commands/logical_table_remove/remove_with_reference_dependent.log
280 .. logical_table_remove \
281 .. --logical_table Logs \
282 .. --shard_key timestamp \
283 .. --dependent yes
284
285 :doc:`object_exist` shows that ``Logs_20160320`` table and
286 ``Bookmarks.log_20160320`` column are removed:
287
288 .. groonga-command
289 .. include:: ../../example/reference/commands/logical_table_remove/remove_with_reference_confirm.log
290 .. object_exist Logs_20160320
291 .. object_exist Bookmarks.log_20160320
292
293 If there is one or more tables for the target shard,
294 ``logical_table_remove`` with ``--dependent yes`` also removes
295 them. Tables that have the same ``_YYYYMMDD`` postfix as the target
296 shard are treated as tables for the target shard.
297
298 Here are two tables that have ``_20160320``
299 postfix. ``NotRelated_20160320`` table isn't used by ``Logs_20160320``
300 table. ``Users_20160320`` table is used by ``Logs_20160320``
301 table. ``Servers`` table exists and used by ``Logs_20160320`` table:
302
303 .. groonga-command
304 .. include:: ../../example/reference/commands/logical_table_remove/remove_with_for_shard_create.log
305 .. table_create NotRelated_20160320 TABLE_PAT_KEY ShortText
306 .. table_create Users_20160320 TABLE_PAT_KEY ShortText
307 .. table_create Servers TABLE_PAT_KEY ShortText
308 .. table_create Logs_20160320 TABLE_NO_KEY
309 .. column_create Logs_20160320 timestamp COLUMN_SCALAR Time
310 .. column_create Logs_20160320 user COLUMN_SCALAR Users_20160320
311 .. column_create Logs_20160320 server COLUMN_SCALAR Servers
312
313 ``logical_table_remove`` with ``--dependent yes`` parameter removes
314 only ``Logs_20160320`` table and ``Users_20160320`` table. Because
315 ``Users_20160320`` table has ``_20160320`` postfix and used by
316 ``Logs_20160320``. ``NotRelated_20160320`` table and ``Servers`` table
317 aren't removed. Because ``NotRelated_20160320`` table has
318 ``_20160320`` postfix but isn't used by ``Logs_20160320``. ``Servers``
319 table is used by ``Logs_20160320`` but doesn't have ``_20160320``
320 postfix:
321
322 .. groonga-command
323 .. include:: ../../example/reference/commands/logical_table_remove/remove_with_for_shard_remove.log
324 .. logical_table_remove \
325 .. --logical_table Logs \
326 .. --shard_key timestamp \
327 .. --dependent yes
328
329 You can confirm that ``Logs_20160320`` table and ``Users_20160320``
330 table are removed but ``NotRelated_20160320`` table and ``Servers``
331 table aren't removed:
332
333 .. groonga-command
334 .. include:: ../../example/reference/commands/logical_table_remove/remove_with_for_shard_configm.log
335 .. object_exist Logs_20160320
336 .. object_exist Users_20160320
337 .. object_exist NotRelated_20160320
338 .. object_exist Servers
339
340 .. _logical-table-remove-removes-broken-tables-as-much-as-possible:
341
342 Removes broken tables as much as possible
343 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
344
345 .. versionadded:: 6.0.9
346
347 If the target tables are broken, you can't remove them. But you can
348 remove them as much as possible by using ``force`` parameter.
349
350 If you specify ``--force yes``, they are removed as much as
351 possible. You can also use ``--dependent yes`` with ``--force yes``.
352
353 Here is a sample schema to show how ``--force yes`` behavior:
354
355 .. groonga-command
356 .. include:: ../../example/reference/commands/logical_table_remove/remove_broken_tables_create.log
357 .. table_create Logs_20160320 TABLE_NO_KEY
358 .. column_create Logs_20160320 timestamp COLUMN_SCALAR Time
359 ..
360 .. table_create Timestamps TABLE_PAT_KEY Time
361 .. column_create Timestamps logs_20160320_timestamp \
362 .. COLUMN_INDEX Logs_20160320 timestamp
363
364 You can't remove ``Logs_20160320`` when
365 ``Timestamps.logs_20160320_timestamp`` is broken:
366
367 .. groonga-command
368 .. thread_limit 1
369 .. database_unmap
370 .. .. ${DB_PATH}.0000109 is Timestamps.logs_20160320_timestamp.
371 .. .. You can confirm ID of Timestamps.logs_20160320_timestamp by object_list.
372 .. % echo > ${DB_PATH}.0000109
373
374 .. groonga-command
375 .. include:: ../../example/reference/commands/logical_table_remove/remove_broken_tables_remove.log
376 .. logical_table_remove \
377 .. --logical_table Logs \
378 .. --shard_key timestamp
379
380 You can remove ``Logs_20160320`` and its columns by using ``--force
381 yes`` parameter even when ``Timestamps.logs_20160320_timestamp`` is
382 broken:
383
384 .. groonga-command
385 .. include:: ../../example/reference/commands/logical_table_remove/remove_broken_tables_remove_force.log
386 .. logical_table_remove \
387 .. --logical_table Logs \
388 .. --shard_key timestamp \
389 .. --force yes
390
391 ``Logs_20160320``, its columns and
392 ``Timestamps.logs_20160320_timestamp`` are removed:
393
394 .. groonga-command
395 .. include:: ../../example/reference/commands/logical_table_remove/remove_broken_tables_index_column_exist.log
396 .. object_exist Logs_20160320
397 .. object_exist Logs_20160320.timestamp
398 .. object_exist Timestamps.logs_20160320_timestamp
399
400 ``--force yes`` parameter is a dangerous parameter. Normally, you
401 don't need to use it.
402
403 .. _logical-table-remove-decreases-used-resources:
404
405 Decreases used resources
406 ^^^^^^^^^^^^^^^^^^^^^^^^
407
408 You can decrease resources for this command. See
409 :ref:`table-remove-decreases-used-resources` for details. Because
410 ``logical_table_remove`` uses the same logic as :doc:`table_remove`.
411
412 Parameters
413 ----------
414
415 This section describes parameters of ``logical_table_remove``.
416
417 Required parameters
418 ^^^^^^^^^^^^^^^^^^^
419
420 There are required parameters.
421
422 .. _logical-table-remove-logical-table:
423
424 ``logical_table``
425 """""""""""""""""
426
427 Specifies logical table name. It means table name without
428 ``_YYYYMMDD`` postfix. If you use actual table such as
429 ``Logs_20150203``, ``Logs_20150203`` and so on, logical table name is
430 ``Logs``.
431
432 See also :ref:`logical-select-logical-table`.
433
434 .. _logical-table-remove-shard-key:
435
436 ``shard_key``
437 """""""""""""
438
439 Specifies column name which is treated as shared key.
440
441 See also :ref:`logical-select-shard-key`.
442
443 Optional parameters
444 ^^^^^^^^^^^^^^^^^^^
445
446 There are optional parameters.
447
448 .. _logical-table-remove-min:
449
450 ``min``
451 """""""
452
453 Specifies the minimum value of ``shard_key`` column.
454
455 See also :ref:`logical-select-min`.
456
457 .. _logical-table-remove-min-border:
458
459 ``min_border``
460 """"""""""""""
461
462 Specifies whether the minimum value is included or not. ``include``
463 and ``exclude`` are available. The default is ``include``.
464
465 See also :ref:`logical-select-min-border`.
466
467 .. _logical-table-remove-max:
468
469 ``max``
470 """""""
471
472 Specifies the maximum value of ``shard_key`` column.
473
474 See also :ref:`logical-select-max`.
475
476 .. _logical-table-remove-max-border:
477
478 ``max_border``
479 """"""""""""""
480
481 Specifies whether the maximum value is included or not. ``include``
482 and ``exclude`` are available. The default is ``include``.
483
484 See also :ref:`logical-select-max-border`.
485
486 .. _logical-table-remove-dependent:
487
488 ``dependent``
489 """""""""""""
490
491 .. versionadded:: 6.0.1
492
493 Specifies whether tables and columns that depend on the target shard
494 are also removed or not.
495
496 Here are conditions for dependent. If table or column satisfies one of
497 the conditions, the table or column depends on the target shard:
498
499 * Tables and columns that reference the target shard
500 * Tables for the shard (= The table has the same ``_YYYYMMDD``
501 postfix as the target shard and is referenced from the target
502 shard)
503
504 If this value is ``yes``, tables and columns that depend on the target
505 shard are also removed. Otherwise, they aren't removed. If there are
506 one or more tables that reference the target shard, an error is
507 returned. If there are tables for the shared, they are not touched.
508
509 You should use this parameter carefully. This is a danger parameter.
510
511 See :ref:`logical-table-remove-removes-with-related-tables` how to use
512 this parameter.
513
514 .. _logical-table-remove-force:
515
516 ``force``
517 """""""""
518
519 .. versionadded:: 6.0.9
520
521 Specifies whether you want to remove target tables and columns even if
522 some problems exist.
523
524 You should use this parameter carefully. This is a danger parameter.
525
526 See
527 :ref:`logical-table-remove-removes-broken-tables-as-much-as-possible`
528 how to use this parameter.
529
530 Return value
531 ------------
532
533 The command returns ``true`` as body on success such as::
534
535 [HEADER, true]
536
537 If the command fails, error details are in ``HEADER``.
538
539 See :doc:`/reference/command/output_format` for ``HEADER``.