Improved Response Time Using the STAGE_ITAB, STAGE_ITAB_MAX_ROWS, and STAGE_ITAB_PARALLEL Options of CONTEXT Index
Oracle Text provides the STAGE_ITAB option for improving the query performance for the CONTEXT indexes that extensively use insert, update, and delete operations for near real-time indexing.
If you do not use the STAGE_ITAB index option, then when you add a new document to the CONTEXT index, SYNC_INDEX is called to make the documents searchable. This call creates new rows in the $I table, and increases the fragmentation in the $I table. The result is deterioration of the query performance.
When you enable the STAGE_ITAB index option, the following happens:
-
Information about the new documents is stored in the
$Gstaging table, not in the$Itable. This storage ensures that the$Itable is not fragmented and does not deteriorate the query performance. -
The
$Hb-tree index is created on the$Gtable. The$Gtable and$Hb-tree index are equivalent to the$Itable and$Xb-tree index.
Use the MERGE optimization mode to optimize the rows in the $G table and move them to the $I table.
Note: The $G table is stored in the KEEP pool. To improve query performance, you should allocate sufficient KEEP pool memory and maintain a large enough $G table size by using the new stage_itab_max_rows option.
To create a CONTEXT index with the STAGE_ITAB index option, first create a basic storage preference by setting the value of its STAGE_ITAB storage attribute to YES. Next, specify this storage preference when you create the CONTEXT index.
The following example creates a basic mystore storage preference and sets the value of its STAGE_ITAB storage attribute to YES:
exec ctx_ddl.create_preference('mystore', 'BASIC_STORAGE');
exec ctx_ddl.set_attribute('mystore', 'STAGE_ITAB', 'YES');
You can also enable the STAGE_ITAB index option for an existing nonpartitioned CONTEXT index by using the rebuild option of the ALTER INDEX statement.
alter index IDX rebuild parameters('replace storage mystore');
To disable the STAGE_ITAB option for a nonpartitioned CONTEXT index, update the existing storage preference (mystore) by setting the value of its STAGE_ITAB storage attribute to NO, and then rebuild the index.
exec ctx_ddl.set_attribute('mystore', 'STAGE_ITAB', 'NO');
alter index idx rebuild parameters('replace storage mystore');
This operation runs the optimization process by using the MERGE optimization mode and then drops the $G table.
The rebuild option of the ALTER INDEX statement does not work with the partitioned CONTEXT index for enabling and disabling the STAGE_ITAB option.
The following example enables the STAGE_ITAB option for the partitioned CONTEXT idx index:
alter index idx parameters('add stage_itab');
The following example disables the STAGE_ITAB option for the partitioned CONTEXT idx index:
alter index idx parameters('remove stage_itab');
Starting with Oracle Database 12c Release 2 (
12.2), the contents of $G are automatically moved to $I during index synchronization when $G has more than 1 million rows. This value is controlled by the STAGE_ITAB_MAX_ROWS attribute of the STORAGE preference.
Note: If an occasional index synchronization takes a long time, you can either reduce the value of the STAGE_ITAB_MAX_ROWS parameter or increase the degree of parallelism by using the STAGE_ITAB_PARALLEL attribute of the STORAGE preference. If you set the value of STAGE_ITAB_MAX_ROWS to a very small value, then the contents of $G are moved to $I frequently. So, do not be set it to a very low value.
Note: To use the STAGE_ITAB index option for a CONTEXT index, you must specify the g_index_clause and g_table_clause BASIC_STORAGE preferences.
The query performance is deteriorated when $G table is too fragmented. To avoid deterioration, starting with Oracle Database Release 18c, Oracle Text provides automatic background optimize merge for every index or partition. To enable automatic background optimize merge, you must set the STAGE_ITAB and STAGE_ITAB_AUTO_OPT storage preference attributes to TRUE, and you must create the index with a storage preference.
By default, if you had enabled STAGE_ITAB in indexes before you upgraded to Oracle Database Release 18c, then STAGE_ITAB_AUTO_OPT is not enabled. If STAGE_ITAB and AUTO_OPTIMIZE are enabled in existing indexes, then you must disable AUTO_OPTIMIZE before you enable STAGE_ITAB_AUTO_OPT.
The following example creates a basic mystore storage preference and sets the value of its STAGE_ITAB_AUTO_OPT storage attribute to TRUE:
exec ctx_ddl.create_preference('mystore', 'basic_storage');
exec ctx_ddl.set_attribute('mystore', 'stage_itab', 'TRUE');
exec ctx_ddl.set_attribute('mystore', 'stage_itab_auto_opt', 'TRUE');
exec ctx_ddl.set_attribute('mystore', 'stage_itab_parallel', 16);
Related Topics