OceanBase Database provides the DBA_INDEX_USAGE view for you to monitor indexes and query index monitoring results to better understand index usage. OceanBase Database periodically clears the monitoring records of deleted index tables in the background. You do not need to manually clear such data.
Note
The DBA_INDEX_USAGE view displays only index statistics of user tenants.
Considerations
If you set the tenant-level parameter
_iut_stat_collection_typetoALL, the index query performance may degrade. Proceed with caution.The
_iut_max_entriesparameter specifies the maximum number of index tables that can be monitored in a tenant. A large value of this parameter may result in a high tenant memory usage. We recommend that you set the parameter to a value no greater than 30,000.
Parameters
OceanBase Database provides the following tenant-level parameters for you to control index monitoring.
Note
The parameters and statistics of a tenant are independent of those of other tenants.
| Parameter | Default value | Description |
|---|---|---|
| _iut_enable | true | Specifies whether to enable index monitoring. The default value is true, which indicates that index monitoring is enabled. false indicates that index monitoring is disabled. |
| _iut_max_entries | 30000 | The maximum number of index tables that can be monitored. The default value is 30000. The value range is [0,+∞).
Note
|
| _iut_stat_collection_type | SAMPLED | The collection mode of index monitoring statistics. Valid values:
|
Collection modes of index monitoring statistics
In the default index statistics collection mode (SAMPLED), only sampled index usage data is recorded. Therefore, a query of the DBA_INDEX_USAGE view may return an empty result. To obtain accurate index usage data of a tenant, set the index statistics collection mode to ALL for the tenant.
You can use the following SQL statement to view the value of the _iut_stat_collection_type parameter:
SELECT name, data_type, value FROM oceanbase.GV$OB_PARAMETERS WHERE name LIKE '%iut_stat_collection%';
You can use the following SQL statement to configure this parameter:
ALTER SYSTEM SET _iut_stat_collection_type="ALL";
Examples
Create a table named
test_tbl1.obclient [test_db]> CREATE TABLE test_tbl1 (col1 INT PRIMARY KEY, col2 VARCHAR(50) NOT NULL, col3 INT);On the
col3column of thetest_tbl1table, create an index namedidx1_test_tbl1.obclient [test_db]> CREATE INDEX idx1_test_tbl1 ON test_tbl1(col3);Insert five records into the
test_tbl1table.obclient [test_db]> INSERT INTO test_tbl1 VALUES (1, 'name1', 20),(2, 'name2', 19),(3, 'name3', 20),(4, 'name4', 29),(5, 'name5', 26);The return result is as follows:
Query OK, 5 rows affected Records: 5 Duplicates: 0 Warnings: 0Execute the
SELECTquery.obclient [test_db]> SELECT col1, col2 FROM test_tbl1 WHERE col3 >= 25;The return result is as follows:
+------+-------+ | col1 | col2 | +------+-------+ | 5 | name5 | | 4 | name4 | +------+-------+ 2 rows in setQuery the
DBA_INDEX_USAGEview.Note
OceanBase Database may take up to 15 minutes to flush the collected index monitoring statistics to the internal table in the background by using scheduled tasks. After that, the monitoring results of index usage can be obtained by querying the view.
obclient [test_db]> SELECT OBJECT_ID, NAME, OWNER, TOTAL_ACCESS_COUNT, TOTAL_EXEC_COUNT, LAST_USED FROM oceanbase.DBA_INDEX_USAGE;The return result is as follows:
Empty setIn the default
SAMPLEDmode, not all index usage data is recorded in the internal table. As a result, the expected monitoring statistics may not exist in the view. You can change the statistics collection mode to collect all index usage data. Here is an example:Use the following SQL statement to set the index statistics collection mode to
ALL.ALTER SYSTEM SET _iut_stat_collection_type="ALL";Execute the
SELECTquery again.SELECT col1, col2 FROM test_tbl1 WHERE col3 >= 25;Query the
DBA_INDEX_USAGEview again.Note
OceanBase Database may take up to 15 minutes to flush the collected index monitoring statistics to the internal table in the background by using scheduled tasks. After that, the monitoring results of index usage can be obtained by querying the view.
SELECT OBJECT_ID, NAME, OWNER, TOTAL_ACCESS_COUNT, TOTAL_EXEC_COUNT, LAST_USED FROM oceanbase.DBA_INDEX_USAGE;The return result is as follows:
+-----------+-----------------------------+---------+--------------------+------------------+----------------------------+ | OBJECT_ID | NAME | OWNER | TOTAL_ACCESS_COUNT | TOTAL_EXEC_COUNT | LAST_USED | +-----------+-----------------------------+---------+--------------------+------------------+----------------------------+ | 500127 | __idx_500126_idx1_test_tbl1 | test_db | 1 | 1 | 2024-01-24 11:09:30.928232 | +-----------+-----------------------------+---------+--------------------+------------------+----------------------------+ 1 row in setIn the query result:
The
TOTAL_ACCESS_COUNTfield indicates that during theSELECToperation, theidx1_test_tbl1index in thetest_dbdatabase was accessed1time at2024-01-24 11:09:30.928232.The fields are described as follows:
OBJECT_ID: the ID of the index table.NAME: the name of the index table.OWNER: the database name.TOTAL_ACCESS_COUNT: the total number of index accesses.TOTAL_EXEC_COUNT: the total number of executions in which the index was involved.LAST_USED: the last time when the index table was used.
For more information about the fields in the
DBA_INDEX_USAGEview, see DBA_INDEX_USAGE.