PHPackages                             shaburov/laravel-mysql-index-hints-scope - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. shaburov/laravel-mysql-index-hints-scope

ActiveLibrary[Database &amp; ORM](/categories/database)

shaburov/laravel-mysql-index-hints-scope
========================================

Index Hints for laravel https://dev.mysql.com/doc/refman/5.7/en/index-hints.html

V3.3.0(8mo ago)546.6k↑10.7%1MITPHPPHP ^8.0|^8.1|^8.2|^8.3|^8.4

Since May 10Pushed 8mo ago1 watchersCompare

[ Source](https://github.com/ishaburov/laravel-mysql-index-hints-scope)[ Packagist](https://packagist.org/packages/shaburov/laravel-mysql-index-hints-scope)[ RSS](/packages/shaburov-laravel-mysql-index-hints-scope/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (6)Versions (8)Used By (0)

Laravel mysql index hints scope
===============================

[](#laravel-mysql-index-hints-scope)

[![Latest Stable Version](https://camo.githubusercontent.com/04a85229ddf506f52cb123f43b88562a4d9599761d4b6700f1bb23872f3ba34a/68747470733a2f2f706f7365722e707567782e6f72672f7368616275726f762f6c61726176656c2d6d7973716c2d696e6465782d68696e74732d73636f70652f76)](//packagist.org/packages/shaburov/laravel-mysql-index-hints-scope)[![Total Downloads](https://camo.githubusercontent.com/7b4a4a3fc00ed757b6587374c722aa4da82d073cea56b02ac716f3165b021cd7/68747470733a2f2f706f7365722e707567782e6f72672f7368616275726f762f6c61726176656c2d6d7973716c2d696e6465782d68696e74732d73636f70652f646f776e6c6f616473)](//packagist.org/packages/shaburov/laravel-mysql-index-hints-scope)[![License](https://camo.githubusercontent.com/4f00f1e5c6d63e414b543773fcc92db606b0d88cede1449b86db84e9deba5be0/68747470733a2f2f706f7365722e707567782e6f72672f7368616275726f762f6c61726176656c2d6d7973716c2d696e6465782d68696e74732d73636f70652f6c6963656e7365)](//packagist.org/packages/shaburov/laravel-mysql-index-hints-scope)[![CircleCI](https://camo.githubusercontent.com/63bfdb4d9000d35ca1053dc2ca6f19728cacd2b0cb3c3dfd47112597bd245571/68747470733a2f2f646c2e636972636c6563692e636f6d2f7374617475732d62616467652f696d672f636972636c6563692f474e6631457573587744744a53366169535348316e312f437a335a33355a4e4846316a3347717a6b51377734712f747265652f6d61737465722e7376673f7374796c653d737667)](https://dl.circleci.com/status-badge/redirect/circleci/GNf1EusXwDtJS6aiSSH1n1/Cz3Z35ZNHF1j3GqzkQ7w4q/tree/master)

### Simple library for mysql index hints and optimisations (USE INDEX, FORCE INDEX, IGNORE INDEX)

[](#simple-library-for-mysql-index-hints-and-optimisations-use-index-force-index-ignore-index)

### requires

[](#requires)

- php: ^7.4|^8.0|^8.1|^8.2|^8.3
- doctrine/dbal: ^3.0
- illuminate/database: ^8.0|^9.0|^10.0|^v11.0
- illuminate/support: ^8.0|^9.0|^10.0|^v11.0

### Installation

[](#installation)

```
composer require shaburov/laravel-mysql-index-hints-scope

```

How it's use
------------

[](#how-its-use)

#### Extended class Blueprint

[](#extended-class-blueprint)

`The following methods have been added to the Blueprint class: dropIndexIfExists,hasIndex`

```
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

Schema::table('test_table', function (Blueprint $table) {
    $table->dropIndexIfExists('test_index'); // index will be delete when index exists
    $table->hasIndex('test_index'); // index existence check
});
```

#### Use trait

[](#use-trait)

```
use IndexHints\Hintable;

class ExampleModel extends Model
{
    use Hintable;
}
```

#### Functions

[](#functions)

If there is no index, then no error will occur.

```
useIndex(INDEX_NAME, (JOIN|GROUP_BY|ORDER_BY), TABLE_ALIAS);
forceIndex(INDEX_NAME, (JOIN|GROUP_BY|ORDER_BY), TABLE_ALIAS);
ignoreIndex((INDEX_NAME | [INDEX_NAME, INDEX_NAME]), (JOIN|GROUP_BY|ORDER_BY), TABLE_ALIAS);

consts:
IndexHintsConstants:JOIN;
IndexHintsConstants:GROUP_BY;
IndexHintsConstants:ORDER_BY;
```

#### Examples

[](#examples)

```
/**
* select * from example_models
* FORCE INDEX (test_index)
*/
ExampleModel::forceIndex('test_index');

/**
* select * from example_models
* IGNORE INDEX (test_index)
*/

ExampleModel::ignoreIndex('test_index');

/**
 * select * from example_models
 * USE INDEX (test_index)
 * IGNORE INDEX (test_index)
 * USE INDEX (test_index,example_index)
 */
ExampleModel::select('*')
            ->useIndex('test_index')
            ->ignoreIndex('test_index')
            ->useIndex(['test_index', 'example_index']);

/**
* select * from example_models
* USE INDEX (example_index)
* IGNORE INDEX FOR ORDER BY (test_index)
* IGNORE INDEX FOR GROUP BY (test_index)
*/
ExampleModel::select('*')
            ->useIndex(['example_index'])
            ->ignoreIndex('test_index', 'ORDER_BY')
            ->ignoreIndex('test_index', 'GROUP_BY');

/**
*select * from example_models
*IGNORE INDEX FOR JOIN (example_index)
*IGNORE INDEX FOR ORDER BY (example_index)
*IGNORE INDEX FOR GROUP BY (example_index)
*/
ExampleModel::select('*')
            ->ignoreIndex('example_index', IndexHintsConstants::JOIN)
            ->ignoreIndex('example_index', IndexHintsConstants::ORDER_BY)
            ->ignoreIndex('example_index', IndexHintsConstants::GROUP_BY);

/**
* Will be exception (However, it is an error to mix USE INDEX and FORCE INDEX for the same table)
*/
 ExampleModel::select('*')
            ->useIndex('example_index', IndexHintsConstants::JOIN)
            ->forceIndex('example_index', IndexHintsConstants::ORDER_BY)
```

Index hints give the optimizer information about how to choose indexes during query processing. Index hints, described here, differ from optimizer hints, described in Section 8.9.3, “Optimizer Hints”. Index and optimizer hints may be used separately or together.

Index hints apply only to SELECT and UPDATE statements.

Index hints are specified following a table name. (For the general syntax for specifying tables in a SELECT statement, see Section 13.2.9.2, “JOIN Clause”.) The syntax for referring to an individual table, including index hints, looks like this:

```
tbl_name [[AS] alias] [index_hint_list]

index_hint_list:
    index_hint [index_hint] ...

index_hint:
    USE {INDEX|KEY}
      [FOR {JOIN|ORDER BY|GROUP BY}] ([index_list])
  | {IGNORE|FORCE} {INDEX|KEY}
      [FOR {JOIN|ORDER BY|GROUP BY}] (index_list)

index_list:
    index_name [, index_name] ...

```

#### Offical MySQL documentation

[](#offical-mysql-documentation)

Index Hints

###  Health Score

48

—

FairBetter than 95% of packages

Maintenance61

Regular maintenance activity

Popularity35

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~204 days

Recently: every ~101 days

Total

7

Last Release

244d ago

Major Versions

v1.0.0 → v2.0.02023-11-14

v2.0.0 → v3.0.02024-08-08

PHP version history (5 changes)v1.0.0PHP ^7.4|^8.0

v2.0.0PHP ^7.4|^8.0|^8.1|^8.2

v3.0.0PHP ^7.4|^8.0|^8.1|^8.2|^8.3

v3.0.1PHP ^8.0|^8.1|^8.2|^8.3

v3.2.0PHP ^8.0|^8.1|^8.2|^8.3|^8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/f3fc58bce43457a6536410c57edf58be2e69fc50cc6e15222f236836dcfa4f32?d=identicon)[nkfrez](/maintainers/nkfrez)

---

Top Contributors

[![ishaburov](https://avatars.githubusercontent.com/u/33578398?v=4)](https://github.com/ishaburov "ishaburov (18 commits)")

---

Tags

laravellaravel-eloquentlaravel-eloquent-modelslaravel-frameworklaravel-packagemysqlphplaraveldatabaselaravel mysqlindexeshintsdatabase hintsforce indexuse indexignore index

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/shaburov-laravel-mysql-index-hints-scope/health.svg)

```
[![Health](https://phpackages.com/badges/shaburov-laravel-mysql-index-hints-scope/health.svg)](https://phpackages.com/packages/shaburov-laravel-mysql-index-hints-scope)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k7.2M71](/packages/mongodb-laravel-mongodb)[spiritix/lada-cache

A Redis based, automated and scalable database caching layer for Laravel

591444.8k2](/packages/spiritix-lada-cache)[pdphilip/elasticsearch

An Elasticsearch implementation of Laravel's Eloquent ORM

145360.2k4](/packages/pdphilip-elasticsearch)[toponepercent/baum

Baum is an implementation of the Nested Set pattern for Eloquent models.

3154.7k](/packages/toponepercent-baum)[dragon-code/laravel-data-dumper

Adding data from certain tables when executing the `php artisan schema:dump` console command

3418.6k](/packages/dragon-code-laravel-data-dumper)[ntanduy/cloudflare-d1-database

Easy configuration and setup for D1 Database connections in Laravel.

215.4k](/packages/ntanduy-cloudflare-d1-database)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
