Plan hints change an execution plan. You can run EXPLAIN to view the changes.
Hints containing errors are invalid and do not affect statement execution. The errors will be displayed in different ways based on statement types. Hint errors in an EXPLAIN statement are displayed as a warning on the interface. Hint errors in other statements will be recorded in debug1-level logs containing the PLANHINT keyword.
An error will be reported if the syntax tree fails to be reduced. The No. of the row generating an error is displayed in the error details.
For example, the hint keyword is incorrect, no table or only one table is specified in the leading or join hint, or no tables are specified in other hints. The parsing of a hint is terminated immediately after a syntax error is detected. Only the hints that have been parsed successfully are valid.
For example:
1 | leading((t1 t2)) nestloop(t1) rows(t1 t2 #10) |
The syntax of nestloop(t1) is wrong and its parsing is terminated. Only leading(t1 t2) that has been successfully parsed before nestloop(t1) is valid.
If hint duplication or conflicts occur, only the first hint takes effect. A message will be displayed to describe the situation.
The table list in the leading hint is disassembled. For example, leading (t1 t2 t3) will be disassembled as leading(t1 t2) leading((t1 t2) t3), which will conflict with leading(t2 t1) (if any). In this case, the latter leading(t2 t1) becomes invalid. If two hints use duplicated table lists and only one of them has the specified outer/inner table, the one without a specified outer/inner table becomes invalid.
In this case, a message will be displayed. Generally, such invalidation occurs if a sublink contains multiple tables to be joined, because the table list in the sublink becomes invalid after the sublink is pulled up.