Purpose
This statement is used to create an outline. An outline can be created in two ways: using SQL_TEXT (the original statement with parameters executed by the user) or using SQL_ID.
Limitations and considerations
Considerations
- 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. - In versions earlier than V4.4.2 BP3, you must execute the statement as the corresponding user to create an outline.
- Starting from V4.4.2 BP3, you can create database-level and tenant-level outlines.
- 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 | Indicates a statement that creates an outline using SQL_TEXT. |
| sql_id_stmt | Indicates a statement that creates an outline using SQL_ID. |
| OR REPLACE | Optional. If specified and the outline to be created already exists, the existing outline is replaced. |
| outline_name | Specifies 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 it, 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 a test table named
employees.obclient> CREATE TABLE employees ( emp_id INT, dept_id INT, salary INT, emp_name VARCHAR(50));Insert data into the
employeestable.obclient> INSERT INTO employees VALUES (1001, 10, 10000, 'John'), (1002, 10, 12000, 'Mike'), (1003, 20, 15000, 'Sarah');Create an index named
idx_dept_idon thedept_idcolumn of theemployeestable.obclient> CREATE INDEX idx_dept_id ON employees(dept_id);Create an outline named
outline1usingSQL_TEXT.obclient> CREATE OUTLINE outline1 ON SELECT/*+ index(employees idx_dept_id)*/ * FROM employees WHERE dept_id = 10;Create an outline named
outline2usingSQL_ID.First, find the
SQL_IDof the SQL statement to bind to the outline.obclient> SELECT sql_id, trace_id, client_ip, user_name, query_sql FROM sys.V$OB_SQL_AUDIT WHERE query_sql LIKE '%employees%';Create the outline using the obtained
SQL_ID.obclient> CREATE OUTLINE outline2 ON '549D27D6DD54688A9B25FD82D5650B96' USING HINT /*+ index(employees idx_dept_id)*/;