Skip to content

如何为Oracle方言添加optimizer hint #475

Answered by vincentlauvlwj
tzhao11 asked this question in Q&A
Discussion options

You must be logged in to vote

可以考虑写成嵌套查询

const val OPTIMIZER_HINTS_KEY: String = "optimizerHints"

class ExtendedOracleFormatter(
    database: Database, beautifySql: Boolean, indentSize: Int
) : OracleFormatter(database, beautifySql, indentSize) {

    @Suppress("UNCHECKED_CAST")
    override fun visitSelect(expr: SelectExpression): SelectExpression {
        val hints = expr.extraProperties[OPTIMIZER_HINTS_KEY] as? List<String>
        if (hints.isNullOrEmpty()) {
            return super.visitSelect(expr)
        }
        
        writeKeyword("select * ")
        write("/*+ ${hints.joinToString(" ")} */ ")
        newLine(Indentation.SAME)
        writeKeyword("from ")
        visitQuerySource(expr)
        newLine(

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@tzhao11
Comment options

@vincentlauvlwj
Comment options

@tzhao11
Comment options

Answer selected by tzhao11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants