Debian Codegraph @

doc/source/reference/commands/column_create.rst

raw
1 .. -*- rst -*-
2
3 .. groonga-command
4 .. database: commands_column_create
5
6 ``column_create``
7 =================
8
9 Summary
10 -------
11
12 ``column_create`` creates a new column in a table.
13
14 You need to create one or more columns to store multiple data in one
15 record.
16
17 Groonga provides an index as a column. It's different from other
18 systems. An index is just an index in other systems. Implementing an
19 index as a column provides flexibility. For example, you can add
20 metadata to each token.
21
22 See :doc:`/reference/column` for column details.
23
24 Syntax
25 ------
26
27 This command takes many parameters.
28
29 Most parameters are required::
30
31 column_create table
32 name
33 flags
34 type
35 [source=null]
36 [path=null]
37 [generator=null]
38 [progress_log_level=debug]
39
40 Usage
41 -----
42
43 This section describes about the followings:
44
45 * :ref:`column-create-scalar`
46 * :ref:`column-create-vector`
47 * :ref:`column-create-vector-weight`
48 * :ref:`column-create-reference`
49 * :ref:`column-create-index`
50 * :ref:`column-create-index-full-text-search`
51 * :ref:`column-create-index-multiple-columns`
52 * :ref:`column-create-index-small`
53 * :ref:`column-create-index-medium`
54 * :ref:`column-create-index-large`
55 * :ref:`column-create-missing-mode`
56 * :ref:`column-create-invalid-mode`
57 * :ref:`column-create-generated-column`
58
59 Here is the ``People`` table definition. The ``People`` table is used
60 in examples:
61
62 .. groonga-command
63 .. include:: ../../example/reference/commands/column_create/usage_table.log
64 .. table_create \
65 .. --name People \
66 .. --flags TABLE_HASH_KEY \
67 .. --key_type ShortText
68
69 .. _column-create-scalar:
70
71 Create a scalar column
72 ^^^^^^^^^^^^^^^^^^^^^^
73
74 Groonga provides scalar column to store one value. For example, scalar
75 column should be used for storing age into a person record. Because a
76 person record must have only one age.
77
78 If you want to store multiple values into a record, scalar column
79 isn't suitable. Use :ref:`column-create-vector` instead.
80
81 You must specify ``COLUMN_SCALAR`` to the ``flags`` parameter to
82 create a scalar column.
83
84 Here is an example to create the ``age`` column to the ``People``
85 table. ``age`` column is a scalar column. It can store one ``UInt8``
86 (``0-255``) value as its value:
87
88 .. groonga-command
89 .. include:: ../../example/reference/commands/column_create/usage_scalar_create.log
90 .. column_create \
91 .. --table People \
92 .. --name age \
93 .. --flags COLUMN_SCALAR \
94 .. --type UInt8
95
96 You can store one value (``7``) by the following :doc:`load` command:
97
98 .. groonga-command
99 .. include:: ../../example/reference/commands/column_create/usage_scalar_load.log
100 .. load --table People
101 .. [
102 .. {"_key": "alice", "age": 7}
103 .. ]
104
105 You can confirm the stored one value (``7``) by the following
106 :doc:`select` command:
107
108 .. groonga-command
109 .. include:: ../../example/reference/commands/column_create/usage_scalar_select.log
110 .. select --table People
111
112 .. _column-create-vector:
113
114 Create a vector column
115 ^^^^^^^^^^^^^^^^^^^^^^
116
117 Groonga provides vector column to store multiple values. For example,
118 vector column may be used for storing roles into a person
119 record. Because a person record may have multiple roles.
120
121 If you want to store only one value into a record, vector column isn't
122 suitable. Use :ref:`column-create-scalar` instead.
123
124 You must specify ``COLUMN_VECTOR`` to the ``flags`` parameter to
125 create a vector column.
126
127 Here is an example to create the ``roles`` column to the ``People``
128 table. ``roles`` column is a vector column. It can store zero or more
129 ``ShortText`` values as its value:
130
131 .. groonga-command
132 .. include:: ../../example/reference/commands/column_create/usage_vector_create.log
133 .. column_create \
134 .. --table People \
135 .. --name roles \
136 .. --flags COLUMN_VECTOR \
137 .. --type ShortText
138
139 You can store multiple values (``["adventurer", "younger-sister"]``)
140 by the following :doc:`load` command:
141
142 .. groonga-command
143 .. include:: ../../example/reference/commands/column_create/usage_vector_load.log
144 .. load --table People
145 .. [
146 .. {"_key": "alice", "roles": ["adventurer", "younger-sister"]}
147 .. ]
148
149 You can confirm the stored multiple values (``["adventurer",
150 "younger-sister"]``) by the following :doc:`select` command:
151
152 .. groonga-command
153 .. include:: ../../example/reference/commands/column_create/usage_vector_select.log
154 .. select --table People
155
156 .. _column-create-vector-weight:
157
158 Create a weight vector column
159 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
160
161 TODO: See also :ref:`weight-vector-column` and :ref:`select-adjuster`.
162
163 .. _column-create-reference:
164
165 Create a column that refers a table's record
166 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
167
168 Both scalar column and vector column can store reference to record of
169 an existing table as column value. It's useful to store relationship
170 between records.
171
172 For example, using a column that refers a person record is better for
173 storing a character into a book record. Because one person may be
174 appeared in some books.
175
176 You must specify table name to be referenced to the ``type`` parameter
177 to create a column that refers a table's record.
178
179 Here is an example to create the ``character`` column to the ``Books``
180 table. The ``character`` column refers the ``People`` table. It can
181 store one ``People`` table's record.
182
183 Here is the ``Books`` table definition:
184
185 .. groonga-command
186 .. include:: ../../example/reference/commands/column_create/usage_reference_create_table.log
187 .. table_create \
188 .. --name Books \
189 .. --flags TABLE_HASH_KEY \
190 .. --key_type ShortText
191
192 Here is the ``character`` column definition in the ``Books``
193 table. ``--type People`` is important:
194
195 .. groonga-command
196 .. include:: ../../example/reference/commands/column_create/usage_reference_create_column.log
197 .. column_create \
198 .. --table Books \
199 .. --name character \
200 .. --flags COLUMN_SCALAR \
201 .. --type People
202
203 You can store one reference (``"alice"``) by the following :doc:`load`
204 command. You can use key value (``People._key`` value) for referring a
205 record:
206
207 .. groonga-command
208 .. include:: ../../example/reference/commands/column_create/usage_reference_load.log
209 .. load --table Books
210 .. [
211 .. {"_key": "Alice's Adventure in Wonderland", "character": "alice"}
212 .. ]
213
214 You can confirm the stored reference (``"alice"`` record) by the
215 following :doc:`select` command. It retrieves the ``age`` column and
216 the ``roles`` column values:
217
218 .. groonga-command
219 .. include:: ../../example/reference/commands/column_create/usage_reference_select.log
220 .. select \
221 .. --table Books \
222 .. --output_columns _key,character._key,character.age,character.roles
223
224 .. _column-create-index:
225
226 Create an index column
227 ^^^^^^^^^^^^^^^^^^^^^^
228
229 Groonga provides index column for fast search. It doesn't store your
230 data. It stores data for fast search.
231
232 You don't need to update index column by yourself. Index column is
233 updated automatically when you store data into a data column (scalar
234 column or vector column) that is marked as index target column. You
235 can set multiple columns as index target columns to one index column.
236
237 If you make a new index, it is invisible until finishing of index build.
238
239 If Groonga has an index column for the ``age`` column of the
240 ``People`` table, Groonga can do fast equal search, fast comparison
241 search and fast range search against ``age`` column values.
242
243 You must specify the following parameters to create an index column:
244
245 * The ``flags`` parameter: ``COLUMN_INDEX``
246
247 * The ``type`` parameter: The table name of index target column such
248 as ``People``
249
250 * The ``source`` parameter: The index target column name such as
251 ``age``
252
253 You don't need additional flags to the ``flags`` parameter for equal
254 search, comparison search and range search index column. You need
255 additional flags to the ``flags`` parameter for full text search index
256 column or multiple column index column. See
257 :ref:`column-create-index-full-text-search` and
258 :ref:`column-create-index-multiple-columns` for details.
259
260 Here is an example to create an index column for the ``age`` column of
261 the ``People`` table.
262
263 First, you need to create a table for range index column. See
264 :ref:`table-create-range-index-table` for details. This example
265 creates the ``Ages`` table as :ref:`table-pat-key`:
266
267 .. groonga-command
268 .. include:: ../../example/reference/commands/column_create/usage_index_create_table.log
269 .. table_create \
270 .. --name Ages \
271 .. --flags TABLE_PAT_KEY \
272 .. --key_type UInt8
273
274 Now, you can create an index column for the ``age`` column of the
275 ``People`` table. ``COLUMN_INDEX`` in the ``flags`` parameter,
276 ``People`` in the ``type`` parameter and ``age`` in the ``source``
277 parameter are important:
278
279 .. groonga-command
280 .. include:: ../../example/reference/commands/column_create/usage_index_create_column.log
281 .. column_create \
282 .. --table Ages \
283 .. --name people_age_index \
284 .. --flags COLUMN_INDEX \
285 .. --type People \
286 .. --source age
287
288 You can confirm that ``age > 5`` is evaluated by the
289 ``Ages.people_age_index`` newly created index column from log. Groonga
290 reports used index columns in ``info`` log level. You can change log
291 level dynamically by :doc:`log_level` command.
292
293 .. groonga-command
294 .. log: true
295 .. include:: ../../example/reference/commands/column_create/usage_index_select.log
296 .. log_level --level info
297 .. select \
298 .. --table People \
299 .. --filter 'age > 5'
300 .. log_level --level notice
301 .. log: false
302
303 You can confirm that the ``Ages.people_age_index`` is used from the
304 following log::
305
306 [table][select][index][range] <Ages.people_age_index>
307
308 The log says ``Ages.people_age_index`` index column is used for range
309 search.
310
311 .. _column-create-index-full-text-search:
312
313 Create an index column for full text search
314 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
315
316 There is a difference between for non full text search (equal search,
317 comparison search or range search) index column and for full text
318 search index column. You need to add ``WITH_POSITION`` to the
319 ``flags`` parameter. It means that you need to specify
320 ``COLUMN_INDEX|WITH_POSITION`` to the ``flags`` parameter. It's the
321 difference.
322
323 Here is an example to create a full text search index column for the
324 key of the ``People`` table.
325
326 First, you need to create a table for full text search index
327 column. See :ref:`table-create-lexicon` for details. This example
328 creates the ``Terms`` table as :ref:`table-pat-key` with
329 :ref:`token-bigram` tokenizer and :ref:`normalizer-auto` normalizer:
330
331 .. groonga-command
332 .. include:: ../../example/reference/commands/column_create/usage_full_text_search_index_create_table.log
333 .. table_create \
334 .. --name Terms \
335 .. --flags TABLE_PAT_KEY \
336 .. --key_type ShortText \
337 .. --default_tokenizer TokenBigram \
338 .. --normalizer NormalizerAuto
339
340 Now, you can create a full text search index column for the key of the
341 ``People`` table. ``COLUMN_INDEX|WITH_POSITION`` in the ``flags``
342 parameter, ``People`` in the ``type`` parameter and ``_key`` in the
343 ``source`` parameter are important:
344
345 .. groonga-command
346 .. include:: ../../example/reference/commands/column_create/usage_full_text_search_index_create_column.log
347 .. column_create \
348 .. --table Terms \
349 .. --name people_key_index \
350 .. --flags COLUMN_INDEX|WITH_POSITION \
351 .. --type People \
352 .. --source _key
353
354 You can confirm that ``--match_columns _key`` and ``--query Alice``
355 are evaluated by the ``Terms.people_key_index`` newly created full
356 text search index column from log. Groonga reports used index columns
357 in ``info`` log level. You can change log level dynamically by
358 :doc:`log_level` command.
359
360 .. groonga-command
361 .. log: true
362 .. include:: ../../example/reference/commands/column_create/usage_full_text_search_index_select.log
363 .. log_level --level info
364 .. select \
365 .. --table People \
366 .. --match_columns _key \
367 .. --query Alice
368 .. log_level --level notice
369 .. log: false
370
371 You can confirm that the ``Terms.people_key_index`` is used from the
372 following log::
373
374 [object][search][index][key][exact] <Terms.people_key_index>
375
376 The log says ``Terms.people_key_index`` index column is used for full
377 text search. (To be precise, the index column is used for exact term
378 search by inverted index.)
379
380 .. _column-create-index-multiple-columns:
381
382 Create a multiple columns index column
383 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
384
385 You can create an index column for multiple columns. It means that you
386 can do fast search for multiple columns with one index
387 column. Multiple columns index column has better space efficiency than
388 single column index column only when multiple columns have many same
389 tokens. Multiple columns index column may be slower than single column
390 index column. Because multiple columns index column will be a bigger
391 index column.
392
393 You can't use multiples columns in different tables as index target
394 columns in the same multiple columns index column. You must specify
395 columns in the same tables as index target columns to one multiple
396 columns index column. For example, you can't create a multiple columns
397 index for ``People._key`` and ``Books._key`` because they are columns
398 of different tables. You can create a multiple columns index column
399 for ``People._key`` and ``People.roles`` because they are columns of
400 the same table.
401
402 There is a difference between for single column index column and for
403 multiple columns index column. You need to add ``WITH_SECTION`` to the
404 ``flags`` parameter. It means that you need to specify
405 ``COLUMN_INDEX|WITH_SECTION`` to the ``flags`` parameter. It's the
406 difference.
407
408 If you want to create a multiple columns index column for full text
409 search, you need to specify
410 ``COLUMN_INDEX|WITH_POSITION|WITH_SECTION`` to the ``flags``
411 parameter. See :ref:`column-create-index-full-text-search` for full
412 text search index column details.
413
414 Here is an example to create a multiple columns index column for the
415 key of the ``People`` table and the ``roles`` column of the ``People``
416 table.
417
418 There is no difference between index table for single column index
419 column and multiple columns index column.
420
421 In this example, ``Names`` table is created for equal search and
422 prefix search. It uses ``TABLE_PAT_KEY`` because ``TABLE_PAT_KEY``
423 supports prefix search. See :doc:`../tables` for details.
424
425 .. groonga-command
426 .. include:: ../../example/reference/commands/column_create/usage_multiple_columns_index_create_table.log
427 .. table_create \
428 .. --name Names \
429 .. --flags TABLE_PAT_KEY \
430 .. --key_type ShortText \
431 .. --normalizer NormalizerAuto
432
433 You can create a multiple columns index column for the key of the
434 ``People`` table and ``roles`` column of the ``People``
435 table. ``COLUMN_INDEX|WITH_SECTION`` in the ``flags`` parameter,
436 ``People`` in the ``type`` parameter and ``_key,roles`` in the
437 ``source`` parameter are important:
438
439 .. groonga-command
440 .. include:: ../../example/reference/commands/column_create/usage_multiple_columns_index_create_column.log
441 .. column_create \
442 .. --table Names \
443 .. --name people_key_roles_index \
444 .. --flags COLUMN_INDEX|WITH_SECTION \
445 .. --type People \
446 .. --source _key,roles
447
448 You can confirm that ``--filter 'roles @^ "Younger"`` is evaluated by
449 the ``Names.people_key_roles_index`` newly created multiple columns
450 index column from log. Groonga reports used index columns in ``info``
451 log level. You can change log level dynamically by :doc:`log_level`
452 command.
453
454 .. groonga-command
455 .. log: true
456 .. include:: ../../example/reference/commands/column_create/usage_multiple_columns_index_select.log
457 .. log_level --level info
458 .. select \
459 .. --table People \
460 .. --filter 'roles @^ "Younger"'
461 .. log_level --level notice
462 .. log: false
463
464 You can confirm that the ``Names.people_key_roles_index`` is used from
465 the following log::
466
467 [table][select][index][prefix] <Names.people_key_roles_index>
468
469 The log says ``Names.people_key_roles_index`` index column is used for
470 prefix search.
471
472 .. _column-create-index-small:
473
474 Create a small index column
475 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
476
477 If you know index target data are small, you can reduce memory usage
478 for the index column. Memory usage is ``1/256`` of the default index
479 column.
480
481 How many data are small? It depends on data. Small index column can't
482 handle 1 billion records at least. If index target is only one
483 scalar column with no text family type (``ShortText``, ``Text`` or
484 ``LongText``), the maximum handleable records are depends of the
485 number of kinds of index target data. If index target column has
486 ``1``, ``1``, ``2`` and ``3``, the number of kinds of them are ``3``
487 (``1`` and ``2`` and ``3``). The following table shows the
488 relationship between the number of kinds of index target data and the
489 number of handleable records:
490
491 .. list-table:: The number of kinds of index target data and the number of handleable records in a small index column
492 :header-rows: 1
493
494 * - The number of kinds of index target data
495 - The number of handleable records
496 * - 1
497 - 16779234
498 * - 2
499 - 4648070
500 * - 4
501 - 7238996
502 * - 8
503 - 8308622
504 * - 16
505 - 11068624
506 * - 32
507 - 12670817
508 * - 64
509 - 18524211
510 * - 128
511 - 38095511
512 * - 256
513 - 51265384
514
515 You need to add ``INDEX_SMALL`` to the ``flags`` parameter such as
516 ``COLUMN_INDEX|INDEX_SMALL`` to create a small index column.
517
518 If the ``People`` table has only 1 million records, you can use a
519 small index column for the ``age`` column:
520
521 .. groonga-command
522 .. include:: ../../example/reference/commands/column_create/usage_small_index_create_column.log
523 .. column_create \
524 .. --table Ages \
525 .. --name people_age_small_index \
526 .. --flags COLUMN_INDEX|INDEX_SMALL \
527 .. --type People \
528 .. --source age
529
530 .. _column-create-index-medium:
531
532 Create a medium index column
533 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
534
535 If you know index target data are medium, you can reduce memory usage
536 for the index column. Memory usage is ``5/24`` of the default index
537 column.
538
539 How many data are medium? It depends on data.
540
541 If index target is only one scalar column, a medium index column
542 can handle all records.
543
544 A medium index column may not handle all records at the following
545 cases:
546
547 * Index target is one text family (``ShortText``, ``Text`` or
548 ``LongText``) scalar column
549 * Index target is one vector column
550 * Index targets are multiple columns
551 * Index table has tokenizer
552
553 You need to add ``INDEX_MEDIUM`` to the ``flags`` parameter such as
554 ``COLUMN_INDEX|INDEX_MEDIUM`` to create a medium index column.
555
556 You can use a medium index column for an index column of the ``age``
557 column of the ``People`` table safely. Because it's one scalar column
558 with ``UInt8`` type.
559
560 Here is an example to create a medium index column:
561
562 .. groonga-command
563 .. include:: ../../example/reference/commands/column_create/usage_medium_index_create_column.log
564 .. column_create \
565 .. --table Ages \
566 .. --name people_age_medium_index \
567 .. --flags COLUMN_INDEX|INDEX_MEDIUM \
568 .. --type People \
569 .. --source age
570
571 .. _column-create-index-large:
572
573 Create a large index column
574 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
575
576 If you know index target data are large, you need to use large index
577 column. It uses increases memory usage for the index column but it can
578 accept more data. Memory usage is 2 times larger than the default
579 index column.
580
581 How many data are large? It depends on data.
582
583 If index target is only one scalar column, it's not large data.
584
585 Large data must have many records (normally at least 10 millions
586 records) and at least one of the following features:
587
588 * Index targets are multiple columns
589 * Index table has tokenizer
590
591 You need to add ``INDEX_LARGE`` to the ``flags`` parameter such as
592 ``COLUMN_INDEX|INDEX_LARGE`` to create a large index column.
593
594 You can use a large index column for an index column of the ``_key``
595 of the ``People`` table and the ``role`` column of the ``People``
596 table.
597
598 Here is an example to create a large index column:
599
600 .. groonga-command
601 .. include:: ../../example/reference/commands/column_create/usage_large_index_create_column.log
602 .. column_create \
603 .. --table Terms \
604 .. --name people_roles_large_index \
605 .. --flags COLUMN_INDEX|WITH_POSITION|WITH_SECTION|INDEX_LARGE \
606 .. --type People \
607 .. --source roles
608
609 .. _column-create-missing-mode:
610
611 Missing mode
612 ^^^^^^^^^^^^
613
614 .. versionadded:: 12.0.2
615
616 You can control how to process a nonexistent key in the specified new
617 value of a reference column by a ``MISSING_*`` flag. Here are
618 available ``MISSING_*`` flags:
619
620 * ``MISSING_ADD`` (default)
621 * ``MISSING_IGNORE``
622 * ``MISSING_NIL``
623
624 You can't specify multiple ``MISSING_*`` flags for a column.
625
626 ``MISSING_*`` flags are meaningful only for a reference column.
627
628 The following table describes the differences between ``MISSING_*``
629 flags when a nonexistent key is specified to a reference scalar
630 column:
631
632 .. list-table::
633 :header-rows: 1
634
635 * - Flag
636 - Description
637 - An example given value
638 - An example set value
639
640 * - ``MISSING_ADD``
641 - The given nonexistent key is added to the referred table
642 automatically and the ID of the newly added record is set.
643
644 This is the default.
645 - ``"nonexistent"``
646 - The record ID of the newly added record whose key is
647 ``"nonexistent"``.
648 * - ``MISSING_IGNORE``
649 - The given nonexistent key is ignored and ``0`` is set.
650
651 There is no difference between ``MISSING_IGNORE`` and
652 ``MISSING_NIL`` for a reference scalar column.
653 - ``"nonexistent"``
654 - ``0``
655 * - ``MISSING_NIL``
656 - The given nonexistent key is ignored and ``0`` is set.
657
658 There is no difference between ``MISSING_IGNORE`` and
659 ``MISSING_NIL`` for a reference scalar column.
660 - ``"nonexistent"``
661 - ``0``
662
663 Here is an example to show differences between ``MISSING_*`` flags for
664 a reference scalar column.
665
666 First this example defines columns for all ``MISSING_*`` flags:
667
668 .. groonga-command
669 .. include:: ../../example/reference/commands/column_create/missing_mode_scalar_schema.log
670 .. table_create \
671 .. --name MissingModeScalarReferred \
672 .. --flags TABLE_HASH_KEY \
673 .. --key_type ShortText
674 .. table_create \
675 .. --name MissingModeScalar \
676 .. --flags TABLE_HASH_KEY \
677 .. --key_type ShortText
678 .. column_create \
679 .. --table MissingModeScalar \
680 .. --name missing_add \
681 .. --flags COLUMN_SCALAR|MISSING_ADD \
682 .. --type MissingModeScalarReferred
683 .. column_create \
684 .. --table MissingModeScalar \
685 .. --name missing_ignore \
686 .. --flags COLUMN_SCALAR|MISSING_IGNORE \
687 .. --type MissingModeScalarReferred
688 .. column_create \
689 .. --table MissingModeScalar \
690 .. --name missing_nil \
691 .. --flags COLUMN_SCALAR|MISSING_NIL \
692 .. --type MissingModeScalarReferred
693
694 Then this example loads nonexistent keys to all columns. The specified
695 nonexistent key for ``MISSING_ADD`` is only added to
696 ``MissingModeScalarReferred`` automatically and the specified
697 nonexistent keys for ``MISSING_IGNORE`` and ``MISSING_NIL`` aren't
698 added to ``MissingModeScalarReferred``. ``missing_ignore``'s value and
699 ``missing_nil``'s value are showed as ``""`` because they refer a
700 record whose ID is ``0`` and record whose ID is ``0`` never exist:
701
702 .. groonga-command
703 .. include:: ../../example/reference/commands/column_create/missing_mode_scalar_load.log
704 .. load --table MissingModeScalar
705 .. [
706 .. {"_key": "key", "missing_add": "nonexistent1"}
707 .. ]
708 .. load --table MissingModeScalar
709 .. [
710 .. {"_key": "key", "missing_ignore": "nonexistent2"}
711 .. ]
712 .. load --table MissingModeScalar
713 .. [
714 .. {"_key": "key", "missing_nil": "nonexistent3"}
715 .. ]
716 .. select --table MissingModeScalar
717 .. select --table MissingModeScalarReferred
718
719 The following table describes the differences between ``MISSING_*``
720 flags when a vector value that has a nonexistent key element is
721 specified to a reference vector column:
722
723 .. list-table::
724 :header-rows: 1
725
726 * - Flag
727 - Description
728 - An example given value
729 - An example set value
730
731 * - ``MISSING_ADD``
732 - The given nonexistent key is added to the referred table
733 automatically and the ID of the newly added record is used for
734 the element.
735
736 This is the default.
737 - ``["existent1", "nonexistent", "existent2"]``
738 - The record IDs of ``"existent1"``, ``"nonexistent"`` and
739 ``"existent2"``.
740 * - ``MISSING_IGNORE``
741 - The given nonexistent key element is ignored.
742 - ``["existent1", "nonexistent", "existent2"]``
743 - The record IDs of ``"existent1"`` and ``"existent2"``.
744 * - ``MISSING_NIL``
745 - The given nonexistent key element is ignored.
746
747 If ``INVALID_WARN`` or ``INVALID_IGNORE`` are also specified,
748 the element is replaced with ``0``. If ``INVALID_ERROR`` is
749 specified or no ``INVALID_*`` are specified, the element is
750 ignored.
751
752 See also :ref:`column-create-invalid-mode`.
753 - ``["existent1", "nonexistent", "existent2"]``
754 - The record ID of ``"existent1"`` and ``0`` and the record ID of
755 ``"existent2"`` for ``INVALID_WARN`` and ``INVALID_IGNORE``.
756
757 The record IDs of ``"existent1"`` and ``"existent2"`` for
758 ``INVALID_ERROR`` and no ``INVALID_*``.
759
760 Here is an example to show differences between ``MISSING_*`` flags for
761 a reference vector column.
762
763 First this example defines columns for all ``MISSING_*`` flags:
764
765 .. groonga-command
766 .. include:: ../../example/reference/commands/column_create/missing_mode_vector_schema.log
767 .. table_create \
768 .. --name MissingModeVectorReferred \
769 .. --flags TABLE_HASH_KEY \
770 .. --key_type ShortText
771 .. table_create \
772 .. --name MissingModeVector \
773 .. --flags TABLE_HASH_KEY \
774 .. --key_type ShortText
775 .. column_create \
776 .. --table MissingModeVector \
777 .. --name missing_add \
778 .. --flags COLUMN_VECTOR|MISSING_ADD \
779 .. --type MissingModeVectorReferred
780 .. column_create \
781 .. --table MissingModeVector \
782 .. --name missing_ignore \
783 .. --flags COLUMN_VECTOR|MISSING_IGNORE|INVALID_IGNORE \
784 .. --type MissingModeVectorReferred
785 .. column_create \
786 .. --table MissingModeVector \
787 .. --name missing_nil \
788 .. --flags COLUMN_VECTOR|MISSING_NIL|INVALID_IGNORE \
789 .. --type MissingModeVectorReferred
790
791 Then this example loads a vector that includes a nonexistent key to
792 all columns. The specified nonexistent key for ``MISSING_ADD`` is only
793 added to ``MissingModeVectorReferred`` automatically and the specified
794 nonexistent keys for ``MISSING_IGNORE`` and ``MISSING_NIL`` aren't
795 added to ``MissingModeVectorReferred``. The specified nonexistent key
796 element is removed from ``missing_ignore``'s value. The specified
797 nonexistent key element is replaced with ``0`` in ``missing_nil``'s
798 value because ``INVALID_IGNORE`` is also specified. And the element
799 replaced with ``0`` is showed as ``""`` because it refers a record
800 whose ID is ``0`` and record whose ID is ``0`` never exist:
801
802 .. groonga-command
803 .. include:: ../../example/reference/commands/column_create/missing_mode_vector_load.log
804 .. load --table MissingModeVectorReferred
805 .. [
806 .. {"_key": "existent1"},
807 .. {"_key": "existent2"}
808 .. ]
809 .. load --table MissingModeVector
810 .. [
811 .. {"_key": "key", "missing_add": ["existent1", "nonexistent1", "existent2"]}
812 .. ]
813 .. load --table MissingModeVector
814 .. [
815 .. {"_key": "key", "missing_ignore": ["existent1", "nonexistent2", "existent2"]}
816 .. ]
817 .. load --table MissingModeVector
818 .. [
819 .. {"_key": "key", "missing_nil": ["existent1", "nonexistent3", "existent2"]}
820 .. ]
821 .. select --table MissingModeVector
822 .. select --table MissingModeVectorReferred
823
824 .. _column-create-invalid-mode:
825
826 Invalid mode
827 ^^^^^^^^^^^^
828
829 .. versionadded:: 12.0.2
830
831 You can control how to process an invalid value in the specified new
832 value of a data column by a ``INVALID_*`` flag. Here are available
833 ``INVALID_*`` flags:
834
835 * ``INVALID_ERROR`` (default)
836 * ``INVALID_WARN``
837 * ``INVALID_IGNORE``
838
839 You can't specify multiple ``INVALID_*`` flags for a column.
840
841 ``INVALID_*`` flags are meaningful only for a ``COLUMN_SCALAR`` column
842 and a ``COLUMN_VECTOR`` column.
843
844 If the target column is a reference column, an invalid value depends
845 on :ref:`column-create-missing-mode`. If you specify
846 ``MISSING_IGNORE`` or ``MISSING_NIL``, a nonexistent key is an invalid
847 value. Note that an empty string key and string keys that are empty
848 strings by normalization aren't an invalid value with all
849 ``MISSING_*`` flags. They are special.
850
851 If the target column isn't a reference column, an invalid value
852 depends on column's value type. For example, ``"invalid"`` is an
853 invalid value for an ``Int32`` scalar column.
854
855 The following table describes the differences between ``INVALID_*``
856 flags when an invalid value is specified to an ``Int32`` scalar column:
857
858 .. list-table::
859 :header-rows: 1
860
861 * - Flag
862 - Description
863 - An example given value
864 - An example set value
865
866 * - ``INVALID_ERROR``
867 - The given invalid value is reported as an error in
868 :ref:`process-log` and by :doc:`load`.
869
870 The given invalid value isn't set.
871
872 This is the default.
873 - ``"invalid"``
874 - The column isn't updated.
875 * - ``INVALID_WARN``
876 - The given invalid value is reported as a warning in
877 :ref:`process-log`.
878
879 The given invalid value is replaced with the default value of
880 the target scalar column. For example, ``0`` is the default
881 value for an ``Int32`` scalar column.
882 - ``"nonexistent"``
883 - ``0``
884 * - ``INVALID_IGNORE``
885 - The given invalid value is ignored.
886
887 The given invalid value is replaced with the default value of
888 the target scalar column. For example, ``0`` is the default
889 value for an ``Int32`` scalar column.
890 - ``"invalid"``
891 - ``0``
892
893 Here is an example to show differences between ``INVALID_*`` flags for
894 an ``Int32`` scalar column.
895
896 First this example defines columns for all ``INVALID_*`` flags:
897
898 .. groonga-command
899 .. include:: ../../example/reference/commands/column_create/invalid_mode_scalar_schema.log
900 .. table_create \
901 .. --name InvalidModeScalar \
902 .. --flags TABLE_HASH_KEY \
903 .. --key_type ShortText
904 .. column_create \
905 .. --table InvalidModeScalar \
906 .. --name invalid_error \
907 .. --flags COLUMN_SCALAR|INVALID_ERROR \
908 .. --type Int32
909 .. column_create \
910 .. --table InvalidModeScalar \
911 .. --name invalid_warn \
912 .. --flags COLUMN_SCALAR|INVALID_WARN \
913 .. --type Int32
914 .. column_create \
915 .. --table InvalidModeScalar \
916 .. --name invalid_ignore \
917 .. --flags COLUMN_SCALAR|INVALID_IGNORE \
918 .. --type Int32
919
920 Then this example loads ``29`` as initial values for all columns to
921 show differences between them on update:
922
923 .. groonga-command
924 .. include:: ../../example/reference/commands/column_create/invalid_mode_scalar_load_initial.log
925 .. load --table InvalidModeScalar
926 .. [
927 .. {
928 .. "_key": "key",
929 .. "invalid_error": 29,
930 .. "invalid_warn": 29,
931 .. "invalid_ignore": 29
932 .. }
933 .. ]
934 .. select \
935 .. --table InvalidModeScalar \
936 .. --output_columns invalid_error,invalid_warn,invalid_ignore
937
938 Then this example update existing column values with invalid values.
939 The specified invalid value is reported as an error by :doc:`load`
940 only with ``INVALID_ERROR``. And the existing value isn't updated only
941 with ``INVALID_ERROR``. The existing value is updated with ``0`` with
942 ``INVALID_WARN`` and ``INVALID_IGNORE``. You can't see differences
943 between ``INVALID_WARN`` and ``INVALID_IGNORE`` with this example but
944 a warning message is logged in :ref:`process-log` only with
945 ``INVALID_WARN``:
946
947 .. groonga-command
948 .. include:: ../../example/reference/commands/column_create/invalid_mode_scalar_load_update.log
949 .. load --table InvalidModeScalar
950 .. [
951 .. {"_key": "key", "invalid_error": "invalid"},
952 .. ]
953 .. load --table InvalidModeScalar
954 .. [
955 .. {"_key": "key", "invalid_warn": "invalid"},
956 .. ]
957 .. load --table InvalidModeScalar
958 .. [
959 .. {"_key": "key", "invalid_ignore": "invalid"},
960 .. ]
961 .. select \
962 .. --table InvalidModeScalar \
963 .. --output_columns invalid_error,invalid_warn,invalid_ignore
964
965 The following table describes the differences between ``INVALID_*``
966 flags when a vector value that has an invalid element is specified to
967 an ``Int32`` vector column:
968
969 .. list-table::
970 :header-rows: 1
971
972 * - Flag
973 - Description
974 - An example given value
975 - An example set value
976
977 * - ``INVALID_ERROR``
978 - The given invalid element is reported as an error in
979 :ref:`process-log` but :doc:`load` doesn't report an error.
980
981 If the target column is a reference vector column and
982 ``MISSING_NIL`` flag is specified, invalid elements are
983 replaced with ``0``. Invalid elements are ignored otherwise.
984
985 - ``[1, "invalid", 3]``
986 - ``[1, 3]``
987 * - ``INVALID_WARN``
988 - The given invalid element is reported as a warning in
989 :ref:`process-log`.
990
991 If the target column is a reference vector column and
992 ``MISSING_NIL`` flag is specified, invalid elements are
993 replaced with ``0``. Invalid elements are ignored otherwise.
994
995 - ``[1, "invalid", 3]``
996 - ``[1, 3]``
997 * - ``INVALID_IGNORE``
998 - The given invalid element is ignored.
999
1000 If the target column is a reference vector column and
1001 ``MISSING_NIL`` flag is specified, invalid elements are
1002 replaced with ``0``. Invalid elements are ignored otherwise.
1003
1004 - ``[1, "invalid", 3]``
1005 - ``[1, 3]``
1006
1007 Here is an example to show differences between ``INVALID_*`` flags for
1008 a reference vector column.
1009
1010 First this example defines columns for all ``INVALID_*`` flags:
1011
1012 .. groonga-command
1013 .. include:: ../../example/reference/commands/column_create/invalid_mode_vector_schema.log
1014 .. table_create \
1015 .. --name InvalidModeVector \
1016 .. --flags TABLE_HASH_KEY \
1017 .. --key_type ShortText
1018 .. column_create \
1019 .. --table InvalidModeVector \
1020 .. --name invalid_error \
1021 .. --flags COLUMN_VECTOR|INVALID_ERROR \
1022 .. --type Int32
1023 .. column_create \
1024 .. --table InvalidModeVector \
1025 .. --name invalid_warn \
1026 .. --flags COLUMN_VECTOR|INVALID_WARN \
1027 .. --type Int32
1028 .. column_create \
1029 .. --table InvalidModeVector \
1030 .. --name invalid_ignore \
1031 .. --flags COLUMN_VECTOR|INVALID_IGNORE \
1032 .. --type Int32
1033
1034 Then this example loads a vector that includes an invalid element to
1035 all columns. The all specified invalid elements are ignored regardless
1036 of ``INVALID_*`` flags. Messages in :ref:`process-log` are different
1037 by ``INVALID_*`` flags. If ``INVALID_ERROR`` is specified, an error
1038 message is logged in :ref:`process-log`. If ``INVALID_WARN`` is
1039 specified, a warning message is logged in
1040 :ref:`process-log`. ``INVALID_IGNORE`` is specified, no message is
1041 logged in :ref:`process-log`:
1042
1043 .. groonga-command
1044 .. include:: ../../example/reference/commands/column_create/invalid_mode_vector_load.log
1045 .. load --table InvalidModeVector
1046 .. [
1047 .. {"_key": "key", "invalid_error": [1, "invalid", 3]}
1048 .. ]
1049 .. load --table InvalidModeVector
1050 .. [
1051 .. {"_key": "key", "invalid_warn": [1, "invalid", 3]}
1052 .. ]
1053 .. load --table InvalidModeVector
1054 .. [
1055 .. {"_key": "key", "invalid_ignore": [1, "invalid", 3]}
1056 .. ]
1057 .. select \
1058 .. --table InvalidModeVector \
1059 .. --output_columns invalid_error,invalid_warn,invalid_ignore
1060
1061 .. _column-create-generated-column:
1062
1063 Create a generated column
1064 ^^^^^^^^^^^^^^^^^^^^^^^^^
1065
1066 .. versionadded:: 14.1.0
1067
1068 You can generate a column value from other column value
1069 automatically. You can use an expression in
1070 :doc:`../grn_expr/script_syntax` how to generate a column value.
1071
1072 Here is an example how to define a generated column:
1073
1074 .. groonga-command
1075 .. include:: ../../example/reference/commands/column_create/generated_column_schema.log
1076 .. table_create \
1077 .. --name Posts \
1078 .. --flags TABLE_NO_KEY
1079 .. column_create \
1080 .. --table Posts \
1081 .. --name title_html \
1082 .. --flags COLUMN_SCALAR \
1083 .. --type ShortText
1084 .. column_create \
1085 .. --table Posts \
1086 .. --name title_text \
1087 .. --flags COLUMN_SCALAR \
1088 .. --type ShortText \
1089 .. --source title_html \
1090 .. --generator 'html_untag(title_html)'
1091
1092 ``Posts.title_text`` is a generated column. Its value is generated
1093 from a value of ``Posts.title_html``. ``--source title_html`` and
1094 ``--generator 'html_untag(title_html)'`` are the important parts.
1095
1096 ``--source title_html`` means that ``Posts.title_text`` uses
1097 ``Posts.title_html`` as source.
1098
1099 ``--generator 'html_untag(title_html)'`` means that
1100 ``Posts.title_text`` value is generated by evaluating
1101 ``html_untag(title_html)``. :doc:`../functions/html_untag` is a
1102 function that removes HTML tags from HTML text. ``html_untag("Hello
1103 <em>Groonga</em>")`` returns ``"Hello Groonga"``.
1104
1105 Let's load a value to ``Posts.title_html`` and see ``Posts.title_text``:
1106
1107 .. groonga-command
1108 .. include:: ../../example/reference/commands/column_create/generated_column_load.log
1109 .. load --table Posts
1110 .. [
1111 .. {"title_html", "Hello <em>Groonga</em>"}
1112 .. ]
1113 .. select --table Posts
1114
1115 You can see ``Posts.title_text`` has ``"Hello Groonga"``
1116 automatically.
1117
1118 Parameters
1119 ----------
1120
1121 This section describes all parameters.
1122
1123 Required parameters
1124 ^^^^^^^^^^^^^^^^^^^
1125
1126 There are some required parameters.
1127
1128 .. _column-create-table:
1129
1130 ``table``
1131 """""""""
1132
1133 Specifies an existing table name for the new column.
1134
1135 .. _column-create-name:
1136
1137 ``name``
1138 """"""""
1139
1140 Specifies the column name to be created.
1141
1142 The column name must be unique in the same table.
1143
1144 Here are available characters:
1145
1146 * ``0`` .. ``9`` (digit)
1147 * ``a`` .. ``z`` (alphabet, lower case)
1148 * ``A`` .. ``Z`` (alphabet, upper case)
1149 * ``#`` (hash)
1150 * ``@`` (at mark)
1151 * ``-`` (hyphen)
1152 * ``_`` (underscore) (NOTE: Underscore can't be used as the first
1153 character.)
1154
1155 You need to create a name with one or more the above characters. Note
1156 that you can't use ``_`` as the first character such as ``_name``.
1157
1158
1159 .. _column-create-flags:
1160
1161 ``flags``
1162 """""""""
1163
1164 Specifies the column type and column customize options.
1165
1166 Here are available flags:
1167
1168 .. list-table::
1169 :header-rows: 1
1170
1171 * - Flag
1172 - Description
1173
1174 * - ``COLUMN_SCALAR``
1175 - Scalar column. It can store one value. See also
1176 :doc:`/reference/columns/scalar` or
1177 :ref:`column-create-scalar`.
1178
1179 * - ``COLUMN_VECTOR``
1180 - Vector column. It can store multiple values. See also
1181 :doc:`/reference/columns/vector` or
1182 :ref:`column-create-vector`.
1183
1184 * - ``COLUMN_INDEX``
1185 - Index column. It stores data for fast search. See also
1186 :doc:`/reference/columns/index` or
1187 :ref:`column-create-index`.
1188
1189 * - ``COMPRESS_ZLIB``
1190 - It enables column value compression by zlib. You need Groonga
1191 that enables zlib support.
1192
1193 Compression by zlib is higher space efficiency than compression
1194 by LZ4. But compression by zlib is slower than compression by
1195 LZ4.
1196
1197 This flag is available only for ``COLUMN_SCALAR`` and
1198 ``COLUMN_VECTOR``.
1199
1200 * - ``COMPRESS_LZ4``
1201 - It enables column value compression by LZ4. You need Groonga
1202 that enables LZ4 support.
1203
1204 Compression by LZ4 is faster than compression by zlib. But
1205 compression by LZ4 is lower space efficiency than compression
1206 by zlib.
1207
1208 This flag is available only for ``COLUMN_SCALAR`` and
1209 ``COLUMN_VECTOR``.
1210
1211 * - ``COMPRESS_ZSTD``
1212 - It enables column value compression by Zstandard. You need
1213 Groonga that enables Zstandard support.
1214
1215 Compression by Zstandard is faster than compression by zlib and
1216 the same space efficiency as zlib.
1217
1218 This flag is available only for ``COLUMN_SCALAR`` and
1219 ``COLUMN_VECTOR``.
1220
1221 * - ``COMPRESS_FILTER_SHUFFLE``
1222 - .. versionadded:: 13.0.8
1223
1224 .. include:: compress_filter.rst
1225
1226 Here are a list of suitable data type for this filter.
1227
1228 This flag reorganize data based on a element of Nth byte.
1229
1230 First, 0th byte data of each element within the vector column
1231 would be gathered and be continuously placed. Then, 1st byte
1232 data would be handled as same as 0th byte data and all byte
1233 data would be as so repeatedly.
1234
1235 There are tendency for those compression algorithms such as
1236 ``COMPRESS_ZLIB``, ``COMPRESS_LZ4`` and ``COMPRESS_ZSTD`` to
1237 have the higher compression rate when the data has same values
1238 in continuance. The point for this flag is to produce data
1239 having same values in continuance by reorganizing data for
1240 every N byte.
1241
1242 In particular, it would work as below.
1243
1244 For example, there is the vector column ``[1, 1051, 515]`` in
1245 ``UInt16``. It would be as below representing in the little
1246 endien byte column.
1247
1248 .. code-block::
1249
1250 | Byte 0 | Byte 1 | | Byte 0 | Byte 1 | | Byte 0 | Byte 1 |
1251 |--------|--------| |--------|--------| |--------|--------|
1252 | 0x01 | 0x00 |, | 0x1b | 0x04 |, | 0x03 | 0x02 |
1253
1254 This flag is to produce the data as following by gathering
1255 values of ``Byte 0``, then of ``Byte 1`` from the above data.
1256 The action to gather values with every N Byte would be called
1257 shuffle from now on. Shuffling the above data would be as
1258 below.
1259
1260 .. code-block::
1261
1262 | Byte 0 | Byte 0 | Byte 0 | | Byte 1 | Byte 1 | Byte 1 |
1263 |--------|--------|--------| |--------|--------|--------|
1264 | 0x01 | 0x1b | 0x03 |, | 0x00 | 0x04 | 0x02 |
1265
1266 The point is whether there would be same values in continuance
1267 or not. Looking at the above example data, it is appeared to
1268 have no same values in continuance after shuffling. Those data
1269 are not suitable for this flag because it is not contributed to
1270 increase the compression rate even shuffling.
1271
1272 On the other hand, the vector column ``[1, 2, 3]`` in
1273 ``UInt16`` would be as following after shuffling. First for
1274 the explanation, ``[1, 2, 3]`` in ``UInt16`` would be
1275 represented as below in the little endien byte column.
1276
1277 .. code-block::
1278
1279 | Byte 0 | Byte 1 | | Byte 0 | Byte 1 | | Byte 0 | Byte 1 |
1280 |--------|--------| |--------|--------| |--------|--------|
1281 | 0x01 | 0x00 |, | 0x02 | 0x00 |, | 0x03 | 0x00 |
1282
1283
1284 And, after shuffling ``[1, 2, 3]`` in ``UInt16``, the data
1285 would be as below.
1286
1287 .. code-block::
1288
1289 | Byte 0 | Byte 0 | Byte 0 | | Byte 1 | Byte 1 | Byte 1 |
1290 |--------|--------|--------| |--------|--------|--------|
1291 | 0x01 | 0x02 | 0x03 |, | 0x00 | 0x00 | 0x00 |
1292
1293 After shuffling ``[1, 2, 3]`` in ``UInt16``, the date in ``Byte
1294 1`` would be all ``0x00``. It means there are same values in
1295 continuance. Thus, this data pattern is suitable for this flag
1296 because it would contribute to increase the compression rate.
1297
1298 In case of a floating-point number, the data having same the
1299 code part and the exponent part would be corresponded. In case
1300 of the IEEE 754 type single-precision floating-point format,
1301 code part would be placed at 31st bit, and exponent part would
1302 be placed at 32nd bit. There would be same values in
1303 continuance after shuffling the data if the code part and the
1304 upper 7 bit of exponent bit become same because the highest
1305 byte would be structured with the code part and the upper 7 bit
1306 of exponent bit.
1307
1308 For example, the data, ``[0.5, 0.6]`` in ``Float32``, would
1309 have same code bit and exponent part by representing in
1310 Single-precision floating-point format in IEEE 754 type as
1311 below.
1312
1313 .. code-block::
1314
1315 | fraction (23bit) | exponent (8bit) | sign (1bit) |
1316 |------------------------------|-----------------|-------------|
1317 | 0000 0000 0000 0000 0000 000 | 0111 1110 | 0 |
1318 | 0101 1001 1001 1001 1001 100 | 0111 1110 | 0 |
1319
1320 Shuffling the given data would have same values in continuance
1321 for ``Byte 3`` as below.
1322
1323 .. code-block::
1324
1325 | Byte 0 | Byte 0 | | Byte 1 | Byte 1 | | Byte 2 | Byte 2 | | Byte 3 | Byte 3 |
1326 |--------|--------| |--------|--------| |--------|--------| |--------|--------|
1327 | 0x00 | 0x9a |, | 0x00 | 0x99 |, | 0x00 | 0x19 |, | 0x3f | 0x3f |
1328
1329 In case of the ``Float`` / ``Float32`` type data, please refer
1330 to explanations for
1331 ``COMPRESS_FILTER_TRUNCATE_PRECISION_1BYTE`` and
1332 ``COMPRESS_FILTER_TRUNCATE_PRECISION_2BYTES`` since it is also
1333 possible to combine
1334 ``COMPRESS_FILTER_TRUNCATE_PRECISION_1BYTE`` or
1335 ``COMPRESS_FILTER_TRUNCATE_PRECISION_2BYTES``.
1336
1337 * - ``COMPRESS_FILTER_BYTE_DELTA``
1338 - .. versionadded:: 13.0.8
1339
1340 .. include:: compress_filter.rst
1341
1342 Here is what kind of the data being effective for this flag.
1343
1344 This flag is to calculate the difference between bytes of
1345 values to be compression targeted. As sample case of the
1346 vector column ``[1, 2, 3, 4, 5]`` in ``UInt8``, applying this
1347 flag would produce data would become ``[1, (2-1), (3-2), (4-3),
1348 (5-4)] = [1, 1, 1, 1, 1]``.
1349
1350 As noted above, it is trying to increase the compression rate
1351 by calculating increments and producing same values in
1352 continuance. The point is there would be same values in
1353 continuance after calculating the increments between each
1354 elements.
1355
1356 Thus, the data is not suitable to use for this flag if there
1357 would not be same values in continuance after calculating the
1358 increments. Here is the list of data pattern to have same
1359 values in continuance after calculating increments.
1360
1361 First pattern would be the data increased with constant
1362 interval such as ``[1, 2, 3, 4, 5]`` in ``UInt8``. The
1363 constant interval could be every ``10`` for ``[1, 11, 21, 31,
1364 41]`` in ``UInt8`` as long as the interval is same.
1365
1366 Next pattern would be the data having same values in
1367 continuance such as ``[5, 5, 5, 5, 5]`` in ``UInt8``. There
1368 would be ``0`` in continuance after calculating the increments
1369 of this data. In opposite, ``[1, 255, 2, 200, 1]`` in
1370 ``UInt8`` is not suitable for this flag because the data would
1371 not have same value in continuance after calculating the
1372 increments.
1373
1374 There would be a case to be able to increase the compression
1375 rate by combining ``COMPRESS_FILTER_SHUFFLE`` even though
1376 calculating increments would not have same value in
1377 continuance, or increments are too large.
1378
1379 For example, ``[4526677, 4592401, 4658217, 4723879]`` in
1380 ``UInt32`` would be ``[4526677, 65724, 65816, 65662]`` after
1381 only being applied ``COMPRESS_FILTER_BYTE_DELTA``. This data
1382 would not have values in continuance, and increments are large.
1383
1384 But applying ``COMPRESS_FILTER_SHUFFLE`` to this data would be
1385 different. And it will be explained in following. First for
1386 the explanation, ``[4526677, 4592401, 4658217, 4723879]`` in
1387 ``UInt32`` would be represent the byte column in the little
1388 endien as below.
1389
1390 .. code-block::
1391
1392 | Byte 0 | Byte 1 | Byte 2 | Byte 3 | | Byte 0 | Byte 1 | Byte 2 | Byte 3 | | Byte 0 | Byte 1 | Byte 2 | Byte 3 | | Byte 0 | Byte 1 | Byte 2 | Byte 3 |
1393 |--------|--------|--------|--------| |--------|--------|--------|--------| |--------|--------|--------|--------| |--------|--------|--------|--------|
1394 | 0x55 | 0x12 | 0x45 | 0x00 |, | 0x11 | 0x13 | 0x46 | 0x00 |, | 0x29 | 0x14 | 0x47 | 0x00 |, | 0xA7 | 0x14 | 0x48 | 0x00 |
1395
1396 Applying ``COMPRESS_FILTER_SHUFFLE`` to this data would be
1397 following byte columns.
1398
1399 .. code-block::
1400
1401 | Byte 0 | Byte 0 | Byte 0 | Byte 0 | | Byte 1 | Byte 1 | Byte 1 | Byte 1 | | Byte 2 | Byte 2 | Byte 2 | Byte 2 | | Byte 3 | Byte 3 | Byte 3 | Byte 3 |
1402 |--------|--------|--------|--------| |--------|--------|--------|--------| |--------|--------|--------|--------| |--------|--------|--------|--------|
1403 | 0x55 | 0x11 | 0x29 | 0xA7 |, | 0x12 | 0x13 | 0x14 | 0x14 |, | 0x45 | 0x46 | 0x47 | 0x48 |, | 0x00 | 0x00 | 0x00 | 0x00 |
1404
1405 Pay attention to the data of ``Byte 1``, ``Byte 2``, and ``Byte
1406 3`` after the shuffling. The data increments of ``Byte 1`` are
1407 ``[0x12, 0x01, 0x01, 0x00]``. The data increments of ``Byte 2``
1408 are ``[0x45, 0x01, 0x01, 0x01]``. The data increments of
1409 ``Byte 3`` are ``[0x00, 0x00, 0x00, 0x00]``. From those
1410 numbers, you can see the data increments have small values and
1411 have same values in continuance.
1412
1413 As you see these, the compression rate could be increase by
1414 combining ``COMPRESS_FILTER_SHUFFLE`` even if applying
1415 ``COMPRESS_FILTER_BYTE_DELTA`` did not change the rate.
1416
1417 Please note that ``COMPRESS_FILTER_SHUFFLE`` would not be
1418 effective for the 1 byte data because it is to gather the same
1419 byte from the data. (The 1 byte data would have same data
1420 column whether being shuffled or not.) Thus, in case of
1421 combining ``COMPRESS_FILTER_BYTE_DELTA`` and
1422 ``COMPRESS_FILTER_SHUFFLE``, please do not use data in ``Int8``
1423 / ``UInt8``. Only use for other type.
1424
1425 * - ``COMPRESS_FILTER_TRUNCATE_PRECISION_1BYTE``
1426 - .. versionadded:: 13.0.8
1427
1428 .. include:: compress_filter.rst
1429
1430 This flag can be used only for ``Float`` / ``Float32``. And it
1431 is expected to be combined with ``COMPRESS_FILTER_SHUFFLE`` .
1432
1433 Here is what kind of the data being effective for this flag.
1434
1435 This flag would drop the 1 byte of fraction from each vector
1436 column elements of ``Float`` / ``Float32`` type. Dropping the
1437 fraction means making all of the lower 1 byte of the
1438 floating-point number ``0``.
1439
1440 For example, ``[1.25, 3.67, 4.55]`` in ``Float32`` would be
1441 presented as following in the IEEE 754 format single-precision
1442 floating-point.
1443
1444 .. code-block::
1445
1446 | fraction (23bit) | exponent (8bit) | sign (1bit) |
1447 |------------------------------|-----------------|-------------|
1448 | 0000 0000 0000 0000 0000 010 | 1111 1110 | 0 |
1449 | 0001 0010 1000 0111 0101 011 | 0000 0001 | 0 |
1450 | 0101 1001 1001 1001 1000 100 | 1000 0001 | 0 |
1451
1452 Applying this flag make all lower 1 byte ``0``. And the data
1453 would be as below. Pay attention to all ``0`` for lower 1byte
1454 of fixed-point part.
1455
1456 .. code-block::
1457
1458 | fraction (23bit) | exponent (8bit) | sign (1bit) |
1459 |------------------------------|-----------------|-------------|
1460 | 0000 0000 0000 0000 0000 010 | 1111 1110 | 0 |
1461 | 0000 0000 1000 0111 0101 011 | 0000 0001 | 0 |
1462 | 0000 0000 1001 1001 1000 100 | 1000 0001 | 0 |
1463
1464 These actions are what would be done for single flag usage. As
1465 noted, this flag is expected to be combined with
1466 ``COLUMN_FILTER_SHUFFLE`` . Thus, by shuffling the data it is
1467 to expected increasing the compression rate after using the
1468 flag.
1469
1470 Applying ``COMPRESS_FILTER_TRUNCATE_PRECISION_1BYTE`` then
1471 shuffling would produce data as below.
1472
1473 .. code-block::
1474
1475 | Byte 0 | Byte 0 | Byte 0 | | Byte 1 | Byte 1 | Byte 1 | | Byte 2 | Byte 2 | Byte 2 | | Byte 3 | Byte 3 | Byte 3 |
1476 |--------|--------|--------| |--------|--------|--------| |--------|--------|--------| |--------|--------|--------|
1477 | 0x00 | 0x00 | 0x00 |, | 0x00 | 0xe1 | 0x99 |, | 0xa0 | 0x6a | 0x91 |, | 0x3f | 0x40 | 0x40 |
1478
1479 Pay attention to the ``Byte 0``. You can find the value ``0``
1480 in continuance for ``Byte 0``. If
1481 ``COMPRESS_FILTER_TRUNCATE_PRECISION_1BYTE`` was not applied
1482 and shuffled, the data would be as following table, there would
1483 be no same value in continuance for any bytes.
1484
1485 .. code-block::
1486
1487 | Byte 0 | Byte 0 | Byte 0 | | Byte 1 | Byte 1 | Byte 1 | | Byte 2 | Byte 2 | Byte 2 | | Byte 3 | Byte 3 | Byte 3 |
1488 |--------|--------|--------| |--------|--------|--------| |--------|--------|--------| |--------|--------|--------|
1489 | 0x00 | 0x48 | 0x9a |, | 0x00 | 0xe1 | 0x99 |, | 0xa0 | 0x6a | 0x91 |, | 0x3f | 0x40 | 0x40 |
1490
1491 Applying ``COMPRESS_FILTER_TRUNCATE_PRECISION_1BYTE`` to those
1492 data can be expected to increase the compression rate even if
1493 those data cannot increase the compression rate only with
1494 shuffling. However, note the data may be inaccurate since the
1495 fraction of the floating-point number is dropped for 1 byte.
1496
1497 * - ``COMPRESS_FILTER_TRUNCATE_PRECISION_2BYTES``
1498 - .. versionadded:: 13.0.8
1499
1500 .. include:: compress_filter.rst
1501
1502 This flag can be used only for ``Float`` / ``Float32``. And it
1503 is expected to be combined with ``COMPRESS_FILTER_SHUFFLE``.
1504
1505 Here is what kind of the data being effective for this flag.
1506
1507 This flag would drop the 2 bytes of fraction from each vector
1508 column elements of ``Float`` / ``Float32`` type. Dropping the
1509 fraction means making all of the lower 2 bytes of the
1510 floating-point number ``0``.
1511
1512 For example, ``[1.25, 3.67, 4.55]`` in ``Float32`` would be
1513 presented as following in the IEEE 754 format single-precision
1514 floating-point.
1515
1516 .. code-block::
1517
1518 | fraction (23bit) | exponent (8bit) | sign (1bit) |
1519 |------------------------------|-----------------|-------------|
1520 | 0000 0000 0000 0000 0000 010 | 1111 1110 | 0 |
1521 | 0001 0010 1000 0111 0101 011 | 0000 0001 | 0 |
1522 | 0101 1001 1001 1001 1000 100 | 1000 0001 | 0 |
1523
1524 Applying this flag make all lower 2 bytes ``0``. And the data
1525 would be as below. Pay attention to all ``0`` for lower 2
1526 bytes of fixed-point part.
1527
1528 .. code-block::
1529
1530 | fraction (23bit) | exponent (8bit) | sign (1bit) |
1531 |------------------------------|-----------------|-------------|
1532 | 0000 0000 0000 0000 0000 010 | 1111 1110 | 0 |
1533 | 0000 0000 0000 0000 0101 011 | 0000 0001 | 0 |
1534 | 0000 0000 0000 0000 1000 100 | 1000 0001 | 0 |
1535
1536 These actions are what would be done for single flag usage. As
1537 noted, this flag is expected to be combined with
1538 ``COLUMN_FILTER_SHUFFLE`` . Thus, by shuffling the data it is
1539 to expected increasing the compression rate after using the
1540 flag.
1541
1542 Applying ``COMPRESS_FILTER_TRUNCATE_PRECISION_2BYTE`` then
1543 shuffling would produce data as below.
1544
1545 .. code-block::
1546
1547 | Byte 0 | Byte 0 | Byte 0 | | Byte 1 | Byte 1 | Byte 1 | | Byte 2 | Byte 2 | Byte 2 | | Byte 3 | Byte 3 | Byte 3 |
1548 |--------|--------|--------| |--------|--------|--------| |--------|--------|--------| |--------|--------|--------|
1549 | 0x00 | 0x00 | 0x00 |, | 0x00 | 0x00 | 0x00 |, | 0xa0 | 0x6a | 0x91 |, | 0x3f | 0x40 | 0x40 |
1550
1551 Pay attention to the ``Byte 0`` and ``Byte 1``. You can find
1552 the value ``0`` in continuance for ``Byte 0`` and ``Byte1``.
1553
1554 If ``COMPRESS_FILTER_TRUNCATE_PRECISION_2BYTE`` was not applied
1555 and shuffled, the data would be as following table, there would
1556 be no same value in continuance for any bytes.
1557
1558 .. code-block::
1559
1560 | Byte 0 | Byte 0 | Byte 0 | | Byte 1 | Byte 1 | Byte 1 | | Byte 2 | Byte 2 | Byte 2 | | Byte 3 | Byte 3 | Byte 3 |
1561 |--------|--------|--------| |--------|--------|--------| |--------|--------|--------| |--------|--------|--------|
1562 | 0x00 | 0x48 | 0x9a |, | 0x00 | 0xe1 | 0x99 |, | 0xa0 | 0x6a | 0x91 |, | 0x3f | 0x40 | 0x40 |
1563
1564 Applying ``COMPRESS_FILTER_TRUNCATE_PRECISION_2BYTE`` to those
1565 data can be expected to increase the compression rate even if
1566 those data cannot increase the compression rate only with
1567 shuffling.
1568
1569 However, note the data may be inaccurate since the fraction of
1570 the floating-point number is dropped for 2 bytes.
1571
1572 * - ``WITH_SECTION``
1573 - It enables section support to index column.
1574
1575 If section support is enabled, you can support multiple
1576 documents in the same index column.
1577
1578 You must specify this flag to create a multiple columns index
1579 column. See also :ref:`column-create-index-multiple-columns` for
1580 details.
1581
1582 Section support requires additional spaces. If you don't need
1583 section support, you should not enable section support.
1584
1585 This flag is available only for ``COLUMN_INDEX``.
1586
1587 * - ``WITH_WEIGHT``
1588 - It enables weight support to vector column or index column.
1589
1590 If weight support is enabled for vector column, you can add
1591 weight for each element. If weight support is enabled for index
1592 column, you can add weight for each posting. They are useful to
1593 compute suitable search score.
1594
1595 You must specify this flag to use :ref:`select-adjuster`. See
1596 also :ref:`column-create-vector-weight` for details.
1597
1598 Weight support requires additional spaces. If you don't need
1599 weight support, you should not enable weight support.
1600
1601 This flag is available only for ``COLUMN_VECTOR`` or
1602 ``COLUMN_INDEX``.
1603
1604 * - ``WEIGHT_FLOAT32``
1605 - .. versionadded:: 10.0.3
1606
1607 You can use 32bit floating point instead of 32bit unsigned
1608 integer for weight value.
1609
1610 You also need to specify ``WITH_WEIGHT``.
1611
1612 This flag is available only for ``COLUMN_VECTOR`` or
1613 ``COLUMN_INDEX``.
1614
1615 * - ``WITH_POSITION``
1616 - It enables position support to index column. It means that the
1617 index column is full inverted index. (Index column is
1618 implemented as inverted index.)
1619
1620 If position support is enabled, you can add position in the
1621 document for each posting. It's required for phrase search. It
1622 means that index column for full text search must enable
1623 position support because most full text search uses phrase
1624 search.
1625
1626 You must specify this flag to create a full text search index
1627 column. See also :ref:`column-create-index-full-text-search` for
1628 details.
1629
1630 Position support requires additional spaces. If you don't need
1631 position support, you should not enable position support.
1632
1633 This flag is available only for ``COLUMN_INDEX``.
1634
1635 * - ``INDEX_SMALL``
1636 - .. versionadded:: 6.0.8
1637
1638 It requires to create a small index column.
1639
1640 If index target data are small, small index column is enough.
1641 Small index column uses fewer memory than a normal index column
1642 or a medium index column. See also
1643 :ref:`column-create-index-small` for knowing what are "small
1644 data" and how to use this flag.
1645
1646 This flag is available only for ``COLUMN_INDEX``.
1647
1648 * - ``INDEX_MEDIUM``
1649 - .. versionadded:: 6.0.8
1650
1651 It requires to create a medium index column.
1652
1653 If index target data are medium, medium index column is enough.
1654 Medium index column uses fewer memory than a normal index
1655 column. See also :ref:`column-create-index-medium` for knowing
1656 what are "medium data" and how to use this flag.
1657
1658 This flag is available only for ``COLUMN_INDEX``.
1659
1660 * - ``INDEX_LARGE``
1661 - .. versionadded:: 9.0.2
1662
1663 It requires to create a large index column.
1664
1665 If index target data are large, you need to use large index
1666 column. Large index column uses more memory than a normal index
1667 column but accepts more data than a normal index column. See
1668 also :ref:`column-create-index-large` for knowing what are
1669 "large data" and how to use this flag.
1670
1671 This flag is available only for ``COLUMN_INDEX``.
1672
1673 * - ``MISSING_ADD``
1674 - .. versionadded:: 12.0.2
1675
1676 You can't specify multiple ``MISSING_*`` flags. They are
1677 exclusive.
1678
1679 This is meaningful only for reference scalar and vector
1680 columns.
1681
1682 If this flag is specified and nonexistent key in the referred
1683 table is specified to the column's value, a new record is
1684 created in the referred table automatically.
1685
1686 If you don't specify any ``MISSING_*`` flag, ``MISSING_ADD`` is
1687 used as the default.
1688
1689 See also :ref:`column-create-missing-mode`.
1690
1691 This flag is available only for ``COLUMN_SCALAR`` and
1692 ``COLUMN_VECTOR``.
1693
1694 * - ``MISSING_IGNORE``
1695 - .. versionadded:: 12.0.2
1696
1697 You can't specify multiple ``MISSING_*`` flags. They are
1698 exclusive.
1699
1700 This is meaningful only for reference scalar and vector
1701 columns.
1702
1703 If this flag is specified and nonexistent key in the referred
1704 table is specified to the column's value, the value is just
1705 ignored. If the column is a scalar column, ``GRN_ID_NIL``
1706 (``0``) is stored because Groonga doesn't support the NULL
1707 value. If the column is a vector column, the element is just
1708 removed from the value. For example, ``["existent1",
1709 "nonexistent", "existent2"]`` is set to the vector column and
1710 ``"nonexistent"`` record doesn't exist in the referred table,
1711 ``["existent1", "existent2"]`` are set to the vector column.
1712
1713 See also :ref:`column-create-missing-mode`.
1714
1715 This flag is available only for ``COLUMN_SCALAR`` and
1716 ``COLUMN_VECTOR``.
1717
1718 * - ``MISSING_NIL``
1719 - .. versionadded:: 12.0.2
1720
1721 You can't specify multiple ``MISSING_*`` flags. They are
1722 exclusive.
1723
1724 This is meaningful only for reference scalar and vector
1725 columns.
1726
1727 If this flag is specified and nonexistent key in the referred
1728 table is specified to the column's value, the value is replaced
1729 with ``GRN_ID_NIL`` (``0``).
1730
1731 See also :ref:`column-create-missing-mode`.
1732
1733 This flag is available only for ``COLUMN_SCALAR`` and
1734 ``COLUMN_VECTOR``.
1735
1736 * - ``INVALID_ERROR``
1737 - .. versionadded:: 12.0.2
1738
1739 You can't specify multiple ``INVALID_*`` flags. They are
1740 exclusive.
1741
1742 If this flag is specified and an invalid value is specified, an
1743 error is reported to :ref:`process-log`.
1744
1745 For example, ``"STRING"`` for ``Int32`` column is an invalid
1746 value.
1747
1748 If the column is a scalar column, :doc:`load` also reports an
1749 error.
1750
1751 If the column is a vector column, :doc:`load` doesn't reports
1752 an error but invalid values in a vector value are removed or
1753 replaced with ``GRN_ID_NIL`` (``0``) depending on ``MISSING_*``
1754 flag of the column.
1755
1756 .. note::
1757
1758 This is an incompatible change at 12.0.2. :doc:`load`
1759 also reports an error for a vector column before 12.0.2.
1760
1761 If you don't specify any ``INVALID_*`` flag, ``INVALID_ERROR`` is
1762 used as the default.
1763
1764 See also :ref:`column-create-invalid-mode`.
1765
1766 This flag is available only for ``COLUMN_SCALAR`` and
1767 ``COLUMN_VECTOR``.
1768
1769 * - ``INVALID_WARN``
1770 - .. versionadded:: 12.0.2
1771
1772 You can't specify multiple ``INVALID_*`` flags. They are
1773 exclusive.
1774
1775 If this flag is specified and an invalid value is specified, a
1776 warning is reported to :ref:`process-log` but no error is
1777 reported.
1778
1779 For example, ``"STRING"`` for ``Int32`` column is an invalid
1780 value.
1781
1782 If the column is a vector column, invalid values in a vector
1783 value are removed or replaced with ``GRN_ID_NIL`` (``0``)
1784 depending on ``MISSING_*`` flag of the column.
1785
1786 See also :ref:`column-create-invalid-mode`.
1787
1788 This flag is available only for ``COLUMN_SCALAR`` and
1789 ``COLUMN_VECTOR``.
1790
1791 * - ``INVALID_IGNORE``
1792 - .. versionadded:: 12.0.2
1793
1794 You can't specify multiple ``INVALID_*`` flags. They are
1795 exclusive.
1796
1797 If this flag is specified and an invalid value is specified,
1798 it's just ignored.
1799
1800 For example, ``"STRING"`` for ``Int32`` column is an invalid
1801 value.
1802
1803 If the column is a vector column, invalid values in a vector
1804 value are removed or replaced with ``GRN_ID_NIL`` (``0``)
1805 depending on ``MISSING_*`` flag of the column.
1806
1807 See also :ref:`column-create-invalid-mode`.
1808
1809 This flag is available only for ``COLUMN_SCALAR`` and
1810 ``COLUMN_VECTOR``.
1811
1812 You must specify one of ``COLUMN_${TYPE}`` flags. You can't specify
1813 two or more ``COLUMN_${TYPE}`` flags. For example,
1814 ``COLUMN_SCALAR|COLUMN_VECTOR`` is invalid.
1815
1816 You can combine flags with ``|`` (vertical bar) such as
1817 ``COLUMN_INDEX|WITH_SECTION|WITH_POSITION``.
1818
1819 .. _column-create-type:
1820
1821 ``type``
1822 """"""""
1823
1824 Specifies type of the column value.
1825
1826 If the column is scalar column or vector column, here are available
1827 types:
1828
1829 * Builtin types described in :doc:`/reference/types`
1830 * Tables defined by users
1831
1832 If the column is index column, here are available types:
1833
1834 * Tables defined by users
1835
1836 See also the followings:
1837
1838 * :ref:`column-create-scalar`
1839 * :ref:`column-create-vector`
1840 * :ref:`column-create-reference`
1841 * :ref:`column-create-index`
1842
1843 Optional parameters
1844 ^^^^^^^^^^^^^^^^^^^
1845
1846 There is an optional parameter.
1847
1848 .. _column-create-source:
1849
1850 ``source``
1851 """"""""""
1852
1853 Specifies index target columns. You can specify one or more columns to
1854 the ``source`` parameter.
1855
1856 This parameter is only available for index column.
1857
1858 You can only specify columns of the table specified as
1859 :ref:`column-create-type`. You can also use the ``_key`` pseudo column
1860 for specifying the table key as index target.
1861
1862 If you specify multiple columns to the ``source`` parameter, separate
1863 columns with ``,`` (comma) such as ``_key,roles``.
1864
1865 ``path``
1866 """"""""
1867
1868 .. versionadded:: 10.0.7
1869
1870 Specifies a path for storing a column.
1871
1872 This option is useful if you want to store a column that
1873 you often use to fast storage (e.g. SSD) and store it that you don't often
1874 use to slow storage (e.g. HDD).
1875
1876 You can use a relative path or an absolute path in this option.
1877 If you specify a relative path, it is resolved from the current directory for the ``groonga`` process.
1878
1879 The default value is none.
1880
1881 .. _column-create-generator:
1882
1883 ``generator``
1884 """""""""""""
1885
1886 .. versionadded:: 14.1.0
1887
1888 Specifies a generator expression in :doc:`../grn_expr/script_syntax`
1889 that is used to generate column value automatically.
1890
1891 This option is useful if you want to generate a column value from
1892 other column value automatically.
1893
1894 The default value is none.
1895
1896 .. seealso:: :ref:`column-create-generated-column`
1897
1898 .. _column-create-progress-log-level:
1899
1900 ``progress_log_level``
1901 ^^^^^^^^^^^^^^^^^^^^^^
1902
1903 .. versionadded:: 15.2.1
1904
1905 Specifies the log level of progress logs.
1906
1907 You can view the progress log during :ref:`offline-index-construction` .
1908
1909 The default log level is ``debug``.
1910 This means you must enable debug level logging to view progress logs.
1911
1912 If you set the log level to ``notice``, you can view progress logs
1913 without other debug logs. See :ref:`log-level-level` for available log
1914 levels.
1915
1916 The default is ``debug``.
1917
1918 Example::
1919
1920 column_create \
1921 --table Ages \
1922 --name people_age_index \
1923 --flags COLUMN_INDEX \
1924 --type People \
1925 --source age \
1926 --progress_log_level notice
1927
1928 Return value
1929 ------------
1930
1931 ``column_create`` returns ``true`` as body on success such as::
1932
1933 [HEADER, true]
1934
1935 If ``column_create`` fails, ``column_create`` returns ``false`` as
1936 body::
1937
1938 [HEADER, false]
1939
1940 Error details are in ``HEADER``.
1941
1942 See :doc:`/reference/command/output_format` for ``HEADER``.
1943
1944 See also
1945 --------
1946
1947 * :doc:`/reference/column`
1948 * :doc:`/reference/commands/table_create`
1949 * :doc:`/reference/command/output_format`