Large IN (?,?,?,...) lists with many parameters can cause slow, unstable query plans, especially compared to hard‑coded literals. Using a temporary table instead avoids the long IN list: you insert all IDs into a temp table and then join your main table to that temp table, which SQL Server can optimize more effectively for larger lists.
Illustrative code in Java:
void queryWithTempTableJoin(Connection con, List<Integer> ids) throws SQLException {
if (ids == null || ids.isEmpty()) {
return; // or handle "no IDs" case explicitly