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
|
.. -*- rst -*-
.. groonga-command
.. database: commands_reference_acquire
``reference_acquire``
=====================
Summary
-------
.. versionadded:: 10.0.4
``reference_acquire`` acquires a reference of target objects.
This command is meaningless unless you use the reference count
mode. You can enable the reference count mode by the
``GRN_ENABLE_REFERENCE_COUNT=yes`` environment variable.
If you acquires a reference of an object, the object isn't closed
automatically because you have at least one reference of the
object. If you need to call multiple :doc:`load` in a short time, auto
close by the reference count mode will degrade performance. You can
avoid the performance degrading by calling ``reference_acquire``
before multiple :doc:`load` and calling :doc:`reference_release` after
multiple :doc:`load`. Between ``reference_acquire`` and
:doc:`reference_release`, auto close is disabled.
You must call :doc:`reference_release` after you finish performance
impact operations. If you don't call :doc:`reference_release`, the
reference count mode doesn't work.
You can use :ref:`reference-acquire-auto-release-count` instead of
calling :doc:`reference_release`. You can release acquired references
automatically by :ref:`reference-acquire-auto-release-count`. But you
need to tune suitable :ref:`reference-acquire-auto-release-count`
value. If you specify too large number, auto close isn't triggered. If
you specify too small number, auto close is triggered before
performance impact operations are finished.
Syntax
------
This command takes two parameters.
All parameters are optional::
reference_acquire [target_name=null]
[recursive=yes]
[auto_release_count=0]
Usage
-----
You can acquire a reference of the all objects with no arguments:
.. groonga-command
.. include:: ../../example/reference/commands/reference_acquire/all.log
.. reference_acquire
If you know what should be referred, you can narrow targets.
Here is a schema definition to show usage:
.. groonga-command
.. include:: ../../example/reference/commands/reference_acquire/schema.log
.. table_create Users TABLE_HASH_KEY ShortText
.. column_create Users age COLUMN_SCALAR UInt8
.. column_create Users introduction COLUMN_SCALAR ShortText
..
.. table_create Ages TABLE_PAT_KEY UInt8
.. column_create Ages user_age COLUMN_INDEX Users age
If you want to call multiple :doc:`select` without any condition
against ``Users`` table, the following command acquires a reference of
``Users``, ``Users.age`` and ``Users.introduction``:
.. groonga-command
.. include:: ../../example/reference/commands/reference_acquire/for_output.log
.. reference_acquire --target_name Users
If you want to call multiple :doc:`select` with condition that uses
indexes against ``Users`` table, the following command acquires a
reference of ``Users``, ``Users.age``, ``Users.introduction``,
``Ages`` (lexicon) and ``Ages.user_age`` (index column). This command
is suitable for :doc:`load` too:
.. groonga-command
.. include:: ../../example/reference/commands/reference_acquire/for_search.log
.. reference_acquire --target_name Users --recursive dependent
If you want to just refer ``Users``, you can specify a table with
``recursive=no``:
.. groonga-command
.. include:: ../../example/reference/commands/reference_acquire/table.log
.. reference_acquire --target_name Users --recursive no
If you want to just refer ``Users.introduction``, you can specify a
column:
.. groonga-command
.. include:: ../../example/reference/commands/reference_acquire/column.log
.. reference_acquire --target_name Users.introduction
You can release acquired references by calling
:doc:`reference_release` with the same arguments:
.. groonga-command
.. include:: ../../example/reference/commands/reference_acquire/release.log
.. reference_acquire --target_name Users --recursive dependent
.. # select Users ...
.. # load --table Users ...
.. reference_release --target_name Users --recursive dependent
Parameters
----------
This section describes all parameters.
Required parameters
^^^^^^^^^^^^^^^^^^^
There is no required parameter.
Optional parameters
^^^^^^^^^^^^^^^^^^^
There are optional parameters.
.. _reference-acquire-target-name:
``target_name``
"""""""""""""""
Specifies a target object name. Target object is one of database,
table or column.
If you omit this parameter, database is the target object:
.. groonga-command
.. include:: ../../example/reference/commands/reference_acquire/target_name_database.log
.. reference_acquire
If you specify a table name, the table is the target object:
.. groonga-command
.. include:: ../../example/reference/commands/reference_acquire/target_name_table.log
.. reference_acquire --target_name Users
If you specify a column name, the column is the target object:
.. groonga-command
.. include:: ../../example/reference/commands/reference_acquire/target_name_column.log
.. reference_acquire --target_name Users.age
.. _reference-acquire-recursive:
``recursive``
"""""""""""""
Specifies whether child objects of the target object are also target
objects.
Child objects of database are all tables and all columns.
Child objects of table are all its columns.
Child objects of column are nothing.
``recursive`` value must be ``yes``, ``no`` or ``dependent``. ``yes``
means that all of the specified target object and child objects are
the target objects. ``no`` means that only the specified target object
is the target object. ``dependent`` means that all of the specified
target object, child objects, corresponding table of index column and
corresponding index column are the target objects.
The following ``reference_acquire`` acquires a reference of all tables
and all columns:
.. groonga-command
.. include:: ../../example/reference/commands/reference_acquire/recursive_yes.log
.. reference_acquire --recursive yes
The following ``reference_acquire`` acquires a reference of only
``Users`` table:
.. groonga-command
.. include:: ../../example/reference/commands/reference_acquire/recursive_no.log
.. reference_acquire --target_name Users --recursive no
If you specify other value (not ``yes`` neither ``no``) or omit
``recursive`` parameter, ``yes`` is used.
``yes`` is used in the following case because invalid ``recursive``
argument is specified:
.. groonga-command
.. include:: ../../example/reference/commands/reference_acquire/recursive_invalid.log
.. reference_acquire --target_name Users --recursive invalid
``yes`` is used in the following case because ``recursive`` parameter
isn't specified:
.. groonga-command
.. include:: ../../example/reference/commands/reference_acquire/recursive_default.log
.. reference_acquire --target_name Users
``dependent`` acquires a reference of not only the target object and
the child objects but also related objects. The related objects are:
* A referenced table
* Data columns of referenced tables
* A related index column (There is source column in target ``TABLE_NAME``)
* A table of related index column (There is source column in target ``TABLE_NAME``)
* Data columns of tables of related index columns
It is useful to keep reference for :doc:`load` and :doc:`select`.
If you want to call multiple :doc:`load` for ``Users`` table, you can
use the following command:
.. groonga-command
.. include:: ../../example/reference/commands/reference_acquire/recursive_dependent.log
.. reference_acquire --target_name Users --recursive dependent
.. _reference-acquire-auto-release-count:
``auto_release_count``
""""""""""""""""""""""
.. versionadded:: 10.0.9
You can release acquired references automatically by
``auto_release_count``.
If ``auto_release_count`` is 1 or greater, acquired references are
automatically after the following ``auto_release_count`` commands are
processed. You must not call corresponding :doc:`reference_release`
when you use ``auto_release_count``.
In the following example, the acquired reference of ``Users`` is
released automatically after the second ``status`` is processed::
reference_acquire --target_name Users --auto_release_count 2
status # Users is still referred.
status # Users' reference is released after this command is processed.
The same :ref:`reference-acquire-recursive` is used when acquired
references are released automatically. You don't need to care about
:ref:`reference-acquire-recursive`.
``auto_release_count`` is safe with :doc:`table_remove`,
:doc:`column_remove` and :doc:`database_unmap`. If one of them are
called, registered auto release hook is removed internally.
Return value
------------
The command returns ``true`` as body on success such as::
[HEADER, true]
If the command fails, error details are in ``HEADER``.
See :doc:`/reference/command/output_format` for ``HEADER``.
|