jOOQ uses bind variables by default, but logs a query with inlined values, which you probably ran in your editor. With bind variables, there's a tendency for optimisers to make estimates based on average cardinalities, which can be terribly off if your data is skewed. This tends not to happen with inline values. I've explained this more in detail here (blog is Oracle specific, but applies to SQL Server just the same):
To verify this, you could force jOOQ to use inline values using DSL.inline(), or StatementType.STATIC_STATEMENT (in Settings):
In some cases, wrong bind variable types may lead to implicit type conversions, which again lead to indexes not being applicable. Here's an Oracle DATE vs TIMESTAMP example that explains the problem:
Again, this doesn't happen with inline values, only with bind variables. The solution is not to inline the values, but to understand why it happened with the bind variable. To verify this, check your execution plans using a query like this one from here:
https://stackoverflow.com/a/7359705/521799
SELECT UseCounts, Cacheobjtype, Objtype, TEXT, query_plan
FROM sys.dm_exec_cached_plans
CROSS APPLY sys.dm_exec_sql_text(plan_handle)
CROSS APPLY sys.dm_exec_query_plan(plan_handle)
In addition to that, if you're running a test with jOOQ and then immediately run a test with a SQL editor using *the same query*, then chances are, the latter may profit from hot caches throughout the execution pipeline, e.g. "buffer caches", or whatever SQL Server calls them, execution plan caches, etc. To verify this, you could try to flush all your caches between executions, or run both executions many times using a benchmark technique like the one documented here:
If your query wasn't a COUNT(*) query, then an additional difference would be that jOOQ fetches all the rows by default, whereas SQL editors fetch only the first few rows by default, but that's irrelevant with COUNT(*).
These are the main reasons why a jOOQ execution could be slower than an execution in your SQL editor, the first two being that you didn't actually compare the exact same thing.