Debian Codegraph @

doc/source/reference/commands/reference_acquire.rst

raw
1 .. -*- rst -*-
2
3 .. groonga-command
4 .. database: commands_reference_acquire
5
6 ``reference_acquire``
7 =====================
8
9 Summary
10 -------
11
12 .. versionadded:: 10.0.4
13
14 ``reference_acquire`` acquires a reference of target objects.
15
16 This command is meaningless unless you use the reference count
17 mode. You can enable the reference count mode by the
18 ``GRN_ENABLE_REFERENCE_COUNT=yes`` environment variable.
19
20 If you acquires a reference of an object, the object isn't closed
21 automatically because you have at least one reference of the
22 object. If you need to call multiple :doc:`load` in a short time, auto
23 close by the reference count mode will degrade performance. You can
24 avoid the performance degrading by calling ``reference_acquire``
25 before multiple :doc:`load` and calling :doc:`reference_release` after
26 multiple :doc:`load`. Between ``reference_acquire`` and
27 :doc:`reference_release`, auto close is disabled.
28
29 You must call :doc:`reference_release` after you finish performance
30 impact operations. If you don't call :doc:`reference_release`, the
31 reference count mode doesn't work.
32
33 You can use :ref:`reference-acquire-auto-release-count` instead of
34 calling :doc:`reference_release`. You can release acquired references
35 automatically by :ref:`reference-acquire-auto-release-count`. But you
36 need to tune suitable :ref:`reference-acquire-auto-release-count`
37 value. If you specify too large number, auto close isn't triggered. If
38 you specify too small number, auto close is triggered before
39 performance impact operations are finished.
40
41 Syntax
42 ------
43
44 This command takes two parameters.
45
46 All parameters are optional::
47
48 reference_acquire [target_name=null]
49 [recursive=yes]
50 [auto_release_count=0]
51
52 Usage
53 -----
54
55 You can acquire a reference of the all objects with no arguments:
56
57 .. groonga-command
58 .. include:: ../../example/reference/commands/reference_acquire/all.log
59 .. reference_acquire
60
61 If you know what should be referred, you can narrow targets.
62
63 Here is a schema definition to show usage:
64
65 .. groonga-command
66 .. include:: ../../example/reference/commands/reference_acquire/schema.log
67 .. table_create Users TABLE_HASH_KEY ShortText
68 .. column_create Users age COLUMN_SCALAR UInt8
69 .. column_create Users introduction COLUMN_SCALAR ShortText
70 ..
71 .. table_create Ages TABLE_PAT_KEY UInt8
72 .. column_create Ages user_age COLUMN_INDEX Users age
73
74 If you want to call multiple :doc:`select` without any condition
75 against ``Users`` table, the following command acquires a reference of
76 ``Users``, ``Users.age`` and ``Users.introduction``:
77
78 .. groonga-command
79 .. include:: ../../example/reference/commands/reference_acquire/for_output.log
80 .. reference_acquire --target_name Users
81
82 If you want to call multiple :doc:`select` with condition that uses
83 indexes against ``Users`` table, the following command acquires a
84 reference of ``Users``, ``Users.age``, ``Users.introduction``,
85 ``Ages`` (lexicon) and ``Ages.user_age`` (index column). This command
86 is suitable for :doc:`load` too:
87
88 .. groonga-command
89 .. include:: ../../example/reference/commands/reference_acquire/for_search.log
90 .. reference_acquire --target_name Users --recursive dependent
91
92 If you want to just refer ``Users``, you can specify a table with
93 ``recursive=no``:
94
95 .. groonga-command
96 .. include:: ../../example/reference/commands/reference_acquire/table.log
97 .. reference_acquire --target_name Users --recursive no
98
99 If you want to just refer ``Users.introduction``, you can specify a
100 column:
101
102 .. groonga-command
103 .. include:: ../../example/reference/commands/reference_acquire/column.log
104 .. reference_acquire --target_name Users.introduction
105
106 You can release acquired references by calling
107 :doc:`reference_release` with the same arguments:
108
109 .. groonga-command
110 .. include:: ../../example/reference/commands/reference_acquire/release.log
111 .. reference_acquire --target_name Users --recursive dependent
112 .. # select Users ...
113 .. # load --table Users ...
114 .. reference_release --target_name Users --recursive dependent
115
116
117 Parameters
118 ----------
119
120 This section describes all parameters.
121
122 Required parameters
123 ^^^^^^^^^^^^^^^^^^^
124
125 There is no required parameter.
126
127 Optional parameters
128 ^^^^^^^^^^^^^^^^^^^
129
130 There are optional parameters.
131
132 .. _reference-acquire-target-name:
133
134 ``target_name``
135 """""""""""""""
136
137 Specifies a target object name. Target object is one of database,
138 table or column.
139
140 If you omit this parameter, database is the target object:
141
142 .. groonga-command
143 .. include:: ../../example/reference/commands/reference_acquire/target_name_database.log
144 .. reference_acquire
145
146 If you specify a table name, the table is the target object:
147
148 .. groonga-command
149 .. include:: ../../example/reference/commands/reference_acquire/target_name_table.log
150 .. reference_acquire --target_name Users
151
152 If you specify a column name, the column is the target object:
153
154 .. groonga-command
155 .. include:: ../../example/reference/commands/reference_acquire/target_name_column.log
156 .. reference_acquire --target_name Users.age
157
158 .. _reference-acquire-recursive:
159
160 ``recursive``
161 """""""""""""
162
163 Specifies whether child objects of the target object are also target
164 objects.
165
166 Child objects of database are all tables and all columns.
167
168 Child objects of table are all its columns.
169
170 Child objects of column are nothing.
171
172 ``recursive`` value must be ``yes``, ``no`` or ``dependent``. ``yes``
173 means that all of the specified target object and child objects are
174 the target objects. ``no`` means that only the specified target object
175 is the target object. ``dependent`` means that all of the specified
176 target object, child objects, corresponding table of index column and
177 corresponding index column are the target objects.
178
179 The following ``reference_acquire`` acquires a reference of all tables
180 and all columns:
181
182 .. groonga-command
183 .. include:: ../../example/reference/commands/reference_acquire/recursive_yes.log
184 .. reference_acquire --recursive yes
185
186 The following ``reference_acquire`` acquires a reference of only
187 ``Users`` table:
188
189 .. groonga-command
190 .. include:: ../../example/reference/commands/reference_acquire/recursive_no.log
191 .. reference_acquire --target_name Users --recursive no
192
193 If you specify other value (not ``yes`` neither ``no``) or omit
194 ``recursive`` parameter, ``yes`` is used.
195
196 ``yes`` is used in the following case because invalid ``recursive``
197 argument is specified:
198
199 .. groonga-command
200 .. include:: ../../example/reference/commands/reference_acquire/recursive_invalid.log
201 .. reference_acquire --target_name Users --recursive invalid
202
203 ``yes`` is used in the following case because ``recursive`` parameter
204 isn't specified:
205
206 .. groonga-command
207 .. include:: ../../example/reference/commands/reference_acquire/recursive_default.log
208 .. reference_acquire --target_name Users
209
210 ``dependent`` acquires a reference of not only the target object and
211 the child objects but also related objects. The related objects are:
212
213 * A referenced table
214 * Data columns of referenced tables
215 * A related index column (There is source column in target ``TABLE_NAME``)
216 * A table of related index column (There is source column in target ``TABLE_NAME``)
217 * Data columns of tables of related index columns
218
219 It is useful to keep reference for :doc:`load` and :doc:`select`.
220
221 If you want to call multiple :doc:`load` for ``Users`` table, you can
222 use the following command:
223
224 .. groonga-command
225 .. include:: ../../example/reference/commands/reference_acquire/recursive_dependent.log
226 .. reference_acquire --target_name Users --recursive dependent
227
228 .. _reference-acquire-auto-release-count:
229
230 ``auto_release_count``
231 """"""""""""""""""""""
232
233 .. versionadded:: 10.0.9
234
235 You can release acquired references automatically by
236 ``auto_release_count``.
237
238 If ``auto_release_count`` is 1 or greater, acquired references are
239 automatically after the following ``auto_release_count`` commands are
240 processed. You must not call corresponding :doc:`reference_release`
241 when you use ``auto_release_count``.
242
243 In the following example, the acquired reference of ``Users`` is
244 released automatically after the second ``status`` is processed::
245
246 reference_acquire --target_name Users --auto_release_count 2
247 status # Users is still referred.
248 status # Users' reference is released after this command is processed.
249
250 The same :ref:`reference-acquire-recursive` is used when acquired
251 references are released automatically. You don't need to care about
252 :ref:`reference-acquire-recursive`.
253
254 ``auto_release_count`` is safe with :doc:`table_remove`,
255 :doc:`column_remove` and :doc:`database_unmap`. If one of them are
256 called, registered auto release hook is removed internally.
257
258 Return value
259 ------------
260
261 The command returns ``true`` as body on success such as::
262
263 [HEADER, true]
264
265 If the command fails, error details are in ``HEADER``.
266
267 See :doc:`/reference/command/output_format` for ``HEADER``.