Purpose
This statement is used to create an outline. You can create an outline in two ways: by using the SQL_TEXT parameter, which specifies the original statement with parameters executed by the user, or by using the SQL_ID parameter.
Limitations and considerations
- In versions earlier than V4.4.2 BP3, you must connect to the corresponding database to create an outline.
- Starting from V4.4.2 BP3, you can create database-level and tenant-level outlines.
- When the
SQL_IDis the same, the outline created by usingSQL_TEXToverwrites the outline created by usingSQL_IDand has higher priority. In addition, OceanBase Database distinguishes different SQL statements by usingSQL_ID, which is obtained by taking the MD5 hash of the parameterizedSQL_TEXT. If the SQL texts are the same except for an extra line break or tab, the resultingSQL_IDwill be different. In a production system, we recommend that you bind outlines by usingSQL_ID. - If
MAPcontains thedb.tableform, you must explicitly specifySCOPE = TENANT; otherwise, the outline fails to be created. - Within the same
BINDING_RULE, each database namepatternand table namepatterncan contain at most one variable. Split complex expressions into multiple outlines. - Variables must be defined before they are referenced, and a variable of the same name can be defined only once.
- The
db.*form is not supported. Use the equivalent expression'db_${D:[0-9]+}'.'${T:.*}'instead. - Patterns use POSIX extended regular expression syntax. Complex features such as backreferences and zero-width assertions are not supported.
- Only outlines with
SCOPE = DATABASEand noMAPbehave exactly as before, which is equivalent to the legacy exact outline. - Throttling outlines such as
MAX_CONCURRENTdo not supportBINDING_RULEfor now. - Cross-tenant outline binding is not supported.
Syntax
sql_text_stmt:
CREATE [OR REPLACE] OUTLINE outline_name ON stmt
[TO target_stmt
| BINDING_RULE (binding_item)];
binding_item:
SCOPE = {DATABASE | TENANT}
| MAP = {real_name TO 'pattern', ...}
sql_id_stmt:
CREATE [OR REPLACE] OUTLINE outline_name ON sql_id USING HINT hint;
Parameters
Parameter |
Description |
|---|---|
| sql_text_stmt | The statement that uses the SQL_TEXT parameter to create the outline. |
| sql_id_stmt | The statement that uses the SQL_ID parameter to create the outline. |
| OR REPLACE | Optional. If you specify OR REPLACE and the outline to be created already exists, the existing outline is replaced. |
| outline_name | The name of the outline to be created. |
| stmt | Generally, a DML statement with hints and original parameters. |
| TO target_stmt | Optional. If you do not specify TO target_stmt, and the parameterized text of a SQL statement accepted by the database is the same as that of stmt after the hint is removed, the SQL statement is bound to the execution plan generated by the hint in stmt. If you want to fix the execution plan for a statement that contains hints, you must specify TO target_stmt to indicate the original SQL statement.
NoticeWhen you use |
| BINDING_RULE (binding_item) | Optional. Specifies the scope in which the outline takes effect. For details, see binding_item.
NoteFor V4.4.2, the |
| sql_id | If the SQL statement corresponding to sql_id already contains hints, the hints specified in the outline overwrite all hints in the original statement. |
| hint | Specifies the hints for the outline in the format /*+ xxx */. For more information about hint syntax, see Optimizer Hint. |
binding_item
SCOPE = {DATABASE | TENANT}:SCOPE = DATABASE: the default value. The outline takes effect only in the current database.SCOPE = TENANT: the outline takes effect in all databases under the current tenant.
MAP = {real_name TO 'pattern', ...}: applies thepatternon the right to the real table name ordb.tableon the left.patterncan contain${variable_name}or${variable_name:regex}.Notice
- If the left side of
MAPis in thedb.tableform, thepatternon the right must be split into two quoted parts:'db_pattern'.'table_pattern'. - Within the same
BINDING_RULE, a variable must be defined before it is referenced, and a variable with the same name must have the same value at all references.
- If the left side of
Examples
Create an outline by using the
SQL_TEXTparameter.obclient> CREATE OUTLINE otl_idx_c2 ON SELECT/*+ index(t1 idx_c2)*/ * FROM t1 WHERE c2 = 1;Create an outline by using the
SQL_IDparameter.obclient> CREATE OUTLINE otl_idx_c2 ON 'ED570339F2C856BA96008A29EDF04C74' USING HINT /*+ index(t1 idx_c2)*/;