File: table_create.rst

package info (click to toggle)
groonga 9.0.0-1%2Bdeb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 101,496 kB
  • sloc: ansic: 608,707; ruby: 35,042; xml: 23,643; cpp: 10,319; sh: 7,453; yacc: 5,968; python: 3,033; makefile: 2,609; perl: 133
file content (381 lines) | stat: -rw-r--r-- 10,934 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
.. -*- rst -*-

.. highlightlang:: none

.. groonga-command
.. database: commands_table_create

``table_create``
================

Summary
-------

``table_create`` creates a new table in the current database. You need
to create one or more tables to store and search data.

See :doc:`/reference/tables` for table details.

Syntax
------

This command takes many parameters.

The required parameter is only ``name`` and otehrs are optional::

  table_create name
               [flags=TABLE_HASH_KEY]
               [key_type=null]
               [value_type=null]
               [default_tokenizer=null]
               [normalizer=null]
               [token_filters=null]

Usage
-----

This section describes about the followings:

  * :ref:`table-create-data-store`
  * :ref:`table-create-large-data-store`
  * :ref:`table-create-lexicon`
  * :ref:`table-create-tag-index-table`
  * :ref:`table-create-range-index-table`

.. _table-create-data-store:

Create data store table
^^^^^^^^^^^^^^^^^^^^^^^

You can use all table types for data store table. See
:doc:`/reference/tables` for all table types.

Table type is specified as ``TABLE_${TYPE}`` to ``flags`` parameter.

Here is an example to create ``TABLE_NO_KEY`` table:

.. groonga-command
.. include:: ../../example/reference/commands/table_create/data_store_table_no_key.log
.. table_create Logs TABLE_NO_KEY

The ``table_create`` command creates a table that is named ``Logs``
and is ``TABLE_NO_KEY`` type.

If your records aren't searched by key, ``TABLE_NO_KEY`` type table is
suitable. Because ``TABLE_NO_KEY`` doesn't support key but it is fast
and small table. Storing logs into Groonga database is the case.

If your records are searched by key or referenced by one or more
columns, ``TABLE_NO_KEY`` type isn't suitable. Lexicon for fulltext
search is the case.

.. _table-create-large-data-store:

Create large data store table
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

If you want to store many large keys, your table may not be able to
store them. If total key data is larger than 4GiB, you can't store all
key data into your table by default.

You can expand the maximum total key size to 1TiB from 4GiB by
``KEY_LARGE`` flag. ``KEY_LARGE`` flag can be used with only
``TABLE_HASH_KEY``. You can't use ``KEY_LARGE`` flag with
``TABLE_NO_KEY``, ``TABLE_PAT_KEY`` nor ``TABLE_DAT_KEY``.

Here is an example to create a table that can store many large keys:

.. groonga-command
.. include:: ../../example/reference/commands/table_create/large_data_store_table.log
.. table_create Paths TABLE_HASH_KEY|KEY_LARGE ShortText

The ``table_create`` command creates a table that is named ``Paths``
and is ``TABLE_HASH_KEY`` type. The ``Paths`` table can store many
large keys.

.. _table-create-lexicon:

Create lexicon
^^^^^^^^^^^^^^

You can use all table types except ``TABLE_NO_KEY`` for lexicon.
Lexicon needs key support but ``TABLE_NO_KEY`` doesn't support key.

Here is an example to create ``TABLE_PAT_KEY`` table:

.. groonga-command
.. include:: ../../example/reference/commands/table_create/lexicon_pat_key.log
.. table_create Lexicon TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram --normalizer NormalizerAuto

The ``table_create`` command creates the following table:

* The table is named ``Lexicon``.
* The table is ``TABLE_PAT_KEY`` type table.
* The table's key is ``ShortText`` type.
* The table uses ``TokenBigram`` tokenizer to extract tokens from a
  normalized text.
* The table uses ``NormalizerAuto`` normalizer to normalize a text.

``TABLE_PAT_KEY`` is suitable table type for lexicon. Lexicon is used
for fulltext search.

