0

I have the following situation: I have a SQL 2008 R2 Enterprise edition where I have enabled TDE encryption in one of the databases. One of the stored procedures from the encrypted database is using a table variable (@t1), table that gets populated with almost 600K records. Then there is a select statement that uses a join between this table and another table from the encrypted database (t2), on t2 tables I have around 20 mil rows. This join takes forever to complete( last time took almost 4h). If I use instead of the table variable a tempoarary table (#t3) and do the same join the result is instant. Also if I run join between these 2 tables in another server where I do not have TDE encryption ( same SQL 2008 R2) , the join finish in seconds So did anybody encounter similar problems with table variables and encrypted databases using TDE? This is how I encrypted the database:

CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'AASFA234234234as234#234#$##$'

CREATE CERTIFICATE SQLCertificate
WITH SUBJECT = 'SQL Certificate',
EXPIRY_DATE = '10/31/2020';

USE DBTest
go

CREATE DATABASE ENCRYPTION KEY
WITH ALGORITHM = AES_256
ENCRYPTION BY SERVER CERTIFICATE SQLCertificate;

ALTER DATABASE DBTest
SET ENCRYPTION ON
And this is the script that I used where _rptHousehold is a table that has 18mil records. The script never gets to the PRINT '3 ' + CONVERT(VARCHAR,GETDATE(),121), hangs on the select count(*) from @tt
PRINT '1 ' + CONVERT(VARCHAR,GETDATE(),121)

IF object_id('tempdb..#tt') IS NOT NULL 
    DROP TABLE #tt


declare  @tt table
(   [id] int        IDENTITY(1,1), 
    TableID         DECIMAL(11,0),
    AdvisorID       INT,
    idBuild         INT,
    Tablename       sysname,
    tCreatedate     datetime,
    ColumnName      varchar(100),
    Column_ID       int,
    qtyValue        decimal(25,9),
    tModifiedDate   datetime
)

INSERT INTO @tt
(TableID , AdvisorID , idBuild,Tablename,   tCreatedate,ColumnName, Column_ID,qtyValue )            
select  TOP 600000 
    t.object_ID
    ,AdvisorID
    ,1635
    ,t.NAME
    ,t.Create_date
    ,c.Name
    ,c.object_ID    
    ,CAST(RAND()* 100000 AS DECIMAL(25,9))
FROM sys.tables t CROSS JOIN sys.columns c  
    CROSS JOIN (SELECT DISTINCT idAdvisor AS AdvisorID FROM dbo._rptHousehold WHERE idBuild = 1635) ac              


PRINT '2 ' + CONVERT(VARCHAR,GETDATE(),121)

SELECT COUNT(*) FROM @tt 
PRINT '3 ' + CONVERT(VARCHAR,GETDATE(),121)

UPDATE tt
    SET 
        qtyValue = rp.qtyAvgPAAssets
FROM @tt tt 
    JOIN _rptHousehold rp
        ON rp.idAdvisor= tt.AdvisorID
            AND rp.idBuild= tt.idBuild

PRINT '4 ' + CONVERT(VARCHAR,GETDATE(),121)
4

1 回答 1

1

好吧,我不认为它与 TDE 直接相关,因为 TDE 会在将数据写入磁盘时加密数据,并在从磁盘读取数据时对其进行解密,据说开销并不大(<10%)。

  • 可能在新服务器上的数据没有缓存在 RAM 中,因此必须从磁盘读取它们(当然在这种情况下 TDE 会使其速度变慢一些)。
  • 如果您有很多行要使用,建议使用临时表而不是表变量。
  • 许多其他原因导致它不能像以前那样工作 - 我将从检查执行计划开始..
于 2012-01-20T17:49:19.023 回答