I know you can add indexes in Laravel's schema builder and all.
What's got my confused is the MySQL/MariaDB 'FORCE INDEX' statement. I'm just not sure if you need to hint/force an index in order for it to be used, or if the database will automatically pick up on it and use them on its own.
The query engine of a database will decide what indices to use. Hints are onlyvto be used when you have performance issues you want to fix by overruling standard query optimisation.
Class SomeModel extends Model {
public static function IndexRaw($index_raw)
{
$model = new static();
$model->setTable(\DB::raw($model->getTable() . ' ' . $index_raw));
return $model;
}
...
}
Usage:
SomeModel::IndexRaw('FORCE INDEX (some_index_name)')->where('condition','=',true)->get();