Skip to content

Commit 08043bc

Browse files
committed
Add test for skiping index hints
1 parent 3502b1f commit 08043bc

1 file changed

Lines changed: 62 additions & 0 deletions

File tree

tests/WP_SQLite_Driver_Translation_Tests.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,6 +1248,68 @@ public function testConcatFunction(): void {
12481248
);
12491249
}
12501250

1251+
public function testIndexHints(): void {
1252+
// USE INDEX
1253+
$this->assertQuery(
1254+
'SELECT * FROM `t`',
1255+
'SELECT * FROM t USE INDEX (i)'
1256+
);
1257+
1258+
// USE KEY
1259+
$this->assertQuery(
1260+
'SELECT * FROM `t`',
1261+
'SELECT * FROM t USE KEY (k)'
1262+
);
1263+
1264+
// FORCE INDEX
1265+
$this->assertQuery(
1266+
'SELECT * FROM `t`',
1267+
'SELECT * FROM t FORCE INDEX (i)'
1268+
);
1269+
1270+
// FORCE KEY
1271+
$this->assertQuery(
1272+
'SELECT * FROM `t`',
1273+
'SELECT * FROM t FORCE KEY (k)'
1274+
);
1275+
1276+
// IGNORE INDEX
1277+
$this->assertQuery(
1278+
'SELECT * FROM `t`',
1279+
'SELECT * FROM t IGNORE INDEX (i)'
1280+
);
1281+
1282+
// IGNORE KEY
1283+
$this->assertQuery(
1284+
'SELECT * FROM `t`',
1285+
'SELECT * FROM t IGNORE KEY (k)'
1286+
);
1287+
1288+
// FOR JOIN
1289+
$this->assertQuery(
1290+
'SELECT * FROM `t` JOIN `j` ON `t`.`id` = `j`.`t_id`',
1291+
'SELECT * FROM t USE INDEX FOR JOIN (i) JOIN j ON t.id = j.t_id'
1292+
);
1293+
1294+
// FOR ORDER BY
1295+
$this->assertQuery(
1296+
'SELECT * FROM `t` ORDER BY `id` DESC',
1297+
'SELECT * FROM t USE INDEX FOR ORDER BY (i) ORDER BY id DESC'
1298+
);
1299+
1300+
// FOR GROUP BY
1301+
$this->assertQuery(
1302+
'SELECT * FROM `t` GROUP BY `id` HAVING `id` = 1',
1303+
'SELECT * FROM t USE INDEX FOR GROUP BY (i) GROUP BY id HAVING id = 1'
1304+
);
1305+
1306+
// A complex query with multiple hints and conditions.
1307+
$this->assertQuery(
1308+
'SELECT * FROM `t` JOIN `j` ON `t`.`id` = `j`.`t_id` WHERE `id` = 1 GROUP BY `id` HAVING `id` = 1 ORDER BY `id` DESC',
1309+
'SELECT * FROM `t` USE INDEX (i) USE INDEX FOR JOIN (j) USE KEY FOR ORDER BY (o) IGNORE INDEX FOR GROUP BY (g) JOIN j ON t.id = j.t_id WHERE id = 1 GROUP BY id HAVING id = 1 ORDER BY id DESC'
1310+
);
1311+
}
1312+
12511313
private function assertQuery( $expected, string $query ): void {
12521314
$error = null;
12531315
try {

0 commit comments

Comments
 (0)