查询语言.forceIndex

Testing Is Documentation

tests/Database/Query/ForceIndexTest.php查询语言.forceIndex - 图1

Uses

  1. <?php
  2. use Tests\Database\DatabaseTestCase as TestCase;

forceIndex,ignoreIndex 基础用法

  1. public function testBaseUse(): void
  2. {
  3. $connect = $this->createDatabaseConnectMock();
  4. $sql = <<<'eot'
  5. [
  6. "SELECT `test_query`.* FROM `test_query` FORCE INDEX(nameindex,statusindex) IGNORE INDEX(testindex) WHERE `test_query`.`id` = :test_query_id",
  7. {
  8. "test_query_id": [
  9. 5
  10. ]
  11. },
  12. false
  13. ]
  14. eot;
  15. $this->assertSame(
  16. $sql,
  17. $this->varJson(
  18. $connect
  19. ->table('test_query')
  20. ->forceIndex('nameindex,statusindex')
  21. ->ignoreIndex('testindex')
  22. ->where('id', '=', 5)
  23. ->findAll(true)
  24. )
  25. );
  26. }

forceIndex 数组支持

  1. public function testForceIndexWithArray(): void
  2. {
  3. $connect = $this->createDatabaseConnectMock();
  4. $sql = <<<'eot'
  5. [
  6. "SELECT `test_query`.* FROM `test_query` FORCE INDEX(nameindex,statusindex) WHERE `test_query`.`id` = :test_query_id",
  7. {
  8. "test_query_id": [
  9. 2
  10. ]
  11. },
  12. false
  13. ]
  14. eot;
  15. $this->assertSame(
  16. $sql,
  17. $this->varJson(
  18. $connect
  19. ->table('test_query')
  20. ->forceIndex(['nameindex', 'statusindex'])
  21. ->where('id', '=', 2)
  22. ->findAll(true)
  23. )
  24. );
  25. }

ignoreIndex 数组支持

  1. public function testIgnoreIndexWithArray(): void
  2. {
  3. $connect = $this->createDatabaseConnectMock();
  4. $sql = <<<'eot'
  5. [
  6. "SELECT `test_query`.* FROM `test_query` IGNORE INDEX(nameindex,statusindex) WHERE `test_query`.`id` = :test_query_id",
  7. {
  8. "test_query_id": [
  9. 6
  10. ]
  11. },
  12. false
  13. ]
  14. eot;
  15. $this->assertSame(
  16. $sql,
  17. $this->varJson(
  18. $connect
  19. ->table('test_query')
  20. ->ignoreIndex(['nameindex', 'statusindex'])
  21. ->where('id', '=', 6)
  22. ->findAll(true)
  23. )
  24. );
  25. }