{"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/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Database/Query/Grammars/Grammar.php#L213-L249","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Replace straightJoin() with a regular join() on non-MySQL engines.","Branch on driver: only call straightJoin when getDriverName() === 'mysql'.","Prefer database-level index/optimizer hints (FORCE INDEX) that are engine-scoped rather than sharing the query builder call."],"exampleFix":"// before\n$query->straightJoin('orders', 'orders.user_id', '=', 'users.id');\n\n// after\n$driver = $query->getConnection()->getDriverName();\nif ($driver === 'mysql') {\n    $query->straightJoin('orders', 'orders.user_id', '=', 'users.id');\n} else {\n    $query->join('orders', 'orders.user_id', '=', 'users.id');\n}","handlingStrategy":"validation","validationCode":"$driver = $query->getConnection()->getDriverName();\nif ($driver === 'mysql') {\n    $query->straightJoin('orders', 'orders.user_id', '=', 'users.id');\n} else {\n    $query->join('orders', 'orders.user_id', '=', 'users.id');\n}","typeGuard":"function supportsStraightJoins(\\Illuminate\\Database\\Connection $connection): bool\n{\n    return $connection instanceof \\Illuminate\\Database\\MySqlConnection;\n}","tryCatchPattern":null,"preventionTips":["Treat straightJoin as MySQL-only and document it at the call site.","Use engine-scoped optimizer hints instead of sharing straightJoin across drivers.","Run the full driver matrix in CI for shared query code."],"tags":["straight-join","database-engine","mysql-specific","joins"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}