You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: modules/n1ql/pages/n1ql-language-reference/execute.adoc
+5-1Lines changed: 5 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -71,7 +71,7 @@ Once retrieved, the query engine creates a local cached copy of the prepared sta
71
71
An error is returned if the name does not identify a prepared statement.
72
72
73
73
[[auto-reprepare]]
74
-
== Auto-Reprepare
74
+
== Automatic Reprepare for Invalid Plans
75
75
76
76
Before execution, the query engine checks whether the statement plan is still valid -- i.e. that all the indexes and keyspaces to which the plan refers are unchanged.
77
77
If any indexes or keyspaces have changed, the statement is automatically prepared again, so that the plan matches the new set of resources.
@@ -80,6 +80,10 @@ If this automatic reprepare succeeds, the statement simply executes as expected.
80
80
However, if any required resources are found to be missing, execution of the affected prepared statement fails until those resources are created again.
81
81
Once the resources are available again, execution proceeds without any further intervention.
82
82
83
+
NOTE: In Couchbase Server 7.6.10 and later, the Query Service provides an opt-in feature that extends this behavior.
84
+
When enabled, the service monitors GSI metadata version changes (such as when you create or drop indexes) and reprepares affected statements.
85
+
For more information, see xref:n1ql-language-reference/prepare.adoc#auto-reprepare-index[Automatic Reprepare on Index Changes].
Copy file name to clipboardExpand all lines: modules/n1ql/pages/n1ql-language-reference/prepare.adoc
+27-21Lines changed: 27 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -209,41 +209,47 @@ For more details, refer to xref:n1ql:n1ql-manage/query-settings.adoc#auto-prepar
209
209
210
210
Auto-prepare is disabled for {sqlpp} requests which contain parameters, if they do not use the PREPARE statement.
211
211
212
-
[[auto-reprepare]]
213
-
== Auto-Reprepare
212
+
[[auto-reprepare-index]]
213
+
== Automatic Reprepare on Index Changes
214
214
[.status]#Couchbase Server 7.6.10#
215
215
216
-
The auto-reprepare feature automatically updates (reprepares) a prepared statement's execution plan whenever the GSI metadata version changes.
217
-
This typically occurs when you create or drop indexes.
216
+
The Query Service validates a statement's prepared plan before executing it.
217
+
If the plan is invalid—for example, if any indexes or keyspaces become unavailable—the service automatically reprepares the statement.
218
+
This is the xref:n1ql-language-reference/execute.adoc#auto-reprepare[default behavior].
218
219
219
-
By default, the Query Service only reprepares a statement when an index in its current plan becomes unavailable.
220
-
With auto-reprepare, statements can use newer and more efficient indexes as they become available.
220
+
The Query Service also provides an opt-in feature that extends this behavior.
221
+
When enabled, the service monitors GSI metadata version changes (such as when you create or drop indexes) and flags affected statements for repreparation.
222
+
The next time a flagged statement runs, the service generates a new plan to match the updated index set.
223
+
This ensures statements automatically use newer, more efficient indexes as they become available.
221
224
222
-
To enable this feature, set bit 23 (0×800000 or 8388608) of the `n1ql-feat-ctrl` setting.
223
-
For information about how to set this value, see the table in the xref:learn:services-and-indexes/indexes/query-without-index.adoc#manage-sequential-scans[Manage Sequential Scans] section.
225
+
The following example shows how the feature works when it's active:
224
226
225
-
When the feature is active, the Query Service monitors index changes and flags statements for repreparation.
226
-
The next time a flagged statement runs, the service generates a new plan for it.
227
+
. You prepare a statement and no suitable indexes exist to support it;
228
+
the Query Service creates a plan that uses a sequential scan.
227
229
228
-
The following example shows how a plan improves as you add new indexes for a statement:
230
+
. You then create a primary index that better supports the statement;
231
+
the service flags the statement, and on the next run generates a new plan that uses the primary index.
229
232
230
-
* If you prepare a statement and no suitable indexes exist to support it, the Query Service creates a plan that uses a sequential scan.
231
-
* If you then create a primary index that better supports the statement, the service flags the statement.
232
-
On the next execution, the service generates a new plan that uses the primary index.
233
-
* If you later create a secondary index that is an even better choice for the statement, the service flags the statement again.
234
-
On the next execution, the service generates a new plan that uses the secondary index.
233
+
. You later create a secondary index that is an even better choice for the statement;
234
+
the service flags the statement again, and on the next run generates a new plan that uses the secondary index.
235
235
236
236
If the feature is inactive, the statement continues to use the original plan (such as a sequential scan) even after you create new indexes.
237
237
238
-
While auto-reprepare generates optimized query plans, it can increase the load on the Query Service.
239
-
Any index modification, even if it's unrelated to a statement, can trigger a repreparation.
238
+
To enable the feature, set bit 23 (0×800000 or 8388608) of the `n1ql-feat-ctrl` setting.
239
+
For information about how to set this value, see the table in the xref:learn:services-and-indexes/indexes/query-without-index.adoc#manage-sequential-scans[Manage Sequential Scans] section.
240
+
241
+
[IMPORTANT]
242
+
====
243
+
This feature can increase the load on the Query Service.
244
+
Any index change, even one unrelated to a given statement, can trigger a repreparation.
240
245
For example, creating or dropping an index that a statement does not use can still flag it for repreparation.
241
-
In such cases, the statement reprepares only to select the same plan again, resulting in redundant work for the service.
246
+
In such cases, the statement reprepares only to select the same plan again, resulting in redundant work.
242
247
243
-
To manage this, you can enable the feature temporarily when you create or drop indexes and disable it after repreparing all statements.
248
+
To reduce this overhead, enable the feature temporarily when you create or drop indexes, and disable it after all statements are reprepared.
244
249
If index changes are infrequent, the effect is minimal.
250
+
====
245
251
246
-
=== Manual Reprepare
252
+
== Manual Reprepare
247
253
248
254
You can also can manually reprepare a specific statement.
249
255
To do this, update xref:n1ql:n1ql-manage/monitoring-n1ql-query.adoc#sys-prepared[system:prepareds] and unset the `planPreparedTime` field for the statement.
0 commit comments