@@ -353,4 +353,65 @@ public function testBuilderSurroundedByParanthesisWithLimit(): void
353353 $ stmt ->build ()
354354 );
355355 }
356+
357+ public function testBuilderSelectFromWithForceIndex (): void
358+ {
359+ $ query = 'SELECT * '
360+ . ' FROM uno FORCE INDEX (id) ' ;
361+ $ parser = new Parser ($ query );
362+ $ stmt = $ parser ->statements [0 ];
363+
364+ self ::assertSame ($ query , $ stmt ->build ());
365+ }
366+
367+ /**
368+ * Ensures issue #497 is fixed.
369+ */
370+ public function testBuilderSelectFromJoinWithForceIndex (): void
371+ {
372+ $ query = 'SELECT * '
373+ . ' FROM uno '
374+ . ' JOIN dos FORCE INDEX (two_id) ON dos.id = uno.id ' ;
375+ $ parser = new Parser ($ query );
376+ $ stmt = $ parser ->statements [0 ];
377+
378+ self ::assertSame ($ query , $ stmt ->build ());
379+ }
380+
381+ /**
382+ * Ensures issue #593 is fixed.
383+ */
384+ public function testBuilderSelectFromInnerJoinWithForceIndex (): void
385+ {
386+ $ query = 'SELECT a.id, a.name, b.order_id, b.total '
387+ . ' FROM customers a '
388+ . ' INNER JOIN orders b FORCE INDEX (idx_customer_id) '
389+ . ' ON a.id = b.customer_id '
390+ . " WHERE a.status = 'active' " ;
391+
392+ $ parser = new Parser ($ query );
393+ $ stmt = $ parser ->statements [0 ];
394+
395+ $ expectedQuery = 'SELECT a.id, a.name, b.order_id, b.total '
396+ . ' FROM customers AS `a` '
397+ . ' INNER JOIN orders AS `b` FORCE INDEX (idx_customer_id) '
398+ . ' ON a.id = b.customer_id '
399+ . " WHERE a.status = 'active' " ;
400+
401+ self ::assertSame ($ expectedQuery , $ stmt ->build ());
402+ }
403+
404+ public function testBuilderSelectAllFormsOfIndexHints (): void
405+ {
406+ $ query = 'SELECT * '
407+ . ' FROM one USE INDEX (col1) IGNORE INDEX (col1, col2) FORCE INDEX (col1, col2, col3) '
408+ . ' INNER JOIN two USE INDEX (col3) IGNORE INDEX (col2, col3) FORCE INDEX (col1, col2, col3) '
409+ . ' ON one.col1 = two.col2 '
410+ . ' WHERE 1 = 1 ' ;
411+
412+ $ parser = new Parser ($ query );
413+ $ stmt = $ parser ->statements [0 ];
414+
415+ self ::assertSame ($ query , $ stmt ->build ());
416+ }
356417}
0 commit comments