| 1 |
.. -*- rst -*- |
| 2 |
|
| 3 |
.. groonga-command |
| 4 |
.. database: commands_table_create |
| 5 |
|
| 6 |
``table_create`` |
| 7 |
================ |
| 8 |
|
| 9 |
Summary |
| 10 |
------- |
| 11 |
|
| 12 |
``table_create`` creates a new table in the current database. You need |
| 13 |
to create one or more tables to store and search data. |
| 14 |
|
| 15 |
See :doc:`/reference/tables` for table details. |
| 16 |
|
| 17 |
Syntax |
| 18 |
------ |
| 19 |
|
| 20 |
This command takes many parameters. |
| 21 |
|
| 22 |
The required parameter is only ``name`` and otehrs are optional:: |
| 23 |
|
| 24 |
table_create name |
| 25 |
[flags=TABLE_HASH_KEY] |
| 26 |
[key_type=null] |
| 27 |
[value_type=null] |
| 28 |
[default_tokenizer=null] |
| 29 |
[normalizer=null] |
| 30 |
[token_filters=null] |
| 31 |
[extractors=null] |
| 32 |
[path=null] |
| 33 |
|
| 34 |
Usage |
| 35 |
----- |
| 36 |
|
| 37 |
This section describes about the followings: |
| 38 |
|
| 39 |
* :ref:`table-create-data-store` |
| 40 |
* :ref:`table-create-large-data-store` |
| 41 |
* :ref:`table-create-lexicon` |
| 42 |
* :ref:`table-create-tag-index-table` |
| 43 |
* :ref:`table-create-range-index-table` |
| 44 |
|
| 45 |
.. _table-create-data-store: |
| 46 |
|
| 47 |
Create data store table |
| 48 |
^^^^^^^^^^^^^^^^^^^^^^^ |
| 49 |
|
| 50 |
You can use all table types for data store table. See |
| 51 |
:doc:`/reference/tables` for all table types. |
| 52 |
|
| 53 |
Table type is specified as ``TABLE_${TYPE}`` to ``flags`` parameter. |
| 54 |
|
| 55 |
Here is an example to create ``TABLE_NO_KEY`` table: |
| 56 |
|
| 57 |
.. groonga-command |
| 58 |
.. include:: ../../example/reference/commands/table_create/data_store_table_no_key.log |
| 59 |
.. table_create Logs TABLE_NO_KEY |
| 60 |
|
| 61 |
The ``table_create`` command creates a table that is named ``Logs`` |
| 62 |
and is ``TABLE_NO_KEY`` type. |
| 63 |
|
| 64 |
If your records aren't searched by key, ``TABLE_NO_KEY`` type table is |
| 65 |
suitable. Because ``TABLE_NO_KEY`` doesn't support key but it is fast |
| 66 |
and small table. Storing logs into Groonga database is the case. |
| 67 |
|
| 68 |
If your records are searched by key or referenced by one or more |
| 69 |
columns, ``TABLE_NO_KEY`` type isn't suitable. Lexicon for fulltext |
| 70 |
search is the case. |
| 71 |
|
| 72 |
.. _table-create-large-data-store: |
| 73 |
|
| 74 |
Create large data store table |
| 75 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 76 |
|
| 77 |
If you want to store many large keys, your table may not be able to |
| 78 |
store them. If total key data is larger than 4GiB, you can't store all |
| 79 |
key data into your table by default. |
| 80 |
|
| 81 |
.. versionadded:: 15.1.5 |
| 82 |
|
| 83 |
``TABLE_PAT_KEY`` also supports ``KEY_LARGE`` flag. |
| 84 |
|
| 85 |
You can expand the maximum total key size to 1TiB from 4GiB by |
| 86 |
``KEY_LARGE`` flag. ``KEY_LARGE`` flag can be used with |
| 87 |
``TABLE_HASH_KEY`` or ``TABLE_PAT_KEY``. You can't use ``KEY_LARGE`` flag with |
| 88 |
``TABLE_NO_KEY`` nor ``TABLE_DAT_KEY``. |
| 89 |
|
| 90 |
Here is an example to create a table that can store many large keys: |
| 91 |
|
| 92 |
.. groonga-command |
| 93 |
.. include:: ../../example/reference/commands/table_create/large_data_store_table.log |
| 94 |
.. table_create Paths TABLE_HASH_KEY|KEY_LARGE ShortText |
| 95 |
|
| 96 |
The ``table_create`` command creates a table that is named ``Paths`` |
| 97 |
and is ``TABLE_HASH_KEY`` type. The ``Paths`` table can store many |
| 98 |
large keys. |
| 99 |
|
| 100 |
The above example is ``TABLE_HASH_KEY`` case even if a table is ``TABLE_PAT_KEY``, you can set ``KEY_LARGE`` flag in the same way. |
| 101 |
|
| 102 |
.. _table-create-lexicon: |
| 103 |
|
| 104 |
Create lexicon |
| 105 |
^^^^^^^^^^^^^^ |
| 106 |
|
| 107 |
You can use all table types except ``TABLE_NO_KEY`` for lexicon. |
| 108 |
Lexicon needs key support but ``TABLE_NO_KEY`` doesn't support key. |
| 109 |
|
| 110 |
Here is an example to create ``TABLE_PAT_KEY`` table: |
| 111 |
|
| 112 |
.. groonga-command |
| 113 |
.. include:: ../../example/reference/commands/table_create/lexicon_pat_key.log |
| 114 |
.. table_create Lexicon TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram --normalizer NormalizerAuto |
| 115 |
|
| 116 |
The ``table_create`` command creates the following table: |
| 117 |
|
| 118 |
* The table is named ``Lexicon``. |
| 119 |
* The table is ``TABLE_PAT_KEY`` type table. |
| 120 |
* The table's key is ``ShortText`` type. |
| 121 |
* The table uses ``TokenBigram`` tokenizer to extract tokens from a |
| 122 |
normalized text. |
| 123 |
* The table uses ``NormalizerAuto`` normalizer to normalize a text. |
| 124 |
|
| 125 |
``TABLE_PAT_KEY`` is suitable table type for lexicon. Lexicon is used |
| 126 |
for fulltext search. |
| 127 |
|
| 128 |
In fulltext search, predictive search may be used for fuzzy |
| 129 |
search. Predictive search is supported by ``TABLE_PAT_KEY`` and |
| 130 |
``TABLE_DAT_KEY``. |
| 131 |
|
| 132 |
Lexicon has many keys because a fulltext target text has many |
| 133 |
tokens. Table that has many keys should consider table size because |
| 134 |
large table requires large memory. Requiring large memory causes disk |
| 135 |
I/O. It blocks fast search. So table size is important for a table |
| 136 |
that has many keys. ``TABLE_PAT_KEY`` is less table size than |
| 137 |
``TABLE_DAT_KEY``. |
| 138 |
|
| 139 |
Because of the above reasons, ``TABLE_PAT_KEY`` is suitable table type |
| 140 |
for lexicon. |
| 141 |
|
| 142 |
.. _table-create-tag-index-table: |
| 143 |
|
| 144 |
Create tag index table |
| 145 |
^^^^^^^^^^^^^^^^^^^^^^ |
| 146 |
|
| 147 |
You can use all table types except ``TABLE_NO_KEY`` for tag index |
| 148 |
table. Tag index table needs key support but ``TABLE_NO_KEY`` doesn't |
| 149 |
support key. |
| 150 |
|
| 151 |
Here is an example to create ``TABLE_HASH_KEY`` table: |
| 152 |
|
| 153 |
.. groonga-command |
| 154 |
.. include:: ../../example/reference/commands/table_create/tag_index_table_hash_key.log |
| 155 |
.. table_create Tags TABLE_HASH_KEY ShortText |
| 156 |
|
| 157 |
The ``table_create`` command creates a table that is named ``Tags``, |
| 158 |
is ``TABLE_HASH_KEY`` type and has ``ShortText`` type key. |
| 159 |
|
| 160 |
``TABLE_HASH_KEY`` or ``TABLE_DAT_KEY`` are suitable table types for |
| 161 |
tag index table. |
| 162 |
|
| 163 |
If you need only exact match tag search feature, ``TABLE_HASH_KEY`` is |
| 164 |
suitable. It is the common case. |
| 165 |
|
| 166 |
If you also need predictive tag search feature (for example, searching |
| 167 |
``"groonga"`` by ``"gr"`` keyword.), ``TABLE_DAT_KEY`` is suitable. |
| 168 |
``TABLE_DAT_KEY`` is large table size but it is not important because |
| 169 |
the number of tags will not be large. |
| 170 |
|
| 171 |
.. _table-create-range-index-table: |
| 172 |
|
| 173 |
Create range index table |
| 174 |
^^^^^^^^^^^^^^^^^^^^^^^^ |
| 175 |
|
| 176 |
You can use ``TABLE_PAT_KEY`` and ``TABLE_DAT_KEY`` table types for |
| 177 |
range index table. Range index table needs range search support but |
| 178 |
``TABLE_NO_KEY`` and ``TABLE_HASH_KEY`` don't support it. |
| 179 |
|
| 180 |
Here is an example to create ``TABLE_DAT_KEY`` table: |
| 181 |
|
| 182 |
.. groonga-command |
| 183 |
.. include:: ../../example/reference/commands/table_create/range_index_table_dat_key.log |
| 184 |
.. table_create Ages TABLE_DAT_KEY UInt32 |
| 185 |
|
| 186 |
The ``table_create`` command creates a table that is named ``Ages``, |
| 187 |
is ``TABLE_DAT_KEY`` type and has ``UInt32`` type key. |
| 188 |
|
| 189 |
``TABLE_PAT_KEY`` and ``TABLE_DAT_KEY`` are suitable table types for |
| 190 |
range index table. |
| 191 |
|
| 192 |
If you don't have many indexed items, ``TABLE_DAT_KEY`` is |
| 193 |
suitable. Index for age is the case in the above example. Index for |
| 194 |
age will have only 0-100 items because human doesn't live so long. |
| 195 |
|
| 196 |
If you have many indexed items, ``TABLE_PAT_KEY`` is suitable. Because |
| 197 |
``TABLE_PAT_KEY`` is smaller than ``TABLE_DAT_KEY``. |
| 198 |
|
| 199 |
Parameters |
| 200 |
---------- |
| 201 |
|
| 202 |
This section describes all parameters. |
| 203 |
|
| 204 |
Required parameters |
| 205 |
^^^^^^^^^^^^^^^^^^^ |
| 206 |
|
| 207 |
There is only one required parameter. |
| 208 |
|
| 209 |
.. _table-create-name: |
| 210 |
|
| 211 |
``name`` |
| 212 |
"""""""" |
| 213 |
|
| 214 |
Specifies a table name to be created. ``name`` must be specified. |
| 215 |
|
| 216 |
Here are available characters: |
| 217 |
|
| 218 |
* ``0`` .. ``9`` (digit) |
| 219 |
* ``a`` .. ``z`` (alphabet, lower case) |
| 220 |
* ``A`` .. ``Z`` (alphabet, upper case) |
| 221 |
* ``#`` (hash) |
| 222 |
* ``@`` (at mark) |
| 223 |
* ``-`` (hyphen) |
| 224 |
* ``_`` (underscore) (NOTE: Underscore can't be used as the first |
| 225 |
character.) |
| 226 |
|
| 227 |
You need to create a name with one or more the above characters. Note |
| 228 |
that you can't use ``_`` as the first character such as ``_name``. |
| 229 |
|
| 230 |
Optional parameters |
| 231 |
^^^^^^^^^^^^^^^^^^^ |
| 232 |
|
| 233 |
There are some optional parameters. |
| 234 |
|
| 235 |
.. _table-create-flags: |
| 236 |
|
| 237 |
``flags`` |
| 238 |
""""""""" |
| 239 |
|
| 240 |
Specifies a table type and table customize options. |
| 241 |
|
| 242 |
Here are available flags: |
| 243 |
|
| 244 |
.. list-table:: |
| 245 |
:header-rows: 1 |
| 246 |
|
| 247 |
* - Flag |
| 248 |
- Description |
| 249 |
* - ``TABLE_NO_KEY`` |
| 250 |
- Array table. See also :ref:`table-no-key`. |
| 251 |
* - ``TABLE_HASH_KEY`` |
| 252 |
- Hash table. See also :ref:`table-hash-key`. |
| 253 |
* - ``TABLE_PAT_KEY`` |
| 254 |
- Patricia trie. See also :ref:`table-pat-key`. |
| 255 |
* - ``TABLE_DAT_KEY`` |
| 256 |
- Double array trie. See also :ref:`table-dat-key`. |
| 257 |
* - ``KEY_WITH_SIS`` |
| 258 |
- Enable Semi Infinite String. Require ``TABLE_PAT_KEY``. |
| 259 |
* - ``KEY_LARGE`` |
| 260 |
- Expand the maximum total key size to 1TiB from 4GiB. Require |
| 261 |
``TABLE_HASH_KEY`` or ``TABLE_PAT_KEY``. |
| 262 |
|
| 263 |
.. note:: |
| 264 |
Since Groonga 2.1.0 ``KEY_NORMALIZE`` flag is deprecated. Use |
| 265 |
``normalizer`` option with ``NormalizerAuto`` instead. |
| 266 |
|
| 267 |
You must specify one of ``TABLE_${TYPE}`` flags. You can't specify two |
| 268 |
or more ``TABLE_${TYPE}`` flags. For example, |
| 269 |
``TABLE_NO_KEY|TABLE_HASH_KEY`` is invalid. |
| 270 |
|
| 271 |
You can combine flags with ``|`` (vertical bar) such as |
| 272 |
``TABLE_PAT_KEY|KEY_WITH_SIS``. |
| 273 |
|
| 274 |
See :doc:`/reference/tables` for difference between table types. |
| 275 |
|
| 276 |
The default flags are ``TABLE_HASH_KEY``. |
| 277 |
|
| 278 |
.. _table-create-key-type: |
| 279 |
|
| 280 |
``key_type`` |
| 281 |
"""""""""""" |
| 282 |
|
| 283 |
Specifies key type. |
| 284 |
|
| 285 |
If you specify ``TABLE_HASH_KEY``, ``TABLE_PAT_KEY`` or |
| 286 |
``TABLE_DAT_KEY`` as ``flags`` parameter, you need to specify |
| 287 |
``key_type`` option. |
| 288 |
|
| 289 |
See :doc:`/reference/types` for all types. |
| 290 |
|
| 291 |
The default value is none. |
| 292 |
|
| 293 |
.. _table-create-value-type: |
| 294 |
|
| 295 |
``value_type`` |
| 296 |
"""""""""""""" |
| 297 |
|
| 298 |
Specifies value type. |
| 299 |
|
| 300 |
You can use value when you specify ``TABLE_NO_KEY``, |
| 301 |
``TABLE_HASH_KEY`` or ``TABLE_PAT_KEY`` as ``flags`` parameter. Value |
| 302 |
type must be a fixed size type. For example, ``UInt32`` can be used |
| 303 |
but ``ShortText`` cannot be used. Use columns instead of value. |
| 304 |
|
| 305 |
The default value is none. |
| 306 |
|
| 307 |
.. _table-create-default-tokenizer: |
| 308 |
|
| 309 |
``default_tokenizer`` |
| 310 |
""""""""""""""""""""" |
| 311 |
|
| 312 |
Specifies the default tokenizer that is used on searching and data |
| 313 |
loading. |
| 314 |
|
| 315 |
You must specify ``default_tokenizer`` for a table that is used for |
| 316 |
lexicon of fulltext search index. See :doc:`/reference/tokenizers` for |
| 317 |
available tokenizers. You must choose a tokenizer from the list for |
| 318 |
fulltext search. |
| 319 |
|
| 320 |
You don't need to specify ``default_tokenizer`` in the following |
| 321 |
cases: |
| 322 |
|
| 323 |
* You don't use the table as a lexicon. |
| 324 |
|
| 325 |
* You use the table as a lexicon but you don't need fulltext |
| 326 |
search. For example: |
| 327 |
|
| 328 |
* Index target data isn't text data such as ``Int32`` and ``Time``. |
| 329 |
* You just need exact match search, prefix search and so on. |
| 330 |
|
| 331 |
You can't use ``default_tokenizer`` with ``TABLE_NO_KEY`` flag because |
| 332 |
a table that uses ``TABLE_NO_KEY`` flag can't be used as lexicon. |
| 333 |
|
| 334 |
You must specify ``TABLE_HASH_KEY``, ``TABLE_PAT_KEY``, |
| 335 |
``TABLE_DAT_KEY`` to :ref:`table-create-flags` when you want to use |
| 336 |
the table as a lexicon. |
| 337 |
|
| 338 |
The default value is none. |
| 339 |
|
| 340 |
.. _table-create-normalizer: |
| 341 |
|
| 342 |
``normalizer`` |
| 343 |
"""""""""""""" |
| 344 |
|
| 345 |
Specifies a normalizer that is used to normalize key. |
| 346 |
|
| 347 |
You cannot use ``normalizer`` with ``TABLE_NO_KEY`` because |
| 348 |
``TABLE_NO_KEY`` doesn't support key. |
| 349 |
|
| 350 |
See :doc:`/reference/normalizers` for all normalizers. |
| 351 |
|
| 352 |
The default value is none. |
| 353 |
|
| 354 |
.. _table-create-token-filters: |
| 355 |
|
| 356 |
``token_filters`` |
| 357 |
""""""""""""""""" |
| 358 |
|
| 359 |
Specifies token filters separated by ``,``. |
| 360 |
Token filters are used to process tokens. |
| 361 |
|
| 362 |
You cannot use ``token_filters`` with ``TABLE_NO_KEY`` because |
| 363 |
``TABLE_NO_KEY`` doesn't support key. |
| 364 |
|
| 365 |
See :doc:`/reference/token_filters` for all token filters. |
| 366 |
|
| 367 |
The default value is none. |
| 368 |
|
| 369 |
.. _table-create-extractors: |
| 370 |
|
| 371 |
``extractors`` |
| 372 |
"""""""""""""" |
| 373 |
|
| 374 |
.. versionadded:: 16.0.6 |
| 375 |
|
| 376 |
.. note:: |
| 377 |
|
| 378 |
This is an experimental feature. Currently, this feature is still |
| 379 |
not stable. |
| 380 |
|
| 381 |
Specifies extractors separated by ``,``. Extractors extract plain text |
| 382 |
or values from structured data such as HTML and JSON before tokenizing |
| 383 |
and indexing a value. |
| 384 |
|
| 385 |
When extractors are set to a lexicon, they are applied automatically |
| 386 |
when an index of the lexicon is updated. If you specify multiple |
| 387 |
extractors, they are applied in order. The output of an extractor is |
| 388 |
passed to the next extractor as its input. |
| 389 |
|
| 390 |
You cannot use ``extractors`` with ``TABLE_NO_KEY`` because |
| 391 |
``TABLE_NO_KEY`` doesn't support key. |
| 392 |
|
| 393 |
See :doc:`/reference/extractors` for all extractors. |
| 394 |
|
| 395 |
The default value is none. |
| 396 |
|
| 397 |
``path`` |
| 398 |
"""""""" |
| 399 |
|
| 400 |
.. versionadded:: 10.0.7 |
| 401 |
|
| 402 |
Specifies a path for storing a table. |
| 403 |
|
| 404 |
This option is useful if you want to store a table that you often use to fast |
| 405 |
storage (e.g. SSD) and store it that you don't often use to slow storage (e.g. HDD). |
| 406 |
|
| 407 |
You can use a relative path or an absolute path in this option. |
| 408 |
If you specify a relative path, it is resolved from the current directory for the ``groonga`` process. |
| 409 |
|
| 410 |
The default value is none. |
| 411 |
|
| 412 |
Return value |
| 413 |
------------ |
| 414 |
|
| 415 |
``table_create`` returns ``true`` as body on success such as:: |
| 416 |
|
| 417 |
[HEADER, true] |
| 418 |
|
| 419 |
If ``table_create`` fails, error details are in ``HEADER``. |
| 420 |
|
| 421 |
See :doc:`/reference/command/output_format` for ``HEADER``. |
| 422 |
|
| 423 |
See also |
| 424 |
-------- |
| 425 |
|
| 426 |
* :doc:`/reference/tables` |
| 427 |
* :doc:`/reference/commands/column_create` |
| 428 |
* :doc:`/reference/tokenizers` |
| 429 |
* :doc:`/reference/normalizers` |
| 430 |
* :doc:`/reference/extractors` |
| 431 |
* :doc:`/reference/command/output_format` |