Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All index hints appear after the last from statement #760

Open
stepantubanov opened this issue Mar 14, 2024 · 0 comments
Open

All index hints appear after the last from statement #760

stepantubanov opened this issue Mar 14, 2024 · 0 comments

Comments

@stepantubanov
Copy link

Description

In a select with multiple from, index hint is simply placed after the last one which produces incorrect SQL.

Steps to Reproduce

fn main() {
    let sql = Query::select()
        .column(Asterisk)
        .from(Alias::new("a"))
        .force_index(IndexName::new("idx_a"), IndexHintScope::All)
        .from(Alias::new("b"))
        .force_index(IndexName::new("idx_b"), IndexHintScope::All)
        .to_string(MysqlQueryBuilder);

    println!("{sql}");
}

Expected Behavior

Correct SQL would be

SELECT * FROM `a` FORCE INDEX (`idx_a`), `b` FORCE INDEX (`idx_b`)

Actual Behavior

Actual generated SQL:

SELECT * FROM `a`, `b` FORCE INDEX (`idx_a`) FORCE INDEX (`idx_b`)

Which results in an error: Key 'idx_a' doesn't exist in table 'b'

Reproduces How Often

Always

Versions

sea-query 0.30.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant