==db:optimize==
{{Mark|Updated with Version 7.7:}} optional index additional $options argument added
{| width='100%'
|-
| width='90' | '''Signatures'''
|{{Func|db:optimize|$db as xs:string|empty-sequence()}}<br/>{{Func|db:optimize|$db as xs:string, $all as xs:boolean|empty-sequence()}}<br/>{{Func|db:optimize|$db as xs:string, $all as xs:boolean, $options as item()|empty-sequence()}}
|-
| '''Summary'''
|Optimizes the meta data and indexes of the database {{Code|$db}}.<br/>If {{Code|$all}} is set to {{Code|true()}}, the complete database will be rebuilt.<br/>The usage of the {{Code|$options}} argument is identical to the [[#db:create|db:create]] function, except that the [[Options#UPDINDEX|UPDINDEX]] option is not supported.
|-
| '''Errors'''
|
* {{Code|db:optimize("DB")}} optimizes the database structures of the database {{Code|DB}}.
* {{Code|db:optimize("DB", true(), map { 'ftindex' := true() })}} optimizes all database structures of the database {{Code|DB}}and creates a full-text index.
|}