Skip to main content

MAJOR and MINOR

Description

This statement is used to initiate a major compaction or a minor compaction (freezing) at the system level. Manual compactions and freezes are supported at the instance level and the partition level.

Syntax

ALTER SYSTEM merge_action;

merge_action:
MAJOR FREEZE
| MAJOR FREEZE TABLET_ID = tablet_id
| MINOR FREEZE [TABLET_ID = tablet_id]
| {SUSPEND | RESUME} MERGE
| CLEAR MERGE ERROR

Parameter description

ParameterDescription
MAJOR FREEZEInitiates a daily major compaction.
MINOR FREEZEInitiates a minor compaction.
{SUSPEND | RESUME} MERGESuspends or resumes a daily major compaction.
CLEAR MERGE ERRORClears the error mark for a major compaction.
MAJOR FREEZE TABLET_ID = tablet_idSpecifies a tablet ID for a major compaction, i.e., a partition-level major compaction.
TABLET_IDSpecifies a partition for a minor compaction or a major compaction.
LSSpecifies a log file for a minor compaction.

Considerations

Partitions and tablets are one-to-one. When you initiate a partition-level major compaction, note the following:

  • If an instance-level major compaction is being executed for the corresponding partition, you cannot initiate a partition-level major compaction.
  • If an adaptive scheduling major compaction is being executed for the corresponding partition, you cannot initiate a partition-level major compaction.
  • If the major compaction is suspended, you cannot initiate a partition-level major compaction.
  • A partition-level major compaction consumes CPU and disk I/O resources. Before you initiate a partition-level major compaction, you need to evaluate the current resource usage. After a partition-level major compaction is initiated, the CPU and I/O usage will increase.

Examples

Example of initiating a major compaction

  • Initiate a daily major compaction.

    ALTER SYSTEM MAJOR FREEZE;

Example of initiating a minor compaction

  • Initiate a minor compaction.

    ALTER SYSTEM MINOR FREEZE;
  • Initiate a minor compaction for a specified partition.

    ALTER SYSTEM MINOR FREEZE tablet_id = 1100611139453887;

Example of suspending or resuming a daily major compaction

  • Suspend a daily major compaction.

    ALTER SYSTEM SUSPEND MERGE;

Example of clearing the error mark for a major compaction

  • Clear the error mark for a major compaction.

    ALTER SYSTEM CLEAR MERGE ERROR;

Example of initiating a partition-level major compaction

  1. Query the tablet ID of the table.

    Here is an example:

    SELECT t1.tenant_id, t2.tenant_name, t1.database_name, t1.table_id, t1.table_name, t1.tablet_id, t1.PARTITION_NAME, t1.SUBPARTITION_NAME
    FROM oceanbase.CDB_OB_TABLE_LOCATIONS t1, oceanbase.DBA_OB_TENANTS t2
    WHERE t1.tenant_id=t2.tenant_id
    AND t1.table_name = 'test_tbl1'
    AND t2.tenant_name = 'oracle001';

    The returned result is as follows:

    +-----------+-------------+---------------+----------+------------+-----------+----------------+-------------------+
    | tenant_id | tenant_name | database_name | table_id | table_name | tablet_id | PARTITION_NAME | SUBPARTITION_NAME |
    +-----------+-------------+---------------+----------+------------+-----------+----------------+-------------------+
    | 1004 | oracle001 | SYS | 500011 | TEST_TBL1 | 200008 | P1 | SP0 |
    | 1004 | oracle001 | SYS | 500011 | TEST_TBL1 | 200009 | P1 | SP1 |
    | 1004 | oracle001 | SYS | 500011 | TEST_TBL1 | 200010 | P1 | SP2 |
    | 1004 | oracle001 | SYS | 500011 | TEST_TBL1 | 200011 | P1 | SP3 |
    | 1004 | oracle001 | SYS | 500011 | TEST_TBL1 | 200012 | P2 | SP4 |
    | 1004 | oracle001 | SYS | 500011 | TEST_TBL1 | 200013 | P2 | SP5 |
    | 1004 | oracle001 | SYS | 500011 | TEST_TBL1 | 200014 | P2 | SP6 |
    | 1004 | oracle001 | SYS | 500011 | TEST_TBL1 | 200015 | P2 | SP7 |
    +-----------+-------------+---------------+----------+------------+-----------+----------------+-------------------+
    8 rows in set (0.012 sec)

    For more information about the view fields, see oceanbase.CDB_OB_TABLE_LOCATIONS.

  2. Initiate a major compaction.

    Here is an example:

    ALTER SYSTEM MAJOR FREEZE TENANT = oracle001 TABLET_ID = 200008;

Example of initiating a partition-level minor compaction

  1. Query the tablet ID of the table.

    Here is an example:

    SELECT database_name, table_id, table_name, tablet_id, PARTITION_NAME, SUBPARTITION_NAME
    FROM oceanbase.CDB_OB_TABLE_LOCATIONS
    WHERE table_name = 'tbl1';

    The returned result is as follows:

    +---------------+----------+------------+-----------+----------------+-------------------+
    | database_name | table_id | table_name | tablet_id | PARTITION_NAME | SUBPARTITION_NAME |
    +---------------+----------+------------+-----------+----------------+-------------------+
    | test_db | 500197 | tbl1 | 200067 | NULL | NULL |
    | test_table | 500557 | tbl1 | 200276 | NULL | NULL |
    | test_data | 500658 | tbl1 | 200337 | NULL | NULL |
    | mysql | 500722 | tbl1 | 200365 | NULL | NULL |
    +---------------+----------+------------+-----------+----------------+-------------------+
    4 rows in set (0.277 sec)

    For more information about the view fields, see oceanbase.CDB_OB_TABLE_LOCATIONS.

  2. Initiate a minor compaction.

    Here is an example:

    ALTER SYSTEM MINOR FREEZE TABLET_ID = 200067;

References