This is not an answer, but has been removed from the question, and I consider this information important enough to include.
If you have parameter sensitivity (parameter sniffing problem), which is what I had, starting from SQL Server 2016, it is possible to disable Parameter Sniffing via ALTER DATABASE SCOPED CONFIGURATION (Transact-SQL)
The command is
ALTER DATABASE SCOPED CONFIGURATION SET PARAMETER_SNIFFING = OFF;
Be aware that this setting will disable parameter sniffing for ALL queries in the database, not a particular set. This would solve my problem if it did not affect other unrelated queries.