{"id":"80f3a3655f1e991b","repo":"laravel/framework","slug":"this-database-engine-does-not-support-lateral-join-80f3a3","errorCode":null,"errorMessage":"This database engine does not support lateral joins.","messagePattern":"This database engine does not support lateral joins\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Database/Query/Grammars/MariaDbGrammar.php","lineNumber":22,"sourceCode":"\nuse Illuminate\\Database\\Query\\Builder;\nuse Illuminate\\Database\\Query\\JoinLateralClause;\nuse RuntimeException;\n\nclass MariaDbGrammar extends MySqlGrammar\n{\n    /**\n     * Compile a \"lateral join\" clause.\n     *\n     * @param  \\Illuminate\\Database\\Query\\JoinLateralClause  $join\n     * @param  string  $expression\n     * @return string\n     *\n     * @throws \\RuntimeException\n     */\n    public function compileJoinLateral(JoinLateralClause $join, string $expression): string\n    {\n        throw new RuntimeException('This database engine does not support lateral joins.');\n    }\n\n    /**\n     * Compile a \"JSON value cast\" statement into SQL.\n     *\n     * @param  string  $value\n     * @return string\n     */\n    public function compileJsonValueCast($value)\n    {\n        return \"json_query({$value}, '$')\";\n    }\n\n    /**\n     * Compile a query to get the number of open connections for a database.\n     *\n     * @return string\n     */","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/laravel/framework/blob/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Database/Query/Grammars/MariaDbGrammar.php#L4-L40","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Switch the connection to MySQL 8.0.14+ which supports LATERAL.","Rewrite the lateral join as a correlated subquery or window function that MariaDB supports.","Gate joinLateral behind a check that the connection is not MariaDB (isMaria() false) and provide a fallback."],"exampleFix":"// before\n$query->joinLateral(fn ($q) => $q->..., 'latest');\n\n// after (MariaDB safe)\nif (! $query->getConnection()->isMaria()) {\n    $query->joinLateral(fn ($q) => $q->..., 'latest');\n} else {\n    // correlated subquery alternative\n}","handlingStrategy":"validation","validationCode":"$connection = $query->getConnection();\nif ($connection instanceof \\Illuminate\\Database\\MySqlConnection && ! $connection->isMaria()) {\n    $query->joinLateral($subquery, 'alias');\n} else {\n    // MariaDB/SQLite: use a correlated-subquery alternative\n}","typeGuard":"function supportsLateralOnMysqlFamily(\\Illuminate\\Database\\Connection $connection): bool\n{\n    return $connection instanceof \\Illuminate\\Database\\MySqlConnection\n        && ! $connection->isMaria();\n}","tryCatchPattern":null,"preventionTips":["Detect MariaDB explicitly (isMaria()) before using MySQL 8 features.","Prefer window functions for top-N patterns on MariaDB.","Confirm the server flavour in deployment, not just 'mysql' driver."],"tags":["lateral-join","mariadb","database-engine","mysql-family"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}