r"""Add an indexing or other executional context hint for the given selectable to this :class:`_expression.Select` or other selectable object. .. tip:: The :meth:`_expression.Select.with_hint` method adds hints that are **specific to a single table**
(
self,
selectable: _FromClauseArgument,
text: str,
dialect_name: str = "*",
)
| 541 | |
| 542 | @_generative |
| 543 | def with_hint( |
| 544 | self, |
| 545 | selectable: _FromClauseArgument, |
| 546 | text: str, |
| 547 | dialect_name: str = "*", |
| 548 | ) -> Self: |
| 549 | r"""Add an indexing or other executional context hint for the given |
| 550 | selectable to this :class:`_expression.Select` or other selectable |
| 551 | object. |
| 552 | |
| 553 | .. tip:: |
| 554 | |
| 555 | The :meth:`_expression.Select.with_hint` method adds hints that are |
| 556 | **specific to a single table** to a statement, in a location that |
| 557 | is **dialect-specific**. To add generic optimizer hints to the |
| 558 | **beginning** of a statement ahead of the SELECT keyword such as |
| 559 | for MySQL or Oracle Database, use the |
| 560 | :meth:`_expression.Select.prefix_with` method. To add optimizer |
| 561 | hints to the **end** of a statement such as for PostgreSQL, use the |
| 562 | :meth:`_expression.Select.with_statement_hint` method. |
| 563 | |
| 564 | The text of the hint is rendered in the appropriate |
| 565 | location for the database backend in use, relative |
| 566 | to the given :class:`_schema.Table` or :class:`_expression.Alias` |
| 567 | passed as the |
| 568 | ``selectable`` argument. The dialect implementation |
| 569 | typically uses Python string substitution syntax |
| 570 | with the token ``%(name)s`` to render the name of |
| 571 | the table or alias. E.g. when using Oracle Database, the |
| 572 | following:: |
| 573 | |
| 574 | select(mytable).with_hint(mytable, "index(%(name)s ix_mytable)") |
| 575 | |
| 576 | Would render SQL as: |
| 577 | |
| 578 | .. sourcecode:: sql |
| 579 | |
| 580 | select /*+ index(mytable ix_mytable) */ ... from mytable |
| 581 | |
| 582 | The ``dialect_name`` option will limit the rendering of a particular |
| 583 | hint to a particular backend. Such as, to add hints for both Oracle |
| 584 | Database and MSSql simultaneously:: |
| 585 | |
| 586 | select(mytable).with_hint( |
| 587 | mytable, "index(%(name)s ix_mytable)", "oracle" |
| 588 | ).with_hint(mytable, "WITH INDEX ix_mytable", "mssql") |
| 589 | |
| 590 | .. seealso:: |
| 591 | |
| 592 | :meth:`_expression.Select.with_statement_hint` |
| 593 | |
| 594 | :meth:`_expression.Select.prefix_with` - generic SELECT prefixing |
| 595 | which also can suit some database-specific HINT syntaxes such as |
| 596 | MySQL or Oracle Database optimizer hints |
| 597 | |
| 598 | """ |
| 599 | |
| 600 | return self._with_hint(selectable, text, dialect_name) |
nothing calls this directly
no test coverage detected