我在我的数据库中创建了一个内存优化表类型,如下所示:
create type tblLocation_InMem as table(
IndexLocation int not null index IX_LocInMem,
IndexRootLocation int not null,
fldLocCrumbs nvarchar(1024) not null
)
with (memory_optimized=on)
此表类型用于需要通过多个 select 语句访问存储在其中的数据的大查询,如下所示:
declare @myLocTbl as tblLocation_InMem;
insert into @myLocTbl <some select statement>;
select <stuff> from <some table> join @myLocTbl on <join stuff>;
select <other stuff> from <other table> join @myLocTbl on <more join stuff>;
一切正常,但我查看了数据库的 File_MemOpt 文件组的 SQL 数据文件夹,我在 $HKv2 文件夹下的 In-Memory 表类型中看到了类似的内容:
显然我的内存表类型并不完全在内存中。有没有办法可以使用这种表类型并将其严格保存在内存中,而无需进行所有磁盘写入。我认为只创建一个内存表类型就可以避免任何磁盘活动。我还尝试创建一个内存表定义并指定durability=schema_only,但这仍然在磁盘上创建了东西。我应该只使用表变量吗?
我不担心重新启动或类似的事情的持久性。选择请求发生在 REST Web 请求的上下文中。如果服务器在请求期间重新启动,那么请求将不得不重新开始。