0

我在我的数据库中创建了一个内存优化表类型,如下所示:

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 请求的上下文中。如果服务器在请求期间重新启动,那么请求将不得不重新开始。

4

1 回答 1

0

内存优化表仍保留在磁盘中。如果您真的想要一个没有数据持久性的仅内存表,请使用

(with memory_optimized=on, durability=schema_only)

阅读文档以获取更多详细信息:

https://docs.microsoft.com/en-us/sql/relational-databases/in-memory-oltp/introduction-to-memory-optimized-tables

https://docs.microsoft.com/en-us/sql/t-sql/statements/create-table-transact-sql

于 2018-03-26T20:20:40.850 回答