In fulltext search, predictive search may be used for fuzzy
search. Predictive search is supported by ``TABLE_PAT_KEY`` and
``TABLE_DAT_KEY``.

Lexicon has many keys because a fulltext target text has many
tokens. Table that has many keys should consider table size because
large table requires large memory. Requiring large memory causes disk
I/O. It blocks fast search. So table size is important for a table
that has many keys. ``TABLE_PAT_KEY`` is less table size than
``TABLE_DAT_KEY``.

Because of the above reasons, ``TABLE_PAT_KEY`` is suitable table type
for lexicon.

.. _table-create-tag-index-table:

Create tag index table
^^^^^^^^^^^^^^^^^^^^^^

You can use all table types except ``TABLE_NO_KEY`` for tag index
table. Tag index table needs key support but ``TABLE_NO_KEY`` doesn't
support key.

Here is an example to create ``TABLE_HASH_KEY`` table:

.. groonga-command
.. include:: ../../example/reference/commands/table_create/tag_index_table_hash_key.log
.. table_create Tags TABLE_HASH_KEY ShortText

The ``table_create`` command creates a table that is named ``Tags``,
is ``TABLE_HASH_KEY`` type and has ``ShortText`` type key.

``TABLE_HASH_KEY`` or ``TABLE_DAT_KEY`` are suitable table types for
tag index table.

If you need only exact match tag search feature, ``TABLE_HASH_KEY`` is
suitable. It is the common case.

If you also need predictive tag search feature (for example, searching
``"groonga"`` by ``"gr"`` keyword.), ``TABLE_DAT_KEY`` is suitable.
``TABLE_DAT_KEY`` is large table size but it is not important because
the number of tags will not be large.

.. _table-create-range-index-table:

Create range index table
^^^^^^^^^^^^^^^^^^^^^^^^

You can use ``TABLE_PAT_KEY`` and ``TABLE_DAT_KEY`` table types for
range index table. Range index table needs range search support but
``TABLE_NO_KEY`` and ``TABLE_HASH_KEY`` don't support it.

Here is an example to create ``TABLE_DAT_KEY`` table:

.. groonga-command
.. include:: ../../example/reference/commands/table_create/range_index_table_dat_key.log
.. table_create Ages TABLE_DAT_KEY UInt32

The ``table_create`` command creates a table that is named ``Ages``,
is ``TABLE_DAT_KEY`` type and has ``UInt32`` type key.

``TABLE_PAT_KEY`` and ``TABLE_DAT_KEY`` are suitable table types for
range index table.

If you don't have many indexed items, ``TABLE_DAT_KEY`` is
suitable. Index for age is the case in the above example. Index for
age will have only 0-100 items because human doesn't live so long.

If you have many indexed items, ``TABLE_PAT_KEY`` is suitable. Because
``TABLE_PAT_KEY`` is smaller than ``TABLE_DAT_KEY``.

Parameters
----------

This section describes all parameters.

Required parameters
^^^^^^^^^^^^^^^^^^^

There is only one required parameter.

.. _table-create-name:

``name``
""""""""

Specifies a table name to be created. ``name`` must be specified.

Here are available characters:

* ``0`` .. ``9`` (digit)
* ``a`` .. ``z`` (alphabet, lower case)
* ``A`` .. ``Z`` (alphabet, upper case)
* ``#`` (hash)
* ``@`` (at mark)
* ``-`` (hyphen)
* ``_`` (underscore) (NOTE: Underscore can't be used as the first
  character.)

You need to create a name with one or more the above characters. Note
that you can't use ``_`` as the first character such as ``_name``.

Optional parameters
^^^^^^^^^^^^^^^^^^^

There are some optional parameters.

.. _table-create-flags:

