top of page

Memory-Optimized Tables -- Non-durable v.s. variable

In-Memory OLTP provides the following objects that can be used for memory-optimizing temp tables and table variables:

  • Memory-optimized tables

  • Durability = SCHEMA_ONLY

  • Memory-optimized table variables

  • Must be declared in two steps (rather than inline):

  • CREATE TYPE my_type AS TABLE ...; , then

  • DECLARE @mytablevariable my_type;.

 

When we talk about Non-durable, we actually talk about SCHEMA_ONLY. This option ensures durability of the table schema. When SQL Server is restarted or a reconfiguration occurs in an Azure SQL Database, the table schema persists, but data in the table is lost. (This is unlike a table in tempdb, where both the table and its data are lost upon restart.) A typical scenario for creating a non-durable table is to store transient data, such as a staging table for an ETL process. A SCHEMA_ONLY durability avoids both transaction logging and checkpoint, which can significantly reduce I/O operations.

Whereas when using the default SCHEMA_AND_DATA tables, SQL Server provides the same durability guarantees as for disk-based tables: Transactional Durability, Restart Durability, and Media Failure Durability.

 

A memory-optimized table variable provides great efficiency by using the same memory-optimized algorithm and data structures that are used by memory-optimized tables. The efficiency is maximized when the table variable is accessed from within a natively compiled module. A memory-optimized table variable:

  • Is stored only in memory, and has no component on disk.

  • Involves no IO activity.

  • Involves no tempdb utilization or contention.

  • Can be passed into a stored proc as a table-valued parameter (TVP).

  • Must have at least one index, either hash or nonclustered.

  • For a hash index, the bucket count should ideally be 1-2 times the number of expected unique index keys, but overestimating bucket count is usually fine (up to 10X). For details see Indexes for Memory-Optimized Tables.

 

If you use temporary tables, table variables, or table-valued parameters, consider conversions of them to leverage memory-optimized tables and table variables to improve performance. The code changes are usually minimal.

 

You must create two staging database tables. The tables have the following requirements:

You need to select the correct storage mechanism for each table.

Answer:

aboutME

I am John Fan Zhang, a data analyst and finance researcher. I hold a PhD in finance, CFA charter and full membership of CFA New Zealand Society. I have fifteen-year experience in corporate investment and eight-year experience in advanced data analysis. My research focuses on the effect of social psychology (culture) on financial decisions. Finance research involves heaps of data analyses that lead me to the data field. I am a Microsoft Certified Solutions Expert (MCSE): Data Management and Analytics (Excel, Power BI, and SQL). Aside from Excel, Power BI and SQL, I am also familiar with econometric tools such as Stata, Eviews, and MATLAB. I use OX and Python for programming. I am an active data community event participant, volunteer, speaker, moderator, program reviewer, including PASS Marathon 2020, Global AI BootCamp Auckland 2019, SQL Saturday Auckland (2017, 2018, 2019), and Definity Conference (2018, 2019, 2020, Auckland, New Zealand).

Auckland, New Zealand

  • Google Site
  • Twitter
  • LinkedIn

©2016 BY JOHN'S DATA STORY

bottom of page