laravel/framework · error · RuntimeException

This database engine does not support lateral joins.

Error message

This database engine does not support lateral joins.

What it means

MariaDbGrammar explicitly overrides compileJoinLateral() to throw because MariaDB does not support LATERAL joins (unlike MySQL 8.0.14+). Although MariaDbGrammar extends MySqlGrammar, it re-declares the method to refuse the feature so developers get a clear message instead of invalid SQL.

Source

Thrown at src/Illuminate/Database/Query/Grammars/MariaDbGrammar.php:22

use Illuminate\Database\Query\Builder;
use Illuminate\Database\Query\JoinLateralClause;
use RuntimeException;

class MariaDbGrammar extends MySqlGrammar
{
    /**
     * Compile a "lateral join" clause.
     *
     * @param  \Illuminate\Database\Query\JoinLateralClause  $join
     * @param  string  $expression
     * @return string
     *
     * @throws \RuntimeException
     */
    public function compileJoinLateral(JoinLateralClause $join, string $expression): string
    {
        throw new RuntimeException('This database engine does not support lateral joins.');
    }

    /**
     * Compile a "JSON value cast" statement into SQL.
     *
     * @param  string  $value
     * @return string
     */
    public function compileJsonValueCast($value)
    {
        return "json_query({$value}, '$')";
    }

    /**
     * Compile a query to get the number of open connections for a database.
     *
     * @return string
     */

View on GitHub (pinned to bd6b5437e6)

Solutions

  1. Switch the connection to MySQL 8.0.14+ which supports LATERAL.
  2. Rewrite the lateral join as a correlated subquery or window function that MariaDB supports.
  3. Gate joinLateral behind a check that the connection is not MariaDB (isMaria() false) and provide a fallback.

Example fix

// before
$query->joinLateral(fn ($q) => $q->..., 'latest');

// after (MariaDB safe)
if (! $query->getConnection()->isMaria()) {
    $query->joinLateral(fn ($q) => $q->..., 'latest');
} else {
    // correlated subquery alternative
}
Defensive patterns

Strategy: validation

Validate before calling

$connection = $query->getConnection();
if ($connection instanceof \Illuminate\Database\MySqlConnection && ! $connection->isMaria()) {
    $query->joinLateral($subquery, 'alias');
} else {
    // MariaDB/SQLite: use a correlated-subquery alternative
}

Type guard

function supportsLateralOnMysqlFamily(\Illuminate\Database\Connection $connection): bool
{
    return $connection instanceof \Illuminate\Database\MySqlConnection
        && ! $connection->isMaria();
}

Prevention

When it happens

Trigger: Calling joinLateral() or leftJoinLateral() on a connection whose driver is determined to be MariaDB (isMaria() true, using MariaDbGrammar). The throw happens when the join is compiled to SQL.

Common situations: Developing against MySQL 8 and using lateral joins, then pointing the same connection at a MariaDB server. A hosting provider defaults to MariaDB where the developer assumed MySQL.

Related errors


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