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

Building statement with FORCE INDEX results in wrong SQL #593

Open
SteveTherrien opened this issue Oct 21, 2024 · 3 comments
Open

Building statement with FORCE INDEX results in wrong SQL #593

SteveTherrien opened this issue Oct 21, 2024 · 3 comments
Labels

Comments

@SteveTherrien
Copy link

Hello,

I have query that's not parsed or built properly when FORCE INDEX is used:

SELECT a.id, a.name, b.order_id, b.total
FROM customers a
INNER JOIN orders b FORCE INDEX (idx_customer_id)
    ON a.id = b.customer_id
WHERE a.status = 'active'

The query becomes:

SELECT a.id, a.name, b.order_id, b.total
FROM customers AS `a` FORCE INDEX (idx_customer_id)
INNER JOIN orders AS `b`
WHERE a.status = 'active'
  • FORCE INDEX got moved from table orders onto customers.
  • The a.id = b.customer_id join condition was removed.

I see the same linting errors as #497, so this is probably related.

Example code
<?php
require __DIR__ . '/vendor/autoload.php';

$in = <<<SQL
SELECT a.id, a.name, b.order_id, b.total
FROM customers a
INNER JOIN orders b FORCE INDEX (idx_customer_id)
    ON a.id = b.customer_id
WHERE a.status = 'active'
SQL;

$parser = new PhpMyAdmin\SqlParser\Parser($in);
$statement = $parser->statements[0];
echo $statement->build();
@williamdes williamdes added the bug label Dec 21, 2024
@williamdes
Copy link
Member

Thank you for reporting this bug !
@niconoe- this one may be interesting for you

@niconoe-
Copy link
Contributor

Yeah, this one might be something I could get involved into. I do think that #497 is very similar and fixing this will fix both.
Due to the holiday period, I won't be available until Jan. 06 at least, and I'll probably have profressional chores to do first before I could take a deeper look at this. But I'll try to investigate and propose something as soon as I can 😉 .

@williamdes
Copy link
Member

Yeah, this one might be something I could get involved into. I do think that #497 is very similar and fixing this will fix both. Due to the holiday period, I won't be available until Jan. 06 at least, and I'll probably have profressional chores to do first before I could take a deeper look at this. But I'll try to investigate and propose something as soon as I can 😉 .

Sure, thank you for all your help !

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

No branches or pull requests

3 participants