greenlion / PHP-SQL-Parser

A pure PHP SQL (non validating) parser w/ focus on MySQL dialect of SQL
BSD 3-Clause "New" or "Revised" License
601 stars 156 forks source link

Add handling index hints in FROM and JOIN #359

Closed czoIg closed 2 years ago

czoIg commented 2 years ago

Queries:

SELECT start_date FROM users USE INDEX FOR JOIN (vacation_idx, users_idx) INNER JOIN vacation ON start_date = end_date;
SELECT start_date FROM users FORCE INDEX FOR JOIN (vacation_idx, users_idx) INNER JOIN vacation ON start_date = end_date;

Cannot be parsed because of exception:

cannot calculate position of users FORCE INDEX   (vacation_idx, users_idx) within  users FORCE INDEX FOR JOIN (vacation_idx, users_idx) INNER JOIN vacation ON start_date = end_date

This PR adds support for parsing joins index hints. It doesn't fix index hints for GROUP BY and ORDER BY!

greenlion commented 2 years ago

Thank you for your contribution.