``flags``
"""""""""

Specifies a table type and table customize options.

Here are available flags:

.. list-table::
   :header-rows: 1

   * - Flag
     - Description
   * - ``TABLE_NO_KEY``
     - Array table. See also :ref:`table-no-key`.
   * - ``TABLE_HASH_KEY``
     - Hash table. See also :ref:`table-hash-key`.
   * - ``TABLE_PAT_KEY``
     - Patricia trie. See also :ref:`table-pat-key`.
   * - ``TABLE_DAT_KEY``
     - Double array trie. See also :ref:`table-dat-key`.
   * - ``KEY_WITH_SIS``
     - Enable Semi Infinite String. Require ``TABLE_PAT_KEY``.
   * - ``KEY_LARGE``
     - Expand the maximum total key size to 1TiB from 4GiB. Require
       ``TABLE_HASH_KEY``.

.. note::
   Since Groonga 2.1.0 ``KEY_NORMALIZE`` flag is deprecated. Use
   ``normalizer`` option with ``NormalizerAuto`` instead.

You must specify one of ``TABLE_${TYPE}`` flags. You can't specify two
or more ``TABLE_${TYPE}`` flags. For example,
``TABLE_NO_KEY|TABLE_HASH_KEY`` is invalid.

You can combine flags with ``|`` (vertical bar) such as
``TABLE_PAT_KEY|KEY_WITH_SIS``.

See :doc:`/reference/tables` for difference between table types.

The default flags are ``TABLE_HASH_KEY``.

.. _table-create-key-type:

``key_type``
""""""""""""

Specifies key type.

If you specify ``TABLE_HASH_KEY``, ``TABLE_PAT_KEY`` or
``TABLE_DAT_KEY`` as ``flags`` parameter, you need to specify
``key_type`` option.

See :doc:`/reference/types` for all types.

The default value is none.

.. _table-create-value-type:

``value_type``
""""""""""""""

Specifies value type.

You can use value when you specify ``TABLE_NO_KEY``,
``TABLE_HASH_KEY`` or ``TABLE_PAT_KEY`` as ``flags`` parameter. Value
type must be a fixed size type. For example, ``UInt32`` can be used
but ``ShortText`` cannot be used. Use columns instead of value.

The default value is none.

.. _table-create-default-tokenizer:

``default_tokenizer``
"""""""""""""""""""""

Specifies the default tokenizer that is used on searching and data
loading.

You must specify ``default_tokenizer`` for a table that is used for
lexicon of fulltext search index. See :doc:`/reference/tokenizers` for
available tokenizers. You must choose a tokenizer from the list for
fulltext search.

You don't need to specify ``default_tokenizer`` in the following
cases:

  * You don't use the table as a lexicon.

  * You use the table as a lexicon but you don't need fulltext
    search. For example:

      * Index target data isn't text data such as ``Int32`` and ``Time``.
      * You just need exact match search, prefix search and so on.

You can't use ``default_tokenizer`` with ``TABLE_NO_KEY`` flag because
a table that uses ``TABLE_NO_KEY`` flag can't be used as lexicon.

You must specify ``TABLE_HASH_KEY``, ``TABLE_PAT_KEY``,
``TABLE_DAT_KEY`` to :ref:`table-create-flags` when you want to use
the table as a lexicon.

The default value is none.

.. _table-create-normalizer:

``normalizer``
""""""""""""""

Specifies a normalizer that is used to normalize key.

You cannot use ``normalizer`` with ``TABLE_NO_KEY`` because
``TABLE_NO_KEY`` doesn't support key.

See :doc:`/reference/normalizers` for all normalizsers.

The default value is none.

.. _table-create-token-filters:

``token_filters``
"""""""""""""""""

Specifies token filters separated by ``,``.
Token filters are used to process tokens.

You cannot use ``token_filters`` with ``TABLE_NO_KEY`` because
``TABLE_NO_KEY`` doesn't support key.

See :doc:`/reference/token_filters` for all token filters.

The default value is none.

Return value
------------

``table_create`` returns ``true`` as body on success such as::

  [HEADER, true]

If ``table_create`` fails, error details are in ``HEADER``.

See :doc:`/reference/command/output_format` for ``HEADER``.

See also
--------

* :doc:`/reference/tables`
* :doc:`/reference/commands/column_create`
* :doc:`/reference/tokenizers`
* :doc:`/reference/normalizers`
* :doc:`/reference/command/output_format`