Purpose
This statement is used to create a fuzzy outline. You can create a fuzzy outline in two ways, by using FORMAT_SQL_TEXT (the original statement with parameters executed by the user) or FORMAT_SQL_ID.
Limitations and considerations
You must log in as the corresponding user to create an outline.
If you create an outline by using
FORMAT_SQL_TEXT, the outline created by usingFORMAT_SQL_TEXTwill override the one created by usingFORMAT_SQL_IDif they have the sameFORMAT_SQL_ID. In addition, OceanBase Database usesFORMAT_SQL_IDto distinguish different SQL statements, andFORMAT_SQL_IDis generated by applying theMD5hash encryption to the result of formattingFORMAT_SQL_TEXT(removing redundant spaces and line breaks, and converting all characters to uppercase or lowercase). We recommend that you bind an outline by usingFORMAT_SQL_IDin a production system.Note
- The matching rule for
FORMAT_SQL_TEXTignores differences in parameter content, case, spaces, and line breaks. It only compares the text content after these differences are removed. FORMAT_SQL_IDis generated by applying theMD5hash encryption to the result of formattingFORMAT_SQL_TEXT(removing redundant spaces and line breaks, and converting all characters to uppercase or lowercase).
- The matching rule for
Syntax
/* Create an outline by using FORMAT_SQL_TEXT. */
CREATE [OR REPLACE] FORMAT OUTLINE outline_name ON format_stmt [ TO format_target_stmt ]
/* Create an outline by using FORMAT_SQL_ID. */
CREATE [OR REPLACE] FORMAT OUTLINE outline_name ON format_sql_id USING HINT hint;
Parameters
| Parameter | Description |
|---|---|
| outline_name | The name of the fuzzy outline to be created. |
| OR REPLACE | If you specify OR REPLACE and the outline to be created already exists, the existing outline will be replaced. |
| format_stmt | The original SQL statement.
NoteOceanBase Database automatically formats the unformatted SQL statement. |
| TO format_target_stmt | Optional. Specifies the target SQL statement to which format_stmt is converted or applied, that is, the SQL statement to which the outline is also applicable. You can use the TO format_target_stmt option to specify these SQL statements.
Notice
|
| format_sql_id | The format_sql_id generated by applying the MD5 hash encryption to the result of formatting FORMAT_SQL_TEXT (removing redundant spaces and line breaks, and converting all characters to uppercase or lowercase) after a series of rules are applied to the SQL statement corresponding to the SQL statement to be bound. |
Examples
Create an outline by using
FORMAT_SQL_TEXT.CREATE FORMAT OUTLINE my_outline ON 'SELECT * FROM employees WHERE department_id = ?';Create an outline by using
FORMAT_SQL_ID.CREATE FORMAT OUTLINE my_sql_id_outline ON 'ED570339F2C856BA96008A29EDF04C74' USING HINT /*+ index(tbl1 idx_col2)*/;
References
For more information about outlines, see Plan binding.