{"record":{"id":"94312c01b47e5244","repo":"laravel/framework","slug":"this-database-engine-does-not-support-straight-joi","errorCode":null,"errorMessage":"This database engine does not support straight joins.","messagePattern":"This database engine does not support straight joins\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Database/Query/Grammars/Grammar.php","lineNumber":231,"sourceCode":"     * @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     * Determine if the grammar supports straight joins.\n     *\n     * @return bool\n     *\n     * @throws \\RuntimeException\n     */\n    protected function supportsStraightJoins()\n    {\n        throw new RuntimeException('This database engine does not support straight joins.');\n    }\n\n    /**\n     * Compile the \"where\" portions of the query.\n     *\n     * @param  \\Illuminate\\Database\\Query\\Builder  $query\n     * @return string\n     */\n    public function compileWheres(Builder $query)\n    {\n        // Each type of where clause has its own compiler function, which is responsible\n        // for actually creating the where clauses SQL. This helps keep the code nice\n        // and maintainable since each clause has a very small method that it uses.\n        if (is_null($query->wheres)) {\n            return '';\n        }\n\n        // If we actually have some where clauses, we will strip off the first boolean","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/laravel/framework/blob/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Database/Query/Grammars/Grammar.php#L213-L249","documentation":"The base Grammar's supportsStraightJoins throws by default. Only MySqlGrammar (including MariaDbGrammar by inheritance) overrides it. PostgreSQL, SQLite, and SQL Server do not override it, so calling straightJoin() on those connections triggers the throw. STRAIGHT_JOIN is a MySQL-specific optimizer hint that forces the join order as written.","triggerScenarios":"Calling straightJoin() on a query builder whose connection is pgsql, sqlite, or sqlsrv. For example: DB::table('users')->join('posts', 'posts.user_id', '=', 'users.id')->straightJoin('comments', 'comments.post_id', '=', 'posts.id')->get().","commonSituations":"Developer assumes STRAIGHT_JOIN is standard SQL and uses it on PostgreSQL. Production code migrated from MySQL to PostgreSQL without removing straightJoin() calls. Test suite uses SQLite while production uses MySQL.","solutions":["Switch the DB connection to MySQL or MariaDB — the only engines whose grammars override supportsStraightJoins","Remove the straightJoin() call; a regular join() produces functionally identical results (the optimizer chooses order)","If you need explicit join ordering hints on PostgreSQL, use setTablePrefix or raw SQL via DB::statement for ANALYZE/VACUUM instead"],"exampleFix":"// before — fails on PostgreSQL / SQLite / SQL Server\nDB::table('users')->join('posts', 'posts.user_id', '=', 'users.id')->straightJoin('comments', 'comments.post_id', '=', 'posts.id')->get();\n\n// after — regular join works everywhere\nDB::table('users')->join('posts', 'posts.user_id', '=', 'users.id')->join('comments', 'comments.post_id', '=', 'posts.id')->get();","handlingStrategy":"type-guard","validationCode":"$driver = DB::connection()->getDriverName();\n\nif ($driver === 'mysql') {\n    $query->straightJoin('comments', 'comments.post_id', '=', 'posts.id');\n} else {\n    $query->join('comments', 'comments.post_id', '=', 'posts.id');\n}","typeGuard":"function supportsStraightJoins(): bool {\n    return DB::connection()->getDriverName() === 'mysql';\n}","tryCatchPattern":"try {\n    $query->straightJoin('comments', 'comments.post_id', '=', 'posts.id');\n} catch (\\RuntimeException $e) {\n    if (str_contains($e->getMessage(), 'straight joins')) {\n        $query->join('comments', 'comments.post_id', '=', 'posts.id');\n    } else {\n        throw $e;\n    }\n}","preventionTips":["Treat straightJoin() as MySQL-only and document it as such","Use regular join() unless you have a proven optimizer-ordering issue","If migrating from MySQL, audit all straightJoin() calls and replace with join()"],"tags":["joins","straight-join","mysql","database","grammar"],"backgroundTag":null,"analyzedSha":"e0f6eb3518ac29fbbca8529e97d0df7fc9f24481","analyzedAt":"2026-08-11T20:52:37.562Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}