
Keep in mind with version 15 of SQL Server, Microsoft introduced a feature called “Table Variable Deferred Compilation” that solves the problem mentioned here, without the use of option RECOMPILE. If you find your Table Variable queries are not performing well then you might consider adding the optimizer hint RECOMPILE to see if your query starts performing better. Once the optimizer has a better guess at the actual number of rows in a table variable, then it has a much better chance of picking an operator that works well for larger record sets, like a Hash Match for a join operation. This will allow the optimizer to know how many rows are in the table variable.
#Option recompile code#
Therefore, to improve the performance of your code that use table variables that contain lots of rows, you should consider adding the optimizer hint RECOMPILE as shown below: SELECT O., TV.īy adding the optimizer hint RECOMPILE, a statement that uses a table variable will be recompiled after the temporary table has been populated. There are two ways to recompile the MLNXOFED modules. Operators that perform well for small numbers of rows do not always scale when large numbers of rows are involved. Using an unsupported installation option Failed to uninstall the previous installation due to. Having an estimated row count of 1 works well for operators that have small row counts, like a NESTED LOOP operator for a join operation. This occurs because table variables don’t have statistics. This is because when a batch is compiled the table variable has yet to be populated with any rows, and therefore the optimizer uses an estimated row count of 1 for table variables.

Table Variables have been known to run slowly when the table variable contains lots of rows.
