June 30, 2025 at 7:34 am
Is there a way to force a query to use Batchmode execution, my database is in 2019 compatibility mode.
For some reason, my queries are not using batch mode even when its scanning through millions of rows.
Is there a query hint or in anyway to force it to use Batch mode execution (SQL server 2019 enterprise edition)?
June 30, 2025 at 10:49 am
there is a trick.
create a temp table #dummy - 1 column with the same datatype/size of one of the tables used on your main select.
create a clustered columnstore index on table
then use it as a left outer join on your main query
drop table if exists #dummy;
create table #dummy
(fieldx varchar(100)
)
;
create clustered columnstore index #cci_dummy on #dummy;
select ...
from maintable mt
left outer join #dummy dm
on dm.fieldx = mt.fieldx
July 1, 2025 at 6:01 am
Thankyou Sir for this amazing trick, I have tested and it is working.
Does this work all the time, are there any scenarios where it might not work.
July 1, 2025 at 10:05 am
never seen it not work - but batch mode NOT always the best option.
Always test before and after with real production data volumes.
July 8, 2025 at 7:15 am
It is not possible to explicitly force Batch mode once your database is in SQL Server 2019 mode. SQL Server automatically selects the appropriate execution plan based on the number of rows and the query characteristics, either using Batch mode or Rowstore mode. In summary, while there is no explicit option like FORCE_BATCH_MODE, you can structure your queries and indexes in a way that encourages SQL Server to use Batch mode.
Viewing 5 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy