laravel/framework · error · RuntimeException

This database engine does not support straight joins.

Error message

This database engine does not support straight joins.

What it means

The base Grammar::supportsStraightJoins() throws because STRAIGHT_JOIN is a MySQL-specific join hint that forces the left table to be read first. Only MySqlGrammar overrides supportsStraightJoins(); SQLite, Postgres, and SQL Server all use the base method and therefore throw when a straight_join clause is compiled.

Source

Thrown at src/Illuminate/Database/Query/Grammars/Grammar.php:231

     * @return string
     *
     * @throws \RuntimeException
     */
    public function compileJoinLateral(JoinLateralClause $join, string $expression): string
    {
        throw new RuntimeException('This database engine does not support lateral joins.');
    }

    /**
     * Determine if the grammar supports straight joins.
     *
     * @return bool
     *
     * @throws \RuntimeException
     */
    protected function supportsStraightJoins()
    {
        throw new RuntimeException('This database engine does not support straight joins.');
    }

    /**
     * Compile the "where" portions of the query.
     *
     * @param  \Illuminate\Database\Query\Builder  $query
     * @return string
     */
    public function compileWheres(Builder $query)
    {
        // Each type of where clause has its own compiler function, which is responsible
        // for actually creating the where clauses SQL. This helps keep the code nice
        // and maintainable since each clause has a very small method that it uses.
        if (is_null($query->wheres)) {
            return '';
        }

        // If we actually have some where clauses, we will strip off the first boolean

View on GitHub (pinned to bd6b5437e6)

Solutions

  1. Replace straightJoin() with a regular join() on non-MySQL engines.
  2. Branch on driver: only call straightJoin when getDriverName() === 'mysql'.
  3. Prefer database-level index/optimizer hints (FORCE INDEX) that are engine-scoped rather than sharing the query builder call.

Example fix

// before
$query->straightJoin('orders', 'orders.user_id', '=', 'users.id');

// after
$driver = $query->getConnection()->getDriverName();
if ($driver === 'mysql') {
    $query->straightJoin('orders', 'orders.user_id', '=', 'users.id');
} else {
    $query->join('orders', 'orders.user_id', '=', 'users.id');
}
Defensive patterns

Strategy: validation

Validate before calling

$driver = $query->getConnection()->getDriverName();
if ($driver === 'mysql') {
    $query->straightJoin('orders', 'orders.user_id', '=', 'users.id');
} else {
    $query->join('orders', 'orders.user_id', '=', 'users.id');
}

Type guard

function supportsStraightJoins(\Illuminate\Database\Connection $connection): bool
{
    return $connection instanceof \Illuminate\Database\MySqlConnection;
}

Prevention

When it happens

Trigger: Calling straightJoin(), straightJoinWhere(), or straightJoinSub() on a connection whose driver is sqlite, pgsql, or sqlsrv. The exception is raised at query compile time (when the join is rendered to SQL), not at call time.

Common situations: Using straightJoin as a MySQL performance hint and then running the same migration/query against Postgres or SQLite in CI. Copying a MySQL-optimized query into shared repository code that runs across multiple engines.

Related errors


AI-assisted analysis of laravel/framework@bd6b5437e6 (2026-08-06). Data as JSON: /data/errors/94312c01b47e5244.json. Report an issue: GitHub.